From bedf4c5c4d4571e20a4c78fd9a0b248b19687748 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Sat, 28 Nov 2020 19:41:00 +0100 Subject: [PATCH] move settings into style provider --- .../scviewer/database/text/TxStream.groovy | 2 +- .../database/ui/IWaveformStyleProvider.java | 15 +++ .../scviewer/database/ui/IWaveformView.java | 6 +- .../database/ui/IWaveformViewFactory.java | 2 + .../ui/swt/DefaultWaveformStyleProvider.java | 87 ++++++++++++++ .../database/ui/swt/WaveformViewFactory.java | 8 +- .../ui/swt/internal/ArrowPainter.java | 18 +-- .../ui/swt/internal/CursorPainter.java | 6 +- .../ui/swt/internal/SignalPainter.java | 58 +++++----- .../ui/swt/internal/StreamPainter.java | 14 +-- .../ui/swt/internal/TrackAreaPainter.java | 2 +- .../ui/swt/internal/WaveformCanvas.java | 87 +++----------- .../ui/swt/internal/WaveformView.java | 84 +++++++------- .../minres/scviewer/database/BitVector.java | 14 +-- .../minres/scviewer/database/HierNode.java | 23 ++-- .../minres/scviewer/database/IHierNode.java | 2 +- .../database/internal/WaveformDb.java | 76 +++++------- .../scviewer/e4/application/E4LifeCycle.java | 9 -- .../application/parts/LoadingWaveformDb.java | 2 +- .../parts/WaveformStyleProvider.java | 108 ++++++++++++++++++ .../e4/application/parts/WaveformViewer.java | 17 +-- 21 files changed, 377 insertions(+), 263 deletions(-) create mode 100644 plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformStyleProvider.java create mode 100644 plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/DefaultWaveformStyleProvider.java create mode 100644 plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformStyleProvider.java diff --git a/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxStream.groovy b/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxStream.groovy index 08fd9c5..f3cdf34 100644 --- a/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxStream.groovy +++ b/plugins/com.minres.scviewer.database.text/src/com/minres/scviewer/database/text/TxStream.groovy @@ -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 diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformStyleProvider.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformStyleProvider.java new file mode 100644 index 0000000..7fcb9c1 --- /dev/null +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformStyleProvider.java @@ -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); +} diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformView.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformView.java index c3eeb49..80cc30c 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformView.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformView.java @@ -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 getCursorList(); - public void setColors(HashMap colourMap); - public long getBaselineTime(); public void setBaselineTime(Long scale); diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformViewFactory.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformViewFactory.java index 79179e1..f535534 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformViewFactory.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/IWaveformViewFactory.java @@ -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); } diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/DefaultWaveformStyleProvider.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/DefaultWaveformStyleProvider.java new file mode 100644 index 0000000..d51c920 --- /dev/null +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/DefaultWaveformStyleProvider.java @@ -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 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()]; + } + +} diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/WaveformViewFactory.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/WaveformViewFactory.java index cb197dc..fc997b2 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/WaveformViewFactory.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/WaveformViewFactory.java @@ -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); } } diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/ArrowPainter.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/ArrowPainter.java index e876b23..61d5cfd 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/ArrowPainter.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/ArrowPainter.java @@ -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) { diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/CursorPainter.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/CursorPainter.java index 1c5719f..e0778bb 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/CursorPainter.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/CursorPainter.java @@ -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); diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/SignalPainter.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/SignalPainter.java index 5538b70..a5322c4 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/SignalPainter.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/SignalPainter.java @@ -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 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 entries, Object left, boolean continous, boolean signed) { this.continous=continous; + this.signed=signed; Collection 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) { diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/StreamPainter.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/StreamPainter.java index 97230d9..2a9dc48 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/StreamPainter.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/StreamPainter.java @@ -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 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 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 firstTx=stream.getEvents().floorEntry(point.x*waveCanvas.getScaleFactor()); if(firstTx!=null){ do { diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/TrackAreaPainter.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/TrackAreaPainter.java index 0ffaf35..bee3352 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/TrackAreaPainter.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/TrackAreaPainter.java @@ -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){ diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformCanvas.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformCanvas.java index 3629bf6..afba1eb 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformCanvas.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformCanvas.java @@ -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 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(); + } } diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java index 13ccc23..648fe58 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformView.java @@ -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 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(); - 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 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 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 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 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(); + } + } diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java index 3fc72b2..edaa19d 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/BitVector.java @@ -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<>= 2; - } - - } + if(lastVal!=0) + res |= -1l< 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()); } } diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/IHierNode.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/IHierNode.java index 2900ace..66d9358 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/IHierNode.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/IHierNode.java @@ -39,7 +39,7 @@ public interface IHierNode extends Comparable{ public void setName(String name); - public void setParentName(String name); + public void setParent(IHierNode parent); public List getChildNodes(); diff --git a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/internal/WaveformDb.java b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/internal/WaveformDb.java index eec0871..a8aac38 100644 --- a/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/internal/WaveformDb.java +++ b/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/internal/WaveformDb.java @@ -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 childNodes; - private List relationTypes; private Map 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(); for(IWaveform stream:getAllWaves()){ //updateMaxTime(stream); String[] hier = stream.getName().split("\\."); IHierNode node = this; - List path=new LinkedList(); - path.add(name); - for(String name:hier){ - IHierNode n1 = null; + for(int i=0; i 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() { + @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 diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java index 054b8be..786b004 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/E4LifeCycle.java @@ -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) { diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/LoadingWaveformDb.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/LoadingWaveformDb.java index 56c69f6..1d94a5a 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/LoadingWaveformDb.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/LoadingWaveformDb.java @@ -38,7 +38,7 @@ public class LoadingWaveformDb implements IWaveformDb { } @Override - public void setParentName(String name) { + public void setParent(IHierNode name) { } @Override diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformStyleProvider.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformStyleProvider.java new file mode 100644 index 0000000..f9e0ddb --- /dev/null +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformStyleProvider.java @@ -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 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 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()]; + } + +} diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java index f0a1c35..73406b3 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java @@ -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 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 {