KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > options > BaseOptions


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
20 package org.netbeans.modules.editor.options;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.awt.Insets JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.ObjectInput JavaDoc;
27 import java.lang.reflect.Field JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.Collections JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.Enumeration JavaDoc;
36 import java.util.logging.Logger JavaDoc;
37 import javax.swing.text.AttributeSet JavaDoc;
38 import javax.swing.text.JTextComponent JavaDoc;
39 import java.awt.Toolkit JavaDoc;
40 import javax.swing.text.StyleConstants JavaDoc;
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 JavaDoc;
60 import org.openide.loaders.DataObject;
61 import java.io.ObjectOutput JavaDoc;
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 JavaDoc;
68 import java.awt.event.KeyEvent JavaDoc;
69 import org.openide.util.Lookup;
70 import java.util.StringTokenizer JavaDoc;
71 import org.netbeans.modules.editor.NbEditorUtilities;
72 import java.util.Set JavaDoc;
73 import java.util.HashSet JavaDoc;
74 import java.awt.RenderingHints JavaDoc;
75 import java.util.logging.Level JavaDoc;
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 /**
86  * Options for the base editor kit.
87  *
88  * <b>Mime type vs editor kit class</b>
89  *
90  * <p>The <code>BaseOptions</code> class suffers the conceptual problem introduced
91  * in the editor infrastructure in early days of the Netbeans project. The problem
92  * is that an implementation class of an editor kit is used for determining the
93  * mime type of a file being edited. Following this concept a lot of other stuff
94  * in the editor infrastructure tied up its initialization or registration with
95  * editor kit implementation classes. While in many situations this only causes
96  * efficiency problems or coding annoyances it is disasterous for modules that
97  * need to provide dynamic support for many mime types.
98  *
99  * <p>The following description tries to remedy the situation by providing guidelines
100  * for writing <code>BaseOptions<code> subclasses that are nearly editor kit
101  * independent.
102  *
103  * <p>First, use <code>MimeLookup</code> whenever you can and avoid using static
104  * getters such as <code>getOptions(Class editorKitClass)</code>. Although the
105  * current <code>MimeLookup</code> infrastructure allows registering editor related
106  * classes in a declrative way based on a mime type the <code>getOptions</code> method
107  * can't simply query <code>MimeLookup</code>, because it doesn't know the mime type!
108  * The correct way of retrieving an instance of your options class from
109  * <code>MimeLookup</code> is this:
110  *
111  * <pre>
112  * MimePath mimePath = MimePath.parse("your-mime-type-here");
113  * YourOptions options = MimeLookup.getLookup(mimePath).lookup(YourOptions.class);
114  * </pre>
115  *
116  * <p>When implementing <code>BaseOptions</code> for a specific mime type override
117  * the <code>getContentType</code> method and return your mime type. Besides the
118  * <code>getOptions</code> method this is currently the only place in this class
119  * where an editor kit implementation class is used.
120  *
121  *
122  * @author Miloslav Metelka
123  * @author Vita Stejskal
124  * @version 1.1
125  */

