1 19 package org.netbeans.test.editor.app.core; 20 21 import org.netbeans.modules.editor.java.JavaIndentEngine; 22 import org.w3c.dom.Element ; 23 import javax.swing.text.Document ; 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 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 LEADING_STAR_IN_COMMENTS = "LeadingStarInComment"; 47 public static String ADD_NEW_LINE_BEFORE_PAR = "AddNewLineBeforeParenthesis"; 48 public static String ADD_SPACE_BEFORE_BRACKETS = "AddSpaceBeforeBrackets"; 49 public static String EXPAND_TABS = "ExpandTabs"; 50 public static String TAB_SIZE = "TabSize"; 51 52 53 public TestSetJavaIEAction(int num) { 54 this("setJavaIE"+Integer.toString(num)); 55 } 56 57 public TestSetJavaIEAction(String 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 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) { this.indentEngine = findIndentEngine(JavaIndentEngine.class); 81 } 82 83 public Element toXML(Element 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 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 getProperty(String 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 name, Object 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 (old), new Integer (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 |