1 19 20 package org.netbeans.modules.java.settings; 21 22 import java.io.*; 23 import java.util.ResourceBundle ; 24 import java.util.Properties ; 25 import java.util.List ; 26 import java.util.Iterator ; 27 import java.util.Collection ; 28 29 import java.util.HashMap ; 30 import java.util.Map ; 31 import org.netbeans.modules.javacore.JMManager; 32 33 import org.openide.options.ContextSystemOption; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.Lookup; 36 import org.openide.util.NbBundle; 37 import org.openide.util.LookupEvent; 38 import org.openide.util.LookupListener; 39 40 44 public class JavaSettings extends ContextSystemOption { 45 private static final int currentVersion = 1; 46 47 48 static final long serialVersionUID = -8522143676848697297L; 49 50 public static final String PROP_SHOW_OVERRIDING = "showOverriding"; 52 public static final String PROP_SHOW_COMPILE_STATUS = "showCompileStatus"; 54 public static final String PROP_REPLACEABLE_STRINGS_TABLE = "replaceableStringsTable"; 56 public static final String PROP_AUTO_PARSING_DELAY = "autoParsingDelay"; public static final String PROP_PARSING_ERRORS = "parsingErrors"; 59 public static final int DEFAULT_AUTO_PARSING_DELAY = 2000; 60 public static final int DEFAULT_PARSING_ERRORS = 100; 61 private static final boolean DEFAULT_SHOW_OVERRIDING = true; 62 63 67 private int version; 68 69 private static JavaSettings javaSettings; 70 71 72 public String displayName () { 73 return getString("CTL_Java_option"); 74 } 75 76 public HelpCtx getHelpCtx () { 77 return new HelpCtx (JavaSettings.class); 78 } 79 80 public JavaSettings() { 81 addOption(getJavaSynchronizationSettings()); 82 } 83 84 87 public void setReplaceableStringsTable(String table) { 88 String t = getReplaceableStringsTable(); 89 if (t.equals(table)) 90 return; 91 putProperty(PROP_REPLACEABLE_STRINGS_TABLE, table, true); 92 } 93 94 97 public String getReplaceableStringsTable() { 98 String table = (String )getProperty(PROP_REPLACEABLE_STRINGS_TABLE); 99 if (table == null) { 100 return "USER="+System.getProperty("user.name")+"\n"; } else { 102 return table; 103 } 104 } 105 106 109 public Properties getReplaceableStringsProps() { 110 Properties props = new Properties (); 111 String propString = getReplaceableStringsTable(); 112 int i,len = propString.length(); 113 StringBuffer unicodeString = new StringBuffer (len); 114 115 for (i=0;i<len;i++) { 116 char aChar = propString.charAt(i); 117 118 if (aChar > 0x00ff) { 119 String hex = Integer.toHexString(aChar); 120 121 unicodeString.append("\\u"); if (aChar < 0x1000) 123 unicodeString.append("0"); unicodeString.append(hex); 125 } else { 126 unicodeString.append(aChar); 127 } 128 } 129 try { 130 props.load(new ByteArrayInputStream(unicodeString.toString().getBytes())); 131 } 132 catch (IOException e) { 133 } 134 return props; 135 } 136 137 140 public int getAutoParsingDelay() { 141 Integer delay = (Integer )getProperty(PROP_AUTO_PARSING_DELAY); 142 if (delay == null) 143 return DEFAULT_AUTO_PARSING_DELAY; 144 return delay.intValue(); 145 } 146 147 151 public void setParsingErrors(int errors) { 152 if (errors < 0) 153 throw new IllegalArgumentException (); 154 putProperty(PROP_PARSING_ERRORS, new Integer (errors),true); } 156 157 161 public int getParsingErrors() { 162 Integer errors = (Integer )getProperty(PROP_PARSING_ERRORS); 163 if (errors == null) 164 return DEFAULT_PARSING_ERRORS; 165 return errors.intValue(); 166 } 167 168 public boolean getShowOverriding () { 169 Boolean value = (Boolean )getProperty (PROP_SHOW_OVERRIDING); 170 if (value == null) 171 return DEFAULT_SHOW_OVERRIDING; 172 return value.booleanValue(); 173 } 174 175 public void setShowOverriding (boolean value) { 176 Boolean b = (Boolean )getProperty(PROP_SHOW_OVERRIDING); 177 if (b != null && b.booleanValue() == value) 178 return; 179 putProperty (PROP_SHOW_OVERRIDING, value? Boolean.TRUE : Boolean.FALSE,true); 180 } 181 182 185 public void setAutoParsingDelay(int delay) { 186 if (delay < 0) 187 throw new IllegalArgumentException (); 188 putProperty(PROP_AUTO_PARSING_DELAY, new Integer (delay)); 189 } 190 191 192 public boolean isCompileStatusEnabled() { 193 Boolean b = (Boolean )getProperty(PROP_SHOW_COMPILE_STATUS); 194 if (b == null) 195 return true; 196 return b.booleanValue(); 197 } 198 199 public void enableCompileStatus(boolean b) { 200 if (isCompileStatusEnabled() == b) 201 return; 202 putProperty(PROP_SHOW_COMPILE_STATUS, b ? Boolean.TRUE : Boolean.FALSE, true); 203 } 204 205 206 static String getString(String s) { 207 return NbBundle.getMessage(JavaSettings.class, s); 208 } 209 210 private static JavaSynchronizationSettings getJavaSynchronizationSettings() { 211 return (JavaSynchronizationSettings) JavaSynchronizationSettings.findObject(JavaSynchronizationSettings.class, true); 212 } 213 214 public void readExternal(ObjectInput in) 215 throws java.io.IOException , ClassNotFoundException { 216 super.readExternal(in); 217 if (in.available() > 0) { 218 version = in.readInt(); 219 } 220 if (version < currentVersion) { 221 223 version = currentVersion; 224 } 225 JMManager.setDefaultEncoding(defaultEncoding); 226 } 227 228 public void writeExternal(ObjectOutput out) throws IOException { 229 super.writeExternal(out); 230 out.writeInt(version); 231 } 232 233 public static final JavaSettings getDefault() { 234 if (javaSettings==null) 235 javaSettings=(JavaSettings) JavaSettings.findObject(JavaSettings.class, true); 236 return javaSettings; 237 } 238 239 240 241 244 public static final String PROP_DEFAULT_ENCODING = "defaultEncoding"; 246 251 public static final String ENCODING_PLATFORM_DEFAULT = ""; 253 257 private String defaultEncoding = ENCODING_PLATFORM_DEFAULT; 258 259 public String getDefaultEncoding() { 260 return defaultEncoding; 261 } 262 263 public void setDefaultEncoding(String enc) { 264 String e = defaultEncoding; 265 defaultEncoding = enc; 266 JMManager.setDefaultEncoding(enc); 267 firePropertyChange(PROP_DEFAULT_ENCODING, e, enc); 268 } 269 270 } 271 | Popular Tags |