KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > gsf > GsfEditorSettings


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 package org.netbeans.modules.gsf;
20
21 import java.awt.event.InputEvent JavaDoc;
22 import java.awt.event.KeyEvent JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.TreeMap JavaDoc;
25
26 import javax.swing.KeyStroke JavaDoc;
27
28 import org.netbeans.editor.BaseKit;
29 import org.netbeans.editor.MultiKeyBinding;
30 import org.netbeans.editor.Settings;
31 import org.netbeans.editor.SettingsNames;
32 import org.netbeans.editor.SettingsUtil;
33 import org.netbeans.editor.TokenCategory;
34 import org.netbeans.editor.TokenContext;
35 import org.netbeans.editor.TokenContextPath;
36 import org.netbeans.editor.ext.ExtKit;
37
38
39 /**
40  * The classes in here no one should ever implement, as I would think all this
41  * information could be defined in a more declarative way: either via a simple interface
42  * implementation where returning specific flags enables a set of settings
43  * or a table or some external xml-like file.
44  * Maybe that is all there already in NetBeans but I could not find it.
45  * This is called from the ModuleInstall class and it's key for the editor to work.
46  */

47 public class GsfEditorSettings extends Settings.AbstractInitializer {
48     public static final Boolean JavaDoc defaultCodeFoldingEnable = Boolean.TRUE;
49
50     // gls=Generic Language Support
51
private static final String JavaDoc SETTINGS_NAME = "gls-editor-settings-initializer"; // NOI18N
52

53     public GsfEditorSettings() {
54         super(SETTINGS_NAME);
55     }
56
57     public void updateSettingsMap(Class JavaDoc kitClass, Map JavaDoc settingsMap) {
58         if (kitClass == null) {
59             return;
60         }
61
62         if (kitClass == GsfEditorKitFactory.GsfEditorKit.class) {
63             SettingsUtil.updateListSetting(settingsMap, SettingsNames.KEY_BINDING_LIST,
64                 getGenericKeyBindings());
65
66             settingsMap.put(SettingsNames.ABBREV_MAP, getDefaultAbbreviations());
67
68             settingsMap.put(SettingsNames.CODE_FOLDING_ENABLE, defaultCodeFoldingEnable);
69
70             // This is wrong; I should be calling Formatter.indentSize() to get the default,
71
// but I can't get to the mime type from here. In 6.0 the editor settings are
72
// being redone so I can hopefully fix this soon.
73
settingsMap.put(SettingsNames.SPACES_PER_TAB, Integer.valueOf(2));
74
75             //} else if (kitClass.getName().startsWith("com.sun.semplice.generated.GeneratedEditorKit")) {
76
// try {
77
// GsfEditorKit kit = (GsfEditorKit)kitClass.newInstance();
78
// String mimeType = kit.getContentType();
79
// Language l = LanguageRegistry.getInstance().getLanguageByMimeType(mimeType);
80
// if (l != null) {
81
// final Scanner scanner = l.getScanner();
82
// if (scanner != null) {
83
// settingsMap.put(SettingsNames.IDENTIFIER_ACCEPTOR, new Acceptor() {
84
// public final boolean accept(char c) {
85
// return scanner.isIdentifierChar(c);
86
// }
87
// });
88
// }
89
// }
90
// } catch (Exception ex) {
91
// ErrorManager.getDefault().notify(ex);
92
// }
93
}
94     }
95
96     public static MultiKeyBinding[] getGenericKeyBindings() {
97         int MENU_MASK = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
98
99         return new MultiKeyBinding[] {
100             new MultiKeyBinding(new KeyStroke JavaDoc[] {
101                     KeyStroke.getKeyStroke(KeyEvent.VK_J, MENU_MASK),
102                     KeyStroke.getKeyStroke(KeyEvent.VK_D, 0)
103                 }, "macro-debug-var" // NOI18N
104
),
105             new MultiKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_T,
106                     MENU_MASK | InputEvent.SHIFT_MASK), ExtKit.commentAction),
107             new MultiKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_D,
108                     MENU_MASK | InputEvent.SHIFT_MASK), ExtKit.uncommentAction)
109         };
110     }
111
112     private static Map JavaDoc getDefaultAbbreviations() {
113         Map JavaDoc abbreviations = new TreeMap JavaDoc();
114
115         // TODO - these need to be populated per-language
116

117         //Code templates
118
abbreviations.put("case", "case ${CONDITION default=\"condition1\"}\n when ${CONDITION1 default=\"condition1\"}\n\n when ${CONDITION2 default=\"condition1\"}\n\nend\n");
119         abbreviations.put("def", "def ${NAME default=\"method\"}\n ${cursor}\nend\n");
120         abbreviations.put("class", "class ${NAME default=\"cls\"}\n ${cursor}\nend\n");
121         abbreviations.put("module", "module ${NAME default=\"mod\"}\n ${cursor}\nend\n");
122         abbreviations.put("do", "do |${VAR newVarName default=\"var\"}|\n ${cursor}\nend\n");
123         abbreviations.put("if", "if ${CONDITION default=\"condition\"}\n ${cursor}\nend\n");
124         abbreviations.put("ifelse", "if ${CONDITION default=\"condition\"}\n ${cursor}\nelse\n\nend\n");
125
126         return abbreviations;
127     }
128 }
129
Popular Tags