move settings into style provider

This commit is contained in:
Eyck Jentzsch 2020-11-28 19:41:00 +01:00
parent 7c27bcec47
commit bedf4c5c4d
21 changed files with 377 additions and 263 deletions

View File

@ -76,7 +76,7 @@ class TxStream extends HierNode implements IWaveform {
def rowendtime = [0]
events.keySet().each{long time ->
def value=events.get(time)
def starts=value.findAll{ITxEvent event ->event.type==EventKind.BEGIN}
def starts=value.findAll{IEvent event ->event.kind==EventKind.BEGIN}
starts.each {ITxEvent event ->
Tx tx = event.transaction
def rowIdx = 0

View File

@ -0,0 +1,15 @@
package com.minres.scviewer.database.ui;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
public interface IWaveformStyleProvider {
Font getNameFont();
Font getNameFontHighlite();
int getTrackHeight();
Color getColor(WaveformColors type);
}

View File

@ -11,7 +11,6 @@
package com.minres.scviewer.database.ui;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.List;
import org.eclipse.jface.viewers.ISelection;
@ -19,7 +18,6 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Control;
import com.minres.scviewer.database.IWaveform;
@ -37,6 +35,8 @@ public interface IWaveformView extends PropertyChangeListener, ISelectionProvide
public void removeSelectionChangedListener(ISelectionChangedListener listener);
public void setStyleProvider(IWaveformStyleProvider styleProvider);
public void update();
public Control getControl();
@ -103,8 +103,6 @@ public interface IWaveformView extends PropertyChangeListener, ISelectionProvide
public List<ICursor> getCursorList();
public void setColors(HashMap<WaveformColors, RGB> colourMap);
public long getBaselineTime();
public void setBaselineTime(Long scale);

View File

@ -14,4 +14,6 @@ import org.eclipse.swt.widgets.Composite;
public interface IWaveformViewFactory {
public IWaveformView createPanel(Composite parent);
public IWaveformView createPanel(Composite parent, IWaveformStyleProvider styleProvider);
}

View File

@ -0,0 +1,87 @@
package com.minres.scviewer.database.ui.swt;
import java.util.HashMap;
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 com.minres.scviewer.database.ui.IWaveformStyleProvider;
import com.minres.scviewer.database.ui.WaveformColors;
public class DefaultWaveformStyleProvider implements IWaveformStyleProvider {
Composite parent;
private Font nameFont;
private Font nameFontB;
Color[] colors = new Color[WaveformColors.values().length];
public DefaultWaveformStyleProvider() {
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);
}
/**
* 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 nameFontB;
}
@Override
public int getTrackHeight() {
return 50;
}
@Override
public Color getColor(WaveformColors type) {
// TODO Auto-generated method stub
return colors[type.ordinal()];
}
}

View File

@ -12,6 +12,7 @@ package com.minres.scviewer.database.ui.swt;
import org.eclipse.swt.widgets.Composite;
import com.minres.scviewer.database.ui.IWaveformStyleProvider;
import com.minres.scviewer.database.ui.IWaveformView;
import com.minres.scviewer.database.ui.IWaveformViewFactory;
import com.minres.scviewer.database.ui.swt.internal.WaveformView;
@ -20,7 +21,12 @@ public class WaveformViewFactory implements IWaveformViewFactory {
@Override
public IWaveformView createPanel(Composite parent) {
return new WaveformView(parent);
return new WaveformView(parent, new DefaultWaveformStyleProvider());
}
@Override
public IWaveformView createPanel(Composite parent, IWaveformStyleProvider styleProvider) {
return new WaveformView(parent, styleProvider);
}
}

View File

@ -30,7 +30,7 @@ public class ArrowPainter implements IPainter {
private final int xCtrlOffset = 50;
private final int yCtrlOffset = 30;
private int yCtrlOffset = 30;
private WaveformCanvas waveCanvas;
@ -101,11 +101,12 @@ public class ArrowPainter implements IPainter {
ITx otherTx = useTarget ? iTxRelation.getTarget() : iTxRelation.getSource();
if (waveCanvas.wave2painterMap.containsKey(otherTx.getStream())) {
IWaveformPainter painter = waveCanvas.wave2painterMap.get(otherTx.getStream());
int laneHeight = painter.getHeight() / tx.getStream().getWidth();
Rectangle bb = new Rectangle((int) (otherTx.getBeginTime() / scaleFactor),
waveCanvas.rulerHeight + painter.getVerticalOffset()
+ laneHeight * otherTx.getConcurrencyIndex(),
(int) ((otherTx.getEndTime() - otherTx.getBeginTime()) / scaleFactor), laneHeight);
int height = waveCanvas.styleProvider.getTrackHeight();
Rectangle bb = new Rectangle(
(int) (otherTx.getBeginTime() / scaleFactor),
waveCanvas.rulerHeight + painter.getVerticalOffset() + height * otherTx.getConcurrencyIndex(),
(int) ((otherTx.getEndTime() - otherTx.getBeginTime()) / scaleFactor),
height);
res.add(new LinkEntry(bb, iTxRelation.getRelationType()));
}
}
@ -113,8 +114,9 @@ public class ArrowPainter implements IPainter {
@Override
public void paintArea(Projection proj, Rectangle clientRect) {
Color fgColor = waveCanvas.colors[WaveformColors.REL_ARROW.ordinal()];
Color highliteColor = waveCanvas.colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()];
yCtrlOffset = waveCanvas.styleProvider.getTrackHeight()/2;
Color fgColor = waveCanvas.styleProvider.getColor(WaveformColors.REL_ARROW);
Color highliteColor = waveCanvas.styleProvider.getColor(WaveformColors.REL_ARROW_HIGHLITE);
if(tx==null) return;
if (!deferUpdate) {

View File

@ -75,9 +75,9 @@ public class CursorPainter implements IPainter, ICursor {
int x = (int) (time/scaleFactor);
// distance of marker from the top of Canvas' painting area
int top = id<0?area.y:area.y+15;
Color drawColor=waveCanvas.colors[id<0?WaveformColors.CURSOR.ordinal():WaveformColors.MARKER.ordinal()];
Color dragColor = waveCanvas.colors[WaveformColors.CURSOR_DRAG.ordinal()];
Color textColor=waveCanvas.colors[id<0?WaveformColors.CURSOR_TEXT.ordinal():WaveformColors.MARKER_TEXT.ordinal()];
Color drawColor=waveCanvas.styleProvider.getColor(id<0?WaveformColors.CURSOR:WaveformColors.MARKER);
Color dragColor = waveCanvas.styleProvider.getColor(WaveformColors.CURSOR_DRAG);
Color textColor=waveCanvas.styleProvider.getColor(id<0?WaveformColors.CURSOR_TEXT:WaveformColors.MARKER_TEXT);
if(x>=beginPos && x<=maxValX){
proj.setForeground(isDragging?dragColor:drawColor);
proj.drawLine(x, top, x, area.y+area.height);

View File

@ -28,6 +28,7 @@ import com.minres.scviewer.database.DoubleVal;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.TrackEntry.ValueDisplay;
import com.minres.scviewer.database.ui.WaveformColors;
public class SignalPainter extends TrackPainter {
@ -88,9 +89,9 @@ public class SignalPainter extends TrackPainter {
public void paintArea(Projection proj, Rectangle area) {
IWaveform signal = trackEntry.waveform;
if (trackEntry.selected)
proj.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()]);
proj.setBackground(this.waveCanvas.styleProvider.getColor(WaveformColors.TRACK_BG_HIGHLITE));
else
proj.setBackground(this.waveCanvas.colors[even ? WaveformColors.TRACK_BG_EVEN.ordinal() : WaveformColors.TRACK_BG_ODD.ordinal()]);
proj.setBackground(this.waveCanvas.styleProvider.getColor(even ? WaveformColors.TRACK_BG_EVEN : WaveformColors.TRACK_BG_ODD));
proj.setFillRule(SWT.FILL_EVEN_ODD);
proj.fillRectangle(area);
@ -108,16 +109,16 @@ public class SignalPainter extends TrackPainter {
} else if (last == null) {
last = signal.getEvents().lastEntry();
}
proj.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]);
proj.setForeground(this.waveCanvas.styleProvider.getColor(WaveformColors.LINE));
proj.setLineStyle(SWT.LINE_SOLID);
proj.setLineWidth(1);
NavigableMap<Long, IEvent[]> entries = signal.getEvents().subMap(first.getKey(), false, last.getKey(), true);
SignalChange left = new SignalChange(first);
SignalChange right = new SignalChange(entries.size() > 0 ? entries.firstEntry() : first);
maxPosX = area.x + area.width;
yOffsetT = this.waveCanvas.getTrackHeight() / 5 + area.y;
yOffsetM = this.waveCanvas.getTrackHeight() / 2 + area.y;
yOffsetB = 4 * this.waveCanvas.getTrackHeight() / 5 + area.y;
yOffsetT = this.waveCanvas.styleProvider.getTrackHeight() / 5 + area.y;
yOffsetM = this.waveCanvas.styleProvider.getTrackHeight() / 2 + area.y;
yOffsetB = 4 * this.waveCanvas.styleProvider.getTrackHeight() / 5 + area.y;
int xSigChangeBeginVal = Math.max(area.x, (int) (left.time / this.waveCanvas.getScaleFactor()));
int xSigChangeBeginPos = area.x;
int xSigChangeEndPos = Math.max(area.x, getXPosEnd(right.time));
@ -195,12 +196,12 @@ public class SignalPainter extends TrackPainter {
}
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) {
Color colorBorder = waveCanvas.colors[WaveformColors.SIGNAL0.ordinal()];
Color colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL0);
BitVector last = (BitVector) left;
if (last.getValue().toString().contains("X")) {
colorBorder = waveCanvas.colors[WaveformColors.SIGNALX.ordinal()];
colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNALX);
} else if (last.getValue().toString().contains("Z")) {
colorBorder = waveCanvas.colors[WaveformColors.SIGNALZ.ordinal()];
colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNALZ);
}
int width = xEnd - xBegin;
if (width > 1) {
@ -214,7 +215,7 @@ public class SignalPainter extends TrackPainter {
};
proj.setForeground(colorBorder);
proj.drawPolygon(points);
proj.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_TEXT.ordinal()]);
proj.setForeground(waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL_TEXT));
//TODO: this code should be provided from a central location
String label = null;
switch(trackEntry.valueDisplay) {
@ -249,19 +250,20 @@ public class SignalPainter extends TrackPainter {
private class MultiBitStencilAnalog implements SignalStencil {
final boolean continous;
final boolean signed;
private long maxVal;
private long minVal;
private long range;
double yRange = (yOffsetB-yOffsetT);
public MultiBitStencilAnalog(NavigableMap<Long, IEvent[]> entries, Object left, boolean continous, boolean signed) {
this.continous=continous;
this.signed=signed;
Collection<IEvent[]> values = entries.values();
minVal=((BitVector) left).toUnsignedValue();
range=2;
minVal=signed?((BitVector)left).toSignedValue():((BitVector)left).toUnsignedValue();
if(!values.isEmpty()) {
long maxVal=minVal;
maxVal=minVal;
for (IEvent[] tp : entries.values())
for(IEvent e: tp) {
long v = ((BitVector)e).toUnsignedValue();
long v = signed?((BitVector)e).toSignedValue():((BitVector)e).toUnsignedValue();
maxVal=Math.max(maxVal, v);
minVal=Math.min(minVal, v);
}
@ -269,16 +271,18 @@ public class SignalPainter extends TrackPainter {
maxVal--;
minVal++;
}
range = maxVal-minVal;
} else
} else {
minVal--;
maxVal=minVal+2;
}
}
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) {
long leftVal = ((BitVector) left).toUnsignedValue();
long rightVal= ((BitVector) right).toUnsignedValue();
proj.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_REAL.ordinal()]);
long leftVal = signed?((BitVector)left).toSignedValue():((BitVector)left).toUnsignedValue();
long rightVal= signed?((BitVector)right).toSignedValue():((BitVector)right).toUnsignedValue();
proj.setForeground(waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL_REAL));
long range = maxVal-minVal;
int yOffsetLeft = (int) ((leftVal-minVal) * yRange / range);
int yOffsetRight = (int) ((rightVal-minVal) * yRange / range);
if(continous) {
@ -303,24 +307,24 @@ public class SignalPainter extends TrackPainter {
private class SingleBitStencil implements SignalStencil {
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) {
if (multiple) {
proj.setForeground(waveCanvas.colors[WaveformColors.SIGNALU.ordinal()]);
proj.setForeground(waveCanvas.styleProvider.getColor(WaveformColors.SIGNALU));
proj.drawLine(xBegin, yOffsetT, xBegin, yOffsetB);
if(xEnd>xBegin)
proj.drawLine(xEnd, yOffsetT, xEnd, yOffsetB);
} else {
Color color = waveCanvas.colors[WaveformColors.SIGNALX.ordinal()];
Color color = waveCanvas.styleProvider.getColor(WaveformColors.SIGNALX);
int yOffset = yOffsetM;
switch (((BitVector) left).getValue()[0]) {
case '1':
color = waveCanvas.colors[WaveformColors.SIGNAL1.ordinal()];
color = waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL1);
yOffset = yOffsetT;
break;
case '0':
color = waveCanvas.colors[WaveformColors.SIGNAL0.ordinal()];
color = waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL0);
yOffset = yOffsetB;
break;
case 'Z':
color = waveCanvas.colors[WaveformColors.SIGNALZ.ordinal()];
color = waveCanvas.styleProvider.getColor(WaveformColors.SIGNALZ);
break;
default:
}
@ -385,7 +389,7 @@ public class SignalPainter extends TrackPainter {
double leftVal = ((DoubleVal) left).value;
double rightVal= ((DoubleVal) right).value;
if(Double.isNaN(leftVal)) {
Color color = waveCanvas.colors[WaveformColors.SIGNAL_NAN.ordinal()];
Color color = waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL_NAN);
int width = xEnd - xBegin;
if (width > 1) {
int[] points = {
@ -403,7 +407,7 @@ public class SignalPainter extends TrackPainter {
proj.drawLine(xEnd, yOffsetT, xEnd, yOffsetB);
}
} else {
proj.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_REAL.ordinal()]);
proj.setForeground(waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL_REAL));
int yOffsetLeft = (int) ((leftVal-minVal) * (yOffsetB-yOffsetT) / range);
int yOffsetRight = Double.isNaN(rightVal)?yOffsetLeft:(int) ((rightVal-minVal) * (yOffsetB-yOffsetT) / range);
if(continous) {

View File

@ -67,10 +67,10 @@ public class StreamPainter extends TrackPainter{
txBase=trackHeight/5;
txHeight=trackHeight*3/5;
if(trackEntry.selected) {
proj.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()]);
proj.setBackground(this.waveCanvas.styleProvider.getColor(WaveformColors.TRACK_BG_HIGHLITE));
}
else
proj.setBackground(this.waveCanvas.colors[even?WaveformColors.TRACK_BG_EVEN.ordinal():WaveformColors.TRACK_BG_ODD.ordinal()]);
proj.setBackground(this.waveCanvas.styleProvider.getColor(even?WaveformColors.TRACK_BG_EVEN:WaveformColors.TRACK_BG_ODD));
proj.setFillRule(SWT.FILL_EVEN_ODD);
proj.fillRectangle(area);
@ -87,7 +87,7 @@ public class StreamPainter extends TrackPainter{
proj.setFillRule(SWT.FILL_EVEN_ODD);
proj.setLineStyle(SWT.LINE_SOLID);
proj.setLineWidth(1);
proj.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]);
proj.setForeground(this.waveCanvas.styleProvider.getColor(WaveformColors.LINE));
for( int y1=area.y+trackHeight/2; y1<area.y+trackEntry.height; y1+=trackHeight)
proj.drawLine(area.x, y1, area.x+area.width, y1);
@ -98,7 +98,7 @@ public class StreamPainter extends TrackPainter{
seenTx.clear();
NavigableMap<Long, IEvent[]> entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true);
boolean highlighed=false;
proj.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]);
proj.setForeground(this.waveCanvas.styleProvider.getColor(WaveformColors.LINE));
for(Entry<Long, IEvent[]> entry: entries.entrySet())
for(IEvent evt:entry.getValue()){
@ -116,7 +116,7 @@ public class StreamPainter extends TrackPainter{
drawTx(proj, area, tx, false);
}
if(highlighed){
proj.setForeground(this.waveCanvas.colors[WaveformColors.LINE_HIGHLITE.ordinal()]);
proj.setForeground(this.waveCanvas.styleProvider.getColor(WaveformColors.LINE_HIGHLITE));
drawTx(proj, area, waveCanvas.currentSelection, true);
}
}
@ -129,7 +129,7 @@ public class StreamPainter extends TrackPainter{
proj.setBackground( toSwtColor( proj.getGC(), transColor[highlighted?1:0] ) );
int offset = tx.getConcurrencyIndex()*this.waveCanvas.getTrackHeight();
int offset = tx.getConcurrencyIndex()*this.waveCanvas.styleProvider.getTrackHeight();
Rectangle bb = new Rectangle(
(int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+txBase,
(int)((tx.getEndTime()-tx.getBeginTime())/this.waveCanvas.getScaleFactor()), txHeight);
@ -155,7 +155,7 @@ public class StreamPainter extends TrackPainter{
}
public ITx getClicked(Point point) {
int lane=point.y/waveCanvas.getTrackHeight();
int lane=point.y/waveCanvas.styleProvider.getTrackHeight();
Entry<Long, IEvent[]> firstTx=stream.getEvents().floorEntry(point.x*waveCanvas.getScaleFactor());
if(firstTx!=null){
do {

View File

@ -36,7 +36,7 @@ public class TrackAreaPainter implements IPainter {
public void paintArea(Projection proj, Rectangle a) {
Rectangle area = proj.unProject(new Rectangle(a.x, a.y+waveCanvas.rulerHeight, a.width, a.height-waveCanvas.rulerHeight));
proj.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_EVEN.ordinal()]);
proj.setBackground(this.waveCanvas.styleProvider.getColor(WaveformColors.TRACK_BG_EVEN));
proj.setFillRule(SWT.FILL_EVEN_ODD);
proj.fillRectangle(area);
if(trackVerticalOffset.size()>0){

View File

@ -23,36 +23,30 @@ import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.wb.swt.SWTResourceManager;
import com.google.common.collect.Lists;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.database.ui.IWaveformStyleProvider;
import com.minres.scviewer.database.ui.IWaveformView;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.WaveformColors;
import com.minres.scviewer.database.ui.swt.Constants;
public class WaveformCanvas extends Canvas {
Color[] colors = new Color[WaveformColors.values().length];
private boolean doubleBuffering = true;
private int trackHeight = 50;
IWaveformStyleProvider styleProvider;
private long scaleFactor = 1000000L; // 1ns
String unit="ns";
@ -88,8 +82,9 @@ public class WaveformCanvas extends Canvas {
* @param style
* the style of this control.
*/
public WaveformCanvas(final Composite parent, int style) {
public WaveformCanvas(final Composite parent, int style, IWaveformStyleProvider styleProvider) {
super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.V_SCROLL | SWT.H_SCROLL);
this.styleProvider=styleProvider;
addControlListener(new ControlAdapter() { /* resize listener. */
public void controlResized(ControlEvent event) {
syncScrollBars();
@ -107,7 +102,6 @@ public class WaveformCanvas extends Canvas {
wave2painterMap=new HashMap<>();
initScrollBars();
initColors(null);
// order is important: it is bottom to top
trackAreaPainter=new TrackAreaPainter(this);
painterList.add(trackAreaPainter);
@ -122,31 +116,6 @@ public class WaveformCanvas extends Canvas {
painterList.add(marker);
cursorPainters.add(marker);
wave2painterMap=new HashMap<>();
// fall back initialization
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 void addCursoPainter(CursorPainter cursorPainter){
@ -154,17 +123,6 @@ public class WaveformCanvas extends Canvas {
cursorPainters.add(cursorPainter);
}
public void initColors(HashMap<WaveformColors, RGB> colourMap) {
Display d = getDisplay();
if (colourMap != null) {
for (WaveformColors c : WaveformColors.values()) {
if (colourMap.containsKey(c))
colors[c.ordinal()] = new Color(d, colourMap.get(c));
}
redraw();
}
}
public void setHighliteRelation(RelationType relationType){
if(arrowPainter!=null){
boolean redraw = arrowPainter.getHighlightType()!=relationType;
@ -206,15 +164,6 @@ public class WaveformCanvas extends Canvas {
syncScrollBars();
}
public int getTrackHeight() {
return trackHeight;
}
public void setTrackHeight(int trackHeight) {
this.trackHeight = trackHeight;
syncScrollBars();
}
public int getZoomLevel() {
return level;
}
@ -315,15 +264,6 @@ public class WaveformCanvas extends Canvas {
return cursorPainters;
}
/**
* Dispose the garbage here
*/
public void dispose() {
for (WaveformColors c : WaveformColors.values())
colors[c.ordinal()].dispose();
super.dispose();
}
/* Initialize the scrollbar and register listeners. */
private void initScrollBars() {
ScrollBar horizontal = getHorizontalBar();
@ -459,7 +399,7 @@ public class WaveformCanvas extends Canvas {
int x = i - origin.x;
for(IPainter p: wave2painterMap.values()){
if (p instanceof StreamPainter && ((StreamPainter)p).getStream()==iWaveform) {
result.add(((StreamPainter) p).getClicked(new Point(x, trackHeight/2)));
result.add(((StreamPainter) p).getClicked(new Point(x, styleProvider.getTrackHeight()/2)));
}
}
return result;
@ -486,10 +426,10 @@ public class WaveformCanvas extends Canvas {
}
for (IWaveformPainter painter : wave2painterMap.values()) {
if (painter instanceof StreamPainter && ((StreamPainter) painter).getStream() == tx.getStream()) {
int top = painter.getVerticalOffset() + trackHeight * tx.getConcurrencyIndex();
int bottom = top + trackHeight;
int top = painter.getVerticalOffset() + styleProvider.getTrackHeight() * tx.getConcurrencyIndex();
int bottom = top + styleProvider.getTrackHeight();
if (top < -origin.y) {
setOrigin(origin.x, -(top-trackHeight));
setOrigin(origin.x, -(top-styleProvider.getTrackHeight()));
} else if (bottom > (size.y - origin.y)) {
setOrigin(origin.x, size.y - bottom);
}
@ -508,9 +448,9 @@ public class WaveformCanvas extends Canvas {
if((sb.getStyle()&SWT.SCROLLBAR_OVERLAY)!=0 && sb.isVisible()) // TODO: check on other platform than MacOSX
size.y-= getHorizontalBar().getSize().y;
int top = te.vOffset;
int bottom = top + trackHeight;
int bottom = top + styleProvider.getTrackHeight();
if (top < -origin.y) {
setOrigin(origin.x, -(top-trackHeight));
setOrigin(origin.x, -(top-styleProvider.getTrackHeight()));
} else if (bottom > (size.y - origin.y)) {
setOrigin(origin.x, size.y - bottom);
}
@ -569,4 +509,9 @@ public class WaveformCanvas extends Canvas {
long getMinVisibleTime() {
return origin.x * scaleFactor;
}
public void setStyleProvider(IWaveformStyleProvider styleProvider) {
this.styleProvider=styleProvider;
redraw();
}
}

View File

@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
@ -57,10 +56,8 @@ import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.layout.FillLayout;
@ -90,9 +87,9 @@ import com.minres.scviewer.database.tx.ITxEvent;
import com.minres.scviewer.database.tx.ITxRelation;
import com.minres.scviewer.database.ui.GotoDirection;
import com.minres.scviewer.database.ui.ICursor;
import com.minres.scviewer.database.ui.IWaveformStyleProvider;
import com.minres.scviewer.database.ui.IWaveformView;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.WaveformColors;
import com.minres.scviewer.database.ui.swt.Constants;
public class WaveformView implements IWaveformView {
@ -129,11 +126,11 @@ public class WaveformView implements IWaveformView {
int selectedMarker = 0;
private int trackVerticalHeight;
private int tracksVerticalHeight;
private TreeMap<Integer, TrackEntry> trackVerticalOffset;
private Font nameFont, nameFontB;
private IWaveformStyleProvider styleProvider;
protected TrackEntry lastClickedEntry;
@ -315,14 +312,13 @@ public class WaveformView implements IWaveformView {
};
protected WaveformMouseListener waveformMouseListener = new WaveformMouseListener();
public WaveformView(Composite parent) {
public WaveformView(Composite parent, IWaveformStyleProvider styleProvider) {
this.styleProvider=styleProvider;
pcs=new PropertyChangeSupport(this);
trackVerticalOffset = new TreeMap<Integer, TrackEntry>();
trackVerticalHeight=0;
nameFont = parent.getDisplay().getSystemFont();
nameFontB = SWTResourceManager.getBoldFont(nameFont);
tracksVerticalHeight=0;
streams = new ObservableList<>();
streams.addPropertyChangeListener("content", this);
@ -341,7 +337,7 @@ public class WaveformView implements IWaveformView {
rightSash.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
Composite valuePane = new Composite(rightSash, SWT.NONE);
waveformCanvas = new WaveformCanvas(rightSash, SWT.NONE);
waveformCanvas = new WaveformCanvas(rightSash, SWT.NONE, styleProvider);
// create the name pane
createTextPane(namePane, "Name");
@ -508,17 +504,17 @@ public class WaveformView implements IWaveformView {
}
public void update() {
trackVerticalHeight = 0;
tracksVerticalHeight = 0;
int nameMaxWidth = 0;
IWaveformPainter painter = null;
trackVerticalOffset.clear();
waveformCanvas.clearAllWaveformPainter(false);
boolean even = true;
TextLayout tl = new TextLayout(waveformCanvas.getDisplay());
tl.setFont(nameFontB);
tl.setFont(styleProvider.getNameFont());
for (TrackEntry streamEntry : streams) {
streamEntry.height = waveformCanvas.getTrackHeight();
streamEntry.vOffset=trackVerticalHeight;
streamEntry.height = styleProvider.getTrackHeight();
streamEntry.vOffset=tracksVerticalHeight;
if (streamEntry.waveform.getType()==WaveformType.TRANSACTION) {
streamEntry.currentValue="";
streamEntry.height *= streamEntry.waveform.getWidth();
@ -528,15 +524,15 @@ public class WaveformView implements IWaveformView {
painter = new SignalPainter(waveformCanvas, even, streamEntry);
}
waveformCanvas.addWaveformPainter(painter, false);
trackVerticalOffset.put(trackVerticalHeight, streamEntry);
trackVerticalOffset.put(tracksVerticalHeight, streamEntry);
tl.setText(streamEntry.waveform.getFullName());
nameMaxWidth = Math.max(nameMaxWidth, tl.getBounds().width);
trackVerticalHeight += streamEntry.height;
tracksVerticalHeight += streamEntry.height;
even = !even;
}
waveformCanvas.syncScrollBars();
nameList.setSize(nameMaxWidth + 15, trackVerticalHeight);
nameListScrolled.setMinSize(nameMaxWidth + 15, trackVerticalHeight);
nameList.setSize(nameMaxWidth + 15, tracksVerticalHeight);
nameListScrolled.setMinSize(nameMaxWidth + 15, tracksVerticalHeight);
nameList.redraw();
updateValueList();
waveformCanvas.redraw();
@ -548,7 +544,7 @@ public class WaveformView implements IWaveformView {
private int calculateValueWidth() {
TextLayout tl = new TextLayout(waveformCanvas.getDisplay());
tl.setFont(nameFontB);
tl.setFont(styleProvider.getNameFontHighlite());
int valueMaxWidth = 0;
for (TrackEntry v : streams) {
tl.setText(v.currentValue);
@ -615,8 +611,8 @@ public class WaveformView implements IWaveformView {
}
}
int width = calculateValueWidth();
valueList.setSize(width, trackVerticalHeight);
valueListScrolled.setMinSize(width, trackVerticalHeight);
valueList.setSize(width, tracksVerticalHeight);
valueListScrolled.setMinSize(width, tracksVerticalHeight);
valueListScrolled.redraw();
}
@ -734,9 +730,6 @@ public class WaveformView implements IWaveformView {
streams.add(trackEntry);
}
currentTxSelection = txSel;
// if(trackEntry!=null) {
// currentWaveformSelection.add((TrackEntry)sel);
// }
selectionChanged = true;
} else if (sel instanceof TrackEntry && !currentWaveformSelection.contains(sel)) {
currentWaveformSelection.add((TrackEntry)sel);
@ -973,7 +966,7 @@ public class WaveformView implements IWaveformView {
if (firstKey == null)
firstKey = trackVerticalOffset.firstKey();
Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height);
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, waveformCanvas.getTrackHeight());
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, styleProvider.getTrackHeight());
if (lastKey == firstKey) {
TrackEntry trackEntry=trackVerticalOffset.get(firstKey);
IWaveform w = trackEntry.waveform;
@ -983,7 +976,7 @@ public class WaveformView implements IWaveformView {
} else {
for (Entry<Integer, TrackEntry> entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()) {
IWaveform w = entry.getValue().waveform;
subArea.height = waveformCanvas.getTrackHeight();
subArea.height = styleProvider.getTrackHeight();
if (w.getType()==WaveformType.TRANSACTION)
subArea.height *= w.getWidth();
drawTextFormat(gc, subArea, entry.getKey(), w.getFullName(), entry.getValue().selected);
@ -1000,7 +993,7 @@ public class WaveformView implements IWaveformView {
if (firstKey == null)
firstKey = trackVerticalOffset.firstKey();
Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height);
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, waveformCanvas.getTrackHeight());
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, styleProvider.getTrackHeight());
if (lastKey == firstKey) {
TrackEntry trackEntry=trackVerticalOffset.get(firstKey);
IWaveform w = trackEntry.waveform;
@ -1011,7 +1004,7 @@ public class WaveformView implements IWaveformView {
for (Entry<Integer, TrackEntry> entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true)
.entrySet()) {
IWaveform w = entry.getValue().waveform;
subArea.height = waveformCanvas.getTrackHeight();
subArea.height = styleProvider.getTrackHeight();
if (w.getType()==WaveformType.TRANSACTION)
subArea.height *= w.getWidth();
drawValue(gc, subArea, entry.getKey(), entry.getValue().currentValue, entry.getValue().selected);
@ -1023,10 +1016,10 @@ public class WaveformView implements IWaveformView {
protected void drawValue(GC gc, Rectangle subArea, Integer yOffset, String value, boolean highlite) {
int beginIndex=0;
for(int offset=0; offset<subArea.height; offset+=waveformCanvas.getTrackHeight()){
for(int offset=0; offset<subArea.height; offset+=styleProvider.getTrackHeight()){
int endIndex=value.indexOf('|', beginIndex);
String str = endIndex<0?value.substring(beginIndex):value.substring(beginIndex, endIndex);
drawTextFormat(gc, new Rectangle(subArea.x, subArea.y, subArea.width, waveformCanvas.getTrackHeight()), yOffset+offset, str, highlite);
drawTextFormat(gc, new Rectangle(subArea.x, subArea.y, subArea.width, styleProvider.getTrackHeight()), yOffset+offset, str, highlite);
beginIndex=endIndex<0?beginIndex:endIndex+1;
}
}
@ -1037,13 +1030,13 @@ public class WaveformView implements IWaveformView {
gc.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION));
gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
gc.fillRectangle(subArea.x, subArea.y + yOffset, subArea.width, subArea.height);
gc.setFont(nameFontB);
gc.setFont(styleProvider.getNameFontHighlite());
} else {
gc.setBackground(namePaneHeader.getBackground());
gc.setForeground(namePaneHeader.getForeground());
gc.setFont(nameFont);
gc.setFont(styleProvider.getNameFont());
}
gc.drawText(value, subArea.x + 5, subArea.y + yOffset + (waveformCanvas.getTrackHeight() - size.y) / 2, true);
gc.drawText(value, subArea.x + 5, subArea.y + yOffset + (styleProvider.getTrackHeight() - size.y) / 2, true);
}
@ -1143,7 +1136,7 @@ public class WaveformView implements IWaveformView {
dragSource.setTransfer(types);
dragSource.addDragListener(new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
if (event.y < trackVerticalHeight) {
if (event.y < tracksVerticalHeight) {
event.doit = true;
LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(currentWaveformSelection));
}
@ -1248,7 +1241,7 @@ public class WaveformView implements IWaveformView {
public void dropAccept(DropTargetEvent event) {
Point offset = canvas.toControl(event.x, event.y);
if (event.detail != DND.DROP_MOVE || offset.y > trackVerticalOffset.lastKey() + waveformCanvas.getTrackHeight()) {
if (event.detail != DND.DROP_MOVE || offset.y > trackVerticalOffset.lastKey() + styleProvider.getTrackHeight()) {
event.detail = DND.DROP_NONE;
}
}
@ -1356,11 +1349,6 @@ public class WaveformView implements IWaveformView {
return res;
}
@Override
public void setColors(HashMap<WaveformColors, RGB> colourMap) {
waveformCanvas.initColors(colourMap);
}
@Override
public long getBaselineTime() {
return -waveformCanvas.getScaleFactorPow10()*waveformCanvas.getOrigin().x;
@ -1394,8 +1382,16 @@ public class WaveformView implements IWaveformView {
}
/// probably not the way it should be done
public void addDisposeListener( DisposeListener listener ) {
@Override
public void addDisposeListener(DisposeListener listener ) {
waveformCanvas.addDisposeListener(listener);
}
@Override
public void setStyleProvider(IWaveformStyleProvider styleProvider) {
this.styleProvider=styleProvider;
waveformCanvas.setStyleProvider(styleProvider);
update();
}
}

View File

@ -152,18 +152,8 @@ public class BitVector implements IEvent {
currentWord >>= 2;
}
}
for(int i=width; i<64; i++) {
if(bitOffset==0) currentWord = packedValues[wordOffset];
res|=lastVal<<i;
bitOffset += 2;
if (bitOffset == 32) {
wordOffset++;
bitOffset = 0;
} else {
currentWord >>= 2;
}
}
if(lastVal!=0)
res |= -1l<<width;
return res;
}

View File

@ -19,7 +19,7 @@ public class HierNode implements IHierNode {
protected String name;
protected String parentName;
protected IHierNode parent = null;
protected ArrayList<IHierNode> childs;
@ -31,13 +31,14 @@ public class HierNode implements IHierNode {
}
public HierNode(String name) {
this(name, "");
}
public HierNode(String name, String parentName) {
this();
this.name=name;
this.parentName=parentName;
}
public HierNode(String name, IHierNode parent) {
this();
this.name=name;
this.parent=parent;
}
@Override
@ -53,8 +54,8 @@ public class HierNode implements IHierNode {
@Override
public String getFullName() {
if(parentName!=null && parentName.length()>0)
return parentName+"."+name;
if(parent!=null)
return parent.getFullName()+"."+name;
else
return name;
}
@ -70,8 +71,8 @@ public class HierNode implements IHierNode {
}
@Override
public void setParentName(String name) {
this.parentName=name;
public void setParent(IHierNode parent) {
this.parent=parent;
}
@Override
@ -81,7 +82,7 @@ public class HierNode implements IHierNode {
@Override
public int compareTo(IHierNode o) {
return name.compareTo(o.getName());
return getFullName().compareTo(o.getFullName());
}
}

View File

@ -39,7 +39,7 @@ public interface IHierNode extends Comparable<IHierNode>{
public void setName(String name);
public void setParentName(String name);
public void setParent(IHierNode parent);
public List<IHierNode> getChildNodes();

View File

@ -12,10 +12,9 @@ package com.minres.scviewer.database.internal;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -34,8 +33,6 @@ public class WaveformDb extends HierNode implements IWaveformDb {
private boolean loaded;
private List<IHierNode> childNodes;
private List<RelationType> relationTypes;
private Map<String, IWaveform> waveforms;
@ -93,7 +90,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
buildHierarchyNodes() ;
relationTypes.addAll(loader.getAllRelationTypes());
pcs.firePropertyChange("WAVEFORMS", null, waveforms);
pcs.firePropertyChange("CHILDS", null, childNodes);
pcs.firePropertyChange("CHILDS", null, childs);
loaded = true;
return true;
}
@ -116,7 +113,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
@Override
public void clear() {
waveforms.clear();
childNodes.clear();
childs.clear();
loaded=false;
}
@ -125,61 +122,46 @@ public class WaveformDb extends HierNode implements IWaveformDb {
}
private void buildHierarchyNodes() throws InputFormatException{
childNodes= new ArrayList<IHierNode>();
for(IWaveform stream:getAllWaves()){
//updateMaxTime(stream);
String[] hier = stream.getName().split("\\.");
IHierNode node = this;
List<String> path=new LinkedList<String>();
path.add(name);
for(String name:hier){
IHierNode n1 = null;
for(int i=0; i<hier.length-1; ++i){
String name = hier[i];
IHierNode childNode = null;
for (IHierNode n : node.getChildNodes()) {
if (n.getName().equals(name)) {
n1=n;
childNode=n;
break;
}
}
if(name.equals(hier[hier.length-1])){ //leaf
if(n1!=null) {
if(n1 instanceof HierNode){
node.getChildNodes().remove(n1);
stream.getChildNodes().addAll(n1.getChildNodes());
Collections.sort(stream.getChildNodes());
} else {
throw new InputFormatException();
}
}
stream.setName(name);
stream.setParentName(join(path, "."));
node.getChildNodes().add(stream);
Collections.sort(node.getChildNodes());
node=stream;
} else { // intermediate
if(n1 != null) {
node=n1;
} else {
HierNode newNode = new HierNode(name, join(path, "."));
node.getChildNodes().add(newNode);
Collections.sort(node.getChildNodes());
node=newNode;
}
if(childNode != null) {
node = childNode;
break;
}
path.add(name);
HierNode newNode = new HierNode(name, node);
node.getChildNodes().add(newNode);
node=newNode;
}
node.getChildNodes().add(stream);
stream.setParent(node);
stream.setName(hier[hier.length-1]);
}
sortRecursive(this);
}
private static String join(Collection<?> col, String delim) {
StringBuilder sb = new StringBuilder();
Iterator<?> iter = col.iterator();
if (iter.hasNext())
sb.append(iter.next().toString());
while (iter.hasNext()) {
sb.append(delim);
sb.append(iter.next().toString());
}
return sb.toString();
private void sortRecursive(IHierNode node) {
Collections.sort(node.getChildNodes(), new Comparator<IHierNode>() {
@Override
public int compare(IHierNode o1, IHierNode o2) {
return o1.getName().compareTo(o2.getName()); }
});
for(IHierNode n:node.getChildNodes()) {
if(n.getChildNodes().size()>0)
sortRecursive(n);
}
}
@Override

View File

@ -75,15 +75,6 @@ public class E4LifeCycle {
}
final String confFile =opt.getSet().isSet("c")?opt.getSet().getOption("c").getResultValue(0):"";
// react on the first view being created, at that time the UI is available
// eventBroker.subscribe(UIEvents.UILifeCycle.ACTIVATE, new EventHandler() {
// @Override
// public void handleEvent(Event event) {
// MPart part = (MPart) event.getProperty("ChangedElement"); //$NON-NLS-1$
// if(part!=null){
// }
// }
// });
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new EventHandler() {
@Override
public void handleEvent(Event event) {

View File

@ -38,7 +38,7 @@ public class LoadingWaveformDb implements IWaveformDb {
}
@Override
public void setParentName(String name) {
public void setParent(IHierNode name) {
}
@Override

View File

@ -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()];
}
}

View File

@ -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 {