126 public class BaseOptions extends OptionSupport {
127
128     private static final Logger JavaDoc LOG = Logger.getLogger(BaseOptions.class.getName());
129     
130     /** Latest version of the options. It must be increased
131      * manually when new patch is added to the options.
132      */

133     protected static final int LATEST_OPTIONS_VERSION = 21;
134     
135     protected static final String JavaDoc OPTIONS_VERSION_PROP = "optionsVersion"; // NOI18N
136

137     public static final String JavaDoc ABBREV_MAP_PROP = "abbrevMap"; // NOI18N
138
public static final String JavaDoc BASE = "base"; // NOI18N
139
public static final String JavaDoc CARET_BLINK_RATE_PROP = "caretBlinkRate"; // NOI18N
140
public static final String JavaDoc CARET_COLOR_INSERT_MODE_PROP = "caretColorInsertMode"; // NOI18N
141
public static final String JavaDoc CARET_COLOR_OVERWRITE_MODE_PROP = "caretColorOverwriteMode"; // NOI18N
142
public static final String JavaDoc CARET_ITALIC_INSERT_MODE_PROP = "caretItalicInsertMode"; // NOI18N
143
public static final String JavaDoc CARET_ITALIC_OVERWRITE_MODE_PROP = "caretItalicOverwriteMode"; // NOI18N
144
public static final String JavaDoc CARET_TYPE_INSERT_MODE_PROP = "caretTypeInsertMode"; // NOI18N
145
public static final String JavaDoc CARET_TYPE_OVERWRITE_MODE_PROP = "caretTypeOverwriteMode"; // NOI18N
146
public static final String JavaDoc COLORING_MAP_PROP = "coloringMap"; // NOI18N
147
public static final String JavaDoc EXPAND_TABS_PROP = "expandTabs"; // NOI18N
148
public static final String JavaDoc FIND_HIGHLIGHT_SEARCH_PROP = "findHighlightSearch"; // NOI18N
149
public static final String JavaDoc FIND_HISTORY_PROP = "findHistory"; // NOI18N
150
public static final String JavaDoc FIND_HISTORY_SIZE_PROP = "findHistorySize"; // NOI18N
151
public static final String JavaDoc FIND_INC_SEARCH_DELAY_PROP = "findIncSearchDelay"; // NOI18N
152
public static final String JavaDoc FIND_INC_SEARCH_PROP = "findIncSearch"; // NOI18N
153
public static final String JavaDoc FIND_MATCH_CASE_PROP = "findMatchCase"; // NOI18N
154
public static final String JavaDoc FIND_REG_EXP_PROP = "findRegExp"; // NOI18N
155
public static final String JavaDoc FIND_SMART_CASE_PROP = "findSmartCase"; // NOI18N
156
public static final String JavaDoc FIND_WHOLE_WORDS_PROP = "findWholeWords"; // NOI18N
157
public static final String JavaDoc FIND_WRAP_SEARCH_PROP = "findWrapSearch"; // NOI18N
158
public static final String JavaDoc FIND_BLOCK_SEARCH_PROP = "findBlockSearch"; // NOI18N
159
public static final String JavaDoc FONT_SIZE_PROP = "fontSize"; // NOI18N
160
public static final String JavaDoc HIGHLIGHT_CARET_ROW_PROP = "highlightCaretRow"; // NOI18N
161
public static final String JavaDoc HIGHLIGHT_MATCHING_BRACKET_PROP = "highlightMatchingBracket"; // NOI18N
162
public static final String JavaDoc INDENT_ENGINE_PROP = "indentEngine"; // NOI18N
163
public static final String JavaDoc KEY_BINDING_LIST_PROP = "keyBindingList"; // NOI18N
164
public static final String JavaDoc LINE_HEIGHT_CORRECTION_PROP = "lineHeightCorrection"; // NOI18N
165
public static final String JavaDoc LINE_NUMBER_VISIBLE_PROP = "lineNumberVisible"; // NOI18N
166
public static final String JavaDoc MACRO_MAP_PROP = "macroMap"; // NOI18N
167
public static final String JavaDoc MARGIN_PROP = "margin"; // NOI18N
168
public static final String JavaDoc PAIR_CHARACTERS_COMPLETION = "pairCharactersCompletion"; // NOI18N
169
public static final String JavaDoc SCROLL_FIND_INSETS_PROP = "scrollFindInsets"; // NOI18N
170
public static final String JavaDoc SCROLL_JUMP_INSETS_PROP = "scrollJumpInsets"; // NOI18N
171
public static final String JavaDoc SPACES_PER_TAB_PROP = "spacesPerTab"; // NOI18N
172
public static final String JavaDoc STATUS_BAR_CARET_DELAY_PROP = "statusBarCaretDelay"; // NOI18N
173
public static final String JavaDoc STATUS_BAR_VISIBLE_PROP = "statusBarVisible"; // NOI18N
174
public static final String JavaDoc TAB_SIZE_PROP = "tabSize"; // NOI18N
175
public static final String JavaDoc TEXT_LIMIT_LINE_COLOR_PROP = "textLimitLineColor"; // NOI18N
176
public static final String JavaDoc TEXT_LIMIT_LINE_VISIBLE_PROP = "textLimitLineVisible"; // NOI18N
177
public static final String JavaDoc TEXT_LIMIT_WIDTH_PROP = "textLimitWidth"; // NOI18N
178
public static final String JavaDoc TOOLBAR_VISIBLE_PROP = "toolbarVisible"; // NOI18N
179
public static final String JavaDoc TEXT_ANTIALIASING_PROP = "textAntialiasing"; // NOI18N
180
public static final String JavaDoc CODE_FOLDING_PROPS_PROP = "codeFoldingProps"; // NOI18N
181

182     protected static final String JavaDoc[] 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         //LINE_NUMBER_VISIBLE_PROP,
200
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 HELP_ID = "editing.global"; // !!! NOI18N
218
private static final String JavaDoc NO_INDENT_ENGINE = "NO_INDENT_ENGINE"; // NOI18N
219

220     private transient Settings.Initializer coloringMapInitializer;
221     
222     /** Version of the options. It's used for patching the options. */
223     private transient int optionsVersion;
224     
225     /* Indent engine available during readExternal() */
226     private transient IndentEngine readExternalIndentEngine;
227     private transient boolean inReadExternal;
228     
229     private transient MIMEOptionNode mimeNode;
230     private transient Map JavaDoc defaultAbbrevsMap;
231     private transient Map JavaDoc defaultMacrosMap;
232     private transient Map JavaDoc defaultKeyBindingsMap;
233     private transient MIMEOptionFolder settingsFolder;
234     private transient Boolean JavaDoc 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     /** Map of Kit to Options */
244     private static final HashMap JavaDoc kitClass2Options = new HashMap JavaDoc();
245     
246     /** Code template expand key setting name */
247     public static final String JavaDoc CODE_TEMPLATE_EXPAND_KEY = "code-template-expand-key"; // NOI18N
248

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 JavaDoc kitClass, String JavaDoc typeName) {
259         super(kitClass, typeName);
260         kitClass2Options.put(kitClass, this);
261 // new Throwable("BaseOptions: " + getClass() + "; kitClass=" + kitClass + "; typeName=" + typeName).printStackTrace();
262
}
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 JavaDoc 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 JavaDoc getContentType(){
284         BaseKit kit = BaseKit.getKit(getKitClass());
285         return kit.getContentType();
286     }
287     
288     /**
289      * Gets an instance of <code>BaseOptions</code> for an editir kit implementation
290      * class. Please see description of <code>BaseKit.getKit(Class)</code> for
291      * more details.
292      *
293      * @param kitClass The editor kit implementation class to get <code>BaseOptions</code> for.
294      *
295      * @return The <code>BaseOptions</code> or <code>null</code> if the options
296      * can't be found or loaded for some reason.
297      * @deprecated Use <code>MimeLookup</code> to find <code>BaseOptions</code>
298      * instances for a mime type.
299      * @see org.netbeans.editor.BaseKit#getKit(Class)
300      */

