Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2005, 2014 IBM Corporation, Ericsson |
73005152 BH |
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 | |
a55887ca AM |
7 | * |
8 | * Contributors: | |
c8422608 AM |
9 | * IBM - Initial API and implementation |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.views.uml2sd.preferences; |
73005152 | 14 | |
e6ace8bb | 15 | import java.util.Arrays; |
cab6c8ff | 16 | import java.util.Collections; |
73005152 | 17 | import java.util.Hashtable; |
eb63f5ff | 18 | import java.util.Map; |
73005152 BH |
19 | |
20 | import org.eclipse.jface.preference.IPreferenceStore; | |
21 | import org.eclipse.jface.preference.PreferenceConverter; | |
22 | import org.eclipse.jface.util.IPropertyChangeListener; | |
23 | import org.eclipse.jface.util.PropertyChangeEvent; | |
73005152 BH |
24 | import org.eclipse.swt.SWT; |
25 | import org.eclipse.swt.graphics.Color; | |
26 | import org.eclipse.swt.graphics.FontData; | |
27 | import org.eclipse.swt.graphics.RGB; | |
28 | import org.eclipse.swt.widgets.Display; | |
2bdf0193 AM |
29 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
30 | import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.IColor; | |
31 | import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.IFont; | |
32 | import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.impl.ColorImpl; | |
33 | import org.eclipse.tracecompass.tmf.ui.views.uml2sd.drawings.impl.FontImpl; | |
34 | import org.eclipse.tracecompass.tmf.ui.views.uml2sd.util.Messages; | |
73005152 BH |
35 | |
36 | /** | |
83dcfe09 MK |
37 | * This is the Sequence Diagram preference handler. This class is responsible |
38 | * for accessing the current user preferences selection This class also provider | |
39 | * getters for each modifiable preferences. | |
a55887ca | 40 | * |
df0b8ff4 | 41 | * @version 1.0 |
73005152 BH |
42 | * @author sveyrier |
43 | */ | |
44 | public class SDViewPref implements ISDPreferences, IPropertyChangeListener { | |
45 | ||
83dcfe09 MK |
46 | private static final RGB DEFAULT_TIME_COMP_RGB = new RGB(218, 232, 238); |
47 | private static final RGB DEFAULT_RGB = new RGB(134, 176, 212); | |
48 | private static final RGB DEFAULT_LIFELINE_HEADER_RGB = new RGB(129, 127, 137); | |
49 | private static final RGB DEFAULT_FRAME_RGB = new RGB(0, 0, 0); | |
50 | private static final RGB DEFAULT_LIFELINE_RGB = new RGB(129, 129, 129); | |
51 | private static final RGB FOREGROUND_LIFELINE_RGB = new RGB(129, 129, 129); | |
52 | private static final RGB FOREGROUND_FRAME_RGB = new RGB(81, 153, 200); | |
53 | private static final RGB FOREGROUND_LIFELINE_HEADER_RGB = new RGB(129, 127, 137); | |
54 | private static final RGB FOREGROUND_RGB = new RGB(134, 176, 212); | |
55 | private static final RGB BACKGROUND_DEFAULT_RGB = new RGB(255, 255, 255); | |
56 | private static final RGB BACKGROUND_LIFELINE_HEADER_RGB = new RGB(245, 244, 244); | |
57 | private static final RGB BACKGROUND_LIFELINE_RGB = new RGB(220, 220, 220); | |
58 | private static final RGB BACKGROUND_FRAME_RGB = new RGB(201, 222, 233); | |
df0b8ff4 BH |
59 | // ------------------------------------------------------------------------ |
60 | // Constants | |
61 | // ------------------------------------------------------------------------ | |
62 | /** | |
a55887ca | 63 | * Postfix string for background color property |
df0b8ff4 | 64 | */ |
73005152 | 65 | public static final String BACK_COLOR_POSTFIX = "_BACK_COLOR";//$NON-NLS-1$ |
df0b8ff4 | 66 | /** |
a55887ca | 67 | * Postfix string for foreground color property |
df0b8ff4 | 68 | */ |
73005152 | 69 | public static final String FORE_COLOR_POSTFIX = "_FORE_COLOR";//$NON-NLS-1$ |
df0b8ff4 | 70 | /** |
a55887ca | 71 | * Postfix string for text color property |
df0b8ff4 | 72 | */ |
73005152 | 73 | public static final String TEXT_COLOR_POSTFIX = "_TEXT_COLOR";//$NON-NLS-1$ |
df0b8ff4 BH |
74 | /** |
75 | * Array of preference names | |
76 | */ | |
eb63f5ff | 77 | private static final String[] FONT_LIST = { 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 }; |
df0b8ff4 BH |
78 | /** |
79 | * A 2nd array of preference names | |
80 | */ | |
83dcfe09 MK |
81 | private static final String[] FONT_LIST2 = { Messages.SequenceDiagram_Lifeline, Messages.SequenceDiagram_ExecutionOccurrence, Messages.SequenceDiagram_SyncMessage, Messages.SequenceDiagram_SyncMessageReturn, |
82 | Messages.SequenceDiagram_AsyncMessage, Messages.SequenceDiagram_AsyncMessageReturn, Messages.SequenceDiagram_Frame, Messages.SequenceDiagram_LifelineHeader, Messages.SequenceDiagram_FrameTitle }; | |
df0b8ff4 BH |
83 | /** |
84 | * Array of background color preference names | |
85 | */ | |
eb63f5ff | 86 | private static final String[] PREF_BACK_COLOR_LIST = { PREF_LIFELINE, PREF_EXEC, PREF_FRAME, PREF_LIFELINE_HEADER, PREF_FRAME_NAME }; |
df0b8ff4 BH |
87 | /** |
88 | * Array of foreground color preference names | |
89 | */ | |
eb63f5ff | 90 | private static final String[] PREF_FORE_COLOR_LIST = { 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 }; |
df0b8ff4 BH |
91 | /** |
92 | * Array of text color preference names | |
93 | */ | |
eb63f5ff | 94 | private static final String[] PREF_TEXT_COLOR_LIST = { PREF_LIFELINE, PREF_SYNC_MESS, PREF_SYNC_MESS_RET, PREF_ASYNC_MESS, PREF_ASYNC_MESS_RET, PREF_LIFELINE_HEADER, PREF_FRAME_NAME }; |
df0b8ff4 | 95 | /** |
a55887ca | 96 | * Temporary tag |
df0b8ff4 | 97 | */ |
cab6c8ff | 98 | public static final String TEMP_TAG = "_TEMP";//$NON-NLS-1$ |
df0b8ff4 BH |
99 | |
100 | // ------------------------------------------------------------------------ | |
101 | // Attributes | |
102 | // ------------------------------------------------------------------------ | |
73005152 | 103 | |
df0b8ff4 BH |
104 | /** |
105 | * The sequence diagram preferences singleton instance | |
106 | */ | |
eb63f5ff | 107 | private static SDViewPref fHandle = null; |
df0b8ff4 | 108 | /** |
a55887ca | 109 | * Hashtable for font preferences |
df0b8ff4 | 110 | */ |
cab6c8ff BH |
111 | private Map<String, IFont> fFontPref; |
112 | ||
df0b8ff4 | 113 | /** |
a55887ca | 114 | * Hashtable for foreground color preferences |
df0b8ff4 | 115 | */ |
cab6c8ff | 116 | private Map<String, IColor> fForeColorPref; |
df0b8ff4 | 117 | /** |
a55887ca | 118 | * Hashtable for background color preferences |
df0b8ff4 | 119 | */ |
cab6c8ff | 120 | private Map<String, IColor> fBackColorPref; |
df0b8ff4 | 121 | /** |
a55887ca | 122 | * Hashtable for text color preferences |
df0b8ff4 | 123 | */ |
cab6c8ff | 124 | private Map<String, IColor> fTextColorPref; |
df0b8ff4 BH |
125 | /** |
126 | * The reference to the preference store. | |
127 | */ | |
cab6c8ff | 128 | private IPreferenceStore fPrefStore = null; |
df0b8ff4 BH |
129 | /** |
130 | * Color for the time compression selection | |
131 | */ | |
cab6c8ff | 132 | private IColor fTimeCompressionSelectionColor = null; |
df0b8ff4 BH |
133 | /** |
134 | * Flag whether no focus selection or not. | |
135 | */ | |
cab6c8ff | 136 | private boolean fNoFocusSelection = false; |
73005152 | 137 | |
df0b8ff4 BH |
138 | // ------------------------------------------------------------------------ |
139 | // Constructors | |
140 | // ------------------------------------------------------------------------ | |
a55887ca | 141 | |
73005152 | 142 | /** |
83dcfe09 MK |
143 | * Builds the Sequence Diagram preference handler: - Define the preference |
144 | * default values. - Load the currently used preferences setting | |
73005152 BH |
145 | */ |
146 | protected SDViewPref() { | |
8fd82db5 | 147 | fPrefStore = Activator.getDefault().getPreferenceStore(); |
73005152 | 148 | |
eb63f5ff BH |
149 | fPrefStore.setDefault(PREF_LINK_FONT, true); |
150 | fPrefStore.setDefault(PREF_EXCLUDE_EXTERNAL_TIME, true); | |
151 | fPrefStore.setDefault(PREF_LIFELINE_WIDTH, 200); | |
152 | fPrefStore.setDefault(PREF_USE_GRADIENT, true); | |
153 | fPrefStore.setDefault(PREF_TOOLTIP, true); | |
73005152 | 154 | |
507b1336 AM |
155 | fFontPref = new Hashtable<>(); |
156 | fForeColorPref = new Hashtable<>(); | |
157 | fBackColorPref = new Hashtable<>(); | |
158 | fTextColorPref = new Hashtable<>(); | |
73005152 | 159 | |
eb63f5ff BH |
160 | for (int i = 0; i < FONT_LIST.length; i++) { |
161 | if (FONT_LIST[i].equals(PREF_FRAME_NAME)) { | |
73005152 BH |
162 | FontData[] data = Display.getDefault().getSystemFont().getFontData(); |
163 | data[0].setStyle(SWT.BOLD); | |
eb63f5ff BH |
164 | PreferenceConverter.setDefault(fPrefStore, FONT_LIST[i], data[0]); |
165 | PreferenceConverter.setDefault(fPrefStore, FONT_LIST[i] + TEMP_TAG, data[0]); | |
73005152 | 166 | } else { |
eb63f5ff BH |
167 | PreferenceConverter.setDefault(fPrefStore, FONT_LIST[i], Display.getDefault().getSystemFont().getFontData()); |
168 | PreferenceConverter.setDefault(fPrefStore, FONT_LIST[i] + TEMP_TAG, Display.getDefault().getSystemFont().getFontData()); | |
73005152 BH |
169 | } |
170 | } | |
171 | ||
eb63f5ff | 172 | for (int i = 0; i < PREF_BACK_COLOR_LIST.length; i++) { |
73005152 | 173 | IColor color; |
eb63f5ff | 174 | if ((PREF_BACK_COLOR_LIST[i].equals(PREF_EXEC)) || PREF_BACK_COLOR_LIST[i].equals(PREF_FRAME_NAME)) { |
83dcfe09 | 175 | color = new ColorImpl(Display.getDefault(), BACKGROUND_FRAME_RGB); |
eb63f5ff | 176 | } else if (PREF_BACK_COLOR_LIST[i].equals(PREF_LIFELINE)) { |
83dcfe09 | 177 | color = new ColorImpl(Display.getDefault(), BACKGROUND_LIFELINE_RGB); |
eb63f5ff | 178 | } else if (PREF_BACK_COLOR_LIST[i].equals(PREF_LIFELINE_HEADER)) { |
83dcfe09 | 179 | color = new ColorImpl(Display.getDefault(), BACKGROUND_LIFELINE_HEADER_RGB); |
df0b8ff4 | 180 | } else { |
83dcfe09 | 181 | color = new ColorImpl(Display.getDefault(), BACKGROUND_DEFAULT_RGB); |
df0b8ff4 | 182 | } |
eb63f5ff BH |
183 | PreferenceConverter.setDefault(fPrefStore, PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX, ((Color) color.getColor()).getRGB()); |
184 | PreferenceConverter.setDefault(fPrefStore, PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX + TEMP_TAG, ((Color) color.getColor()).getRGB()); | |
73005152 BH |
185 | color.dispose(); |
186 | } | |
187 | ||
eb63f5ff | 188 | for (int i = 0; i < PREF_FORE_COLOR_LIST.length; i++) { |
73005152 | 189 | IColor color; |
eb63f5ff | 190 | if (PREF_FORE_COLOR_LIST[i].equals(PREF_LIFELINE)) { |
83dcfe09 | 191 | color = new ColorImpl(Display.getDefault(), FOREGROUND_LIFELINE_RGB); |
eb63f5ff | 192 | } else if (PREF_FORE_COLOR_LIST[i].equals(PREF_FRAME_NAME)) { |
83dcfe09 | 193 | color = new ColorImpl(Display.getDefault(), FOREGROUND_FRAME_RGB); |
eb63f5ff | 194 | } else if (PREF_FORE_COLOR_LIST[i].equals(PREF_LIFELINE_HEADER)) { |
83dcfe09 | 195 | color = new ColorImpl(Display.getDefault(), FOREGROUND_LIFELINE_HEADER_RGB); |
df0b8ff4 | 196 | } else { |
83dcfe09 | 197 | color = new ColorImpl(Display.getDefault(), FOREGROUND_RGB); |
df0b8ff4 | 198 | } |
eb63f5ff BH |
199 | PreferenceConverter.setDefault(fPrefStore, PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX, ((Color) color.getColor()).getRGB()); |
200 | PreferenceConverter.setDefault(fPrefStore, PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX + TEMP_TAG, ((Color) color.getColor()).getRGB()); | |
73005152 BH |
201 | color.dispose(); |
202 | } | |
203 | ||
eb63f5ff | 204 | for (int i = 0; i < PREF_TEXT_COLOR_LIST.length; i++) { |
73005152 | 205 | IColor color; |
eb63f5ff | 206 | if (PREF_TEXT_COLOR_LIST[i].equals(PREF_LIFELINE)) { |
83dcfe09 | 207 | color = new ColorImpl(Display.getDefault(), DEFAULT_LIFELINE_RGB); |
eb63f5ff | 208 | } else if (PREF_TEXT_COLOR_LIST[i].equals(PREF_FRAME_NAME)) { |
83dcfe09 | 209 | color = new ColorImpl(Display.getDefault(), DEFAULT_FRAME_RGB); |
eb63f5ff | 210 | } else if (PREF_TEXT_COLOR_LIST[i].equals(PREF_LIFELINE_HEADER)) { |
83dcfe09 | 211 | color = new ColorImpl(Display.getDefault(), DEFAULT_LIFELINE_HEADER_RGB); |
df0b8ff4 | 212 | } else { |
83dcfe09 | 213 | color = new ColorImpl(Display.getDefault(), DEFAULT_RGB); |
df0b8ff4 | 214 | } |
eb63f5ff BH |
215 | PreferenceConverter.setDefault(fPrefStore, PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX, ((Color) color.getColor()).getRGB()); |
216 | PreferenceConverter.setDefault(fPrefStore, PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX + TEMP_TAG, ((Color) color.getColor()).getRGB()); | |
73005152 BH |
217 | color.dispose(); |
218 | } | |
219 | ||
83dcfe09 | 220 | IColor color = new ColorImpl(Display.getDefault(), DEFAULT_TIME_COMP_RGB); |
eb63f5ff | 221 | PreferenceConverter.setDefault(fPrefStore, PREF_TIME_COMP, ((Color) color.getColor()).getRGB()); |
73005152 BH |
222 | color.dispose(); |
223 | ||
224 | buildFontsAndColors(); | |
225 | ||
eb63f5ff | 226 | fPrefStore.addPropertyChangeListener(this); |
73005152 BH |
227 | } |
228 | ||
229 | /** | |
230 | * Returns the PreferenceStore | |
a55887ca | 231 | * |
73005152 BH |
232 | * @return the PreferenceStore |
233 | */ | |
234 | public IPreferenceStore getPreferenceStore() { | |
eb63f5ff | 235 | return fPrefStore; |
73005152 BH |
236 | } |
237 | ||
238 | /** | |
239 | * Apply the preferences in the preferences handler | |
240 | */ | |
241 | public void apply() { | |
242 | buildFontsAndColors(); | |
eb63f5ff | 243 | fPrefStore.firePropertyChangeEvent("PREFOK", null, null); //$NON-NLS-1$ |
73005152 BH |
244 | } |
245 | ||
246 | /** | |
247 | * Returns an unique instance of the Sequence Diagram preference handler | |
a55887ca | 248 | * |
73005152 BH |
249 | * @return the preference handler instance |
250 | */ | |
df0b8ff4 | 251 | public static synchronized SDViewPref getInstance() { |
eb63f5ff BH |
252 | if (fHandle == null) { |
253 | fHandle = new SDViewPref(); | |
df0b8ff4 | 254 | } |
eb63f5ff | 255 | return fHandle; |
73005152 BH |
256 | } |
257 | ||
73005152 BH |
258 | @Override |
259 | public IColor getForeGroundColor(String prefName) { | |
eb63f5ff | 260 | if ((fForeColorPref.get(prefName + FORE_COLOR_POSTFIX) != null) && (fForeColorPref.get(prefName + FORE_COLOR_POSTFIX) instanceof ColorImpl)) { |
abbdd66a | 261 | return fForeColorPref.get(prefName + FORE_COLOR_POSTFIX); |
df0b8ff4 BH |
262 | } |
263 | return ColorImpl.getSystemColor(SWT.COLOR_BLACK); | |
73005152 BH |
264 | } |
265 | ||
73005152 BH |
266 | @Override |
267 | public IColor getBackGroundColor(String prefName) { | |
eb63f5ff | 268 | if ((fBackColorPref.get(prefName + BACK_COLOR_POSTFIX) != null) && (fBackColorPref.get(prefName + BACK_COLOR_POSTFIX) instanceof ColorImpl)) { |
abbdd66a | 269 | return fBackColorPref.get(prefName + BACK_COLOR_POSTFIX); |
df0b8ff4 BH |
270 | } |
271 | return ColorImpl.getSystemColor(SWT.COLOR_WHITE); | |
73005152 BH |
272 | } |
273 | ||
73005152 BH |
274 | @Override |
275 | public IColor getFontColor(String prefName) { | |
eb63f5ff | 276 | if ((fTextColorPref.get(prefName + TEXT_COLOR_POSTFIX) != null) && (fTextColorPref.get(prefName + TEXT_COLOR_POSTFIX) instanceof ColorImpl)) { |
abbdd66a | 277 | return fTextColorPref.get(prefName + TEXT_COLOR_POSTFIX); |
df0b8ff4 BH |
278 | } |
279 | return ColorImpl.getSystemColor(SWT.COLOR_BLACK); | |
73005152 BH |
280 | } |
281 | ||
73005152 BH |
282 | @Override |
283 | public IColor getForeGroundColorSelection() { | |
eb63f5ff | 284 | if (fNoFocusSelection) { |
73005152 | 285 | return ColorImpl.getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND); |
df0b8ff4 | 286 | } |
73005152 BH |
287 | return ColorImpl.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); |
288 | } | |
289 | ||
73005152 BH |
290 | @Override |
291 | public IColor getBackGroundColorSelection() { | |
eb63f5ff | 292 | if (fNoFocusSelection) { |
73005152 | 293 | return ColorImpl.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); |
df0b8ff4 | 294 | } |
73005152 BH |
295 | return ColorImpl.getSystemColor(SWT.COLOR_LIST_SELECTION); |
296 | } | |
297 | ||
73005152 BH |
298 | @Override |
299 | public IFont getFont(String prefName) { | |
abbdd66a AM |
300 | if (fFontPref.get(prefName) != null) { |
301 | return fFontPref.get(prefName); | |
df0b8ff4 BH |
302 | } |
303 | return FontImpl.getSystemFont(); | |
73005152 BH |
304 | } |
305 | ||
306 | /** | |
307 | * Returns the SwimLane width chosen | |
a55887ca | 308 | * |
73005152 BH |
309 | * @return the SwimLane width |
310 | */ | |
311 | public int getLifelineWidth() { | |
eb63f5ff | 312 | return fPrefStore.getInt(PREF_LIFELINE_WIDTH); |
73005152 BH |
313 | } |
314 | ||
315 | /** | |
316 | * Returns if font linkage with zoom has been chosen | |
a55887ca | 317 | * |
73005152 BH |
318 | * @return true if checked false otherwise |
319 | */ | |
320 | public boolean fontLinked() { | |
eb63f5ff | 321 | return fPrefStore.getBoolean(PREF_LINK_FONT); |
73005152 BH |
322 | } |
323 | ||
324 | /** | |
325 | * Returns the tooltip enablement | |
a55887ca | 326 | * |
73005152 BH |
327 | * @return true if checked false otherwise |
328 | */ | |
329 | public boolean tooltipEnabled() { | |
eb63f5ff | 330 | return fPrefStore.getBoolean(PREF_TOOLTIP); |
73005152 BH |
331 | } |
332 | ||
333 | /** | |
83dcfe09 MK |
334 | * Return true if the user do not want to take external time (basically |
335 | * found and lost messages with time) into account in the min max | |
336 | * computation | |
a55887ca | 337 | * |
73005152 BH |
338 | * @return true if checked false otherwise |
339 | */ | |
340 | public boolean excludeExternalTime() { | |
eb63f5ff | 341 | return fPrefStore.getBoolean(PREF_EXCLUDE_EXTERNAL_TIME); |
73005152 BH |
342 | } |
343 | ||
73005152 BH |
344 | @Override |
345 | public boolean useGradienColor() { | |
eb63f5ff | 346 | return fPrefStore.getBoolean(PREF_USE_GRADIENT); |
73005152 BH |
347 | } |
348 | ||
73005152 BH |
349 | @Override |
350 | public IColor getTimeCompressionSelectionColor() { | |
eb63f5ff | 351 | return fTimeCompressionSelectionColor; |
73005152 BH |
352 | } |
353 | ||
354 | /** | |
83dcfe09 MK |
355 | * Builds the new colors and fonts according the current user selection when |
356 | * the OK or Apply button is clicked | |
73005152 | 357 | */ |
eb63f5ff | 358 | private void buildFontsAndColors() { |
73005152 BH |
359 | |
360 | Display display = Display.getDefault(); | |
361 | ||
eb63f5ff BH |
362 | for (int i = 0; i < FONT_LIST.length; i++) { |
363 | FontData fontData = PreferenceConverter.getFontData(fPrefStore, FONT_LIST[i]); | |
abbdd66a AM |
364 | if (fFontPref.get(FONT_LIST[i]) != null) { |
365 | fFontPref.get(FONT_LIST[i]).dispose(); | |
df0b8ff4 | 366 | } |
eb63f5ff | 367 | fFontPref.put(FONT_LIST[i], new FontImpl(display, fontData)); |
73005152 BH |
368 | } |
369 | ||
eb63f5ff BH |
370 | for (int i = 0; i < PREF_BACK_COLOR_LIST.length; i++) { |
371 | RGB rgb = PreferenceConverter.getColor(fPrefStore, PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX); | |
abbdd66a AM |
372 | if (fBackColorPref.get(PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX) != null) { |
373 | fBackColorPref.get(PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX).dispose(); | |
df0b8ff4 | 374 | } |
eb63f5ff | 375 | fBackColorPref.put(PREF_BACK_COLOR_LIST[i] + BACK_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue)); |
73005152 BH |
376 | } |
377 | ||
eb63f5ff BH |
378 | for (int i = 0; i < PREF_FORE_COLOR_LIST.length; i++) { |
379 | RGB rgb = PreferenceConverter.getColor(fPrefStore, PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX); | |
abbdd66a AM |
380 | if (fForeColorPref.get(PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX) != null) { |
381 | fForeColorPref.get(PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX).dispose(); | |
df0b8ff4 | 382 | } |
eb63f5ff | 383 | fForeColorPref.put(PREF_FORE_COLOR_LIST[i] + FORE_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue)); |
73005152 BH |
384 | } |
385 | ||
eb63f5ff BH |
386 | for (int i = 0; i < PREF_TEXT_COLOR_LIST.length; i++) { |
387 | RGB rgb = PreferenceConverter.getColor(fPrefStore, PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX); | |
abbdd66a AM |
388 | if (fTextColorPref.get(PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX) != null) { |
389 | fTextColorPref.get(PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX).dispose(); | |
df0b8ff4 | 390 | } |
eb63f5ff | 391 | fTextColorPref.put(PREF_TEXT_COLOR_LIST[i] + TEXT_COLOR_POSTFIX, new ColorImpl(display, rgb.red, rgb.green, rgb.blue)); |
73005152 BH |
392 | } |
393 | ||
eb63f5ff BH |
394 | RGB rgb = PreferenceConverter.getColor(fPrefStore, PREF_TIME_COMP); |
395 | if (fTimeCompressionSelectionColor != null) { | |
396 | fTimeCompressionSelectionColor.dispose(); | |
df0b8ff4 | 397 | } |
eb63f5ff | 398 | fTimeCompressionSelectionColor = new ColorImpl(display, rgb.red, rgb.green, rgb.blue); |
73005152 BH |
399 | } |
400 | ||
a55887ca AM |
401 | /** |
402 | * Add a property-change listener | |
403 | * | |
404 | * @param listener | |
405 | * The listener to add | |
406 | */ | |
73005152 | 407 | public void addPropertyChangeListener(IPropertyChangeListener listener) { |
eb63f5ff | 408 | fPrefStore.addPropertyChangeListener(listener); |
73005152 BH |
409 | } |
410 | ||
a55887ca AM |
411 | /** |
412 | * Remove a property-change listener | |
413 | * | |
414 | * @param listener | |
415 | * The listerner to remove | |
416 | */ | |
73005152 | 417 | public void removePropertyChangeListener(IPropertyChangeListener listener) { |
eb63f5ff | 418 | fPrefStore.removePropertyChangeListener(listener); |
73005152 BH |
419 | } |
420 | ||
73005152 BH |
421 | @Override |
422 | public void propertyChange(PropertyChangeEvent event) { | |
df0b8ff4 | 423 | if (!event.getProperty().equals("PREFOK")) { //$NON-NLS-1$ |
73005152 | 424 | buildFontsAndColors(); |
a55887ca | 425 | fPrefStore.firePropertyChangeEvent("PREFOK", null, null); //$NON-NLS-1$ |
73005152 BH |
426 | } |
427 | } | |
428 | ||
a55887ca AM |
429 | /** |
430 | * Set the "no focus selection" preference | |
431 | * | |
432 | * @param v | |
433 | * New value to use | |
434 | */ | |
73005152 | 435 | public void setNoFocusSelection(boolean v) { |
eb63f5ff | 436 | fNoFocusSelection = v; |
73005152 | 437 | } |
e6ace8bb | 438 | |
cab6c8ff BH |
439 | /** |
440 | * Returns a unmodifiable map with font preferences. | |
441 | * | |
442 | * @return map with font preferences | |
cab6c8ff BH |
443 | */ |
444 | protected Map<String, IFont> getFontPref() { | |
445 | return Collections.unmodifiableMap(fFontPref); | |
446 | } | |
447 | ||
448 | /** | |
449 | * Returns a unmodifiable map with foreground color preferences | |
450 | * | |
451 | * @return map with foreground color preferences | |
cab6c8ff BH |
452 | */ |
453 | public Map<String, IColor> getForeColorPref() { | |
454 | return Collections.unmodifiableMap(fForeColorPref); | |
455 | } | |
456 | ||
457 | /** | |
458 | * Returns a unmodifiable map with background color preferences | |
459 | * | |
460 | * @return map with background color preferences | |
cab6c8ff BH |
461 | */ |
462 | public Map<String, IColor> getBackColorPref() { | |
463 | return Collections.unmodifiableMap(fBackColorPref); | |
464 | } | |
465 | ||
466 | /** | |
467 | * Returns a unmodifiable map with text color preferences | |
468 | * | |
469 | * @return map with text color preferences | |
cab6c8ff BH |
470 | */ |
471 | public Map<String, IColor> getTextColorPref() { | |
472 | return Collections.unmodifiableMap(fTextColorPref); | |
473 | } | |
474 | ||
475 | /** | |
476 | * Returns the preference store. | |
477 | * | |
478 | * @return the preference store | |
cab6c8ff BH |
479 | */ |
480 | public IPreferenceStore getPrefStore() { | |
481 | return fPrefStore; | |
482 | } | |
483 | ||
484 | /** | |
485 | * Returns flag about focus selection | |
486 | * | |
487 | * @return flag about focus selection | |
cab6c8ff BH |
488 | */ |
489 | public boolean isNoFocusSelection() { | |
490 | return fNoFocusSelection; | |
491 | } | |
492 | ||
e6ace8bb | 493 | /** |
df0b8ff4 | 494 | * Returns the static font list. |
a55887ca | 495 | * |
e6ace8bb BH |
496 | * @return static font list |
497 | */ | |
498 | public static String[] getFontList() { | |
eb63f5ff | 499 | return Arrays.copyOf(FONT_LIST, FONT_LIST.length); |
e6ace8bb | 500 | } |
a55887ca | 501 | |
e6ace8bb | 502 | /** |
df0b8ff4 | 503 | * Returns the 2nd static font list. |
a55887ca | 504 | * |
e6ace8bb BH |
505 | * @return 2nd static font list |
506 | */ | |
507 | public static String[] getFontList2() { | |
eb63f5ff | 508 | return Arrays.copyOf(FONT_LIST2, FONT_LIST2.length); |
e6ace8bb | 509 | } |
a55887ca | 510 | |
e6ace8bb | 511 | /** |
df0b8ff4 | 512 | * Returns the preference background color list. |
a55887ca | 513 | * |
e6ace8bb BH |
514 | * @return preference background color list |
515 | */ | |
516 | public static String[] getPrefBackColorList() { | |
eb63f5ff | 517 | return Arrays.copyOf(PREF_BACK_COLOR_LIST, PREF_BACK_COLOR_LIST.length); |
e6ace8bb | 518 | } |
a55887ca | 519 | |
e6ace8bb | 520 | /** |
df0b8ff4 | 521 | * Returns the preference foreground color list. |
a55887ca | 522 | * |
e6ace8bb BH |
523 | * @return preference foreground color list |
524 | */ | |
525 | public static String[] getPrefForeColorList() { | |
eb63f5ff | 526 | return Arrays.copyOf(PREF_FORE_COLOR_LIST, PREF_FORE_COLOR_LIST.length); |
e6ace8bb | 527 | } |
a55887ca | 528 | |
e6ace8bb | 529 | /** |
df0b8ff4 | 530 | * Returns the preference text color list color list. |
a55887ca | 531 | * |
e6ace8bb BH |
532 | * @return preference text color list color list |
533 | */ | |
534 | public static String[] getPrefTextColorList() { | |
eb63f5ff | 535 | return Arrays.copyOf(PREF_TEXT_COLOR_LIST, PREF_TEXT_COLOR_LIST.length); |
e6ace8bb | 536 | } |
73005152 | 537 | } |