fixes color preferences handling

This commit is contained in:
Eyck Jentzsch 2023-02-28 12:03:34 +01:00
parent 74f30e921f
commit 463dad60b9
1 changed files with 24 additions and 53 deletions

View File

@ -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<WaveformColors, RGB> 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<WaveformColors, RGB> 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;