001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.swing.tabcontrol.plaf;
043:
044: import java.util.HashSet;
045: import java.util.Set;
046: import junit.framework.TestCase;
047:
048: /**
049: *
050: * @author tim
051: */
052: public class TabStateTest extends TestCase {
053:
054: public TabStateTest(String testName) {
055: super (testName);
056: }
057:
058: private TS ts = null;
059:
060: public void setUp() {
061: ts = new TS();
062: }
063:
064: /*
065: public static final int TabState.REPAINT_ON_MOUSE_ENTER_TAB = 1;
066: public static final int REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA = 3;
067: public static final int TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON = 4;
068: public static final int TabState.REPAINT_ON_MOUSE_PRESSED = 8;
069: public static final int REPAINT_SELECTION_ON_ACTIVATION_CHANGE = 16;
070: public static final int REPAINT_ALL_TABS_ON_ACTIVATION_CHANGE = 32; //includes selection
071: public static final int TabState.REPAINT_ON_SELECTION_CHANGE = 64;
072: public static final int REPAINT_ALL_TABS_ON_SELECTION_CHANGE = 192;
073: public static final int TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED = 256;
074: */
075:
076: /**
077: * Test of setPressed method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
078: */
079: public void testSetPressed() {
080: System.out.println("testSetPressed");
081:
082: policy = 0;
083: ts.setPressed(5);
084: ts
085: .assertChange("Initial set of selected index should trigger a call to change");
086: ts
087: .assertNoTabsRepainted("No tabs should have been repainted with a 0 policy, after pressing a tab");
088:
089: policy = TabState.REPAINT_ON_MOUSE_PRESSED;
090: ts.setPressed(6);
091: // ts.assertTabRepainted("With policy TabState.REPAINT_ON_MOUSE_PRESSED, pressing tab 6 should generate a repaint of only tab 6", 6);
092: ts
093: .assertChange("Changing index from 5 to 6 should cause a call to change");
094:
095: policy = TabState.REPAINT_ON_MOUSE_PRESSED
096: | TabState.REPAINT_ON_SELECTION_CHANGE
097: | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED;
098: }
099:
100: /**
101: * Test of setContainsMouse method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
102: */
103: public void testSetContainsMouse() {
104: System.out.println("testSetContainsMouse");
105:
106: }
107:
108: /**
109: * Test of setCloseButtonContainsMouse method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
110: */
111: public void testSetCloseButtonContainsMouse() {
112: System.out.println("testSetCloseButtonContainsMouse");
113:
114: }
115:
116: /**
117: * Test of setMousePressedInCloseButton method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
118: */
119: public void testSetMousePressedInCloseButton() {
120: System.out.println("testSetMousePressedInCloseButton");
121:
122: }
123:
124: /**
125: * Test of setSelected method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
126: */
127: public void testSetSelected() {
128: System.out.println("testSetSelected");
129:
130: }
131:
132: /**
133: * Test of setMouseInTabsArea method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
134: */
135: public void testSetMouseInTabsArea() {
136: System.out.println("testSetMouseInTabsArea");
137:
138: }
139:
140: /**
141: * Test of setActive method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
142: */
143: public void testSetActive() {
144: System.out.println("testSetActive");
145:
146: }
147:
148: /**
149: * Test of clearTransientStates method, of class org.netbeans.swing.tabcontrol.plaf.TabState.
150: */
151: public void testClearTransientStates() {
152: System.out.println("testClearTransientStates");
153:
154: }
155:
156: private class TS extends TabState {
157: private int possibleChangeLastTab = Integer.MIN_VALUE;
158: private int possibleChangeCurrTab = Integer.MIN_VALUE;
159: private int possibleChangeType = Integer.MIN_VALUE;
160: private Boolean possibleChangePrevValue = null;
161: private Boolean possibleChangeCurrValue = null;
162: private int possibleChangeBoolType = Integer.MIN_VALUE;
163:
164: private void clear() {
165: possibleChangeLastTab = Integer.MIN_VALUE;
166: possibleChangeCurrTab = Integer.MIN_VALUE;
167: possibleChangeType = Integer.MIN_VALUE;
168: possibleChangePrevValue = null;
169: possibleChangeCurrValue = null;
170: possibleChangeBoolType = Integer.MIN_VALUE;
171: }
172:
173: public void assertPossibleChange(String msg) {
174: int _possibleChangeLastTab = possibleChangeLastTab;
175: int _possibleChangeCurrTab = possibleChangeCurrTab;
176: int _possibleChangeType = possibleChangeType;
177: Boolean _possibleChangePrevValue = possibleChangePrevValue;
178: Boolean _possibleChangeCurrValue = possibleChangeCurrValue;
179: int _possibleChangeBoolType = possibleChangeBoolType;
180: clear();
181:
182: if (_possibleChangeLastTab == Integer.MIN_VALUE
183: && _possibleChangePrevValue == null) {
184: fail("no event occured - " + msg);
185: }
186: }
187:
188: public void assertPossibleChange(String msg, int lastTab,
189: int currTab, int type) {
190: int _possibleChangeLastTab = possibleChangeLastTab;
191: int _possibleChangeCurrTab = possibleChangeCurrTab;
192: int _possibleChangeType = possibleChangeType;
193: Boolean _possibleChangePrevValue = possibleChangePrevValue;
194: Boolean _possibleChangeCurrValue = possibleChangeCurrValue;
195: int _possibleChangeBoolType = possibleChangeBoolType;
196: clear();
197:
198: if (_possibleChangeLastTab == Integer.MIN_VALUE
199: || _possibleChangeLastTab == Integer.MIN_VALUE) {
200: fail("no event occurred - " + msg);
201: }
202:
203: if (_possibleChangeLastTab != lastTab
204: || _possibleChangeCurrTab != currTab
205: || _possibleChangeType != type) {
206: fail("wrong event occured - " + msg + " lastTab "
207: + _possibleChangeLastTab + " currTab "
208: + _possibleChangeCurrTab + " type "
209: + _possibleChangeType);
210: }
211: }
212:
213: public void assertPossibleChange(String msg, boolean prevVal,
214: boolean currVal, int type) {
215: int _possibleChangeLastTab = possibleChangeLastTab;
216: int _possibleChangeCurrTab = possibleChangeCurrTab;
217: int _possibleChangeType = possibleChangeType;
218: Boolean _possibleChangePrevValue = possibleChangePrevValue;
219: Boolean _possibleChangeCurrValue = possibleChangeCurrValue;
220: int _possibleChangeBoolType = possibleChangeBoolType;
221: clear();
222: if (_possibleChangePrevValue == null
223: || _possibleChangeCurrValue == null) {
224: fail("no event occured - " + msg);
225: }
226:
227: if (_possibleChangePrevValue.booleanValue() != prevVal
228: || _possibleChangeCurrValue.booleanValue() != currVal
229: || _possibleChangeBoolType != type) {
230: fail("wrong event occured - " + msg + " prevVal: "
231: + _possibleChangePrevValue + " currVal "
232: + _possibleChangeCurrValue + " type "
233: + _possibleChangeBoolType);
234: }
235: }
236:
237: protected void possibleChange(int lastTab, int currTab, int type) {
238: possibleChangeLastTab = lastTab;
239: possibleChangeCurrTab = currTab;
240: possibleChangeType = type;
241: super .possibleChange(lastTab, currTab, type);
242: }
243:
244: protected void possibleChange(boolean prevVal, boolean currVal,
245: int type) {
246: possibleChangePrevValue = prevVal ? Boolean.TRUE
247: : Boolean.FALSE;
248: possibleChangeCurrValue = prevVal ? Boolean.TRUE
249: : Boolean.FALSE;
250: possibleChangeBoolType = type;
251: super .possibleChange(prevVal, currVal, type);
252: }
253:
254: private int repaintTabInt = Integer.MAX_VALUE;
255: private Set repaintedTabs = null;
256:
257: public void assertNoTabsRepainted(String msg) {
258: if (repaintedTabs != null) {
259: fail("Tabs were repainted: " + repaintedTabs);
260: }
261: assertAllTabsNotRepainted(msg);
262: }
263:
264: private void assertTabRepainted(String msg, int tab) {
265: if (repaintedTabs == null) {
266: fail("No tabs repainted - " + msg);
267: }
268: Set set = new HashSet(repaintedTabs);
269: repaintedTabs = null;
270: assertTrue("Number of tabs repainted should be 1 but is "
271: + set.size() + " - contents: " + set,
272: set.size() == 1);
273: Integer in = (Integer) set.iterator().next();
274: assertTrue("Wrong tab repainted - should be " + tab
275: + " but is " + in + " - " + msg,
276: in.intValue() == tab);
277: }
278:
279: private void assertTabsRepainted(String msg, int[] tabs) {
280: if (repaintedTabs == null) {
281: fail("No tabs repainted - " + msg);
282: }
283: Set set = new HashSet(repaintedTabs);
284: repaintedTabs = null;
285: for (int i = 0; i < tabs.length; i++) {
286: if (!set.contains(new Integer(tabs[i]))) {
287: fail(msg
288: + " Tab "
289: + tabs[i]
290: + " was not repainted - repainted tabs were "
291: + set);
292: }
293: }
294: }
295:
296: protected void repaintTab(int tab) {
297: if (repaintedTabs == null) {
298: repaintedTabs = new HashSet();
299: }
300: repaintedTabs.add(new Integer(tab));
301: }
302:
303: public void assertAllTabsRepainted(String msg) {
304: Boolean b = allTabsRepainted;
305: allTabsRepainted = null;
306: assertTrue("repaintAllTabs not called - " + msg, b
307: .booleanValue());
308: }
309:
310: public void assertAllTabsNotRepainted(String msg) {
311: assertTrue("All tabs repainted - " + msg,
312: allTabsRepainted == null);
313: }
314:
315: private Boolean allTabsRepainted = null;
316:
317: protected void repaintAllTabs() {
318: allTabsRepainted = Boolean.TRUE;
319: }
320:
321: private int changeLastTab = Integer.MIN_VALUE;
322: private int changeCurrTab = Integer.MIN_VALUE;
323: private int changeType = Integer.MIN_VALUE;
324: private int typeOfChange = Integer.MIN_VALUE;
325:
326: public void assertChange(String msg) {
327: if (changeLastTab == Integer.MIN_VALUE
328: || changeCurrTab == Integer.MIN_VALUE
329: || changeType == Integer.MIN_VALUE
330: || typeOfChange == Integer.MIN_VALUE) {
331: fail("Change not called - " + msg);
332: }
333: }
334:
335: public void assertNoChange(String msg) {
336: if (changeLastTab == Integer.MIN_VALUE
337: || changeCurrTab == Integer.MIN_VALUE
338: || changeType == Integer.MIN_VALUE
339: || typeOfChange == Integer.MIN_VALUE) {
340:
341: } else {
342: fail(msg);
343: }
344: }
345:
346: public void assertChange(String msg, int lastTab, int currTab) {
347: assertChange(msg);
348: if (lastTab != changeLastTab || currTab != changeCurrTab) {
349: fail(msg + " - Wrong arguments for call to change: "
350: + "lastTab " + changeLastTab + " currTab "
351: + changeCurrTab);
352: }
353: changeLastTab = Integer.MIN_VALUE;
354: changeCurrTab = Integer.MIN_VALUE;
355: typeOfChange = Integer.MIN_VALUE;
356: changeType = Integer.MIN_VALUE;
357: }
358:
359: public void assertChange(String msg, int lastTab, int currTab,
360: int type, int cType) {
361: int t = changeType;
362: int tc = typeOfChange;
363: assertChange(msg, lastTab, currTab);
364: if (type != t || tc != cType) {
365: fail(msg + " - Wrong arguments for call to change: "
366: + stateToString(t) + " - "
367: + changeToString(cType));
368: }
369: }
370:
371: protected void change(int lastTab, int currTab, int type,
372: int changeType) {
373: changeLastTab = lastTab;
374: changeCurrTab = currTab;
375: typeOfChange = type;
376: this .changeType = changeType;
377: super .change(lastTab, currTab, type, changeType);
378: }
379:
380: public int getRepaintPolicy(int tab) {
381: return policy;
382: }
383: }
384:
385: private int policy = 0;
386: }
|