01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Anton Avtamonov
19: * @version $Revision$
20: */package javax.swing;
21:
22: import java.awt.Component;
23: import java.awt.Container;
24: import java.awt.DefaultFocusTraversalPolicy;
25: import java.awt.FocusTraversalPolicy;
26: import java.awt.KeyboardFocusManager;
27: import junit.framework.TestCase;
28:
29: public class FocusManagerTest extends TestCase {
30: public FocusManagerTest(final String name) {
31: super (name);
32: }
33:
34: @Override
35: protected void setUp() throws Exception {
36: KeyboardFocusManager.getCurrentKeyboardFocusManager()
37: .setDefaultFocusTraversalPolicy(new TestPolicy());
38: }
39:
40: public void testGetSetCurrentManager() throws Exception {
41: FocusManager m = new FocusManager() {
42: };
43: FocusManager.setCurrentManager(m);
44: assertEquals(m, KeyboardFocusManager
45: .getCurrentKeyboardFocusManager());
46: }
47:
48: public void testIsFocusManagerEnabled() throws Exception {
49: assertTrue(FocusManager.isFocusManagerEnabled());
50: assertFalse(KeyboardFocusManager
51: .getCurrentKeyboardFocusManager()
52: .getDefaultFocusTraversalPolicy() instanceof DefaultFocusTraversalPolicy);
53: FocusManager.disableSwingFocusManager();
54: assertFalse(FocusManager.isFocusManagerEnabled());
55: assertTrue(KeyboardFocusManager
56: .getCurrentKeyboardFocusManager()
57: .getDefaultFocusTraversalPolicy() instanceof DefaultFocusTraversalPolicy);
58: }
59:
60: private class TestPolicy extends FocusTraversalPolicy {
61: @Override
62: public Component getComponentAfter(final Container a0,
63: final Component a1) {
64: return null;
65: }
66:
67: @Override
68: public Component getComponentBefore(final Container a0,
69: final Component a1) {
70: return null;
71: }
72:
73: @Override
74: public Component getDefaultComponent(final Container a0) {
75: return null;
76: }
77:
78: @Override
79: public Component getFirstComponent(final Container a0) {
80: return null;
81: }
82:
83: @Override
84: public Component getLastComponent(final Container a0) {
85: return null;
86: }
87: }
88: }
|