KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > tabcontrol > plaf > TabStateTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.swing.tabcontrol.plaf;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24 import junit.framework.TestCase;
25
26 /**
27  *
28  * @author tim
29  */

30 public class TabStateTest extends TestCase {
31
32     public TabStateTest(String JavaDoc testName) {
33         super(testName);
34     }
35
36     private TS ts = null;
37     public void setUp() {
38         ts = new TS();
39     }
40
41 /*
42         public static final int TabState.REPAINT_ON_MOUSE_ENTER_TAB = 1;
43         public static final int REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA = 3;
44         public static final int TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON = 4;
45         public static final int TabState.REPAINT_ON_MOUSE_PRESSED = 8;
46         public static final int REPAINT_SELECTION_ON_ACTIVATION_CHANGE = 16;
47         public static final int REPAINT_ALL_TABS_ON_ACTIVATION_CHANGE = 32; //includes selection
48         public static final int TabState.REPAINT_ON_SELECTION_CHANGE = 64;
49         public static final int REPAINT_ALL_TABS_ON_SELECTION_CHANGE = 192;
50         public static final int TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED = 256;
51  */

52     
53     /**
54      * Test of setPressed method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
55      */

56     public void testSetPressed() {
57         System.out.println("testSetPressed");
58         
59         policy = 0;
60         ts.setPressed (5);
61         ts.assertChange("Initial set of selected index should trigger a call to change");
62         ts.assertNoTabsRepainted("No tabs should have been repainted with a 0 policy, after pressing a tab");
63         
64         policy = TabState.REPAINT_ON_MOUSE_PRESSED;
65         ts.setPressed (6);
66 // ts.assertTabRepainted("With policy TabState.REPAINT_ON_MOUSE_PRESSED, pressing tab 6 should generate a repaint of only tab 6", 6);
67
ts.assertChange ("Changing index from 5 to 6 should cause a call to change");
68         
69         policy = TabState.REPAINT_ON_MOUSE_PRESSED | TabState.REPAINT_ON_SELECTION_CHANGE | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED;
70     }
71     
72     /**
73      * Test of setContainsMouse method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
74      */

75     public void testSetContainsMouse() {
76         System.out.println("testSetContainsMouse");
77         
78     }
79     
80     /**
81      * Test of setCloseButtonContainsMouse method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
82      */

83     public void testSetCloseButtonContainsMouse() {
84         System.out.println("testSetCloseButtonContainsMouse");
85         
86     }
87     
88     /**
89      * Test of setMousePressedInCloseButton method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
90      */

91     public void testSetMousePressedInCloseButton() {
92         System.out.println("testSetMousePressedInCloseButton");
93         
94     }
95     
96     /**
97      * Test of setSelected method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
98      */

99     public void testSetSelected() {
100         System.out.println("testSetSelected");
101         
102     }
103     
104     /**
105      * Test of setMouseInTabsArea method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
106      */

107     public void testSetMouseInTabsArea() {
108         System.out.println("testSetMouseInTabsArea");
109         
110     }
111     
112     /**
113      * Test of setActive method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
114      */

115     public void testSetActive() {
116         System.out.println("testSetActive");
117         
118     }
119     
120     /**
121      * Test of clearTransientStates method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
122      */

123     public void testClearTransientStates() {
124         System.out.println("testClearTransientStates");
125         
126     }
127     
128     
129     private class TS extends TabState {
130         private int possibleChangeLastTab = Integer.MIN_VALUE;
131         private int possibleChangeCurrTab = Integer.MIN_VALUE;
132         private int possibleChangeType = Integer.MIN_VALUE;
133         private Boolean JavaDoc possibleChangePrevValue = null;
134         private Boolean JavaDoc possibleChangeCurrValue = null;
135         private int possibleChangeBoolType = Integer.MIN_VALUE;
136
137         
138         private void clear() {
139             possibleChangeLastTab = Integer.MIN_VALUE;
140             possibleChangeCurrTab = Integer.MIN_VALUE;
141             possibleChangeType = Integer.MIN_VALUE;
142             possibleChangePrevValue = null;
143             possibleChangeCurrValue = null;
144             possibleChangeBoolType = Integer.MIN_VALUE;
145         }
146         
147         public void assertPossibleChange (String JavaDoc msg) {
148             int _possibleChangeLastTab = possibleChangeLastTab;
149             int _possibleChangeCurrTab = possibleChangeCurrTab;
150             int _possibleChangeType = possibleChangeType;
151             Boolean JavaDoc _possibleChangePrevValue = possibleChangePrevValue;
152             Boolean JavaDoc _possibleChangeCurrValue = possibleChangeCurrValue;
153             int _possibleChangeBoolType = possibleChangeBoolType;
154             clear();
155             
156             if (_possibleChangeLastTab == Integer.MIN_VALUE && _possibleChangePrevValue == null) {
157                 fail ("no event occured - " + msg);
158             }
159         }
160         
161         public void assertPossibleChange (String JavaDoc msg, int lastTab, int currTab, int type) {
162             int _possibleChangeLastTab = possibleChangeLastTab;
163             int _possibleChangeCurrTab = possibleChangeCurrTab;
164             int _possibleChangeType = possibleChangeType;
165             Boolean JavaDoc _possibleChangePrevValue = possibleChangePrevValue;
166             Boolean JavaDoc _possibleChangeCurrValue = possibleChangeCurrValue;
167             int _possibleChangeBoolType = possibleChangeBoolType;
168             clear();
169             
170             if (_possibleChangeLastTab == Integer.MIN_VALUE || _possibleChangeLastTab == Integer.MIN_VALUE) {
171                 fail ("no event occurred - " + msg);
172             }
173             
174             if (_possibleChangeLastTab != lastTab || _possibleChangeCurrTab != currTab || _possibleChangeType != type) {
175                 fail ("wrong event occured - " + msg + " lastTab " + _possibleChangeLastTab + " currTab " + _possibleChangeCurrTab + " type " + _possibleChangeType);
176             }
177         }
178         
179
180         public void assertPossibleChange (String JavaDoc msg, boolean prevVal, boolean currVal, int type) {
181             int _possibleChangeLastTab = possibleChangeLastTab;
182             int _possibleChangeCurrTab = possibleChangeCurrTab;
183             int _possibleChangeType = possibleChangeType;
184             Boolean JavaDoc _possibleChangePrevValue = possibleChangePrevValue;
185             Boolean JavaDoc _possibleChangeCurrValue = possibleChangeCurrValue;
186             int _possibleChangeBoolType = possibleChangeBoolType;
187             clear();
188             if (_possibleChangePrevValue == null || _possibleChangeCurrValue == null) {
189                 fail ("no event occured - " + msg);
190             }
191             
192             if (_possibleChangePrevValue.booleanValue() != prevVal || _possibleChangeCurrValue.booleanValue() != currVal || _possibleChangeBoolType != type) {
193                 fail ("wrong event occured - " + msg + " prevVal: " + _possibleChangePrevValue + " currVal " + _possibleChangeCurrValue + " type " + _possibleChangeBoolType);
194             }
195         }
196         
197         protected void possibleChange(int lastTab, int currTab, int type) {
198             possibleChangeLastTab = lastTab;
199             possibleChangeCurrTab = currTab;
200             possibleChangeType = type;
201             super.possibleChange (lastTab, currTab, type);
202         }
203         
204         protected void possibleChange(boolean prevVal, boolean currVal, int type) {
205             possibleChangePrevValue = prevVal ? Boolean.TRUE : Boolean.FALSE;
206             possibleChangeCurrValue = prevVal ? Boolean.TRUE : Boolean.FALSE;
207             possibleChangeBoolType = type;
208             super.possibleChange (prevVal, currVal, type);
209         }
210         
211         private int repaintTabInt = Integer.MAX_VALUE;
212         private Set JavaDoc repaintedTabs = null;
213         
214         public void assertNoTabsRepainted(String JavaDoc msg) {
215             if (repaintedTabs != null) {
216                 fail ("Tabs were repainted: " + repaintedTabs);
217             }
218             assertAllTabsNotRepainted(msg);
219         }
220         
221         private void assertTabRepainted (String JavaDoc msg, int tab) {
222             if (repaintedTabs == null) {
223                 fail ("No tabs repainted - " + msg);
224             }
225             Set JavaDoc set = new HashSet JavaDoc (repaintedTabs);
226             repaintedTabs = null;
227             assertTrue ("Number of tabs repainted should be 1 but is " + set.size() + " - contents: " + set, set.size() == 1);
228             Integer JavaDoc in = (Integer JavaDoc) set.iterator().next();
229             assertTrue ("Wrong tab repainted - should be " + tab + " but is " + in + " - " + msg, in.intValue() == tab);
230         }
231         
232         private void assertTabsRepainted (String JavaDoc msg, int[] tabs) {
233             if (repaintedTabs == null) {
234                 fail ("No tabs repainted - " + msg );
235             }
236             Set JavaDoc set = new HashSet JavaDoc (repaintedTabs);
237             repaintedTabs = null;
238             for (int i=0; i < tabs.length; i++) {
239                 if (!set.contains(new Integer JavaDoc(tabs[i]))) {
240                     fail (msg + " Tab " + tabs[i] + " was not repainted - repainted tabs were " + set);
241                 }
242             }
243         }
244         
245         protected void repaintTab(int tab) {
246             if (repaintedTabs == null) {
247                 repaintedTabs = new HashSet JavaDoc();
248             }
249             repaintedTabs.add (new Integer JavaDoc(tab));
250         }
251         
252         public void assertAllTabsRepainted(String JavaDoc msg) {
253             Boolean JavaDoc b = allTabsRepainted;
254             allTabsRepainted = null;
255             assertTrue ("repaintAllTabs not called - " + msg, b.booleanValue());
256         }
257         
258         public void assertAllTabsNotRepainted (String JavaDoc msg) {
259             assertTrue ("All tabs repainted - " + msg, allTabsRepainted == null);
260         }
261         
262         private Boolean JavaDoc allTabsRepainted = null;
263         protected void repaintAllTabs() {
264             allTabsRepainted = Boolean.TRUE;
265         }
266         
267         private int changeLastTab = Integer.MIN_VALUE;
268         private int changeCurrTab = Integer.MIN_VALUE;
269         private int changeType = Integer.MIN_VALUE;
270         private int typeOfChange = Integer.MIN_VALUE;
271         
272         public void assertChange (String JavaDoc msg) {
273             if (changeLastTab == Integer.MIN_VALUE || changeCurrTab == Integer.MIN_VALUE || changeType == Integer.MIN_VALUE || typeOfChange == Integer.MIN_VALUE) {
274                 fail ("Change not called - " + msg);
275             }
276         }
277         
278         public void assertNoChange (String JavaDoc msg) {
279             if (changeLastTab == Integer.MIN_VALUE || changeCurrTab == Integer.MIN_VALUE || changeType == Integer.MIN_VALUE || typeOfChange == Integer.MIN_VALUE) {
280                 
281             } else {
282                 fail (msg);
283             }
284         }
285         
286         public void assertChange (String JavaDoc msg, int lastTab, int currTab) {
287             assertChange (msg);
288             if (lastTab != changeLastTab || currTab != changeCurrTab) {
289                 fail (msg + " - Wrong arguments for call to change: " + "lastTab " + changeLastTab + " currTab " + changeCurrTab);
290             }
291             changeLastTab = Integer.MIN_VALUE;
292             changeCurrTab = Integer.MIN_VALUE;
293             typeOfChange = Integer.MIN_VALUE;
294             changeType = Integer.MIN_VALUE;
295         }
296         
297         public void assertChange (String JavaDoc msg, int lastTab, int currTab, int type, int cType) {
298             int t = changeType;
299             int tc = typeOfChange;
300             assertChange (msg, lastTab, currTab);
301             if (type != t || tc != cType) {
302                 fail (msg + " - Wrong arguments for call to change: " + stateToString (t) + " - " + changeToString(cType));
303             }
304         }
305         
306         
307         protected void change(int lastTab, int currTab, int type, int changeType) {
308             changeLastTab = lastTab;
309             changeCurrTab = currTab;
310             typeOfChange = type;
311             this.changeType = changeType;
312             super.change (lastTab, currTab, type, changeType);
313         }
314
315         public int getRepaintPolicy(int tab) {
316             return policy;
317         }
318     }
319     
320     private int policy = 0;
321 }
322
Popular Tags