1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
;
16 import java
.util
.Arrays
;
17 import java
.util
.Hashtable
;
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
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IFont
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.impl
.ColorImpl
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.impl
.FontImpl
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
30 import org
.eclipse
.swt
.SWT
;
31 import org
.eclipse
.swt
.graphics
.Color
;
32 import org
.eclipse
.swt
.graphics
.FontData
;
33 import org
.eclipse
.swt
.graphics
.RGB
;
34 import org
.eclipse
.swt
.widgets
.Display
;
37 * This is the Sequence Diagram preference handler. This class is responsible for accessing the current user preferences
38 * selection This class also provider getters for each modifiable preferences.
43 public class SDViewPref
implements ISDPreferences
, IPropertyChangeListener
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 * Postfix string for background color property
51 public static final String BACK_COLOR_POSTFIX
= "_BACK_COLOR";//$NON-NLS-1$
53 * Postfix string for foreground color property
55 public static final String FORE_COLOR_POSTFIX
= "_FORE_COLOR";//$NON-NLS-1$
57 * Postfix string for text color property
59 public static final String TEXT_COLOR_POSTFIX
= "_TEXT_COLOR";//$NON-NLS-1$
61 * Array of preference names
63 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
};
65 * A 2nd array of preference names
67 private static final String
[] FONT_LIST2
= { SDMessages
._88
, SDMessages
._89
, SDMessages
._90
, SDMessages
._91
, SDMessages
._92
, SDMessages
._93
, SDMessages
._94
, SDMessages
._95
, SDMessages
._96
};
69 * Array of background color preference names
71 private static final String
[] PREF_BACK_COLOR_LIST
= { PREF_LIFELINE
, PREF_EXEC
, PREF_FRAME
, PREF_LIFELINE_HEADER
, PREF_FRAME_NAME
};
73 * Array of foreground color preference names
75 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
};
77 * Array of text color preference names
79 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
};
83 protected static final String TEMP_TAG
= "_TEMP";//$NON-NLS-1$
85 // ------------------------------------------------------------------------
87 // ------------------------------------------------------------------------
90 * The sequence diagram preferences singleton instance
92 private static SDViewPref fHandle
= null;
94 * Hashtable for font preferences
96 protected Map
<String
, IFont
> fFontPref
;
98 * Hashtable for foreground color preferences
100 protected Map
<String
, IColor
> fForeColorPref
;
102 * Hashtable for background color preferences
104 protected Map
<String
, IColor
> fBackColorPref
;
106 * Hashtable for text color preferences
108 protected Map
<String
, IColor
> fTextColorPref
;
110 * The reference to the preference store.
112 protected IPreferenceStore fPrefStore
= null;
114 * Color for the time compression selection
116 protected IColor fTimeCompressionSelectionColor
= null;
118 * Flag whether no focus selection or not.
120 protected boolean fNoFocusSelection
= false;
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
127 * Builds the Sequence Diagram preference handler: - Define the preference default values. - Load the currently used
128 * preferences setting
130 protected SDViewPref() {
131 fPrefStore
= Activator
.getDefault().getPreferenceStore();
133 fPrefStore
.setDefault(PREF_LINK_FONT
, true);
134 fPrefStore
.setDefault(PREF_EXCLUDE_EXTERNAL_TIME
, true);
135 fPrefStore
.setDefault(PREF_LIFELINE_WIDTH
, 200);
136 fPrefStore
.setDefault(PREF_USE_GRADIENT
, true);
137 fPrefStore
.setDefault(PREF_TOOLTIP
, true);
139 fFontPref
= new Hashtable
<String
, IFont
>();
140 fForeColorPref
= new Hashtable
<String
, IColor
>();
141 fBackColorPref
= new Hashtable
<String
, IColor
>();
142 fTextColorPref
= new Hashtable
<String
, IColor
>();
144 for (int i
= 0; i
< FONT_LIST
.length
; i
++) {
145 if (FONT_LIST
[i
].equals(PREF_FRAME_NAME
)) {
146 FontData
[] data
= Display
.getDefault().getSystemFont().getFontData();
147 data
[0].setStyle(SWT
.BOLD
);
148 PreferenceConverter
.setDefault(fPrefStore
, FONT_LIST
[i
], data
[0]);
149 PreferenceConverter
.setDefault(fPrefStore
, FONT_LIST
[i
] + TEMP_TAG
, data
[0]);
151 PreferenceConverter
.setDefault(fPrefStore
, FONT_LIST
[i
], Display
.getDefault().getSystemFont().getFontData());
152 PreferenceConverter
.setDefault(fPrefStore
, FONT_LIST
[i
] + TEMP_TAG
, Display
.getDefault().getSystemFont().getFontData());
156 for (int i
= 0; i
< PREF_BACK_COLOR_LIST
.length
; i
++) {
158 if ((PREF_BACK_COLOR_LIST
[i
].equals(PREF_EXEC
)) || PREF_BACK_COLOR_LIST
[i
].equals(PREF_FRAME_NAME
)) {
159 color
= new ColorImpl(Display
.getDefault(), 201, 222, 233);
160 } else if (PREF_BACK_COLOR_LIST
[i
].equals(PREF_LIFELINE
)) {
161 color
= new ColorImpl(Display
.getDefault(), 220, 220, 220);
162 } else if (PREF_BACK_COLOR_LIST
[i
].equals(PREF_LIFELINE_HEADER
)) {
163 color
= new ColorImpl(Display
.getDefault(), 245, 244, 244);
165 color
= new ColorImpl(Display
.getDefault(), 255, 255, 255);
167 PreferenceConverter
.setDefault(fPrefStore
, PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
, ((Color
) color
.getColor()).getRGB());
168 PreferenceConverter
.setDefault(fPrefStore
, PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
+ TEMP_TAG
, ((Color
) color
.getColor()).getRGB());
172 for (int i
= 0; i
< PREF_FORE_COLOR_LIST
.length
; i
++) {
174 if (PREF_FORE_COLOR_LIST
[i
].equals(PREF_LIFELINE
)) {
175 color
= new ColorImpl(Display
.getDefault(), 129, 129, 129);
176 } else if (PREF_FORE_COLOR_LIST
[i
].equals(PREF_FRAME_NAME
)) {
177 color
= new ColorImpl(Display
.getDefault(), 81, 153, 200);
178 } else if (PREF_FORE_COLOR_LIST
[i
].equals(PREF_LIFELINE_HEADER
)) {
179 color
= new ColorImpl(Display
.getDefault(), 129, 127, 137);
181 color
= new ColorImpl(Display
.getDefault(), 134, 176, 212);
183 PreferenceConverter
.setDefault(fPrefStore
, PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
, ((Color
) color
.getColor()).getRGB());
184 PreferenceConverter
.setDefault(fPrefStore
, PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
+ TEMP_TAG
, ((Color
) color
.getColor()).getRGB());
188 for (int i
= 0; i
< PREF_TEXT_COLOR_LIST
.length
; i
++) {
190 if (PREF_TEXT_COLOR_LIST
[i
].equals(PREF_LIFELINE
)) {
191 color
= new ColorImpl(Display
.getDefault(), 129, 129, 129);
192 } else if (PREF_TEXT_COLOR_LIST
[i
].equals(PREF_FRAME_NAME
)) {
193 color
= new ColorImpl(Display
.getDefault(), 0, 0, 0);
194 } else if (PREF_TEXT_COLOR_LIST
[i
].equals(PREF_LIFELINE_HEADER
)) {
195 color
= new ColorImpl(Display
.getDefault(), 129, 127, 137);
197 color
= new ColorImpl(Display
.getDefault(), 134, 176, 212);
199 PreferenceConverter
.setDefault(fPrefStore
, PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
, ((Color
) color
.getColor()).getRGB());
200 PreferenceConverter
.setDefault(fPrefStore
, PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
+ TEMP_TAG
, ((Color
) color
.getColor()).getRGB());
204 IColor color
= new ColorImpl(Display
.getDefault(), 218, 232, 238);
205 PreferenceConverter
.setDefault(fPrefStore
, PREF_TIME_COMP
, ((Color
) color
.getColor()).getRGB());
208 buildFontsAndColors();
210 fPrefStore
.addPropertyChangeListener(this);
214 * Returns the PreferenceStore
216 * @return the PreferenceStore
218 public IPreferenceStore
getPreferenceStore() {
223 * Apply the preferences in the preferences handler
225 public void apply() {
226 buildFontsAndColors();
227 fPrefStore
.firePropertyChangeEvent("PREFOK", null, null); //$NON-NLS-1$
231 * Returns an unique instance of the Sequence Diagram preference handler
233 * @return the preference handler instance
235 public static synchronized SDViewPref
getInstance() {
236 if (fHandle
== null) {
237 fHandle
= new SDViewPref();
244 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getForeGroundColor(java.lang.String)
247 public IColor
getForeGroundColor(String prefName
) {
248 if ((fForeColorPref
.get(prefName
+ FORE_COLOR_POSTFIX
) != null) && (fForeColorPref
.get(prefName
+ FORE_COLOR_POSTFIX
) instanceof ColorImpl
)) {
249 return fForeColorPref
.get(prefName
+ FORE_COLOR_POSTFIX
);
251 return ColorImpl
.getSystemColor(SWT
.COLOR_BLACK
);
256 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getBackGroundColor(java.lang.String)
259 public IColor
getBackGroundColor(String prefName
) {
260 if ((fBackColorPref
.get(prefName
+ BACK_COLOR_POSTFIX
) != null) && (fBackColorPref
.get(prefName
+ BACK_COLOR_POSTFIX
) instanceof ColorImpl
)) {
261 return fBackColorPref
.get(prefName
+ BACK_COLOR_POSTFIX
);
263 return ColorImpl
.getSystemColor(SWT
.COLOR_WHITE
);
268 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getFontColor(java.lang.String)
271 public IColor
getFontColor(String prefName
) {
272 if ((fTextColorPref
.get(prefName
+ TEXT_COLOR_POSTFIX
) != null) && (fTextColorPref
.get(prefName
+ TEXT_COLOR_POSTFIX
) instanceof ColorImpl
)) {
273 return fTextColorPref
.get(prefName
+ TEXT_COLOR_POSTFIX
);
275 return ColorImpl
.getSystemColor(SWT
.COLOR_BLACK
);
280 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getForeGroundColorSelection()
283 public IColor
getForeGroundColorSelection() {
284 if (fNoFocusSelection
) {
285 return ColorImpl
.getSystemColor(SWT
.COLOR_TITLE_INACTIVE_FOREGROUND
);
287 return ColorImpl
.getSystemColor(SWT
.COLOR_LIST_SELECTION_TEXT
);
292 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getBackGroundColorSelection()
295 public IColor
getBackGroundColorSelection() {
296 if (fNoFocusSelection
) {
297 return ColorImpl
.getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
299 return ColorImpl
.getSystemColor(SWT
.COLOR_LIST_SELECTION
);
304 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getFont(java.lang.String)
307 public IFont
getFont(String prefName
) {
308 if (fFontPref
.get(prefName
) != null) {
309 return fFontPref
.get(prefName
);
311 return FontImpl
.getSystemFont();
315 * Returns the SwimLane width chosen
317 * @return the SwimLane width
319 public int getLifelineWidth() {
320 return fPrefStore
.getInt(PREF_LIFELINE_WIDTH
);
324 * Returns if font linkage with zoom has been chosen
326 * @return true if checked false otherwise
328 public boolean fontLinked() {
329 return fPrefStore
.getBoolean(PREF_LINK_FONT
);
333 * Returns the tooltip enablement
335 * @return true if checked false otherwise
337 public boolean tooltipEnabled() {
338 return fPrefStore
.getBoolean(PREF_TOOLTIP
);
342 * Return true if the user do not want to take external time (basically found and lost messages with time) into
343 * account in the min max computation
345 * @return true if checked false otherwise
347 public boolean excludeExternalTime() {
348 return fPrefStore
.getBoolean(PREF_EXCLUDE_EXTERNAL_TIME
);
353 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#useGradienColor()
356 public boolean useGradienColor() {
357 return fPrefStore
.getBoolean(PREF_USE_GRADIENT
);
362 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getTimeCompressionSelectionColor()
365 public IColor
getTimeCompressionSelectionColor() {
366 return fTimeCompressionSelectionColor
;
370 * Builds the new colors and fonts according the current user selection when the OK or Apply button is clicked
372 private void buildFontsAndColors() {
374 Display display
= Display
.getDefault();
376 for (int i
= 0; i
< FONT_LIST
.length
; i
++) {
377 FontData fontData
= PreferenceConverter
.getFontData(fPrefStore
, FONT_LIST
[i
]);
378 if (fFontPref
.get(FONT_LIST
[i
]) != null) {
379 fFontPref
.get(FONT_LIST
[i
]).dispose();
381 fFontPref
.put(FONT_LIST
[i
], new FontImpl(display
, fontData
));
384 for (int i
= 0; i
< PREF_BACK_COLOR_LIST
.length
; i
++) {
385 RGB rgb
= PreferenceConverter
.getColor(fPrefStore
, PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
);
386 if (fBackColorPref
.get(PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
) != null) {
387 fBackColorPref
.get(PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
).dispose();
389 fBackColorPref
.put(PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
, new ColorImpl(display
, rgb
.red
, rgb
.green
, rgb
.blue
));
392 for (int i
= 0; i
< PREF_FORE_COLOR_LIST
.length
; i
++) {
393 RGB rgb
= PreferenceConverter
.getColor(fPrefStore
, PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
);
394 if (fForeColorPref
.get(PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
) != null) {
395 fForeColorPref
.get(PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
).dispose();
397 fForeColorPref
.put(PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
, new ColorImpl(display
, rgb
.red
, rgb
.green
, rgb
.blue
));
400 for (int i
= 0; i
< PREF_TEXT_COLOR_LIST
.length
; i
++) {
401 RGB rgb
= PreferenceConverter
.getColor(fPrefStore
, PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
);
402 if (fTextColorPref
.get(PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
) != null) {
403 fTextColorPref
.get(PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
).dispose();
405 fTextColorPref
.put(PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
, new ColorImpl(display
, rgb
.red
, rgb
.green
, rgb
.blue
));
408 RGB rgb
= PreferenceConverter
.getColor(fPrefStore
, PREF_TIME_COMP
);
409 if (fTimeCompressionSelectionColor
!= null) {
410 fTimeCompressionSelectionColor
.dispose();
412 fTimeCompressionSelectionColor
= new ColorImpl(display
, rgb
.red
, rgb
.green
, rgb
.blue
);
416 * Add a property-change listener
419 * The listener to add
421 public void addPropertyChangeListener(IPropertyChangeListener listener
) {
422 fPrefStore
.addPropertyChangeListener(listener
);
426 * Remove a property-change listener
429 * The listerner to remove
431 public void removePropertyChangeListener(IPropertyChangeListener listener
) {
432 fPrefStore
.removePropertyChangeListener(listener
);
437 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
440 public void propertyChange(PropertyChangeEvent event
) {
441 if (!event
.getProperty().equals("PREFOK")) { //$NON-NLS-1$
442 buildFontsAndColors();
443 fPrefStore
.firePropertyChangeEvent("PREFOK", null, null); //$NON-NLS-1$
448 * Set the "no focus selection" preference
453 public void setNoFocusSelection(boolean v
) {
454 fNoFocusSelection
= v
;
458 * Returns the static font list.
460 * @return static font list
462 public static String
[] getFontList() {
463 return Arrays
.copyOf(FONT_LIST
, FONT_LIST
.length
);
467 * Returns the 2nd static font list.
469 * @return 2nd static font list
471 public static String
[] getFontList2() {
472 return Arrays
.copyOf(FONT_LIST2
, FONT_LIST2
.length
);
476 * Returns the preference background color list.
478 * @return preference background color list
480 public static String
[] getPrefBackColorList() {
481 return Arrays
.copyOf(PREF_BACK_COLOR_LIST
, PREF_BACK_COLOR_LIST
.length
);
485 * Returns the preference foreground color list.
487 * @return preference foreground color list
489 public static String
[] getPrefForeColorList() {
490 return Arrays
.copyOf(PREF_FORE_COLOR_LIST
, PREF_FORE_COLOR_LIST
.length
);
494 * Returns the preference text color list color list.
496 * @return preference text color list color list
498 public static String
[] getPrefTextColorList() {
499 return Arrays
.copyOf(PREF_TEXT_COLOR_LIST
, PREF_TEXT_COLOR_LIST
.length
);