1 19 20 package org.netbeans.modules.form; 21 22 import java.awt.Color ; 23 import java.lang.String ; 24 import java.lang.String ; 25 import java.lang.String ; 26 import java.util.*; 27 import java.util.prefs.Preferences ; 28 import org.openide.util.HelpCtx; 29 import org.netbeans.modules.form.codestructure.*; 30 import org.openide.nodes.BeanNode; 31 import org.openide.util.NbPreferences; 32 33 36 37 public class FormLoaderSettings { 38 private static final FormLoaderSettings INSTANCE = new FormLoaderSettings(); 39 public static final String PROP_USE_INDENT_ENGINE = "useIndentEngine"; 41 42 public static final String PROP_EVENT_VARIABLE_NAME = "eventVariableName"; 44 45 public static final String PROP_LISTENER_GENERATION_STYLE = "listenerGenerationStyle"; 47 48 public static final String PROP_SELECTION_BORDER_SIZE = "selectionBorderSize"; 50 public static final String PROP_SELECTION_BORDER_COLOR = "selectionBorderColor"; 52 public static final String PROP_CONNECTION_BORDER_COLOR = "connectionBorderColor"; 54 public static final String PROP_DRAG_BORDER_COLOR = "dragBorderColor"; 56 public static final String PROP_GUIDING_LINE_COLOR = "guidingLineColor"; 58 public static final String PROP_FORMDESIGNER_BACKGROUND_COLOR = 59 "formDesignerBackgroundColor"; 61 public static final String PROP_FORMDESIGNER_BORDER_COLOR = 62 "formDesignerBorderColor"; 64 65 public static final String PROP_GRID_X = "gridX"; 67 public static final String PROP_GRID_Y = "gridY"; 69 public static final String PROP_APPLY_GRID_TO_POSITION = "applyGridToPosition"; 71 public static final String PROP_APPLY_GRID_TO_SIZE = "applyGridToSize"; 73 74 public static final String PROP_VARIABLES_MODIFIER = "variablesModifier"; 76 public static final String PROP_VARIABLES_LOCAL = "variablesLocal"; 78 79 public static final String PROP_GENERATE_MNEMONICS = "generateMnemonicsCode"; 81 public static final String PROP_SHOW_MNEMONICS_DIALOG = "showMnemonicsDialog"; 83 84 public static final String PROP_DISPLAY_WRITABLE_ONLY = "displayWritableOnly"; 86 87 public static final String PROP_EDITOR_SEARCH_PATH = "editorSearchPath"; 89 public static final String PROP_REGISTERED_EDITORS = "registeredEditors"; 91 92 public static final String PROP_PALETTE_IN_TOOLBAR = "toolBarPalette"; 94 public static final String PROP_FOLD_GENERATED_CODE = "foldGeneratedCode"; 96 public static final String PROP_ASSISTANT_SHOWN = "assistantShown"; 98 public static final String PROP_DESIGNER_LAF = "designerLAF"; 100 101 public static final String PROP_LAYOUT_CODE_TARGET = "layoutCodeTarget"; 103 104 public static final String PROP_AUTO_I18N = "i18nAutoMode"; static final int AUTO_I18N_DEFAULT = 0; 106 static final int AUTO_I18N_ON = 1; 107 static final int AUTO_I18N_OFF = 2; 108 110 112 private static java.awt.Color dragBorderColor = java.awt.Color.gray; 113 115 private static boolean showMnemonicsDialog = true; 116 117 private static String [] editorSearchPath = null; 118 119 private static String [][] registeredEditors; 120 private static final int MIN_SELECTION_BORDER_SIZE = 1; 121 private static final int MAX_SELECTION_BORDER_SIZE = 15; 122 123 private static final int MIN_GRID_X = 2; 124 private static final int MIN_GRID_Y = 2; 125 126 128 130 public static final Preferences getPreferences() { 131 return NbPreferences.forModule(FormLoaderSettings.class); 132 } 133 134 public static FormLoaderSettings getInstance() { 135 return INSTANCE; 136 } 137 138 141 public boolean getUseIndentEngine() { 142 return getPreferences().getBoolean(PROP_USE_INDENT_ENGINE, false); 143 } 144 145 public void setUseIndentEngine(boolean value) { 146 getPreferences().putBoolean(PROP_USE_INDENT_ENGINE, value); 147 } 148 149 150 public String getEventVariableName() { 151 return getPreferences().get(PROP_EVENT_VARIABLE_NAME, "evt"); 152 } 153 154 155 public void setEventVariableName(String value) { 156 getPreferences().put(PROP_EVENT_VARIABLE_NAME, value); 157 } 158 159 160 public int getListenerGenerationStyle() { 161 return getPreferences().getInt(PROP_LISTENER_GENERATION_STYLE, 0); 162 } 163 164 165 public void setListenerGenerationStyle(int style) { 166 getPreferences().putInt(PROP_LISTENER_GENERATION_STYLE, style); 167 } 168 169 170 public int getSelectionBorderSize() { 171 return getPreferences().getInt(PROP_SELECTION_BORDER_SIZE, 1); 172 } 173 174 175 public void setSelectionBorderSize(int value) { 176 if (value < MIN_SELECTION_BORDER_SIZE) 177 value = MIN_SELECTION_BORDER_SIZE; 178 else if (value > MAX_SELECTION_BORDER_SIZE) 179 value = MAX_SELECTION_BORDER_SIZE; 180 181 182 getPreferences().putInt(PROP_SELECTION_BORDER_SIZE, value); 183 } 184 185 186 public java.awt.Color getSelectionBorderColor() { 187 int rgb = getPreferences().getInt(PROP_SELECTION_BORDER_COLOR, new Color (255, 164, 0).getRGB()); 188 return new Color (rgb); 189 } 190 191 192 public void setSelectionBorderColor(java.awt.Color value) { 193 if (value == null) { 194 return; 195 } 196 getPreferences().putInt(PROP_SELECTION_BORDER_COLOR, value.getRGB()); 197 } 198 199 200 public java.awt.Color getConnectionBorderColor() { 201 int rgb = getPreferences().getInt(PROP_CONNECTION_BORDER_COLOR, Color.red.getRGB()); 202 return new Color (rgb); 203 } 204 205 206 public void setConnectionBorderColor(java.awt.Color value) { 207 if (value == null) { 208 return; 209 } 210 getPreferences().putInt(PROP_CONNECTION_BORDER_COLOR, value.getRGB()); 211 } 212 213 214 public java.awt.Color getDragBorderColor() { 215 int rgb = getPreferences().getInt(PROP_DRAG_BORDER_COLOR, Color.gray.getRGB()); 216 return new Color (rgb); 217 } 218 219 220 public void setDragBorderColor(java.awt.Color value) { 221 if (value == null) { 222 return; 223 } 224 getPreferences().putInt(PROP_DRAG_BORDER_COLOR, value.getRGB()); 225 } 226 227 228 public java.awt.Color getGuidingLineColor() { 229 int rgb = getPreferences().getInt(PROP_GUIDING_LINE_COLOR, new Color (143, 171, 196).getRGB()); 230 return new Color (rgb); 231 232 } 233 234 235 public void setGuidingLineColor(java.awt.Color value) { 236 if (value == null) { 237 return; 238 } 239 getPreferences().putInt(PROP_GUIDING_LINE_COLOR, value.getRGB()); 240 } 241 242 243 public int getGridX() { 244 return getPreferences().getInt(PROP_GRID_X, 10); 245 } 246 247 248 public void setGridX(int value) { 249 if (value < MIN_GRID_X) value = MIN_GRID_X; 250 getPreferences().putInt(PROP_GRID_X, value); 251 } 252 253 254 public int getGridY() { 255 return getPreferences().getInt(PROP_GRID_Y, 10); 256 } 257 258 259 public void setGridY(int value) { 260 if (value < MIN_GRID_Y) value = MIN_GRID_Y; 261 getPreferences().putInt(PROP_GRID_Y, value); 262 } 263 264 265 public boolean getApplyGridToPosition() { 266 return getPreferences().getBoolean(PROP_APPLY_GRID_TO_POSITION, true); 267 } 268 269 270 public void setApplyGridToPosition(boolean value) { 271 getPreferences().putBoolean(PROP_APPLY_GRID_TO_POSITION, value); 272 } 273 274 275 public boolean getApplyGridToSize() { 276 return getPreferences().getBoolean(PROP_APPLY_GRID_TO_SIZE, true); 277 278 } 279 280 281 public void setApplyGridToSize(boolean value) { 282 getPreferences().putBoolean(PROP_APPLY_GRID_TO_SIZE, value); 283 } 284 285 286 public boolean getVariablesLocal() { 287 return getPreferences().getBoolean(PROP_VARIABLES_LOCAL, false); 288 } 289 290 291 public void setVariablesLocal(boolean value) { 292 getPreferences().putBoolean(PROP_VARIABLES_LOCAL, value); 293 int variablesModifier = getVariablesModifier(); 294 int varType = value ? 295 CodeVariable.LOCAL | (variablesModifier & CodeVariable.FINAL) 296 | CodeVariable.EXPLICIT_DECLARATION 297 : 298 CodeVariable.FIELD | variablesModifier; 299 CodeStructure.setGlobalDefaultVariableType(varType); 300 301 if (value) { 302 variablesModifier &= CodeVariable.FINAL; 303 setVariablesModifier(variablesModifier); 304 } 305 306 307 } 308 309 310 public int getVariablesModifier() { 311 return getPreferences().getInt(PROP_VARIABLES_MODIFIER, java.lang.reflect.Modifier.PRIVATE); 312 } 313 314 315 public void setVariablesModifier(int value) { 316 int variablesModifier = value; 317 318 int varType; 319 if (getVariablesLocal()) { 320 varType = CodeVariable.LOCAL | variablesModifier; 321 if ((variablesModifier & CodeVariable.FINAL) == 0) 322 varType |= CodeVariable.EXPLICIT_DECLARATION; 323 } 324 else varType = CodeVariable.FIELD | variablesModifier; 325 CodeStructure.setGlobalDefaultVariableType(varType); 326 } 327 328 329 public boolean getGenerateMnemonicsCode() { 330 return getPreferences().getBoolean(PROP_GENERATE_MNEMONICS, false); 331 } 332 333 334 public void setGenerateMnemonicsCode(boolean value) { 335 getPreferences().putBoolean(PROP_GENERATE_MNEMONICS, value); 336 } 337 338 339 public boolean getDisplayWritableOnly() { 340 return getPreferences().getBoolean(PROP_DISPLAY_WRITABLE_ONLY, true); 341 } 342 343 344 public void setDisplayWritableOnly(boolean value) { 345 getPreferences().putBoolean(PROP_DISPLAY_WRITABLE_ONLY, value); 346 } 347 348 349 public String [] getEditorSearchPath() { 350 if (editorSearchPath == null) { 351 editorSearchPath = translatedEditorSearchPath( 352 toArray(getPreferences().get(PROP_EDITOR_SEARCH_PATH, "org.netbeans.modules.form.editors2"))); 353 } 354 return editorSearchPath; 355 } 356 357 358 public void setEditorSearchPath(String [] value) { 359 editorSearchPath = value; 360 getPreferences().put(PROP_EDITOR_SEARCH_PATH, fromArray(editorSearchPath)); } 362 363 364 public String [][] getRegisteredEditors() { 365 if (registeredEditors == null) { 366 registeredEditors = toArray2(getPreferences().get(PROP_REGISTERED_EDITORS, "")); 367 } 368 369 return registeredEditors; 370 } 371 372 373 public void setRegisteredEditors(String [][] value) { 374 registeredEditors = value; 375 getPreferences().put(PROP_REGISTERED_EDITORS, fromArray2(registeredEditors)); } 377 378 public String [] getRegisteredEditor(int index) { 379 return getRegisteredEditors()[index]; 380 } 381 382 public void setRegisteredEditor(int index, String [] value) { 383 registeredEditors[index] = value; 384 FormPropertyEditorManager.clearEditorsCache(); setRegisteredEditors(registeredEditors); 386 } 387 388 public boolean isPaletteInToolBar() { 389 return getPreferences().getBoolean(PROP_PALETTE_IN_TOOLBAR, false); 390 } 391 392 public void setPaletteInToolBar(boolean value) { 393 getPreferences().putBoolean(PROP_PALETTE_IN_TOOLBAR, value); 394 } 395 396 397 public java.awt.Color getFormDesignerBackgroundColor() { 398 int rgb = getPreferences().getInt(PROP_FORMDESIGNER_BACKGROUND_COLOR , Color.white.getRGB()); 399 return new Color (rgb); 400 401 } 402 403 404 public void setFormDesignerBackgroundColor(java.awt.Color value) { 405 if (value == null) 406 return; 407 getPreferences().putInt(PROP_FORMDESIGNER_BACKGROUND_COLOR , value.getRGB()); 408 } 409 410 411 public java.awt.Color getFormDesignerBorderColor() { 412 int rgb = getPreferences().getInt(PROP_FORMDESIGNER_BORDER_COLOR , new Color (224, 224, 255).getRGB()); 413 return new Color (rgb); 414 415 } 416 417 418 public void setFormDesignerBorderColor(java.awt.Color value) { 419 if (value == null) 420 return; 421 getPreferences().putInt(PROP_FORMDESIGNER_BORDER_COLOR , value.getRGB()); 422 } 423 424 425 public boolean getFoldGeneratedCode() { 426 return getPreferences().getBoolean(PROP_FOLD_GENERATED_CODE, true); 427 } 428 429 430 public void setFoldGeneratedCode(boolean value) { 431 getPreferences().putBoolean(PROP_FOLD_GENERATED_CODE, value); 432 } 433 434 435 public boolean getAssistantShown() { 436 return getPreferences().getBoolean(PROP_ASSISTANT_SHOWN, true); 437 } 438 439 440 public void setAssistantShown(boolean value) { 441 getPreferences().putBoolean(PROP_ASSISTANT_SHOWN, value); 442 } 443 444 public int getLayoutCodeTarget() { 445 return getPreferences().getInt(PROP_LAYOUT_CODE_TARGET, 0); 446 } 447 448 public void setLayoutCodeTarget(int target) { 449 getPreferences().putInt(PROP_LAYOUT_CODE_TARGET, target); 450 } 451 452 public int getI18nAutoMode() { 453 return getPreferences().getInt(PROP_AUTO_I18N, 0); 454 } 455 456 public void setI18nAutoMode(int mode) { 457 getPreferences().putInt(PROP_AUTO_I18N, mode); 458 } 459 460 private static String [][] toArray2(String esp) { 461 List<String []> retval = new ArrayList<String []> (); String [] items = esp.split(" | "); for (int i = 0; i < items.length; i++) { 464 String s = items[i]; 465 retval.add(toArray(s)); 466 } 467 return retval.toArray(new String [][] {{}}); 468 } 469 470 private static String fromArray2(String [][] items) { 471 StringBuffer sb = new StringBuffer (); 472 for (int i = 0; i < items.length; i++) { 473 sb.append(fromArray(items[i])); 474 if (i < items.length-1) { 475 sb.append(" | "); } 477 } 478 return sb.toString(); 479 } 480 481 private static String [] toArray(String esp) { 482 return esp.split(" , "); } 484 485 private static String fromArray(String [] items) { 486 StringBuffer sb = new StringBuffer (); 487 for (int i = 0; i < items.length; i++) { 488 sb.append(items[i]); 489 if (i < items.length-1) { 490 sb.append(" , "); } 492 } 493 return sb.toString(); 494 } 495 496 private static String [] translatedEditorSearchPath(String [] eSearchPath) { 500 String [] retval = new String [eSearchPath.length]; 501 for (int i = 0; i < eSearchPath.length; i++) { 502 String path = eSearchPath[i]; 503 path = org.openide.util.Utilities.translate(path + ".BogusClass"); path = path.substring(0, path.length() - ".BogusClass".length()); retval[i] = path; 506 } 507 return retval; 508 } 509 510 512 public String displayName() { 513 return FormUtils.getBundleString("CTL_FormSettings"); } 515 516 public HelpCtx getHelpCtx() { 517 return new HelpCtx("gui.configuring"); } 519 520 private static BeanNode createViewNode() throws java.beans.IntrospectionException { 521 return new BeanNode(FormLoaderSettings.getInstance()); 522 } 523 } 524 | Popular Tags |