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