move color settings into style provider

This commit is contained in:
2020-11-28 20:32:11 +01:00
parent bedf4c5c4d
commit 754a61e989
11 changed files with 104 additions and 137 deletions

View File

@ -32,7 +32,7 @@ public class WaveformPopupMenuContribution {
@Inject MPart activePart;
final TrackEntry nullEntry = new TrackEntry(null);
final TrackEntry nullEntry = new TrackEntry(null, null);
private boolean selHasBitVector(ISelection sel, boolean checkForDouble) {
if(!sel.isEmpty() && sel instanceof IStructuredSelection) {

View File

@ -20,13 +20,14 @@ import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
public class WaveformStyleProvider implements IWaveformStyleProvider {
Composite parent;
private Composite parent;
private Font nameFont;
private Font nameFontB;
private Color[] colors = new Color[WaveformColors.values().length];
Color[] colors = new Color[WaveformColors.values().length];
// list of random colors
private static Color[][] randomColors;
public WaveformStyleProvider() {
@ -34,8 +35,9 @@ public class WaveformStyleProvider implements IWaveformStyleProvider {
}
private void setupDefaults() {
nameFont = Display.getCurrent().getSystemFont();
nameFontB = SWTResourceManager.getBoldFont(nameFont);
Display display = Display.getCurrent();
nameFont = display.getSystemFont();
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);
@ -59,6 +61,24 @@ public class WaveformStyleProvider implements IWaveformStyleProvider {
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);
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) {
@ -105,4 +125,16 @@ public class WaveformStyleProvider implements IWaveformStyleProvider {
return colors[type.ordinal()];
}
@Override
public Color[] computeColor (String streamValue) {
Color[] result = new Color[] {SWTResourceManager.getColor( 200,0,0), SWTResourceManager.getColor( 255,0,0)};
// assign "random" color here, one name always results in the same color!
if( streamValue!=null && randomColors.length > 0 ) {
int index = Math.abs(streamValue.hashCode()) % randomColors.length;
result[0] = randomColors[index][0];
result[1] = randomColors[index][1];
}
return result;
}
}

View File

@ -504,7 +504,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
return false;
}
});
setupColors();
waveformPane.setStyleProvider(new WaveformStyleProvider(store));
}
@Inject
@ -537,17 +537,9 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (!PreferenceConstants.DATABASE_RELOAD.equals(event.getKey()) && !PreferenceConstants.SHOW_HOVER.equals(event.getKey())){
setupColors();
}
waveformPane.setStyleProvider(new WaveformStyleProvider(store)); }
}
/**
* Setup colors.
*/
protected void setupColors() {
waveformPane.setStyleProvider(new WaveformStyleProvider(store));
}
class DbLoadJob extends Job {
final File file;
public DbLoadJob(String name, final File file) {
@ -809,7 +801,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
for (int i = 0; i < waves; i++) {
IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i));
if (waveform != null) {
TrackEntry t = new TrackEntry(waveform);
TrackEntry t = waveformPane.addWaveform(waveform, -1);
//check if t is selected
boolean isSelected = Boolean.valueOf(state.get(SHOWN_WAVEFORM + i + WAVEFORM_SELECTED));
if(isSelected) {
@ -826,8 +818,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
t.waveDisplay=WaveDisplay.valueOf(s);
}
}
if (res.size() > 0)
waveformPane.getStreamList().addAll(res);
Integer cursorLength = state.containsKey(SHOWN_CURSOR+"S")?Integer.parseInt(state.get(SHOWN_CURSOR + "S")):0; //$NON-NLS-1$ //$NON-NLS-2$
List<ICursor> cursors = waveformPane.getCursorList();
if (cursorLength == cursors.size()) {
@ -997,12 +987,10 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
* @param insert the insert
*/
public void addStreamsToList(IWaveform[] iWaveforms, boolean insert) {
List<TrackEntry> streams = new LinkedList<>();
for (IWaveform stream : iWaveforms)
streams.add(new TrackEntry(stream));
IStructuredSelection selection = (IStructuredSelection) waveformPane.getSelection();
if (selection.size() == 0) {
waveformPane.getStreamList().addAll(streams);
for (IWaveform waveform : iWaveforms)
waveformPane.addWaveform(waveform, -1);
} else {
Object first = selection.getFirstElement();
if(first instanceof ITx) {
@ -1010,17 +998,21 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
TrackEntry trackEntry = waveformPane.getEntryForStream(stream);
if (insert) {
int index = waveformPane.getStreamList().indexOf(trackEntry);
waveformPane.getStreamList().addAll(index, streams);
for (IWaveform waveform : iWaveforms)
waveformPane.addWaveform(waveform, index++);
} else {
waveformPane.getStreamList().addAll(streams);
for (IWaveform waveform : iWaveforms)
waveformPane.addWaveform(waveform, -1);
}
} else if(first instanceof TrackEntry) {
TrackEntry trackEntry = (TrackEntry) first;
if (insert) {
int index = waveformPane.getStreamList().indexOf(trackEntry);
waveformPane.getStreamList().addAll(index, streams);
for (IWaveform waveform : iWaveforms)
waveformPane.addWaveform(waveform, index++);
} else {
waveformPane.getStreamList().addAll(streams);
for (IWaveform waveform : iWaveforms)
waveformPane.addWaveform(waveform, -1);
}
}