001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package java.awt;
018:
019: import java.awt.event.InputEvent;
020: import java.awt.event.KeyEvent;
021: import java.beans.PropertyChangeEvent;
022: import java.beans.PropertyChangeListener;
023: import java.beans.PropertyChangeListenerProxy;
024: import java.beans.PropertyVetoException;
025: import java.beans.VetoableChangeListener;
026: import java.beans.VetoableChangeListenerProxy;
027: import java.util.HashSet;
028: import java.util.LinkedHashSet;
029: import java.util.Set;
030:
031: import junit.framework.TestCase;
032:
033: public class KeyboardFocusManagerTest extends TestCase {
034:
035: boolean listenerCalled, newListenerCalled, vlistenerCalled;
036: KeyboardFocusManager kfm = new MyKeyboardManager();
037:
038: SimpleComponent comp = new SimpleComponent();
039: SimpleComponent comp1 = new SimpleComponent();
040: PropertyChangeEvent event, newEvent, vetoedEvent;
041: PropertyChangeListener listener = new PropertyChangeListener() {
042:
043: public void propertyChange(PropertyChangeEvent e) {
044: listenerCalled = true;
045: event = e;
046: }
047:
048: };
049: VetoableChangeListener vlistener = new VetoableChangeListener() {
050: String vetoedPropName = "activeWindow";
051:
052: public void vetoableChange(PropertyChangeEvent e)
053: throws PropertyVetoException {
054: event = e;
055: vlistenerCalled = true;
056: String propName = e.getPropertyName();
057: if (propName.equals(vetoedPropName)
058: && e.getNewValue() != null) {
059: vetoedEvent = e;
060: throw new PropertyVetoException(propName
061: + " change is vetoed!", e);
062: }
063: }
064:
065: };
066:
067: public static void main(String[] args) {
068: junit.textui.TestRunner.run(KeyboardFocusManagerTest.class);
069: }
070:
071: @SuppressWarnings("serial")
072: public class SimpleComponent extends Component {
073: }
074:
075: class MyKeyboardManager extends DefaultKeyboardFocusManager {
076:
077: }
078:
079: @Override
080: protected void setUp() throws Exception {
081: super .setUp();
082: listenerCalled = vlistenerCalled = false;
083: clearVetoableChangeListeners();
084: clearPropertyChangeListeners();
085: kfm.clearGlobalFocusOwner();
086: kfm.setGlobalActiveWindow(null);
087: kfm.setGlobalFocusedWindow(null);
088: kfm.setGlobalPermanentFocusOwner(null);
089: event = vetoedEvent = newEvent = null;
090: }
091:
092: /*
093: * @see TestCase#tearDown()
094: */
095: @Override
096: protected void tearDown() throws Exception {
097: super .tearDown();
098: }
099:
100: void clearPropertyChangeListeners() {
101: if (kfm != null) {
102: PropertyChangeListener[] listeners = kfm
103: .getPropertyChangeListeners();
104: if (listeners != null) {
105: for (PropertyChangeListener element : listeners) {
106: kfm.removePropertyChangeListener(element);
107: }
108: }
109: }
110: }
111:
112: void clearVetoableChangeListeners() {
113: if (kfm != null) {
114: VetoableChangeListener[] listeners = kfm
115: .getVetoableChangeListeners();
116: if (listeners != null) {
117: for (VetoableChangeListener element : listeners) {
118: kfm.removeVetoableChangeListener(element);
119: }
120: }
121: }
122: }
123:
124: /*
125: * Class under test for void addPropertyChangeListener(java.lang.String,
126: * java.beans.PropertyChangeListener)
127: */
128: public final void testAddPropertyChangeListenerString() {
129: assertNotNull(kfm);
130:
131: String propName = "focusOwner";
132: kfm.addPropertyChangeListener(propName, listener);
133: PropertyChangeListener[] listeners = kfm
134: .getPropertyChangeListeners(propName);
135: assertNotNull(listeners);
136: int len = listeners.length;
137: assertEquals(1, len);
138: assertSame(listener, listeners[0]);
139: assertFalse(listenerCalled);
140: kfm.setGlobalActiveWindow(new Frame());
141: assertFalse(listenerCalled);
142: kfm.setGlobalFocusOwner(comp);
143: assertTrue(listenerCalled);
144: assertNotNull(event);
145: assertSame(kfm, event.getSource());
146: assertNull(event.getOldValue());
147: assertSame(comp, event.getNewValue());
148: assertEquals(propName, event.getPropertyName());
149: listenerCalled = false;
150: kfm.setGlobalFocusOwner(comp1);
151: assertTrue(listenerCalled);
152: assertNotNull(event);
153: assertSame(comp, event.getOldValue());
154: assertSame(comp1, event.getNewValue());
155:
156: }
157:
158: /*
159: * Class under test for void
160: * addPropertyChangeListener(java.beans.PropertyChangeListener)
161: */
162: // TODO: FIXME
163: public final void testAddPropertyChangeListener() {
164: assertNotNull(kfm);
165:
166: kfm.addPropertyChangeListener(listener);
167: PropertyChangeListener[] listeners = kfm
168: .getPropertyChangeListeners();
169: assertNotNull(listeners);
170: int len = listeners.length;
171: assertEquals(1, len);
172: assertSame(listener, listeners[0]);
173: assertFalse(listenerCalled);
174: Frame f = new Frame();
175: kfm.setGlobalFocusedWindow(f);
176: assertTrue(listenerCalled);
177: assertNotNull(event);
178: assertNull(event.getOldValue());
179: assertSame(f, event.getNewValue());
180: assertEquals("focusedWindow", event.getPropertyName());
181: listenerCalled = false;
182: event = null;
183: kfm.setGlobalFocusOwner(comp);
184: assertTrue(listenerCalled);
185: assertNotNull(event);
186: // assertNull(event.getOldValue());
187: assertSame(comp, event.getNewValue());
188: assertEquals("focusOwner", event.getPropertyName());
189: listenerCalled = false;
190: event = null;
191: kfm.setGlobalFocusOwner(comp1);
192: assertTrue(listenerCalled);
193: assertNotNull(event);
194: assertSame(comp, event.getOldValue());
195: assertSame(comp1, event.getNewValue());
196: kfm.addPropertyChangeListener("newproperty", listener);
197: len = kfm.getPropertyChangeListeners().length;
198: assertEquals(2, len);
199: }
200:
201: /*
202: * Class under test for void
203: * addVetoableChangeListener(java.beans.VetoableChangeListener)
204: */
205: // public final void testAddRemoveVetoableChangeListener() {
206: // assertNotNull(kfm);
207: // kfm.addVetoableChangeListener(vlistener);
208: // VetoableChangeListener[] listeners = kfm.getVetoableChangeListeners();
209: // assertNotNull(listeners);
210: // int len = listeners.length;
211: // assertEquals(1, len);
212: // assertSame(vlistener, listeners[0]);
213: // assertFalse(vlistenerCalled);
214: // //test non-vetoed property change:
215: // kfm.setGlobalFocusOwner(comp);
216: // assertTrue(vlistenerCalled);
217: // assertNotNull(event);
218: // assertNull(event.getOldValue());
219: // assertSame(comp, event.getNewValue());
220: // assertEquals("focusOwner", event.getPropertyName());
221: // //verify that change wasn't vetoed:
222: // assertSame(comp, kfm.getFocusOwner());
223: // //test vetoed property change:
224: // Frame f = new Frame();
225: // vlistenerCalled = false;
226: // event = null;
227: // kfm.setGlobalActiveWindow(f);
228: // assertTrue(vlistenerCalled);
229: // assertNotNull(event);
230: // //check first that vetoed change was reported to listener:
231: // assertSame(f, vetoedEvent.getNewValue());
232: // assertNull(vetoedEvent.getOldValue());
233: // assertEquals("activeWindow", vetoedEvent.getPropertyName());
234: // //then check that the last change was
235: // //back to old value:
236: // assertSame(f, event.getOldValue());
237: // assertNull(event.getNewValue());
238: // assertEquals("activeWindow", event.getPropertyName());
239: // //verify that the change was vetoed:
240: // assertNull(kfm.getActiveWindow());
241: // //verify removal of listener:
242: // vlistenerCalled = false;
243: // event = vetoedEvent = null;
244: // kfm.removeVetoableChangeListener(null);
245: // listeners = kfm.getVetoableChangeListeners();
246: // assertEquals(1, listeners.length);
247: // assertSame(vlistener, listeners[0]);
248: // kfm.removeVetoableChangeListener(new VetoableChangeListenerProxy("q",
249: // vlistener));
250: // listeners = kfm.getVetoableChangeListeners();
251: // assertEquals(1, listeners.length);
252: // assertSame(vlistener, listeners[0]);
253: // kfm.removeVetoableChangeListener(vlistener);
254: // listeners = kfm.getVetoableChangeListeners();
255: // assertEquals(0, listeners.length);
256: // kfm.setGlobalActiveWindow(f);
257: // assertFalse(vlistenerCalled);
258: // assertSame(f, kfm.getActiveWindow());
259: //
260: // }
261: /*
262: * Class under test for void addVetoableChangeListener(java.lang.String,
263: * java.beans.VetoableChangeListener)
264: */
265: public final void testAddRemoveVetoableChangeListenerString() {
266: assertNotNull(kfm);
267: String propName = "focusedWindow";
268: kfm.addVetoableChangeListener(propName, vlistener);
269: VetoableChangeListener[] listeners = kfm
270: .getVetoableChangeListeners(propName);
271: assertNotNull(listeners);
272: int len = listeners.length;
273: assertEquals(1, len);
274: assertSame(vlistener, listeners[0]);
275: assertFalse(vlistenerCalled);
276: Frame f = new Frame();
277: kfm.setGlobalActiveWindow(f);
278: assertFalse(vlistenerCalled);
279: assertSame(f, kfm.getActiveWindow());
280: kfm.setGlobalFocusedWindow(f);
281: assertTrue(vlistenerCalled);
282: assertNotNull(event);
283: assertSame(kfm, event.getSource());
284: assertNull(event.getOldValue());
285: assertSame(f, event.getNewValue());
286: assertEquals(propName, event.getPropertyName());
287: assertSame(f, kfm.getFocusedWindow());
288: vlistenerCalled = false;
289: event = vetoedEvent = null;
290: kfm.removeVetoableChangeListener("q", vlistener);
291: listeners = kfm.getVetoableChangeListeners(propName);
292: assertNotNull(listeners);
293: assertEquals(1, listeners.length);
294: kfm.removeVetoableChangeListener(propName, vlistener);
295: listeners = kfm.getVetoableChangeListeners(propName);
296: assertNotNull(listeners);
297: assertEquals(0, listeners.length);
298: kfm.setGlobalFocusedWindow(null);
299: assertFalse(vlistenerCalled);
300: assertNull(kfm.getFocusedWindow());
301: kfm.setGlobalActiveWindow(null);
302: assertFalse(vlistenerCalled);
303: assertNull(kfm.getActiveWindow());
304: propName = "activeWindow";
305: kfm.addVetoableChangeListener(propName, vlistener);
306: listeners = kfm.getVetoableChangeListeners(propName);
307: assertNotNull(listeners);
308: assertEquals(1, listeners.length);
309: kfm.setGlobalActiveWindow(f);
310: assertTrue(vlistenerCalled);
311: assertNull(kfm.getActiveWindow());
312: }
313:
314: /*
315: * Class under test for java.beans.PropertyChangeListener[]
316: * getPropertyChangeListeners()
317: */
318: public final void testGetPropertyChangeListeners() {
319: PropertyChangeListener[] listeners = kfm
320: .getPropertyChangeListeners();
321: assertNotNull(listeners);
322: assertEquals(0, listeners.length);
323: kfm.addPropertyChangeListener(listener);
324: assertEquals(0, listeners.length);
325: listeners = kfm.getPropertyChangeListeners();
326: assertEquals(1, listeners.length);
327: assertSame(listener, listeners[0]);
328: String propName = "currentFocusCycleRoot";
329: kfm.addPropertyChangeListener(propName, listener);
330: listeners = kfm.getPropertyChangeListeners();
331: assertEquals(2, listeners.length);
332: assertNotSame(listener, listeners[1]);
333: assertTrue(listeners[1] instanceof PropertyChangeListenerProxy);
334: PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) listeners[1];
335: assertEquals(propName, proxy.getPropertyName());
336: assertSame(listener, proxy.getListener());
337: }
338:
339: /*
340: * Class under test for java.beans.PropertyChangeListener[]
341: * getPropertyChangeListeners(java.lang.String)
342: */
343: public final void testGetPropertyChangeListenersString() {
344: String propName = "defaultFocusTraversalPolicy";
345: PropertyChangeListener[] listeners = kfm
346: .getPropertyChangeListeners(propName);
347: assertNotNull(listeners);
348: assertEquals(0, listeners.length);
349:
350: kfm.addPropertyChangeListener("focusedWindow", listener);
351: int len = kfm.getPropertyChangeListeners(propName).length;
352: assertEquals(0, len);
353: kfm.addPropertyChangeListener(propName, listener);
354: listeners = kfm.getPropertyChangeListeners(propName);
355: len = listeners.length;
356: assertEquals(1, len);
357: assertSame(listener, listeners[0]);
358: listeners = kfm.getPropertyChangeListeners("property");
359: assertEquals(0, listeners.length);
360: }
361:
362: /*
363: * Class under test for java.beans.VetoableChangeListener[]
364: * getVetoableChangeListeners(java.lang.String)
365: */
366: public final void testGetVetoableChangeListenersString() {
367: String propName = "permanentFocusOwner";
368: VetoableChangeListener[] listeners = kfm
369: .getVetoableChangeListeners(propName);
370: assertNotNull(listeners);
371: assertEquals(0, listeners.length);
372:
373: kfm.addPropertyChangeListener("focusedWindow", listener);
374: int len = kfm.getVetoableChangeListeners(propName).length;
375: assertEquals(0, len);
376: kfm.addVetoableChangeListener(propName, vlistener);
377: listeners = kfm.getVetoableChangeListeners(propName);
378: len = listeners.length;
379: assertEquals(1, len);
380: assertSame(vlistener, listeners[0]);
381: listeners = kfm.getVetoableChangeListeners("q");
382: assertEquals(0, listeners.length);
383: }
384:
385: /*
386: * Class under test for java.beans.VetoableChangeListener[]
387: * getVetoableChangeListeners()
388: */
389: public final void testGetVetoableChangeListeners() {
390: VetoableChangeListener[] listeners = kfm
391: .getVetoableChangeListeners();
392: assertNotNull(listeners);
393: assertEquals(0, listeners.length);
394: kfm.addVetoableChangeListener(vlistener);
395: assertEquals(0, listeners.length);
396: listeners = kfm.getVetoableChangeListeners();
397: assertEquals(1, listeners.length);
398: assertSame(vlistener, listeners[0]);
399: String propName = "focusOwner";
400: kfm.addVetoableChangeListener(propName, vlistener);
401: listeners = kfm.getVetoableChangeListeners();
402: assertEquals(2, listeners.length);
403: assertNotSame(vlistener, listeners[1]);
404: assertTrue(listeners[1] instanceof VetoableChangeListenerProxy);
405: VetoableChangeListenerProxy proxy = (VetoableChangeListenerProxy) listeners[1];
406: assertEquals(propName, proxy.getPropertyName());
407: assertSame(vlistener, proxy.getListener());
408: }
409:
410: /*
411: * Class under test for void removePropertyChangeListener(java.lang.String,
412: * java.beans.PropertyChangeListener)
413: */
414: public final void testRemovePropertyChangeListenerString() {
415: String propName = "forwardDefaultFocusTraversalKeys";
416: kfm.removePropertyChangeListener(propName, null);
417: PropertyChangeListener[] listeners = kfm
418: .getPropertyChangeListeners(propName);
419: assertNotNull(listeners);
420: assertEquals(0, listeners.length);
421: kfm.addPropertyChangeListener(propName, listener);
422: listeners = kfm.getPropertyChangeListeners(propName);
423: assertEquals(1, listeners.length);
424: Set<AWTKeyStroke> forSet = new HashSet<AWTKeyStroke>();
425: forSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
426: kfm.setDefaultFocusTraversalKeys(
427: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forSet);
428: assertTrue(listenerCalled);
429: listenerCalled = false;
430: kfm.removePropertyChangeListener("property", listener);
431: listeners = kfm.getPropertyChangeListeners(propName);
432: assertEquals(1, listeners.length);
433: kfm.removePropertyChangeListener(propName, listener);
434: listeners = kfm.getPropertyChangeListeners(propName);
435: assertEquals(0, listeners.length);
436: forSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER,
437: InputEvent.CTRL_DOWN_MASK));
438: kfm.setDefaultFocusTraversalKeys(
439: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forSet);
440: assertFalse(listenerCalled);
441: }
442:
443: /*
444: * Class under test for void
445: * removePropertyChangeListener(java.beans.PropertyChangeListener)
446: */
447: // public final void testRemovePropertyChangeListener() {
448: // String propName = "backwardDefaultFocusTraversalKeys";
449: // kfm.removePropertyChangeListener(listener);
450: // PropertyChangeListener[] listeners = kfm.getPropertyChangeListeners();
451: // assertNotNull(listeners);
452: // assertEquals(0, listeners.length);
453: // kfm.addPropertyChangeListener(propName, listener);
454: // listeners = kfm.getPropertyChangeListeners();
455: // assertEquals(1, listeners.length);
456: // Set backSet = new HashSet();
457: // backSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_SPACE,
458: // KeyEvent.CTRL_DOWN_MASK));
459: // kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
460: // backSet);
461: // assertTrue(listenerCalled);
462: // listenerCalled = false;
463: // kfm.removePropertyChangeListener(listeners[0]);
464: // listeners = kfm.getPropertyChangeListeners();
465: // assertEquals(0, listeners.length);
466: // backSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_SPACE, 0));
467: // kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
468: // backSet);
469: // assertFalse(listenerCalled);
470: // kfm.addPropertyChangeListener(listener);
471: // listeners = kfm.getPropertyChangeListeners();
472: // assertEquals(1, listeners.length);
473: // kfm.firePropertyChange("property", new Integer(0), new Integer(1));
474: // assertTrue(listenerCalled);
475: // listenerCalled = false;
476: // kfm.removePropertyChangeListener(listener);
477: // listeners = kfm.getPropertyChangeListeners();
478: // assertEquals(0, listeners.length);
479: // kfm.firePropertyChange("property", new Integer(1), new Integer(0));
480: // assertFalse(listenerCalled);
481: //
482: // }
483: public final void testSetCurrentKeyboardFocusManager() {
484: String propName = "managingFocus";
485: PropertyChangeListener newListener = new PropertyChangeListener() {
486:
487: public void propertyChange(PropertyChangeEvent e) {
488: newListenerCalled = true;
489: newEvent = e;
490: }
491:
492: };
493:
494: KeyboardFocusManager oldFocusManager = KeyboardFocusManager
495: .getCurrentKeyboardFocusManager();
496: assertNotSame(oldFocusManager, kfm);
497: oldFocusManager.addPropertyChangeListener(propName, listener);
498: kfm.addPropertyChangeListener(propName, newListener);
499: KeyboardFocusManager.setCurrentKeyboardFocusManager(kfm);
500: assertSame(KeyboardFocusManager
501: .getCurrentKeyboardFocusManager(), kfm);
502: assertTrue(listenerCalled);
503: assertNotNull(event);
504: assertSame(event.getSource(), oldFocusManager);
505: assertEquals(propName, event.getPropertyName());
506: assertEquals(event.getOldValue(), new Boolean(true));
507: assertEquals(event.getNewValue(), new Boolean(false));
508: assertTrue(newListenerCalled);
509: assertNotNull(newEvent);
510: assertSame(newEvent.getSource(), kfm);
511: assertEquals(propName, newEvent.getPropertyName());
512: assertEquals(newEvent.getOldValue(), new Boolean(false));
513: assertEquals(newEvent.getNewValue(), new Boolean(true));
514: }
515:
516: public void testSetDefaultFocusTraversalKeys() {
517: final KeyboardFocusManager mgr = new DefaultKeyboardFocusManager();
518: Set<AWTKeyStroke> s;
519: Set<AWTKeyStroke> s1;
520:
521: try {
522: mgr.setDefaultFocusTraversalKeys(-1, createSet());
523: } catch (IllegalArgumentException ex) {
524: // expected
525: }
526:
527: try {
528: mgr.setDefaultFocusTraversalKeys(
529: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
530: } catch (IllegalArgumentException ex) {
531: // expected
532: }
533:
534: try {
535: mgr.setDefaultFocusTraversalKeys(
536: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
537: createSet((AWTKeyStroke) null));
538: } catch (IllegalArgumentException ex) {
539: // expected
540: }
541:
542: try {
543: mgr.setDefaultFocusTraversalKeys(
544: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
545: createSet(AWTKeyStroke.getAWTKeyStroke(
546: KeyEvent.KEY_TYPED, 0)));
547: } catch (IllegalArgumentException ex) {
548: // expected
549: }
550:
551: try {
552: mgr.setDefaultFocusTraversalKeys(
553: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
554: createSet(AWTKeyStroke.getAWTKeyStroke(
555: KeyEvent.VK_TAB, 0)));
556: } catch (IllegalArgumentException ex) {
557: // expected
558: }
559:
560: s = createSet(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
561: s1 = mgr
562: .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
563: mgr.addPropertyChangeListener(listener);
564: mgr.setDefaultFocusTraversalKeys(
565: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, s);
566: assertEquals(
567: s,
568: mgr
569: .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
570: assertNotNull(event);
571: assertSame(s, event.getNewValue());
572: assertSame(s1, event.getOldValue());
573: }
574:
575: public void testGetDefaultFocusTraversalKeys() {
576: final KeyboardFocusManager mgr = new DefaultKeyboardFocusManager();
577:
578: assertNotNull(mgr
579: .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
580: assertNotNull(mgr
581: .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
582: assertNotNull(mgr
583: .getDefaultFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS));
584: assertNotNull(mgr
585: .getDefaultFocusTraversalKeys(KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS));
586:
587: assertEquals(
588: createSet(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
589: 0), AWTKeyStroke.getAWTKeyStroke(
590: KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK)),
591: mgr
592: .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
593: assertEquals(
594: createSet(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
595: InputEvent.SHIFT_DOWN_MASK), AWTKeyStroke
596: .getAWTKeyStroke(KeyEvent.VK_TAB,
597: InputEvent.SHIFT_DOWN_MASK
598: | InputEvent.CTRL_DOWN_MASK)),
599: mgr
600: .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
601: assertTrue(mgr.getDefaultFocusTraversalKeys(
602: KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS).isEmpty());
603: assertTrue(mgr.getDefaultFocusTraversalKeys(
604: KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS)
605: .isEmpty());
606:
607: try {
608: mgr.getDefaultFocusTraversalKeys(
609: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS).add(
610: null);
611: fail("UnsupportedOperationException was not thrown"); //$NON-NLS-1$
612: } catch (UnsupportedOperationException ex) {
613: // expected
614: }
615: }
616:
617: private static Set<AWTKeyStroke> createSet(
618: final AWTKeyStroke... keystrokes) {
619: final Set<AWTKeyStroke> s = new LinkedHashSet<AWTKeyStroke>();
620:
621: for (AWTKeyStroke stroke : keystrokes) {
622: s.add(stroke);
623: }
624: return s;
625: }
626: }
|