1 /**********************************************************************
2 * Copyright (c) 2005, 2012 IBM Corporation, Ericsson
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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
;
15 import java
.util
.Arrays
;
16 import java
.util
.Hashtable
;
19 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
20 import org
.eclipse
.jface
.preference
.PreferenceConverter
;
21 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
22 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
23 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IFont
;
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
;
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.
42 public class SDViewPref
implements ISDPreferences
, IPropertyChangeListener
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * Postfix string for background color property
50 public static final String BACK_COLOR_POSTFIX
= "_BACK_COLOR";//$NON-NLS-1$
52 * Postfix string for foreground color property
54 public static final String FORE_COLOR_POSTFIX
= "_FORE_COLOR";//$NON-NLS-1$
56 * Postfix string for text color property
58 public static final String TEXT_COLOR_POSTFIX
= "_TEXT_COLOR";//$NON-NLS-1$
60 * Array of preference names
62 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
};
64 * A 2nd array of preference names
66 private static final String
[] FONT_LIST2
= { SDMessages
._88
, SDMessages
._89
, SDMessages
._90
, SDMessages
._91
, SDMessages
._92
, SDMessages
._93
, SDMessages
._94
, SDMessages
._95
, SDMessages
._96
};
68 * Array of background color preference names
70 private static final String
[] PREF_BACK_COLOR_LIST
= { PREF_LIFELINE
, PREF_EXEC
, PREF_FRAME
, PREF_LIFELINE_HEADER
, PREF_FRAME_NAME
};
72 * Array of foreground color preference names
74 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
};
76 * Array of text color preference names
78 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
};
82 protected static final String TEMP_TAG
= "_TEMP";//$NON-NLS-1$
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
89 * The sequence diagram preferences singleton instance
91 private static SDViewPref fHandle
= null;
93 * Hashtable for font preferences
95 protected Map
<String
, IFont
> fFontPref
;
97 * Hashtable for foreground color preferences
99 protected Map
<String
, IColor
> fForeColorPref
;
101 * Hashtable for background color preferences
103 protected Map
<String
, IColor
> fBackColorPref
;
105 * Hashtable for text color preferences
107 protected Map
<String
, IColor
> fTextColorPref
;
109 * The reference to the preference store.
111 protected IPreferenceStore fPrefStore
= null;
113 * Color for the time compression selection
115 protected IColor fTimeCompressionSelectionColor
= null;
117 * Flag whether no focus selection or not.
119 protected boolean fNoFocusSelection
= false;
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
126 * Builds the Sequence Diagram preference handler: - Define the preference default values. - Load the currently used
127 * preferences setting
129 protected SDViewPref() {
130 fPrefStore
= Activator
.getDefault().getPreferenceStore();
132 fPrefStore
.setDefault(PREF_LINK_FONT
, true);
133 fPrefStore
.setDefault(PREF_EXCLUDE_EXTERNAL_TIME
, true);
134 fPrefStore
.setDefault(PREF_LIFELINE_WIDTH
, 200);
135 fPrefStore
.setDefault(PREF_USE_GRADIENT
, true);
136 fPrefStore
.setDefault(PREF_TOOLTIP
, true);
138 fFontPref
= new Hashtable
<String
, IFont
>();
139 fForeColorPref
= new Hashtable
<String
, IColor
>();
140 fBackColorPref
= new Hashtable
<String
, IColor
>();
141 fTextColorPref
= new Hashtable
<String
, IColor
>();
143 for (int i
= 0; i
< FONT_LIST
.length
; i
++) {
144 if (FONT_LIST
[i
].equals(PREF_FRAME_NAME
)) {
145 FontData
[] data
= Display
.getDefault().getSystemFont().getFontData();
146 data
[0].setStyle(SWT
.BOLD
);
147 PreferenceConverter
.setDefault(fPrefStore
, FONT_LIST
[i
], data
[0]);
148 PreferenceConverter
.setDefault(fPrefStore
, FONT_LIST
[i
] + TEMP_TAG
, data
[0]);
150 PreferenceConverter
.setDefault(fPrefStore
, FONT_LIST
[i
], Display
.getDefault().getSystemFont().getFontData());
151 PreferenceConverter
.setDefault(fPrefStore
, FONT_LIST
[i
] + TEMP_TAG
, Display
.getDefault().getSystemFont().getFontData());
155 for (int i
= 0; i
< PREF_BACK_COLOR_LIST
.length
; i
++) {
157 if ((PREF_BACK_COLOR_LIST
[i
].equals(PREF_EXEC
)) || PREF_BACK_COLOR_LIST
[i
].equals(PREF_FRAME_NAME
)) {
158 color
= new ColorImpl(Display
.getDefault(), 201, 222, 233);
159 } else if (PREF_BACK_COLOR_LIST
[i
].equals(PREF_LIFELINE
)) {
160 color
= new ColorImpl(Display
.getDefault(), 220, 220, 220);
161 } else if (PREF_BACK_COLOR_LIST
[i
].equals(PREF_LIFELINE_HEADER
)) {
162 color
= new ColorImpl(Display
.getDefault(), 245, 244, 244);
164 color
= new ColorImpl(Display
.getDefault(), 255, 255, 255);
166 PreferenceConverter
.setDefault(fPrefStore
, PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
, ((Color
) color
.getColor()).getRGB());
167 PreferenceConverter
.setDefault(fPrefStore
, PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
+ TEMP_TAG
, ((Color
) color
.getColor()).getRGB());
171 for (int i
= 0; i
< PREF_FORE_COLOR_LIST
.length
; i
++) {
173 if (PREF_FORE_COLOR_LIST
[i
].equals(PREF_LIFELINE
)) {
174 color
= new ColorImpl(Display
.getDefault(), 129, 129, 129);
175 } else if (PREF_FORE_COLOR_LIST
[i
].equals(PREF_FRAME_NAME
)) {
176 color
= new ColorImpl(Display
.getDefault(), 81, 153, 200);
177 } else if (PREF_FORE_COLOR_LIST
[i
].equals(PREF_LIFELINE_HEADER
)) {
178 color
= new ColorImpl(Display
.getDefault(), 129, 127, 137);
180 color
= new ColorImpl(Display
.getDefault(), 134, 176, 212);
182 PreferenceConverter
.setDefault(fPrefStore
, PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
, ((Color
) color
.getColor()).getRGB());
183 PreferenceConverter
.setDefault(fPrefStore
, PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
+ TEMP_TAG
, ((Color
) color
.getColor()).getRGB());
187 for (int i
= 0; i
< PREF_TEXT_COLOR_LIST
.length
; i
++) {
189 if (PREF_TEXT_COLOR_LIST
[i
].equals(PREF_LIFELINE
)) {
190 color
= new ColorImpl(Display
.getDefault(), 129, 129, 129);
191 } else if (PREF_TEXT_COLOR_LIST
[i
].equals(PREF_FRAME_NAME
)) {
192 color
= new ColorImpl(Display
.getDefault(), 0, 0, 0);
193 } else if (PREF_TEXT_COLOR_LIST
[i
].equals(PREF_LIFELINE_HEADER
)) {
194 color
= new ColorImpl(Display
.getDefault(), 129, 127, 137);
196 color
= new ColorImpl(Display
.getDefault(), 134, 176, 212);
198 PreferenceConverter
.setDefault(fPrefStore
, PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
, ((Color
) color
.getColor()).getRGB());
199 PreferenceConverter
.setDefault(fPrefStore
, PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
+ TEMP_TAG
, ((Color
) color
.getColor()).getRGB());
203 IColor color
= new ColorImpl(Display
.getDefault(), 218, 232, 238);
204 PreferenceConverter
.setDefault(fPrefStore
, PREF_TIME_COMP
, ((Color
) color
.getColor()).getRGB());
207 buildFontsAndColors();
209 fPrefStore
.addPropertyChangeListener(this);
213 * Returns the PreferenceStore
215 * @return the PreferenceStore
217 public IPreferenceStore
getPreferenceStore() {
222 * Apply the preferences in the preferences handler
224 public void apply() {
225 buildFontsAndColors();
226 fPrefStore
.firePropertyChangeEvent("PREFOK", null, null); //$NON-NLS-1$
230 * Returns an unique instance of the Sequence Diagram preference handler
232 * @return the preference handler instance
234 public static synchronized SDViewPref
getInstance() {
235 if (fHandle
== null) {
236 fHandle
= new SDViewPref();
243 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getForeGroundColor(java.lang.String)
246 public IColor
getForeGroundColor(String prefName
) {
247 if ((fForeColorPref
.get(prefName
+ FORE_COLOR_POSTFIX
) != null) && (fForeColorPref
.get(prefName
+ FORE_COLOR_POSTFIX
) instanceof ColorImpl
)) {
248 return fForeColorPref
.get(prefName
+ FORE_COLOR_POSTFIX
);
250 return ColorImpl
.getSystemColor(SWT
.COLOR_BLACK
);
255 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getBackGroundColor(java.lang.String)
258 public IColor
getBackGroundColor(String prefName
) {
259 if ((fBackColorPref
.get(prefName
+ BACK_COLOR_POSTFIX
) != null) && (fBackColorPref
.get(prefName
+ BACK_COLOR_POSTFIX
) instanceof ColorImpl
)) {
260 return fBackColorPref
.get(prefName
+ BACK_COLOR_POSTFIX
);
262 return ColorImpl
.getSystemColor(SWT
.COLOR_WHITE
);
267 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getFontColor(java.lang.String)
270 public IColor
getFontColor(String prefName
) {
271 if ((fTextColorPref
.get(prefName
+ TEXT_COLOR_POSTFIX
) != null) && (fTextColorPref
.get(prefName
+ TEXT_COLOR_POSTFIX
) instanceof ColorImpl
)) {
272 return fTextColorPref
.get(prefName
+ TEXT_COLOR_POSTFIX
);
274 return ColorImpl
.getSystemColor(SWT
.COLOR_BLACK
);
279 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getForeGroundColorSelection()
282 public IColor
getForeGroundColorSelection() {
283 if (fNoFocusSelection
) {
284 return ColorImpl
.getSystemColor(SWT
.COLOR_TITLE_INACTIVE_FOREGROUND
);
286 return ColorImpl
.getSystemColor(SWT
.COLOR_LIST_SELECTION_TEXT
);
291 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getBackGroundColorSelection()
294 public IColor
getBackGroundColorSelection() {
295 if (fNoFocusSelection
) {
296 return ColorImpl
.getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
298 return ColorImpl
.getSystemColor(SWT
.COLOR_LIST_SELECTION
);
303 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getFont(java.lang.String)
306 public IFont
getFont(String prefName
) {
307 if (fFontPref
.get(prefName
) != null) {
308 return fFontPref
.get(prefName
);
310 return FontImpl
.getSystemFont();
314 * Returns the SwimLane width chosen
316 * @return the SwimLane width
318 public int getLifelineWidth() {
319 return fPrefStore
.getInt(PREF_LIFELINE_WIDTH
);
323 * Returns if font linkage with zoom has been chosen
325 * @return true if checked false otherwise
327 public boolean fontLinked() {
328 return fPrefStore
.getBoolean(PREF_LINK_FONT
);
332 * Returns the tooltip enablement
334 * @return true if checked false otherwise
336 public boolean tooltipEnabled() {
337 return fPrefStore
.getBoolean(PREF_TOOLTIP
);
341 * Return true if the user do not want to take external time (basically found and lost messages with time) into
342 * account in the min max computation
344 * @return true if checked false otherwise
346 public boolean excludeExternalTime() {
347 return fPrefStore
.getBoolean(PREF_EXCLUDE_EXTERNAL_TIME
);
352 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#useGradienColor()
355 public boolean useGradienColor() {
356 return fPrefStore
.getBoolean(PREF_USE_GRADIENT
);
361 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences#getTimeCompressionSelectionColor()
364 public IColor
getTimeCompressionSelectionColor() {
365 return fTimeCompressionSelectionColor
;
369 * Builds the new colors and fonts according the current user selection when the OK or Apply button is clicked
371 private void buildFontsAndColors() {
373 Display display
= Display
.getDefault();
375 for (int i
= 0; i
< FONT_LIST
.length
; i
++) {
376 FontData fontData
= PreferenceConverter
.getFontData(fPrefStore
, FONT_LIST
[i
]);
377 if (fFontPref
.get(FONT_LIST
[i
]) != null) {
378 fFontPref
.get(FONT_LIST
[i
]).dispose();
380 fFontPref
.put(FONT_LIST
[i
], new FontImpl(display
, fontData
));
383 for (int i
= 0; i
< PREF_BACK_COLOR_LIST
.length
; i
++) {
384 RGB rgb
= PreferenceConverter
.getColor(fPrefStore
, PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
);
385 if (fBackColorPref
.get(PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
) != null) {
386 fBackColorPref
.get(PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
).dispose();
388 fBackColorPref
.put(PREF_BACK_COLOR_LIST
[i
] + BACK_COLOR_POSTFIX
, new ColorImpl(display
, rgb
.red
, rgb
.green
, rgb
.blue
));
391 for (int i
= 0; i
< PREF_FORE_COLOR_LIST
.length
; i
++) {
392 RGB rgb
= PreferenceConverter
.getColor(fPrefStore
, PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
);
393 if (fForeColorPref
.get(PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
) != null) {
394 fForeColorPref
.get(PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
).dispose();
396 fForeColorPref
.put(PREF_FORE_COLOR_LIST
[i
] + FORE_COLOR_POSTFIX
, new ColorImpl(display
, rgb
.red
, rgb
.green
, rgb
.blue
));
399 for (int i
= 0; i
< PREF_TEXT_COLOR_LIST
.length
; i
++) {
400 RGB rgb
= PreferenceConverter
.getColor(fPrefStore
, PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
);
401 if (fTextColorPref
.get(PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
) != null) {
402 fTextColorPref
.get(PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
).dispose();
404 fTextColorPref
.put(PREF_TEXT_COLOR_LIST
[i
] + TEXT_COLOR_POSTFIX
, new ColorImpl(display
, rgb
.red
, rgb
.green
, rgb
.blue
));
407 RGB rgb
= PreferenceConverter
.getColor(fPrefStore
, PREF_TIME_COMP
);
408 if (fTimeCompressionSelectionColor
!= null) {
409 fTimeCompressionSelectionColor
.dispose();
411 fTimeCompressionSelectionColor
= new ColorImpl(display
, rgb
.red
, rgb
.green
, rgb
.blue
);
415 * Add a property-change listener
418 * The listener to add
420 public void addPropertyChangeListener(IPropertyChangeListener listener
) {
421 fPrefStore
.addPropertyChangeListener(listener
);
425 * Remove a property-change listener
428 * The listerner to remove
430 public void removePropertyChangeListener(IPropertyChangeListener listener
) {
431 fPrefStore
.removePropertyChangeListener(listener
);
436 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
439 public void propertyChange(PropertyChangeEvent event
) {
440 if (!event
.getProperty().equals("PREFOK")) { //$NON-NLS-1$
441 buildFontsAndColors();
442 fPrefStore
.firePropertyChangeEvent("PREFOK", null, null); //$NON-NLS-1$
447 * Set the "no focus selection" preference
452 public void setNoFocusSelection(boolean v
) {
453 fNoFocusSelection
= v
;
457 * Returns the static font list.
459 * @return static font list
461 public static String
[] getFontList() {
462 return Arrays
.copyOf(FONT_LIST
, FONT_LIST
.length
);
466 * Returns the 2nd static font list.
468 * @return 2nd static font list
470 public static String
[] getFontList2() {
471 return Arrays
.copyOf(FONT_LIST2
, FONT_LIST2
.length
);
475 * Returns the preference background color list.
477 * @return preference background color list
479 public static String
[] getPrefBackColorList() {
480 return Arrays
.copyOf(PREF_BACK_COLOR_LIST
, PREF_BACK_COLOR_LIST
.length
);
484 * Returns the preference foreground color list.
486 * @return preference foreground color list
488 public static String
[] getPrefForeColorList() {
489 return Arrays
.copyOf(PREF_FORE_COLOR_LIST
, PREF_FORE_COLOR_LIST
.length
);
493 * Returns the preference text color list color list.
495 * @return preference text color list color list
497 public static String
[] getPrefTextColorList() {
498 return Arrays
.copyOf(PREF_TEXT_COLOR_LIST
, PREF_TEXT_COLOR_LIST
.length
);