KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > core > TestSetCompletionAction


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 package org.netbeans.test.editor.app.core;
20
21 import org.netbeans.modules.java.editor.options.JavaOptions;
22 import org.w3c.dom.Element JavaDoc;
23 import javax.swing.text.Document JavaDoc;
24 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException;
25 import org.netbeans.test.editor.app.core.properties.BooleanProperty;
26 import org.netbeans.test.editor.app.core.properties.Properties;
27 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction;
28 import org.netbeans.test.editor.app.gui.tree.ActionsCache;
29 import org.netbeans.test.editor.app.util.ParsingUtils;
30 import org.openide.options.SystemOption;
31
32 /**
33  *
34  * @author jlahoda
35  * @version
36  */

37 public class TestSetCompletionAction extends TestSetAction {
38     
39     private boolean caseSensitive;
40     private boolean instantSubstitution;
41     private boolean naturalSort;
42     
43     public static String JavaDoc CASE_SENSITIVE = "CaseSensitive";
44     public static String JavaDoc INSTANT_SUBSTITUTION = "InstantSubstitution";
45     public static String JavaDoc NATURAL_SORT = "NaturalSort";
46     
47     /** Creates new TestSetJavaIEAction */
48     public TestSetCompletionAction(int num) {
49         this("setCompletion"+Integer.toString(num));
50     }
51     
52     public TestSetCompletionAction(String JavaDoc name) {
53         super(name);
54     }
55     
56     public TestSetCompletionAction(Element JavaDoc node) {
57         super(node);
58         setCaseSensitive(ParsingUtils.readBoolean(node, CASE_SENSITIVE));
59         setInstantSubstitution(ParsingUtils.readBoolean(node, INSTANT_SUBSTITUTION));
60         setNaturalSort(ParsingUtils.readBoolean(node, NATURAL_SORT));
61     }
62     
63     public Element JavaDoc toXML(Element JavaDoc node) {
64         node = super.toXML(node);
65         
66         node.setAttribute(CASE_SENSITIVE, String.valueOf(getCaseSensitive()));
67         node.setAttribute(INSTANT_SUBSTITUTION, String.valueOf(getInstantSubstitution()));
68         node.setAttribute(NATURAL_SORT, String.valueOf(getNaturalSort()));
69         return node;
70     }
71     
72     public void fromXML(Element JavaDoc node) throws BadPropertyNameException {
73         super.fromXML(node);
74         setCaseSensitive(ParsingUtils.readBoolean(node, CASE_SENSITIVE));
75         setInstantSubstitution(ParsingUtils.readBoolean(node, INSTANT_SUBSTITUTION));
76         setNaturalSort(ParsingUtils.readBoolean(node, NATURAL_SORT));
77     }
78     
79     public Properties getProperties() {
80         Properties ret=super.getProperties();
81         ret.put(CASE_SENSITIVE, new BooleanProperty(caseSensitive));
82         ret.put(INSTANT_SUBSTITUTION, new BooleanProperty(instantSubstitution));
83         ret.put(NATURAL_SORT, new BooleanProperty(naturalSort));
84         return ret;
85     }
86     
87     public Object JavaDoc getProperty(String JavaDoc name) throws BadPropertyNameException {
88         if (name.compareTo(CASE_SENSITIVE) == 0) {
89             return new BooleanProperty(caseSensitive);
90         } else if (name.compareTo(INSTANT_SUBSTITUTION) == 0) {
91             return new BooleanProperty(instantSubstitution);
92         } else if (name.compareTo(NATURAL_SORT) == 0) {
93             return new BooleanProperty(naturalSort);
94         } else {
95             return super.getProperty(name);
96         }
97     }
98     
99     public void setProperty(String JavaDoc name, Object JavaDoc value) throws BadPropertyNameException {
100         if (name.compareTo(CASE_SENSITIVE) == 0) {
101             setCaseSensitive(((BooleanProperty)value).getValue());
102         } else if (name.compareTo(INSTANT_SUBSTITUTION) == 0) {
103             setInstantSubstitution(((BooleanProperty)value).getValue());
104         } else if (name.compareTo(NATURAL_SORT) == 0) {
105             setNaturalSort(((BooleanProperty)value).getValue());
106         } else {
107             super.setProperty(name, value);
108         }
109     }
110     
111     public boolean getCaseSensitive() {
112         return caseSensitive;
113     }
114     
115     public void setCaseSensitive(boolean value) {
116         boolean old = getCaseSensitive();
117         
118         caseSensitive = value;
119         firePropertyChange(CASE_SENSITIVE, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
120     }
121     
122     public boolean getInstantSubstitution() {
123         return instantSubstitution;
124     }
125     
126     public void setInstantSubstitution(boolean value) {
127         boolean old = getInstantSubstitution();
128         
129         instantSubstitution = value;
130         firePropertyChange(INSTANT_SUBSTITUTION, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
131     }
132     
133     public boolean getNaturalSort() {
134         return naturalSort;
135     }
136     
137     public void setNaturalSort(boolean value) {
138         boolean old = getNaturalSort();
139         
140         naturalSort = value;
141         firePropertyChange(NATURAL_SORT, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
142     }
143     
144     public void perform() {
145         super.perform();
146         JavaOptions opts = (JavaOptions)(SystemOption.findObject(JavaOptions.class));
147         opts.setCompletionCaseSensitive(caseSensitive);
148         opts.setCompletionInstantSubstitution(instantSubstitution);
149         opts.setCompletionNaturalSort(naturalSort);
150     }
151 }
152
Popular Tags