From 463dad60b956e176d6729425963d6b8d9afad7b6 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Tue, 28 Feb 2023 12:03:34 +0100 Subject: [PATCH] fixes color preferences handling --- .../parts/WaveformStyleProvider.java | 77 ++++++------------- 1 file changed, 24 insertions(+), 53 deletions(-) diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformStyleProvider.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformStyleProvider.java index d61b191..f7698cc 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformStyleProvider.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformStyleProvider.java @@ -8,7 +8,6 @@ import org.eclipse.jface.resource.StringConverter; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.wb.swt.SWTResourceManager; import org.osgi.service.prefs.Preferences; @@ -20,74 +19,46 @@ import com.minres.scviewer.e4.application.preferences.PreferenceConstants; public class WaveformStyleProvider implements IWaveformStyleProvider { - private Composite parent; - private Font nameFont; private Color[] colors = new Color[WaveformColors.values().length]; // list of random colors - private static Color[][] randomColors; + private static Color[][] randomColors = new Color[][] { + { SWTResourceManager.getColor( 170, 66, 37 ), SWTResourceManager.getColor( 190, 66, 37 ) }, + { SWTResourceManager.getColor( 96, 74, 110 ), SWTResourceManager.getColor( 96, 74, 130 ) }, + { SWTResourceManager.getColor( 133, 105, 128 ), SWTResourceManager.getColor( 153, 105, 128 ) }, + { SWTResourceManager.getColor( 0, 126, 135 ), SWTResourceManager.getColor( 0, 126, 155 ) }, + { SWTResourceManager.getColor( 243, 146, 75 ), SWTResourceManager.getColor( 255, 146, 75 ) }, + { SWTResourceManager.getColor( 206, 135, 163 ), SWTResourceManager.getColor( 226, 135, 163 ) }, + { SWTResourceManager.getColor( 124, 103, 74 ), SWTResourceManager.getColor( 144, 103, 74 ) }, + { SWTResourceManager.getColor( 194, 187, 169 ), SWTResourceManager.getColor( 214, 187, 169 ) }, + { SWTResourceManager.getColor( 104, 73, 71 ), SWTResourceManager.getColor( 124, 73, 71 ) }, + { SWTResourceManager.getColor( 75, 196, 213 ), SWTResourceManager.getColor( 75, 196, 233 ) }, + { SWTResourceManager.getColor( 206, 232, 229 ), SWTResourceManager.getColor( 206, 252, 229 ) }, + { SWTResourceManager.getColor( 169, 221, 199 ), SWTResourceManager.getColor( 169, 241, 199 ) }, + { SWTResourceManager.getColor( 100, 165, 197 ), SWTResourceManager.getColor( 100, 165, 217 ) }, + { SWTResourceManager.getColor( 150, 147, 178 ), SWTResourceManager.getColor( 150, 147, 198 ) }, + { SWTResourceManager.getColor( 200, 222, 182 ), SWTResourceManager.getColor( 200, 242, 182 ) }, + { SWTResourceManager.getColor( 147, 208, 197 ), SWTResourceManager.getColor( 147, 228, 197 ) } +}; private int trackHeigth=25; - public WaveformStyleProvider() { - setupDefaults(); - } - - private void setupDefaults() { - Display display = Display.getCurrent(); - - nameFont = display.getSystemFont(); - DefaultWaveformStyleProvider x = new DefaultWaveformStyleProvider(); - for (WaveformColors color : WaveformColors.values()) - colors[color.ordinal()] = x.getColor(color); - randomColors = new Color[][] { - { SWTResourceManager.getColor( 170, 66, 37 ), SWTResourceManager.getColor( 190, 66, 37 ) }, - { SWTResourceManager.getColor( 96, 74, 110 ), SWTResourceManager.getColor( 96, 74, 130 ) }, - { SWTResourceManager.getColor( 133, 105, 128 ), SWTResourceManager.getColor( 153, 105, 128 ) }, - { SWTResourceManager.getColor( 0, 126, 135 ), SWTResourceManager.getColor( 0, 126, 155 ) }, - { SWTResourceManager.getColor( 243, 146, 75 ), SWTResourceManager.getColor( 255, 146, 75 ) }, - { SWTResourceManager.getColor( 206, 135, 163 ), SWTResourceManager.getColor( 226, 135, 163 ) }, - { SWTResourceManager.getColor( 124, 103, 74 ), SWTResourceManager.getColor( 144, 103, 74 ) }, - { SWTResourceManager.getColor( 194, 187, 169 ), SWTResourceManager.getColor( 214, 187, 169 ) }, - { SWTResourceManager.getColor( 104, 73, 71 ), SWTResourceManager.getColor( 124, 73, 71 ) }, - { SWTResourceManager.getColor( 75, 196, 213 ), SWTResourceManager.getColor( 75, 196, 233 ) }, - { SWTResourceManager.getColor( 206, 232, 229 ), SWTResourceManager.getColor( 206, 252, 229 ) }, - { SWTResourceManager.getColor( 169, 221, 199 ), SWTResourceManager.getColor( 169, 241, 199 ) }, - { SWTResourceManager.getColor( 100, 165, 197 ), SWTResourceManager.getColor( 100, 165, 217 ) }, - { SWTResourceManager.getColor( 150, 147, 178 ), SWTResourceManager.getColor( 150, 147, 198 ) }, - { SWTResourceManager.getColor( 200, 222, 182 ), SWTResourceManager.getColor( 200, 242, 182 ) }, - { SWTResourceManager.getColor( 147, 208, 197 ), SWTResourceManager.getColor( 147, 228, 197 ) } - }; - } - public WaveformStyleProvider(IEclipsePreferences store) { - setupDefaults(); + Display display = Display.getCurrent(); + DefaultWaveformStyleProvider defaultStyleProvider = new DefaultWaveformStyleProvider(); Preferences defaultPrefs= store.parent().parent().node("/"+DefaultScope.SCOPE+"/"+PreferenceConstants.PREFERENCES_SCOPE); - HashMap colorPref = new HashMap<>(); for (WaveformColors c : WaveformColors.values()) { String key = c.name() + "_COLOR"; - String prefValue = store.get(key, defaultPrefs.get(key, "")); //$NON-NLS-1$ + String prefValue = store.get(key, defaultPrefs.get(key, defaultStyleProvider.getColor(c).toString())); //$NON-NLS-1$ RGB rgb = StringConverter.asRGB(prefValue); - colorPref.put(c, rgb); + colors[c.ordinal()] = new Color(display, rgb); } trackHeigth = store.getInt(PreferenceConstants.TRACK_HEIGHT, defaultPrefs.getInt(PreferenceConstants.TRACK_HEIGHT, 25)); //$NON-NLS-1$ + nameFont = display.getSystemFont(); } - /** - * needs redraw() afterwards - * @param colourMap - */ - public void initColors(HashMap colourMap) { - Display d = parent.getDisplay(); - if (colourMap != null) { - for (WaveformColors c : WaveformColors.values()) { - if (colourMap.containsKey(c)) - colors[c.ordinal()] = new Color(d, colourMap.get(c)); - } - } - } - + @Override public Font getNameFont() { return nameFont;