KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > java > NbJavaSettingsInitializer


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.java;
21
22 import java.awt.Toolkit JavaDoc;
23 import java.awt.event.KeyEvent JavaDoc;
24 import java.awt.event.InputEvent JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import javax.swing.KeyStroke JavaDoc;
30 import org.netbeans.editor.BaseKit;
31 import org.netbeans.editor.MultiKeyBinding;
32 import org.netbeans.editor.Settings;
33 import org.netbeans.editor.SettingsUtil;
34 import org.netbeans.editor.SettingsNames;
35 import org.netbeans.editor.ext.ExtSettingsNames;
36 import org.openide.actions.SaveAction;
37 import org.openide.actions.CutAction;
38 import org.openide.actions.CopyAction;
39 import org.openide.actions.PasteAction;
40 import org.openide.actions.DeleteAction;
41 import org.openide.actions.NewAction;
42 import org.openide.actions.ToolsAction;
43 import org.openide.actions.PropertiesAction;
44 import org.openide.windows.TopComponent;
45 import org.netbeans.editor.ext.ExtSettingsDefaults;
46 import org.netbeans.editor.ext.java.JavaSettingsDefaults;
47 import org.netbeans.editor.ext.java.JavaSettingsNames;
48
49 /**
50 * Nb settings for Java.
51 *
52 * @author Miloslav Metelka
53 * @version 1.00
54 */

55
56 public class NbJavaSettingsInitializer extends Settings.AbstractInitializer {
57
58     public static final String JavaDoc NAME = "nb-java-settings-initializer"; // NOI18N
59

60     public NbJavaSettingsInitializer() {
61         super(NAME);
62     }
63
64     private static final int ALT_MASK = System.getProperty("mrj.version") != null ?
65         InputEvent.CTRL_MASK : InputEvent.ALT_MASK;
66
67     /** Update map filled with the settings.
68     * @param kitClass kit class for which the settings are being updated.
69     * It is always non-null value.
70     * @param settingsMap map holding [setting-name, setting-value] pairs.
71     * The map can be empty if this is the first initializer
72     * that updates it or if no previous initializers updated it.
73     */

74     public void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
75
76         if (kitClass == JavaKit.class) {
77
78             SettingsUtil.updateListSetting(settingsMap, SettingsNames.KEY_BINDING_LIST, getJavaKeyBindings());
79
80             SettingsUtil.updateListSetting(settingsMap, SettingsNames.KEY_BINDING_LIST,
81                                            new MultiKeyBinding[] {
82                                                new MultiKeyBinding(
83                                                    KeyStroke.getKeyStroke(KeyEvent.VK_O, ALT_MASK),
84                                                    JavaKit.gotoSourceAction
85                                                ),
86                                                new MultiKeyBinding(
87                                                    KeyStroke.getKeyStroke(KeyEvent.VK_F1, ALT_MASK),
88                                                    JavaKit.gotoHelpAction
89                                                ),
90                                            }
91                                           );
92
93 // settingsMap.put(ExtSettingsNames.UPDATE_PD_AFTER_MOUNTING,
94
// ExtSettingsDefaults.defaultUpdatePDAfterMounting);
95

96             settingsMap.put(ExtSettingsNames.SHOW_DEPRECATED_MEMBERS,
97                             ExtSettingsDefaults.defaultShowDeprecatedMembers);
98             
99             settingsMap.put(SettingsNames.CODE_FOLDING_ENABLE, JavaSettingsDefaults.defaultCodeFoldingEnable);
100             settingsMap.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_METHOD, JavaSettingsDefaults.defaultCodeFoldingCollapseMethod);
101             settingsMap.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INNERCLASS, JavaSettingsDefaults.defaultCodeFoldingCollapseInnerClass);
102             settingsMap.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_IMPORT, JavaSettingsDefaults.defaultCodeFoldingCollapseImport);
103             settingsMap.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_JAVADOC, JavaSettingsDefaults.defaultCodeFoldingCollapseJavadoc);
104             settingsMap.put(JavaSettingsNames.CODE_FOLDING_COLLAPSE_INITIAL_COMMENT, JavaSettingsDefaults.defaultCodeFoldingCollapseInitialComment);
105             
106         }
107
108     }
109
110     public MultiKeyBinding[] getJavaKeyBindings() {
111         int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
112         boolean isMac = System.getProperty("mrj.version") != null;
113         return new MultiKeyBinding[] {
114                    new MultiKeyBinding(
115                        new KeyStroke JavaDoc[] {
116                            KeyStroke.getKeyStroke(KeyEvent.VK_U, ALT_MASK),
117                            KeyStroke.getKeyStroke(KeyEvent.VK_G, 0)
118                        },
119                        JavaKit.makeGetterAction
120                    ),
121                    new MultiKeyBinding(
122                        new KeyStroke JavaDoc[] {
123                            KeyStroke.getKeyStroke(KeyEvent.VK_U, ALT_MASK),
124                            KeyStroke.getKeyStroke(KeyEvent.VK_S, 0)
125                        },
126                        JavaKit.makeSetterAction
127                    ),
128                    new MultiKeyBinding(
129                        new KeyStroke JavaDoc[] {
130                            KeyStroke.getKeyStroke(KeyEvent.VK_U, ALT_MASK),
131                            KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)
132                        },
133                        JavaKit.makeIsAction
134                    ),
135                    new MultiKeyBinding(
136                        KeyStroke.getKeyStroke(KeyEvent.VK_I,
137                            ALT_MASK | InputEvent.SHIFT_MASK),
138                        JavaKit.fastImportAction
139                    ),
140                    new MultiKeyBinding(
141                        KeyStroke.getKeyStroke(KeyEvent.VK_B,
142                            mask),
143                        JavaKit.gotoSuperImplementationAction
144                    ),
145                    new MultiKeyBinding(
146                        KeyStroke.getKeyStroke(KeyEvent.VK_F,
147                            ALT_MASK | InputEvent.SHIFT_MASK),
148                        JavaKit.fixImportsAction
149                    ),
150 // new MultiKeyBinding(
151
// KeyStroke.getKeyStroke(KeyEvent.VK_S,
152
// ALT_MASK | mask),
153
// JavaKit.tryCatchAction
154
// ),
155
new MultiKeyBinding(
156                        KeyStroke.getKeyStroke(KeyEvent.VK_G, ALT_MASK | (isMac ? InputEvent.SHIFT_MASK : 0)),
157                        org.netbeans.editor.ext.ExtKit.gotoDeclarationAction
158                    ),
159                    new MultiKeyBinding(
160                        KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,
161                            mask | InputEvent.SHIFT_MASK),
162                        JavaKit.javaDocShowAction
163                    ),
164                    
165                    new MultiKeyBinding(
166                        KeyStroke.getKeyStroke(KeyEvent.VK_S,
167                            InputEvent.SHIFT_MASK | ALT_MASK),
168                        JavaKit.selectNextElementAction
169                    ),
170                    
171                    new MultiKeyBinding(
172                        KeyStroke.getKeyStroke(KeyEvent.VK_A,
173                            InputEvent.SHIFT_MASK | ALT_MASK),
174                        JavaKit.selectPreviousElementAction
175                    )
176                    
177                };
178     }
179
180 }
181
Popular Tags