KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > propertyeditors > PropertyType_Color


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 gui.propertyeditors;
21
22 import org.netbeans.jellytools.properties.ColorProperty;
23 import org.netbeans.jellytools.properties.PropertySheetOperator;
24
25 import org.netbeans.jellytools.properties.editors.ColorCustomEditorOperator;
26
27 import org.netbeans.junit.NbTestSuite;
28
29 /**
30  * Tests of Color Property Editor.
31  *
32  * @author Marian.Mirilovic@Sun.Com
33  */

34 public class PropertyType_Color extends PropertyEditorsTest {
35
36     public String JavaDoc propertyName_L;
37     public String JavaDoc propertyValue_L;
38     public String JavaDoc propertyValueExpectation_L;
39     
40     public boolean waitDialog = false;
41     
42     /** Creates a new instance of PropertyType_Boolean */
43     public PropertyType_Color(String JavaDoc testName) {
44         super(testName);
45     }
46     
47     
48     public void setUp(){
49         propertyName_L = "Color";
50         super.setUp();
51     }
52     
53     public static NbTestSuite suite() {
54         NbTestSuite suite = new NbTestSuite();
55         suite.addTest(new PropertyType_Color("verifyCustomizer"));
56         suite.addTest(new PropertyType_Color("testCustomizerCancel"));
57         suite.addTest(new PropertyType_Color("testCustomizerOk"));
58         suite.addTest(new PropertyType_Color("testByInPlace"));
59         suite.addTest(new PropertyType_Color("testByInPlaceInvalid"));
60         return suite;
61     }
62     
63     public void testCustomizerOk() {
64         propertyValue_L = "50,50,50";
65         propertyValueExpectation_L = "["+propertyValue_L+"]";
66         waitDialog = false;
67         setByCustomizerOk(propertyName_L, true);
68     }
69     
70     public void testCustomizerCancel(){
71         propertyValue_L = "100,100,100";
72         propertyValueExpectation_L = "["+propertyValue_L+"]";
73         waitDialog = false;
74         setByCustomizerCancel(propertyName_L, false);
75     }
76     
77     public void testByInPlace(){
78         propertyValue_L = "20,10,100";
79         propertyValueExpectation_L = "["+propertyValue_L+"]";
80         waitDialog = false;
81         setByInPlace(propertyName_L, propertyValue_L, true);
82     }
83     
84     public void testByInPlaceInvalid(){
85         propertyValue_L = "xx color";
86         propertyValueExpectation_L = propertyValue_L;
87         waitDialog = true;
88         setByInPlace(propertyName_L, propertyValue_L, false);
89     }
90     
91     public void verifyCustomizer(){
92         verifyCustomizer(propertyName_L);
93     }
94     
95     public void setCustomizerValue() {
96         ColorCustomEditorOperator customizer = new ColorCustomEditorOperator(propertyCustomizer);
97         
98         int first_comma = propertyValue_L.indexOf(',');
99         int second_comma = propertyValue_L.indexOf(',',first_comma+1);
100         
101         int r = new Integer JavaDoc(propertyValue_L.substring(0,first_comma)).intValue();
102         int g = new Integer JavaDoc(propertyValue_L.substring(first_comma+1, second_comma)).intValue();
103         int b = new Integer JavaDoc(propertyValue_L.substring(second_comma+1)).intValue();
104         
105         customizer.setRGBValue(r,g,b);
106     }
107     
108     public void verifyPropertyValue(boolean expectation) {
109         verifyExpectationValue(propertyName_L,expectation, propertyValueExpectation_L, propertyValue_L, waitDialog);
110     }
111     
112     public String JavaDoc getValue(String JavaDoc propertyName) {
113         String JavaDoc returnValue;
114         PropertySheetOperator propertiesTab = new PropertySheetOperator(propertiesWindow);
115         
116         returnValue = new ColorProperty(propertiesTab, propertyName_L).getValue();
117         err.println("GET VALUE = [" + returnValue + "].");
118         
119         // hack for color poperty, this action expects, that right value is displayed as tooltip
120
// returnValue = new Property(propertiesTab, propertyName_L).valueButtonOperator().getToolTipText();
121
// err.println("GET VALUE TOOLTIP = [" + returnValue + "].");
122

123         return returnValue;
124     }
125     
126     public void verifyCustomizerLayout() {
127         ColorCustomEditorOperator customizer = new ColorCustomEditorOperator(propertyCustomizer);
128         customizer.verify();
129         customizer.btOK();
130         customizer.btCancel();
131     }
132     
133     /** Test could be executed internaly in Forte without XTest
134      * @param args arguments from command line
135      */

136     public static void main(String JavaDoc[] args) {
137         //junit.textui.TestRunner.run(new NbTestSuite(PropertyType_Color.class));
138
junit.textui.TestRunner.run(suite());
139     }
140 }
141
Popular Tags