1 19 20 package org.netbeans.modules.editor.options; 21 22 import java.awt.Color ; 23 import java.awt.Font ; 24 import java.awt.Insets ; 25 import java.io.IOException ; 26 import java.io.ObjectInput ; 27 import java.lang.reflect.Field ; 28 import java.util.Collection ; 29 import java.util.Collections ; 30 import java.util.Map ; 31 import java.util.HashMap ; 32 import java.util.List ; 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 import java.util.Enumeration ; 36 import java.util.logging.Logger ; 37 import javax.swing.text.AttributeSet ; 38 import javax.swing.text.JTextComponent ; 39 import java.awt.Toolkit ; 40 import javax.swing.text.StyleConstants ; 41 import org.netbeans.api.editor.mimelookup.MimeLookup; 42 import org.netbeans.api.editor.settings.FontColorNames; 43 import org.netbeans.api.editor.settings.FontColorSettings; 44 import org.netbeans.api.editor.settings.KeyBindingSettings; 45 import org.netbeans.editor.Settings; 46 import org.netbeans.editor.SettingsNames; 47 import org.netbeans.editor.SettingsDefaults; 48 import org.netbeans.editor.SettingsUtil; 49 import org.netbeans.editor.Coloring; 50 import org.netbeans.editor.BaseKit; 51 import org.netbeans.editor.Formatter; 52 import org.netbeans.editor.MultiKeyBinding; 53 import org.netbeans.editor.ext.ExtSettingsNames; 54 import org.netbeans.modules.editor.NbEditorDocument; 55 import org.netbeans.modules.editor.FormatterIndentEngine; 56 import org.netbeans.modules.editor.IndentEngineFormatter; 57 import org.netbeans.modules.editor.SimpleIndentEngine; 58 import org.openide.text.IndentEngine; 59 import java.beans.IntrospectionException ; 60 import org.openide.loaders.DataObject; 61 import java.io.ObjectOutput ; 62 import org.openide.util.LookupEvent; 63 import org.openide.util.LookupListener; 64 import org.openide.util.RequestProcessor; 65 import org.openide.loaders.DataFolder; 66 import org.openide.filesystems.FileObject; 67 import javax.swing.KeyStroke ; 68 import java.awt.event.KeyEvent ; 69 import org.openide.util.Lookup; 70 import java.util.StringTokenizer ; 71 import org.netbeans.modules.editor.NbEditorUtilities; 72 import java.util.Set ; 73 import java.util.HashSet ; 74 import java.awt.RenderingHints ; 75 import java.util.logging.Level ; 76 import org.netbeans.api.editor.mimelookup.MimePath; 77 import org.netbeans.modules.editor.NbEditorKit; 78 import org.netbeans.modules.editor.impl.KitsTracker; 79 import org.openide.filesystems.Repository; 80 import org.openide.util.Utilities; 81 import org.openide.util.WeakListeners; 82 83 84 85 126 public class BaseOptions extends OptionSupport { 127 128 private static final Logger LOG = Logger.getLogger(BaseOptions.class.getName()); 129 130 133 protected static final int LATEST_OPTIONS_VERSION = 21; 134 135 protected static final String OPTIONS_VERSION_PROP = "optionsVersion"; 137 public static final String ABBREV_MAP_PROP = "abbrevMap"; public static final String BASE = "base"; public static final String CARET_BLINK_RATE_PROP = "caretBlinkRate"; public static final String CARET_COLOR_INSERT_MODE_PROP = "caretColorInsertMode"; public static final String CARET_COLOR_OVERWRITE_MODE_PROP = "caretColorOverwriteMode"; public static final String CARET_ITALIC_INSERT_MODE_PROP = "caretItalicInsertMode"; public static final String CARET_ITALIC_OVERWRITE_MODE_PROP = "caretItalicOverwriteMode"; public static final String CARET_TYPE_INSERT_MODE_PROP = "caretTypeInsertMode"; public static final String CARET_TYPE_OVERWRITE_MODE_PROP = "caretTypeOverwriteMode"; public static final String COLORING_MAP_PROP = "coloringMap"; public static final String EXPAND_TABS_PROP = "expandTabs"; public static final String FIND_HIGHLIGHT_SEARCH_PROP = "findHighlightSearch"; public static final String FIND_HISTORY_PROP = "findHistory"; public static final String FIND_HISTORY_SIZE_PROP = "findHistorySize"; public static final String FIND_INC_SEARCH_DELAY_PROP = "findIncSearchDelay"; public static final String FIND_INC_SEARCH_PROP = "findIncSearch"; public static final String FIND_MATCH_CASE_PROP = "findMatchCase"; public static final String FIND_REG_EXP_PROP = "findRegExp"; public static final String FIND_SMART_CASE_PROP = "findSmartCase"; public static final String FIND_WHOLE_WORDS_PROP = "findWholeWords"; public static final String FIND_WRAP_SEARCH_PROP = "findWrapSearch"; public static final String FIND_BLOCK_SEARCH_PROP = "findBlockSearch"; public static final String FONT_SIZE_PROP = "fontSize"; public static final String HIGHLIGHT_CARET_ROW_PROP = "highlightCaretRow"; public static final String HIGHLIGHT_MATCHING_BRACKET_PROP = "highlightMatchingBracket"; public static final String INDENT_ENGINE_PROP = "indentEngine"; public static final String KEY_BINDING_LIST_PROP = "keyBindingList"; public static final String LINE_HEIGHT_CORRECTION_PROP = "lineHeightCorrection"; public static final String LINE_NUMBER_VISIBLE_PROP = "lineNumberVisible"; public static final String MACRO_MAP_PROP = "macroMap"; public static final String MARGIN_PROP = "margin"; public static final String PAIR_CHARACTERS_COMPLETION = "pairCharactersCompletion"; public static final String SCROLL_FIND_INSETS_PROP = "scrollFindInsets"; public static final String SCROLL_JUMP_INSETS_PROP = "scrollJumpInsets"; public static final String SPACES_PER_TAB_PROP = "spacesPerTab"; public static final String STATUS_BAR_CARET_DELAY_PROP = "statusBarCaretDelay"; public static final String STATUS_BAR_VISIBLE_PROP = "statusBarVisible"; public static final String TAB_SIZE_PROP = "tabSize"; public static final String TEXT_LIMIT_LINE_COLOR_PROP = "textLimitLineColor"; public static final String TEXT_LIMIT_LINE_VISIBLE_PROP = "textLimitLineVisible"; public static final String TEXT_LIMIT_WIDTH_PROP = "textLimitWidth"; public static final String TOOLBAR_VISIBLE_PROP = "toolbarVisible"; public static final String TEXT_ANTIALIASING_PROP = "textAntialiasing"; public static final String CODE_FOLDING_PROPS_PROP = "codeFoldingProps"; 182 protected static final String [] BASE_PROP_NAMES = { 183 ABBREV_MAP_PROP, 184 CARET_BLINK_RATE_PROP, 185 CARET_COLOR_INSERT_MODE_PROP, 186 CARET_COLOR_OVERWRITE_MODE_PROP, 187 CARET_ITALIC_INSERT_MODE_PROP, 188 CARET_ITALIC_OVERWRITE_MODE_PROP, 189 CARET_TYPE_INSERT_MODE_PROP, 190 CARET_TYPE_OVERWRITE_MODE_PROP, 191 COLORING_MAP_PROP, 192 EXPAND_TABS_PROP, 193 FONT_SIZE_PROP, 194 HIGHLIGHT_CARET_ROW_PROP, 195 HIGHLIGHT_MATCHING_BRACKET_PROP, 196 INDENT_ENGINE_PROP, 197 KEY_BINDING_LIST_PROP, 198 LINE_HEIGHT_CORRECTION_PROP, 199 MACRO_MAP_PROP, 201 MARGIN_PROP, 202 PAIR_CHARACTERS_COMPLETION, 203 SCROLL_FIND_INSETS_PROP, 204 SCROLL_JUMP_INSETS_PROP, 205 SPACES_PER_TAB_PROP, 206 STATUS_BAR_CARET_DELAY_PROP, 207 STATUS_BAR_VISIBLE_PROP, 208 TAB_SIZE_PROP, 209 TEXT_LIMIT_LINE_COLOR_PROP, 210 TEXT_LIMIT_LINE_VISIBLE_PROP, 211 TEXT_LIMIT_WIDTH_PROP, 212 OPTIONS_VERSION_PROP 213 }; 214 215 static final long serialVersionUID =-5469192431366914841L; 216 217 private static final String NO_INDENT_ENGINE = "NO_INDENT_ENGINE"; 220 private transient Settings.Initializer coloringMapInitializer; 221 222 223 private transient int optionsVersion; 224 225 226 private transient IndentEngine readExternalIndentEngine; 227 private transient boolean inReadExternal; 228 229 private transient MIMEOptionNode mimeNode; 230 private transient Map defaultAbbrevsMap; 231 private transient Map defaultMacrosMap; 232 private transient Map defaultKeyBindingsMap; 233 private transient MIMEOptionFolder settingsFolder; 234 private transient Boolean usingNewOptions = null; 235 private transient FontColorSettings fontColorSettings; 236 private transient KeyBindingSettings keyBindingsSettings; 237 private transient LookupListener lookupListener; 238 239 private transient boolean coloringsInitialized = false; 240 private transient boolean keybindingsInitialized = false; 241 private transient boolean loaded = false; 242 243 244 private static final HashMap kitClass2Options = new HashMap (); 245 246 247 public static final String CODE_TEMPLATE_EXPAND_KEY = "code-template-expand-key"; 249 private Lookup.Result resultKB; 250 private LookupListener weakLookupListenerKB; 251 private LookupListener lookupListenerKB; 252 253 public BaseOptions() { 254 this(BaseKit.class, BASE); 255 optionsVersion = LATEST_OPTIONS_VERSION; 256 } 257 258 public BaseOptions(Class kitClass, String typeName) { 259 super(kitClass, typeName); 260 kitClass2Options.put(kitClass, this); 261 } 263 264 public boolean usesNewOptionsDialog() { 265 if (usingNewOptions == null) { 266 boolean b = false; 267 if (!BASE.equals(getTypeName())){ 268 FontColorSettings fcs = getFontColorSettings(); 269 if (fcs != null){ 270 AttributeSet as = fcs.getTokenFontColors(FontColorNames.DEFAULT_COLORING); 271 if (as !=null){ 272 b = true; 273 } 274 } 275 } 276 277 usingNewOptions = b ? Boolean.TRUE : Boolean.FALSE; 278 } 279 280 return usingNewOptions.booleanValue(); 281 } 282 283 protected String getContentType(){ 284 BaseKit kit = BaseKit.getKit(getKitClass()); 285 return kit.getContentType(); 286 } 287 288 301 public static BaseOptions getOptions(Class kitClass) { 302 BaseOptions options = null; 303 304 if (kitClass != BaseKit.class && kitClass != NbEditorKit.class) { 305 String mimeType = KitsTracker.getInstance().findMimeType(kitClass); 306 if (mimeType != null) { 307 Lookup lookup = MimeLookup.getLookup(MimePath.parse(mimeType)); 308 options = (BaseOptions) lookup.lookup(BaseOptions.class); 309 } 310 } 311 312 if (options == null) { 314 Class c = kitClass; 317 318 while (c != null) { 319 options = (BaseOptions)kitClass2Options.get(c); 320 if (options != null) 321 break; 322 323 AllOptionsFolder.getDefault().loadMIMEOption(c, false); 324 options = (BaseOptions)kitClass2Options.get(c); 325 if (options != null) 326 break; 327 328 c = c.getSuperclass(); 329 } 330 } 331 332 return options; 333 } 334 335 336 337 341 protected MIMEOptionFolder getMIMEFolder(){ 342 346 String name = getContentType(); 347 if (name == null) { 348 return null; 349 } 350 351 synchronized (Settings.class) { 352 if (settingsFolder!=null) return settingsFolder; 354 355 FileObject f = Repository.getDefault().getDefaultFileSystem(). 356 findResource(AllOptionsFolder.FOLDER+"/"+name); 358 if (f==null){ 360 FileObject fo = Repository.getDefault().getDefaultFileSystem(). 361 findResource(AllOptionsFolder.FOLDER); 362 363 if (fo != null){ 364 try{ 365 StringTokenizer stok = new StringTokenizer (name,"/"); while (stok.hasMoreElements()) { 367 String newFolder = stok.nextToken(); 368 if (fo.getFileObject(newFolder) == null){ 369 fo = fo.createFolder(newFolder); 370 } 371 else 372 fo = fo.getFileObject(newFolder); 373 } 374 }catch(IOException ioe){ 375 ioe.printStackTrace(); 376 } 377 378 f = Repository.getDefault().getDefaultFileSystem(). 379 findResource(AllOptionsFolder.FOLDER+"/"+name); } 381 } 382 383 if (f != null) { 384 try { 385 DataObject d = DataObject.find(f); 386 DataFolder df = (DataFolder)d.getCookie(DataFolder.class); 387 if (df != null) { 388 settingsFolder = new MIMEOptionFolder(df, this); 389 return settingsFolder; 390 } 391 } catch (org.openide.loaders.DataObjectNotFoundException ex) { 392 ex.printStackTrace(); 393 } 394 } 395 396 return null; 397 } 398 } 399 400 401 public MIMEOptionNode getMimeNode() { 402 synchronized (Settings.class) { 403 if (mimeNode == null) { 404 createMIMENode(getTypeName()); 405 } 406 return mimeNode; 407 } 408 } 409 410 411 private void createMIMENode(String typeName){ 412 if (typeName.equals(BASE)){ 413 return; 414 } 415 try{ 416 mimeNode = new MIMEOptionNode(this); 417 }catch(IntrospectionException ie){ 418 ie.printStackTrace(); 419 } 420 } 421 422 protected void updateSettingsMap(Class kitClass, Map settingsMap) { 423 426 loadXMLSettings(); 427 428 super.updateSettingsMap(kitClass, settingsMap); 429 430 if (kitClass == getKitClass()) { 431 settingsMap.put(NbEditorDocument.INDENT_ENGINE, 433 new Settings.Evaluator() { 434 public Object getValue(Class kitClass2, String settingName) { 435 return getIndentEngine(); 436 } 437 } 438 ); 439 440 settingsMap.put(NbEditorDocument.FORMATTER, 441 new Settings.Evaluator() { 442 public Object getValue(Class kitClass2, String settingName) { 443 IndentEngine eng = getIndentEngine(); 444 return (eng != null) 445 ? ((eng instanceof FormatterIndentEngine) 446 ? ((FormatterIndentEngine)eng).getFormatter() 447 : ((Formatter)new IndentEngineFormatter(getKitClass(), eng))) 448 : null; 449 } 450 } 451 ); 452 453 settingsMap.put(SettingsNames.RENDERING_HINTS, 454 new Settings.Evaluator() { 455 public Object getValue(Class kitClass2, String settingName) { 456 return computeTextAntialiasingMap( isTextAntialiasing() ); 457 } 458 } 459 ); 460 461 if (coloringMapInitializer != null) { 462 coloringMapInitializer.updateSettingsMap(kitClass, settingsMap); 463 } 464 } 465 466 if (kitClass == BaseKit.class && coloringMapInitializer != null) { 467 coloringMapInitializer.updateSettingsMap(BaseKit.class, settingsMap); 468 } 469 } 470 471 private Map computeTextAntialiasingMap( boolean aaSetting ) { 472 473 Map result; 474 475 Map defaultHints = (Map )(Toolkit.getDefaultToolkit().getDesktopProperty( 476 "awt.font.desktophints")); 478 if ( defaultHints != null ) { if (true) return defaultHints; 481 482 Object systemSetting = defaultHints.get( RenderingHints.KEY_TEXT_ANTIALIASING ); 483 484 if ( systemSetting == RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT || 485 systemSetting == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF || 486 isGasp( systemSetting ) ) { 487 result = new HashMap (); 488 result.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON ); 489 } 490 else { 491 result = defaultHints; 492 } 493 } 494 else { if ( !aaSetting ) { 496 return Collections.EMPTY_MAP; 497 } 498 result = new HashMap (); 499 result.put(RenderingHints.KEY_TEXT_ANTIALIASING, 500 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 501 } 502 503 return result; 504 } 505 506 private static Object gaspConst = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; 507 508 private boolean isGasp( Object systemSetting ) { 509 if ( gaspConst == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF ) { 511 try { 512 Field aaConst = RenderingHints .class.getField( "VALUE_TEXT_ANTIALIAS_GASP" ); gaspConst = aaConst.get( null ); 514 } 515 catch ( NoSuchFieldException e ) { 516 gaspConst = null; 517 } 518 catch ( IllegalAccessException e ) { 519 gaspConst = null; 520 } 521 } 522 523 return systemSetting == gaspConst; 524 } 525 526 531 532 public int getTabSize() { 533 return getSettingInteger(SettingsNames.TAB_SIZE); 534 } 535 public void setTabSize(int tabSize) { 536 if (tabSize < 0) { 537 NbEditorUtilities.invalidArgument("MSG_NegativeValue"); return; 539 } 540 setSettingInteger(SettingsNames.TAB_SIZE, tabSize, TAB_SIZE_PROP); 541 } 542 543 548 549 public void setExpandTabs(boolean expandTabs) { 550 setSettingBoolean(SettingsNames.EXPAND_TABS, expandTabs, EXPAND_TABS_PROP); 551 } 552 553 558 public void setSpacesPerTab(int i){ 559 if (i > 0) 560 setSettingInteger(SettingsNames.SPACES_PER_TAB, i, SPACES_PER_TAB_PROP); 561 else 562 Toolkit.getDefaultToolkit().beep(); 563 } 564 565 567 public Map getDefaultAbbrevMap(){ 568 loadDefaultAbbreviations(); 569 return defaultAbbrevsMap; 570 } 571 572 574 private void loadDefaultAbbreviations(){ 575 if (defaultAbbrevsMap!=null) return; 576 MIMEOptionFolder mimeFolder = getMIMEFolder(); 577 if (mimeFolder == null) return; 578 MIMEOptionFolder mof = mimeFolder.getFolder(OptionUtilities.DEFAULT_FOLDER); 579 if (mof == null) { 580 return; 581 } 582 583 MIMEOptionFile file = mof.getFile(AbbrevsMIMEProcessor.class, false); 584 if ((file!=null) && (!file.isLoaded())) { 585 file.loadSettings(); 586 defaultAbbrevsMap = new HashMap (file.getAllProperties()); 587 } 588 } 589 590 public Map getAbbrevMap() { 591 loadDefaultAbbreviations(); 592 loadSettings(AbbrevsMIMEProcessor.class); 593 Map settingsMap = (Map )super.getSettingValue(SettingsNames.ABBREV_MAP); 594 if (settingsMap == null){ 595 org.netbeans.editor.Utilities.annotateLoggable(new NullPointerException ("settingsMap is null for kit:"+getKitClass())); } 597 Map ret = (settingsMap == null) ? new HashMap () : new HashMap (settingsMap); 598 return ret; 599 } 600 601 603 public void setAbbrevMap(Map map, boolean saveToXML) { 604 Map diffMap = null; 605 if (saveToXML){ 606 loadDefaultAbbreviations(); 609 diffMap = OptionUtilities.getMapDiff(getAbbrevMap(),map,true); 610 if (diffMap.size()>0){ 611 updateSettings(AbbrevsMIMEProcessor.class, diffMap); 613 } 614 } 615 super.setSettingValue(SettingsNames.ABBREV_MAP, map, ABBREV_MAP_PROP); 616 } 617 618 619 public void setAbbrevMap(Map map) { 620 setAbbrevMap(map, true); 621 } 622 623 public String getCaretTypeInsertMode() { 624 return (String )getSettingValue(SettingsNames.CARET_TYPE_INSERT_MODE); 625 } 626 public void setCaretTypeInsertMode(String type) { 627 setSettingValue(SettingsNames.CARET_TYPE_INSERT_MODE, type, 628 CARET_TYPE_INSERT_MODE_PROP); 629 } 630 631 public String getCaretTypeOverwriteMode() { 632 return (String )getSettingValue(SettingsNames.CARET_TYPE_OVERWRITE_MODE); 633 } 634 public void setCaretTypeOverwriteMode(String type) { 635 setSettingValue(SettingsNames.CARET_TYPE_OVERWRITE_MODE, type, 636 CARET_TYPE_OVERWRITE_MODE_PROP); 637 } 638 639 643 public boolean getCaretItalicInsertMode() { 644 return false; } 646 650 public void setCaretItalicInsertMode(boolean b) { 651 setSettingBoolean(SettingsNames.CARET_ITALIC_INSERT_MODE, b, 652 CARET_ITALIC_INSERT_MODE_PROP); 653 } 654 655 659 public boolean getCaretItalicOverwriteMode() { 660 return false; } 662 666 public void setCaretItalicOverwriteMode(boolean b) { 667 setSettingBoolean(SettingsNames.CARET_ITALIC_OVERWRITE_MODE, b, 668 CARET_ITALIC_OVERWRITE_MODE_PROP); 669 } 670 671 public Color getCaretColorInsertMode() { 672 loadSettings(FontsColorsMIMEProcessor.class); 673 return (Color )super.getSettingValue(SettingsNames.CARET_COLOR_INSERT_MODE); 674 } 675 676 678 public void setCaretColorInsertMode(Color color) { 679 setCaretColorInsertMode(color, true); 680 } 681 682 684 public void setCaretColorInsertMode(Color color, boolean saveToXML) { 685 if (saveToXML){ 686 if (!getCaretColorInsertMode().equals(color) && (color!=null)){ 687 Map map = new HashMap (); 689 map.put(SettingsNames.CARET_COLOR_INSERT_MODE,color); 690 if (map!=null){ 691 updateSettings(FontsColorsMIMEProcessor.class, 692 map); 693 } 694 } 695 } 696 697 super.setSettingValue(SettingsNames.CARET_COLOR_INSERT_MODE, color, 698 CARET_COLOR_INSERT_MODE_PROP); 699 } 700 701 public Color getCaretColorOverwriteMode() { 702 loadSettings(FontsColorsMIMEProcessor.class); 703 return (Color )super.getSettingValue(SettingsNames.CARET_COLOR_OVERWRITE_MODE); 704 } 705 706 708 public void setCaretColorOverwriteMode(Color color) { 709 setCaretColorOverwriteMode(color, true); 710 } 711 712 714 public void setCaretColorOverwriteMode(Color color, boolean saveToXML) { 715 if (saveToXML){ 716 if (!getCaretColorOverwriteMode().equals(color) && (color!=null)){ 717 Map map = new HashMap (); 719 map.put(SettingsNames.CARET_COLOR_OVERWRITE_MODE,color); 720 if (map!=null){ 721 updateSettings(FontsColorsMIMEProcessor.class, 722 map); 723 } 724 } 725 } 726 727 super.setSettingValue(SettingsNames.CARET_COLOR_OVERWRITE_MODE, color, 728 CARET_COLOR_OVERWRITE_MODE_PROP); 729 } 730 731 public int getCaretBlinkRate() { 732 return getSettingInteger(SettingsNames.CARET_BLINK_RATE); 733 } 734 public void setCaretBlinkRate(int rate) { 735 if (rate < 0) { 736 NbEditorUtilities.invalidArgument("MSG_NegativeValue"); return; 738 } 739 setSettingInteger(SettingsNames.CARET_BLINK_RATE, rate, 740 CARET_BLINK_RATE_PROP); 741 } 742 743 public boolean getLineNumberVisible() { 744 return getSettingBoolean(SettingsNames.LINE_NUMBER_VISIBLE); 745 } 746 public void setLineNumberVisible(boolean b) { 747 setSettingBoolean(SettingsNames.LINE_NUMBER_VISIBLE, b, 748 LINE_NUMBER_VISIBLE_PROP); 749 } 750 751 public Insets getScrollJumpInsets() { 752 return (Insets )getSettingValue(SettingsNames.SCROLL_JUMP_INSETS); 753 } 754 public void setScrollJumpInsets(Insets i) { 755 setSettingValue(SettingsNames.SCROLL_JUMP_INSETS, i, 756 SCROLL_JUMP_INSETS_PROP); 757 } 758 759 public Insets getScrollFindInsets() { 760 return (Insets )getSettingValue(SettingsNames.SCROLL_FIND_INSETS); 761 } 762 public void setScrollFindInsets(Insets i) { 763 setSettingValue(SettingsNames.SCROLL_FIND_INSETS, i, 764 SCROLL_FIND_INSETS_PROP); 765 } 766 767 769 public Map getDefaultKeyBindingsMap(){ 770 loadDefaultKeyBindings(); 771 return defaultKeyBindingsMap; 772 } 773 774 776 private void loadDefaultKeyBindings(){ 777 if (defaultKeyBindingsMap!=null) return; 778 MIMEOptionFolder mof; 779 MIMEOptionFolder mimeFolder = AllOptionsFolder.getDefault().getMIMEFolder(); 780 if (mimeFolder == null) return; 781 mof = mimeFolder.getFolder(OptionUtilities.DEFAULT_FOLDER); 782 if (mof == null) { 783 return; 784 } 785 MIMEOptionFile file = mof.getFile(KeyBindingsMIMEProcessor.class, false); 786 if ((file!=null) && (!file.isLoaded())) { 787 file.loadSettings(false); 788 defaultKeyBindingsMap = new HashMap (file.getAllProperties()); 789 } 790 if (!usesNewOptionsDialog() && !BASE.equals(getTypeName())){ 792 super.setSettingValue(SettingsNames.KEY_BINDING_LIST, 793 new ArrayList (defaultKeyBindingsMap.values()), 794 KEY_BINDING_LIST_PROP); 795 } 796 } 797 798 private List getKBList(){ 799 if (!keybindingsInitialized) { 800 keybindingsInitialized = true; 801 if (usesNewOptionsDialog()){ 802 updateKeybindingsFromNewOptionsDialogAttributes(); 803 } else { 804 loadDefaultKeyBindings(); 805 loadSettings(KeyBindingsMIMEProcessor.class); 806 } 807 } 808 809 Class kitClass = getKitClass(); 810 Settings.KitAndValue[] kav = getSettingValueHierarchy(SettingsNames.KEY_BINDING_LIST); 811 List kbList = null; 812 for (int i = 0; i < kav.length; i++) { 813 if (kav[i].kitClass == kitClass) { 814 kbList = (List )kav[i].value; 815 } 816 } 817 if (kbList == null) { 818 kbList = new ArrayList (); 819 } 820 821 int cnt = kbList.size(); 823 for (int i = 0; i < cnt; i++) { 824 Object o = kbList.get(i); 825 if (!(o instanceof MultiKeyBinding) && o != null) { 826 JTextComponent.KeyBinding b = (JTextComponent.KeyBinding )o; 827 kbList.set(i, new MultiKeyBinding(b.key, b.actionName)); 828 } 829 } 830 return new ArrayList ( kbList ); 831 } 832 833 public List getKeyBindingList() { 834 List kb2 = new ArrayList ( getKBList() ); 835 kb2.add( 0, getKitClass().getName() ); return kb2; 837 } 838 839 840 public void setKeyBindingList(List list) { 841 setKeyBindingList(list, true); 842 } 843 844 845 847 public void setKeyBindingsDiffMap(Map diffMap){ 848 if ((diffMap != null) && (diffMap.size()>0)){ 849 updateSettings(KeyBindingsMIMEProcessor.class, diffMap); 850 } 851 } 852 853 854 856 public void setKeyBindingList(List list, boolean saveToXML) { 857 if( list.size() > 0 && 858 ( list.get( 0 ) instanceof Class || list.get( 0 ) instanceof String ) 859 ) { 860 list.remove( 0 ); } 862 863 Map diffMap = null; 864 if (saveToXML){ 865 loadDefaultKeyBindings(); 868 List kbMap = getKeyBindingList(); 869 if( kbMap.size() > 0 && 870 ( kbMap.get( 0 ) instanceof Class || kbMap.get( 0 ) instanceof String ) 871 ) { 872 kbMap.remove( 0 ); } 874 875 diffMap = OptionUtilities.getMapDiff(OptionUtilities.makeKeyBindingsMap(kbMap), 876 OptionUtilities.makeKeyBindingsMap(list),true); 877 if (diffMap.size()>0){ 878 updateSettings(KeyBindingsMIMEProcessor.class, diffMap); 880 } 881 } 882 883 super.setSettingValue(SettingsNames.KEY_BINDING_LIST, list, KEY_BINDING_LIST_PROP); 884 } 885 886 private void updateKeybindingsFromNewOptionsDialogAttributes(){ 887 KeyBindingSettings kbs = getKeybindingSettings(); 888 if (kbs == null){ 889 return; 890 } 891 List newKeybs = new ArrayList (); 892 List newOptionDialogKeybs = kbs.getKeyBindings(); 893 for (int i=0; i<newOptionDialogKeybs.size(); i++){ 895 org.netbeans.api.editor.settings.MultiKeyBinding mkb = 896 (org.netbeans.api.editor.settings.MultiKeyBinding) newOptionDialogKeybs.get(i); 897 List lst = mkb.getKeyStrokeList(); 898 KeyStroke keys[] = new KeyStroke [lst.size()]; 899 lst.toArray(keys); 900 MultiKeyBinding editorMkb = new MultiKeyBinding(keys, mkb.getActionName()); 901 newKeybs.add(editorMkb); 902 } 903 super.setSettingValue(SettingsNames.KEY_BINDING_LIST, newKeybs, KEY_BINDING_LIST_PROP); 904 } 905 906 private void updateColoringsFromNewOptionsDialogAttributes(){ 907 Map m = getColoringMap_old(); 908 m.remove(null); 909 FontColorSettings fcs = getFontColorSettings(); 910 if (fcs == null){ 911 return; 912 } 913 914 for(Iterator it = m.keySet().iterator(); it.hasNext(); ) { 915 String category = (String ) it.next (); 916 if (category == null) continue; 917 918 AttributeSet as = fcs.getTokenFontColors (category); 919 if (as == null) { 920 as = fcs.getFontColors (category); 921 } 922 if (as == null) { 923 System.out.println("ColorBridge.unknown category " + category); continue; 925 } 926 927 m.put(category, Coloring.fromAttributeSet(as)); 928 } 929 m.put(null, getKitClass().getName() ); setColoringMap (m); 931 932 AttributeSet set = (AttributeSet ) fcs.getFontColors(SettingsNames.CARET_COLOR_INSERT_MODE); 934 if (set != null){ 935 Color color = (Color )set.getAttribute(StyleConstants.Foreground); 936 Color current = getCaretColorInsertMode(); 937 if (color!=null && !color.equals(current)){ 938 setCaretColorInsertMode(color); 939 setCaretColorOverwriteMode(color); 940 } 941 } 942 943 set = (AttributeSet ) fcs.getFontColors(SettingsNames.TEXT_LIMIT_LINE_COLOR); 944 if (set != null){ 945 Color color = (Color )set.getAttribute(StyleConstants.Foreground); 946 Color current = getTextLimitLineColor(); 947 if (color!=null && !color.equals(current)){ 948 setTextLimitLineColor(color); 949 } 950 } 951 } 952 953 private KeyBindingSettings getKeybindingSettings() { 954 synchronized (Settings.class) { 955 if (keyBindingsSettings == null){ 956 String mime = getContentType(); 957 Lookup lookup = MimeLookup.getLookup(MimePath.parse(mime)); 958 resultKB = lookup.lookup(new Lookup.Template(KeyBindingSettings.class)); 959 Collection inst = resultKB.allInstances(); 960 lookupListenerKB = new LookupListener(){ 961 public void resultChanged(LookupEvent ev){ 962 Lookup.Result result = ((Lookup.Result)ev.getSource()); 963 Collection newInstances = result.allInstances(); 965 if (newInstances.size() > 0){ 966 keyBindingsSettings = (KeyBindingSettings)newInstances.iterator().next(); 967 } 968 969 updateKeybindingsFromNewOptionsDialogAttributes(); 970 } 971 }; 972 973 weakLookupListenerKB = (LookupListener) WeakListeners.create( 974 LookupListener.class, lookupListenerKB, resultKB); 975 976 resultKB.addLookupListener(weakLookupListenerKB); 977 if (inst.size() > 0){ 978 keyBindingsSettings = (KeyBindingSettings)inst.iterator().next(); 979 } 980 } 981 return keyBindingsSettings; 982 } 983 } 984 985 private FontColorSettings getFontColorSettings() { 986 synchronized (Settings.class) { 987 if (fontColorSettings == null) { 988 String mime = getContentType(); 989 Lookup lookup = MimeLookup.getLookup(MimePath.parse(mime)); 990 Lookup.Result result = lookup.lookup(new Lookup.Template(FontColorSettings.class)); 991 Collection inst = result.allInstances(); 992 lookupListener = new LookupListener(){ 993 public void resultChanged(LookupEvent ev){ 994 Lookup.Result result = ((Lookup.Result)ev.getSource()); 995 Collection newInstances = result.allInstances(); 997 if (newInstances.size() > 0){ 998 fontColorSettings = (FontColorSettings)newInstances.iterator().next(); 999 } 1000 1001 updateColoringsFromNewOptionsDialogAttributes(); 1002 } 1003 }; 1004 result.addLookupListener(lookupListener); 1005 if (inst.size() > 0){ 1006 fontColorSettings = (FontColorSettings)inst.iterator().next(); 1007 } 1008 } 1009 return fontColorSettings; 1010 } 1011 } 1012 1013 public Map getColoringMap() { 1014 if (!coloringsInitialized) { 1015 coloringsInitialized = true; 1016 if (usesNewOptionsDialog()) { 1017 updateColoringsFromNewOptionsDialogAttributes(); 1018 } else { 1019 loadSettings(FontsColorsMIMEProcessor.class); 1020 } 1021 } 1022 1023 return getColoringMap_old(); 1024 } 1025 1026 private Map getColoringMap_old() { 1027 Map settingsMap = SettingsUtil.getColoringMap(getKitClass(), false, true); if (settingsMap == null){ 1029 org.netbeans.editor.Utilities.annotateLoggable(new NullPointerException ("settingsMap is null for kit:"+getKitClass())); } 1031 Map cm = (settingsMap == null) ? new HashMap () : new HashMap (settingsMap); 1032 cm.put(null, getKitClass().getName() ); return cm; 1034 } 1035 1036 1037 public void setColoringMap(Map coloringMap) { 1038 setColoringMap(coloringMap, true); 1039 } 1040 1041 1043 public void setColoringMap(final Map coloringMap, boolean saveToXML){ 1044 Map diffMap = null; 1045 if (coloringMap != null) { 1046 1058 1061 if (!usesNewOptionsDialog() && saveToXML){ 1062 diffMap = OptionUtilities.getMapDiff(getColoringMap(),coloringMap,false); 1063 if (diffMap.size()>0){ 1064 updateSettings(FontsColorsMIMEProcessor.class, diffMap); 1067 } 1068 } 1069 1070 coloringMap.remove(null); 1072 Settings.update(new Runnable () { 1073 public void run() { 1074 SettingsUtil.setColoringMap( getKitClass(), coloringMap, false ); 1075 } 1076 }); 1077 1078 coloringMapInitializer = SettingsUtil.getColoringMapInitializer( 1079 getKitClass(), coloringMap, false, 1080 getTypeName() + "-coloring-map-initializer" ); 1082 1083 firePropertyChange(COLORING_MAP_PROP, null, null); 1084 } 1085 } 1086 1087 public int getFontSize() { 1088 Coloring dc = SettingsUtil.getColoring(getKitClass(), SettingsNames.DEFAULT_COLORING, false); 1089 return (dc != null) ? dc.getFont().getSize() : SettingsDefaults.defaultFont.getSize(); 1090 } 1091 1092 public void setFontSize(final int size) { 1093 if (size < 0) { 1094 NbEditorUtilities.invalidArgument("MSG_NegativeValue"); return; 1096 } 1097 final int oldSize = getFontSize(); 1098 Map cm = SettingsUtil.getColoringMap(getKitClass(), false, true); if (cm != null) { 1100 Iterator it = cm.entrySet().iterator(); 1101 while (it.hasNext()) { 1102 Map.Entry entry = (Map.Entry )it.next(); 1103 Object value = entry.getValue(); 1104 if (value instanceof Coloring) { 1105 Coloring c = (Coloring)value; 1106 Font font = c.getFont(); 1107 if (font != null && font.getSize() != size) { 1108 font = font.deriveFont((float)size); 1109 Coloring newColoring = new Coloring(font, c.getFontMode(), 1110 c.getForeColor(), c.getBackColor()); entry.setValue(newColoring); 1112 } 1113 } 1114 } 1115 setColoringMap(cm); 1116 1117 firePropertyChange(FONT_SIZE_PROP, null, null); 1118 } 1119 } 1120 1121 public float getLineHeightCorrection() { 1122 return ((Float ) getSettingValue(SettingsNames.LINE_HEIGHT_CORRECTION)).floatValue(); 1123 } 1124 public void setLineHeightCorrection(float f) { 1125 if (f <= 0) { 1126 NbEditorUtilities.invalidArgument("MSG_OutOfRange"); return; 1128 } 1129 setSettingValue(SettingsNames.LINE_HEIGHT_CORRECTION, new Float (f), 1130 LINE_HEIGHT_CORRECTION_PROP); 1131 } 1132 1133 1135 public Map getDefaultMacrosMap(){ 1136 loadDefaultMacros(); 1137 return defaultMacrosMap; 1138 } 1139 1140 1142 private void loadDefaultMacros(){ 1143 if (defaultMacrosMap!=null) return; 1144 MIMEOptionFolder mimeFolder = getMIMEFolder(); 1145 if (mimeFolder == null) return; 1146 1147 MIMEOptionFolder mof = mimeFolder.getFolder(OptionUtilities.DEFAULT_FOLDER); 1148 if (mof == null) return; 1149 1150 MIMEOptionFile file = mof.getFile(MacrosMIMEProcessor.class, false); 1151 if ((file!=null) && (!file.isLoaded())) { 1152 file.loadSettings(false); 1153 defaultMacrosMap = new HashMap (file.getAllProperties()); 1154 } 1155 } 1156 1157 1159 private void processMacroKeyBindings(Map diff, List oldKB){ 1160 List deletedKB = new ArrayList (); 1161 List addedKB = new ArrayList (); 1162 List newKB = getKBList(); 1163 1164 for( Iterator i = diff.keySet().iterator(); i.hasNext(); ) { 1165 String key = (String )i.next(); 1166 if (!(diff.get(key) instanceof String )) continue; 1167 String action = (String ) diff.get(key); 1168 String kbActionName = BaseKit.macroActionPrefix+key; 1169 1170 if (action.length()!=0){ 1171 for (int j = 0; j < oldKB.size(); j++){ 1173 if(oldKB.get(j) instanceof MultiKeyBinding){ 1174 MultiKeyBinding mkb = (MultiKeyBinding) oldKB.get(j); 1175 if (!kbActionName.equals(mkb.actionName)) continue; 1176 addedKB.add(mkb); 1177 break; 1178 } 1179 } 1180 continue; 1181 } 1182 1183 for (int j = 0; j < newKB.size(); j++){ 1184 if(newKB.get(j) instanceof MultiKeyBinding){ 1186 MultiKeyBinding mkb = (MultiKeyBinding) newKB.get(j); 1187 if (!kbActionName.equals(mkb.actionName)) continue; 1188 deletedKB.add(mkb); 1189 break; 1190 } 1191 } 1192 } 1193 1194 if ((deletedKB.size()>0) || (addedKB.size()>0)){ 1195 newKB.removeAll(deletedKB); 1196 newKB.addAll(addedKB); 1197 setKeyBindingsDiffMap(OptionUtilities.getMapDiff(OptionUtilities.makeKeyBindingsMap(getKBList()), 1199 OptionUtilities.makeKeyBindingsMap(newKB), true)); 1200 Settings.setValue( getKitClass(), SettingsNames.KEY_BINDING_LIST, newKB); 1202 } 1203 } 1204 1205 1206 public Map getMacroMap() { 1207 loadDefaultMacros(); 1208 loadSettings(MacrosMIMEProcessor.class); 1209 Map settingsMap = (Map )super.getSettingValue(SettingsNames.MACRO_MAP); 1210 if (settingsMap == null){ 1211 org.netbeans.editor.Utilities.annotateLoggable(new NullPointerException ("settingsMap is null for kit:"+getKitClass())); } 1213 Map ret = (settingsMap == null) ? new HashMap () : new HashMap (settingsMap); 1214 ret.put(null, getKBList()); 1215 return ret; 1216 } 1217 1218 1220 public void setMacroDiffMap(Map diffMap){ 1221 if ((diffMap != null) && (diffMap.size()>0)){ 1222 updateSettings(MacrosMIMEProcessor.class, diffMap); 1223 } 1224 } 1225 1226 1228 public void setMacroMap(Map map, boolean saveToXML) { 1229 Map diffMap = null; 1230 List kb = new ArrayList (); 1231 if (map.containsKey(null)){ 1232 kb.addAll((List )map.get(null)); 1233 map.remove(null); 1234 } 1235 if (saveToXML){ 1236 loadDefaultMacros(); 1239 diffMap = OptionUtilities.getMapDiff(getMacroMap(),map,true); 1240 if (diffMap.containsKey(null)) diffMap.remove(null); 1241 if (diffMap.size()>0){ 1242 processMacroKeyBindings(diffMap,kb); 1244 updateSettings(MacrosMIMEProcessor.class, diffMap); 1245 } 1246 } 1247 1248 super.setSettingValue(SettingsNames.MACRO_MAP, map); 1249 } 1250 1251 1252 public void setMacroMap(Map map) { 1253 setMacroMap(map, true); 1254 } 1255 1256 public Insets getMargin() { 1257 return (Insets )getSettingValue(SettingsNames.MARGIN); 1258 } 1259 public void setMargin(Insets i) { 1260 setSettingValue(SettingsNames.MARGIN, i, MARGIN_PROP); 1261 } 1262 1263 public boolean getStatusBarVisible() { 1264 return getSettingBoolean(SettingsNames.STATUS_BAR_VISIBLE); 1265 } 1266 public void setStatusBarVisible(boolean v) { 1267 setSettingBoolean(SettingsNames.STATUS_BAR_VISIBLE, v, STATUS_BAR_VISIBLE_PROP); 1268 } 1269 1270 public int getStatusBarCaretDelay() { 1271 return getSettingInteger(SettingsNames.STATUS_BAR_CARET_DELAY); 1272 } 1273 public void setStatusBarCaretDelay(int delay) { 1274 if (delay < 0) { 1275 NbEditorUtilities.invalidArgument("MSG_NegativeValue"); return; 1277 } 1278 setSettingInteger(SettingsNames.STATUS_BAR_CARET_DELAY, delay, 1279 STATUS_BAR_CARET_DELAY_PROP); 1280 } 1281 1282 public boolean getFindHighlightSearch() { 1283 return getSettingBoolean(SettingsNames.FIND_HIGHLIGHT_SEARCH); 1284 } 1285 1286 public void setFindHighlightSearch(boolean b) { 1287 setSettingBoolean(SettingsNames.FIND_HIGHLIGHT_SEARCH, b, 1288 FIND_HIGHLIGHT_SEARCH_PROP); 1289 } 1290 1291 public boolean getFindBlockSearch() { 1292 return getSettingBoolean(SettingsNames.FIND_BLOCK_SEARCH); 1293 } 1294 1295 public void setFindBlockSearch(boolean b) { 1296 setSettingBoolean(SettingsNames.FIND_BLOCK_SEARCH, b, FIND_BLOCK_SEARCH_PROP); 1297 } 1298 1299 public boolean getFindIncSearch() { 1300 return getSettingBoolean(SettingsNames.FIND_INC_SEARCH); 1301 } 1302 1303 public void setFindIncSearch(boolean b) { 1304 setSettingBoolean(SettingsNames.FIND_INC_SEARCH, b, FIND_INC_SEARCH_PROP); 1305 } 1306 1307 public int getFindIncSearchDelay() { 1308 return getSettingInteger(SettingsNames.FIND_INC_SEARCH_DELAY); 1309 } 1310 1311 public void setFindIncSearchDelay(int delay) { 1312 if (delay < 0) { 1313 NbEditorUtilities.invalidArgument("MSG_NegativeValue"); return; 1315 } 1316 setSettingInteger(SettingsNames.FIND_INC_SEARCH_DELAY, delay, 1317 FIND_INC_SEARCH_DELAY_PROP); 1318 } 1319 1320 public boolean getFindWrapSearch() { 1321 return getSettingBoolean(SettingsNames.FIND_WRAP_SEARCH); 1322 } 1323 1324 public void setFindWrapSearch(boolean b) { 1325 setSettingBoolean(SettingsNames.FIND_WRAP_SEARCH, b, 1326 FIND_WRAP_SEARCH_PROP); 1327 } 1328 1329 public boolean getFindSmartCase() { 1330 return getSettingBoolean(SettingsNames.FIND_SMART_CASE); 1331 } 1332 1333 public void setFindSmartCase(boolean b) { 1334 setSettingBoolean(SettingsNames.FIND_SMART_CASE, b, FIND_SMART_CASE_PROP); 1335 } 1336 1337 public Map getFindHistory() { 1338 return new HashMap ( (Map )getSettingValue(SettingsNames.FIND_HISTORY) ); 1339 } 1340 1341 public void setFindHistory(Map m) { 1342 setSettingValue(SettingsNames.FIND_HISTORY, m, FIND_HISTORY_PROP); 1343 } 1344 1345 public int getFindHistorySize() { 1346 return getSettingInteger(SettingsNames.FIND_HISTORY_SIZE); 1347 } 1348 1349 public void setFindHistorySize(int size) { 1350 setSettingInteger(SettingsNames.FIND_HISTORY_SIZE, size, 1351 FIND_HISTORY_SIZE_PROP); 1352 } 1353 1354 public boolean getPairCharactersCompletion() { 1355 return getSettingBoolean(SettingsNames.PAIR_CHARACTERS_COMPLETION); 1356 } 1357 1358 public void setPairCharactersCompletion(boolean v) { 1359 setSettingBoolean(SettingsNames.PAIR_CHARACTERS_COMPLETION, v, 1360 PAIR_CHARACTERS_COMPLETION); 1361 } 1362 1363 1364 public Color getTextLimitLineColor() { 1365 loadSettings(FontsColorsMIMEProcessor.class); 1366 return (Color )super.getSettingValue(SettingsNames.TEXT_LIMIT_LINE_COLOR); 1367 } 1368 1369 1371 public void setTextLimitLineColor(Color color) { 1372 setTextLimitLineColor(color, true); 1373 } 1374 1375 1377 public void setTextLimitLineColor(Color color , boolean saveToXML) { 1378 if (saveToXML){ 1379 if (!getTextLimitLineColor().equals(color) && (color!=null)){ 1380 Map map = new HashMap (); 1382 map.put(SettingsNames.TEXT_LIMIT_LINE_COLOR,color); 1383 if (map!=null){ 1384 updateSettings(FontsColorsMIMEProcessor.class, 1385 map); 1386 } 1387 } 1388 } 1389 1390 super.setSettingValue(SettingsNames.TEXT_LIMIT_LINE_COLOR, color, 1391 TEXT_LIMIT_LINE_COLOR_PROP); 1392 } 1393 1394 public int getTextLimitWidth() { 1395 return getSettingInteger(SettingsNames.TEXT_LIMIT_WIDTH); 1396 } 1397 1398 public void setTextLimitWidth(int width) { 1399 if (width <= 0) { 1400 NbEditorUtilities.invalidArgument("MSG_OutOfRange"); return; 1402 } 1403 setSettingInteger(SettingsNames.TEXT_LIMIT_WIDTH, width, 1404 TEXT_LIMIT_WIDTH_PROP); 1405 } 1406 1407 public boolean getTextLimitLineVisible() { 1408 return getSettingBoolean(SettingsNames.TEXT_LIMIT_LINE_VISIBLE); 1409 } 1410 1411 public void setTextLimitLineVisible(boolean visible) { 1412 setSettingBoolean(SettingsNames.TEXT_LIMIT_LINE_VISIBLE, visible, 1413 TEXT_LIMIT_LINE_VISIBLE_PROP); 1414 } 1415 1416 public boolean getHighlightMatchingBracket() { 1417 return getSettingBoolean(ExtSettingsNames.HIGHLIGHT_MATCH_BRACE); 1418 } 1419 1420 public void setHighlightMatchingBracket(boolean highlight) { 1421 setSettingBoolean(ExtSettingsNames.HIGHLIGHT_MATCH_BRACE, highlight, 1422 HIGHLIGHT_MATCHING_BRACKET_PROP); 1423 } 1424 1425 public boolean getHighlightCaretRow() { 1426 return getSettingBoolean(ExtSettingsNames.HIGHLIGHT_CARET_ROW); 1427 } 1428 1429 public void setHighlightCaretRow(boolean highlight) { 1430 setSettingBoolean(ExtSettingsNames.HIGHLIGHT_CARET_ROW, highlight, 1431 HIGHLIGHT_CARET_ROW_PROP); 1432 } 1433 1434 public boolean isToolbarVisible() { 1435 return getSettingBoolean(TOOLBAR_VISIBLE_PROP); 1436 } 1437 1438 public void setToolbarVisible(boolean toolbarVisible) { 1439 setSettingBoolean(TOOLBAR_VISIBLE_PROP, toolbarVisible, TOOLBAR_VISIBLE_PROP); 1440 } 1441 1442 public boolean isTextAntialiasing() { 1443 Boolean val = (Boolean )getSettingValue(TEXT_ANTIALIASING_PROP); 1445 if (val != null) { 1446 return val.booleanValue(); 1447 } else { 1448 if (Boolean.getBoolean("javax.aatext")) { 1453 return true; 1454 1455 } else { 1456 if (Utilities.isMac()) { 1458 return true; 1460 } else { 1461 return isSystemAntialias(); 1462 } 1463 } 1464 } 1465 } 1466 1467 private static boolean isSystemAntialias() { 1468 Map systemHints = (Map )(Toolkit.getDefaultToolkit().getDesktopProperty( 1469 "awt.font.desktophints")); if (systemHints != null) { 1471 Object o = systemHints.get(RenderingHints.KEY_TEXT_ANTIALIASING); 1472 boolean result = o != null && 1473 o != RenderingHints.VALUE_TEXT_ANTIALIAS_OFF && 1474 o != RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT; 1475 return result; 1476 } else { 1477 return false; 1478 } 1479 } 1480 1481 public void setTextAntialiasing(boolean textAntialiasing) { 1482 setSettingBoolean(TEXT_ANTIALIASING_PROP, textAntialiasing, TEXT_ANTIALIASING_PROP); 1483 Settings.touchValue(getKitClass(), SettingsNames.RENDERING_HINTS); 1485 } 1486 1487 public Map getCodeFoldingProps(){ 1488 Map map = new HashMap (); 1489 1490 Boolean val = (Boolean )getSettingValue(SettingsNames.CODE_FOLDING_ENABLE); 1491 map.put(SettingsNames.CODE_FOLDING_ENABLE, val); 1492 1493 return map; 1494 } 1495 1496 public void setCodeFoldingProps(Map props){ 1497 String name = SettingsNames.CODE_FOLDING_ENABLE; 1498 setSettingValue(name, props.get(name)); 1499 } 1500 1501 1502 public void initPopupMenuItems(){ 1503 List orderedPopupFiles = getOrderedMultiPropertyFolderFiles("Popup"); } 1509 1510 public List getOrderedMultiPropertyFolderFiles(String folderName){ 1511 if (!BASE.equals(getTypeName())){ 1512 MIMEOptionFolder mimeFolder = getMIMEFolder(); 1513 if (mimeFolder != null){ 1514 MultiPropertyFolder mpf = mimeFolder.getMPFolder(folderName,false); if (mpf!=null){ 1516 DataFolder df = mpf.getDataFolder(); 1517 List mimeFolderAttribs = new ArrayList (); 1518 for (Enumeration e = df.getPrimaryFile().getAttributes() ; e.hasMoreElements() ;) { 1519 mimeFolderAttribs.add(e.nextElement()); 1520 } 1521 1522 if ( (mpf.getProperties().size()!=0) || (mimeFolderAttribs.size() != 0)) { 1524 1525 Set mergedItems = new HashSet (OptionUtilities.getGlobalMenuItems(folderName)); 1528 1529 mergedItems.addAll(mpf.getProperties()); 1530 1531 Set mergedAttribs = new HashSet (OptionUtilities.getGlobalAttribs(folderName)); 1533 mergedAttribs.addAll(mimeFolderAttribs); 1534 1535 return OptionUtilities.arrangeMergedFolderObjects(mergedItems, mergedAttribs); 1537 } 1538 } 1539 } 1540 } 1541 1542 return OptionUtilities.getGlobalMenuItems(folderName); 1543 } 1544 1545 public IndentEngine getIndentEngine() { 1546 if (inReadExternal) { 1548 return readExternalIndentEngine; 1549 } 1550 1551 if (!BASE.equals(getTypeName())){ 1552 loadSettings(PropertiesMIMEProcessor.class); 1553 1554 MIMEOptionFile file; 1555 MIMEOptionFolder mimeFolder = getMIMEFolder(); 1556 if (mimeFolder != null){ 1557 file= mimeFolder.getFile(PropertiesMIMEProcessor.class, false); 1558 if (file != null) { 1559 Map setMap = file.getAllProperties(); 1560 Object handle = setMap.get(INDENT_ENGINE_PROP); 1561 if (handle instanceof String ){ 1562 Object instance = null; 1563 String handleString = (String ) handle; 1564 1565 if (handleString.equals(NO_INDENT_ENGINE)){ 1566 return IndentEngine.getDefault(); 1567 } 1568 1569 Lookup.Template tmp = new Lookup.Template(null, handleString, null); 1570 Lookup.Item item = Lookup.getDefault().lookupItem(tmp); 1571 if (item != null) { 1572 instance = item.getInstance(); 1573 if(instance instanceof IndentEngine){ 1574 return (IndentEngine) instance; 1575 } 1576 } 1577 1578 } 1579 } 1580 } 1581 1582 } 1583 1584 1588 Object o = getProperty(INDENT_ENGINE_PROP); 1589 if (o instanceof IndentEngine.Handle) { 1590 IndentEngine eng = (IndentEngine)((IndentEngine.Handle)o).getServiceType(); 1591 if (eng != null) { 1592 setIndentEngine(eng); 1593 return eng; 1594 } 1595 1596 } else if (o instanceof IndentEngine) { 1597 setIndentEngine((IndentEngine)o); 1598 return (IndentEngine)o; 1599 } 1600 1602 1603 IndentEngine eng = findDefaultIndentEngine(); 1605 if (eng != null) { setIndentEngine(eng); 1607 } 1608 1609 return eng; 1610 } 1611 1612 public void setIndentEngine(IndentEngine eng) { 1613 1617 if (!inReadExternal) { 1618 String id = null; 1619 if (eng != null) { 1620 Lookup.Template tmp = new Lookup.Template(null, null, eng); 1621 Lookup.Item item = Lookup.getDefault().lookupItem(tmp); 1622 if (item != null) id = item.getId(); 1623 1624 } 1625 1626 if (!BASE.equals(getTypeName())){ 1627 Map map = new HashMap (); 1628 if (id == null) id = NO_INDENT_ENGINE; 1629 map.put(INDENT_ENGINE_PROP, id); 1630 updateSettings(PropertiesMIMEProcessor.class, map, false); 1631 } 1632 1633 refreshIndentEngineSettings(); 1634 } 1635 } 1636 1637 private void refreshIndentEngineSettings() { 1638 RequestProcessor.postRequest(new Runnable (){ 1640 public void run(){ 1641 Settings.touchValue(getKitClass(), NbEditorDocument.INDENT_ENGINE); 1642 Settings.touchValue(getKitClass(), NbEditorDocument.FORMATTER); 1643 } 1644 }); 1645 } 1646 1647 1648 protected Class getDefaultIndentEngineClass() { 1649 return SimpleIndentEngine.class; 1650 } 1651 1652 private IndentEngine findDefaultIndentEngine() { 1653 if (getDefaultIndentEngineClass() != null) { 1654 return (IndentEngine) Lookup.getDefault().lookup(getDefaultIndentEngineClass()); 1655 } 1656 1657 return null; 1658 } 1659 1660 public void setOptionsVersion(int optionsVersion) { 1661 int oldOptionsVersion = this.optionsVersion; 1662 this.optionsVersion = optionsVersion; 1663 1664 if (optionsVersion != oldOptionsVersion) { 1665 firePropertyChange(OPTIONS_VERSION_PROP, 1666 new Integer (oldOptionsVersion), new Integer (optionsVersion)); 1667 } 1668 1669 } 1670 1671 public int getOptionsVersion() { 1672 return optionsVersion; 1673 } 1674 1675 public void readExternal(ObjectInput in) 1676 throws IOException , ClassNotFoundException { 1677 1678 1679 readExternalIndentEngine = getIndentEngine(); 1680 inReadExternal = true; 1681 1682 1689 optionsVersion = 0; 1690 1691 try { 1692 super.readExternal(in); 1694 }catch(java.io.OptionalDataException ode){ 1695 } finally { 1697 1698 refreshIndentEngineSettings(); 1701 1702 1707 optionsVersion = LATEST_OPTIONS_VERSION; 1708 1709 1710 inReadExternal = false; 1711 readExternalIndentEngine = null; 1712 } 1713 } 1714 1715 1720 protected void upgradeOptions(int version, int latestVersion) { 1721 } 1724 1725 1726 private void loadSettings(Class processor){ 1727 MIMEOptionFile file; 1728 if (BASE.equals(getTypeName())){ 1729 MIMEOptionFolder mimeFolder = AllOptionsFolder.getDefault().getMIMEFolder(); 1730 if (mimeFolder == null) return; 1731 file= mimeFolder.getFile(processor, false); 1732 }else{ 1733 MIMEOptionFolder mimeFolder = getMIMEFolder(); 1734 if (mimeFolder == null) return; 1735 file= mimeFolder.getFile(processor, false); 1736 } 1737 if ((file!=null) && (!file.isLoaded())) { 1738 file.loadSettings(); 1739 } 1740 } 1741 1742 1745 private void updateSettings(Class processor, Map settings){ 1746 updateSettings(processor, settings, true); 1747 } 1748 1749 1754 private void updateSettings(Class processor, Map settings, boolean useRequestProcessorForSaving){ 1755 if (usesNewOptionsDialog() && ( 1756 processor == FontsColorsMIMEProcessor.class || 1757 processor == KeyBindingsMIMEProcessor.class 1758 )) { 1759 return; 1760 } 1761 MIMEOptionFile fileX; 1762 MIMEOptionFolder mimeFolder; 1763 if (BASE.equals(getTypeName())){ 1764 mimeFolder = AllOptionsFolder.getDefault().getMIMEFolder(); 1765 if (mimeFolder == null) return; 1766 fileX = mimeFolder.getFile(processor, true); 1767 }else{ 1768 mimeFolder = getMIMEFolder(); 1769 if (mimeFolder == null) return; 1770 fileX = mimeFolder.getFile(processor, true); 1771 } 1772 final Map finalSettings = settings; 1773 final MIMEOptionFile file = fileX; 1774 if (file!=null){ 1775 if (useRequestProcessorForSaving){ 1776 RequestProcessor.postRequest(new Runnable (){ 1777 public void run(){ 1778 file.updateSettings(finalSettings); 1779 } 1780 }); 1781 }else{ 1782 file.updateSettings(finalSettings); 1783 } 1784 1785 } else { 1786 LOG.info("A settings file for " + processor + " does not exist in " + mimeFolder.getDataFolder()); } 1788 } 1789 1790 public void setSettingValue(String settingName, Object newValue) { 1791 setSettingValue(settingName, newValue, settingName); 1792 } 1793 1794 private boolean isTheSame(String settingName, Object newValue){ 1795 if (settingName == null || 1796 settingName.equals(NbEditorDocument.INDENT_ENGINE) || 1797 settingName.equals(NbEditorDocument.FORMATTER) ){ 1798 return true; 1799 } 1800 Object oldValue = getSettingValue(settingName); 1801 if ((oldValue == null && newValue == null) 1802 || (oldValue != null && oldValue.equals(newValue)) 1803 ) { 1804 return true; } 1806 return false; 1807 } 1808 1809 1811 public void setSettingValue(String settingName, Object newValue, 1812 String propertyName) { 1813 if (!isTheSame(settingName, newValue)){ 1814 Map map = new HashMap (); 1815 map.put(settingName, newValue); 1816 updateSettings(PropertiesMIMEProcessor.class, map); 1817 } 1818 super.setSettingValue(settingName,newValue,propertyName); 1819 } 1820 1821 public Object getSettingValue(String settingName) { 1822 loadSettings(PropertiesMIMEProcessor.class); 1823 return super.getSettingValue(settingName); 1824 } 1825 1826 protected final void setSettingBoolean(String settingName, boolean newValue, String propertyName) { 1827 setSettingValue(settingName, newValue ? Boolean.TRUE : Boolean.FALSE); 1828 } 1829 1830 protected final void setSettingInteger(String settingName, int newValue, String propertyName) { 1831 setSettingValue(settingName, new Integer (newValue)); 1832 } 1833 1834 1835 protected void loadXMLSettings() { 1836 if (!loaded) { 1837 loaded = true; 1838 if (LOG.isLoggable(Level.FINE)) { 1839 LOG.fine("Loading " + getClass() + "; mimeType='" + getContentType() + "'"); } 1841 1842 getKeyBindingList(); 1843 getAbbrevMap(); 1844 getMacroMap(); 1845 getColoringMap(); 1846 loadSettings(PropertiesMIMEProcessor.class); 1847 1848 if (LOG.isLoggable(Level.FINE)) { 1849 LOG.fine("Loaded! " + getClass() + "; mimeType='" + getContentType() + "'"); } 1851 } else { 1852 if (LOG.isLoggable(Level.FINE)) { 1853 LOG.fine("Already loaded! " + getClass() + "; mimeType='" + getContentType() + "'"); } 1855 } 1856 } 1857 1858 1859 public void writeExternal() throws IOException { 1860 } 1861 1862 1863 public void writeExternal(ObjectOutput out) throws IOException { 1864 } 1865 1866 protected void firePropertyChange(String name, Object oldValue, Object newValue){ 1867 } 1871 1872 1873 public static void setCodeTemplateExpandKey(KeyStroke ks){ 1874 String s = OptionUtilities.keyToString(ks); 1875 BaseOptions base = getOptions(BaseKit.class); 1876 Map map = new HashMap (); 1877 map.put(CODE_TEMPLATE_EXPAND_KEY, s); 1878 base.updateSettings(PropertiesMIMEProcessor.class, map); 1879 } 1880 1881 1882 public static KeyStroke getCodeTemplateExpandKey(){ 1883 MIMEOptionFolder mimeFolder = AllOptionsFolder.getDefault().getMIMEFolder(); 1884 if (mimeFolder != null){ 1885 MIMEOptionFile file = mimeFolder.getFile(PropertiesMIMEProcessor.class, false); 1886 if (file != null){ 1887 if (!file.isLoaded()) { 1888 file.loadSettings(false); 1889 } 1890 Map properties = file.getAllProperties(); 1891 String s = (String ) properties.get(CODE_TEMPLATE_EXPAND_KEY); 1892 if (s != null){ 1893 return OptionUtilities.stringToKey(s); 1894 } 1895 } 1896 } 1897 return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); 1898 } 1899} 1900 | Popular Tags |