KickJava   Java API By Example, From Geeks To Geeks.

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


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.editor.java.JavaIndentEngine;
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.IntegerProperty;
27 import org.netbeans.test.editor.app.core.properties.Properties;
28 import org.netbeans.test.editor.app.gui.actions.TestDeleteAction;
29 import org.netbeans.test.editor.app.gui.tree.ActionsCache;
30 import org.netbeans.test.editor.app.util.ParsingUtils;
31 import org.openide.text.IndentEngine;
32
33 /**
34  *
35  * @author jlahoda
36  * @version
37  */

38 public class TestSetJavaIEAction extends TestSetIEAction {
39     
40     private boolean leadingStarInComment;
41     private boolean addNewLineBeforePar;
42     private boolean addSpaceBeforeBrackets;
43     private boolean expandTabs;
44     private int tabSize;
45     
46     public static String JavaDoc LEADING_STAR_IN_COMMENTS = "LeadingStarInComment";
47     public static String JavaDoc ADD_NEW_LINE_BEFORE_PAR = "AddNewLineBeforeParenthesis";
48     public static String JavaDoc ADD_SPACE_BEFORE_BRACKETS = "AddSpaceBeforeBrackets";
49     public static String JavaDoc EXPAND_TABS = "ExpandTabs";
50     public static String JavaDoc TAB_SIZE = "TabSize";
51     
52     /** Creates new TestSetJavaIEAction */
53     public TestSetJavaIEAction(int num) {
54         this("setJavaIE"+Integer.toString(num));
55     }
56     
57     public TestSetJavaIEAction(String JavaDoc name) {
58         super(name);
59         setIndentEngine(findIndentEngine(JavaIndentEngine.class));
60         
61         JavaIndentEngine engine = (JavaIndentEngine) getIndentEngine();
62         
63         setExpandTabs(engine.isExpandTabs());
64         setLeadingStarInComment(engine.getJavaFormatLeadingStarInComment());
65         setAddNewLineBeforePar(engine.getJavaFormatNewlineBeforeBrace());
66         setAddSpaceBeforeBrackets(engine.getJavaFormatSpaceBeforeParenthesis());
67         setTabSize(engine.getSpacesPerTab());
68     }
69     
70     public TestSetJavaIEAction(Element JavaDoc node) {
71         super(node);
72         setLeadingStarInComment(ParsingUtils.readBoolean(node, LEADING_STAR_IN_COMMENTS));
73         setAddNewLineBeforePar(ParsingUtils.readBoolean(node, ADD_NEW_LINE_BEFORE_PAR));
74         setAddSpaceBeforeBrackets(ParsingUtils.readBoolean(node, ADD_SPACE_BEFORE_BRACKETS));
75         setExpandTabs(ParsingUtils.readBoolean(node, EXPAND_TABS));
76         setTabSize(ParsingUtils.readInt(node, TAB_SIZE));
77     }
78     
79     public void setIndentEngine(IndentEngine indentEngine) { //no indent engine except Java IE
80
this.indentEngine = findIndentEngine(JavaIndentEngine.class);
81     }
82     
83     public Element JavaDoc toXML(Element JavaDoc node) {
84         node = super.toXML(node);
85         
86         node.setAttribute(LEADING_STAR_IN_COMMENTS, String.valueOf(getLeadingStarInComment()));
87         node.setAttribute(ADD_NEW_LINE_BEFORE_PAR, String.valueOf(getAddNewLineBeforePar()));
88         node.setAttribute(ADD_SPACE_BEFORE_BRACKETS, String.valueOf(getAddSpaceBeforeBrackets()));
89         node.setAttribute(EXPAND_TABS, String.valueOf(getExpandTabs()));
90         node.setAttribute(TAB_SIZE, String.valueOf(getTabSize()));
91         return node;
92     }
93     
94     public void fromXML(Element JavaDoc node) throws BadPropertyNameException {
95         super.fromXML(node);
96         setLeadingStarInComment(ParsingUtils.readBoolean(node, LEADING_STAR_IN_COMMENTS));
97         setAddNewLineBeforePar(ParsingUtils.readBoolean(node, ADD_NEW_LINE_BEFORE_PAR));
98         setAddSpaceBeforeBrackets(ParsingUtils.readBoolean(node, ADD_SPACE_BEFORE_BRACKETS));
99         setExpandTabs(ParsingUtils.readBoolean(node, EXPAND_TABS));
100         setTabSize(ParsingUtils.readInt(node, TAB_SIZE));
101     }
102     
103     public Properties getProperties() {
104         Properties ret=super.getProperties();
105         ret.put(LEADING_STAR_IN_COMMENTS, new BooleanProperty(getLeadingStarInComment()));
106         ret.put(ADD_NEW_LINE_BEFORE_PAR, new BooleanProperty(getAddNewLineBeforePar()));
107         ret.put(ADD_SPACE_BEFORE_BRACKETS, new BooleanProperty(getAddSpaceBeforeBrackets()));
108         ret.put(EXPAND_TABS, new BooleanProperty(getExpandTabs()));
109         ret.put(TAB_SIZE, new IntegerProperty(getTabSize()));
110         return ret;
111     }
112     
113     public Object JavaDoc getProperty(String JavaDoc name) throws BadPropertyNameException {
114         if (name.compareTo(LEADING_STAR_IN_COMMENTS) == 0) {
115             return new BooleanProperty(leadingStarInComment);
116         } else if (name.compareTo(ADD_NEW_LINE_BEFORE_PAR) == 0) {
117             return new BooleanProperty(addNewLineBeforePar);
118         } else if (name.compareTo(ADD_SPACE_BEFORE_BRACKETS) == 0) {
119             return new BooleanProperty(addSpaceBeforeBrackets);
120         } else if (name.compareTo(EXPAND_TABS) == 0) {
121             return new BooleanProperty(expandTabs);
122         } else if (name.compareTo(TAB_SIZE) == 0) {
123             return new IntegerProperty(tabSize);
124         } else {
125             return super.getProperty(name);
126         }
127     }
128     
129     public void setProperty(String JavaDoc name, Object JavaDoc value) throws BadPropertyNameException {
130         if (name.compareTo(LEADING_STAR_IN_COMMENTS) == 0) {
131             setLeadingStarInComment(((BooleanProperty)value).getValue());
132         } else if (name.compareTo(ADD_NEW_LINE_BEFORE_PAR) == 0) {
133             setAddNewLineBeforePar(((BooleanProperty)value).getValue());
134         } else if (name.compareTo(ADD_SPACE_BEFORE_BRACKETS) == 0) {
135             setAddSpaceBeforeBrackets(((BooleanProperty)value).getValue());
136         } else if (name.compareTo(EXPAND_TABS) == 0) {
137             setExpandTabs(((BooleanProperty)value).getValue());
138         } else if (name.compareTo(TAB_SIZE) == 0) {
139             setTabSize(((IntegerProperty)value).getValue());
140         } else {
141             super.setProperty(name, value);
142         }
143     }
144     
145     public boolean getLeadingStarInComment() {
146         return leadingStarInComment;
147     }
148     
149     public void setLeadingStarInComment(boolean value) {
150         boolean old = getLeadingStarInComment();
151         
152         leadingStarInComment = value;
153         firePropertyChange(LEADING_STAR_IN_COMMENTS, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
154     }
155     
156     public boolean getAddNewLineBeforePar() {
157         return addNewLineBeforePar;
158     }
159     
160     public void setAddNewLineBeforePar(boolean value) {
161         boolean old = getAddNewLineBeforePar();
162         
163         addNewLineBeforePar = value;
164         firePropertyChange(ADD_NEW_LINE_BEFORE_PAR, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
165     }
166     
167     public boolean getAddSpaceBeforeBrackets() {
168         return addSpaceBeforeBrackets;
169     }
170     
171     public void setAddSpaceBeforeBrackets(boolean value) {
172         boolean old = getAddSpaceBeforeBrackets();
173         
174         addSpaceBeforeBrackets = value;
175         firePropertyChange(ADD_SPACE_BEFORE_BRACKETS, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
176     }
177     
178     public boolean getExpandTabs() {
179         return expandTabs;
180     }
181     
182     public void setExpandTabs(boolean value) {
183         boolean old = getExpandTabs();
184         
185         expandTabs = value;
186         firePropertyChange(EXPAND_TABS, old ? Boolean.TRUE : Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
187     }
188     
189     public int getTabSize() {
190         return tabSize;
191     }
192     
193     public void setTabSize(int value) {
194         int old = getTabSize();
195         
196         tabSize = value;
197         firePropertyChange(TAB_SIZE, new Integer JavaDoc(old), new Integer JavaDoc(value));
198     }
199     
200     public void perform() {
201         super.perform();
202         JavaIndentEngine engine = (JavaIndentEngine) getIndentEngine();
203         
204         engine.setExpandTabs(getExpandTabs());
205         engine.setJavaFormatLeadingStarInComment(getLeadingStarInComment());
206         engine.setJavaFormatNewlineBeforeBrace(getAddNewLineBeforePar());
207         engine.setJavaFormatSpaceBeforeParenthesis(getAddSpaceBeforeBrackets());
208         engine.setSpacesPerTab(getTabSize());
209     }
210 }
211
Popular Tags