Commit | Line | Data |
---|---|---|
73005152 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2005, 2008, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * $Id: SDViewPref.java,v 1.3 2008/01/24 02:28:51 apnan Exp $ | |
8 | * | |
9 | * Contributors: | |
10 | * IBM - Initial API and implementation | |
11 | * Bernd Hufmann - Updated for TMF | |
12 | **********************************************************************/ | |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences; | |
14 | ||
e6ace8bb | 15 | import java.util.Arrays; |
73005152 BH |
16 | import java.util.Hashtable; |
17 | ||
18 | import org.eclipse.jface.preference.IPreferenceStore; | |
19 | import org.eclipse.jface.preference.PreferenceConverter; | |
20 | import org.eclipse.jface.util.IPropertyChangeListener; | |
21 | import org.eclipse.jface.util.PropertyChangeEvent; | |
d34665f9 | 22 | import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; |
73005152 BH |
23 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; |
24 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont; | |
25 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences; | |
26 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl.ColorImpl; | |
27 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl.FontImpl; | |
28 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages; | |
29 | import org.eclipse.swt.SWT; | |
30 | import org.eclipse.swt.graphics.Color; | |
31 | import org.eclipse.swt.graphics.FontData; | |
32 | import org.eclipse.swt.graphics.RGB; | |
33 | import org.eclipse.swt.widgets.Display; | |
34 | ||
35 | /** | |
36 | * This is the Sequence Diagram preference handler This class is responsible for accessing the current user preferences | |
37 | * selection This class also provider getters for each modifiable preferences | |
38 | * | |
39 | * @author sveyrier | |
40 | */ | |
41 | public class SDViewPref implements ISDPreferences, IPropertyChangeListener { | |
42 | ||
43 | public static final String BACK_COLOR_POSTFIX = "_BACK_COLOR";//$NON-NLS-1$ | |
44 | public static final String FORE_COLOR_POSTFIX = "_FORE_COLOR";//$NON-NLS-1$ | |
45 | public static final String TEXT_COLOR_POSTFIX = "_TEXT_COLOR";//$NON-NLS-1$ | |
46 | ||
e6ace8bb | 47 | private static final String[] fontList = { PREF_LIFELINE, PREF_EXEC, PREF_SYNC_MESS, PREF_SYNC_MESS_RET, PREF_ASYNC_MESS, PREF_ASYNC_MESS_RET, PREF_FRAME, PREF_LIFELINE_HEADER, PREF_FRAME_NAME }; |
73005152 | 48 | |
e6ace8bb | 49 | private static final String[] fontList2 = { SDMessages._88, SDMessages._89, SDMessages._90, SDMessages._91, SDMessages._92, SDMessages._93, SDMessages._94, SDMessages._95, SDMessages._96 }; |
73005152 | 50 | |
e6ace8bb | 51 | private static final String[] prefBackColorList = { PREF_LIFELINE, PREF_EXEC, PREF_FRAME, PREF_LIFELINE_HEADER, PREF_FRAME_NAME }; |
73005152 | 52 | |
e6ace8bb | 53 | private static final String[] prefForeColorList = { PREF_LIFELINE, PREF_EXEC, PREF_SYNC_MESS, PREF_SYNC_MESS_RET, PREF_ASYNC_MESS, PREF_ASYNC_MESS_RET, PREF_FRAME, PREF_LIFELINE_HEADER, PREF_FRAME_NAME }; |
73005152 | 54 | |
e6ace8bb | 55 | private static final String[] prefTextColorList = { PREF_LIFELINE, PREF_SYNC_MESS, PREF_SYNC_MESS_RET, PREF_ASYNC_MESS, PREF_ASYNC_MESS_RET, PREF_LIFELINE_HEADER, PREF_FRAME_NAME }; |
73005152 BH |
56 | |
57 | protected Hashtable<String, IFont> fontPref; | |
58 | protected Hashtable<String, IColor> foreColorPref; | |
59 | protected Hashtable<String, IColor> backColorPref; | |
60 | protected Hashtable<String, IColor> textColorPref; | |
61 | ||
e6ace8bb | 62 | private static SDViewPref handle = null; |
73005152 BH |
63 | protected IPreferenceStore prefStore = null; |
64 | protected IColor timeCompressionSelectionColor = null; | |
65 | ||
66 | protected boolean noFocusSelection = false; | |
67 | ||
68 | protected static final String TEMP_TAG = "_TEMP";//$NON-NLS-1$ | |
69 | ||
70 | /** | |
71 | * Builds the Sequence Diagram preference handler: - Define the preference default values. - Load the currently used | |
72 | * preferences setting | |
73 | * | |
74 | */ | |
75 | protected SDViewPref() { | |
76 | prefStore = TmfUiPlugin.getDefault().getPreferenceStore(); | |
77 | ||
78 | prefStore.setDefault(PREF_LINK_FONT, true); | |
79 | prefStore.setDefault(PREF_EXCLUDE_EXTERNAL_TIME, true); | |
80 | prefStore.setDefault(PREF_LIFELINE_WIDTH, 200); | |
81 | prefStore.setDefault(PREF_USE_GRADIENT, true); | |
82 | prefStore.setDefault(PREF_TOOLTIP, true); | |
83 | ||
84 | fontPref = new Hashtable<String, IFont>(); | |
85 | foreColorPref = new Hashtable<String, IColor>(); | |
86 | backColorPref = new Hashtable<String, IColor>(); | |
87 | textColorPref = new Hashtable<String, IColor>(); | |
88 | ||
89 | for (int i = 0; i < fontList.length; i++) { | |
90 | if (fontList[i].equals(PREF_FRAME_NAME)) { | |
91 | FontData[] data = Display.getDefault().getSystemFont().getFontData(); | |
92 | data[0].setStyle(SWT.BOLD); | |
93 | PreferenceConverter.setDefault(prefStore, fontList[i], data[0]); | |
94 | PreferenceConverter.setDefault(prefStore, fontList[i] + TEMP_TAG, data[0]); | |
95 | } else { | |
96 | PreferenceConverter.setDefault(prefStore, fontList[i], Display.getDefault().getSystemFont().getFontData()); | |
97 | PreferenceConverter.setDefault(prefStore, fontList[i] + TEMP_TAG, Display.getDefault().getSystemFont().getFontData()); | |
98 | } | |
99 | } | |
100 | ||
101 | for (int i = 0; i < prefBackColorList.length; i++) { | |
102 | IColor color; | |
103 | if ((prefBackColorList[i].equals(PREF_EXEC)) || prefBackColorList[i].equals(PREF_FRAME_NAME)) | |
104 | color = new ColorImpl(Display.getDefault(), 201, 222, 233); | |
105 | else if (prefBackColorList[i].equals(PREF_LIFELINE)) | |
106 | color = new ColorImpl(Display.getDefault(), 220, 220, 220); | |
107 | else if (prefBackColorList[i].equals(PREF_LIFELINE_HEADER)) | |
108 | color = new ColorImpl(Display.getDefault(), 245, 244, 244); | |
109 | else | |
110 | color = new ColorImpl(Display.getDefault(), 255, 255, 255); | |
111 | PreferenceConverter.setDefault(prefStore, prefBackColorList[i] + BACK_COLOR_POSTFIX, ((Color) color.getColor()).getRGB()); | |
112 | PreferenceConverter.setDefault(prefStore, prefBackColorList[i] + BACK_COLOR_POSTFIX + TEMP_TAG, ((Color) color.getColor()).getRGB()); | |
113 | color.dispose(); | |
114 | } | |
115 | ||
116 | for (int i = 0; i < prefForeColorList.length; i++) { | |
117 | IColor color; | |
118 | if (prefForeColorList[i].equals(PREF_LIFELINE)) | |
119 | color = new ColorImpl(Display.getDefault(), 129, 129, 129); | |
120 | else if (prefForeColorList[i].equals(PREF_FRAME_NAME)) | |
121 | color = new ColorImpl(Display.getDefault(), 81, 153, 200); | |
122 | else if (prefForeColorList[i].equals(PREF_LIFELINE_HEADER)) | |
123 | color = new ColorImpl(Display.getDefault(), 129, 127, 137); | |
124 | else | |
125 | color = new ColorImpl(Display.getDefault(), 134, 176, 212); | |
126 | PreferenceConverter.setDefault(prefStore, prefForeColorList[i] + FORE_COLOR_POSTFIX, ((Color) color.getColor()).getRGB()); | |
127 | PreferenceConverter.setDefault(prefStore, prefForeColorList[i] + FORE_COLOR_POSTFIX + TEMP_TAG, ((Color) color.getColor()).getRGB()); | |
128 | color.dispose(); | |
129 | } | |
130 | ||
131 | for (int i = 0; i < prefTextColorList.length; i++) { | |
132 | IColor color; | |
133 | if (prefTextColorList[i].equals(PREF_LIFELINE)) | |
134 | color = new ColorImpl(Display.getDefault(), 129, 129, 129); | |
135 | else if (prefTextColorList[i].equals(PREF_FRAME_NAME)) | |
136 | color = new ColorImpl(Display.getDefault(), 0, 0, 0); | |
137 | else if (prefTextColorList[i].equals(PREF_LIFELINE_HEADER)) | |
138 | color = new ColorImpl(Display.getDefault(), 129, 127, 137); | |
139 | else | |
140 | color = new ColorImpl(Display.getDefault(), 134, 176, 212); | |
141 | PreferenceConverter.setDefault(prefStore, prefTextColorList[i] + TEXT_COLOR_POSTFIX, ((Color) color.getColor()).getRGB()); | |
142 | PreferenceConverter.setDefault(prefStore, prefTextColorList[i] + TEXT_COLOR_POSTFIX + TEMP_TAG, ((Color) color.getColor()).getRGB()); | |
143 | color.dispose(); | |
144 | } | |
145 | ||
146 | IColor color = new ColorImpl(Display.getDefault(), 218, 232, 238); | |
147 | PreferenceConverter.setDefault(prefStore, PREF_TIME_COMP, ((Color) color.getColor()).getRGB()); | |
148 | color.dispose(); | |
149 | ||
150 | buildFontsAndColors(); | |
151 | ||
152 | prefStore.addPropertyChangeListener(this); | |
153 | } | |
154 | ||
155 | /** | |
156 | * Returns the PreferenceStore | |
157 | * | |
158 | * @return the PreferenceStore | |
159 | */ | |
160 | public IPreferenceStore getPreferenceStore() { | |
161 | return prefStore; | |
162 | } | |
163 | ||
164 | /** | |
165 | * Apply the preferences in the preferences handler | |
166 | */ | |
167 | public void apply() { | |
168 | buildFontsAndColors(); | |
169 | prefStore.firePropertyChangeEvent("PREFOK", null, null); //$NON-NLS-1$ | |
170 | } | |
171 | ||
172 | /** | |
173 | * Returns an unique instance of the Sequence Diagram preference handler | |
174 | * | |
175 | * @return the preference handler instance | |
176 | */ | |
177 | static public SDViewPref getInstance() { | |
178 | if (handle == null) | |
179 | handle = new SDViewPref(); | |
180 | return handle; | |
181 | } | |
182 | ||
183 | /** | |
184 | * Returns the chosen foreground color | |
185 | * | |
186 | * @return the foreground color | |
187 | */ | |
188 | @Override | |
189 | public IColor getForeGroundColor(String prefName) { | |
190 | if ((foreColorPref.get(prefName + FORE_COLOR_POSTFIX) != null) && (foreColorPref.get(prefName + FORE_COLOR_POSTFIX) instanceof ColorImpl)) | |
191 | return (IColor) foreColorPref.get(prefName + FORE_COLOR_POSTFIX); | |
192 | else | |
193 | return ColorImpl.getSystemColor(SWT.COLOR_BLACK); | |
194 | } | |
195 | ||
196 | /** | |
197 | * Returns the chosen background color | |
198 | * | |
199 | * @return the background color | |
200 | */ | |
201 | @Override | |
202 | public IColor getBackGroundColor(String prefName) { | |
203 | if ((backColorPref.get(prefName + BACK_COLOR_POSTFIX) != null) && (backColorPref.get(prefName + BACK_COLOR_POSTFIX) instanceof ColorImpl)) | |
204 | return (IColor) backColorPref.get(prefName + BACK_COLOR_POSTFIX); | |
205 | else | |
206 | return ColorImpl.getSystemColor(SWT.COLOR_WHITE); | |
207 | } | |
208 | ||
209 | /** | |
210 | * Returns the chosen font color | |
211 | * | |
212 | * @return the font color | |
213 | */ | |
214 | @Override | |
215 | public IColor getFontColor(String prefName) { | |
216 | if ((textColorPref.get(prefName + TEXT_COLOR_POSTFIX) != null) && (textColorPref.get(prefName + TEXT_COLOR_POSTFIX) instanceof ColorImpl)) | |
217 | return (IColor) textColorPref.get(prefName + TEXT_COLOR_POSTFIX); | |
218 | else | |
219 | return ColorImpl.getSystemColor(SWT.COLOR_BLACK); | |
220 | } | |
221 | ||
222 | /** | |
223 | * Returns the foreground color to use for widget selection. This color is system dependent and not set using the | |
224 | * preference page | |
225 | * | |
226 | * @return the foreground color | |
227 | */ | |
228 | @Override | |
229 | public IColor getForeGroundColorSelection() { | |
230 | if (noFocusSelection) | |
231 | return ColorImpl.getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND); | |
232 | return ColorImpl.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); | |
233 | } | |
234 | ||
235 | /** | |
236 | * Returns the background color to use for widget selection. This color is system dependent and not set using the | |
237 | * preference page | |
238 | * | |
239 | * @return the background color | |
240 | */ | |
241 | @Override | |
242 | public IColor getBackGroundColorSelection() { | |
243 | if (noFocusSelection) | |
244 | return ColorImpl.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); | |
245 | return ColorImpl.getSystemColor(SWT.COLOR_LIST_SELECTION); | |
246 | } | |
247 | ||
248 | /** | |
249 | * Returns the chosen font | |
250 | * | |
251 | * @return the font | |
252 | */ | |
253 | @Override | |
254 | public IFont getFont(String prefName) { | |
255 | if ((fontPref.get(prefName) != null) && (fontPref.get(prefName) instanceof IFont)) | |
256 | return (IFont) fontPref.get(prefName); | |
257 | else | |
258 | return FontImpl.getSystemFont(); | |
259 | } | |
260 | ||
261 | /** | |
262 | * Returns the SwimLane width chosen | |
263 | * | |
264 | * @return the SwimLane width | |
265 | */ | |
266 | public int getLifelineWidth() { | |
267 | return prefStore.getInt(PREF_LIFELINE_WIDTH); | |
268 | } | |
269 | ||
270 | /** | |
271 | * Returns if font linkage with zoom has been chosen | |
272 | * | |
273 | * @return true if checked false otherwise | |
274 | */ | |
275 | public boolean fontLinked() { | |
276 | return prefStore.getBoolean(PREF_LINK_FONT); | |
277 | } | |
278 | ||
279 | /** | |
280 | * Returns the tooltip enablement | |
281 | * | |
282 | * @return true if checked false otherwise | |
283 | */ | |
284 | public boolean tooltipEnabled() { | |
285 | return prefStore.getBoolean(PREF_TOOLTIP); | |
286 | } | |
287 | ||
288 | /** | |
289 | * Return true if the user do not want to take external time (basically found and lost messages with time) into | |
290 | * account in the min max computation | |
291 | * | |
292 | * @return true if checked false otherwise | |
293 | */ | |
294 | public boolean excludeExternalTime() { | |
295 | return prefStore.getBoolean(PREF_EXCLUDE_EXTERNAL_TIME); | |
296 | } | |
297 | ||
298 | /** | |
299 | * Returns if the use gradient color has been chosen | |
300 | * | |
301 | * @return true if checked false otherwise | |
302 | */ | |
303 | @Override | |
304 | public boolean useGradienColor() { | |
305 | return prefStore.getBoolean(PREF_USE_GRADIENT); | |
306 | } | |
307 | ||
308 | /** | |
309 | * Returns the color used to connect the time compression bar to the diagram graph node | |
310 | * | |
311 | * @return the selection color | |
312 | */ | |
313 | @Override | |
314 | public IColor getTimeCompressionSelectionColor() { | |
315 | return timeCompressionSelectionColor; | |
316 | } | |
317 | ||
318 | /** | |
319 | * Builds the new colors and fonts according the current user selection when the OK or Apply button is clicked | |
320 | * | |
321 | */ | |
322 | protected void buildFontsAndColors() { | |
323 | ||
324 | Display display = Display.getDefault(); | |
325 | ||
326 | for (int i = 0; i < fontList.length; i++) { | |
327 | FontData fontData = PreferenceConverter.getFontData(prefStore, fontList[i]); | |
328 | if ((fontPref.get(fontList[i]) != null) && (fontPref.get(fontList[i]) instanceof IFont)) | |
329 | ((IFont) fontPref.get(fontList[i])).dispose(); | |
330 | fontPref.put(fontList[i], new FontImpl(display, fontData)); | |
331 | } | |
332 | ||
333 | for (int i = 0; i < prefBackColorList.length; i++) { | |
334 | RGB rgb = PreferenceConverter.getColor(prefStore, prefBackColorList[i] + BACK_COLOR_POSTFIX); | |
335 | if ((backColorPref.get(prefBackColorList[i] + BACK_COLOR_POSTFIX) != null) && (backColorPref.get(prefBackColorList[i] + BACK_COLOR_POSTFIX) instanceof IColor)) | |
336 | ((IColor) backColorPref.get(prefBackColorList[i] + BACK_COLOR_POSTFIX)).dispose(); | |
337 | backColorPref.put(prefBackColorList[i] + BACK_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue)); | |
338 | } | |
339 | ||
340 | for (int i = 0; i < prefForeColorList.length; i++) { | |
341 | RGB rgb = PreferenceConverter.getColor(prefStore, prefForeColorList[i] + FORE_COLOR_POSTFIX); | |
342 | if ((foreColorPref.get(prefForeColorList[i] + FORE_COLOR_POSTFIX) != null) && (foreColorPref.get(prefForeColorList[i] + FORE_COLOR_POSTFIX) instanceof IColor)) | |
343 | ((IColor) foreColorPref.get(prefForeColorList[i] + FORE_COLOR_POSTFIX)).dispose(); | |
344 | foreColorPref.put(prefForeColorList[i] + FORE_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue)); | |
345 | } | |
346 | ||
347 | for (int i = 0; i < prefTextColorList.length; i++) { | |
348 | RGB rgb = PreferenceConverter.getColor(prefStore, prefTextColorList[i] + TEXT_COLOR_POSTFIX); | |
349 | if ((textColorPref.get(prefTextColorList[i] + TEXT_COLOR_POSTFIX) != null) && (textColorPref.get(prefTextColorList[i] + TEXT_COLOR_POSTFIX) instanceof IColor)) | |
350 | ((IColor) textColorPref.get(prefTextColorList[i] + TEXT_COLOR_POSTFIX)).dispose(); | |
351 | textColorPref.put(prefTextColorList[i] + TEXT_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue)); | |
352 | } | |
353 | ||
354 | RGB rgb = PreferenceConverter.getColor(prefStore, PREF_TIME_COMP); | |
355 | if (timeCompressionSelectionColor != null) | |
356 | timeCompressionSelectionColor.dispose(); | |
357 | timeCompressionSelectionColor = new ColorImpl(display, rgb.red, rgb.green, rgb.blue); | |
358 | } | |
359 | ||
360 | public void addPropertyChangeListener(IPropertyChangeListener listener) { | |
361 | prefStore.addPropertyChangeListener(listener); | |
362 | } | |
363 | ||
364 | public void removePropertyChangeListener(IPropertyChangeListener listener) { | |
365 | prefStore.removePropertyChangeListener(listener); | |
366 | } | |
367 | ||
368 | /* | |
369 | * (non-Javadoc) | |
370 | * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) | |
371 | */ | |
372 | @Override | |
373 | public void propertyChange(PropertyChangeEvent event) { | |
374 | if (!event.getProperty().equals("PREFOK")) //$NON-NLS-1$ | |
375 | { | |
376 | buildFontsAndColors(); | |
377 | prefStore.firePropertyChangeEvent("PREFOK", null, null); //$NON-NLS-1$ | |
378 | } | |
379 | } | |
380 | ||
381 | public void setNoFocusSelection(boolean v) { | |
382 | noFocusSelection = v; | |
383 | } | |
e6ace8bb BH |
384 | |
385 | /** | |
386 | * @return static font list | |
387 | */ | |
388 | public static String[] getFontList() { | |
389 | return Arrays.copyOf(fontList, fontList.length); | |
390 | } | |
391 | ||
392 | /** | |
393 | * @return 2nd static font list | |
394 | */ | |
395 | public static String[] getFontList2() { | |
396 | return Arrays.copyOf(fontList2, fontList2.length); | |
397 | } | |
398 | ||
399 | /** | |
400 | * @return preference background color list | |
401 | */ | |
402 | public static String[] getPrefBackColorList() { | |
403 | return Arrays.copyOf(prefBackColorList, prefBackColorList.length); | |
404 | } | |
405 | ||
406 | /** | |
407 | * @return preference foreground color list | |
408 | */ | |
409 | public static String[] getPrefForeColorList() { | |
410 | return Arrays.copyOf(prefForeColorList, prefForeColorList.length); | |
411 | } | |
412 | ||
413 | /** | |
414 | * @return preference text color list color list | |
415 | */ | |
416 | public static String[] getPrefTextColorList() { | |
417 | return Arrays.copyOf(prefTextColorList, prefTextColorList.length); | |
418 | } | |
73005152 | 419 | } |