001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import junit.framework.TestCase;
023:
024: @SuppressWarnings("serial")
025: public class ContainerOrderFocusTraversalPolicyTest extends TestCase {
026: Frame frame;
027: SimpleComponent comp1, comp2, comp3;
028: SimpleContainer cont1;
029: ContainerOrderFocusTraversalPolicy policy;
030:
031: public class SimpleContainer extends Container {
032: }
033:
034: public class SimpleComponent extends Component {
035: }
036:
037: @Override
038: protected void setUp() throws Exception {
039: super .setUp();
040: frame = new Frame();
041: policy = new ContainerOrderFocusTraversalPolicy();
042: comp1 = new SimpleComponent();
043: comp2 = new SimpleComponent();
044: comp3 = new SimpleComponent();
045: cont1 = new SimpleContainer();
046: }
047:
048: @Override
049: protected void tearDown() throws Exception {
050: super .tearDown();
051: if (frame != null) {
052: frame.dispose();
053: }
054: }
055:
056: public final void testGetComponentAfter() {
057: assertNotNull(frame);
058: assertNotNull(comp1);
059: assertNull(policy.getComponentAfter(frame, frame));
060: frame.setVisible(true);
061: assertSame(frame, policy.getComponentAfter(frame, frame));
062: frame.add(comp1);
063: assertSame(comp1, policy.getComponentAfter(frame, frame));
064: assertSame(frame, policy.getComponentAfter(frame, comp1));
065: comp1.setEnabled(false);
066: assertSame(frame, policy.getComponentAfter(frame, comp1));
067: assertSame(frame, policy.getComponentAfter(frame, frame));
068: assertNotNull(cont1);
069: frame.add(cont1);
070: assertNotNull(comp2);
071: cont1.add(comp2);
072: assertSame(frame, policy.getComponentAfter(frame, comp2));
073: assertNotNull(comp3);
074: frame.add(comp3);
075: assertSame(comp3, policy.getComponentAfter(frame, comp2));
076: assertSame(cont1, policy.getComponentAfter(frame, frame));
077: assertSame(cont1, policy.getComponentAfter(frame, comp1));
078: assertSame(comp2, policy.getComponentAfter(frame, cont1));
079: }
080:
081: public final void testGetComponentBefore() {
082: assertNotNull(frame);
083: assertNotNull(comp1);
084: assertNull(policy.getComponentBefore(frame, frame));
085: frame.setVisible(true);
086: assertSame(frame, policy.getComponentBefore(frame, frame));
087: frame.add(comp1);
088: assertSame(comp1, policy.getComponentBefore(frame, frame));
089: assertSame(frame, policy.getComponentBefore(frame, comp1));
090: comp1.setEnabled(false);
091: assertSame(frame, policy.getComponentBefore(frame, comp1));
092: assertSame(frame, policy.getComponentBefore(frame, frame));
093: assertNotNull(cont1);
094: frame.add(cont1);
095: assertNotNull(comp2);
096: cont1.add(comp2);
097: assertNotNull(comp3);
098: frame.add(comp3);
099: assertSame(comp2, policy.getComponentBefore(frame, comp3));
100: assertSame(cont1, policy.getComponentBefore(frame, comp2));
101: assertSame(frame, policy.getComponentBefore(frame, cont1));
102: assertSame(frame, policy.getComponentBefore(frame, comp1));
103: assertSame(comp3, policy.getComponentBefore(frame, frame));
104: }
105:
106: public final void testGetDefaultComponent() {
107: assertNotNull(frame);
108: assertSame(policy.getFirstComponent(frame), policy
109: .getDefaultComponent(frame));
110: }
111:
112: public final void testGetFirstComponent() {
113: assertNotNull(frame);
114: assertNotNull(comp1);
115: frame.add(comp1);
116: assertNull(policy.getFirstComponent(frame));
117: frame.setVisible(true);
118: assertSame(frame, policy.getFirstComponent(frame));
119: frame.setFocusable(false);
120: assertSame(comp1, policy.getFirstComponent(frame));
121: frame.setEnabled(false);
122: assertNull(policy.getFirstComponent(frame));
123: frame.setEnabled(true);
124: assertNotNull(comp2);
125: frame.add(comp2);
126: comp1.setEnabled(false);
127: assertSame(comp2, policy.getFirstComponent(frame));
128: }
129:
130: public final void testGetLastComponent() {
131: assertNotNull(frame);
132: assertNotNull(comp1);
133: frame.add(comp1);
134: assertNull(policy.getLastComponent(frame));
135: frame.setVisible(true);
136: assertSame(comp1, policy.getLastComponent(frame));
137: frame.setFocusable(false);
138: assertSame(comp1, policy.getLastComponent(frame));
139: frame.setEnabled(false);
140: assertNull(policy.getLastComponent(frame));
141: frame.setEnabled(true);
142: assertNotNull(comp2);
143: frame.add(comp2);
144: //comp1.setEnabled(false);
145: assertSame(comp2, policy.getLastComponent(frame));
146: comp2.setVisible(false);
147: assertSame(comp1, policy.getLastComponent(frame));
148: comp1.setFocusable(false);
149: frame.setFocusable(true);
150: assertSame(frame, policy.getLastComponent(frame));
151: }
152:
153: public final void testAccept() {
154: assertNotNull(comp1);
155: assertFalse(policy.accept(comp1));
156: frame.add(comp1);
157: assertFalse(policy.accept(comp1));
158: frame.setVisible(true);
159: assertTrue(policy.accept(comp1));
160: comp1.setEnabled(false);
161: assertFalse(policy.accept(comp1));
162: comp1.setEnabled(true);
163: assertTrue(policy.accept(comp1));
164: comp1.setFocusable(false);
165: assertFalse(policy.accept(comp1));
166: comp1.setFocusable(true);
167: assertTrue(policy.accept(comp1));
168: comp1.setVisible(false);
169: assertFalse(policy.accept(comp1));
170: comp1.setVisible(true);
171: assertTrue(policy.accept(comp1));
172: }
173:
174: public final void testGetImplicitDownCycleTraversal() {
175: assertTrue(policy.getImplicitDownCycleTraversal());
176: assertNotNull(comp1);
177: assertNotNull(cont1);
178: cont1.add(comp1);
179: frame.add(cont1);
180: frame.setVisible(true);
181: cont1.setFocusCycleRoot(true);
182: cont1.setFocusTraversalPolicy(policy);
183: Component expectedComp = policy.getDefaultComponent(cont1);
184: assertSame(expectedComp, policy.getComponentAfter(frame, cont1));
185: }
186:
187: public final void testSetImplicitDownCycleTraversal() {
188: policy.setImplicitDownCycleTraversal(false);
189: assertFalse(policy.getImplicitDownCycleTraversal());
190: assertNotNull(comp1);
191: assertNotNull(cont1);
192: cont1.add(comp1);
193: frame.add(cont1);
194: frame.setVisible(true);
195: cont1.setFocusCycleRoot(true);
196: cont1.setFocusTraversalPolicy(policy);
197: Component expectedComp = frame;
198: assertSame(expectedComp, policy.getComponentAfter(frame, cont1));
199: }
200:
201: }
|