move settings into style provider
This commit is contained in:
@ -38,7 +38,7 @@ public class LoadingWaveformDb implements IWaveformDb {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParentName(String name) {
|
||||
public void setParent(IHierNode name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,108 @@
|
||||
package com.minres.scviewer.e4.application.parts;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.jface.resource.StringConverter;
|
||||
import org.eclipse.swt.SWT;
|
||||
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;
|
||||
|
||||
import com.minres.scviewer.database.ui.IWaveformStyleProvider;
|
||||
import com.minres.scviewer.database.ui.WaveformColors;
|
||||
import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
|
||||
|
||||
public class WaveformStyleProvider implements IWaveformStyleProvider {
|
||||
|
||||
Composite parent;
|
||||
|
||||
private Font nameFont;
|
||||
|
||||
private Font nameFontB;
|
||||
|
||||
Color[] colors = new Color[WaveformColors.values().length];
|
||||
|
||||
|
||||
public WaveformStyleProvider() {
|
||||
setupDefaults();
|
||||
}
|
||||
|
||||
private void setupDefaults() {
|
||||
nameFont = Display.getCurrent().getSystemFont();
|
||||
nameFontB = SWTResourceManager.getBoldFont(nameFont);
|
||||
colors[WaveformColors.LINE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
|
||||
colors[WaveformColors.LINE_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_CYAN);
|
||||
colors[WaveformColors.TRACK_BG_EVEN.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_BLACK);
|
||||
colors[WaveformColors.TRACK_BG_ODD.ordinal()] = SWTResourceManager.getColor(40, 40, 40);
|
||||
colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(40, 40, 80);
|
||||
colors[WaveformColors.TX_BG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GREEN);
|
||||
colors[WaveformColors.TX_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
|
||||
colors[WaveformColors.TX_BORDER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
|
||||
colors[WaveformColors.SIGNAL0.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GREEN);
|
||||
colors[WaveformColors.SIGNAL1.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GREEN);
|
||||
colors[WaveformColors.SIGNALZ.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_YELLOW);
|
||||
colors[WaveformColors.SIGNALX.ordinal()] = SWTResourceManager.getColor(255, 51, 51);
|
||||
colors[WaveformColors.SIGNALU.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_YELLOW);
|
||||
colors[WaveformColors.SIGNAL_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE);
|
||||
colors[WaveformColors.SIGNAL_REAL.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_YELLOW);
|
||||
colors[WaveformColors.SIGNAL_NAN.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
|
||||
colors[WaveformColors.CURSOR.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
|
||||
colors[WaveformColors.CURSOR_DRAG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY);
|
||||
colors[WaveformColors.CURSOR_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE);
|
||||
colors[WaveformColors.MARKER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY);
|
||||
colors[WaveformColors.MARKER_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE);
|
||||
colors[WaveformColors.REL_ARROW.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_MAGENTA);
|
||||
colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()] = SWTResourceManager.getColor(255, 128, 255);
|
||||
}
|
||||
|
||||
public WaveformStyleProvider(IEclipsePreferences store) {
|
||||
setupDefaults();
|
||||
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$
|
||||
RGB rgb = StringConverter.asRGB(prefValue);
|
||||
colorPref.put(c, rgb);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Font getNameFontHighlite() {
|
||||
return nameFont;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTrackHeight() {
|
||||
return 25;
|
||||
}
|
||||
@Override
|
||||
public Color getColor(WaveformColors type) {
|
||||
return colors[type.ordinal()];
|
||||
}
|
||||
|
||||
}
|
@ -37,7 +37,6 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.core.runtime.jobs.JobGroup;
|
||||
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
|
||||
@ -55,7 +54,6 @@ import org.eclipse.e4.ui.services.EMenuService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.resource.StringConverter;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
@ -70,7 +68,6 @@ import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
@ -83,7 +80,6 @@ import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.eclipse.swt.widgets.Widget;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.IEvent;
|
||||
@ -101,7 +97,6 @@ import com.minres.scviewer.database.ui.IWaveformView;
|
||||
import com.minres.scviewer.database.ui.TrackEntry;
|
||||
import com.minres.scviewer.database.ui.TrackEntry.ValueDisplay;
|
||||
import com.minres.scviewer.database.ui.TrackEntry.WaveDisplay;
|
||||
import com.minres.scviewer.database.ui.WaveformColors;
|
||||
import com.minres.scviewer.database.ui.swt.Constants;
|
||||
import com.minres.scviewer.database.ui.swt.ToolTipContentProvider;
|
||||
import com.minres.scviewer.database.ui.swt.ToolTipHelpTextProvider;
|
||||
@ -301,7 +296,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
transactionList = ContextInjectionFactory.make(TransactionListView.class, ctx);
|
||||
|
||||
waveformPane.setMaxTime(0);
|
||||
setupColors();
|
||||
//set selection to empty selection when opening a new waveformPane
|
||||
selectionService.setSelection(new StructuredSelection());
|
||||
|
||||
@ -510,6 +504,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
return false;
|
||||
}
|
||||
});
|
||||
setupColors();
|
||||
}
|
||||
|
||||
@Inject
|
||||
@ -550,15 +545,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
* Setup colors.
|
||||
*/
|
||||
protected void setupColors() {
|
||||
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$
|
||||
RGB rgb = StringConverter.asRGB(prefValue);
|
||||
colorPref.put(c, rgb);
|
||||
}
|
||||
waveformPane.setColors(colorPref);
|
||||
waveformPane.setStyleProvider(new WaveformStyleProvider(store));
|
||||
}
|
||||
|
||||
class DbLoadJob extends Job {
|
||||
|
Reference in New Issue
Block a user