1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.preferences;
26
27 import org.eclipse.jface.preference.ColorFieldEditor;
28 import org.eclipse.jface.preference.FieldEditorPreferencePage;
29 import org.eclipse.jface.preference.PreferenceConverter;
30 import org.eclipse.swt.graphics.RGB;
31 import org.eclipse.swt.layout.*;
32 import org.eclipse.ui.*;
33 import org.wsmostudio.ui.WsmoUIPlugin;
34 import org.wsmostudio.ui.editors.text.WSMOTextEditor;
35
36 /***
37 * A preference page which defines different colors for the syntax highlighting in the
38 * WSMO Text editor.
39 *
40 * @author not attributable
41 * @version $Revision: 545 $ $Date: 2006-01-26 13:57:14 +0200 $
42 */
43
44 public class TextEditorColorsPage extends FieldEditorPreferencePage
45 implements IWorkbenchPreferencePage {
46
47 private static final String TEXT_EDITOR_SYSTEM_COLOR = "$WSMOTextEditor$system_color";
48 private static final String TEXT_EDITOR_KEY_COLOR = "$WSMOTextEditor$key_color";
49 private static final String TEXT_EDITOR_AUX_COLOR = "$WSMOTextEditor$aux_color";
50 private static final String TEXT_EDITOR_STR_COLOR = "$WSMOTextEditor$str_color";
51 private static final String TEXT_EDITOR_COMM_COLOR = "$WSMOTextEditor$comm_color";
52 private static final String TEXT_EDITOR_DEFAULT_COLOR = "$WSMOTextEditor$def_color";
53
54 static final String STYLE_SUFFIX = "_style";
55
56 private ColorFieldEditor systemChooser,
57 keywordsChooser,
58 auxwordsChooser,
59 stringsChooser,
60 commentsChooser,
61 defaultChooser;
62
63 public TextEditorColorsPage() {
64 super("Text Editor Syntax Coloring", FieldEditorPreferencePage.GRID);
65 setPreferenceStore(WsmoUIPlugin.getDefault().getPreferenceStore());
66 initColors();
67 }
68
69 protected void createFieldEditors() {
70
71 getFieldEditorParent().setLayout(new GridLayout(4, false));
72
73 systemChooser = new TextStyleFieldEditor(TEXT_EDITOR_SYSTEM_COLOR, "System Words : ", getFieldEditorParent());
74 addField(systemChooser);
75
76 keywordsChooser = new TextStyleFieldEditor(TEXT_EDITOR_KEY_COLOR, "Keywords : ", getFieldEditorParent());
77 addField(keywordsChooser);
78 auxwordsChooser = new TextStyleFieldEditor(TEXT_EDITOR_AUX_COLOR, "Auxiliary Words : ", getFieldEditorParent());
79 addField(auxwordsChooser);
80 stringsChooser = new TextStyleFieldEditor(TEXT_EDITOR_STR_COLOR, "String Values : ", getFieldEditorParent());
81 addField(stringsChooser);
82 commentsChooser = new TextStyleFieldEditor(TEXT_EDITOR_COMM_COLOR, "Comments : ", getFieldEditorParent());
83 addField(commentsChooser);
84 defaultChooser = new TextStyleFieldEditor(TEXT_EDITOR_DEFAULT_COLOR, "Default : ", getFieldEditorParent());
85 addField(defaultChooser);
86 }
87
88
89 public void init(IWorkbench workbench) {
90 }
91
92 public boolean performOk() {
93 boolean stat = super.performOk();
94 doUpdateOpenedEditors();
95 return stat;
96 }
97
98 protected void performDefaults() {
99 PreferenceConverter.setDefault(getPreferenceStore(), TEXT_EDITOR_SYSTEM_COLOR, WSMOTextEditor.SYSTEM_COLOR);
100 PreferenceConverter.setDefault(getPreferenceStore(), TEXT_EDITOR_KEY_COLOR, WSMOTextEditor.KEY_COLOR);
101 PreferenceConverter.setDefault(getPreferenceStore(), TEXT_EDITOR_AUX_COLOR, WSMOTextEditor.AUX_COLOR);
102 PreferenceConverter.setDefault(getPreferenceStore(), TEXT_EDITOR_STR_COLOR, WSMOTextEditor.STRING_COLOR);
103 PreferenceConverter.setDefault(getPreferenceStore(), TEXT_EDITOR_COMM_COLOR, WSMOTextEditor.COMMENT_COLOR);
104 PreferenceConverter.setDefault(getPreferenceStore(), TEXT_EDITOR_DEFAULT_COLOR, WSMOTextEditor.DEFAULT_COLOR);
105
106 getPreferenceStore().setDefault(TEXT_EDITOR_SYSTEM_COLOR + STYLE_SUFFIX, WSMOTextEditor.SYSTEM_STYLE);
107 getPreferenceStore().setDefault(TEXT_EDITOR_KEY_COLOR + STYLE_SUFFIX, WSMOTextEditor.KEY_STYLE);
108 getPreferenceStore().setDefault(TEXT_EDITOR_AUX_COLOR + STYLE_SUFFIX, WSMOTextEditor.AUX_STYLE);
109 getPreferenceStore().setDefault(TEXT_EDITOR_STR_COLOR + STYLE_SUFFIX, WSMOTextEditor.STRING_STYLE);
110 getPreferenceStore().setDefault(TEXT_EDITOR_COMM_COLOR + STYLE_SUFFIX, WSMOTextEditor.COMMENT_STYLE);
111 getPreferenceStore().setDefault(TEXT_EDITOR_DEFAULT_COLOR + STYLE_SUFFIX, WSMOTextEditor.DEFAULT_STYLE);
112
113 super.performDefaults();
114 }
115
116 private void initColors() {
117 initColorEntry(TEXT_EDITOR_SYSTEM_COLOR, WSMOTextEditor.SYSTEM_COLOR, WSMOTextEditor.SYSTEM_STYLE);
118 initColorEntry(TEXT_EDITOR_KEY_COLOR, WSMOTextEditor.KEY_COLOR, WSMOTextEditor.KEY_STYLE);
119 initColorEntry(TEXT_EDITOR_AUX_COLOR, WSMOTextEditor.AUX_COLOR, WSMOTextEditor.AUX_STYLE);
120 initColorEntry(TEXT_EDITOR_STR_COLOR, WSMOTextEditor.STRING_COLOR, WSMOTextEditor.STRING_STYLE);
121 initColorEntry(TEXT_EDITOR_COMM_COLOR, WSMOTextEditor.COMMENT_COLOR, WSMOTextEditor.COMMENT_STYLE);
122 initColorEntry(TEXT_EDITOR_DEFAULT_COLOR, WSMOTextEditor.DEFAULT_COLOR, WSMOTextEditor.DEFAULT_STYLE);
123 }
124
125 private void doUpdateOpenedEditors() {
126
127 IWorkbenchPage page = PlatformUI.getWorkbench()
128 .getActiveWorkbenchWindow()
129 .getActivePage();
130 if (page == null) {
131 return;
132 }
133 IEditorReference[] editors = page.getEditorReferences();
134 if (editors == null) {
135 return;
136 }
137 for(int i = 0; i < editors.length; i++) {
138 IEditorPart editor = editors[i].getEditor(true);
139 if (editor != null
140 && editor instanceof WSMOTextEditor) {
141 ((WSMOTextEditor)editor).doUpdateView();
142 }
143 }
144 }
145
146 private void initColorEntry(String key, RGB colorInfo, int style) {
147 if (getPreferenceStore().contains(key)) {
148 return;
149 }
150 PreferenceConverter.setValue(getPreferenceStore(), key, colorInfo);
151 PreferenceConverter.setDefault(getPreferenceStore(), key, colorInfo);
152 getPreferenceStore().setValue(key + STYLE_SUFFIX, style);
153 getPreferenceStore().setDefault(key + STYLE_SUFFIX, style);
154 }
155
156 public void dispose() {
157 systemChooser.dispose();
158 keywordsChooser.dispose();
159 auxwordsChooser.dispose();
160 stringsChooser.dispose();
161 commentsChooser.dispose();
162 defaultChooser.dispose();
163 }
164
165 public static RGB getSystemColor() {
166 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(TEXT_EDITOR_SYSTEM_COLOR)) {
167 return WSMOTextEditor.SYSTEM_COLOR;
168 }
169 return PreferenceConverter.getColor(WsmoUIPlugin.getDefault().getPreferenceStore(),
170 TEXT_EDITOR_SYSTEM_COLOR);
171 }
172 public static int getSystemStyle() {
173 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(
174 TEXT_EDITOR_SYSTEM_COLOR + STYLE_SUFFIX)) {
175 return WSMOTextEditor.SYSTEM_STYLE;
176 }
177 return WsmoUIPlugin.getDefault().getPreferenceStore().getInt(
178 TEXT_EDITOR_SYSTEM_COLOR + STYLE_SUFFIX);
179 }
180
181 public static RGB getKeywordsColor() {
182 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(TEXT_EDITOR_KEY_COLOR)) {
183 return WSMOTextEditor.KEY_COLOR;
184 }
185 return PreferenceConverter.getColor(WsmoUIPlugin.getDefault().getPreferenceStore(),
186 TEXT_EDITOR_KEY_COLOR);
187 }
188 public static int getKeywordsStyle() {
189 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(
190 TEXT_EDITOR_KEY_COLOR + STYLE_SUFFIX)) {
191 return WSMOTextEditor.KEY_STYLE;
192 }
193 return WsmoUIPlugin.getDefault().getPreferenceStore().getInt(
194 TEXT_EDITOR_KEY_COLOR + STYLE_SUFFIX);
195 }
196
197
198 public static RGB getAuxwordsColor() {
199 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(TEXT_EDITOR_AUX_COLOR)) {
200 return WSMOTextEditor.AUX_COLOR;
201 }
202 return PreferenceConverter.getColor(WsmoUIPlugin.getDefault().getPreferenceStore(),
203 TEXT_EDITOR_AUX_COLOR);
204 }
205 public static int getAuxwordsStyle() {
206 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(
207 TEXT_EDITOR_AUX_COLOR + STYLE_SUFFIX)) {
208 return WSMOTextEditor.AUX_STYLE;
209 }
210 return WsmoUIPlugin.getDefault().getPreferenceStore().getInt(
211 TEXT_EDITOR_AUX_COLOR + STYLE_SUFFIX);
212 }
213
214 public static RGB getStringsColor() {
215 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(TEXT_EDITOR_STR_COLOR)) {
216 return WSMOTextEditor.STRING_COLOR;
217 }
218 return PreferenceConverter.getColor(WsmoUIPlugin.getDefault().getPreferenceStore(),
219 TEXT_EDITOR_STR_COLOR);
220 }
221 public static int getStringsStyle() {
222 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(
223 TEXT_EDITOR_STR_COLOR + STYLE_SUFFIX)) {
224 return WSMOTextEditor.STRING_STYLE;
225 }
226 return WsmoUIPlugin.getDefault().getPreferenceStore().getInt(
227 TEXT_EDITOR_STR_COLOR + STYLE_SUFFIX);
228 }
229
230 public static RGB getCommentColor() {
231 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(TEXT_EDITOR_COMM_COLOR)) {
232 return WSMOTextEditor.COMMENT_COLOR;
233 }
234 return PreferenceConverter.getColor(WsmoUIPlugin.getDefault().getPreferenceStore(),
235 TEXT_EDITOR_COMM_COLOR);
236 }
237 public static int getCommentStyle() {
238 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(
239 TEXT_EDITOR_COMM_COLOR + STYLE_SUFFIX)) {
240 return WSMOTextEditor.COMMENT_STYLE;
241 }
242 return WsmoUIPlugin.getDefault().getPreferenceStore().getInt(
243 TEXT_EDITOR_COMM_COLOR + STYLE_SUFFIX);
244 }
245
246 public static RGB getDefaultColor() {
247 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(TEXT_EDITOR_DEFAULT_COLOR)) {
248 return WSMOTextEditor.DEFAULT_COLOR;
249 }
250 return PreferenceConverter.getColor(WsmoUIPlugin.getDefault().getPreferenceStore(),
251 TEXT_EDITOR_DEFAULT_COLOR);
252 }
253 public static int getDefaultStyle() {
254 if (false == WsmoUIPlugin.getDefault().getPreferenceStore().contains(
255 TEXT_EDITOR_DEFAULT_COLOR + STYLE_SUFFIX)) {
256 return WSMOTextEditor.DEFAULT_STYLE;
257 }
258 return WsmoUIPlugin.getDefault().getPreferenceStore().getInt(
259 TEXT_EDITOR_DEFAULT_COLOR + STYLE_SUFFIX);
260 }
261
262 }
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279