KickJava   Java API By Example, From Geeks To Geeks.

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


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.java.editor;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26 import org.netbeans.editor.BaseDocument;
27 import org.netbeans.editor.LocaleSupport;
28 import org.netbeans.editor.Settings;
29 import org.netbeans.editor.SettingsChangeListener;
30 import org.netbeans.editor.SettingsNames;
31 import org.netbeans.editor.ext.java.JavaSettingsInitializer;
32 import org.netbeans.editor.ext.java.JavaSettingsNames;
33 import org.netbeans.modules.editor.FormatterIndentEngine;
34 import org.netbeans.modules.editor.NbEditorDocument;
35 import org.netbeans.modules.editor.java.JavaIndentEngine;
36 import org.netbeans.modules.editor.java.JavaKit;
37 import org.netbeans.modules.editor.java.NbJavaSettingsInitializer;
38 import org.netbeans.modules.editor.NbLocalizer;
39 import org.netbeans.modules.editor.options.BaseOptions;
40 import org.netbeans.modules.java.editor.options.JavaPrintOptions;
41 import org.netbeans.modules.java.editor.options.JavaOptions;
42 //import org.netbeans.modules.javacore.IndentationSettingsProvider;
43
//import org.netbeans.modules.javacore.JMManager;
44
import org.openide.modules.ModuleInstall;
45 import org.openide.options.SystemOption;
46 import org.openide.text.IndentEngine;
47 import org.openide.text.PrintSettings;
48 import org.openide.util.SharedClassObject;
49
50 /**
51  * Module installation class for editor.
52  *
53  * @author Miloslav Metelka
54  */

55 public class JavaEditorModule extends ModuleInstall {
56
57     private NbLocalizer settingsNamesLocalizer;
58     private NbLocalizer optionsLocalizer;
59 // private JavaIndentationSettingsProvider jisProvider = null;
60
static boolean inited = false;
61     
62     public static void init(){
63         if (inited) return;
64         inited = true;
65         Settings.addInitializer(new JavaSettingsInitializer(JavaKit.class));
66         Settings.addInitializer(new NbJavaSettingsInitializer());
67         Settings.reset();
68     }
69     
70     /** Module installed again. */
71     public void restored () {
72         init();
73
74         PrintSettings ps = (PrintSettings) SharedClassObject.findObject(PrintSettings.class, true);
75         ps.addOption((SystemOption)SharedClassObject.findObject(JavaPrintOptions.class, true));
76
77 // JMManager.setDocumentLocksCounter(BaseDocument.THREAD_LOCAL_LOCK_DEPTH);
78

79         settingsNamesLocalizer = new NbLocalizer(JavaSettingsNames.class);
80         optionsLocalizer = new NbLocalizer(JavaOptions.class);
81         LocaleSupport.addLocalizer(settingsNamesLocalizer);
82         LocaleSupport.addLocalizer(optionsLocalizer);
83 // if (jisProvider == null) {
84
// jisProvider = new JavaIndentationSettingsProvider();
85
// JMManager.setIndentationSettingsProvider(jisProvider);
86
// }
87

88     }
89
90     /** Called when module is uninstalled. Overrides superclass method. */
91     public void uninstalled() {
92         
93 // if (jisProvider != null) {
94
// jisProvider.release();
95
// JMManager.setIndentationSettingsProvider(null);
96
// jisProvider = null;
97
// }
98

99         // Options
100
PrintSettings ps = (PrintSettings) SharedClassObject.findObject(PrintSettings.class, true);
101         ps.removeOption((SystemOption)SharedClassObject.findObject(JavaPrintOptions.class, true));
102
103 // JMManager.setDocumentLocksCounter(null);
104

105         Settings.removeInitializer(JavaSettingsInitializer.NAME);
106         Settings.removeInitializer(NbJavaSettingsInitializer.NAME);
107         Settings.reset();
108
109         LocaleSupport.removeLocalizer(settingsNamesLocalizer);
110         settingsNamesLocalizer = null;
111         LocaleSupport.removeLocalizer(optionsLocalizer);
112         optionsLocalizer = null;
113         
114     }
115     
116 // private static class JavaIndentationSettingsProvider implements IndentationSettingsProvider, PropertyChangeListener{
117
//
118
// private static final Map indentSettings2propertyName
119
// = new HashMap();
120
//
121
// static {
122
// indentSettings2propertyName.put(
123
// JavaIndentEngine.JAVA_FORMAT_LEADING_STAR_IN_COMMENT_PROP,
124
// JavaSettingsNames.JAVA_FORMAT_LEADING_STAR_IN_COMMENT
125
// );
126
// indentSettings2propertyName.put(
127
// JavaIndentEngine.JAVA_FORMAT_NEWLINE_BEFORE_BRACE_PROP,
128
// JavaSettingsNames.JAVA_FORMAT_NEWLINE_BEFORE_BRACE
129
// );
130
// indentSettings2propertyName.put(
131
// JavaIndentEngine.JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS_PROP,
132
// JavaSettingsNames.JAVA_FORMAT_SPACE_BEFORE_PARENTHESIS
133
// );
134
// indentSettings2propertyName.put(
135
// JavaIndentEngine.JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT_PROP,
136
// JavaSettingsNames.JAVA_FORMAT_STATEMENT_CONTINUATION_INDENT
137
// );
138
// indentSettings2propertyName.put(
139
// FormatterIndentEngine.EXPAND_TABS_PROP,
140
// SettingsNames.EXPAND_TABS
141
// );
142
// indentSettings2propertyName.put(
143
// FormatterIndentEngine.SPACES_PER_TAB_PROP,
144
// SettingsNames.SPACES_PER_TAB
145
// );
146
// }
147
//
148
// private JavaIndentEngine indentEngine = null;
149
//
150
// private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
151
//
152
// public JavaIndentationSettingsProvider(){
153
// }
154
//
155
// private synchronized JavaIndentEngine getIndentEngine() {
156
// if (indentEngine == null) {
157
// BaseOptions javaOptions = BaseOptions.getOptions(JavaKit.class);
158
// if (javaOptions instanceof JavaOptions) {
159
// IndentEngine eng = javaOptions.getIndentEngine();
160
// if (eng instanceof JavaIndentEngine) {
161
// indentEngine = (JavaIndentEngine)eng;
162
// indentEngine.addPropertyChangeListener(this);
163
// }
164
// }
165
// }
166
// return indentEngine;
167
// }
168
//
169
// public Object getPropertyValue(String propertyName) {
170
// JavaIndentEngine eng = getIndentEngine();
171
// if (eng != null){
172
// String settingsPropertyName = (String)indentSettings2propertyName.get(propertyName);
173
// if (settingsPropertyName != null) {
174
// return eng.getValue(settingsPropertyName);
175
// }
176
// }
177
//
178
// return null;
179
// }
180
//
181
// public void removePropertyChangeListener(java.beans.PropertyChangeListener l) {
182
// getIndentEngine(); // possibly init engine to listen on it
183
// pcs.removePropertyChangeListener(l);
184
// }
185
//
186
// public void addPropertyChangeListener(java.beans.PropertyChangeListener l) {
187
// getIndentEngine(); // possibly init engine to listen on it
188
// pcs.addPropertyChangeListener(l);
189
// }
190
//
191
// public void propertyChange(java.beans.PropertyChangeEvent evt) {
192
// if (evt == null) return;
193
// pcs.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
194
// }
195
//
196
// public synchronized void release() {
197
// if (indentEngine != null) {
198
// indentEngine.removePropertyChangeListener(this);
199
// }
200
// }
201
//
202
// }
203
}
204
Popular Tags