0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: /**
0018: * @author Alexander T. Simbirtsev
0019: * @version $Revision$
0020: * Created on 02.09.2004
0021: *
0022: */package javax.swing;
0023:
0024: import java.awt.Canvas;
0025: import java.awt.Color;
0026: import java.awt.Component;
0027: import java.awt.Container;
0028: import java.awt.DefaultFocusTraversalPolicy;
0029: import java.awt.Dimension;
0030: import java.awt.Font;
0031: import java.awt.Graphics;
0032: import java.awt.Insets;
0033: import java.awt.Panel;
0034: import java.awt.Point;
0035: import java.awt.Rectangle;
0036: import java.awt.event.ActionEvent;
0037: import java.awt.event.ActionListener;
0038: import java.awt.event.InputEvent;
0039: import java.awt.event.KeyEvent;
0040: import java.awt.event.MouseAdapter;
0041: import java.awt.event.MouseEvent;
0042: import java.awt.event.MouseListener;
0043: import java.beans.PropertyChangeEvent;
0044: import java.beans.PropertyChangeListener;
0045: import java.beans.PropertyVetoException;
0046: import java.beans.VetoableChangeListener;
0047: import java.lang.reflect.InvocationTargetException;
0048: import java.lang.reflect.Method;
0049: import java.util.EventListener;
0050: import java.util.Locale;
0051: import javax.swing.border.Border;
0052: import javax.swing.border.EmptyBorder;
0053: import javax.swing.event.AncestorEvent;
0054: import javax.swing.event.AncestorListener;
0055: import javax.swing.event.SwingPropertyChangeSupportTest.ConcreteVetoableChangeListener;
0056: import javax.swing.plaf.ComponentUI;
0057: import javax.swing.plaf.basic.BasicPanelUI;
0058:
0059: @SuppressWarnings("serial")
0060: public class JComponentTest extends SwingTestCase {
0061: protected JComponent panel = null;
0062:
0063: protected int find(final Object[] array, final Object value) {
0064: int found = 0;
0065: if (array != null) {
0066: for (int i = 0; i < array.length; i++) {
0067: if (array[i].equals(value)) {
0068: found++;
0069: }
0070: }
0071: }
0072: return found;
0073: }
0074:
0075: /**
0076: * Constructor for JComponentTest.
0077: */
0078: public JComponentTest(final String str) {
0079: super (str);
0080: setIgnoreNotImplemented(true);
0081: }
0082:
0083: /*
0084: * @see TestCase#setUp()
0085: */
0086: @Override
0087: protected void setUp() throws Exception {
0088: super .setUp();
0089: panel = new JComponent() {
0090: public ComponentUI getUI() {
0091: return ui;
0092: }
0093: };
0094: }
0095:
0096: /*
0097: * @see TestCase#tearDown()
0098: */
0099: @Override
0100: protected void tearDown() throws Exception {
0101: super .tearDown();
0102: panel = null;
0103: }
0104:
0105: public void testGetHeight() {
0106: int height = 100;
0107: int width = 200;
0108: panel.setSize(width, height);
0109: assertEquals(panel.getHeight(), height);
0110: }
0111:
0112: public void testGetWidth() {
0113: int height = 100;
0114: int width = 200;
0115: panel.setSize(width, height);
0116: assertEquals(panel.getWidth(), width);
0117: }
0118:
0119: public void testGetX() {
0120: int x = 100;
0121: int y = 200;
0122: panel.setLocation(x, y);
0123: assertEquals(panel.getX(), x);
0124: }
0125:
0126: public void testGetY() {
0127: int x = 100;
0128: int y = 200;
0129: panel.setLocation(x, y);
0130: assertEquals(panel.getY(), y);
0131: }
0132:
0133: /*
0134: * Class under test for boolean contains(int, int)
0135: */
0136: public void testContainsintint() {
0137: int x = 100;
0138: int y = 200;
0139: int height = 200;
0140: int width = 400;
0141: panel.setBounds(x, y, width, height);
0142: assertTrue(panel.contains(20, 50));
0143: assertTrue(panel.contains(width - 20, height - 50));
0144: assertFalse(panel.contains(width + 20, height - 50));
0145: assertFalse(panel.contains(width - 20, height + 50));
0146: }
0147:
0148: public void testReshape() {
0149: int x = 100;
0150: int y = 200;
0151: int height = 200;
0152: int width = 400;
0153: panel.setBounds(x, y, width, height);
0154: assertTrue(panel.getLocation().equals(new Point(x, y)));
0155: assertTrue(panel.getSize().equals(new Dimension(width, height)));
0156: }
0157:
0158: public void testIsMaximumSizeSet() {
0159: assertFalse(panel.isMaximumSizeSet());
0160: panel.setMaximumSize(new Dimension(100, 200));
0161: assertTrue(panel.isMaximumSizeSet());
0162: }
0163:
0164: public void testIsMinimumSizeSet() {
0165: assertFalse(panel.isMinimumSizeSet());
0166: panel.setMinimumSize(new Dimension(100, 200));
0167: assertTrue(panel.isMinimumSizeSet());
0168: }
0169:
0170: public void testIsPreferredSizeSet() {
0171: assertFalse(panel.isPreferredSizeSet());
0172: panel.setPreferredSize(new Dimension(100, 200));
0173: assertTrue(panel.isPreferredSizeSet());
0174: }
0175:
0176: /*
0177: * Class under test for Rectangle getBounds(Rectangle)
0178: */
0179: public void testGetBoundsRectangle() {
0180: Rectangle newBounds = new Rectangle(100, 200, 300, 400);
0181: panel.setBounds(newBounds);
0182: Rectangle boundsObtained = new Rectangle();
0183: boundsObtained = panel.getBounds(boundsObtained);
0184: assertEquals(newBounds, boundsObtained);
0185: }
0186:
0187: /*
0188: * Class under test for Point getLocation(Point)
0189: */
0190: public void testGetLocationPoint() {
0191: Point newLocation = new Point(100, 200);
0192: panel.setLocation(newLocation);
0193: Point pointObtained = new Point();
0194: pointObtained = panel.getLocation(pointObtained);
0195: assertTrue(pointObtained.equals(newLocation));
0196: }
0197:
0198: /*
0199: * Class under test for Insets getInsets()
0200: */
0201: public void testGetInsets() {
0202: Insets insetsObtained = panel.getInsets();
0203: assertTrue(insetsObtained.equals(new Insets(0, 0, 0, 0)));
0204: int top = 10;
0205: int left = 20;
0206: int bottom = 30;
0207: int right = 40;
0208: panel.setBorder(new EmptyBorder(top, left, bottom, right));
0209: insetsObtained = panel.getInsets();
0210: assertTrue(insetsObtained.equals(new Insets(top, left, bottom,
0211: right)));
0212: }
0213:
0214: /*
0215: * Class under test for Insets getInsets(Insets)
0216: */
0217: public void testGetInsetsInsets() {
0218: int top = 10;
0219: int left = 20;
0220: int bottom = 30;
0221: int right = 40;
0222: Insets insetsForParameter = new Insets(right, bottom, left, top);
0223: Insets insetsObtained = panel.getInsets(insetsForParameter);
0224: assertTrue(insetsObtained.equals(new Insets(0, 0, 0, 0)));
0225: insetsForParameter = new Insets(right, bottom, left, top);
0226: panel.setBorder(new EmptyBorder(top, left, bottom, right));
0227: insetsObtained = panel.getInsets(insetsForParameter);
0228: assertTrue(insetsObtained.equals(new Insets(top, left, bottom,
0229: right)));
0230: }
0231:
0232: /*
0233: * Class under test for Dimension getSize(Dimension)
0234: */
0235: public void testGetSizeDimension() {
0236: Dimension newSize = new Dimension(100, 100);
0237: panel.setSize(newSize);
0238: Dimension sizeObtained = new Dimension();
0239: sizeObtained = panel.getSize(sizeObtained);
0240: assertTrue(newSize.equals(sizeObtained));
0241: }
0242:
0243: /*
0244: * Class under test for Dimension getMinimumSize()
0245: */
0246: public void testGetMinimumSize() {
0247: panel = new JLayeredPane();
0248: assertEquals(new Dimension(0, 0), panel.getMinimumSize());
0249: panel = new JPanel();
0250: panel.setPreferredSize(new Dimension(100, 200));
0251: // assertEquals(new Dimension(10 ,10), panel.getMinimumSize());
0252: panel = new JPanel();
0253: panel.setMinimumSize(new Dimension(100, 200));
0254: assertEquals(new Dimension(100, 200), panel.getMinimumSize());
0255: // if (InternalTests.isIncluded) {
0256: // assertTrue(panel.getMinimumSize() != panel.getMinimumSize());
0257: // }
0258: }
0259:
0260: /*
0261: * Class under test for void setMinimumSize(Dimension)
0262: */
0263: public void testSetMinimumSizeDimension() {
0264: final Dimension minimumSize1 = new Dimension(100, 200);
0265: final Dimension minimumSize2 = new Dimension(200, 300);
0266: class MinimumListener implements PropertyChangeListener {
0267: boolean caught = false;
0268:
0269: public void propertyChange(final PropertyChangeEvent evt) {
0270: assertTrue("minimumSize".equals(evt.getPropertyName()));
0271: assertTrue(minimumSize1.equals(evt.getOldValue()));
0272: assertTrue(minimumSize2.equals(evt.getNewValue()));
0273: caught = true;
0274: }
0275: }
0276: ;
0277: panel.setMinimumSize(minimumSize1);
0278: assertTrue(panel.getMinimumSize().equals(minimumSize1));
0279: MinimumListener listener = new MinimumListener();
0280: panel.addPropertyChangeListener(listener);
0281: panel.setMinimumSize(minimumSize2);
0282: assertTrue(listener.caught);
0283: assertTrue(panel.getMinimumSize().equals(minimumSize2));
0284: }
0285:
0286: /*
0287: * Class under test for Dimension getMaximumSize()
0288: */
0289: public void testGetMaximumSize() {
0290: panel = new JPanel();
0291: panel.setPreferredSize(new Dimension(100, 200));
0292: assertEquals(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE),
0293: panel.getMaximumSize());
0294: panel = new JPanel();
0295: panel.setMaximumSize(new Dimension(100, 200));
0296: assertEquals(new Dimension(100, 200), panel.getMaximumSize());
0297: // if (InternalTests.isIncluded) {
0298: // assertTrue(panel.getMaximumSize() != panel.getMaximumSize());
0299: // }
0300: }
0301:
0302: /*
0303: * Class under test for void setMaximumSize(Dimension)
0304: */
0305: public void testSetMaximumSizeDimension() {
0306: final Dimension maximumSize1 = new Dimension(100, 200);
0307: final Dimension maximumSize2 = new Dimension(200, 300);
0308: class MaximumListener implements PropertyChangeListener {
0309: boolean caught = false;
0310:
0311: public void propertyChange(final PropertyChangeEvent evt) {
0312: assertTrue("maximumSize".equals(evt.getPropertyName()));
0313: assertTrue(maximumSize1.equals(evt.getOldValue()));
0314: assertTrue(maximumSize2.equals(evt.getNewValue()));
0315: caught = true;
0316: }
0317: }
0318: ;
0319: panel.setMaximumSize(maximumSize1);
0320: assertTrue(maximumSize1.equals(panel.getMaximumSize()));
0321: MaximumListener listener = new MaximumListener();
0322: panel.addPropertyChangeListener(listener);
0323: panel.setMaximumSize(maximumSize2);
0324: assertTrue(listener.caught);
0325: assertTrue(maximumSize2.equals(panel.getMaximumSize()));
0326: }
0327:
0328: /*
0329: * Class under test for Dimension getPreferredSize()
0330: */
0331: public void testGetPreferredSize() {
0332: final Dimension preferredSize1 = new Dimension(100, 200);
0333: final Dimension preferredSize2 = new Dimension(200, 300);
0334: panel.setPreferredSize(preferredSize1);
0335: assertTrue(preferredSize1.equals(panel.getPreferredSize()));
0336: panel.setPreferredSize(preferredSize2);
0337: assertTrue(preferredSize2.equals(panel.getPreferredSize()));
0338: panel = new JLayeredPane();
0339: assertEquals(new Dimension(0, 0), panel.getPreferredSize());
0340: panel.setPreferredSize(new Dimension(100, 200));
0341: assertEquals(new Dimension(100, 200), panel.getPreferredSize());
0342: // if (InternalTests.isIncluded) {
0343: // assertTrue(panel.getPreferredSize() != panel.getPreferredSize());
0344: // }
0345: }
0346:
0347: /*
0348: * Class under test for void setPreferredSize(Dimension)
0349: */
0350: public void testSetPreferredSizeDimension() {
0351: final Dimension preferredSize1 = new Dimension(100, 200);
0352: final Dimension preferredSize2 = new Dimension(200, 300);
0353: class PreferredListener implements PropertyChangeListener {
0354: boolean caught = false;
0355:
0356: public void propertyChange(final PropertyChangeEvent evt) {
0357: assertTrue("preferredSize"
0358: .equals(evt.getPropertyName()));
0359: assertTrue(preferredSize1.equals(evt.getOldValue()));
0360: assertTrue(preferredSize2.equals(evt.getNewValue()));
0361: caught = true;
0362: }
0363: }
0364: ;
0365: panel.setPreferredSize(preferredSize1);
0366: assertTrue(preferredSize1.equals(panel.getPreferredSize()));
0367: PreferredListener listener = new PreferredListener();
0368: panel.addPropertyChangeListener(listener);
0369: panel.setPreferredSize(preferredSize2);
0370: assertTrue(listener.caught);
0371: assertTrue(preferredSize2.equals(panel.getPreferredSize()));
0372: panel = new JLayeredPane();
0373: assertEquals(new Dimension(0, 0), panel.getPreferredSize());
0374: panel.setPreferredSize(new Dimension(100, 200));
0375: assertEquals(new Dimension(100, 200), panel.getPreferredSize());
0376: }
0377:
0378: @SuppressWarnings("deprecation")
0379: public void testComputeVisibleRect() {
0380: JWindow window = new JWindow();
0381: JComponent panel1 = new JPanel();
0382: JComponent panel2 = new JPanel();
0383: JComponent panel3 = new JPanel();
0384: panel1.setPreferredSize(new Dimension(100, 100));
0385: panel2.setPreferredSize(new Dimension(100, 100));
0386: panel3.setPreferredSize(new Dimension(100, 100));
0387: panel1.setMaximumSize(new Dimension(100, 100));
0388: panel2.setMaximumSize(new Dimension(100, 100));
0389: panel3.setMaximumSize(new Dimension(100, 100));
0390: panel1.setMinimumSize(new Dimension(100, 100));
0391: panel2.setMinimumSize(new Dimension(100, 100));
0392: panel3.setMinimumSize(new Dimension(100, 100));
0393: panel.setPreferredSize(new Dimension(300, 300));
0394: panel1.setBackground(Color.BLACK);
0395: panel2.setBackground(Color.RED);
0396: panel3.setBackground(Color.YELLOW);
0397: panel.setLayout(new OverlayLayout(panel));
0398: panel1.setAlignmentX(1.0f);
0399: panel2.setAlignmentX(0.3f);
0400: panel3.setAlignmentX(0.0f);
0401: panel1.setAlignmentY(1.0f);
0402: panel2.setAlignmentY(0.3f);
0403: panel3.setAlignmentY(0.0f);
0404: panel.add(panel1);
0405: panel.add(panel2);
0406: panel.add(panel3);
0407: window.setSize(150, 150);
0408: panel.setBorder(new EmptyBorder(10, 20, 30, 40));
0409: window.getContentPane().add(panel);
0410: window.show();
0411: Rectangle rect = new Rectangle();
0412: panel.computeVisibleRect(rect);
0413: assertEquals("visible rectangle ",
0414: new Rectangle(0, 0, 150, 150), rect);
0415: panel1.computeVisibleRect(rect);
0416: assertEquals("visible rectangle ", new Rectangle(0, 0, 45, 55),
0417: rect);
0418: panel2.computeVisibleRect(rect);
0419: assertEquals("visible rectangle ", new Rectangle(0, 0, 75, 85),
0420: rect);
0421: panel3.computeVisibleRect(rect);
0422: assertEquals("visible rectangle ", new Rectangle(0, 0, 45, 55),
0423: rect);
0424: }
0425:
0426: @SuppressWarnings("deprecation")
0427: public void testGetVisibleRect() {
0428: JWindow window = new JWindow();
0429: JWindow window2 = new JWindow(window);
0430: JComponent panel1 = new JPanel();
0431: Container panel2 = new Panel();
0432: JComponent panel3 = new JPanel();
0433: JComponent panel4 = new JPanel();
0434: panel1.setPreferredSize(new Dimension(100, 100));
0435: panel2.setSize(new Dimension(110, 110));
0436: panel3.setPreferredSize(new Dimension(120, 120));
0437: panel1.setMaximumSize(new Dimension(100, 100));
0438: panel3.setMaximumSize(new Dimension(120, 120));
0439: panel1.setMinimumSize(new Dimension(100, 100));
0440: panel3.setMinimumSize(new Dimension(120, 120));
0441: panel.setPreferredSize(new Dimension(300, 300));
0442: panel1.setBackground(Color.BLACK);
0443: panel2.setBackground(Color.RED);
0444: panel3.setBackground(Color.YELLOW);
0445: panel.setLayout(new OverlayLayout(panel));
0446: panel1.setAlignmentX(1.0f);
0447: panel3.setAlignmentX(0.0f);
0448: panel1.setAlignmentY(1.0f);
0449: panel3.setAlignmentY(0.0f);
0450: panel.add(panel1);
0451: panel1.add(panel2);
0452: panel2.add(panel3);
0453: window.setSize(150, 150);
0454: panel.setBorder(new EmptyBorder(10, 20, 30, 40));
0455: window.getContentPane().add(panel);
0456: window.setVisible(true);
0457: window2.setBounds(500, 500, 100, 110);
0458: window2.getContentPane().add(panel4);
0459: window2.show();
0460: assertEquals("visible rectangle ", new Rectangle(150, 150),
0461: panel.getVisibleRect());
0462: assertEquals("visible rectangle ", new Rectangle(90, 100),
0463: panel1.getVisibleRect());
0464: assertEquals("visible rectangle ",
0465: new Rectangle(15, 0, 90, 90), panel3.getVisibleRect());
0466: assertEquals(new Rectangle(100, 110), panel4.getVisibleRect());
0467: window.setVisible(false);
0468: window.setSize(10, 10);
0469: window.pack();
0470: assertEquals("visible rectangle ", new Rectangle(300, 300),
0471: panel.getVisibleRect());
0472: assertEquals("visible rectangle ", new Rectangle(100, 100),
0473: panel1.getVisibleRect());
0474: assertEquals("visible rectangle ",
0475: new Rectangle(10, 0, 100, 90), panel3.getVisibleRect());
0476: }
0477:
0478: class ActionListenerDummy implements ActionListener {
0479: public ActionEvent eventHeard = null;
0480:
0481: String str;
0482:
0483: public ActionListenerDummy() {
0484: }
0485:
0486: public ActionListenerDummy(String s) {
0487: str = s;
0488: }
0489:
0490: public void actionPerformed(final ActionEvent e) {
0491: eventHeard = e;
0492: }
0493: };
0494:
0495: /*
0496: * Class under test for void processKeyEvent(KeyEvent)
0497: */
0498: public void testProcessKeyEventKeyEvent() {
0499: ActionListenerDummy action1 = new ActionListenerDummy("1");
0500: ActionListenerDummy action2 = new ActionListenerDummy("2");
0501: ActionListenerDummy action3 = new ActionListenerDummy("3");
0502: ActionListenerDummy action41 = new ActionListenerDummy("41");
0503: ActionListenerDummy action43 = new ActionListenerDummy("42");
0504: ActionListenerDummy action51 = new ActionListenerDummy("51");
0505: ActionListenerDummy action52 = new ActionListenerDummy("52");
0506: ActionListenerDummy action53 = new ActionListenerDummy("53");
0507: ActionListenerDummy action54 = new ActionListenerDummy("54");
0508: JComponent component1 = new JPanel();
0509: Component component2 = new Panel();
0510: JComponent component3 = new JButton("3");
0511: JWindow component4 = new JWindow();
0512: component4.getContentPane().add(component1);
0513: component1.add(component2);
0514: component1.add(component3);
0515: KeyEvent event11 = new KeyEvent(component1,
0516: KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_A, 'a');
0517: KeyEvent event22 = new KeyEvent(component2,
0518: KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_B, 'b');
0519: KeyEvent event33 = new KeyEvent(component3,
0520: KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_C, 'c');
0521: KeyEvent event42 = new KeyEvent(component2,
0522: KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_D, 'd');
0523: KeyEvent event51 = new KeyEvent(component1,
0524: KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_ENTER, '\n');
0525: KeyStroke keyStroke1 = KeyStroke.getKeyStrokeForEvent(event11);
0526: KeyStroke keyStroke2 = KeyStroke.getKeyStrokeForEvent(event22);
0527: KeyStroke keyStroke3 = KeyStroke.getKeyStrokeForEvent(event33);
0528: KeyStroke keyStroke4 = KeyStroke.getKeyStrokeForEvent(event42);
0529: KeyStroke keyStroke5 = KeyStroke.getKeyStrokeForEvent(event51);
0530: component1.registerKeyboardAction(action1, keyStroke1,
0531: JComponent.WHEN_FOCUSED);
0532: component1.registerKeyboardAction(action2, keyStroke2,
0533: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0534: component3.registerKeyboardAction(action3, keyStroke3,
0535: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0536: component1.registerKeyboardAction(action41, keyStroke4,
0537: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0538: component3.registerKeyboardAction(action43, keyStroke4,
0539: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0540: component3.registerKeyboardAction(action43, keyStroke4,
0541: JComponent.WHEN_IN_FOCUSED_WINDOW);
0542: component3.registerKeyboardAction(action53, keyStroke5,
0543: JComponent.WHEN_FOCUSED);
0544: component1.registerKeyboardAction(action51, keyStroke5,
0545: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0546: // component3.processKeyEvent(event1);
0547: // assertFalse(event1.isConsumed());
0548: //
0549: // event1 = new KeyEvent(component1, KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_A, 'a');
0550: // new JPanel().processKeyEvent(event1);
0551: // assertFalse(event1.isConsumed());
0552: component1.processKeyEvent(event11);
0553: assertTrue("event1: actionPerformed called for component",
0554: action1.eventHeard != null);
0555: assertTrue(event11.isConsumed());
0556: action1.eventHeard = null;
0557: component3.processKeyEvent(event22);
0558: assertNull("event2: wrong actionPerformed called for parent",
0559: action1.eventHeard);
0560: assertTrue("event2: right actionPerformed called for parent",
0561: action2.eventHeard != null);
0562: assertTrue(event22.isConsumed());
0563: action2.eventHeard = null;
0564: component3.processKeyEvent(event33);
0565: assertNull("event3: actionPerformed called for parent",
0566: action1.eventHeard);
0567: assertNull("event3: actionPerformed called for brother",
0568: action2.eventHeard);
0569: assertTrue("event3: actionPerformed called for component",
0570: action3.eventHeard != null);
0571: assertTrue(event33.isConsumed());
0572: action3.eventHeard = null;
0573: component3.processKeyEvent(event42);
0574: assertNull("event4: actionPerformed called for parent",
0575: action1.eventHeard);
0576: assertNull("event4: actionPerformed called for brother",
0577: action2.eventHeard);
0578: assertNull("event4: actionPerformed called for component",
0579: action3.eventHeard);
0580: assertNull("event4: actionPerformed called for brother",
0581: action41.eventHeard);
0582: assertTrue("event4: actionPerformed called for brother",
0583: action43.eventHeard != null);
0584: assertTrue(event42.isConsumed());
0585: component3.processKeyEvent(event51);
0586: assertNull("event5: actionPerformed called for parent",
0587: action51.eventHeard);
0588: assertTrue("event5: actionPerformed called for parent",
0589: action53.eventHeard != null);
0590: assertTrue(event51.isConsumed());
0591: JComponent panel1 = new JPanel();
0592: JComponent panel2 = new JPanel();
0593: JTextField editor = new JTextField();
0594: KeyEvent event6 = new KeyEvent(editor, KeyEvent.KEY_PRESSED, 0,
0595: 0, KeyEvent.VK_ENTER, '\n');
0596: panel1.registerKeyboardAction(action52, keyStroke5,
0597: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0598: panel2.registerKeyboardAction(action54, keyStroke5,
0599: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0600: panel2.add(panel1);
0601: panel1.add(editor);
0602: action52.eventHeard = null;
0603: action54.eventHeard = null;
0604: panel2.processKeyEvent(event6);
0605: assertNull("event6: actionPerformed called for parent",
0606: action52.eventHeard);
0607: assertTrue("event6: actionPerformed called for parent",
0608: action54.eventHeard != null);
0609: assertTrue(event6.isConsumed());
0610: action52.eventHeard = null;
0611: action54.eventHeard = null;
0612: event6 = new KeyEvent(editor, KeyEvent.KEY_PRESSED, 0, 0,
0613: KeyEvent.VK_ENTER, '\n');
0614: panel1.processKeyEvent(event6);
0615: assertTrue("event6: actionPerformed called for parent",
0616: action52.eventHeard != null);
0617: assertNull("event6: actionPerformed called for parent",
0618: action54.eventHeard);
0619: assertTrue(event6.isConsumed());
0620: }
0621:
0622: public void testProcessKeyEvent2() {
0623: ActionListenerDummy action1 = new ActionListenerDummy();
0624: JComponent container = new JPanel();
0625: JComponent button = new JButton();
0626: JTextField editor = new JTextField();
0627: KeyEvent event1 = new KeyEvent(editor, KeyEvent.KEY_PRESSED, 0,
0628: 0, KeyEvent.VK_ENTER, '\n');
0629: KeyEvent event2 = new KeyEvent(editor, KeyEvent.KEY_TYPED, 0,
0630: 0, KeyEvent.VK_UNDEFINED, '\n');
0631: KeyEvent event3 = new KeyEvent(editor, KeyEvent.KEY_RELEASED,
0632: 0, 0, KeyEvent.VK_ENTER, '\n');
0633: KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0634: 0);
0635: button.registerKeyboardAction(action1, keyStroke,
0636: JComponent.WHEN_IN_FOCUSED_WINDOW);
0637: container.add(button);
0638: container.add(editor);
0639: Action action = (Action) editor
0640: .getActionForKeyStroke(keyStroke);
0641: assertFalse(action.isEnabled());
0642: editor.processKeyEvent(event1);
0643: assertFalse(event1.isConsumed());
0644: editor.processKeyEvent(event2);
0645: assertTrue(event2.isConsumed());
0646: editor.processKeyEvent(event3);
0647: assertFalse(event3.isConsumed());
0648: editor.addActionListener(action1);
0649: action = (Action) editor.getActionForKeyStroke(keyStroke);
0650: assertFalse(action.isEnabled());
0651: editor.processKeyEvent(event1);
0652: assertFalse(event1.isConsumed());
0653: }
0654:
0655: /*
0656: * Class under test for String getUIClassID()
0657: */
0658: public void testGetUIClassID() {
0659: JComponent component = new JComponent() {
0660: };
0661: assertEquals("ComponentUI", component.getUIClassID());
0662: }
0663:
0664: /*
0665: * Class under test for void setUI(ComponentUI)
0666: */
0667: public void testSetUI() {
0668: ComponentUI componentUI1 = new BasicPanelUI();
0669: ComponentUI componentUI2 = new BasicPanelUI();
0670: panel = new JPanel();
0671: ((JPanel) panel).getUI().uninstallUI(panel);
0672: panel.setUI(null);
0673: PropertyChangeController changeListener = new PropertyChangeController();
0674: panel.addPropertyChangeListener(changeListener);
0675: panel.setUI(componentUI1);
0676: assertEquals(componentUI1, panel.ui);
0677: changeListener.checkPropertyFired(panel, "UI", null,
0678: componentUI1);
0679: changeListener.reset();
0680: panel.setUI(componentUI2);
0681: changeListener.checkPropertyFired(panel, "UI", componentUI1,
0682: componentUI2);
0683: changeListener.reset();
0684: panel.setUI(componentUI2);
0685: assertFalse(changeListener.isChanged("UI"));
0686: }
0687:
0688: public void testSetVisible() {
0689: panel.setVisible(false);
0690: assertFalse(panel.isVisible());
0691: panel.setVisible(true);
0692: assertTrue(panel.isVisible());
0693: panel.setVisible(false);
0694: assertFalse(panel.isVisible());
0695: }
0696:
0697: public void testSetEnabled() {
0698: panel.setEnabled(true);
0699: class PropertyChangeListenerFalse implements
0700: PropertyChangeListener {
0701: public boolean isChanged = false;
0702:
0703: public void propertyChange(final PropertyChangeEvent evt) {
0704: if ("enabled".equals(evt.getPropertyName())
0705: && (evt.getNewValue() != null)) {
0706: assertTrue(evt.getNewValue().equals(Boolean.FALSE));
0707: isChanged = true;
0708: }
0709: }
0710: }
0711: ;
0712: class PropertyChangeListenerTrue implements
0713: PropertyChangeListener {
0714: public void propertyChange(final PropertyChangeEvent evt) {
0715: if ("enabled".equals(evt.getPropertyName())
0716: && (evt.getNewValue() != null)) {
0717: assertTrue(evt.getNewValue().equals(Boolean.TRUE));
0718: }
0719: }
0720: }
0721: ;
0722: PropertyChangeListenerFalse changeListenerFalse = new PropertyChangeListenerFalse();
0723: PropertyChangeListenerTrue changeListenerTrue = new PropertyChangeListenerTrue();
0724: panel.addPropertyChangeListener(changeListenerFalse);
0725: panel.setEnabled(false);
0726: assertFalse(panel.isEnabled());
0727: assertTrue(changeListenerFalse.isChanged);
0728: panel.removePropertyChangeListener(changeListenerFalse);
0729: panel.addPropertyChangeListener(changeListenerTrue);
0730: panel.setEnabled(true);
0731: assertTrue(panel.isEnabled());
0732: assertTrue(changeListenerFalse.isChanged);
0733: changeListenerFalse.isChanged = false;
0734: panel.setEnabled(true);
0735: assertTrue(panel.isEnabled());
0736: assertFalse(changeListenerFalse.isChanged);
0737: }
0738:
0739: public void testSetOpaque() {
0740: panel.setOpaque(false);
0741: assertFalse("now JPanel is not opaque ", panel.isOpaque());
0742: panel = new JRootPane();
0743: panel.setOpaque(true);
0744: assertTrue("now JRootPane is opaque ", panel.isOpaque());
0745: }
0746:
0747: public void testIsOpaque() {
0748: assertFalse("JComponent isn't opaque ", panel.isOpaque());
0749: panel = new JPanel();
0750: assertTrue("JPanel is opaque ", panel.isOpaque());
0751: panel = new JRootPane();
0752: assertFalse("JRootPane is not opaque ", panel.isOpaque());
0753: }
0754:
0755: public void testSetBorder() {
0756: final Border border1 = BorderFactory.createEmptyBorder(30, 30,
0757: 30, 30);
0758: final Border border2 = BorderFactory.createEmptyBorder(10, 10,
0759: 10, 10);
0760: class PropertyChangeListenerBorder1 implements
0761: PropertyChangeListener {
0762: public boolean isChanged = false;
0763:
0764: public void propertyChange(final PropertyChangeEvent evt) {
0765: if ("border".equals(evt.getPropertyName())
0766: && (evt.getNewValue() != null)) {
0767: assertTrue(evt.getNewValue().equals(border1));
0768: isChanged = true;
0769: }
0770: }
0771: }
0772: ;
0773: class PropertyChangeListenerBorder2 implements
0774: PropertyChangeListener {
0775: public boolean isChanged = false;
0776:
0777: public void propertyChange(final PropertyChangeEvent evt) {
0778: if ("border".equals(evt.getPropertyName())
0779: && (evt.getNewValue() != null)) {
0780: assertTrue(evt.getNewValue().equals(border2));
0781: isChanged = true;
0782: }
0783: }
0784: }
0785: ;
0786: PropertyChangeController changeListener = new PropertyChangeController();
0787: panel.addPropertyChangeListener(changeListener);
0788: assertNull(panel.getBorder());
0789: Border newBorder1 = new EmptyBorder(10, 10, 10, 10);
0790: Border newBorder2 = new EmptyBorder(20, 20, 20, 20);
0791: panel.setBorder(newBorder1);
0792: assertSame(newBorder1, panel.getBorder());
0793: changeListener.checkPropertyFired(panel, "border", null,
0794: newBorder1);
0795: changeListener.reset();
0796: panel.setBorder(newBorder2);
0797: assertSame(newBorder2, panel.getBorder());
0798: changeListener.checkPropertyFired(panel, "border", newBorder1,
0799: newBorder2);
0800: changeListener.reset();
0801: panel.setBorder(newBorder2);
0802: assertTrue(panel.getBorder() == newBorder2);
0803: assertFalse(changeListener.isChanged());
0804: changeListener.reset();
0805: panel.setBorder(null);
0806: PropertyChangeListenerBorder1 changeListener1 = new PropertyChangeListenerBorder1();
0807: PropertyChangeListenerBorder2 changeListener2 = new PropertyChangeListenerBorder2();
0808: panel.addPropertyChangeListener(changeListener1);
0809: panel.setBorder(border1);
0810: assertTrue(panel.getBorder().equals(border1));
0811: assertTrue(changeListener1.isChanged);
0812: panel.removePropertyChangeListener(changeListener1);
0813: panel.addPropertyChangeListener(changeListener2);
0814: panel.setBorder(border2);
0815: assertTrue(panel.getBorder().equals(border2));
0816: assertTrue(changeListener2.isChanged);
0817: changeListener2.isChanged = false;
0818: panel.setBorder(border2);
0819: assertTrue(panel.getBorder().equals(border2));
0820: assertFalse(changeListener2.isChanged);
0821: }
0822:
0823: public void testGetBorder() {
0824: assertNull(panel.getBorder());
0825: }
0826:
0827: public void testGetAlignmentX() {
0828: assertEquals("alignment ", panel.getAlignmentX(), 0.5f, 1e-5);
0829: }
0830:
0831: public void testSetAlignmentX() {
0832: float value = 0.111f;
0833: panel.setAlignmentX(value);
0834: assertEquals("alignment ", value, panel.getAlignmentX(), 1e-5);
0835: value = 2.5f;
0836: panel.setAlignmentX(value);
0837: assertEquals("alignment ", 1.0f, panel.getAlignmentX(), 1e-5);
0838: value = -2.5f;
0839: panel.setAlignmentX(value);
0840: assertEquals("alignment ", 0.0f, panel.getAlignmentX(), 1e-5);
0841: }
0842:
0843: public void testGetAlignmentY() {
0844: assertEquals("alignment ", panel.getAlignmentY(), 0.5f, 1e-5);
0845: }
0846:
0847: public void testSetAlignmentY() {
0848: float value = 0.111f;
0849: panel.setAlignmentY(value);
0850: assertEquals("alignment ", value, panel.getAlignmentY(), 1e-5);
0851: value = 2.5f;
0852: panel.setAlignmentY(value);
0853: assertEquals("alignment ", 1.0f, panel.getAlignmentY(), 1e-5);
0854: value = -2.5f;
0855: panel.setAlignmentY(value);
0856: assertEquals("alignment ", 0.0f, panel.getAlignmentY(), 1e-5);
0857: }
0858:
0859: /*
0860: * Class under test for void enable()
0861: */
0862: public void testEnable() {
0863: panel.setEnabled(true);
0864: assertTrue("panel is enabled now ", panel.isEnabled());
0865: panel.setEnabled(false);
0866: assertFalse("panel is disabled now ", panel.isEnabled());
0867: panel.setEnabled(true);
0868: assertTrue("panel is enabled now ", panel.isEnabled());
0869: }
0870:
0871: public void testDisable() {
0872: panel.setEnabled(false);
0873: assertFalse("panel is disabled now ", panel.isEnabled());
0874: panel.setEnabled(true);
0875: assertTrue("panel is enabled now ", panel.isEnabled());
0876: panel.setEnabled(false);
0877: assertFalse("panel is disabled now ", panel.isEnabled());
0878: }
0879:
0880: public void testIsDoubleBuffered() {
0881: assertFalse("JComponent isn't DoubleBuffered", panel
0882: .isDoubleBuffered());
0883: panel = new JPanel();
0884: assertTrue("JPanel is DoubleBuffered", panel.isDoubleBuffered());
0885: panel = new JRootPane();
0886: assertTrue("JRootPane is DoubleBuffered", panel
0887: .isDoubleBuffered());
0888: }
0889:
0890: public void testFireVetoableChange() throws PropertyVetoException {
0891: ConcreteVetoableChangeListener changeListener = new ConcreteVetoableChangeListener();
0892: VetoableChangeListener[] listenersArray = null;
0893: listenersArray = panel.getVetoableChangeListeners();
0894: assertTrue(listenersArray != null && listenersArray.length == 0);
0895: panel.addVetoableChangeListener(changeListener);
0896: JPanel button1 = new JPanel();
0897: JPanel button2 = new JPanel();
0898: panel.fireVetoableChange("button", button1, button2);
0899: assertTrue("button".equals(changeListener.valueChangedKey));
0900: assertTrue(button1.equals(changeListener.valueChangedOld));
0901: assertTrue(button2.equals(changeListener.valueChangedNew));
0902: }
0903:
0904: /*
0905: * Class under test for void firePropertyChange(String, short, short)
0906: */
0907: public void testFirePropertyChangeStringshortshort() {
0908: PropertyChangeController changeListener = new PropertyChangeController();
0909: panel.addPropertyChangeListener(changeListener);
0910: short oldValue = 100;
0911: short newValue = 200;
0912: panel.firePropertyChange("short", oldValue, newValue);
0913: changeListener.checkPropertyFired(panel, "short", new Short(
0914: oldValue), new Short(newValue));
0915: changeListener.reset();
0916: panel.firePropertyChange("short", (short) 1, (short) 1);
0917: assertFalse(changeListener.isChanged());
0918: }
0919:
0920: /*
0921: * Class under test for void firePropertyChange(String, long, long)
0922: */
0923: public void testFirePropertyChangeStringlonglong() {
0924: PropertyChangeController changeListener = new PropertyChangeController();
0925: panel.addPropertyChangeListener(changeListener);
0926: long oldValue = 100;
0927: long newValue = 200;
0928: panel.firePropertyChange("long", oldValue, newValue);
0929: changeListener.checkLastPropertyFired(panel, "long", new Long(
0930: oldValue), new Long(newValue));
0931: changeListener.reset();
0932: panel.firePropertyChange("int", 1L, 1L);
0933: assertFalse(changeListener.isChanged());
0934: }
0935:
0936: /*
0937: * Class under test for void firePropertyChange(String, int, int)
0938: */
0939: public void testFirePropertyChangeStringintint() {
0940: PropertyChangeController changeListener = new PropertyChangeController();
0941: panel.addPropertyChangeListener(changeListener);
0942: int oldValue = 100;
0943: int newValue = 200;
0944: panel.firePropertyChange("int", oldValue, newValue);
0945: changeListener.checkLastPropertyFired(panel, "int",
0946: new Integer(oldValue), new Integer(newValue));
0947: changeListener.reset();
0948: panel.firePropertyChange("int", 1, 1);
0949: assertFalse(changeListener.isChanged());
0950: }
0951:
0952: /*
0953: * Class under test for void firePropertyChange(String, float, float)
0954: */
0955: public void testFirePropertyChangeStringfloatfloat() {
0956: PropertyChangeController changeListener = new PropertyChangeController();
0957: panel.addPropertyChangeListener(changeListener);
0958: float oldValue = 100.01f;
0959: float newValue = 200.01f;
0960: panel.firePropertyChange("float", oldValue, newValue);
0961: changeListener.checkLastPropertyFired(panel, "float",
0962: new Float(oldValue), new Float(newValue));
0963: changeListener.reset();
0964: panel.firePropertyChange("float", 1.0f, 1.0f);
0965: assertFalse(changeListener.isChanged());
0966: }
0967:
0968: /*
0969: * Class under test for void firePropertyChange(String, double, double)
0970: */
0971: public void testFirePropertyChangeStringdoubledouble() {
0972: PropertyChangeController changeListener = new PropertyChangeController();
0973: panel.addPropertyChangeListener(changeListener);
0974: double oldValue = 100.1;
0975: double newValue = 200.1;
0976: panel.firePropertyChange("double", oldValue, newValue);
0977: changeListener.checkLastPropertyFired(panel, "double",
0978: new Double(oldValue), new Double(newValue));
0979: changeListener.reset();
0980: panel.firePropertyChange("double", 1.0, 1);
0981: assertFalse(changeListener.isChanged());
0982: }
0983:
0984: /*
0985: * Class under test for void firePropertyChange(String, char, char)
0986: */
0987: public void testFirePropertyChangeStringcharchar() {
0988: PropertyChangeController changeListener = new PropertyChangeController();
0989: panel.addPropertyChangeListener(changeListener);
0990: char oldValue = 'a';
0991: char newValue = 'b';
0992: panel.firePropertyChange("char", oldValue, newValue);
0993: changeListener.checkLastPropertyFired(panel, "char",
0994: new Character(oldValue), new Character(newValue));
0995: changeListener.reset();
0996: panel.firePropertyChange("char", 'h', 'h');
0997: assertFalse(changeListener.isChanged());
0998: }
0999:
1000: /*
1001: * Class under test for void firePropertyChange(String, byte, byte)
1002: */
1003: public void testFirePropertyChangeStringbytebyte() {
1004: PropertyChangeController changeListener = new PropertyChangeController();
1005: panel.addPropertyChangeListener(changeListener);
1006: byte oldValue = 66;
1007: byte newValue = 13;
1008: panel.firePropertyChange("byte", oldValue, newValue);
1009: changeListener.checkLastPropertyFired(panel, "byte", new Byte(
1010: oldValue), new Byte(newValue));
1011: changeListener.reset();
1012: panel.firePropertyChange("byte", (byte) 2, (byte) 2);
1013: assertFalse(changeListener.isChanged());
1014: }
1015:
1016: /*
1017: * Class under test for EventListener[] getListeners(Class)
1018: */
1019: public void testGetListenersClass1() {
1020: PropertyChangeController changeListener1 = new PropertyChangeController();
1021: PropertyChangeController changeListener2 = new PropertyChangeController();
1022: class ConcreteAncestorListener implements AncestorListener {
1023: public void ancestorAdded(final AncestorEvent event) {
1024: }
1025:
1026: public void ancestorMoved(final AncestorEvent event) {
1027: }
1028:
1029: public void ancestorRemoved(final AncestorEvent event) {
1030: }
1031: }
1032: ;
1033: AncestorListener ancestorListener1 = new ConcreteAncestorListener();
1034: AncestorListener ancestorListener2 = new ConcreteAncestorListener();
1035: VetoableChangeListener vetoableChangeListener = new VetoableChangeListener() {
1036: public void vetoableChange(final PropertyChangeEvent evt) {
1037: }
1038: };
1039: EventListener[] listenersArray = null;
1040: removeListeners(panel, PropertyChangeListener.class);
1041: listenersArray = panel
1042: .getListeners(VetoableChangeListener.class);
1043: assertEquals(0, listenersArray.length);
1044: listenersArray = panel.getListeners(AncestorListener.class);
1045: assertEquals(0, listenersArray.length);
1046: panel.addPropertyChangeListener(changeListener1);
1047: panel.addVetoableChangeListener(vetoableChangeListener);
1048: panel.addPropertyChangeListener(changeListener2);
1049: panel.addPropertyChangeListener(changeListener2);
1050: listenersArray = panel
1051: .getListeners(PropertyChangeListener.class);
1052: assertEquals(3, listenersArray.length);
1053: panel.removePropertyChangeListener(changeListener2);
1054: panel.removePropertyChangeListener(changeListener2);
1055: listenersArray = panel
1056: .getListeners(PropertyChangeListener.class);
1057: assertEquals(1, listenersArray.length);
1058: assertTrue(changeListener1.findMe(listenersArray) == 1);
1059: panel.addAncestorListener(ancestorListener1);
1060: panel.addAncestorListener(ancestorListener2);
1061: listenersArray = panel
1062: .getListeners(PropertyChangeListener.class);
1063: assertEquals(1, listenersArray.length);
1064: listenersArray = panel
1065: .getListeners(VetoableChangeListener.class);
1066: assertEquals(1, listenersArray.length);
1067: listenersArray = panel.getListeners(AncestorListener.class);
1068: assertEquals(2, listenersArray.length);
1069: panel.removeVetoableChangeListener(vetoableChangeListener);
1070: listenersArray = panel
1071: .getListeners(VetoableChangeListener.class);
1072: assertTrue(listenersArray.length == 0);
1073: panel.addAncestorListener(ancestorListener2);
1074: assertEquals("MouseListeners", 0, panel
1075: .getListeners(MouseListener.class).length);
1076: panel.addMouseListener(new MouseAdapter() {
1077: });
1078: assertEquals("MouseListeners", 1, panel
1079: .getListeners(MouseListener.class).length);
1080: }
1081:
1082: /*
1083: * Class under test for EventListener[] getListeners(Class)
1084: */
1085: public void testGetListenersClass2() {
1086: PropertyChangeController changeListener1 = new PropertyChangeController();
1087: PropertyChangeController changeListener2 = new PropertyChangeController();
1088: EventListener[] listenersArray = null;
1089: int initialNumber = panel
1090: .getListeners(PropertyChangeListener.class).length;
1091: panel.addPropertyChangeListener(changeListener1);
1092: panel.addPropertyChangeListener(changeListener2);
1093: panel.addPropertyChangeListener(changeListener2);
1094: panel.addPropertyChangeListener("first", changeListener2);
1095: panel.addPropertyChangeListener("first", changeListener2);
1096: panel.addPropertyChangeListener("first", changeListener1);
1097: panel.addPropertyChangeListener("second", changeListener1);
1098: listenersArray = panel
1099: .getListeners(PropertyChangeListener.class);
1100: assertEquals(7 + initialNumber, listenersArray.length);
1101: panel.removePropertyChangeListener(changeListener2);
1102: panel.removePropertyChangeListener(changeListener2);
1103: panel.removePropertyChangeListener(changeListener2);
1104: listenersArray = panel
1105: .getListeners(PropertyChangeListener.class);
1106: assertEquals(5 + initialNumber, listenersArray.length);
1107: panel.removePropertyChangeListener("second", changeListener2);
1108: panel.removePropertyChangeListener("first", changeListener2);
1109: panel.removePropertyChangeListener("first", changeListener2);
1110: listenersArray = panel
1111: .getListeners(PropertyChangeListener.class);
1112: assertEquals(3 + initialNumber, listenersArray.length);
1113: }
1114:
1115: public void testPutClientProperty() {
1116: PropertyChangeController changeListener = new PropertyChangeController();
1117: panel.addPropertyChangeListener(changeListener);
1118: Object value1 = "property1";
1119: Object value2 = "property2";
1120: String key1 = "value1";
1121: assertNull(panel.getClientProperty(key1));
1122: assertFalse("event's not fired", changeListener.isChanged());
1123: panel.putClientProperty(key1, value1);
1124: changeListener
1125: .checkLastPropertyFired(panel, key1, null, value1);
1126: assertTrue(panel.getClientProperty(key1).equals(value1));
1127: changeListener.reset();
1128: panel.putClientProperty(key1, value2);
1129: changeListener.checkLastPropertyFired(panel, key1, value1,
1130: value2);
1131: assertTrue(panel.getClientProperty(key1).equals(value2));
1132: changeListener.reset();
1133: panel.putClientProperty(key1, null);
1134: changeListener
1135: .checkLastPropertyFired(panel, key1, value2, null);
1136: assertNull(panel.getClientProperty(key1));
1137: changeListener.reset();
1138:
1139: try {
1140: JComponent jc = new JComponent() {
1141: };
1142: jc.putClientProperty(null, new Object());
1143: fail("NPE should be thrown");
1144: } catch (NullPointerException npe) {
1145: // PASSED
1146: }
1147: }
1148:
1149: /*
1150: * Class under test for void removePropertyChangeListener(PropertyChangeListener)
1151: */
1152: public void testRemovePropertyChangeListenerPropertyChangeListener() {
1153: PropertyChangeController changeListener1 = new PropertyChangeController();
1154: PropertyChangeController changeListener2 = new PropertyChangeController();
1155: PropertyChangeController changeListener3 = new PropertyChangeController();
1156: PropertyChangeController changeListener4 = new PropertyChangeController();
1157: PropertyChangeListener[] listenersArray = null;
1158: int initialNumber = panel.getPropertyChangeListeners().length;
1159: listenersArray = panel.getPropertyChangeListeners("first");
1160: assertTrue(listenersArray.length == 0);
1161: listenersArray = panel.getPropertyChangeListeners("second");
1162: assertTrue(listenersArray.length == 0);
1163: panel.addPropertyChangeListener(changeListener1);
1164: panel.addPropertyChangeListener("first", changeListener2);
1165: listenersArray = panel.getPropertyChangeListeners("first");
1166: assertEquals(1, listenersArray.length);
1167: listenersArray = panel.getPropertyChangeListeners();
1168: assertEquals(initialNumber + 2, listenersArray.length);
1169: panel.removePropertyChangeListener("first", changeListener1);
1170: listenersArray = panel.getPropertyChangeListeners("first");
1171: assertEquals(1, listenersArray.length);
1172: listenersArray = panel.getPropertyChangeListeners();
1173: assertEquals(initialNumber + 2, listenersArray.length);
1174: panel.removePropertyChangeListener(changeListener1);
1175: listenersArray = panel.getPropertyChangeListeners();
1176: assertEquals(initialNumber + 1, listenersArray.length);
1177: assertFalse(changeListener1.findMe(listenersArray) > 0);
1178: panel.removePropertyChangeListener(changeListener2);
1179: listenersArray = panel.getPropertyChangeListeners();
1180: assertEquals(initialNumber + 1, listenersArray.length);
1181: panel.removePropertyChangeListener("first", changeListener2);
1182: listenersArray = panel.getPropertyChangeListeners();
1183: assertEquals(initialNumber, listenersArray.length);
1184: panel.addPropertyChangeListener("first", changeListener1);
1185: panel.addPropertyChangeListener(changeListener2);
1186: panel.addPropertyChangeListener("second", changeListener3);
1187: panel.addPropertyChangeListener(changeListener4);
1188: panel.removePropertyChangeListener("asd", null);
1189: listenersArray = panel.getPropertyChangeListeners("second");
1190: assertEquals(1, listenersArray.length);
1191: panel.removePropertyChangeListener(changeListener1);
1192: listenersArray = panel.getPropertyChangeListeners();
1193: assertEquals(initialNumber + 4, listenersArray.length);
1194: panel.removePropertyChangeListener(changeListener2);
1195: listenersArray = panel.getPropertyChangeListeners();
1196: assertEquals(initialNumber + 3, listenersArray.length);
1197: panel.removePropertyChangeListener(changeListener4);
1198: listenersArray = panel.getPropertyChangeListeners();
1199: assertEquals(initialNumber + 2, listenersArray.length);
1200: panel.removePropertyChangeListener(changeListener3);
1201: listenersArray = panel.getPropertyChangeListeners();
1202: assertEquals(initialNumber + 2, listenersArray.length);
1203: }
1204:
1205: /*
1206: * Class under test for void addPropertyChangeListener(PropertyChangeListener)
1207: */
1208: public void testAddPropertyChangeListenerPropertyChangeListener() {
1209: PropertyChangeController changeListener1 = new PropertyChangeController();
1210: PropertyChangeController changeListener2 = new PropertyChangeController();
1211: PropertyChangeListener[] listenersArray = null;
1212: panel.addPropertyChangeListener(changeListener1);
1213: listenersArray = panel.getPropertyChangeListeners();
1214: assertEquals(1, changeListener1.findMe(listenersArray));
1215: assertEquals(0, panel.listenerList
1216: .getListeners(PropertyChangeListener.class).length);
1217: panel.addPropertyChangeListener(changeListener2);
1218: listenersArray = panel.getPropertyChangeListeners();
1219: assertEquals(1, changeListener1.findMe(listenersArray));
1220: assertEquals(1, changeListener2.findMe(listenersArray));
1221: panel.addPropertyChangeListener(changeListener2);
1222: listenersArray = panel.getPropertyChangeListeners();
1223: assertEquals(1, changeListener1.findMe(listenersArray));
1224: assertEquals(2, changeListener2.findMe(listenersArray));
1225: }
1226:
1227: /*
1228: * Class under test for PropertyChangeListener[] getPropertyChangeListeners()
1229: */
1230: public void testGetPropertyChangeListeners() {
1231: PropertyChangeController changeListener1 = new PropertyChangeController();
1232: PropertyChangeController changeListener2 = new PropertyChangeController();
1233: PropertyChangeListener[] listenersArray = null;
1234: listenersArray = panel.getPropertyChangeListeners();
1235: int initialNumber = listenersArray.length;
1236: panel.addPropertyChangeListener(changeListener1);
1237: listenersArray = panel.getPropertyChangeListeners();
1238: assertEquals(initialNumber + 1, listenersArray.length);
1239: assertTrue(changeListener1.findMe(listenersArray) == 1);
1240: panel.addPropertyChangeListener(changeListener2);
1241: listenersArray = panel.getPropertyChangeListeners();
1242: assertEquals(initialNumber + 2, listenersArray.length);
1243: assertTrue(changeListener1.findMe(listenersArray) == 1);
1244: assertTrue(changeListener2.findMe(listenersArray) == 1);
1245: }
1246:
1247: /*
1248: * Class under test for void removePropertyChangeListener(String, PropertyChangeListener)
1249: */
1250: public void testRemovePropertyChangeListenerStringPropertyChangeListener() {
1251: PropertyChangeController changeListener1 = new PropertyChangeController();
1252: PropertyChangeController changeListener2 = new PropertyChangeController();
1253: PropertyChangeController changeListener3 = new PropertyChangeController();
1254: PropertyChangeController changeListener4 = new PropertyChangeController();
1255: PropertyChangeListener[] listenersArray = null;
1256: listenersArray = panel.getPropertyChangeListeners("first");
1257: assertTrue(listenersArray.length == 0);
1258: listenersArray = panel.getPropertyChangeListeners("second");
1259: assertTrue(listenersArray.length == 0);
1260: panel.addPropertyChangeListener("first", changeListener1);
1261: panel.addPropertyChangeListener("first", changeListener2);
1262: listenersArray = panel.getPropertyChangeListeners("first");
1263: assertTrue(listenersArray.length == 2);
1264: panel.removePropertyChangeListener("first", changeListener2);
1265: listenersArray = panel.getPropertyChangeListeners("first");
1266: assertTrue(listenersArray.length == 1);
1267: assertTrue(changeListener1.findMe(listenersArray) == 1);
1268: assertFalse(changeListener2.findMe(listenersArray) > 0);
1269: panel.removePropertyChangeListener("first", changeListener1);
1270: listenersArray = panel.getPropertyChangeListeners("first");
1271: assertTrue(listenersArray.length == 0);
1272: assertFalse(changeListener1.findMe(listenersArray) > 0);
1273: assertFalse(changeListener2.findMe(listenersArray) > 0);
1274: panel.addPropertyChangeListener("second", changeListener2);
1275: panel.addPropertyChangeListener("second", changeListener3);
1276: panel.addPropertyChangeListener("second", changeListener4);
1277: listenersArray = panel.getPropertyChangeListeners("second");
1278: assertTrue(listenersArray.length == 3);
1279: panel.removePropertyChangeListener("second", changeListener3);
1280: listenersArray = panel.getPropertyChangeListeners("second");
1281: assertTrue(listenersArray.length == 2);
1282: assertTrue(changeListener2.findMe(listenersArray) == 1);
1283: assertFalse(changeListener3.findMe(listenersArray) > 0);
1284: assertTrue(changeListener4.findMe(listenersArray) == 1);
1285: panel.removePropertyChangeListener("second", changeListener2);
1286: panel.addPropertyChangeListener("second", changeListener3);
1287: listenersArray = panel.getPropertyChangeListeners("second");
1288: assertTrue(listenersArray.length == 2);
1289: assertFalse(changeListener2.findMe(listenersArray) > 0);
1290: assertTrue(changeListener3.findMe(listenersArray) == 1);
1291: assertTrue(changeListener4.findMe(listenersArray) == 1);
1292: }
1293:
1294: /*
1295: * Class under test for void addPropertyChangeListener(String, PropertyChangeListener)
1296: */
1297: public void testAddPropertyChangeListenerStringPropertyChangeListener()
1298: throws SecurityException, NoSuchMethodException,
1299: IllegalArgumentException, IllegalAccessException,
1300: InvocationTargetException {
1301: PropertyChangeController changeListener1 = new PropertyChangeController();
1302: PropertyChangeController changeListener2 = new PropertyChangeController();
1303: panel.addPropertyChangeListener("first", changeListener1);
1304: panel.addPropertyChangeListener("second", changeListener2);
1305: String oldValue = "old";
1306: String newValue = "new";
1307: Method method = Component.class.getDeclaredMethod(
1308: "firePropertyChange", new Class[] { String.class,
1309: Object.class, Object.class });
1310: if (method != null) {
1311: method.setAccessible(true);
1312: } else {
1313: fail("access error");
1314: }
1315: method.invoke(panel,
1316: new Object[] { "first", oldValue, newValue });
1317: changeListener1.checkLastPropertyFired(panel, "first",
1318: oldValue, newValue);
1319: assertFalse("event's not fired", changeListener2.isChanged());
1320: changeListener1.reset();
1321: changeListener2.reset();
1322: method.invoke(panel, new Object[] { "second", oldValue,
1323: newValue });
1324: changeListener2.checkLastPropertyFired(panel, "second",
1325: oldValue, newValue);
1326: assertFalse("event's not fired", changeListener1.isChanged());
1327: changeListener1.reset();
1328: changeListener2.reset();
1329: panel.addPropertyChangeListener("first", changeListener2);
1330: method.invoke(panel,
1331: new Object[] { "first", oldValue, newValue });
1332: changeListener1.checkLastPropertyFired(panel, "first",
1333: oldValue, newValue);
1334: changeListener2.checkLastPropertyFired(panel, "first",
1335: oldValue, newValue);
1336: }
1337:
1338: /*
1339: * Class under test for PropertyChangeListener[] getPropertyChangeListeners(String)
1340: */
1341: public void testGetPropertyChangeListenersString() {
1342: PropertyChangeController changeListener1 = new PropertyChangeController();
1343: PropertyChangeController changeListener2 = new PropertyChangeController();
1344: PropertyChangeController changeListener3 = new PropertyChangeController();
1345: PropertyChangeController changeListener4 = new PropertyChangeController();
1346: PropertyChangeListener[] listenersArray = null;
1347: listenersArray = panel.getPropertyChangeListeners("first");
1348: assertTrue(listenersArray.length == 0);
1349: listenersArray = panel.getPropertyChangeListeners("second");
1350: assertTrue(listenersArray.length == 0);
1351: panel.addPropertyChangeListener("first", changeListener1);
1352: panel.addPropertyChangeListener("first", changeListener2);
1353: listenersArray = panel.getPropertyChangeListeners("first");
1354: assertTrue(listenersArray.length == 2);
1355: assertTrue(changeListener1.findMe(listenersArray) == 1);
1356: assertTrue(changeListener2.findMe(listenersArray) == 1);
1357: panel.addPropertyChangeListener("second", changeListener2);
1358: panel.addPropertyChangeListener("second", changeListener3);
1359: panel.addPropertyChangeListener("second", changeListener4);
1360: listenersArray = panel.getPropertyChangeListeners("second");
1361: assertTrue(listenersArray.length == 3);
1362: assertTrue(changeListener2.findMe(listenersArray) == 1);
1363: assertTrue(changeListener3.findMe(listenersArray) == 1);
1364: assertTrue(changeListener4.findMe(listenersArray) == 1);
1365: listenersArray = panel.getPropertyChangeListeners("first");
1366: assertTrue(listenersArray.length == 2);
1367: assertTrue(changeListener1.findMe(listenersArray) == 1);
1368: assertTrue(changeListener2.findMe(listenersArray) == 1);
1369: }
1370:
1371: public void testGetComponentGraphics() {
1372: JWindow window = new JWindow();
1373: window.setVisible(true);
1374: Graphics g = window.getGraphics();
1375: Graphics componentGraphics = null;
1376: Font font = new Font(null, Font.BOLD, 10);
1377: Color color = Color.RED;
1378: panel.setFont(font);
1379: panel.setForeground(color);
1380: componentGraphics = panel.getComponentGraphics(g);
1381: assertTrue("graphics object's created ",
1382: componentGraphics != null);
1383: assertEquals("graphics object's created properly", font,
1384: componentGraphics.getFont());
1385: assertEquals("graphics object's created properly", color,
1386: componentGraphics.getColor());
1387: panel.setDebugGraphicsOptions(DebugGraphics.FLASH_OPTION);
1388: componentGraphics = panel.getComponentGraphics(g);
1389: assertTrue("graphics object's created ",
1390: componentGraphics != null);
1391: if (isHarmony()) {
1392: assertTrue("Debug graphics is created",
1393: componentGraphics instanceof DebugGraphics);
1394: }
1395: assertEquals("graphics object's created properly", font,
1396: componentGraphics.getFont());
1397: assertEquals("graphics object's created properly", color,
1398: componentGraphics.getColor());
1399: }
1400:
1401: public void testRemoveAncestorListener() {
1402: class ConcreteAncestorListener implements AncestorListener {
1403: public void ancestorAdded(final AncestorEvent event) {
1404: }
1405:
1406: public void ancestorMoved(final AncestorEvent event) {
1407: }
1408:
1409: public void ancestorRemoved(final AncestorEvent event) {
1410: }
1411: }
1412: ;
1413: AncestorListener ancestorListener1 = new ConcreteAncestorListener();
1414: AncestorListener ancestorListener2 = new ConcreteAncestorListener();
1415: AncestorListener ancestorListener3 = new ConcreteAncestorListener();
1416: EventListener[] listenersArray = null;
1417: listenersArray = panel.getAncestorListeners();
1418: assertTrue(listenersArray.length == 0);
1419: panel.addAncestorListener(ancestorListener1);
1420: panel.addAncestorListener(ancestorListener2);
1421: panel.addAncestorListener(ancestorListener2);
1422: listenersArray = panel.getAncestorListeners();
1423: assertTrue(listenersArray.length == 3);
1424: panel.removeAncestorListener(ancestorListener1);
1425: panel.addAncestorListener(ancestorListener3);
1426: panel.addAncestorListener(ancestorListener3);
1427: listenersArray = panel.getAncestorListeners();
1428: assertTrue(listenersArray.length == 4);
1429: panel.removeAncestorListener(ancestorListener3);
1430: panel.removeAncestorListener(ancestorListener3);
1431: listenersArray = panel.getAncestorListeners();
1432: assertTrue(listenersArray.length == 2);
1433: panel.removeAncestorListener(ancestorListener2);
1434: panel.removeAncestorListener(ancestorListener2);
1435: listenersArray = panel.getAncestorListeners();
1436: assertTrue(listenersArray.length == 0);
1437: }
1438:
1439: // this function is tested by testGetAncestorListeners() and
1440: // testRemoveAncestorListener()
1441: public void testAddAncestorListener() {
1442: }
1443:
1444: public void testGetAncestorListeners() {
1445: class ConcreteAncestorListener implements AncestorListener {
1446: public void ancestorAdded(final AncestorEvent event) {
1447: }
1448:
1449: public void ancestorMoved(final AncestorEvent event) {
1450: }
1451:
1452: public void ancestorRemoved(final AncestorEvent event) {
1453: }
1454: }
1455: ;
1456: AncestorListener ancestorListener1 = new ConcreteAncestorListener();
1457: AncestorListener ancestorListener2 = new ConcreteAncestorListener();
1458: AncestorListener ancestorListener3 = new ConcreteAncestorListener();
1459: EventListener[] listenersArray = null;
1460: listenersArray = panel.getListeners(AncestorListener.class);
1461: assertTrue(listenersArray.length == 0);
1462: listenersArray = panel.getAncestorListeners();
1463: assertTrue(listenersArray.length == 0);
1464: panel.addAncestorListener(ancestorListener1);
1465: panel.addAncestorListener(ancestorListener2);
1466: listenersArray = panel.getListeners(AncestorListener.class);
1467: assertTrue(listenersArray.length == 2);
1468: listenersArray = panel.getAncestorListeners();
1469: assertTrue(listenersArray.length == 2);
1470: panel.addAncestorListener(ancestorListener3);
1471: panel.addAncestorListener(ancestorListener2);
1472: listenersArray = panel.getListeners(AncestorListener.class);
1473: assertTrue(listenersArray.length == 4);
1474: listenersArray = panel.getAncestorListeners();
1475: assertTrue(listenersArray.length == 4);
1476: }
1477:
1478: public void testSetTransferHandler() {
1479: PropertyChangeController changeListener = new PropertyChangeController();
1480: panel.addPropertyChangeListener(changeListener);
1481: JComponent panel1 = new JPanel();
1482: JComponent panel2 = new JPanel();
1483: TransferHandler handler1 = new TransferHandler("1");
1484: TransferHandler handler2 = new TransferHandler("2");
1485: panel.setTransferHandler(handler1);
1486: changeListener.checkLastPropertyFired(panel, "transferHandler",
1487: null, handler1);
1488: assertEquals("transferHandler's set properly ", handler1, panel
1489: .getTransferHandler());
1490: changeListener.reset();
1491: panel.setTransferHandler(handler2);
1492: changeListener.checkLastPropertyFired(panel, "transferHandler",
1493: handler1, handler2);
1494: assertEquals("transferHandler's set properly ", handler2, panel
1495: .getTransferHandler());
1496: changeListener.reset();
1497: panel.setTransferHandler(handler2);
1498: assertFalse("event's not fired", changeListener.isChanged());
1499: assertEquals("transferHandler's set properly ", handler2, panel
1500: .getTransferHandler());
1501: changeListener.reset();
1502: System.setProperty("suppressSwingDropSupport", "false");
1503: panel1.setTransferHandler(handler1);
1504: assertNotNull("DropTarget is installed ", panel1
1505: .getDropTarget());
1506: assertEquals("DropTarget is installed properly ", panel1
1507: .getDropTarget().getComponent(), panel1);
1508: assertEquals("transferHandler's set properly ", handler1,
1509: panel1.getTransferHandler());
1510: System.setProperty("suppressSwingDropSupport", "true");
1511: panel2.setTransferHandler(handler2);
1512: if (isHarmony()) {
1513: assertNull("DropTarget is not installed ", panel2
1514: .getDropTarget());
1515: } else {
1516: assertNotNull("DropTarget is installed ", panel2
1517: .getDropTarget());
1518: assertEquals("transferHandler's set properly ", handler2,
1519: panel2.getTransferHandler());
1520: }
1521: }
1522:
1523: public void testGetTransferHandler() {
1524: JComponent panel1 = new JPanel();
1525: JComponent panel2 = new JButton();
1526: TransferHandler handler1 = new TransferHandler("1");
1527: TransferHandler handler2 = new TransferHandler("1");
1528: assertNull("transferHandler is not set by default ", panel
1529: .getTransferHandler());
1530: panel1.setTransferHandler(handler1);
1531: assertEquals("transferHandler's set properly ", handler1,
1532: panel1.getTransferHandler());
1533: panel2.setTransferHandler(handler2);
1534: assertEquals("transferHandler's set properly ", handler2,
1535: panel2.getTransferHandler());
1536: }
1537:
1538: /*
1539: * Class under test for void registerKeyboardAction(ActionListener, String, KeyStroke, int)
1540: */
1541: public void testRegisterKeyboardActionActionListenerStringKeyStrokeint() {
1542: ActionListener action1 = new ActionListener() {
1543: public void actionPerformed(final ActionEvent e) {
1544: }
1545: };
1546: ActionListener action2 = new ActionListener() {
1547: public void actionPerformed(final ActionEvent e) {
1548: }
1549: };
1550: ActionListener action3 = new ActionListener() {
1551: public void actionPerformed(final ActionEvent e) {
1552: }
1553: };
1554: String command1 = "new";
1555: String command2 = "delete";
1556: String command3 = "show";
1557: KeyStroke keyStroke1 = KeyStroke.getKeyStroke(
1558: KeyEvent.VK_PAGE_DOWN, 0);
1559: KeyStroke keyStroke2 = KeyStroke.getKeyStroke(
1560: KeyEvent.VK_PAGE_UP, 0);
1561: KeyStroke keyStroke3 = KeyStroke.getKeyStroke(
1562: KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK);
1563: panel.registerKeyboardAction(action3, command3, keyStroke1,
1564: JComponent.WHEN_IN_FOCUSED_WINDOW);
1565: assertTrue(panel.getActionForKeyStroke(keyStroke1) == action3);
1566: panel.registerKeyboardAction(action1, command2, keyStroke1,
1567: JComponent.WHEN_FOCUSED);
1568: assertTrue(panel.getActionForKeyStroke(keyStroke1) == action1);
1569: panel.registerKeyboardAction(action1, command1, keyStroke2,
1570: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1571: panel.registerKeyboardAction(action2, command2, keyStroke3,
1572: JComponent.WHEN_IN_FOCUSED_WINDOW);
1573: assertTrue(panel.getActionForKeyStroke(keyStroke2) == action1);
1574: assertTrue(panel.getActionForKeyStroke(keyStroke3) == action2);
1575: panel.registerKeyboardAction(action3, command3, keyStroke3,
1576: JComponent.WHEN_IN_FOCUSED_WINDOW);
1577: assertTrue(panel.getActionForKeyStroke(keyStroke3) == action3);
1578: panel.registerKeyboardAction(null, command3, keyStroke3,
1579: JComponent.WHEN_FOCUSED);
1580: assertNull(panel.getActionForKeyStroke(keyStroke3));
1581: }
1582:
1583: public void testProcessKeyBinding()
1584: throws IllegalArgumentException, IllegalAccessException,
1585: InvocationTargetException {
1586: ActionListenerDummy action1 = new ActionListenerDummy();
1587: ActionListenerDummy action2 = new ActionListenerDummy();
1588: ActionListenerDummy action3 = new ActionListenerDummy();
1589: KeyStroke keyStroke1 = KeyStroke.getKeyStroke(
1590: KeyEvent.VK_PAGE_DOWN, 0);
1591: KeyStroke keyStroke2 = KeyStroke.getKeyStroke(
1592: KeyEvent.VK_PAGE_UP, 0);
1593: KeyStroke keyStroke3 = KeyStroke.getKeyStroke(
1594: KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK);
1595: KeyStroke keyStroke4 = KeyStroke.getKeyStroke(KeyEvent.VK_X, 0);
1596: KeyEvent keyEvent1 = new KeyEvent(panel, 1, 10, 0, 100, '1');
1597: KeyEvent keyEvent2 = new KeyEvent(panel, 2, 20, 0, 200, '2');
1598: KeyEvent keyEvent3 = new KeyEvent(panel, 3, 30, 0, 300, '3');
1599: KeyEvent keyEvent4 = new KeyEvent(panel, 3, 30, 0, 300, '3');
1600: String command1 = "command1";
1601: String command2 = "command2";
1602: String command3 = null;
1603: boolean result = false;
1604: panel.registerKeyboardAction(action1, command1, keyStroke1,
1605: JComponent.WHEN_FOCUSED);
1606: panel.registerKeyboardAction(action2, command2, keyStroke2,
1607: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1608: panel.registerKeyboardAction(action3, command3, keyStroke3,
1609: JComponent.WHEN_IN_FOCUSED_WINDOW);
1610: result = panel.processKeyBinding(keyStroke1, keyEvent1,
1611: JComponent.WHEN_FOCUSED, true);
1612: assertTrue(action1.eventHeard != null
1613: && action1.eventHeard.getActionCommand().equals(
1614: command1));
1615: assertTrue(result);
1616: result = panel.processKeyBinding(keyStroke2, keyEvent2,
1617: JComponent.WHEN_FOCUSED, true);
1618: assertNull(action2.eventHeard);
1619: assertFalse(result);
1620: result = panel.processKeyBinding(keyStroke2, keyEvent2,
1621: JComponent.WHEN_IN_FOCUSED_WINDOW, false);
1622: assertNull(action2.eventHeard);
1623: assertFalse(result);
1624: result = panel.processKeyBinding(keyStroke2, keyEvent2,
1625: JComponent.WHEN_IN_FOCUSED_WINDOW, true);
1626: assertNull(action2.eventHeard);
1627: assertFalse(result);
1628: result = panel.processKeyBinding(keyStroke2, keyEvent2,
1629: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, false);
1630: assertTrue(action2.eventHeard != null
1631: && action2.eventHeard.getActionCommand() == command2);
1632: assertTrue(result);
1633: result = panel.processKeyBinding(keyStroke2, keyEvent2,
1634: JComponent.WHEN_IN_FOCUSED_WINDOW, true);
1635: assertTrue(action2.eventHeard != null
1636: && action2.eventHeard.getActionCommand() == command2);
1637: assertFalse(result);
1638: result = panel.processKeyBinding(keyStroke3, keyEvent3,
1639: JComponent.WHEN_IN_FOCUSED_WINDOW, true);
1640: assertTrue(action3.eventHeard != null
1641: && action3.eventHeard.getActionCommand() == command3);
1642: assertTrue(result);
1643: result = panel.processKeyBinding(keyStroke3, keyEvent3,
1644: JComponent.WHEN_IN_FOCUSED_WINDOW, true);
1645: assertTrue(action3.eventHeard != null
1646: && action3.eventHeard.getActionCommand() == command3);
1647: assertTrue(result);
1648: Action action = new AbstractAction() {
1649: public void actionPerformed(final ActionEvent e) {
1650: }
1651: };
1652: panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
1653: keyStroke4, "asdasda");
1654: panel.getActionMap().put("asdasda", action);
1655: action.setEnabled(false);
1656: result = panel.processKeyBinding(keyStroke4, keyEvent4,
1657: JComponent.WHEN_IN_FOCUSED_WINDOW, true);
1658: assertFalse(result);
1659: action.setEnabled(true);
1660: panel.setEnabled(false);
1661: result = panel.processKeyBinding(keyStroke4, keyEvent4,
1662: JComponent.WHEN_IN_FOCUSED_WINDOW, true);
1663: assertFalse(result);
1664: panel.setEnabled(true);
1665: panel.setVisible(false);
1666: result = panel.processKeyBinding(keyStroke4, keyEvent4,
1667: JComponent.WHEN_IN_FOCUSED_WINDOW, true);
1668: assertTrue(result);
1669: }
1670:
1671: public void testGetActionForKeyStroke() {
1672: ActionListener action1 = new ActionListener() {
1673: public void actionPerformed(final ActionEvent e) {
1674: }
1675: };
1676: ActionListener action2 = new ActionListener() {
1677: public void actionPerformed(final ActionEvent e) {
1678: }
1679: };
1680: ActionListener action3 = new ActionListener() {
1681: public void actionPerformed(final ActionEvent e) {
1682: }
1683: };
1684: KeyStroke keyStroke1 = KeyStroke.getKeyStroke(
1685: KeyEvent.VK_PAGE_DOWN, 0);
1686: KeyStroke keyStroke2 = KeyStroke.getKeyStroke(
1687: KeyEvent.VK_PAGE_UP, 0);
1688: KeyStroke keyStroke3 = KeyStroke.getKeyStroke(
1689: KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK);
1690: panel.registerKeyboardAction(action3, keyStroke1,
1691: JComponent.WHEN_IN_FOCUSED_WINDOW);
1692: assertTrue(panel.getActionForKeyStroke(keyStroke1) == action3);
1693: panel.registerKeyboardAction(action1, keyStroke1,
1694: JComponent.WHEN_FOCUSED);
1695: assertTrue(panel.getActionForKeyStroke(keyStroke1) == action1);
1696: panel.registerKeyboardAction(action1, keyStroke2,
1697: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1698: panel.registerKeyboardAction(action2, keyStroke3,
1699: JComponent.WHEN_IN_FOCUSED_WINDOW);
1700: assertTrue(panel.getActionForKeyStroke(keyStroke2) == action1);
1701: assertTrue(panel.getActionForKeyStroke(keyStroke3) == action2);
1702: panel.registerKeyboardAction(action3, keyStroke3,
1703: JComponent.WHEN_IN_FOCUSED_WINDOW);
1704: assertTrue(panel.getActionForKeyStroke(keyStroke3) == action3);
1705: panel.registerKeyboardAction(null, keyStroke3,
1706: JComponent.WHEN_FOCUSED);
1707: assertNull(panel.getActionForKeyStroke(keyStroke3));
1708: }
1709:
1710: /*
1711: * Class under test for void registerKeyboardAction(ActionListener, KeyStroke, int)
1712: * this method is being tested by testGetActionForKeyStroke()
1713: */
1714: public void testRegisterKeyboardActionActionListenerKeyStrokeint() {
1715: }
1716:
1717: public void testUnregisterKeyboardAction() {
1718: ActionListener action1 = new ActionListener() {
1719: public void actionPerformed(final ActionEvent e) {
1720: }
1721: };
1722: ActionListener action2 = new ActionListener() {
1723: public void actionPerformed(final ActionEvent e) {
1724: }
1725: };
1726: ActionListener action3 = new ActionListener() {
1727: public void actionPerformed(final ActionEvent e) {
1728: }
1729: };
1730: KeyStroke keyStroke1 = KeyStroke.getKeyStroke(
1731: KeyEvent.VK_PAGE_DOWN, 0);
1732: KeyStroke keyStroke2 = KeyStroke.getKeyStroke(
1733: KeyEvent.VK_PAGE_UP, 0);
1734: KeyStroke keyStroke3 = KeyStroke.getKeyStroke(
1735: KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK);
1736: panel.registerKeyboardAction(action1, keyStroke1,
1737: JComponent.WHEN_FOCUSED);
1738: panel.registerKeyboardAction(action2, keyStroke2,
1739: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1740: panel.registerKeyboardAction(action3, keyStroke3,
1741: JComponent.WHEN_IN_FOCUSED_WINDOW);
1742: assertTrue(panel.getActionForKeyStroke(keyStroke1) == action1);
1743: assertTrue(panel.getActionForKeyStroke(keyStroke2) == action2);
1744: assertTrue(panel.getActionForKeyStroke(keyStroke3) == action3);
1745: panel.unregisterKeyboardAction(keyStroke1);
1746: assertNull(panel.getActionForKeyStroke(keyStroke1));
1747: assertTrue(panel.getActionForKeyStroke(keyStroke2) == action2);
1748: assertTrue(panel.getActionForKeyStroke(keyStroke3) == action3);
1749: panel.unregisterKeyboardAction(keyStroke2);
1750: assertNull(panel.getActionForKeyStroke(keyStroke1));
1751: assertNull(panel.getActionForKeyStroke(keyStroke2));
1752: assertTrue(panel.getActionForKeyStroke(keyStroke3) == action3);
1753: panel.unregisterKeyboardAction(keyStroke3);
1754: assertNull(panel.getActionForKeyStroke(keyStroke1));
1755: assertNull(panel.getActionForKeyStroke(keyStroke2));
1756: assertNull(panel.getActionForKeyStroke(keyStroke3));
1757: panel.registerKeyboardAction(action1, keyStroke1,
1758: JComponent.WHEN_FOCUSED);
1759: panel.registerKeyboardAction(action2, keyStroke1,
1760: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1761: panel.unregisterKeyboardAction(keyStroke1);
1762: assertNull(panel.getActionForKeyStroke(keyStroke1));
1763: assertTrue(panel.getActionMap().size() == 0);
1764: }
1765:
1766: public void testGetConditionForKeyStroke() {
1767: ActionListener action1 = new ActionListener() {
1768: public void actionPerformed(final ActionEvent e) {
1769: }
1770: };
1771: ActionListener action2 = new ActionListener() {
1772: public void actionPerformed(final ActionEvent e) {
1773: }
1774: };
1775: ActionListener action3 = new ActionListener() {
1776: public void actionPerformed(final ActionEvent e) {
1777: }
1778: };
1779: KeyStroke keyStroke1 = KeyStroke.getKeyStroke(
1780: KeyEvent.VK_PAGE_DOWN, 0);
1781: KeyStroke keyStroke2 = KeyStroke.getKeyStroke(
1782: KeyEvent.VK_PAGE_UP, 0);
1783: KeyStroke keyStroke3 = KeyStroke.getKeyStroke(
1784: KeyEvent.VK_ASTERISK, 0);
1785: assertTrue(panel.getConditionForKeyStroke(keyStroke1) == JComponent.UNDEFINED_CONDITION);
1786: assertTrue(panel.getConditionForKeyStroke(keyStroke2) == JComponent.UNDEFINED_CONDITION);
1787: panel.registerKeyboardAction(action1, keyStroke1,
1788: JComponent.WHEN_IN_FOCUSED_WINDOW);
1789: assertTrue(panel.getConditionForKeyStroke(keyStroke1) == JComponent.WHEN_IN_FOCUSED_WINDOW);
1790: panel.registerKeyboardAction(action1, keyStroke1,
1791: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1792: assertTrue(panel.getConditionForKeyStroke(keyStroke1) == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1793: panel.registerKeyboardAction(action1, keyStroke1,
1794: JComponent.WHEN_FOCUSED);
1795: assertTrue(panel.getConditionForKeyStroke(keyStroke1) == JComponent.WHEN_FOCUSED);
1796: panel.registerKeyboardAction(action2, keyStroke2,
1797: JComponent.WHEN_FOCUSED);
1798: assertTrue(panel.getConditionForKeyStroke(keyStroke2) == JComponent.WHEN_FOCUSED);
1799: panel.registerKeyboardAction(action2, keyStroke2,
1800: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1801: assertTrue(panel.getConditionForKeyStroke(keyStroke2) == JComponent.WHEN_FOCUSED);
1802: panel.registerKeyboardAction(action2, keyStroke2,
1803: JComponent.WHEN_IN_FOCUSED_WINDOW);
1804: assertTrue(panel.getConditionForKeyStroke(keyStroke2) == JComponent.WHEN_FOCUSED);
1805: panel.registerKeyboardAction(action3, keyStroke3,
1806: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1807: assertTrue(panel.getConditionForKeyStroke(keyStroke3) == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1808: panel.registerKeyboardAction(action3, keyStroke3,
1809: JComponent.WHEN_IN_FOCUSED_WINDOW);
1810: assertTrue(panel.getConditionForKeyStroke(keyStroke3) == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1811: panel.registerKeyboardAction(action3, keyStroke3,
1812: JComponent.WHEN_FOCUSED);
1813: assertTrue(panel.getConditionForKeyStroke(keyStroke3) == JComponent.WHEN_FOCUSED);
1814: }
1815:
1816: public void testGetRegisteredKeyStrokes() {
1817: ActionListener action1 = new ActionListener() {
1818: public void actionPerformed(final ActionEvent e) {
1819: }
1820: };
1821: ActionListener action2 = new ActionListener() {
1822: public void actionPerformed(final ActionEvent e) {
1823: }
1824: };
1825: ActionListener action3 = new ActionListener() {
1826: public void actionPerformed(final ActionEvent e) {
1827: }
1828: };
1829: KeyStroke keyStroke1 = KeyStroke.getKeyStroke(
1830: KeyEvent.VK_PAGE_DOWN, 0);
1831: KeyStroke keyStroke2 = KeyStroke.getKeyStroke(
1832: KeyEvent.VK_PAGE_UP, 0);
1833: KeyStroke keyStroke3 = KeyStroke.getKeyStroke(
1834: KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK);
1835: KeyStroke keyStroke4 = KeyStroke.getKeyStroke(KeyEvent.VK_0, 0);
1836: KeyStroke[] strokes = panel.getRegisteredKeyStrokes();
1837: assertTrue(strokes != null && strokes.length == 0);
1838: panel.registerKeyboardAction(action3, keyStroke1,
1839: JComponent.WHEN_IN_FOCUSED_WINDOW);
1840: panel.registerKeyboardAction(action1, keyStroke1,
1841: JComponent.WHEN_FOCUSED);
1842: panel.registerKeyboardAction(action1, keyStroke2,
1843: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1844: panel.registerKeyboardAction(action2, keyStroke3,
1845: JComponent.WHEN_IN_FOCUSED_WINDOW);
1846: strokes = panel.getRegisteredKeyStrokes();
1847: assertTrue(strokes != null && strokes.length == 4);
1848: assertTrue(find(strokes, keyStroke1) == 2);
1849: assertTrue(find(strokes, keyStroke2) == 1);
1850: assertTrue(find(strokes, keyStroke3) == 1);
1851: panel.registerKeyboardAction(action3, keyStroke3,
1852: JComponent.WHEN_IN_FOCUSED_WINDOW);
1853: strokes = panel.getRegisteredKeyStrokes();
1854: assertTrue(strokes != null && strokes.length == 4);
1855: assertTrue(find(strokes, keyStroke1) == 2);
1856: assertTrue(find(strokes, keyStroke2) == 1);
1857: assertTrue(find(strokes, keyStroke3) == 1);
1858: panel.registerKeyboardAction(null, keyStroke3,
1859: JComponent.WHEN_FOCUSED);
1860: strokes = panel.getRegisteredKeyStrokes();
1861: assertTrue(strokes != null && strokes.length == 5);
1862: assertTrue(find(strokes, keyStroke1) == 2);
1863: assertTrue(find(strokes, keyStroke2) == 1);
1864: assertTrue(find(strokes, keyStroke3) == 2);
1865: InputMap parentMap = new InputMap();
1866: parentMap.put(keyStroke4, keyStroke4);
1867: panel.getInputMap().setParent(parentMap);
1868: strokes = panel.getRegisteredKeyStrokes();
1869: assertTrue("KeyStrokes array is not null", strokes != null);
1870: assertEquals("Number of keyStrokes registered", 6,
1871: strokes.length);
1872: assertEquals("Number of keyStrokes registered", 2, find(
1873: strokes, keyStroke1));
1874: assertEquals("Number of keyStrokes registered", 1, find(
1875: strokes, keyStroke2));
1876: assertEquals("Number of keyStrokes registered", 2, find(
1877: strokes, keyStroke3));
1878: assertEquals("Number of keyStrokes registered", 1, find(
1879: strokes, keyStroke4));
1880: }
1881:
1882: public void testResetKeyboardActions() {
1883: ActionListener action1 = new ActionListener() {
1884: public void actionPerformed(final ActionEvent e) {
1885: }
1886: };
1887: ActionListener action2 = new ActionListener() {
1888: public void actionPerformed(final ActionEvent e) {
1889: }
1890: };
1891: ActionListener action3 = new ActionListener() {
1892: public void actionPerformed(final ActionEvent e) {
1893: }
1894: };
1895: KeyStroke keyStroke1 = KeyStroke.getKeyStroke(
1896: KeyEvent.VK_PAGE_DOWN, 0);
1897: KeyStroke keyStroke2 = KeyStroke.getKeyStroke(
1898: KeyEvent.VK_PAGE_UP, 0);
1899: KeyStroke keyStroke3 = KeyStroke.getKeyStroke(
1900: KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK);
1901: panel.registerKeyboardAction(action1, keyStroke1,
1902: JComponent.WHEN_FOCUSED);
1903: panel.registerKeyboardAction(action2, keyStroke2,
1904: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
1905: panel.registerKeyboardAction(action3, keyStroke3,
1906: JComponent.WHEN_IN_FOCUSED_WINDOW);
1907: assertTrue(panel.getActionForKeyStroke(keyStroke1) == action1);
1908: assertTrue(panel.getActionForKeyStroke(keyStroke2) == action2);
1909: assertTrue(panel.getActionForKeyStroke(keyStroke3) == action3);
1910: panel.resetKeyboardActions();
1911: assertNull(panel.getActionForKeyStroke(keyStroke1));
1912: assertNull(panel.getActionForKeyStroke(keyStroke2));
1913: assertNull(panel.getActionForKeyStroke(keyStroke3));
1914: }
1915:
1916: public void testGetRootPane() {
1917: JFrame mainFrame = new JFrame();
1918: JRootPane rootPane = new JRootPane();
1919: assertNull(panel.getRootPane());
1920: mainFrame.getContentPane().add(panel);
1921: assertTrue(panel.getRootPane() != null);
1922: assertTrue(panel.getRootPane() == mainFrame.getRootPane());
1923: rootPane.getContentPane().add(panel);
1924: assertTrue(panel.getRootPane() != null);
1925: assertTrue(panel.getRootPane() == rootPane);
1926: rootPane.getContentPane().remove(panel);
1927: assertNull(panel.getRootPane());
1928: mainFrame.dispose();
1929: }
1930:
1931: public void testSetInputVerifier() {
1932: PropertyChangeController changeListener = new PropertyChangeController();
1933: panel.addPropertyChangeListener(changeListener);
1934: InputVerifier verifier1 = new InputVerifier() {
1935: @Override
1936: public boolean verify(final JComponent input) {
1937: return false;
1938: }
1939: };
1940: InputVerifier verifier2 = new InputVerifier() {
1941: @Override
1942: public boolean verify(final JComponent input) {
1943: return false;
1944: }
1945: };
1946: panel.setInputVerifier(verifier1);
1947: changeListener.checkPropertyFired(panel, "inputVerifier", null,
1948: verifier1);
1949: changeListener.reset();
1950: panel.setInputVerifier(verifier2);
1951: changeListener.checkPropertyFired(panel, "inputVerifier",
1952: verifier1, verifier2);
1953: changeListener.reset();
1954: panel.setInputVerifier(verifier2);
1955: assertFalse("event's not fired", changeListener.isChanged());
1956: changeListener.reset();
1957: }
1958:
1959: public void testGetInputVerifier() {
1960: InputVerifier verifier1 = new InputVerifier() {
1961: @Override
1962: public boolean verify(final JComponent input) {
1963: return false;
1964: }
1965: };
1966: InputVerifier verifier2 = new InputVerifier() {
1967: @Override
1968: public boolean verify(final JComponent input) {
1969: return false;
1970: }
1971: };
1972: assertNull("There's not inputVerifier set by default", panel
1973: .getInputVerifier());
1974: panel.setInputVerifier(verifier1);
1975: assertEquals("InputVerifier set properly: ", verifier1, panel
1976: .getInputVerifier());
1977: panel.setInputVerifier(verifier2);
1978: assertEquals("InputVerifier set properly: ", verifier2, panel
1979: .getInputVerifier());
1980: }
1981:
1982: /*
1983: * Class under test for InputMap setInputMap()
1984: */
1985: public void testSetInputMap() {
1986: InputMap map1 = new InputMap();
1987: InputMap map2 = new InputMap();
1988: InputMap map3 = new ComponentInputMap(panel);
1989: panel.setInputMap(JComponent.WHEN_FOCUSED, map1);
1990: panel.setInputMap(
1991: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, map2);
1992: panel.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, map3);
1993: assertTrue(panel.getInputMap(JComponent.WHEN_FOCUSED) == map1);
1994: assertTrue(panel
1995: .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) == map2);
1996: assertTrue(panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) == map3);
1997: panel.setInputMap(JComponent.WHEN_FOCUSED, map2);
1998: panel.setInputMap(
1999: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, map3);
2000: assertTrue(panel.getInputMap(JComponent.WHEN_FOCUSED) == map2);
2001: assertTrue(panel
2002: .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) == map3);
2003: panel.setInputMap(JComponent.WHEN_FOCUSED, null);
2004: assertNull(panel.getInputMap(JComponent.WHEN_FOCUSED));
2005: boolean isThrown = false;
2006: try {
2007: panel.setInputMap(1945, map2);
2008: } catch (IllegalArgumentException e) {
2009: isThrown = true;
2010: }
2011: assertTrue("Exception is thrown", isThrown);
2012: isThrown = false;
2013: try {
2014: panel.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, map1);
2015: } catch (IllegalArgumentException e) {
2016: isThrown = true;
2017: }
2018: assertTrue("Exception is thrown", isThrown);
2019: if (isHarmony()) {
2020: isThrown = false;
2021: try {
2022: panel.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW,
2023: null);
2024: } catch (IllegalArgumentException e) {
2025: isThrown = true;
2026: }
2027: assertTrue("Exception is thrown", isThrown);
2028: }
2029: }
2030:
2031: /*
2032: * Class under test for InputMap getInputMap(int)
2033: */
2034: public void testGetInputMapint() {
2035: assertTrue(panel.getInputMap(JComponent.WHEN_FOCUSED) != null);
2036: assertTrue(panel
2037: .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) != null);
2038: assertTrue(panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) != null);
2039: boolean isThrown = false;
2040: try {
2041: panel.getInputMap(1812);
2042: } catch (IllegalArgumentException e) {
2043: isThrown = true;
2044: }
2045: assertTrue(isThrown);
2046: }
2047:
2048: /*
2049: * Class under test for InputMap getInputMap()
2050: */
2051: public void testGetInputMap() {
2052: assertTrue(panel.getInputMap() == panel
2053: .getInputMap(JComponent.WHEN_FOCUSED));
2054: panel.setInputMap(JComponent.WHEN_FOCUSED, new InputMap());
2055: assertTrue(panel.getInputMap() == panel
2056: .getInputMap(JComponent.WHEN_FOCUSED));
2057: }
2058:
2059: /*
2060: * Class under test for InputMap getInputMap(int, boolean)
2061: */
2062: public void testGetInputMapintboolean() {
2063: assertNull(panel.getInputMap(JComponent.WHEN_FOCUSED, false));
2064: assertNotNull(panel.getInputMap(JComponent.WHEN_FOCUSED, true));
2065: assertNotNull(panel.getInputMap(JComponent.WHEN_FOCUSED, false));
2066: panel.setInputMap(JComponent.WHEN_FOCUSED, null);
2067: assertNull(panel.getInputMap(JComponent.WHEN_FOCUSED, true));
2068: assertNull(panel.getInputMap(JComponent.WHEN_FOCUSED, false));
2069: assertNull(panel.getInputMap(
2070: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, false));
2071: assertNotNull(panel.getInputMap(
2072: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true));
2073: assertNotNull(panel.getInputMap(
2074: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, false));
2075: panel.setInputMap(
2076: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
2077: assertNull(panel.getInputMap(
2078: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true));
2079: assertNull(panel.getInputMap(
2080: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, false));
2081: assertNull(panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW,
2082: false));
2083: assertNotNull(panel.getInputMap(
2084: JComponent.WHEN_IN_FOCUSED_WINDOW, true));
2085: assertNotNull(panel.getInputMap(
2086: JComponent.WHEN_IN_FOCUSED_WINDOW, false));
2087: }
2088:
2089: /*
2090: * Class under test for ActionMap getActionMap()
2091: */
2092: public void testGetActionMap() {
2093: PropertyChangeController listener = new PropertyChangeController();
2094: assertTrue(panel.getActionMap() != null);
2095: ActionMap map = new ActionMap();
2096: panel.addPropertyChangeListener(listener);
2097: panel.setActionMap(map);
2098: assertTrue(panel.getActionMap() == map);
2099: assertFalse("event's not fired", listener.isChanged());
2100: }
2101:
2102: // this method is being tested by testGetActionMap()
2103: public void testSetActionMap() {
2104: }
2105:
2106: /*
2107: * Class under test for ActionMap getActionMap(boolean)
2108: */
2109: public void testGetActionMapboolean() {
2110: assertNull(panel.getActionMap(false));
2111: assertNotNull(panel.getActionMap(true));
2112: assertNotNull(panel.getActionMap(false));
2113: panel.setActionMap(null);
2114: assertNull(panel.getActionMap(true));
2115: assertNull(panel.getActionMap(false));
2116: }
2117:
2118: public void testSetToolTipText() {
2119: PropertyChangeController changeListener = new PropertyChangeController();
2120: String toolTipText1 = "toolTipText1";
2121: String toolTipText2 = "toolTipText2";
2122: panel.addPropertyChangeListener(changeListener);
2123: panel.setToolTipText(toolTipText1);
2124: changeListener.checkLastPropertyFired(panel,
2125: JComponent.TOOL_TIP_TEXT_KEY, null, toolTipText1);
2126: changeListener.reset();
2127: panel.setToolTipText(toolTipText1);
2128: assertFalse("event's not fired", changeListener.isChanged());
2129: panel.setToolTipText(toolTipText2);
2130: changeListener.checkLastPropertyFired(panel,
2131: JComponent.TOOL_TIP_TEXT_KEY, toolTipText1,
2132: toolTipText2);
2133: changeListener.reset();
2134: panel.setToolTipText(null);
2135: changeListener.checkLastPropertyFired(panel,
2136: JComponent.TOOL_TIP_TEXT_KEY, toolTipText2, null);
2137: panel.putClientProperty(JComponent.TOOL_TIP_TEXT_KEY,
2138: toolTipText1);
2139: assertTrue(panel.getToolTipText().equals(toolTipText1));
2140: panel.setToolTipText(toolTipText2);
2141: assertTrue(panel.getToolTipText().equals(toolTipText2));
2142: panel.setToolTipText(null);
2143: assertNull(panel.getToolTipText());
2144: }
2145:
2146: /*
2147: * Class under test for String getToolTipText()
2148: */
2149: public void testGetToolTipText() {
2150: String toolTipText1 = "toolTipText1";
2151: String toolTipText2 = "toolTipText2";
2152: assertNull(panel.getToolTipText());
2153: panel.setToolTipText(toolTipText1);
2154: assertTrue(panel.getToolTipText().equals(toolTipText1));
2155: panel.setToolTipText(toolTipText2);
2156: assertTrue(panel.getToolTipText().equals(toolTipText2));
2157: panel.setToolTipText(null);
2158: assertNull(panel.getToolTipText());
2159: }
2160:
2161: /*
2162: * Class under test for String getToolTipText(MouseEvent)
2163: */
2164: public void testGetToolTipTextMouseEvent() {
2165: MouseEvent event = new MouseEvent(panel, 0, 0, 0, 0, 0, 0,
2166: false);
2167: String toolTipText1 = "toolTipText1";
2168: String toolTipText2 = "toolTipText2";
2169: assertNull(panel.getToolTipText(event));
2170: panel.setToolTipText(toolTipText1);
2171: assertTrue(panel.getToolTipText(event).equals(toolTipText1));
2172: assertTrue(panel.getToolTipText(null).equals(toolTipText1));
2173: panel.setToolTipText(toolTipText2);
2174: assertTrue(panel.getToolTipText(event).equals(toolTipText2));
2175: assertTrue(panel.getToolTipText(null).equals(toolTipText2));
2176: panel.setToolTipText(null);
2177: assertNull(panel.getToolTipText(event));
2178: assertNull(panel.getToolTipText(null));
2179: }
2180:
2181: public void testGetToolTipLocation() {
2182: int x = 100;
2183: int y = 200;
2184: MouseEvent event = new MouseEvent(panel, 0, 0, 0, x, y, 0,
2185: false);
2186: assertNull(panel.getToolTipLocation(event));
2187: assertNull(panel.getToolTipLocation(null));
2188: }
2189:
2190: public void testCreateToolTip() {
2191: String toolTipText1 = "toolTipText1";
2192: JToolTip toolTip = null;
2193: toolTip = panel.createToolTip();
2194: assertTrue(toolTip.getComponent() == panel);
2195: assertNull(toolTip.getTipText());
2196: panel.setToolTipText(toolTipText1);
2197: toolTip = panel.createToolTip();
2198: assertTrue(toolTip.getComponent() == panel);
2199: assertNull(toolTip.getTipText());
2200: JPanel panel2 = new JPanel();
2201: toolTip = panel2.createToolTip();
2202: assertTrue(toolTip.getComponent() == panel2);
2203: assertNull(toolTip.getTipText());
2204: }
2205:
2206: /*
2207: * Class under test for String paramString()
2208: */
2209: public void testParamString() {
2210: String str = panel.paramString();
2211: assertTrue(str != null);
2212: assertTrue(str != "");
2213: }
2214:
2215: public void testRemoveVetoableChangeListener() {
2216: ConcreteVetoableChangeListener changeListener1 = new ConcreteVetoableChangeListener();
2217: ConcreteVetoableChangeListener changeListener2 = new ConcreteVetoableChangeListener();
2218: ConcreteVetoableChangeListener changeListener3 = new ConcreteVetoableChangeListener();
2219: VetoableChangeListener[] listenersArray = null;
2220: panel.addVetoableChangeListener(changeListener1);
2221: panel.addVetoableChangeListener(changeListener2);
2222: panel.addVetoableChangeListener(changeListener3);
2223: listenersArray = panel.getVetoableChangeListeners();
2224: assertTrue(listenersArray.length == 3);
2225: assertTrue(changeListener1.findMe(listenersArray) == 1);
2226: assertTrue(changeListener2.findMe(listenersArray) == 1);
2227: assertTrue(changeListener3.findMe(listenersArray) == 1);
2228: panel.removeVetoableChangeListener(changeListener2);
2229: listenersArray = panel.getVetoableChangeListeners();
2230: assertTrue(listenersArray.length == 2);
2231: assertTrue(changeListener1.findMe(listenersArray) == 1);
2232: assertTrue(changeListener2.findMe(listenersArray) == 0);
2233: assertTrue(changeListener3.findMe(listenersArray) == 1);
2234: panel.removeVetoableChangeListener(changeListener1);
2235: listenersArray = panel.getVetoableChangeListeners();
2236: assertTrue(listenersArray.length == 1);
2237: assertTrue(changeListener3.findMe(listenersArray) == 1);
2238: panel.removeVetoableChangeListener(changeListener3);
2239: listenersArray = panel.getVetoableChangeListeners();
2240: assertTrue(listenersArray.length == 0);
2241: }
2242:
2243: public void testAddVetoableChangeListener() {
2244: ConcreteVetoableChangeListener changeListener1 = new ConcreteVetoableChangeListener();
2245: ConcreteVetoableChangeListener changeListener2 = new ConcreteVetoableChangeListener();
2246: VetoableChangeListener[] listenersArray = null;
2247: panel.addVetoableChangeListener(changeListener1);
2248: listenersArray = panel.getVetoableChangeListeners();
2249: assertTrue(listenersArray.length == 1);
2250: assertEquals(0, panel.listenerList
2251: .getListeners(VetoableChangeListener.class).length);
2252: assertEquals(1, panel
2253: .getListeners(VetoableChangeListener.class).length);
2254: assertTrue(changeListener1.findMe(listenersArray) > 0);
2255: panel.addVetoableChangeListener(changeListener2);
2256: listenersArray = panel.getVetoableChangeListeners();
2257: assertTrue(listenersArray.length == 2);
2258: assertTrue(changeListener1.findMe(listenersArray) > 0);
2259: assertTrue(changeListener2.findMe(listenersArray) > 0);
2260: panel.addVetoableChangeListener(changeListener2);
2261: listenersArray = panel.getVetoableChangeListeners();
2262: assertTrue(listenersArray.length == 3);
2263: }
2264:
2265: public void testGetVetoableChangeListeners() {
2266: ConcreteVetoableChangeListener changeListener1 = new ConcreteVetoableChangeListener();
2267: ConcreteVetoableChangeListener changeListener2 = new ConcreteVetoableChangeListener();
2268: ConcreteVetoableChangeListener changeListener3 = new ConcreteVetoableChangeListener();
2269: VetoableChangeListener[] listenersArray = null;
2270: listenersArray = panel.getVetoableChangeListeners();
2271: assertTrue(listenersArray != null && listenersArray.length == 0);
2272: panel.addVetoableChangeListener(changeListener1);
2273: panel.addVetoableChangeListener(changeListener2);
2274: panel.addVetoableChangeListener(changeListener3);
2275: panel.addVetoableChangeListener(changeListener2);
2276: listenersArray = panel.getVetoableChangeListeners();
2277: assertTrue(listenersArray.length == 4);
2278: assertTrue(changeListener1.findMe(listenersArray) == 1);
2279: assertTrue(changeListener2.findMe(listenersArray) == 2);
2280: assertTrue(changeListener3.findMe(listenersArray) == 1);
2281: }
2282:
2283: public void testScrollRectToVisible() {
2284: class SRTVComponent extends JComponent {
2285: Rectangle scrollRect = null;
2286:
2287: @Override
2288: public void scrollRectToVisible(final Rectangle rect) {
2289: scrollRect = new Rectangle(rect);
2290: }
2291: }
2292: ;
2293: Container container1 = new Panel();
2294: Container container2 = new Container();
2295: Container container3 = new Panel();
2296: SRTVComponent container4 = new SRTVComponent();
2297: container1.add(panel);
2298: panel.setLocation(10, 10);
2299: container2.add(container1);
2300: container1.setLocation(10, 10);
2301: container3.add(container2);
2302: container2.setLocation(10, 10);
2303: container4.add(container3);
2304: container3.setLocation(10, 10);
2305: panel.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
2306: assertEquals("rectangle's tranformed properly ", new Rectangle(
2307: 40, 40, 1, 1), container4.scrollRect);
2308: }
2309:
2310: /*
2311: * this method is supposed to be tested in Component.testGetGraphics()
2312: */
2313: public void testGetGraphics() {
2314: }
2315:
2316: /*
2317: * Class under test for void setFont(Font)
2318: */
2319: public void testSetFontFont() {
2320: PropertyChangeController changeListener = new PropertyChangeController();
2321: panel.addPropertyChangeListener(changeListener);
2322: Font newFont1 = new Font(null, Font.BOLD, 10);
2323: Font newFont2 = new Font(null, Font.BOLD, 20);
2324: Font oldFont = panel.getFont();
2325: panel.setFont(newFont1);
2326: assertTrue(panel.getFont() == newFont1);
2327: changeListener.checkLastPropertyFired(panel, "font", oldFont,
2328: newFont1);
2329: changeListener.reset();
2330: panel.setFont(newFont2);
2331: assertTrue(panel.getFont() == newFont2);
2332: changeListener.checkLastPropertyFired(panel, "font", newFont1,
2333: newFont2);
2334: changeListener.reset();
2335: panel.setFont(newFont2);
2336: assertTrue(panel.getFont() == newFont2);
2337: assertFalse("event's not fired", changeListener.isChanged());
2338: changeListener.reset();
2339: }
2340:
2341: public void testGetTopLevelAncestor() {
2342: JFrame mainFrame = new JFrame();
2343: JDialog dialog = new JDialog();
2344: assertNull(panel.getTopLevelAncestor());
2345: mainFrame.getContentPane().add(panel);
2346: assertTrue(panel.getTopLevelAncestor() == mainFrame);
2347: dialog.getContentPane().add(panel);
2348: assertTrue(panel.getTopLevelAncestor() == dialog);
2349: dialog.getContentPane().remove(panel);
2350: assertNull(panel.getTopLevelAncestor());
2351: mainFrame.dispose();
2352: }
2353:
2354: public void testSetNextFocusableComponent() {
2355: JComponent container = new JPanel();
2356: JComponent panel1 = new JButton();
2357: JComponent panel2 = new JButton();
2358: PropertyChangeController changeListener = new PropertyChangeController();
2359: panel.addPropertyChangeListener(changeListener);
2360: panel.setNextFocusableComponent(panel1);
2361: changeListener.checkLastPropertyFired(panel, "nextFocus", null,
2362: panel1);
2363: changeListener.reset();
2364: panel.setNextFocusableComponent(panel2);
2365: changeListener.checkLastPropertyFired(panel, "nextFocus",
2366: panel1, panel2);
2367: changeListener.reset();
2368: panel.setNextFocusableComponent(panel2);
2369: assertFalse("event's not fired", changeListener.isChanged());
2370: JFrame frame = new JFrame();
2371: container.add(panel1);
2372: container.add(panel2);
2373: frame.getContentPane().add(container);
2374: frame.pack();
2375: container.setFocusCycleRoot(true);
2376: container
2377: .setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
2378: panel1.setNextFocusableComponent(panel2);
2379: assertNull(container.getFocusTraversalPolicy()
2380: .getComponentBefore(container, panel1));
2381: assertEquals(panel2, container.getFocusTraversalPolicy()
2382: .getComponentAfter(container, panel1));
2383: assertEquals(panel1, container.getFocusTraversalPolicy()
2384: .getComponentBefore(container, panel2));
2385: assertNull(container.getFocusTraversalPolicy()
2386: .getComponentAfter(container, panel2));
2387: }
2388:
2389: public void testGetNextFocusableComponent() {
2390: JComponent panel1 = new JPanel();
2391: JComponent panel2 = new JPanel();
2392: assertNull("default nextFocusableComponent isn't set ", panel
2393: .getNextFocusableComponent());
2394: panel.setNextFocusableComponent(panel1);
2395: assertEquals("nextFocusableComponent set correctly ", panel1,
2396: panel.getNextFocusableComponent());
2397: panel.setNextFocusableComponent(panel2);
2398: assertEquals("nextFocusableComponent set correctly ", panel2,
2399: panel.getNextFocusableComponent());
2400: }
2401:
2402: /*
2403: * Class under test for void setForeground(Color)
2404: */
2405: public void testSetForegroundColor() {
2406: PropertyChangeController changeListener = new PropertyChangeController();
2407: panel.addPropertyChangeListener(changeListener);
2408: Color newColor1 = new Color(10, 10, 10);
2409: Color newColor2 = new Color(20, 20, 20);
2410: Color oldColor = panel.getForeground();
2411: panel.setForeground(newColor1);
2412: assertSame(newColor1, panel.getForeground());
2413: changeListener.checkLastPropertyFired(panel, "foreground",
2414: oldColor, newColor1);
2415: changeListener.reset();
2416: panel.setForeground(newColor2);
2417: assertSame(newColor2, panel.getForeground());
2418: changeListener.checkLastPropertyFired(panel, "foreground",
2419: newColor1, newColor2);
2420: changeListener.reset();
2421: panel.setForeground(newColor2);
2422: assertTrue(panel.getForeground() == newColor2);
2423: assertFalse("event's not fired", changeListener.isChanged());
2424: changeListener.reset();
2425: }
2426:
2427: /*
2428: * Class under test for void setBackground(Color)
2429: */
2430: public void testSetBackgroundColor() {
2431: PropertyChangeController changeListener = new PropertyChangeController();
2432: panel.addPropertyChangeListener(changeListener);
2433: Color newColor1 = new Color(10, 10, 10);
2434: Color newColor2 = new Color(20, 20, 20);
2435: Color oldColor = panel.getBackground();
2436: panel.setBackground(newColor1);
2437: assertSame(newColor1, panel.getBackground());
2438: changeListener.checkLastPropertyFired(panel, "background",
2439: oldColor, newColor1);
2440: changeListener.reset();
2441: panel.setBackground(newColor2);
2442: assertSame(newColor2, panel.getBackground());
2443: changeListener.checkLastPropertyFired(panel, "background",
2444: newColor1, newColor2);
2445: changeListener.reset();
2446: panel.setBackground(newColor2);
2447: assertSame(newColor2, panel.getBackground());
2448: assertFalse("event's not fired", changeListener.isChanged());
2449: changeListener.reset();
2450: }
2451:
2452: public void testSetVerifyInputWhenFocusTarget() {
2453: PropertyChangeController changeListener = new PropertyChangeController();
2454: panel.addPropertyChangeListener(changeListener);
2455: panel.setVerifyInputWhenFocusTarget(false);
2456: changeListener.checkLastPropertyFired(panel,
2457: "verifyInputWhenFocusTarget", Boolean.TRUE,
2458: Boolean.FALSE);
2459: changeListener.reset();
2460: panel.setVerifyInputWhenFocusTarget(true);
2461: changeListener.checkLastPropertyFired(panel,
2462: "verifyInputWhenFocusTarget", Boolean.FALSE,
2463: Boolean.TRUE);
2464: changeListener.reset();
2465: panel.setVerifyInputWhenFocusTarget(true);
2466: assertFalse("event's not fired", changeListener.isChanged());
2467: changeListener.reset();
2468: }
2469:
2470: public void testIsRequestFocusEnabled() {
2471: assertTrue("default value for requestFocusEnabled ", panel
2472: .isRequestFocusEnabled());
2473: }
2474:
2475: public void testSetRequestFocusEnabled() {
2476: panel.setRequestFocusEnabled(false);
2477: assertFalse("value for requestFocusEnabled set correctly ",
2478: panel.isRequestFocusEnabled());
2479: panel.setRequestFocusEnabled(true);
2480: assertTrue("value for requestFocusEnabled set correctly ",
2481: panel.isRequestFocusEnabled());
2482: }
2483:
2484: public void testSetDoubleBuffered() {
2485: panel.setDoubleBuffered(true);
2486: assertTrue("now panel is doubleBuffered ", panel
2487: .isDoubleBuffered());
2488: panel.setDoubleBuffered(false);
2489: assertFalse("now panel is not doubleBuffered ", panel
2490: .isDoubleBuffered());
2491: panel.setDoubleBuffered(true);
2492: assertTrue("now panel is doubleBuffered ", panel
2493: .isDoubleBuffered());
2494: }
2495:
2496: /*
2497: * Class under test for void paintImmediately(int, int, int, int)
2498: */
2499: public void testPaintImmediatelyintintintint() {
2500: // TODO
2501: }
2502:
2503: public void testIsPaintingTile() {
2504: // TODO
2505: }
2506:
2507: public void testRevalidate() {
2508: JFrame frame = new JFrame();
2509: JButton button = new JButton("test");
2510: frame.getContentPane().add(button);
2511: frame.setVisible(true);
2512: assertTrue(button.isValid());
2513: button.revalidate();
2514: assertFalse(button.isValid());
2515:
2516: frame.getRootPane().validate();
2517: assertTrue(button.isValid());
2518:
2519: final Marker rm = new Marker();
2520: RepaintManager.setCurrentManager(new RepaintManager() {
2521: public void addInvalidComponent(
2522: final JComponent invalidComponent) {
2523: rm.setAuxiliary(invalidComponent);
2524: }
2525: });
2526: button.revalidate();
2527: assertFalse(button.isValid());
2528: assertSame(button, rm.getAuxiliary());
2529:
2530: frame.dispose();
2531: }
2532:
2533: /*
2534: * Class under test for void repaint(Rectangle)
2535: */
2536: public void testRepaintRectangle() {
2537: // TODO
2538: }
2539:
2540: /*
2541: * Class under test for void paintImmediately(Rectangle)
2542: */
2543: public void testPaintImmediatelyRectangle() {
2544: try {
2545: new JComponent() {
2546: }.paintImmediately(null);
2547: fail("NPE should be thrown");
2548: } catch (NullPointerException npe) {
2549: // PASSED
2550: }
2551: }
2552:
2553: /*
2554: * Class under test for void update(Graphics)
2555: */
2556: public void testUpdateGraphics() {
2557: // TODO
2558: }
2559:
2560: public void testPrintComponent() {
2561: // TODO
2562: }
2563:
2564: public void testPrintChildren() {
2565: // TODO
2566: }
2567:
2568: public void testPrintBorder() {
2569: // TODO
2570: }
2571:
2572: /*
2573: * Class under test for void printAll(Graphics)
2574: */
2575: public void testPrintAllGraphics() {
2576: // TODO
2577: }
2578:
2579: /*
2580: * Class under test for void print(Graphics)
2581: */
2582: public void testPrintGraphics() {
2583: // TODO
2584: }
2585:
2586: public void testPaintComponent() {
2587: // TODO
2588: }
2589:
2590: public void testPaintChildren() {
2591: // TODO
2592: }
2593:
2594: public void testPaintBorder() {
2595: // TODO
2596: }
2597:
2598: /*
2599: * Class under test for void paint(Graphics)
2600: */
2601: public void testPaintGraphics() {
2602: // TODO
2603: }
2604:
2605: /*
2606: * Class under test for void repaint(long, int, int, int, int)
2607: */
2608: public void testRepaintlongintintintint() {
2609: // TODO
2610: }
2611:
2612: public void testSetDebugGraphicsOptions() {
2613: if (!isHarmony()) {
2614: panel.setDebugGraphicsOptions(DebugGraphics.LOG_OPTION
2615: | DebugGraphics.FLASH_OPTION);
2616: assertTrue(
2617: "options are set correctly ",
2618: (panel.getDebugGraphicsOptions() & DebugGraphics.FLASH_OPTION) != 0);
2619: assertTrue(
2620: "options are set correctly ",
2621: (panel.getDebugGraphicsOptions() & DebugGraphics.LOG_OPTION) != 0);
2622: assertFalse(
2623: "options are set correctly ",
2624: (panel.getDebugGraphicsOptions() & DebugGraphics.BUFFERED_OPTION) != 0);
2625: panel
2626: .setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
2627: assertFalse(
2628: "options are set correctly ",
2629: (panel.getDebugGraphicsOptions() & DebugGraphics.FLASH_OPTION) != 0);
2630: assertFalse(
2631: "options are set correctly ",
2632: (panel.getDebugGraphicsOptions() & DebugGraphics.LOG_OPTION) != 0);
2633: assertTrue(
2634: "options are set correctly ",
2635: (panel.getDebugGraphicsOptions() & DebugGraphics.BUFFERED_OPTION) != 0);
2636: panel.setDebugGraphicsOptions(DebugGraphics.NONE_OPTION);
2637: assertFalse(
2638: "options are set correctly ",
2639: (panel.getDebugGraphicsOptions() & DebugGraphics.FLASH_OPTION) != 0);
2640: assertFalse(
2641: "options are set correctly ",
2642: (panel.getDebugGraphicsOptions() & DebugGraphics.LOG_OPTION) != 0);
2643: assertFalse(
2644: "options are set correctly ",
2645: (panel.getDebugGraphicsOptions() & DebugGraphics.BUFFERED_OPTION) != 0);
2646: assertTrue("options are set correctly ", panel
2647: .getDebugGraphicsOptions() == 0);
2648: }
2649: }
2650:
2651: public void testGetDebugGraphicsOptions() {
2652: assertTrue("options are set correctly ", panel
2653: .getDebugGraphicsOptions() == 0);
2654: }
2655:
2656: public void testIsValidateRoot() {
2657: assertFalse("isValidateRoot always returns false ", panel
2658: .isValidateRoot());
2659: }
2660:
2661: public void testIsOptimizedDrawingEnabled() {
2662: assertTrue("isOptimizedDrawingEnabled always returns true ",
2663: panel.isOptimizedDrawingEnabled());
2664: }
2665:
2666: public void testIsManagingFocus() {
2667: assertFalse("isManagingFocus always returns false ", panel
2668: .isManagingFocus());
2669: }
2670:
2671: public void testGetVerifyInputWhenFocusTarget() {
2672: assertTrue("default verifyInputWhenFocusTarget value", panel
2673: .getVerifyInputWhenFocusTarget());
2674: panel.setVerifyInputWhenFocusTarget(false);
2675: assertFalse("verifyInputWhenFocusTarget value set properly ",
2676: panel.getVerifyInputWhenFocusTarget());
2677: panel.setVerifyInputWhenFocusTarget(true);
2678: assertTrue("verifyInputWhenFocusTarget value set properly ",
2679: panel.getVerifyInputWhenFocusTarget());
2680: }
2681:
2682: public void testSetAutoscrolls() {
2683: panel.setAutoscrolls(true);
2684: assertTrue(panel.getAutoscrolls());
2685: panel.setAutoscrolls(false);
2686: assertFalse(panel.getAutoscrolls());
2687: panel.setAutoscrolls(true);
2688: assertTrue(panel.getAutoscrolls());
2689: }
2690:
2691: public void testGetAutoscrolls() {
2692: assertFalse(panel.getAutoscrolls());
2693: }
2694:
2695: public void testSetDefaultLocale() {
2696: Locale locale = JComponent.getDefaultLocale().equals(
2697: Locale.CHINA) ? Locale.ITALIAN : Locale.CHINA;
2698: assertFalse(panel.getLocale().equals(locale));
2699: assertFalse(JComponent.getDefaultLocale().equals(locale));
2700: JComponent.setDefaultLocale(locale);
2701: panel = new JPanel();
2702: assertTrue(panel.getLocale().equals(locale));
2703: assertTrue(JComponent.getDefaultLocale().equals(locale));
2704: }
2705:
2706: // this method is being tested by testSetDefaultLocale()
2707: public void testGetDefaultLocale() {
2708: }
2709:
2710: public void testIsLightweightComponent() {
2711: JFrame mainFrame = new JFrame();
2712: Canvas button = new Canvas();
2713: JPanel jbutton = new JPanel();
2714: Panel awtPanel = new Panel();
2715: // assertFalse(JComponent.isLightweightComponent(panel));
2716: // assertFalse(JComponent.isLightweightComponent(button));
2717: // assertFalse(JComponent.isLightweightComponent(jbutton));
2718: // assertFalse(JComponent.isLightweightComponent(awtPanel));
2719: mainFrame.getContentPane().add(panel);
2720: mainFrame.getContentPane().add(button);
2721: mainFrame.getContentPane().add(jbutton);
2722: mainFrame.getContentPane().add(awtPanel);
2723: mainFrame.pack();
2724: assertTrue(JComponent.isLightweightComponent(panel));
2725: assertFalse(JComponent.isLightweightComponent(button));
2726: assertTrue(JComponent.isLightweightComponent(jbutton));
2727: assertFalse(JComponent.isLightweightComponent(awtPanel));
2728: mainFrame.dispose();
2729: }
2730:
2731: public void testUpdateUI() {
2732: new JPanel().updateUI();
2733: new JLayeredPane().updateUI();
2734: }
2735:
2736: public void testSetInheritsPopupMenu() {
2737: PropertyChangeController listener1 = new PropertyChangeController();
2738: panel.addPropertyChangeListener(listener1);
2739: panel.setInheritsPopupMenu(true);
2740: if (isHarmony()) {
2741: listener1.checkPropertyFired(panel, "inheritsPopupMenu",
2742: Boolean.FALSE, Boolean.TRUE);
2743: }
2744: assertTrue("InheritsPopupMenu", panel.getInheritsPopupMenu());
2745: listener1.reset();
2746: panel.setInheritsPopupMenu(false);
2747: if (isHarmony()) {
2748: listener1.checkPropertyFired(panel, "inheritsPopupMenu",
2749: Boolean.TRUE, Boolean.FALSE);
2750: }
2751: assertFalse("InheritsPopupMenu", panel.getInheritsPopupMenu());
2752: listener1.reset();
2753: panel.setInheritsPopupMenu(false);
2754: assertTrue("event's not been fired ", !listener1.isChanged());
2755: }
2756:
2757: public void testGetInheritsPopupMenu() {
2758: assertFalse("InheritsPopupMenu", panel.getInheritsPopupMenu());
2759: }
2760:
2761: public void testSetComponentPopupMenu() {
2762: PropertyChangeController listener1 = new PropertyChangeController();
2763: JPopupMenu popup1 = new JPopupMenu();
2764: JPopupMenu popup2 = new JPopupMenu();
2765: panel.addPropertyChangeListener(listener1);
2766: panel.setComponentPopupMenu(popup1);
2767: if (isHarmony()) {
2768: listener1.checkPropertyFired(panel, "componentPopupMenu",
2769: null, popup1);
2770: }
2771: assertEquals("ComponentPopupMenu", popup1, panel
2772: .getComponentPopupMenu());
2773: listener1.reset();
2774: panel.setComponentPopupMenu(popup2);
2775: if (isHarmony()) {
2776: listener1.checkPropertyFired(panel, "componentPopupMenu",
2777: popup1, popup2);
2778: }
2779: assertEquals("ComponentPopupMenu", popup2, panel
2780: .getComponentPopupMenu());
2781: listener1.reset();
2782: panel.setInheritsPopupMenu(true);
2783: listener1.reset();
2784: panel.setComponentPopupMenu(popup2);
2785: assertTrue("event's not been fired ", !listener1.isChanged());
2786: }
2787:
2788: public void testGetComponentPopupMenu() {
2789: assertNull("ComponentPopupMenu", panel.getComponentPopupMenu());
2790: JPanel parent = new JPanel();
2791: parent.add(panel);
2792: JPopupMenu popup1 = new JPopupMenu();
2793: JPopupMenu popup2 = new JPopupMenu();
2794: panel.setComponentPopupMenu(popup1);
2795: parent.setComponentPopupMenu(popup2);
2796: panel.setInheritsPopupMenu(false);
2797: assertEquals("ComponentPopupMenu", popup1, panel
2798: .getComponentPopupMenu());
2799: panel.setInheritsPopupMenu(true);
2800: assertEquals("ComponentPopupMenu", popup1, panel
2801: .getComponentPopupMenu());
2802: panel.setComponentPopupMenu(null);
2803: assertEquals("ComponentPopupMenu", popup2, panel
2804: .getComponentPopupMenu());
2805: panel.setInheritsPopupMenu(false);
2806: assertNull("ComponentPopupMenu", panel.getComponentPopupMenu());
2807: }
2808:
2809: public void testGetPopupLocation() {
2810: panel.setPreferredSize(new Dimension(100, 100));
2811: MouseEvent event = new MouseEvent(panel, 0, 0, 0, 10, 20, 1,
2812: true);
2813: assertNull("PopupLocation", panel.getPopupLocation(event));
2814: }
2815:
2816: @SuppressWarnings("unchecked")
2817: private void removeListeners(final JComponent comp,
2818: final Class<? extends EventListener> c) {
2819: EventListener[] listeners = comp.getListeners(c);
2820: for (int i = 0; i < listeners.length; i++) {
2821: comp.listenerList.remove((Class<EventListener>) c,
2822: listeners[i]);
2823: }
2824: }
2825: }
|