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 Vadim L. Bogdanov
019: * @version $Revision$
020: */package javax.swing.plaf.metal;
021:
022: import java.awt.LayoutManager;
023: import java.awt.Rectangle;
024: import java.beans.PropertyChangeListener;
025: import javax.swing.Icon;
026: import javax.swing.JButton;
027: import javax.swing.JInternalFrame;
028: import javax.swing.JMenu;
029: import javax.swing.JMenuBar;
030: import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
031: import javax.swing.SwingTestCase;
032:
033: public class MetalInternalFrameTitlePaneTest extends SwingTestCase {
034: /*
035: * This class is used to access protected members
036: */
037: private class TestMetalInternalFrameTitlePane extends
038: MetalInternalFrameTitlePane {
039: private static final long serialVersionUID = 1L;
040:
041: public TestMetalInternalFrameTitlePane(
042: final JInternalFrame frame) {
043: super (frame);
044: }
045:
046: public JMenu getWindowMenu() {
047: return windowMenu;
048: }
049:
050: public JMenuBar getMenuBar() {
051: return menuBar;
052: }
053:
054: public JButton getCloseButton() {
055: return closeButton;
056: }
057:
058: public Icon getCloseIcon() {
059: return closeIcon;
060: }
061:
062: public JButton getIconButton() {
063: return iconButton;
064: }
065:
066: public JButton getMaxButton() {
067: return maxButton;
068: }
069: }
070:
071: private MetalInternalFrameTitlePane pane;
072:
073: private JInternalFrame frame;
074:
075: /*
076: * Constructor for MetalInternalFrameTitlePaneTest.
077: */
078: public MetalInternalFrameTitlePaneTest(final String name) {
079: super (name);
080: }
081:
082: /*
083: * @see TestCase#setUp()
084: */
085: @Override
086: protected void setUp() throws Exception {
087: super .setUp();
088: frame = new JInternalFrame();
089: pane = new MetalInternalFrameTitlePane(frame);
090: }
091:
092: /*
093: * @see TestCase#tearDown()
094: */
095: @Override
096: protected void tearDown() throws Exception {
097: super .tearDown();
098: }
099:
100: /*
101: * Class under test for void addNotify()
102: */
103: public void testAddNotify() {
104: // Note: it's unclear what to test here
105: }
106:
107: /*
108: * Class under test for void addSubComponents()
109: */
110: public void testAddSubComponents() {
111: frame = new JInternalFrame("", true, true, true, true);
112: pane = new MetalInternalFrameTitlePane(frame);
113: assertEquals(3, pane.getComponentCount());
114: frame = new JInternalFrame("", true, true, true, false);
115: pane = new MetalInternalFrameTitlePane(frame);
116: if (isHarmony()) {
117: assertEquals(2, pane.getComponentCount());
118: }
119: }
120:
121: /*
122: * Class under test for void installDefaults()
123: */
124: public void testInstallDefaults() {
125: pane.uninstallDefaults();
126: pane.paletteTitleHeight = 0;
127: pane.paletteCloseIcon = null;
128: pane.installDefaults();
129: assertTrue("paletteTitleHeight != 0",
130: pane.paletteTitleHeight != 0);
131: assertTrue("installed paletteCloseIcon",
132: pane.paletteCloseIcon != null);
133: }
134:
135: /*
136: * Class under test for void uninstallDefaults()
137: */
138: public void testUninstallDefaults() {
139: pane.uninstallDefaults();
140: assertTrue("paletteTitleHeight != 0",
141: pane.paletteTitleHeight != 0);
142: assertTrue("didn't uninstall paletteCloseIcon",
143: pane.paletteCloseIcon != null);
144: }
145:
146: /*
147: * Class under test for void createButtons()
148: */
149: public void testCreateButtons() {
150: TestMetalInternalFrameTitlePane pane = new TestMetalInternalFrameTitlePane(
151: frame);
152: assertEquals("maxButton accessible name", "Maximize", pane
153: .getMaxButton().getAccessibleContext()
154: .getAccessibleName());
155: if (isHarmony()) {
156: assertFalse("maxButton's border is not painted", pane
157: .getMaxButton().isBorderPainted());
158: }
159: assertEquals("iconButton accessible name", "Iconify", pane
160: .getIconButton().getAccessibleContext()
161: .getAccessibleName());
162: if (isHarmony()) {
163: assertFalse("iconButton's border is not painted", pane
164: .getIconButton().isBorderPainted());
165: }
166: assertEquals("closeButton accessible name", "Close", pane
167: .getCloseButton().getAccessibleContext()
168: .getAccessibleName());
169: if (isHarmony()) {
170: assertFalse("closeButton's border is not painted", pane
171: .getCloseButton().isBorderPainted());
172: }
173: }
174:
175: /*
176: * Class under test for void assembleSystemMenu()
177: */
178: public void testAssembleSystemMenu() {
179: TestMetalInternalFrameTitlePane pane = new TestMetalInternalFrameTitlePane(
180: frame);
181: pane.assembleSystemMenu();
182: assertNull("windowMenu == null", pane.getWindowMenu());
183: assertNull("menuBar == null", pane.getMenuBar());
184: }
185:
186: /*
187: * Class under test for void showSystemMenu()
188: */
189: public void testShowSystemMenu() {
190: // does nothing
191: }
192:
193: /*
194: * Class under test for MetalInternalFrameTitlePane(JInternalFrame)
195: */
196: public void testMetalInternalFrameTitlePane() {
197: pane = new MetalInternalFrameTitlePane(frame);
198: assertFalse("isPalette == false", pane.isPalette);
199: }
200:
201: /*
202: * Class under test for void addSystemMenuItems(JMenu)
203: */
204: public void testAddSystemMenuItems() {
205: // the tested function does nothing
206: JMenu menu = new JMenu();
207: pane.addSystemMenuItems(menu);
208: assertEquals(0, menu.getItemCount());
209: }
210:
211: /*
212: * Class under test for PropertyChangeListener createPropertyChangeListener()
213: */
214: public void testCreatePropertyChangeListener() {
215: PropertyChangeListener listener = pane
216: .createPropertyChangeListener();
217: assertTrue("!= null", listener != null);
218: assertTrue(
219: "instanceof TitlePaneLayout",
220: listener instanceof BasicInternalFrameTitlePane.PropertyChangeHandler);
221: }
222:
223: /*
224: * Class under test for LayoutManager createLayout()
225: */
226: public void testCreateLayout() {
227: LayoutManager layout = pane.createLayout();
228: assertTrue("!= null", layout != null);
229: assertTrue(
230: "instanceof TitlePaneLayout",
231: layout instanceof BasicInternalFrameTitlePane.TitlePaneLayout);
232: }
233:
234: /*
235: * Class under test for void void setPalette(boolean)
236: */
237: public void testSetPalette() {
238: TestMetalInternalFrameTitlePane pane = new TestMetalInternalFrameTitlePane(
239: frame);
240: frame.setClosable(true);
241: frame.setIconifiable(true);
242: frame.setMaximizable(true);
243: // test set to true
244: pane.setPalette(true);
245: assertTrue("isPalette is true", pane.isPalette);
246: assertTrue("changed close icon", pane.getCloseButton()
247: .getIcon() == pane.paletteCloseIcon);
248: assertTrue("1 child", pane.getComponentCount() == 1);
249: // is layoutContainer called?
250: // test set to false
251: pane.setPalette(false);
252: assertFalse("isPalette is false", pane.isPalette);
253: assertTrue("changed close icon", pane.getCloseButton()
254: .getIcon() == pane.getCloseIcon());
255: assertTrue("3 children", pane.getComponentCount() == 3);
256: }
257:
258: public void testPaintPalette() {
259: // Note: painting code, cannot test
260: }
261:
262: /*
263: * Class under test for void paintComponent(Graphics)
264: */
265: public void testPaintComponent() {
266: // Note: painting code, cannot test
267: }
268:
269: /*
270: * Test MetalInternalFrameTitlePane.MetalTitlePaneLayout class
271: */
272: public void testMetalTitlePaneLayout() {
273: TestMetalInternalFrameTitlePane pane = new TestMetalInternalFrameTitlePane(
274: frame);
275: pane.setSize(200, 31);
276: LayoutManager layout = pane.getLayout();
277: final Rectangle iconButtonBounds = new Rectangle(134, 7, 16, 16);
278: final Rectangle maximizeButtonBounds = new Rectangle(156, 7,
279: 16, 16);
280: final Rectangle closeButtonBounds = new Rectangle(178, 7, 16,
281: 16);
282: // test layoutContainer(): non-iconifiable, non-maximizable, non-closable
283: layout.layoutContainer(null);
284: // assertEquals("iconButton", zeroBounds,
285: // pane.getComponent(0).getBounds());
286: // assertTrue("maximizeButton", pane.getComponent(1).getBounds().
287: // equals(zeroBounds));
288: // assertTrue("closeButton", pane.getComponent(2).getBounds().
289: // equals(zeroBounds));
290: // test layoutContainer(): iconifiable, maximizable, closable
291: frame.setIconifiable(true);
292: frame.setMaximizable(true);
293: frame.setClosable(true);
294: layout.layoutContainer(pane);
295: if (isHarmony()) {
296: assertEquals("iconButton", iconButtonBounds, pane
297: .getComponent(0).getBounds());
298: assertEquals("maximizeButton", maximizeButtonBounds, pane
299: .getComponent(1).getBounds());
300: assertEquals("closeButton", closeButtonBounds, pane
301: .getComponent(2).getBounds());
302: }
303: // test layoutContainer(): isPalette == true
304: pane.setPalette(true);
305: layout.layoutContainer(null);
306: // these bounds can be changed in the future
307: if (isHarmony()) {
308: assertEquals("palette: closeButton", new Rectangle(189, 11,
309: 8, 8), pane.getComponent(0).getBounds());
310: }
311: // minimumLayoutSize(), preferredLayoutSize() implementations
312: assertTrue("", layout.minimumLayoutSize(pane) != null);
313: assertTrue("", layout.preferredLayoutSize(pane) != null);
314: }
315: }
|