301     public static BaseOptions getOptions(Class JavaDoc kitClass) {
302         BaseOptions options = null;
303
304         if (kitClass != BaseKit.class && kitClass != NbEditorKit.class) {
305             String JavaDoc 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         // The old way of doing things
313
if (options == null) {
314             //check also all superclasses whether they are not in the
315
//kitClass2Options map
316
Class JavaDoc 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     /** Listening for Settings.settings creation.*/
336     
337     /** Lazy initialization of the MIME specific settings folder. The folder should be created
338      * via XML layers, if not, it will be created.
339      * Instances of all XML file in this folder will be created.
340      */

341     protected MIMEOptionFolder getMIMEFolder(){
342         /* #25541 - Instead of synchronized getMIMEFolder() the kit
343          * is first obtained and then the synchronization is done
344          * to avoid the deadlock caused by locking in opposite order.
345          */

346         String JavaDoc name = getContentType();
347         if (name == null) {
348             return null;
349         }
350
351         synchronized (Settings.class) {
352             // return already initialized folder
353
if (settingsFolder!=null) return settingsFolder;
354             
355             FileObject f = Repository.getDefault().getDefaultFileSystem().
356             findResource(AllOptionsFolder.FOLDER+"/"+name); //NOI18N
357

358             // MIME folder doesn't exist, let's create it
359
if (f==null){
360                 FileObject fo = Repository.getDefault().getDefaultFileSystem().
361                 findResource(AllOptionsFolder.FOLDER);
362                 
363                 if (fo != null){
364                     try{
365                         StringTokenizer JavaDoc stok = new StringTokenizer JavaDoc(name,"/"); // NOI18N
366
while (stok.hasMoreElements()) {
367                             String JavaDoc 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 JavaDoc ioe){
375                         ioe.printStackTrace();
376                     }
377                     
378                     f = Repository.getDefault().getDefaultFileSystem().
379                     findResource(AllOptionsFolder.FOLDER+"/"+name); // NOI18N
380
}
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     /** Gets MIMEOptionNode that belongs to this bean */
401     public MIMEOptionNode getMimeNode() {
402         synchronized (Settings.class) {
403             if (mimeNode == null) {
404                 createMIMENode(getTypeName());
405             }
406             return mimeNode;
407         }
408     }
409     
410     /** Creates Node in global options for appropriate MIME type */
411     private void createMIMENode(String JavaDoc typeName){
412         if (typeName.equals(BASE)){
413             return;
414         }
415         try{
416             mimeNode = new MIMEOptionNode(this);
417         }catch(IntrospectionException JavaDoc ie){
418             ie.printStackTrace();
419         }
420     }
421     
422     protected void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
423 // final String id = "kitClass=" + kitClass + "; getKitClass()=" + getKitClass() + "; this=" + this;
424
// System.out.println("### USM: " + id);
425

426         loadXMLSettings();
427
428         super.updateSettingsMap(kitClass, settingsMap);
429
430         if (kitClass == getKitClass()) {
431             // Create evaluators for indentEngine and formatter
432
settingsMap.put(NbEditorDocument.INDENT_ENGINE,
433                 new Settings.Evaluator() {
434                     public Object JavaDoc getValue(Class JavaDoc kitClass2, String JavaDoc settingName) {
435                         return getIndentEngine();
436                     }
437                 }
438             );
439
440             settingsMap.put(NbEditorDocument.FORMATTER,
441                 new Settings.Evaluator() {
442                     public Object JavaDoc getValue(Class JavaDoc kitClass2, String JavaDoc 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 JavaDoc getValue(Class JavaDoc kitClass2, String JavaDoc 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 JavaDoc computeTextAntialiasingMap( boolean aaSetting ) {
472         
473         Map JavaDoc result;
474         
475         Map JavaDoc defaultHints = (Map JavaDoc)(Toolkit.getDefaultToolkit().getDesktopProperty(
476                 "awt.font.desktophints")); //NOI18N
477

478         if ( defaultHints != null ) { // OK We're at 1.6 or higher
479
if (true) // On 1.6 always use the default rendering hints regardless of the aaSetting
480
return defaultHints;
481             
482             Object JavaDoc 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 JavaDoc();
488                 result.put( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
489             }
490             else {
491                 result = defaultHints;
492             }
493         }
494         else { // Lower than 1.6 Jdk
495
if ( !aaSetting ) {
496                 return Collections.EMPTY_MAP;
497             }
498             result = new HashMap JavaDoc();
499             result.put(RenderingHints.KEY_TEXT_ANTIALIASING,
500                        RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
501         }
502         
503         return result;
504     }
505     
506     private static Object JavaDoc gaspConst = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF;
507     
508     private boolean isGasp( Object JavaDoc systemSetting ) {
509         // RenderingHints.VALUE_TEXT_ANTIALIAS_GASP is available on JDK 1.6+ only
510
if ( gaspConst == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF ) {
511             try {
512                 Field JavaDoc aaConst = RenderingHints JavaDoc.class.getField( "VALUE_TEXT_ANTIALIAS_GASP" ); // NOI18N
513
gaspConst = aaConst.get( null );
514             }
515             catch ( NoSuchFieldException JavaDoc e ) {
516                 gaspConst = null;
517             }
518             catch ( IllegalAccessException JavaDoc e ) {
519                 gaspConst = null;
520             }
521         }
522         
523         return systemSetting == gaspConst;
524     }
525     
526     /* #54893
527     public HelpCtx getHelpCtx() {
528         return new HelpCtx(HELP_ID);
529     }
530      */

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"); // NOI18N
538
return;
539         }
540         setSettingInteger(SettingsNames.TAB_SIZE, tabSize, TAB_SIZE_PROP);
541     }
542     
543 /* public boolean getExpandTabs() {
544         return getSettingBoolean(SettingsNames.EXPAND_TABS);
545     }
546     [Mila] Moved to IndentEngine; Setter must stay here
547  */

548     
549     public void setExpandTabs(boolean expandTabs) {
550         setSettingBoolean(SettingsNames.EXPAND_TABS, expandTabs, EXPAND_TABS_PROP);
551     }
552     
553 /* public int getSpacesPerTab() {
554         return getSettingInteger(SettingsNames.SPACES_PER_TAB);
555     }
556     [Mila] Moved to IndentEngine; Setter must stay here
557  */

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     /** Gets Map of default Abbreviations as they are stored in
566      * MIMEFolder/Defaults/abbreviations.xml */

567     public Map JavaDoc getDefaultAbbrevMap(){
568         loadDefaultAbbreviations();
569         return defaultAbbrevsMap;
570     }
571     
572     /** Loads default abbreviations from MIMEFolder/Defaults/abbreviations.xml and
573      * stores them to defaultAbbrevsMap */

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 JavaDoc(file.getAllProperties());
587         }
588     }
589     
590     public Map JavaDoc getAbbrevMap() {
591         loadDefaultAbbreviations();
592         loadSettings(AbbrevsMIMEProcessor.class);
593         Map JavaDoc settingsMap = (Map JavaDoc)super.getSettingValue(SettingsNames.ABBREV_MAP);
594         if (settingsMap == null){
595             org.netbeans.editor.Utilities.annotateLoggable(new NullPointerException JavaDoc("settingsMap is null for kit:"+getKitClass())); //NOI18N
596
}
597         Map JavaDoc ret = (settingsMap == null) ? new HashMap JavaDoc() : new HashMap JavaDoc(settingsMap);
598         return ret;
599     }
600     
601     /** Sets new abbreviations map to initializer map and if saveToXML is true,
602      * then new settings will be saved to XML file. */

603     public void setAbbrevMap(Map JavaDoc map, boolean saveToXML) {
604         Map JavaDoc diffMap = null;
605         if (saveToXML){
606             // we are going to save the diff-ed changes to XML, all default
607
// properties have to be available
608
loadDefaultAbbreviations();
609             diffMap = OptionUtilities.getMapDiff(getAbbrevMap(),map,true);
610             if (diffMap.size()>0){
611                 // settings has changed, write changed settings to XML file
612
updateSettings(AbbrevsMIMEProcessor.class, diffMap);
613             }
614         }
615         super.setSettingValue(SettingsNames.ABBREV_MAP, map, ABBREV_MAP_PROP);
616     }
617     
618     /** Sets new abbreviations map and save the diff-ed changes to XML file*/
619     public void setAbbrevMap(Map JavaDoc map) {
620         setAbbrevMap(map, true);
621     }
622     
623     public String JavaDoc getCaretTypeInsertMode() {
624         return (String JavaDoc)getSettingValue(SettingsNames.CARET_TYPE_INSERT_MODE);
625     }
626     public void setCaretTypeInsertMode(String JavaDoc type) {
627         setSettingValue(SettingsNames.CARET_TYPE_INSERT_MODE, type,
628         CARET_TYPE_INSERT_MODE_PROP);
629     }
630     
631     public String JavaDoc getCaretTypeOverwriteMode() {
632         return (String JavaDoc)getSettingValue(SettingsNames.CARET_TYPE_OVERWRITE_MODE);
633     }
634     public void setCaretTypeOverwriteMode(String JavaDoc type) {
635         setSettingValue(SettingsNames.CARET_TYPE_OVERWRITE_MODE, type,
636         CARET_TYPE_OVERWRITE_MODE_PROP);
637     }
638
639     /**
640      *@deprecated since adaptation to new view implementation
641         the option is not supported
642      */

643     public boolean getCaretItalicInsertMode() {
644         return false;//getSettingBoolean(SettingsNames.CARET_ITALIC_INSERT_MODE);
645
}
646     /**
647      *@deprecated since adaptation to new view implementation
648         the option is not supported
649      */

650     public void setCaretItalicInsertMode(boolean b) {
651         setSettingBoolean(SettingsNames.CARET_ITALIC_INSERT_MODE, b,
652         CARET_ITALIC_INSERT_MODE_PROP);
653     }
654
655     /**
656      *@deprecated since adaptation to new view implementation
657         the option is not supported
658      */

659     public boolean getCaretItalicOverwriteMode() {
660         return false;//getSettingBoolean(SettingsNames.CARET_ITALIC_OVERWRITE_MODE);
661
}
662     /**
663      *@deprecated since adaptation to new view implementation
664         the option is not supported
665      */

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 JavaDoc getCaretColorInsertMode() {
672         loadSettings(FontsColorsMIMEProcessor.class);
673         return (Color JavaDoc)super.getSettingValue(SettingsNames.CARET_COLOR_INSERT_MODE);
674     }
675     
676     /** Sets new CaretColorInsertMode property to initializer map and save the
677      * changes to XML file */

678     public void setCaretColorInsertMode(Color JavaDoc color) {
679         setCaretColorInsertMode(color, true);
680     }
681     
682     /** Sets new CaretColorInsertMode property to initializer map and if saveToXML is true,
683      * then new settings will be saved to XML file (fontsColors.xml). */

684     public void setCaretColorInsertMode(Color JavaDoc color, boolean saveToXML) {
685         if (saveToXML){
686             if (!getCaretColorInsertMode().equals(color) && (color!=null)){
687                 // settings has changed, write changed settings to XML file
688
Map JavaDoc map = new HashMap JavaDoc();
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 JavaDoc getCaretColorOverwriteMode() {
702         loadSettings(FontsColorsMIMEProcessor.class);
703         return (Color JavaDoc)super.getSettingValue(SettingsNames.CARET_COLOR_OVERWRITE_MODE);
704     }
705     
706     /** Sets new CaretColorOverwriteMode property to initializer map and save the
707      * changes to XML file */

708     public void setCaretColorOverwriteMode(Color JavaDoc color) {
709         setCaretColorOverwriteMode(color, true);
710     }
711     
712     /** Sets new CaretColorOverwriteMode property to initializer map and if saveToXML is true,
713      * then new settings will be saved to XML file (fontsColors.xml). */

714     public void setCaretColorOverwriteMode(Color JavaDoc color, boolean saveToXML) {
715         if (saveToXML){
716             if (!getCaretColorOverwriteMode().equals(color) && (color!=null)){
717                 // settings has changed, write changed settings to XML file
718
Map JavaDoc map = new HashMap JavaDoc();
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"); // NOI18N
737
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 JavaDoc getScrollJumpInsets() {
752         return (Insets JavaDoc)getSettingValue(SettingsNames.SCROLL_JUMP_INSETS);
753     }
754     public void setScrollJumpInsets(Insets JavaDoc i) {
755         setSettingValue(SettingsNames.SCROLL_JUMP_INSETS, i,
756         SCROLL_JUMP_INSETS_PROP);
757     }
758     
759     public Insets JavaDoc getScrollFindInsets() {
760         return (Insets JavaDoc)getSettingValue(SettingsNames.SCROLL_FIND_INSETS);
761     }
762     public void setScrollFindInsets(Insets JavaDoc i) {
763         setSettingValue(SettingsNames.SCROLL_FIND_INSETS, i,
764         SCROLL_FIND_INSETS_PROP);
765     }
766     
767     /** Gets Map of default KeyBindings as they are stored in
768      * MIMEFolder/Defaults/keybindings.xml */

769     public Map JavaDoc getDefaultKeyBindingsMap(){
770         loadDefaultKeyBindings();
771         return defaultKeyBindingsMap;
772     }
773     
774     /** Loads default abbreviations from MIMEFolder/Defaults/keybindings.xml and
775      * stores them to defaultKeyBindingsMap */

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 JavaDoc(file.getAllProperties());
789         }
790         //#68762 - Basic keybinding broken for old editor kits
791
if (!usesNewOptionsDialog() && !BASE.equals(getTypeName())){
792                 super.setSettingValue(SettingsNames.KEY_BINDING_LIST,
793                         new ArrayList JavaDoc(defaultKeyBindingsMap.values()),
794                         KEY_BINDING_LIST_PROP);
795         }
796     }
797     
798     private List JavaDoc 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 JavaDoc kitClass = getKitClass();
810         Settings.KitAndValue[] kav = getSettingValueHierarchy(SettingsNames.KEY_BINDING_LIST);
811         List JavaDoc kbList = null;
812         for (int i = 0; i < kav.length; i++) {
813             if (kav[i].kitClass == kitClass) {
814                 kbList = (List JavaDoc)kav[i].value;
815             }
816         }
817         if (kbList == null) {
818             kbList = new ArrayList JavaDoc();
819         }
820         
821         // must convert all members to serializable MultiKeyBinding
822
int cnt = kbList.size();
823         for (int i = 0; i < cnt; i++) {
824             Object JavaDoc o = kbList.get(i);
825             if (!(o instanceof MultiKeyBinding) && o != null) {
826                 JTextComponent.KeyBinding JavaDoc b = (JTextComponent.KeyBinding JavaDoc)o;
827                 kbList.set(i, new MultiKeyBinding(b.key, b.actionName));
828             }
829         }
830         return new ArrayList JavaDoc( kbList );
831     }
832     
833     public List JavaDoc getKeyBindingList() {
834         List JavaDoc kb2 = new ArrayList JavaDoc( getKBList() );
835         kb2.add( 0, getKitClass().getName() ); //insert kit class name
836
return kb2;
837     }
838     
839     /** Sets new keybindings map and save the diff-ed changes to XML file*/
840     public void setKeyBindingList(List JavaDoc list) {
841         setKeyBindingList(list, true);
842     }
843     
844     
845     /** Saves keybindings settings to XML file.
846      * (This is used especially for record macro action.)*/

847     public void setKeyBindingsDiffMap(Map JavaDoc diffMap){
848         if ((diffMap != null) && (diffMap.size()>0)){
849             updateSettings(KeyBindingsMIMEProcessor.class, diffMap);
850         }
851     }
852     
853     
854     /** Sets new keybindings list to initializer map and if saveToXML is true,
855      * then new settings will be saved to XML file. */

856     public void setKeyBindingList(List JavaDoc list, boolean saveToXML) {
857         if( list.size() > 0 &&
858         ( list.get( 0 ) instanceof Class JavaDoc || list.get( 0 ) instanceof String JavaDoc )
859         ) {
860             list.remove( 0 ); //remove kit class name
861
}
862         
863         Map JavaDoc diffMap = null;
864         if (saveToXML){
865             // we are going to save the diff-ed changes to XML, all default
866
// properties have to be available
867
loadDefaultKeyBindings();
868             List JavaDoc kbMap = getKeyBindingList();
869             if( kbMap.size() > 0 &&
870             ( kbMap.get( 0 ) instanceof Class JavaDoc || kbMap.get( 0 ) instanceof String JavaDoc )
871             ) {
872                 kbMap.remove( 0 ); //remove kit class name
873
}
874             
875             diffMap = OptionUtilities.getMapDiff(OptionUtilities.makeKeyBindingsMap(kbMap),
876             OptionUtilities.makeKeyBindingsMap(list),true);
877             if (diffMap.size()>0){
878                 // settings has changed, write changed settings to XML file
879
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 JavaDoc newKeybs = new ArrayList JavaDoc();
892         List JavaDoc newOptionDialogKeybs = kbs.getKeyBindings();
893         // convert to editor's MultiKeyBinding
894
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 JavaDoc lst = mkb.getKeyStrokeList();
898             KeyStroke JavaDoc keys[] = new KeyStroke JavaDoc[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 JavaDoc m = getColoringMap_old();
908         m.remove(null);
909         FontColorSettings fcs = getFontColorSettings();
910         if (fcs == null){
911             return;
912         }
913         
914         for(Iterator JavaDoc it = m.keySet().iterator(); it.hasNext(); ) {
915             String JavaDoc category = (String JavaDoc) it.next ();
916         if (category == null) continue;
917             
918             AttributeSet JavaDoc 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); //NOI18N
924
continue;
925         }
926             
927             m.put(category, Coloring.fromAttributeSet(as));
928         }
929         m.put(null, getKitClass().getName() ); // add kit class
930
setColoringMap (m);
931
932         // set other colorings like text limit line, caret
933
AttributeSet JavaDoc set = (AttributeSet JavaDoc) fcs.getFontColors(SettingsNames.CARET_COLOR_INSERT_MODE);
934         if (set != null){
935             Color JavaDoc color = (Color JavaDoc)set.getAttribute(StyleConstants.Foreground);
936             Color JavaDoc current = getCaretColorInsertMode();
937             if (color!=null && !color.equals(current)){
938                 setCaretColorInsertMode(color);
939                 setCaretColorOverwriteMode(color);
940             }
941         }
942
943         set = (AttributeSet JavaDoc) fcs.getFontColors(SettingsNames.TEXT_LIMIT_LINE_COLOR);
944         if (set != null){
945             Color JavaDoc color = (Color JavaDoc)set.getAttribute(StyleConstants.Foreground);
946             Color JavaDoc 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 JavaDoc mime = getContentType();
957                 Lookup lookup = MimeLookup.getLookup(MimePath.parse(mime));
958                 resultKB = lookup.lookup(new Lookup.Template(KeyBindingSettings.class));
959                 Collection JavaDoc inst = resultKB.allInstances();
960                 lookupListenerKB = new LookupListener(){
961                     public void resultChanged(LookupEvent ev){
962                         Lookup.Result result = ((Lookup.Result)ev.getSource());
963                         // refresh keyBindingsSettings
964
Collection JavaDoc 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 JavaDoc mime = getContentType();
989                 Lookup lookup = MimeLookup.getLookup(MimePath.parse(mime));
990                 Lookup.Result result = lookup.lookup(new Lookup.Template(FontColorSettings.class));
991                 Collection JavaDoc inst = result.allInstances();
992                 lookupListener = new LookupListener(){
993                     public void resultChanged(LookupEvent ev){
994                         Lookup.Result result = ((Lookup.Result)ev.getSource());
995                         // refresh fontColorSettings
996
Collection JavaDoc 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 JavaDoc 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 JavaDoc getColoringMap_old() {
1027        Map JavaDoc settingsMap = SettingsUtil.getColoringMap(getKitClass(), false, true); // !!! !evaluateEvaluators
1028
if (settingsMap == null){
1029            org.netbeans.editor.Utilities.annotateLoggable(new NullPointerException JavaDoc("settingsMap is null for kit:"+getKitClass())); //NOI18N
1030
}
1031        Map JavaDoc cm = (settingsMap == null) ? new HashMap JavaDoc() : new HashMap JavaDoc(settingsMap);
1032        cm.put(null, getKitClass().getName() ); // add kit class
1033
return cm;
1034    }
1035    
1036    /** Sets new coloring map and save the diff-ed changes to XML file*/
1037    public void setColoringMap(Map JavaDoc coloringMap) {
1038        setColoringMap(coloringMap, true);
1039    }
1040    
1041    /** Sets new coloring map to initializer map and if saveToXML is true,
1042     * then new settings will be saved to XML file. */

1043    public void setColoringMap(final Map JavaDoc coloringMap, boolean saveToXML){
1044        Map JavaDoc diffMap = null;
1045        if (coloringMap != null) {
1046// if (inReadExternal) {
1047
/* Fix of #11115
1048                 * The better place would be in upgradeOptions()
1049                 * which was attempted originally. However the normal
1050                 * behavior of setColoringMap() destroys the colorings
1051                 * if they are not upgraded immediately. Therefore
1052                 * the readExternalColoringMap approach was attempted.
1053                 * However there was an NPE in
1054                 * properties.syntax.EditorSettingsCopy.updateColors
1055                 * at line 235 the keyColoring was null.
1056                 * Therefore the patch appears here.
1057                 */

1058                //coloringMap = UpgradeOptions.patchColorings(getKitClass(), coloringMap);
1059
// }
1060

1061            if (!usesNewOptionsDialog() && saveToXML){
1062                diffMap = OptionUtilities.getMapDiff(getColoringMap(),coloringMap,false);
1063                if (diffMap.size()>0){
1064                    // settings has changed, write changed settings to XML file
1065
//System.out.println("SETTING COLORING MAP:"+diffMap);
1066
updateSettings(FontsColorsMIMEProcessor.class, diffMap);
1067                }
1068            }
1069            
1070            coloringMap.remove(null); // remove kit class
1071

1072            Settings.update(new Runnable JavaDoc() {
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" //NOI18N
1081
);
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"); // NOI18N
1095
return;
1096        }
1097        final int oldSize = getFontSize();
1098        Map JavaDoc cm = SettingsUtil.getColoringMap(getKitClass(), false, true); // !!! !evaluateEvaluators
1099
if (cm != null) {
1100            Iterator JavaDoc it = cm.entrySet().iterator();
1101            while (it.hasNext()) {
1102                Map.Entry JavaDoc entry = (Map.Entry JavaDoc)it.next();
1103                Object JavaDoc value = entry.getValue();
1104                if (value instanceof Coloring) {
1105                    Coloring c = (Coloring)value;
1106                    Font JavaDoc 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()); // this way due to bug in Coloring
1111
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 JavaDoc) getSettingValue(SettingsNames.LINE_HEIGHT_CORRECTION)).floatValue();
1123    }
1124    public void setLineHeightCorrection(float f) {
1125        if (f <= 0) {
1126            NbEditorUtilities.invalidArgument("MSG_OutOfRange"); // NOI18N
1127
return;
1128        }
1129        setSettingValue(SettingsNames.LINE_HEIGHT_CORRECTION, new Float JavaDoc(f),
1130        LINE_HEIGHT_CORRECTION_PROP);
1131    }
1132    
1133    /** Gets Map of default Macros as they are stored in
1134     * MIMEFolder/Defaults/macros.xml */

1135    public Map JavaDoc getDefaultMacrosMap(){
1136        loadDefaultMacros();
1137        return defaultMacrosMap;
1138    }
1139    
1140    /** Loads default abbreviations from MIMEFolder/Defaults/macros.xml and
1141     * stores them to defaultMacrosMap */

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 JavaDoc(file.getAllProperties());
1154        }
1155    }
1156
1157    /** removes keybindings from deleted macros, or if macro deletion was cancelled
1158     * it restores old keybinding value */

1159    private void processMacroKeyBindings(Map JavaDoc diff, List JavaDoc oldKB){
1160        List JavaDoc deletedKB = new ArrayList JavaDoc();
1161        List JavaDoc addedKB = new ArrayList JavaDoc();
1162        List JavaDoc newKB = getKBList();
1163
1164        for( Iterator JavaDoc i = diff.keySet().iterator(); i.hasNext(); ) {
1165            String JavaDoc key = (String JavaDoc)i.next();
1166            if (!(diff.get(key) instanceof String JavaDoc)) continue;
1167            String JavaDoc action = (String JavaDoc) diff.get(key);
1168            String JavaDoc kbActionName = BaseKit.macroActionPrefix+key;
1169
1170            if (action.length()!=0){
1171                // process restored macros
1172
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                // process deleted macros
1185
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            // save changed keybindings to XML file
1198
setKeyBindingsDiffMap(OptionUtilities.getMapDiff(OptionUtilities.makeKeyBindingsMap(getKBList()),
1199                OptionUtilities.makeKeyBindingsMap(newKB), true));
1200            // set new keybindings
1201
Settings.setValue( getKitClass(), SettingsNames.KEY_BINDING_LIST, newKB);
1202        }
1203    }
1204    
1205    /** Gets Macro Map */
1206    public Map JavaDoc getMacroMap() {
1207        loadDefaultMacros();
1208        loadSettings(MacrosMIMEProcessor.class);
1209        Map JavaDoc settingsMap = (Map JavaDoc)super.getSettingValue(SettingsNames.MACRO_MAP);
1210        if (settingsMap == null){
1211            org.netbeans.editor.Utilities.annotateLoggable(new NullPointerException JavaDoc("settingsMap is null for kit:"+getKitClass())); //NOI18N
1212
}
1213        Map JavaDoc ret = (settingsMap == null) ? new HashMap JavaDoc() : new HashMap JavaDoc(settingsMap);
1214        ret.put(null, getKBList());
1215        return ret;
1216    }
1217    
1218    /** Saves macro settings to XML file.
1219     * (This is used especially for record macro action.)*/

1220    public void setMacroDiffMap(Map JavaDoc diffMap){
1221        if ((diffMap != null) && (diffMap.size()>0)){
1222            updateSettings(MacrosMIMEProcessor.class, diffMap);
1223        }
1224    }
1225    
1226    /** Sets new macro map to initializer map and if saveToXML is true,
1227     * then new settings will be saved to XML file. */

1228    public void setMacroMap(Map JavaDoc map, boolean saveToXML) {
1229        Map JavaDoc diffMap = null;
1230        List JavaDoc kb = new ArrayList JavaDoc();
1231        if (map.containsKey(null)){
1232            kb.addAll((List JavaDoc)map.get(null));
1233            map.remove(null);
1234        }
1235        if (saveToXML){
1236            // we are going to save the diff-ed changes to XML, all default
1237
// properties have to be available
1238
loadDefaultMacros();
1239            diffMap = OptionUtilities.getMapDiff(getMacroMap(),map,true);
1240            if (diffMap.containsKey(null)) diffMap.remove(null);
1241            if (diffMap.size()>0){
1242                // settings has changed, write changed settings to XML file
1243
processMacroKeyBindings(diffMap,kb);
1244                updateSettings(MacrosMIMEProcessor.class, diffMap);
1245            }
1246        }
1247        
1248        super.setSettingValue(SettingsNames.MACRO_MAP, map);
1249    }
1250    
1251    /** Sets new macros map and save the diff-ed changes to XML file*/
1252    public void setMacroMap(Map JavaDoc map) {
1253        setMacroMap(map, true);
1254    }
1255    
1256    public Insets JavaDoc getMargin() {
1257        return (Insets JavaDoc)getSettingValue(SettingsNames.MARGIN);
1258    }
1259    public void setMargin(Insets JavaDoc 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"); // NOI18N
1276
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"); // NOI18N
1314
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 JavaDoc getFindHistory() {
1338        return new HashMap JavaDoc( (Map JavaDoc)getSettingValue(SettingsNames.FIND_HISTORY) );
1339    }
1340    
1341    public void setFindHistory(Map JavaDoc 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 JavaDoc getTextLimitLineColor() {
1365        loadSettings(FontsColorsMIMEProcessor.class);
1366        return (Color JavaDoc)super.getSettingValue(SettingsNames.TEXT_LIMIT_LINE_COLOR);
1367    }
1368    
1369    /** Sets new TextLimitLineColor property to initializer map and save the
1370     * changes to XML file */

1371    public void setTextLimitLineColor(Color JavaDoc color) {
1372        setTextLimitLineColor(color, true);
1373    }
1374    
1375    /** Sets new TextLimitLineColor property to initializer map and if saveToXML is true,
1376     * then new settings will be saved to XML file (fontsColors.xml). */

1377    public void setTextLimitLineColor(Color JavaDoc color , boolean saveToXML) {
1378        if (saveToXML){
1379            if (!getTextLimitLineColor().equals(color) && (color!=null)){
1380                // settings has changed, write changed settings to XML file
1381
Map JavaDoc map = new HashMap JavaDoc();
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"); // NOI18N
1401
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        // artificial setting -> evaluator used (at begining of this class)
1444
Boolean JavaDoc val = (Boolean JavaDoc)getSettingValue(TEXT_ANTIALIASING_PROP);
1445        if (val != null) {
1446            return val.booleanValue();
1447        } else {
1448            //XXX this prop is not used anymore, but anyway, I believe
1449
//it should have been swing.aatext - I've never seen
1450
//javax.aatext. -Tim
1451
// #56234: Check -Djavax.aatext=true
1452
if (Boolean.getBoolean("javax.aatext")) {
1453                return true;
1454
1455            } else {
1456                // fix of #31758
1457
if (Utilities.isMac()) {
1458                    // On OSX, default to true
1459
return true;
1460                } else {
1461                    return isSystemAntialias();
1462                }
1463            }
1464        }
1465    }
1466    
1467    private static boolean isSystemAntialias() {
1468        Map JavaDoc systemHints = (Map JavaDoc)(Toolkit.getDefaultToolkit().getDesktopProperty(
1469                "awt.font.desktophints")); //NOI18N
1470
if (systemHints != null) {
1471            Object JavaDoc 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        // Cause refresh or renderingHints variable in EditorUI
1484
Settings.touchValue(getKitClass(), SettingsNames.RENDERING_HINTS);
1485    }
1486    
1487    public Map JavaDoc getCodeFoldingProps(){
1488        Map JavaDoc map = new HashMap JavaDoc();
1489        
1490        Boolean JavaDoc val = (Boolean JavaDoc)getSettingValue(SettingsNames.CODE_FOLDING_ENABLE);
1491        map.put(SettingsNames.CODE_FOLDING_ENABLE, val);
1492        
1493        return map;
1494    }
1495    
1496    public void setCodeFoldingProps(Map JavaDoc props){
1497        String JavaDoc name = SettingsNames.CODE_FOLDING_ENABLE;
1498        setSettingValue(name, props.get(name));
1499    }
1500        
1501    /** Retrieves the actions from XML file */
1502    public void initPopupMenuItems(){
1503        List JavaDoc orderedPopupFiles = getOrderedMultiPropertyFolderFiles("Popup"); //NOI18N
1504
//if (orderedPopupFiles.size() >0){
1505
// super.setSettingValue(ExtSettingsNames.POPUP_MENU_ACTION_NAME_LIST,
1506
// OptionUtilities.getPopupStrings(orderedPopupFiles)); //NOI18N
1507
//}
1508
}
1509    
1510    public List JavaDoc getOrderedMultiPropertyFolderFiles(String JavaDoc folderName){
1511        if (!BASE.equals(getTypeName())){
1512            MIMEOptionFolder mimeFolder = getMIMEFolder();
1513            if (mimeFolder != null){
1514                MultiPropertyFolder mpf = mimeFolder.getMPFolder(folderName,false); //NOI18N
1515
if (mpf!=null){
1516                    DataFolder df = mpf.getDataFolder();
1517                    List JavaDoc mimeFolderAttribs = new ArrayList JavaDoc();
1518                    for (Enumeration JavaDoc e = df.getPrimaryFile().getAttributes() ; e.hasMoreElements() ;) {
1519                        mimeFolderAttribs.add(e.nextElement());
1520                    }
1521
1522                    // merge folders only if mime folder has some relevant info
1523
if ( (mpf.getProperties().size()!=0) || (mimeFolderAttribs.size() != 0)) {
1524                        
1525                        // We are going to merge global items and mime popup items ...
1526
// Firstly merge popup items
1527
Set JavaDoc mergedItems = new HashSet JavaDoc(OptionUtilities.getGlobalMenuItems(folderName));
1528
1529                        mergedItems.addAll(mpf.getProperties());
1530                        
1531                        // Then merge attribs
1532
Set JavaDoc mergedAttribs = new HashSet JavaDoc(OptionUtilities.getGlobalAttribs(folderName));
1533                        mergedAttribs.addAll(mimeFolderAttribs);
1534                        
1535                        // Sort it in accordance with merged Attribs
1536
return OptionUtilities.arrangeMergedFolderObjects(mergedItems, mergedAttribs);
1537                    }
1538                }
1539            }
1540        }
1541
1542        return OptionUtilities.getGlobalMenuItems(folderName);
1543    }
1544    
1545    public IndentEngine getIndentEngine() {
1546        // Due to #11212
1547
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 JavaDoc setMap = file.getAllProperties();
1560                    Object JavaDoc handle = setMap.get(INDENT_ENGINE_PROP);
1561                    if (handle instanceof String JavaDoc){
1562                        Object JavaDoc instance = null;
1563                        String JavaDoc handleString = (String JavaDoc) 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        // [BACKWARD-COMPATIBILITY-START]
1585
/* Either handle or real indent-egine is attempted
1586         * to be obtained from property.
1587         */

1588        Object JavaDoc 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        // [BACKWARD-COMPATIBILITY-END]
1601

1602        
1603        // Try to find the default indent engine in Services registry
1604
IndentEngine eng = findDefaultIndentEngine();
1605        if (eng != null) { // found
1606
setIndentEngine(eng);
1607        }
1608        
1609        return eng;
1610    }
1611    
1612    public void setIndentEngine(IndentEngine eng) {
1613        /* Disabled direct setting of the engine
1614         * during project deserialization to avoid doubled
1615         * indent engine as described in #9687
1616         */

1617        if (!inReadExternal) {
1618            String JavaDoc 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 JavaDoc map = new HashMap JavaDoc();
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        // Touches the settings
1639
RequestProcessor.postRequest(new Runnable JavaDoc(){
1640            public void run(){
1641                Settings.touchValue(getKitClass(), NbEditorDocument.INDENT_ENGINE);
1642                Settings.touchValue(getKitClass(), NbEditorDocument.FORMATTER);
1643            }
1644        });
1645    }
1646    
1647    /** Return class of the default indentation engine. */
1648    protected Class JavaDoc 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 JavaDoc(oldOptionsVersion), new Integer JavaDoc(optionsVersion));
1667        }
1668
1669    }
1670    
1671    public int getOptionsVersion() {
1672        return optionsVersion;
1673    }
1674    
1675    public void readExternal(ObjectInput JavaDoc in)
1676    throws IOException JavaDoc, ClassNotFoundException JavaDoc {
1677        
1678        /** Hold the current indent engine due to #11212 */
1679        readExternalIndentEngine = getIndentEngine();
1680        inReadExternal = true;
1681        
1682        /* Make the current options version to be zero
1683         * temporarily to distinguish whether the options
1684         * imported were old and the setOptionsVersion()
1685         * was not called or whether the options
1686         * were new so the options version was set
1687         * to the LATEST_OPTIONS_VERSION value.
1688         */

1689        optionsVersion = 0;
1690        
1691        try {
1692            // Read the serialized options
1693
super.readExternal(in);
1694        }catch(java.io.OptionalDataException JavaDoc ode){
1695            // #17385. It occurs during reading Settings.settings, that is unimportant
1696
} finally {
1697
1698            // Make sure the indent engine settings are propagated
1699
// (SharedClassObject.putProperty() is final)
1700
refreshIndentEngineSettings();
1701
1702            // Possibly upgrade the options
1703
//if (optionsVersion < LATEST_OPTIONS_VERSION) {
1704
// upgradeOptions(optionsVersion, LATEST_OPTIONS_VERSION);
1705
//}
1706

1707            optionsVersion = LATEST_OPTIONS_VERSION;
1708
1709            /** Release temp indent engine - #11212 */
1710            inReadExternal = false;
1711            readExternalIndentEngine = null;
1712        }
1713    }
1714    
1715    /** Upgrade the deserialized options.
1716     * @param version deserialized version of the options
1717     * @param latestVersion latest version of the options
1718     * that will be set to them after they are upgraded
1719     */

1720    protected void upgradeOptions(int version, int latestVersion) {
1721        // Upgrade in separate class to avoid messing up BaseOptions
1722
//UpgradeOptions.upgradeOptions(this, version, latestVersion);
1723
}
1724    
1725    /** Load settings from XML files and initialize changes */
1726    private void loadSettings(Class JavaDoc 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    /** Save changes to XML files.
1743     * @see #updateSettings(java.lang.Class, java.util.Map, boolean )
1744     */

1745    private void updateSettings(Class JavaDoc processor, Map JavaDoc settings){
1746        updateSettings(processor, settings, true);
1747    }
1748    
1749    /** Save changes to XML files
1750     * @param processor MIMEProcessor class
1751     * @param settings the settings map
1752     * @param useRequestProcessorForSaving if true settings will be saved in RequestProcessor thread.
1753     */

1754    private void updateSettings(Class JavaDoc processor, Map JavaDoc 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 JavaDoc finalSettings = settings;
1773        final MIMEOptionFile file = fileX;
1774        if (file!=null){
1775            if (useRequestProcessorForSaving){
1776                RequestProcessor.postRequest(new Runnable JavaDoc(){
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()); //NOI18N
1787
}
1788    }
1789    
1790    public void setSettingValue(String JavaDoc settingName, Object JavaDoc newValue) {
1791        setSettingValue(settingName, newValue, settingName);
1792    }
1793    
1794    private boolean isTheSame(String JavaDoc settingName, Object JavaDoc newValue){
1795        if (settingName == null ||
1796        settingName.equals(NbEditorDocument.INDENT_ENGINE) ||
1797        settingName.equals(NbEditorDocument.FORMATTER) ){
1798            return true;
1799        }
1800        Object JavaDoc oldValue = getSettingValue(settingName);
1801        if ((oldValue == null && newValue == null)
1802        || (oldValue != null && oldValue.equals(newValue))
1803        ) {
1804            return true; // the same object
1805
}
1806        return false;
1807    }
1808    
1809    /** Sets setting value to initializer Map and save the changes to XML file
1810     * (properties.xml) */

1811    public void setSettingValue(String JavaDoc settingName, Object JavaDoc newValue,
1812    String JavaDoc propertyName) {
1813        if (!isTheSame(settingName, newValue)){
1814            Map JavaDoc map = new HashMap JavaDoc();
1815            map.put(settingName, newValue);
1816            updateSettings(PropertiesMIMEProcessor.class, map);
1817        }
1818        super.setSettingValue(settingName,newValue,propertyName);
1819    }
1820    
1821    public Object JavaDoc getSettingValue(String JavaDoc settingName) {
1822        loadSettings(PropertiesMIMEProcessor.class);
1823        return super.getSettingValue(settingName);
1824    }
1825    
1826    protected final void setSettingBoolean(String JavaDoc settingName, boolean newValue, String JavaDoc propertyName) {
1827        setSettingValue(settingName, newValue ? Boolean.TRUE : Boolean.FALSE);
1828    }
1829    
1830    protected final void setSettingInteger(String JavaDoc settingName, int newValue, String JavaDoc propertyName) {
1831        setSettingValue(settingName, new Integer JavaDoc(newValue));
1832    }
1833    
1834    /** Load all available settings from XML files and initialize them */
1835    protected void loadXMLSettings() {
1836        if (!loaded) {
1837            loaded = true;
1838            if (LOG.isLoggable(Level.FINE)) {
1839                LOG.fine("Loading " + getClass() + "; mimeType='" + getContentType() + "'"); //NOI18N
1840
}
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() + "'"); //NOI18N
1850
}
1851        } else {
1852            if (LOG.isLoggable(Level.FINE)) {
1853                LOG.fine("Already loaded! " + getClass() + "; mimeType='" + getContentType() + "'"); //NOI18N
1854
}
1855        }
1856    }
1857
1858    /** Overriden writeExternal method. BaseOptions are no longer serialized. */
1859    public void writeExternal() throws IOException JavaDoc{
1860    }
1861    
1862    /** Overriden writeExternal method. BaseOptions are no longer serialized. */
1863    public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc{
1864    }
1865
1866    protected void firePropertyChange(String JavaDoc name, Object JavaDoc oldValue, Object JavaDoc newValue){
1867        // ignore firing... Quick fix of #47261.
1868
// BaseOptions should be rewritten to not extend SystemOption ...
1869
// there is no need to be compatile with NB 3.2 and deserialize its options...
1870
}
1871
1872    /** Saves the keystroke of code tamplate expansion into properties.xml file under Editors/text/base */
1873    public static void setCodeTemplateExpandKey(KeyStroke JavaDoc ks){
1874        String JavaDoc s = OptionUtilities.keyToString(ks);
1875        BaseOptions base = getOptions(BaseKit.class);
1876        Map JavaDoc map = new HashMap JavaDoc();
1877        map.put(CODE_TEMPLATE_EXPAND_KEY, s);
1878        base.updateSettings(PropertiesMIMEProcessor.class, map);
1879    }
1880    
1881    /** Gets Code Template Expand Key. Can return null if there is no key in the settings file */
1882    public static KeyStroke JavaDoc 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 JavaDoc properties = file.getAllProperties();
1891                String JavaDoc s = (String JavaDoc) 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