KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > NbEditorSettingsInitializer


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;
21
22 import java.awt.event.InputEvent JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import org.netbeans.api.editor.mimelookup.MimeLookup;
29 import org.netbeans.api.editor.mimelookup.MimePath;
30 import org.netbeans.editor.BaseSettingsInitializer;
31 import org.netbeans.editor.Settings;
32 import org.netbeans.editor.SettingsDefaults;
33 import org.netbeans.editor.ext.ExtSettingsNames;
34 import org.netbeans.editor.ext.ExtSettingsInitializer;
35 import org.netbeans.modules.editor.options.OptionUtilities;
36 import org.netbeans.modules.editor.options.AllOptionsFolder;
37 import org.netbeans.editor.BaseKit;
38 import org.netbeans.editor.SettingsNames;
39 import org.netbeans.modules.editor.impl.KitsTracker;
40 import org.netbeans.modules.editor.options.BaseOptions;
41 import org.netbeans.modules.editor.options.BasePrintOptions;
42 import org.openide.util.Utilities;
43
44 /**
45 * Customized settings for NetBeans editor
46 *
47 * @author Miloslav Metelka
48 * @version 1.00
49 */

50
51 public class NbEditorSettingsInitializer extends Settings.AbstractInitializer {
52
53     private static final Logger JavaDoc LOG = Logger.getLogger(NbEditorSettingsInitializer.class.getName());
54     
55     public static final String JavaDoc NAME = "nb-editor-settings-initializer"; // NOI18N
56

57     private static boolean mainInitDone;
58
59     public static void init() {
60         if (!mainInitDone) {
61             mainInitDone = true;
62             Settings.addInitializer(new BaseSettingsInitializer(), Settings.CORE_LEVEL);
63             Settings.addInitializer(new ExtSettingsInitializer(), Settings.CORE_LEVEL);
64             Settings.addInitializer(new NbEditorSettingsInitializer());
65
66             Settings.reset();
67             
68             // Start listening on addition/removal of print options
69
BasePrintOptions bpo = (BasePrintOptions) BasePrintOptions.findObject(BasePrintOptions.class, true);
70             bpo.init();
71         }
72     }
73
74     public NbEditorSettingsInitializer() {
75         super(NAME);
76     }
77
78     /** Update map filled with the settings.
79     * @param kitClass kit class for which the settings are being updated.
80     * It is always non-null value.
81     * @param settingsMap map holding [setting-name, setting-value] pairs.
82     * The map can be empty if this is the first initializer
83     * that updates it or if no previous initializers updated it.
84     */

85     public void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
86
87         if (kitClass == BaseKit.class) {
88             settingsMap.put(BaseOptions.TOOLBAR_VISIBLE_PROP, Boolean.TRUE);
89             settingsMap.put(BaseOptions.LINE_NUMBER_VISIBLE_PROP, SettingsDefaults.defaultLineNumberVisible);
90             
91         //Fix for IZ bug #53744:
92
//On MAC OS X, Ctrl+left click has the same meaning as the right-click.
93
//The hyperlinking should be enabled for the Command key on MAC OS X, for Ctrl on others:
94
int activationMask;
95             
96             activationMask = Utilities.isMac()? InputEvent.META_MASK: InputEvent.CTRL_DOWN_MASK;
97             settingsMap.put(SettingsNames.HYPERLINK_ACTIVATION_MODIFIERS, Integer.valueOf(activationMask));
98         }
99
100         if (kitClass == NbEditorKit.class) {
101             // init popup menu items from layer folder
102
if (AllOptionsFolder.getDefault().baseInitialized()){
103                 // put to the settings map only if base options has been initialized. See #19470
104
settingsMap.put(ExtSettingsNames.POPUP_MENU_ACTION_NAME_LIST,
105                     OptionUtilities.getPopupStrings(OptionUtilities.getGlobalPopupMenuItems())
106                 );
107             }
108         }
109
110         List JavaDoc mimeTypes = KitsTracker.getInstance().getMimeTypesForKitClass(kitClass);
111         for(Iterator JavaDoc i = mimeTypes.iterator(); i.hasNext(); ) {
112             String JavaDoc mimeType = (String JavaDoc) i.next();
113             
114             if (LOG.isLoggable(Level.FINE)) {
115                 LOG.fine("Initializing settings for '" + mimeType + "', " + kitClass);
116             }
117             
118             // Lookup BaseOptions for the given mime type so that it can hook up its
119
// own settings initializer.
120
MimePath mimePath = MimePath.parse(mimeType);
121             BaseOptions bo = (BaseOptions) MimeLookup.getLookup(mimePath).lookup(BaseOptions.class);
122             if (bo == null) {
123                 if (LOG.isLoggable(Level.FINE)) {
124                     LOG.fine("Top level mime type '" + mimeType + "' with no BaseOptions."); //NOI18N
125
}
126             }
127         }
128     }
129 }
130
Popular Tags