001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Sergey Burlak
019: * @version $Revision$
020: */package javax.swing.plaf.metal;
021:
022: import javax.swing.Icon;
023: import javax.swing.SwingTestCase;
024: import javax.swing.plaf.UIResource;
025:
026: public class MetalIconFactoryTest extends SwingTestCase {
027: public void testGetCheckBoxIcon() {
028: Icon icon = MetalIconFactory.getCheckBoxIcon();
029: checkIcon(icon, 13, 13);
030: assertTrue(MetalIconFactory.getCheckBoxIcon() == MetalIconFactory
031: .getCheckBoxIcon());
032: }
033:
034: public void testGetCheckBoxMenuItemIcon() {
035: Icon icon = MetalIconFactory.getCheckBoxMenuItemIcon();
036: checkIcon(icon, 10, 10);
037: assertTrue(icon instanceof UIResource);
038: assertTrue(MetalIconFactory.getCheckBoxMenuItemIcon() == MetalIconFactory
039: .getCheckBoxMenuItemIcon());
040: }
041:
042: public void testGetFileChooserDetailViewIcon() {
043: Icon icon = MetalIconFactory.getFileChooserDetailViewIcon();
044: checkIcon(icon, 18, 18);
045: assertTrue(icon instanceof UIResource);
046: assertTrue(MetalIconFactory.getFileChooserDetailViewIcon() == MetalIconFactory
047: .getFileChooserDetailViewIcon());
048: }
049:
050: public void testGetFileChooserHomeFolderIcon() {
051: Icon icon = MetalIconFactory.getFileChooserHomeFolderIcon();
052: checkIcon(icon, 18, 18);
053: assertTrue(icon instanceof UIResource);
054: assertTrue(MetalIconFactory.getFileChooserHomeFolderIcon() == MetalIconFactory
055: .getFileChooserHomeFolderIcon());
056: }
057:
058: public void testGetFileChooserListViewIcon() {
059: Icon icon = MetalIconFactory.getFileChooserListViewIcon();
060: checkIcon(icon, 18, 18);
061: assertTrue(icon instanceof UIResource);
062: assertTrue(MetalIconFactory.getFileChooserListViewIcon() == MetalIconFactory
063: .getFileChooserListViewIcon());
064: }
065:
066: public void testGetFileChooserNewFolderIcon() {
067: Icon icon = MetalIconFactory.getFileChooserNewFolderIcon();
068: checkIcon(icon, 18, 18);
069: assertTrue(icon instanceof UIResource);
070: assertTrue(MetalIconFactory.getFileChooserNewFolderIcon() == MetalIconFactory
071: .getFileChooserNewFolderIcon());
072: }
073:
074: public void testGetFileChooserUpFolserIcon() {
075: Icon icon = MetalIconFactory.getFileChooserUpFolderIcon();
076: checkIcon(icon, 18, 18);
077: assertTrue(icon instanceof UIResource);
078: assertTrue(MetalIconFactory.getFileChooserUpFolderIcon() == MetalIconFactory
079: .getFileChooserUpFolderIcon());
080: }
081:
082: public void testGetHorizontalSliderThumbIcon() {
083: Icon icon = MetalIconFactory.getHorizontalSliderThumbIcon();
084: checkIcon(icon, 16, 15);
085: assertTrue(icon instanceof UIResource);
086: assertSame(MetalIconFactory.getHorizontalSliderThumbIcon(),
087: MetalIconFactory.getHorizontalSliderThumbIcon());
088: }
089:
090: public void testGetInternalFrameAltMaximizeIcon() {
091: int size = 10;
092: Icon icon = MetalIconFactory
093: .getInternalFrameAltMaximizeIcon(size);
094: checkIcon(icon, size, size);
095: assertTrue(icon instanceof UIResource);
096: assertFalse(MetalIconFactory
097: .getInternalFrameAltMaximizeIcon(size) == MetalIconFactory
098: .getInternalFrameAltMaximizeIcon(size));
099: }
100:
101: public void testGetInternalFrameCloseIcon() {
102: int size = 14;
103: Icon icon = MetalIconFactory.getInternalFrameCloseIcon(size);
104: checkIcon(icon, size, size);
105: assertTrue(icon instanceof UIResource);
106: assertFalse(MetalIconFactory.getInternalFrameCloseIcon(size) == MetalIconFactory
107: .getInternalFrameCloseIcon(size));
108: }
109:
110: public void testGetInternalFrameDefaultMenuIcon() {
111: Icon icon = MetalIconFactory.getInternalFrameDefaultMenuIcon();
112: checkIcon(icon, 16, 16);
113: assertTrue(icon instanceof UIResource);
114: assertTrue(MetalIconFactory.getInternalFrameDefaultMenuIcon() == MetalIconFactory
115: .getInternalFrameDefaultMenuIcon());
116: }
117:
118: public void testGetInternalFrameMaximizeIcon() {
119: int size = 14;
120: Icon icon = MetalIconFactory.getInternalFrameMaximizeIcon(size);
121: checkIcon(icon, size, size);
122: assertTrue(icon instanceof UIResource);
123: assertFalse(MetalIconFactory.getInternalFrameMaximizeIcon(size) == MetalIconFactory
124: .getInternalFrameMaximizeIcon(size));
125: }
126:
127: public void testGetInternalFrameMinimizeIcon() {
128: int size = 15;
129: Icon icon = MetalIconFactory.getInternalFrameMinimizeIcon(size);
130: checkIcon(icon, size, size);
131: assertTrue(icon instanceof UIResource);
132: assertFalse(MetalIconFactory.getInternalFrameMinimizeIcon(size) == MetalIconFactory
133: .getInternalFrameMinimizeIcon(size));
134: }
135:
136: public void testGetMenuArrowIcon() {
137: Icon icon = MetalIconFactory.getMenuArrowIcon();
138: checkIcon(icon, 8, 4);
139: assertTrue(icon instanceof UIResource);
140: assertTrue(MetalIconFactory.getMenuArrowIcon() == MetalIconFactory
141: .getMenuArrowIcon());
142: }
143:
144: public void testGetMenuItemArrowIcon() {
145: Icon icon = MetalIconFactory.getMenuItemArrowIcon();
146: checkIcon(icon, 8, 4);
147: assertTrue(icon instanceof UIResource);
148: assertTrue(MetalIconFactory.getMenuItemArrowIcon() == MetalIconFactory
149: .getMenuItemArrowIcon());
150: }
151:
152: public void testGetMenuItemCheckIcon() {
153: assertNull(MetalIconFactory.getMenuItemCheckIcon());
154: }
155:
156: public void testGetRadioButtonIcon() {
157: Icon icon = MetalIconFactory.getRadioButtonIcon();
158: checkIcon(icon, 13, 13);
159: assertTrue(icon instanceof UIResource);
160: assertTrue(MetalIconFactory.getRadioButtonIcon() == MetalIconFactory
161: .getRadioButtonIcon());
162: }
163:
164: public void testGetRadioButtonMenuItemIcon() {
165: Icon icon = MetalIconFactory.getRadioButtonMenuItemIcon();
166: checkIcon(icon, 10, 10);
167: assertTrue(icon instanceof UIResource);
168: assertTrue(MetalIconFactory.getRadioButtonMenuItemIcon() == MetalIconFactory
169: .getRadioButtonMenuItemIcon());
170: }
171:
172: public void testGetTreeComputerIcon() {
173: Icon icon = MetalIconFactory.getTreeComputerIcon();
174: checkIcon(icon, 16, 16);
175: assertTrue(icon instanceof UIResource);
176: assertTrue(MetalIconFactory.getTreeComputerIcon() == MetalIconFactory
177: .getTreeComputerIcon());
178: }
179:
180: public void testGetTreeControlIcon() {
181: MetalIconFactory.TreeControlIcon icon = (MetalIconFactory.TreeControlIcon) MetalIconFactory
182: .getTreeControlIcon(true);
183: checkIcon(icon, 18, 18);
184: assertFalse(icon instanceof UIResource);
185: assertTrue(icon.isLight);
186: assertFalse(MetalIconFactory.getTreeControlIcon(true) == MetalIconFactory
187: .getTreeControlIcon(true));
188: }
189:
190: public void testGetTreeFloppyDriveIcon() {
191: Icon icon = MetalIconFactory.getTreeFloppyDriveIcon();
192: checkIcon(icon, 16, 16);
193: assertTrue(icon instanceof UIResource);
194: assertTrue(MetalIconFactory.getTreeFloppyDriveIcon() == MetalIconFactory
195: .getTreeFloppyDriveIcon());
196: }
197:
198: public void testGetTreeFolderIcon() {
199: MetalIconFactory.TreeFolderIcon icon = (MetalIconFactory.TreeFolderIcon) MetalIconFactory
200: .getTreeFolderIcon();
201: checkIcon(icon, 18, 16);
202: assertFalse(icon instanceof UIResource);
203: assertEquals(-1, icon.getShift());
204: assertEquals(2, icon.getAdditionalHeight());
205: assertFalse(MetalIconFactory.getTreeFolderIcon() == MetalIconFactory
206: .getTreeFolderIcon());
207: }
208:
209: public void testGetTreeHardDriveIcon() {
210: Icon icon = MetalIconFactory.getTreeHardDriveIcon();
211: checkIcon(icon, 16, 16);
212: assertTrue(icon instanceof UIResource);
213: assertTrue(MetalIconFactory.getTreeHardDriveIcon() == MetalIconFactory
214: .getTreeHardDriveIcon());
215: }
216:
217: public void testGetTreeLeafIcon() {
218: MetalIconFactory.TreeLeafIcon icon = (MetalIconFactory.TreeLeafIcon) MetalIconFactory
219: .getTreeLeafIcon();
220: checkIcon(icon, 20, 16);
221: assertEquals(2, icon.getShift());
222: assertEquals(4, icon.getAdditionalHeight());
223: assertFalse(icon instanceof UIResource);
224: assertFalse(MetalIconFactory.getTreeLeafIcon() == MetalIconFactory
225: .getTreeLeafIcon());
226: }
227:
228: public void testGetVerticalSliderThumbIcon() {
229: Icon icon = MetalIconFactory.getVerticalSliderThumbIcon();
230: checkIcon(icon, 15, 16);
231: assertTrue(icon instanceof UIResource);
232: assertSame(MetalIconFactory.getVerticalSliderThumbIcon(),
233: MetalIconFactory.getVerticalSliderThumbIcon());
234: }
235:
236: public void testPaletteCloseIcon() {
237: MetalIconFactory.PaletteCloseIcon icon = new MetalIconFactory.PaletteCloseIcon();
238: if (isHarmony()) {
239: checkIcon(icon, 8, 8);
240: } else {
241: checkIcon(icon, 7, 7);
242: }
243: }
244:
245: public void testFolderIcon16() {
246: MetalIconFactory.FolderIcon16 icon = new MetalIconFactory.FolderIcon16();
247: checkIcon(icon, 16, 16);
248: assertFalse(icon instanceof UIResource);
249: assertEquals(0, icon.getAdditionalHeight());
250: assertEquals(0, icon.getShift());
251: }
252:
253: public void testFileIcon16() {
254: MetalIconFactory.FileIcon16 icon = new MetalIconFactory.FileIcon16();
255: checkIcon(icon, 16, 16);
256: assertFalse(icon instanceof UIResource);
257: assertEquals(0, icon.getAdditionalHeight());
258: assertEquals(0, icon.getShift());
259: }
260:
261: private static void checkIcon(final Icon icon, final int height,
262: final int width) {
263: assertNotNull(icon);
264: assertEquals(height, icon.getIconHeight());
265: assertEquals(width, icon.getIconWidth());
266: }
267: }
|