fixes color preferences handling
This commit is contained in:
parent
74f30e921f
commit
463dad60b9
|
@ -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,29 +19,12 @@ 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 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[][] {
|
||||
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 ) },
|
||||
|
@ -59,33 +41,22 @@ public class WaveformStyleProvider implements IWaveformStyleProvider {
|
|||
{ 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(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$
|
||||
}
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
nameFont = display.getSystemFont();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue