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.Color;
import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.wb.swt.SWTResourceManager;
import org.osgi.service.prefs.Preferences; import org.osgi.service.prefs.Preferences;
@ -20,29 +19,12 @@ import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
public class WaveformStyleProvider implements IWaveformStyleProvider { public class WaveformStyleProvider implements IWaveformStyleProvider {
private Composite parent;
private Font nameFont; private Font nameFont;
private Color[] colors = new Color[WaveformColors.values().length]; private Color[] colors = new Color[WaveformColors.values().length];
// list of random colors // list of random colors
private static Color[][] randomColors; private static Color[][] randomColors = new Color[][] {
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( 170, 66, 37 ), SWTResourceManager.getColor( 190, 66, 37 ) },
{ SWTResourceManager.getColor( 96, 74, 110 ), SWTResourceManager.getColor( 96, 74, 130 ) }, { SWTResourceManager.getColor( 96, 74, 110 ), SWTResourceManager.getColor( 96, 74, 130 ) },
{ SWTResourceManager.getColor( 133, 105, 128 ), SWTResourceManager.getColor( 153, 105, 128 ) }, { SWTResourceManager.getColor( 133, 105, 128 ), SWTResourceManager.getColor( 153, 105, 128 ) },
@ -60,32 +42,21 @@ public class WaveformStyleProvider implements IWaveformStyleProvider {
{ SWTResourceManager.getColor( 200, 222, 182 ), SWTResourceManager.getColor( 200, 242, 182 ) }, { SWTResourceManager.getColor( 200, 222, 182 ), SWTResourceManager.getColor( 200, 242, 182 ) },
{ SWTResourceManager.getColor( 147, 208, 197 ), SWTResourceManager.getColor( 147, 228, 197 ) } { SWTResourceManager.getColor( 147, 208, 197 ), SWTResourceManager.getColor( 147, 228, 197 ) }
}; };
}
private int trackHeigth=25;
public WaveformStyleProvider(IEclipsePreferences store) { public WaveformStyleProvider(IEclipsePreferences store) {
setupDefaults(); Display display = Display.getCurrent();
DefaultWaveformStyleProvider defaultStyleProvider = new DefaultWaveformStyleProvider();
Preferences defaultPrefs= store.parent().parent().node("/"+DefaultScope.SCOPE+"/"+PreferenceConstants.PREFERENCES_SCOPE); Preferences defaultPrefs= store.parent().parent().node("/"+DefaultScope.SCOPE+"/"+PreferenceConstants.PREFERENCES_SCOPE);
HashMap<WaveformColors, RGB> colorPref = new HashMap<>();
for (WaveformColors c : WaveformColors.values()) { for (WaveformColors c : WaveformColors.values()) {
String key = c.name() + "_COLOR"; 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); 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$ 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 @Override