fix sonar lint reported issues in UI plugins

This commit is contained in:
Eyck Jentzsch 2020-11-29 12:42:51 +01:00
parent 6c5032da10
commit 70ccf35fe4
16 changed files with 254 additions and 280 deletions

View File

@ -17,7 +17,6 @@ public class TrackEntry {
IWaveformStyleProvider styleProvider; IWaveformStyleProvider styleProvider;
public enum ValueDisplay { public enum ValueDisplay {
DEFAULT, SIGNED, UNSIGNED DEFAULT, SIGNED, UNSIGNED
@ -49,10 +48,6 @@ public class TrackEntry {
selected=false; selected=false;
} }
public IWaveform getWaveform(){
return waveform;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj instanceof TrackEntry){ if(obj instanceof TrackEntry){

View File

@ -2,11 +2,13 @@ package com.minres.scviewer.database.ui.swt;
public class Constants { public class Constants {
public static final String[] unitString={"fs", "ps", "ns", "us", "ms"};//, "s"}; public static final String[] UNIT_STRING={"fs", "ps", "ns", "us", "ms"};//, "s"};
public static final int[] unitMultiplier={1, 3, 10, 30, 100, 300}; public static final int[] UNIT_MULTIPLIER={1, 3, 10, 30, 100, 300};
public static final String CONTENT_PROVIDER_TAG = "TOOLTIP_CONTENT_PROVIDER"; public static final String CONTENT_PROVIDER_TAG = "TOOLTIP_CONTENT_PROVIDER";
public static final String HELP_PROVIDER_TAG = "TOOLTIP_HELP_PROVIDER"; public static final String HELP_PROVIDER_TAG = "TOOLTIP_HELP_PROVIDER";
private Constants() {}
} }

View File

@ -17,10 +17,12 @@ import org.osgi.framework.BundleContext;
public class DatabaseUiPlugin extends Plugin { public class DatabaseUiPlugin extends Plugin {
@Override
public void start(BundleContext context) throws Exception { public void start(BundleContext context) throws Exception {
getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Starting org.eclipse.e4.core bundle...")); getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Starting org.eclipse.e4.core bundle..."));
} }
@Override
public void stop(BundleContext context) throws Exception { public void stop(BundleContext context) throws Exception {
getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Stopping org.eclipse.e4.core bundle...")); getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Stopping org.eclipse.e4.core bundle..."));
} }

View File

@ -1,6 +1,6 @@
package com.minres.scviewer.database.ui.swt; package com.minres.scviewer.database.ui.swt;
import java.util.HashMap; import java.util.Map;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
@ -54,7 +54,7 @@ public class DefaultWaveformStyleProvider implements IWaveformStyleProvider {
* needs redraw() afterwards * needs redraw() afterwards
* @param colourMap * @param colourMap
*/ */
public void initColors(HashMap<WaveformColors, RGB> colourMap) { public void initColors(Map<WaveformColors, RGB> colourMap) {
Display d = parent.getDisplay(); Display d = parent.getDisplay();
if (colourMap != null) { if (colourMap != null) {
for (WaveformColors c : WaveformColors.values()) { for (WaveformColors c : WaveformColors.values()) {
@ -80,7 +80,6 @@ public class DefaultWaveformStyleProvider implements IWaveformStyleProvider {
} }
@Override @Override
public Color getColor(WaveformColors type) { public Color getColor(WaveformColors type) {
// TODO Auto-generated method stub
return colors[type.ordinal()]; return colors[type.ordinal()];
} }
@Override @Override

View File

@ -28,7 +28,7 @@ import com.minres.scviewer.database.ui.WaveformColors;
public class ArrowPainter implements IPainter { public class ArrowPainter implements IPainter {
private final int xCtrlOffset = 50; private static final float X_CTRL_OFFSET = 50;
private int yCtrlOffset = 30; private int yCtrlOffset = 30;
@ -151,10 +151,10 @@ public class ArrowPainter implements IPainter {
path.moveTo(point1.x, point1.y); path.moveTo(point1.x, point1.y);
if (point1.y == point2.y) { if (point1.y == point2.y) {
Point center = new Point((point1.x + point2.x) / 2, point1.y - yCtrlOffset); Point center = new Point((point1.x + point2.x) / 2, point1.y - yCtrlOffset);
path.cubicTo(point1.x + xCtrlOffset, point1.y, center.x - xCtrlOffset, center.y, center.x, center.y); path.cubicTo(point1.x + X_CTRL_OFFSET, point1.y, center.x - X_CTRL_OFFSET, center.y, center.x, center.y);
path.cubicTo(center.x + xCtrlOffset, center.y, point2.x - xCtrlOffset, point2.y, point2.x, point2.y); path.cubicTo(center.x + X_CTRL_OFFSET, center.y, point2.x - X_CTRL_OFFSET, point2.y, point2.x, point2.y);
} else } else
path.cubicTo(point1.x + xCtrlOffset, point1.y, point2.x - xCtrlOffset, point2.y, point2.x, point2.y); path.cubicTo(point1.x + X_CTRL_OFFSET, point1.y, point2.x - X_CTRL_OFFSET, point2.y, point2.x, point2.y);
proj.setAntialias(SWT.ON); proj.setAntialias(SWT.ON);
proj.setForeground(fgColor); proj.setForeground(fgColor);
@ -167,8 +167,8 @@ public class ArrowPainter implements IPainter {
} }
class LinkEntry { class LinkEntry {
public Rectangle rectangle; public final Rectangle rectangle;
public RelationType relationType; public final RelationType relationType;
public LinkEntry(Rectangle rectangle, RelationType relationType) { public LinkEntry(Rectangle rectangle, RelationType relationType) {
super(); super();

View File

@ -63,7 +63,7 @@ public class CursorPainter implements IPainter, ICursor {
public void paintArea(Projection proj, Rectangle clientRect) { public void paintArea(Projection proj, Rectangle clientRect) {
Rectangle area = proj.unProject(clientRect); Rectangle area = proj.unProject(clientRect);
if(this.waveCanvas.painterList.size()>0){ if(!waveCanvas.painterList.isEmpty()){
long scaleFactor=waveCanvas.getScaleFactor(); long scaleFactor=waveCanvas.getScaleFactor();
long beginPos = area.x; long beginPos = area.x;
@ -83,7 +83,7 @@ public class CursorPainter implements IPainter, ICursor {
proj.drawLine(x, top, x, area.y+area.height); proj.drawLine(x, top, x, area.y+area.height);
proj.setBackground(drawColor); proj.setBackground(drawColor);
proj.setForeground(textColor); proj.setForeground(textColor);
Double dTime=new Double(time); double dTime=time;
proj.drawText((dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top); proj.drawText((dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top);
} }
} }

View File

@ -27,7 +27,7 @@ public class ObservableList<E> implements List<E> {
public static final String CONTENT_PROPERTY = "content"; public static final String CONTENT_PROPERTY = "content";
public ObservableList() { public ObservableList() {
this(new ArrayList<E>()); this(new ArrayList<>());
} }
public ObservableList(List<E> delegate) { public ObservableList(List<E> delegate) {
@ -100,7 +100,7 @@ public class ObservableList<E> implements List<E> {
boolean success = this.delegate.addAll(c); boolean success = this.delegate.addAll(c);
if ((success) && (c != null)) { if ((success) && (c != null)) {
List<E> values = new ArrayList<E>(); List<E> values = new ArrayList<>();
for (Iterator<? extends E> i = c.iterator(); i.hasNext();) { for (Iterator<? extends E> i = c.iterator(); i.hasNext();) {
values.add(i.next()); values.add(i.next());
} }
@ -118,7 +118,7 @@ public class ObservableList<E> implements List<E> {
boolean success = this.delegate.addAll(index, c); boolean success = this.delegate.addAll(index, c);
if ((success) && (c != null)) { if ((success) && (c != null)) {
List<E> values = new ArrayList<E>(); List<E> values = new ArrayList<>();
for (Iterator<? extends E> i = c.iterator(); i.hasNext();) { for (Iterator<? extends E> i = c.iterator(); i.hasNext();) {
values.add(i.next()); values.add(i.next());
} }
@ -133,7 +133,7 @@ public class ObservableList<E> implements List<E> {
public void clear() { public void clear() {
int oldSize = size(); int oldSize = size();
List<E> values = new ArrayList<E>(); List<E> values = new ArrayList<>();
values.addAll(this.delegate); values.addAll(this.delegate);
this.delegate.clear(); this.delegate.clear();
if (!(values.isEmpty())) { if (!(values.isEmpty())) {
@ -215,8 +215,7 @@ public class ObservableList<E> implements List<E> {
return false; return false;
} }
List<E> values = new ArrayList<E>(); List<E> values = new ArrayList<>();
if (c != null) {
for (Iterator<?> i = c.iterator(); i.hasNext();) { for (Iterator<?> i = c.iterator(); i.hasNext();) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
E element = (E) i.next(); E element = (E) i.next();
@ -224,7 +223,6 @@ public class ObservableList<E> implements List<E> {
values.add(element); values.add(element);
} }
} }
}
int oldSize = size(); int oldSize = size();
boolean success = this.delegate.removeAll(c); boolean success = this.delegate.removeAll(c);
@ -241,16 +239,14 @@ public class ObservableList<E> implements List<E> {
return false; return false;
} }
List<E> values = new ArrayList<E>(); List<E> values = new ArrayList<>();
Iterator<? extends E> i; Iterator<? extends E> i;
if (c != null) {
for (i = this.delegate.iterator(); i.hasNext();) { for (i = this.delegate.iterator(); i.hasNext();) {
E element = i.next(); E element = i.next();
if (!(c.contains(element))) { if (!(c.contains(element))) {
values.add(element); values.add(element);
} }
} }
}
int oldSize = size(); int oldSize = size();
boolean success = this.delegate.retainAll(c); boolean success = this.delegate.retainAll(c);
@ -327,7 +323,7 @@ public class ObservableList<E> implements List<E> {
*/ */
private static final long serialVersionUID = 7819626246672640599L; private static final long serialVersionUID = 7819626246672640599L;
private List<Object> values = new ArrayList<Object>(); private List<Object> values = new ArrayList<>();
public MultiElementUpdatedEvent(Object source, List<?> values) { public MultiElementUpdatedEvent(Object source, List<?> values) {
super(source, ObservableList.ChangeType.oldValue, ObservableList.ChangeType.newValue, 0, super(source, ObservableList.ChangeType.oldValue, ObservableList.ChangeType.newValue, 0,
@ -336,7 +332,7 @@ public class ObservableList<E> implements List<E> {
this.values.addAll(values); this.values.addAll(values);
} }
public List<?> getValues() { public List<Object> getValues() {
return Collections.unmodifiableList(this.values); return Collections.unmodifiableList(this.values);
} }
} }
@ -347,7 +343,7 @@ public class ObservableList<E> implements List<E> {
*/ */
private static final long serialVersionUID = 7819626246672640599L; private static final long serialVersionUID = 7819626246672640599L;
private List<Object> values = new ArrayList<Object>(); private List<Object> values = new ArrayList<>();
public MultiElementRemovedEvent(Object source, List<?> values) { public MultiElementRemovedEvent(Object source, List<?> values) {
super(source, ObservableList.ChangeType.oldValue, ObservableList.ChangeType.newValue, 0, super(source, ObservableList.ChangeType.oldValue, ObservableList.ChangeType.newValue, 0,
@ -356,7 +352,7 @@ public class ObservableList<E> implements List<E> {
this.values.addAll(values); this.values.addAll(values);
} }
public List<?> getValues() { public List<Object> getValues() {
return Collections.unmodifiableList(this.values); return Collections.unmodifiableList(this.values);
} }
} }
@ -366,7 +362,7 @@ public class ObservableList<E> implements List<E> {
* *
*/ */
private static final long serialVersionUID = -116376519087713082L; private static final long serialVersionUID = -116376519087713082L;
private List<Object> values = new ArrayList<Object>(); private List<Object> values = new ArrayList<>();
public MultiElementAddedEvent(Object source, int index, List<?> values) { public MultiElementAddedEvent(Object source, int index, List<?> values) {
super(source, ObservableList.ChangeType.oldValue, ObservableList.ChangeType.newValue, index, super(source, ObservableList.ChangeType.oldValue, ObservableList.ChangeType.newValue, index,
@ -375,7 +371,7 @@ public class ObservableList<E> implements List<E> {
this.values.addAll(values); this.values.addAll(values);
} }
public List<?> getValues() { public List<Object> getValues() {
return Collections.unmodifiableList(this.values); return Collections.unmodifiableList(this.values);
} }
} }
@ -385,7 +381,7 @@ public class ObservableList<E> implements List<E> {
* *
*/ */
private static final long serialVersionUID = -8654027608903811577L; private static final long serialVersionUID = -8654027608903811577L;
private List<Object> values = new ArrayList<Object>(); private List<Object> values = new ArrayList<>();
public ElementClearedEvent(Object source, List<?> values) { public ElementClearedEvent(Object source, List<?> values) {
super(source, ObservableList.ChangeType.oldValue, ObservableList.ChangeType.newValue, 0, super(source, ObservableList.ChangeType.oldValue, ObservableList.ChangeType.newValue, 0,
@ -394,7 +390,7 @@ public class ObservableList<E> implements List<E> {
this.values.addAll(values); this.values.addAll(values);
} }
public List<?> getValues() { public List<Object> getValues() {
return Collections.unmodifiableList(this.values); return Collections.unmodifiableList(this.values);
} }
} }
@ -432,7 +428,7 @@ public class ObservableList<E> implements List<E> {
} }
} }
public static abstract class ElementEvent extends PropertyChangeEvent { public abstract static class ElementEvent extends PropertyChangeEvent {
/** /**
* *
*/ */
@ -441,7 +437,7 @@ public class ObservableList<E> implements List<E> {
private final int index; private final int index;
public ElementEvent(Object source, Object oldValue, Object newValue, int index, ObservableList.ChangeType type) { public ElementEvent(Object source, Object oldValue, Object newValue, int index, ObservableList.ChangeType type) {
super(source, "content", oldValue, newValue); super(source, CONTENT_PROPERTY, oldValue, newValue);
this.type = type; this.type = type;
this.index = index; this.index = index;
} }
@ -463,7 +459,7 @@ public class ObservableList<E> implements List<E> {
} }
} }
public static enum ChangeType { public enum ChangeType {
ADDED, UPDATED, REMOVED, CLEARED, MULTI_ADD, MULTI_UPDATED, MULTI_REMOVE, NONE; ADDED, UPDATED, REMOVED, CLEARED, MULTI_ADD, MULTI_UPDATED, MULTI_REMOVE, NONE;
public static final Object oldValue; public static final Object oldValue;
@ -483,10 +479,10 @@ public class ObservableList<E> implements List<E> {
return MULTI_REMOVE; return MULTI_REMOVE;
case 6: case 6:
return NONE; return NONE;
case 1: default:
}
return UPDATED; return UPDATED;
} }
}
static { static {
oldValue = new Object(); oldValue = new Object();
@ -554,6 +550,7 @@ public class ObservableList<E> implements List<E> {
return this.iterDelegate.next(); return this.iterDelegate.next();
} }
@Override
public void remove() { public void remove() {
int oldSize = ObservableList.this.size(); int oldSize = ObservableList.this.size();
Object element = ObservableList.this.get(this.cursor); Object element = ObservableList.this.get(this.cursor);

View File

@ -24,7 +24,7 @@ class RelSelectionDialog extends Dialog {
private ITxRelation selected = null; private ITxRelation selected = null;
public RelSelectionDialog(Shell shell, ArrayList<ITxRelation> candidates, boolean target) { public RelSelectionDialog(Shell shell, java.util.List<ITxRelation> candidates, boolean target) {
super(shell); super(shell);
entries = candidates; entries = candidates;
entryTx = entries.stream().map(r->target?r.getTarget():r.getSource()).collect(Collectors.toCollection(ArrayList::new)); entryTx = entries.stream().map(r->target?r.getTarget():r.getSource()).collect(Collectors.toCollection(ArrayList::new));

View File

@ -21,8 +21,8 @@ import org.eclipse.wb.swt.SWTResourceManager;
public class RulerPainter implements IPainter { public class RulerPainter implements IPainter {
protected WaveformCanvas waveCanvas; protected WaveformCanvas waveCanvas;
static final int rulerTickMinorC = 10; static final int RULER_TICK_MINOR = 10;
static final int rulerTickMajorC = 100; static final int RULER_TICK_MAJOR = 100;
static final DecimalFormat df = new DecimalFormat("#.00####"); static final DecimalFormat df = new DecimalFormat("#.00####");
@ -47,8 +47,8 @@ public class RulerPainter implements IPainter {
long startVal=startPos - proj.getTranslation().x*scaleFactor; long startVal=startPos - proj.getTranslation().x*scaleFactor;
long endPos=startPos+area.width*scaleFactor; long endPos=startPos+area.width*scaleFactor;
long rulerTickMinor = rulerTickMinorC*scaleFactor; long rulerTickMinor = RULER_TICK_MINOR*scaleFactor;
long rulerTickMajor = rulerTickMajorC*scaleFactor; long rulerTickMajor = RULER_TICK_MAJOR*scaleFactor;
int minorTickY = waveCanvas.rulerHeight-5; int minorTickY = waveCanvas.rulerHeight-5;
int majorTickY = waveCanvas.rulerHeight-15; int majorTickY = waveCanvas.rulerHeight-15;
@ -68,13 +68,13 @@ public class RulerPainter implements IPainter {
gc.drawLine(area.x, area.y+bottom, area.x+area.width, area.y+bottom); gc.drawLine(area.x, area.y+bottom, area.x+area.width, area.y+bottom);
for (long pos = startMinorIncrPos, tick = startMinorIncrVal; pos < endPos; pos+= rulerTickMinor, tick += rulerTickMinor) { for (long pos = startMinorIncrPos, tick = startMinorIncrVal; pos < endPos; pos+= rulerTickMinor, tick += rulerTickMinor) {
int x0_pos = (int) (pos/scaleFactor); int x0Pos = (int) (pos/scaleFactor);
long x0_val = tick/scaleFactor; long x0Val = tick/scaleFactor;
if ((tick % rulerTickMajor) == 0) { if ((tick % rulerTickMajor) == 0) {
gc.drawText(df.format(x0_val*unitMultiplier)+unit, x0_pos, area.y+textY); gc.drawText(df.format(x0Val*unitMultiplier)+unit, x0Pos, area.y+textY);
gc.drawLine(x0_pos, area.y+majorTickY, x0_pos,area.y+ bottom); gc.drawLine(x0Pos, area.y+majorTickY, x0Pos,area.y+ bottom);
} else { } else {
gc.drawLine(x0_pos, area.y+minorTickY, x0_pos, area.y+bottom); gc.drawLine(x0Pos, area.y+minorTickY, x0Pos, area.y+bottom);
} }
} }
} }

View File

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database.ui.swt.internal; package com.minres.scviewer.database.ui.swt.internal;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NavigableMap; import java.util.NavigableMap;
@ -140,7 +141,7 @@ public class SignalPainter extends TrackPainter {
SignalStencil stencil = getStencil(proj.getGC(), left, entries); SignalStencil stencil = getStencil(proj.getGC(), left, entries);
do { if(stencil!=null) do {
stencil.draw(proj, area, left.value, right.value, xSigChangeBeginPos, xSigChangeEndPos, multiple); stencil.draw(proj, area, left.value, right.value, xSigChangeBeginPos, xSigChangeEndPos, multiple);
if (right.time >= endTime) if (right.time >= endTime)
break; break;
@ -197,9 +198,9 @@ public class SignalPainter extends TrackPainter {
public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, IEvent left, IEvent right, int xBegin, int xEnd, boolean multiple) {
Color colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL0); Color colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL0);
BitVector last = (BitVector) left; BitVector last = (BitVector) left;
if (last.getValue().toString().contains("X")) { if (Arrays.toString(last.getValue()).contains("X")) {
colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNALX); colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNALX);
} else if (last.getValue().toString().contains("Z")) { } else if (Arrays.toString(last.getValue()).contains("Z")) {
colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNALZ); colorBorder = waveCanvas.styleProvider.getColor(WaveformColors.SIGNALZ);
} }
int width = xEnd - xBegin; int width = xEnd - xBegin;
@ -215,7 +216,6 @@ public class SignalPainter extends TrackPainter {
proj.setForeground(colorBorder); proj.setForeground(colorBorder);
proj.drawPolygon(points); proj.drawPolygon(points);
proj.setForeground(waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL_TEXT)); proj.setForeground(waveCanvas.styleProvider.getColor(WaveformColors.SIGNAL_TEXT));
//TODO: this code should be provided from a central location
String label = null; String label = null;
switch(trackEntry.valueDisplay) { switch(trackEntry.valueDisplay) {
case SIGNED: case SIGNED:
@ -351,7 +351,8 @@ public class SignalPainter extends TrackPainter {
private class RealStencil implements SignalStencil { private class RealStencil implements SignalStencil {
double minVal, range; double minVal;
double range;
final double scaleFactor = 1.05; final double scaleFactor = 1.05;
@ -359,13 +360,14 @@ public class SignalPainter extends TrackPainter {
public RealStencil(NavigableMap<Long, IEvent[]> entries, Object left, boolean continous) { public RealStencil(NavigableMap<Long, IEvent[]> entries, Object left, boolean continous) {
this.continous=continous; this.continous=continous;
Collection<IEvent[]> values = ((NavigableMap<Long, IEvent[]>) entries).values(); Collection<IEvent[]> values = entries.values();
minVal=(Double) left; minVal=(Double) left;
range=2.0; range=2.0;
if(!values.isEmpty()) { if(!values.isEmpty()) {
double maxVal=minVal; double maxVal=minVal;
for (Object e : entries.values()) { for (IEvent[] val : entries.values())
double v = ((Double)e); for(IEvent e:val) {
double v = ((DoubleVal)e).value;
if(Double.isNaN(maxVal)) if(Double.isNaN(maxVal))
maxVal=v; maxVal=v;
else if(!Double.isNaN(v)) else if(!Double.isNaN(v))

View File

@ -35,15 +35,15 @@ public class StreamPainter extends TrackPainter{
*/ */
private final WaveformCanvas waveCanvas; private final WaveformCanvas waveCanvas;
private IWaveform stream; private IWaveform stream;
private int txBase, txHeight; private int txBase;
private boolean even; private int txHeight;
private TreeSet<ITx> seenTx; private TreeSet<ITx> seenTx;
public StreamPainter(WaveformCanvas waveCanvas, boolean even, TrackEntry trackEntry) { public StreamPainter(WaveformCanvas waveCanvas, boolean even, TrackEntry trackEntry) {
super(trackEntry, even); super(trackEntry, even);
this.waveCanvas = waveCanvas; this.waveCanvas = waveCanvas;
this.stream=trackEntry.waveform; this.stream=trackEntry.waveform;
this.seenTx=new TreeSet<ITx>(); this.seenTx=new TreeSet<>();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -63,7 +63,6 @@ public class StreamPainter extends TrackPainter{
long scaleFactor = this.waveCanvas.getScaleFactor(); long scaleFactor = this.waveCanvas.getScaleFactor();
long beginPos = area.x; long beginPos = area.x;
long beginTime = beginPos*scaleFactor; long beginTime = beginPos*scaleFactor;
//long endPos = beginPos + area.width;
long endTime = beginTime + area.width*scaleFactor; long endTime = beginTime + area.width*scaleFactor;
Entry<Long, ?> firstTx=stream.getEvents().floorEntry(beginTime); Entry<Long, ?> firstTx=stream.getEvents().floorEntry(beginTime);
@ -127,11 +126,11 @@ public class StreamPainter extends TrackPainter{
bb.width = bb.width-(area.x-bb.x)+5; bb.width = bb.width-(area.x-bb.x)+5;
bb.x=area.x-5; bb.x=area.x-5;
} }
int bb_x2 = bb.x+bb.width; int bbX2 = bb.x+bb.width;
int area_x2 = area.x+area.width; int areaX2 = area.x+area.width;
if(bb_x2>area_x2){ if(bbX2>areaX2){
bb_x2=area_x2+5; bbX2=areaX2+5;
bb.width= bb_x2-bb.x; bb.width= bbX2-bb.x;
} }
int arc = bb.width<10?1:5; int arc = bb.width<10?1:5;
proj.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, arc, arc); proj.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, arc, arc);

View File

@ -26,7 +26,7 @@ class ToolTipHandler {
private Widget tipWidget; // widget this tooltip is hovering over private Widget tipWidget; // widget this tooltip is hovering over
private Point tipPosition; // the position being hovered over private Point tipPosition; // the position being hovered over
private static final int hoverYOffset = 1; private static final int HOVER_YOFFSET = 1;
/** /**
* Creates a new tooltip handler * Creates a new tooltip handler
@ -45,56 +45,57 @@ class ToolTipHandler {
*/ */
public void activateHoverHelp(final Control control) { public void activateHoverHelp(final Control control) {
Listener listener = new Listener () { Listener listener = new Listener () {
Shell tip = null; Shell shell = null;
@Override @Override
public void handleEvent (Event event) { public void handleEvent (Event event) {
switch (event.type) { switch (event.type) {
case SWT.KeyDown:{ case SWT.KeyDown:
if (tip != null && tip.isVisible() && event.keyCode == SWT.F2) { if (shell != null && shell.isVisible() && event.keyCode == SWT.F2)
tip.setFocus(); shell.setFocus();
break; break;
}
}
case SWT.Dispose: case SWT.Dispose:
case SWT.MouseMove: case SWT.MouseMove:
case SWT.MouseDown: { case SWT.MouseDown:
if (tip != null){ if (shell != null){
tip.dispose (); shell.dispose ();
tip = null; shell = null;
tipWidget=null; tipWidget=null;
} }
break; break;
case SWT.MouseHover:
createHoverWindow(control, event);
break;
default:
/* do nothing */
} }
case SWT.MouseHover: { }
private void createHoverWindow(final Control control, Event event) {
Object o = control.getData(Constants.CONTENT_PROVIDER_TAG); Object o = control.getData(Constants.CONTENT_PROVIDER_TAG);
if(o != null && o instanceof ToolTipContentProvider) { if(o instanceof ToolTipContentProvider) {
ToolTipContentProvider provider = ((ToolTipContentProvider)o); ToolTipContentProvider provider = ((ToolTipContentProvider)o);
Point pt = new Point (event.x, event.y); Point pt = new Point (event.x, event.y);
tipPosition = control.toDisplay(pt); tipPosition = control.toDisplay(pt);
if (tip != null && !tip.isDisposed ()) tip.dispose (); if (shell != null && !shell.isDisposed ()) shell.dispose ();
tip = new Shell (parentShell, SWT.NO_FOCUS | SWT.TOOL); shell = new Shell (parentShell, SWT.NO_FOCUS | SWT.TOOL);
tip.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND)); shell.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
GridLayout layout = new GridLayout(1, true); GridLayout layout = new GridLayout(1, true);
layout.verticalSpacing=0; layout.verticalSpacing=0;
layout.horizontalSpacing=0; layout.horizontalSpacing=0;
layout.marginWidth = 0; layout.marginWidth = 0;
layout.marginHeight = 0; layout.marginHeight = 0;
tip.setLayout(layout); shell.setLayout(layout);
boolean visible = provider.createContent(tip, pt); boolean visible = provider.createContent(shell, pt);
tip.pack(); shell.pack();
tip.setSize(tip.computeSize(SWT.DEFAULT, SWT.DEFAULT)); shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT));
setHoverLocation(tip, tipPosition); setHoverLocation(shell, tipPosition);
tip.setVisible (visible); shell.setVisible (visible);
if(visible) if(visible)
tipWidget=event.widget; tipWidget=event.widget;
} }
} }
}
}
}; };
control.addListener (SWT.Dispose, listener); control.addListener (SWT.Dispose, listener);
control.addListener (SWT.KeyDown, listener); control.addListener (SWT.KeyDown, listener);
//control.addListener (SWT.MouseMove, listener);
control.addListener (SWT.MouseHover, listener); control.addListener (SWT.MouseHover, listener);
control.addListener (SWT.MouseDown, listener); control.addListener (SWT.MouseDown, listener);
@ -119,11 +120,6 @@ class ToolTipHandler {
helpShell.open(); helpShell.open();
} }
}); });
// control.addKeyListener(KeyListener.keyPressedAdapter( e-> {
// if (e.keyCode == SWT.F2 && shell.isVisible()) {
// shell.setFocus();
// }
// }));
} }
/** /**
@ -136,7 +132,7 @@ class ToolTipHandler {
Rectangle displayBounds = shell.getDisplay().getBounds(); Rectangle displayBounds = shell.getDisplay().getBounds();
Rectangle shellBounds = shell.getBounds(); Rectangle shellBounds = shell.getBounds();
shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0); shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0);
shellBounds.y = Math.max(Math.min(position.y + hoverYOffset, displayBounds.height - shellBounds.height), 0); shellBounds.y = Math.max(Math.min(position.y + HOVER_YOFFSET, displayBounds.height - shellBounds.height), 0);
shell.setBounds(shellBounds); shell.setBounds(shellBounds);
} }
} }

View File

@ -25,7 +25,7 @@ public class TrackAreaPainter implements IPainter {
*/ */
private final WaveformCanvas waveCanvas; private final WaveformCanvas waveCanvas;
TreeMap<Integer, IWaveformPainter> trackVerticalOffset; final TreeMap<Integer, IWaveformPainter> trackVerticalOffset;
/** /**
* @param txDisplay * @param txDisplay
*/ */
@ -44,7 +44,7 @@ public class TrackAreaPainter implements IPainter {
if(firstKey==null) firstKey=trackVerticalOffset.firstKey(); if(firstKey==null) firstKey=trackVerticalOffset.firstKey();
Integer lastKey = trackVerticalOffset.floorKey(area.y+area.height); Integer lastKey = trackVerticalOffset.floorKey(area.y+area.height);
Rectangle subArea = new Rectangle(area.x, 0, area.width, 0); Rectangle subArea = new Rectangle(area.x, 0, area.width, 0);
if(lastKey==firstKey){ if(lastKey.equals(firstKey)){
subArea.y=firstKey; subArea.y=firstKey;
IWaveformPainter p = trackVerticalOffset.get(firstKey); IWaveformPainter p = trackVerticalOffset.get(firstKey);
subArea.height=p.getHeight(); subArea.height=p.getHeight();
@ -59,10 +59,6 @@ public class TrackAreaPainter implements IPainter {
} }
} }
public TreeMap<Integer, IWaveformPainter> getTrackVerticalOffset() {
return trackVerticalOffset;
}
public void addTrackPainter(IWaveformPainter trackPainter){ public void addTrackPainter(IWaveformPainter trackPainter){
trackVerticalOffset.put(trackPainter.getVerticalOffset()+waveCanvas.rulerHeight, trackPainter); trackVerticalOffset.put(trackPainter.getVerticalOffset()+waveCanvas.rulerHeight, trackPainter);

View File

@ -20,7 +20,6 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
@ -86,16 +85,13 @@ public class WaveformCanvas extends Canvas {
super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.V_SCROLL | SWT.H_SCROLL); super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.V_SCROLL | SWT.H_SCROLL);
this.styleProvider=styleProvider; this.styleProvider=styleProvider;
addControlListener(new ControlAdapter() { /* resize listener. */ addControlListener(new ControlAdapter() { /* resize listener. */
@Override
public void controlResized(ControlEvent event) { public void controlResized(ControlEvent event) {
syncScrollBars(); syncScrollBars();
} }
}); });
addPaintListener(new PaintListener() { /* paint listener. */ addPaintListener((final PaintEvent event) -> paint(event.gc));
public void paintControl(final PaintEvent event) { painterList = new LinkedList<>();
paint(event.gc);
}
});
painterList = new LinkedList<IPainter>();
origin = new Point(0, 0); origin = new Point(0, 0);
selectionListeners = new LinkedList<>(); selectionListeners = new LinkedList<>();
cursorPainters= new ArrayList<>(); cursorPainters= new ArrayList<>();
@ -169,7 +165,7 @@ public class WaveformCanvas extends Canvas {
} }
public int getMaxZoomLevel(){ public int getMaxZoomLevel(){
return Constants.unitMultiplier.length*Constants.unitString.length-1; return Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length-1;
} }
public void setZoomLevel(int level) { public void setZoomLevel(int level) {
@ -181,8 +177,8 @@ public class WaveformCanvas extends Canvas {
//FIXME: keep center if zoom-out and cursor is not in view //FIXME: keep center if zoom-out and cursor is not in view
long oldScaleFactor=scaleFactor; long oldScaleFactor=scaleFactor;
if(level<0) level = 0; if(level<0) level = 0;
if(level<Constants.unitMultiplier.length*Constants.unitString.length){ if(level<Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length){
this.scaleFactor = (long) Math.pow(10, level/2); this.scaleFactor = (long) Math.pow(10, level/2d);
if(level%2==1) this.scaleFactor*=3; if(level%2==1) this.scaleFactor*=3;
ITx tx = arrowPainter.getTx(); ITx tx = arrowPainter.getTx();
arrowPainter.setTx(null); arrowPainter.setTx(null);
@ -213,17 +209,17 @@ public class WaveformCanvas extends Canvas {
} }
public long getScaleFactorPow10() { public long getScaleFactorPow10() {
int scale = level/Constants.unitMultiplier.length; int scale = level/Constants.UNIT_MULTIPLIER.length;
double res = Math.pow(1000, scale); double res = Math.pow(1000, scale);
return (long) res; return (long) res;
} }
public String getUnitStr(){ public String getUnitStr(){
return Constants.unitString[level/Constants.unitMultiplier.length]; return Constants.UNIT_STRING[level/Constants.UNIT_MULTIPLIER.length];
} }
public int getUnitMultiplier(){ public int getUnitMultiplier(){
return Constants.unitMultiplier[level%Constants.unitMultiplier.length]; return Constants.UNIT_MULTIPLIER[level%Constants.UNIT_MULTIPLIER.length];
} }
public long getTimeForOffset(int xOffset){ public long getTimeForOffset(int xOffset){
@ -245,7 +241,7 @@ public class WaveformCanvas extends Canvas {
} }
void clearAllWaveformPainter(boolean update) { void clearAllWaveformPainter(boolean update) {
trackAreaPainter.getTrackVerticalOffset().clear(); trackAreaPainter.trackVerticalOffset.clear();
wave2painterMap.clear(); wave2painterMap.clear();
if(update) syncScrollBars(); if(update) syncScrollBars();
} }
@ -270,8 +266,9 @@ public class WaveformCanvas extends Canvas {
horizontal.setEnabled(false); horizontal.setEnabled(false);
horizontal.setVisible(true); horizontal.setVisible(true);
horizontal.addSelectionListener(new SelectionAdapter() { horizontal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
if (painterList.size() == 0) if (painterList.isEmpty())
return; return;
setOrigin(-((ScrollBar) event.widget).getSelection(), origin.y); setOrigin(-((ScrollBar) event.widget).getSelection(), origin.y);
} }
@ -280,8 +277,9 @@ public class WaveformCanvas extends Canvas {
vertical.setEnabled(false); vertical.setEnabled(false);
vertical.setVisible(true); vertical.setVisible(true);
vertical.addSelectionListener(new SelectionAdapter() { vertical.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
if (painterList.size() == 0) if (painterList.isEmpty())
return; return;
setOrigin(origin.x, -((ScrollBar) event.widget).getSelection()); setOrigin(origin.x, -((ScrollBar) event.widget).getSelection());
} }
@ -294,7 +292,7 @@ public class WaveformCanvas extends Canvas {
* :<b> transform, image size, client area</b>. * :<b> transform, image size, client area</b>.
*/ */
public void syncScrollBars() { public void syncScrollBars() {
if (painterList.size() == 0) { if (painterList.isEmpty()) {
redraw(); redraw();
return; return;
} }
@ -302,14 +300,14 @@ public class WaveformCanvas extends Canvas {
long width = maxTime / scaleFactor; long width = maxTime / scaleFactor;
Rectangle clientArea=getClientArea(); Rectangle clientArea=getClientArea();
ScrollBar horizontal = getHorizontalBar(); ScrollBar horizontal = getHorizontalBar();
horizontal.setIncrement((int) (getClientArea().width / 100)); horizontal.setIncrement(getClientArea().width / 100);
horizontal.setPageIncrement(getClientArea().width); horizontal.setPageIncrement(getClientArea().width);
int clientWidthw = clientArea.width; int clientWidthw = clientArea.width;
if (width > clientWidthw) { /* image is wider than client area */ if (width > clientWidthw) { /* image is wider than client area */
horizontal.setMinimum(0); horizontal.setMinimum(0);
horizontal.setMaximum((int)width); horizontal.setMaximum((int)width);
horizontal.setEnabled(true); horizontal.setEnabled(true);
if (((int) -origin.x) > horizontal.getMaximum() - clientWidthw) { if (-origin.x > horizontal.getMaximum() - clientWidthw) {
origin.x = -horizontal.getMaximum() + clientWidthw; origin.x = -horizontal.getMaximum() + clientWidthw;
} }
} else { /* image is narrower than client area */ } else { /* image is narrower than client area */
@ -319,18 +317,18 @@ public class WaveformCanvas extends Canvas {
horizontal.setSelection(-origin.x); horizontal.setSelection(-origin.x);
ScrollBar vertical = getVerticalBar(); ScrollBar vertical = getVerticalBar();
vertical.setIncrement((int) (getClientArea().height / 100)); vertical.setIncrement(getClientArea().height / 100);
vertical.setPageIncrement((int) (getClientArea().height)); vertical.setPageIncrement(getClientArea().height);
int clientHeighth = clientArea.height; int clientHeighth = clientArea.height;
if (height > clientHeighth) { /* image is higher than client area */ if (height > clientHeighth) { /* image is higher than client area */
vertical.setMinimum(0); vertical.setMinimum(0);
vertical.setMaximum(height); vertical.setMaximum(height);
vertical.setEnabled(true); vertical.setEnabled(true);
if (((int) -origin.y) > vertical.getMaximum() - clientHeighth) { if ( -origin.y > vertical.getMaximum() - clientHeighth) {
origin.y = -vertical.getMaximum() + clientHeighth; origin.y = -vertical.getMaximum() + clientHeighth;
} }
} else { /* image is less higher than client area */ } else { /* image is less higher than client area */
vertical.setMaximum((int) (clientHeighth)); vertical.setMaximum(clientHeighth);
vertical.setEnabled(false); vertical.setEnabled(false);
} }
vertical.setThumb(clientHeighth); vertical.setThumb(clientHeighth);
@ -345,10 +343,10 @@ public class WaveformCanvas extends Canvas {
if(pt.x==0 || pt.y==0) return; if(pt.x==0 || pt.y==0) return;
Rectangle clientRect = getClientArea(); /* Canvas' painting area */ Rectangle clientRect = getClientArea(); /* Canvas' painting area */
GC thisGc = gc; GC thisGc = gc;
Image d_backingImg = null; Image dBackingImg = null;
if(doubleBuffering) { if(doubleBuffering) {
d_backingImg = new Image(getDisplay(), pt.x, pt.y); dBackingImg = new Image(getDisplay(), pt.x, pt.y);
thisGc = new GC(d_backingImg); thisGc = new GC(dBackingImg);
thisGc.setBackground(gc.getBackground()); thisGc.setBackground(gc.getBackground());
thisGc.setForeground(gc.getForeground()); thisGc.setForeground(gc.getForeground());
thisGc.setFont(gc.getFont()); thisGc.setFont(gc.getFont());
@ -356,7 +354,7 @@ public class WaveformCanvas extends Canvas {
} }
Projection p = new Projection(thisGc); Projection p = new Projection(thisGc);
p.setTranslation(origin); p.setTranslation(origin);
if (painterList.size() > 0 ) { if (!painterList.isEmpty() ) {
for (IPainter painter : painterList) for (IPainter painter : painterList)
painter.paintArea(p, clientRect); painter.paintArea(p, clientRect);
} else { } else {
@ -364,8 +362,8 @@ public class WaveformCanvas extends Canvas {
initScrollBars(); initScrollBars();
} }
if(doubleBuffering) { if(doubleBuffering) {
gc.drawImage(d_backingImg, 0, 0); gc.drawImage(dBackingImg, 0, 0);
d_backingImg.dispose(); if(dBackingImg!=null) dBackingImg.dispose();
thisGc.dispose(); thisGc.dispose();
} }
} }
@ -376,7 +374,7 @@ public class WaveformCanvas extends Canvas {
if (p instanceof TrackAreaPainter) { if (p instanceof TrackAreaPainter) {
int y = point.y - origin.y; int y = point.y - origin.y;
int x = point.x - origin.x; int x = point.x - origin.x;
Entry<Integer, IWaveformPainter> entry = trackAreaPainter.getTrackVerticalOffset().floorEntry(y); Entry<Integer, IWaveformPainter> entry = trackAreaPainter.trackVerticalOffset.floorEntry(y);
if (entry != null) { if (entry != null) {
if (entry.getValue() instanceof StreamPainter) { if (entry.getValue() instanceof StreamPainter) {
ITx tx = ((StreamPainter) entry.getValue()).getClicked(new Point(x, y - entry.getKey())); ITx tx = ((StreamPainter) entry.getValue()).getClicked(new Point(x, y - entry.getKey()));
@ -397,7 +395,7 @@ public class WaveformCanvas extends Canvas {
public List<Object> getEntriesAtPosition(IWaveform iWaveform, int i) { public List<Object> getEntriesAtPosition(IWaveform iWaveform, int i) {
LinkedList<Object> result=new LinkedList<>(); LinkedList<Object> result=new LinkedList<>();
int x = i - origin.x; int x = i - origin.x;
for(IPainter p: wave2painterMap.values()){ for(IWaveformPainter p: wave2painterMap.values()){
if (p instanceof StreamPainter && ((StreamPainter)p).getStream()==iWaveform) { if (p instanceof StreamPainter && ((StreamPainter)p).getStream()==iWaveform) {
result.add(((StreamPainter) p).getClicked(new Point(x, styleProvider.getTrackHeight()/2))); result.add(((StreamPainter) p).getClicked(new Point(x, styleProvider.getTrackHeight()/2)));
} }
@ -442,10 +440,9 @@ public class WaveformCanvas extends Canvas {
TrackEntry te = painter.getTrackEntry(); TrackEntry te = painter.getTrackEntry();
if(te.waveform == waveform) { if(te.waveform == waveform) {
Point size = getSize(); Point size = getSize();
//size.x -= getVerticalBar().getSize().x + 2;
size.y -=+rulerHeight; size.y -=+rulerHeight;
ScrollBar sb = getHorizontalBar(); ScrollBar sb = getHorizontalBar();
if((sb.getStyle()&SWT.SCROLLBAR_OVERLAY)!=0 && sb.isVisible()) // TODO: check on other platform than MacOSX if((sb.getStyle()&SWT.SCROLLBAR_OVERLAY)!=0 && sb.isVisible())
size.y-= getHorizontalBar().getSize().y; size.y-= getHorizontalBar().getSize().y;
int top = te.vOffset; int top = te.vOffset;
int bottom = top + styleProvider.getTrackHeight(); int bottom = top + styleProvider.getTrackHeight();

View File

@ -93,7 +93,7 @@ import com.minres.scviewer.database.ui.swt.Constants;
public class WaveformView implements IWaveformView { public class WaveformView implements IWaveformView {
private ListenerList<ISelectionChangedListener> selectionChangedListeners = new ListenerList<ISelectionChangedListener>(); private ListenerList<ISelectionChangedListener> selectionChangedListeners = new ListenerList<>();
private PropertyChangeSupport pcs; private PropertyChangeSupport pcs;
@ -109,9 +109,9 @@ public class WaveformView implements IWaveformView {
private Control namePaneHeader; private Control namePaneHeader;
final private Canvas nameList; private final Canvas nameList;
final private Canvas valueList; private final Canvas valueList;
final WaveformCanvas waveformCanvas; final WaveformCanvas waveformCanvas;
@ -170,7 +170,8 @@ public class WaveformView implements IWaveformView {
}; };
class WaveformMouseListener implements PaintListener, Listener { class WaveformMouseListener implements PaintListener, Listener {
Point start, end; Point start;
Point end;
List<Object> initialSelected; List<Object> initialSelected;
boolean down=false; boolean down=false;
@ -181,9 +182,9 @@ public class WaveformView implements IWaveformView {
gc.setAlpha(128); gc.setAlpha(128);
int minX = Math.min(start.x, end.x); int minX = Math.min(start.x, end.x);
int width = Math.max(start.x, end.x) - minX; int width = Math.max(start.x, end.x) - minX;
int y_top = waveformCanvas.getRulerHeight(); int yTop = waveformCanvas.getRulerHeight();
int y_bottom = waveformCanvas.getSize().y; int yBottom = waveformCanvas.getSize().y;
gc.fillRectangle(minX, y_top, width,y_bottom); gc.fillRectangle(minX, yTop, width,yBottom);
} }
} }
@ -200,7 +201,7 @@ public class WaveformView implements IWaveformView {
if(targetTimeRange==0) return; if(targetTimeRange==0) return;
long relation = currentTimeRange/targetTimeRange; long relation = currentTimeRange/targetTimeRange;
long i = 1; long i = 1;
int level=0;//relation>0?0:0; int level=0;
do { do {
if(relation<0 ) { if(relation<0 ) {
if(-relation<i) { if(-relation<i) {
@ -247,7 +248,8 @@ public class WaveformView implements IWaveformView {
long time= waveformCanvas.getTimeForOffset(p.x); long time= waveformCanvas.getTimeForOffset(p.x);
long scaling=5*waveformCanvas.getScaleFactor(); long scaling=5*waveformCanvas.getScaleFactor();
for(Object o:waveformCanvas.getElementsAt(p)){ for(Object o:waveformCanvas.getElementsAt(p)){
Entry<Long, ?> floorEntry=null, ceilEntry=null; Entry<Long, IEvent[]> floorEntry=null;
Entry<Long, IEvent[]> ceilEntry=null;
if(o instanceof TrackEntry){ if(o instanceof TrackEntry){
TrackEntry entry = (TrackEntry) o; TrackEntry entry = (TrackEntry) o;
NavigableMap<Long, IEvent[]> map = entry.waveform.getEvents(); NavigableMap<Long, IEvent[]> map = entry.waveform.getEvents();
@ -293,9 +295,6 @@ public class WaveformView implements IWaveformView {
case SWT.MouseUp: case SWT.MouseUp:
mouseUp(new MouseEvent(e)); mouseUp(new MouseEvent(e));
break; break;
//case SWT.MouseDoubleClick:
//mouseDoubleClick(new MouseEvent(e));
//break;
case SWT.MouseMove: case SWT.MouseMove:
if(down) { if(down) {
end=new Point(e.x, e.y); end=new Point(e.x, e.y);
@ -308,7 +307,7 @@ public class WaveformView implements IWaveformView {
} }
}; }
protected WaveformMouseListener waveformMouseListener = new WaveformMouseListener(); protected WaveformMouseListener waveformMouseListener = new WaveformMouseListener();
public WaveformView(Composite parent, IWaveformStyleProvider styleProvider) { public WaveformView(Composite parent, IWaveformStyleProvider styleProvider) {
@ -316,7 +315,7 @@ public class WaveformView implements IWaveformView {
pcs=new PropertyChangeSupport(this); pcs=new PropertyChangeSupport(this);
trackVerticalOffset = new TreeMap<Integer, TrackEntry>(); trackVerticalOffset = new TreeMap<>();
tracksVerticalHeight=0; tracksVerticalHeight=0;
streams = new ObservableList<>(); streams = new ObservableList<>();
@ -363,15 +362,12 @@ public class WaveformView implements IWaveformView {
return new Point(bounds.width, bounds.height); return new Point(bounds.width, bounds.height);
} }
}; };
nameList.addListener(SWT.Paint, new Listener() { nameList.addListener(SWT.Paint, (Event event) -> {
@Override
public void handleEvent(Event event) {
if(!trackVerticalOffset.isEmpty()) { if(!trackVerticalOffset.isEmpty()) {
GC gc = event.gc; GC gc = event.gc;
Rectangle rect = ((Canvas) event.widget).getClientArea(); Rectangle rect = ((Canvas) event.widget).getClientArea();
paintNames(gc, rect); paintNames(gc, rect);
} }
}
}); });
nameList.addMouseListener(nameValueMouseListener); nameList.addMouseListener(nameValueMouseListener);
nameListScrolled.setContent(nameList); nameListScrolled.setContent(nameList);
@ -398,15 +394,12 @@ public class WaveformView implements IWaveformView {
return new Point(bounds.width, bounds.height); return new Point(bounds.width, bounds.height);
} }
}; };
valueList.addListener(SWT.Paint, new Listener() { valueList.addListener(SWT.Paint, (Event event) -> {
@Override
public void handleEvent(Event event) {
if(!trackVerticalOffset.isEmpty()) { if(!trackVerticalOffset.isEmpty()) {
GC gc = event.gc; GC gc = event.gc;
Rectangle rect = ((Canvas) event.widget).getClientArea(); Rectangle rect = ((Canvas) event.widget).getClientArea();
paintValues(gc, rect); paintValues(gc, rect);
} }
}
}); });
valueList.addMouseListener(nameValueMouseListener); valueList.addMouseListener(nameValueMouseListener);
valueListScrolled.setContent(valueList); valueListScrolled.setContent(valueList);
@ -415,11 +408,11 @@ public class WaveformView implements IWaveformView {
waveformCanvas.addPaintListener(waveformMouseListener); waveformCanvas.addPaintListener(waveformMouseListener);
waveformCanvas.addListener(SWT.MouseDown,waveformMouseListener); waveformCanvas.addListener(SWT.MouseDown,waveformMouseListener);
waveformCanvas.addListener(SWT.MouseUp,waveformMouseListener); waveformCanvas.addListener(SWT.MouseUp,waveformMouseListener);
//waveformCanvas.addListener(SWT.MouseDoubleClick,waveformMouseListener);
waveformCanvas.addListener(SWT.MouseMove,waveformMouseListener); waveformCanvas.addListener(SWT.MouseMove,waveformMouseListener);
waveformCanvas.addListener(SWT.MouseWheel, waveformMouseListener); waveformCanvas.addListener(SWT.MouseWheel, waveformMouseListener);
nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() { nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int y = ((ScrollBar) e.widget).getSelection(); int y = ((ScrollBar) e.widget).getSelection();
Point v = valueListScrolled.getOrigin(); Point v = valueListScrolled.getOrigin();
@ -429,6 +422,7 @@ public class WaveformView implements IWaveformView {
} }
}); });
valueListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() { valueListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int y = ((ScrollBar) e.widget).getSelection(); int y = ((ScrollBar) e.widget).getSelection();
nameListScrolled.setOrigin(nameListScrolled.getOrigin().x, y); nameListScrolled.setOrigin(nameListScrolled.getOrigin().x, y);
@ -436,6 +430,7 @@ public class WaveformView implements IWaveformView {
} }
}); });
waveformCanvas.addSelectionListener(new SelectionAdapter() { waveformCanvas.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int y = waveformCanvas.getVerticalBar().getSelection(); int y = waveformCanvas.getVerticalBar().getSelection();
nameListScrolled.setOrigin(nameListScrolled.getOrigin().x, y); nameListScrolled.setOrigin(nameListScrolled.getOrigin().x, y);
@ -457,48 +452,40 @@ public class WaveformView implements IWaveformView {
} }
private void createTextPane(Composite namePane, String text) { private void createTextPane(Composite namePane, String text) {
GridLayout gl_namePane = new GridLayout(1, false); GridLayout glNamePane = new GridLayout(1, false);
gl_namePane.verticalSpacing = 0; glNamePane.verticalSpacing = 0;
gl_namePane.marginWidth = 0; glNamePane.marginWidth = 0;
gl_namePane.horizontalSpacing = 0; glNamePane.horizontalSpacing = 0;
gl_namePane.marginHeight = 0; glNamePane.marginHeight = 0;
namePane.setLayout(gl_namePane); namePane.setLayout(glNamePane);
CLabel nameLabel = new CLabel(namePane, SWT.NONE); CLabel nameLabel = new CLabel(namePane, SWT.NONE);
GridData gd_nameLabel = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1); GridData gdNameLabel = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
gd_nameLabel.heightHint = waveformCanvas.getRulerHeight() - 2; gdNameLabel.heightHint = waveformCanvas.getRulerHeight() - 2;
nameLabel.setLayoutData(gd_nameLabel); nameLabel.setLayoutData(gdNameLabel);
nameLabel.setText(text); nameLabel.setText(text);
Label nameSep = new Label(namePane, SWT.SEPARATOR | SWT.HORIZONTAL); Label nameSep = new Label(namePane, SWT.SEPARATOR | SWT.HORIZONTAL);
nameSep.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY)); nameSep.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
nameSep.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK)); nameSep.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
GridData gd_nameSep = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); GridData gdNameSep = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_nameSep.heightHint = 2; gdNameSep.heightHint = 2;
nameSep.setLayoutData(gd_nameSep); nameSep.setLayoutData(gdNameSep);
} }
@Override @Override
public void propertyChange(PropertyChangeEvent pce) { public void propertyChange(PropertyChangeEvent pce) {
if ("size".equals(pce.getPropertyName()) || "content".equals(pce.getPropertyName())) { if ("size".equals(pce.getPropertyName()) || "content".equals(pce.getPropertyName())) {
if(revealSelected) { if(revealSelected) {
waveformCanvas.getDisplay().asyncExec(new Runnable() { waveformCanvas.getDisplay().asyncExec(() ->{
@Override
public void run() {
update(); update();
currentWaveformSelection.stream().forEach(e -> waveformCanvas.reveal(e.waveform)); currentWaveformSelection.stream().forEach(e -> waveformCanvas.reveal(e.waveform));
valueList.redraw(); valueList.redraw();
nameList.redraw(); nameList.redraw();
}
}); });
revealSelected=false; revealSelected=false;
} else } else
waveformCanvas.getDisplay().asyncExec(new Runnable() { waveformCanvas.getDisplay().asyncExec(WaveformView.this::update);
@Override
public void run() {
update();
}
});
} }
} }
@ -562,7 +549,6 @@ public class WaveformView implements IWaveformView {
if(bv.getWidth()==1) if(bv.getWidth()==1)
entry.currentValue="b'"+bv; entry.currentValue="b'"+bv;
else { else {
// TODO: same code resides in SignalPainter, fix it
switch(entry.valueDisplay) { switch(entry.valueDisplay) {
case SIGNED: case SIGNED:
entry.currentValue=Long.toString(bv.toSignedValue()); entry.currentValue=Long.toString(bv.toSignedValue());
@ -597,15 +583,15 @@ public class WaveformView implements IWaveformView {
} }
firstTx=entry.waveform.getEvents().lowerEntry(firstTx.getKey()); firstTx=entry.waveform.getEvents().lowerEntry(firstTx.getKey());
}while(firstTx!=null && !isArrayFull(resultsList)); }while(firstTx!=null && !isArrayFull(resultsList));
entry.currentValue="";
boolean separator=false; boolean separator=false;
StringBuilder sb = new StringBuilder();
for(ITx o:resultsList){ for(ITx o:resultsList){
if(separator) entry.currentValue+="|"; if(separator) sb.append("|");
if(o!=null) entry.currentValue+=((ITx)o).getGenerator().getName(); if(o!=null) sb.append(o.getGenerator().getName());
separator=true; separator=true;
} }
entry.currentValue=sb.toString();
} }
} }
} }
@ -680,7 +666,6 @@ public class WaveformView implements IWaveformView {
if (currentTxSelection != null) { if (currentTxSelection != null) {
sel.add(currentTxSelection); sel.add(currentTxSelection);
} }
// sel.addAll(currentWaveformSelection.stream().map(e -> e.waveform).collect(Collectors.toList()));
sel.addAll(currentWaveformSelection); sel.addAll(currentWaveformSelection);
return new StructuredSelection(sel.toArray()); return new StructuredSelection(sel.toArray());
} }
@ -736,7 +721,7 @@ public class WaveformView implements IWaveformView {
} }
} }
} else { } else {
if (currentTxSelection != null || currentWaveformSelection.size() > 0) if (currentTxSelection != null || !currentWaveformSelection.isEmpty())
selectionChanged = true; selectionChanged = true;
currentTxSelection = null; currentTxSelection = null;
currentWaveformSelection.clear(); currentWaveformSelection.clear();
@ -864,13 +849,12 @@ public class WaveformView implements IWaveformView {
private ITxRelation selectTxToNavigateTo(Collection<ITxRelation> rel, RelationType relationType, boolean target) { private ITxRelation selectTxToNavigateTo(Collection<ITxRelation> rel, RelationType relationType, boolean target) {
ArrayList<ITxRelation> candidates = rel.stream().filter(r -> relationType.equals(r.getRelationType())).collect(Collectors.toCollection(ArrayList::new)); ArrayList<ITxRelation> candidates = rel.stream().filter(r -> relationType.equals(r.getRelationType())).collect(Collectors.toCollection(ArrayList::new));
//new RelSelectionDialog(waveformCanvas.getShell(), candidates, target).open();
switch (candidates.size()) { switch (candidates.size()) {
case 0: return null; case 0: return null;
case 1: return candidates.get(0); case 1: return candidates.get(0);
default: default:
ArrayList<ITxRelation> visibleCandidates = candidates.stream().filter(r -> streamsVisible(r)).collect(Collectors.toCollection(ArrayList::new)); ArrayList<ITxRelation> visibleCandidates = candidates.stream().filter(this::streamsVisible).collect(Collectors.toCollection(ArrayList::new));
if(visibleCandidates.size()==0) { if(visibleCandidates.isEmpty()) {
return new RelSelectionDialog(waveformCanvas.getShell(), candidates, target).open(); return new RelSelectionDialog(waveformCanvas.getShell(), candidates, target).open();
} else if(visibleCandidates.size()==1) { } else if(visibleCandidates.size()==1) {
return visibleCandidates.size()==1?visibleCandidates.get(0):null; return visibleCandidates.size()==1?visibleCandidates.get(0):null;
@ -895,9 +879,7 @@ public class WaveformView implements IWaveformView {
TrackEntry sel = currentWaveformSelection.get(0); TrackEntry sel = currentWaveformSelection.get(0);
long time = getCursorTime(); long time = getCursorTime();
NavigableMap<Long, ?> map=null; NavigableMap<Long, ?> map=null;
if(sel.waveform.getType()==WaveformType.TRANSACTION){ if(sel.waveform.getType()==WaveformType.TRANSACTION || sel.waveform.getType()==WaveformType.SIGNAL){
map=sel.waveform.getEvents();
} else if(sel.waveform.getType()==WaveformType.SIGNAL){
map=sel.waveform.getEvents(); map=sel.waveform.getEvents();
} }
if(map!=null){ if(map!=null){
@ -925,12 +907,12 @@ public class WaveformView implements IWaveformView {
*/ */
@Override @Override
public void deleteSelectedTracks() { public void deleteSelectedTracks() {
List<TrackEntry> streams = getStreamList(); List<TrackEntry> streamList = getStreamList();
for (Object o : (IStructuredSelection)getSelection()) { for (Object o : (IStructuredSelection)getSelection()) {
if(o instanceof TrackEntry) { if(o instanceof TrackEntry) {
TrackEntry e = (TrackEntry) o; TrackEntry e = (TrackEntry) o;
e.selected=false; e.selected=false;
streams.remove(e); streamList.remove(e);
} }
} }
setSelection(new StructuredSelection()); setSelection(new StructuredSelection());
@ -941,7 +923,7 @@ public class WaveformView implements IWaveformView {
*/ */
@Override @Override
public void moveSelectedTrack(int i) { public void moveSelectedTrack(int i) {
if(currentWaveformSelection.size()>0){ if(!currentWaveformSelection.isEmpty()){
int idx = streams.indexOf(currentWaveformSelection.get(0)); int idx = streams.indexOf(currentWaveformSelection.get(0));
for(Object o: currentWaveformSelection) for(Object o: currentWaveformSelection)
streams.remove(o); streams.remove(o);
@ -956,14 +938,14 @@ public class WaveformView implements IWaveformView {
protected void paintNames(GC gc, Rectangle rect) { protected void paintNames(GC gc, Rectangle rect) {
if (streams.size() > 0) { if (!streams.isEmpty()) {
try { try {
Integer firstKey = trackVerticalOffset.floorKey(rect.y); Integer firstKey = trackVerticalOffset.floorKey(rect.y);
if (firstKey == null) if (firstKey == null)
firstKey = trackVerticalOffset.firstKey(); firstKey = trackVerticalOffset.firstKey();
Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height); Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height);
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, styleProvider.getTrackHeight()); Rectangle subArea = new Rectangle(rect.x, 0, rect.width, styleProvider.getTrackHeight());
if (lastKey == firstKey) { if (lastKey.equals(firstKey)) {
TrackEntry trackEntry=trackVerticalOffset.get(firstKey); TrackEntry trackEntry=trackVerticalOffset.get(firstKey);
IWaveform w = trackEntry.waveform; IWaveform w = trackEntry.waveform;
if (w.getType()==WaveformType.TRANSACTION) if (w.getType()==WaveformType.TRANSACTION)
@ -983,14 +965,14 @@ public class WaveformView implements IWaveformView {
} }
protected void paintValues(GC gc, Rectangle rect) { protected void paintValues(GC gc, Rectangle rect) {
if (streams.size() > 0) { if (!streams.isEmpty()) {
try { try {
Integer firstKey = trackVerticalOffset.floorKey(rect.y); Integer firstKey = trackVerticalOffset.floorKey(rect.y);
if (firstKey == null) if (firstKey == null)
firstKey = trackVerticalOffset.firstKey(); firstKey = trackVerticalOffset.firstKey();
Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height); Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height);
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, styleProvider.getTrackHeight()); Rectangle subArea = new Rectangle(rect.x, 0, rect.width, styleProvider.getTrackHeight());
if (lastKey == firstKey) { if (lastKey.equals(firstKey)) {
TrackEntry trackEntry=trackVerticalOffset.get(firstKey); TrackEntry trackEntry=trackVerticalOffset.get(firstKey);
IWaveform w = trackEntry.waveform; IWaveform w = trackEntry.waveform;
if (w.getType()==WaveformType.TRANSACTION) if (w.getType()==WaveformType.TRANSACTION)
@ -1131,13 +1113,14 @@ public class WaveformView implements IWaveformView {
DragSource dragSource = new DragSource(canvas, DND.DROP_MOVE); DragSource dragSource = new DragSource(canvas, DND.DROP_MOVE);
dragSource.setTransfer(types); dragSource.setTransfer(types);
dragSource.addDragListener(new DragSourceAdapter() { dragSource.addDragListener(new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) { public void dragStart(DragSourceEvent event) {
if (event.y < tracksVerticalHeight) { if (event.y < tracksVerticalHeight) {
event.doit = true; event.doit = true;
LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(currentWaveformSelection)); LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(currentWaveformSelection));
} }
} }
@Override
public void dragSetData(DragSourceEvent event) { public void dragSetData(DragSourceEvent event) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) { if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
event.data =getSelection(); event.data =getSelection();
@ -1153,10 +1136,11 @@ public class WaveformView implements IWaveformView {
dropTarget.addDropListener(new DropTargetAdapter() { dropTarget.addDropListener(new DropTargetAdapter() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override
public void drop(DropTargetEvent event) { public void drop(DropTargetEvent event) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)){ if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)){
ISelection s = LocalSelectionTransfer.getTransfer().getSelection(); ISelection s = LocalSelectionTransfer.getTransfer().getSelection();
if(s!=null && s instanceof IStructuredSelection){ if(s instanceof IStructuredSelection){
IStructuredSelection sel = (IStructuredSelection) s; IStructuredSelection sel = (IStructuredSelection) s;
for(Object o: sel.toList()) for(Object o: sel.toList())
streams.remove(o); streams.remove(o);
@ -1173,7 +1157,7 @@ public class WaveformView implements IWaveformView {
} }
} }
} }
@Override
public void dropAccept(DropTargetEvent event) { public void dropAccept(DropTargetEvent event) {
if (event.detail != DND.DROP_MOVE) { if (event.detail != DND.DROP_MOVE) {
event.detail = DND.DROP_NONE; event.detail = DND.DROP_NONE;
@ -1197,6 +1181,7 @@ public class WaveformView implements IWaveformView {
DragSource dragSource = new DragSource(canvas, DND.DROP_MOVE); DragSource dragSource = new DragSource(canvas, DND.DROP_MOVE);
dragSource.setTransfer(types); dragSource.setTransfer(types);
dragSource.addDragListener(new DragSourceAdapter() { dragSource.addDragListener(new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) { public void dragStart(DragSourceEvent event) {
event.doit = false; event.doit = false;
List<Object> clicked = waveformCanvas.getElementsAt(new Point(event.x, event.y)); List<Object> clicked = waveformCanvas.getElementsAt(new Point(event.x, event.y));
@ -1209,13 +1194,22 @@ public class WaveformView implements IWaveformView {
} }
} }
} }
@Override
public void dragSetData(DragSourceEvent event) { public void dragSetData(DragSourceEvent event) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) { if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
event.data=waveformCanvas.getElementsAt(new Point(event.x, event.y)); event.data=waveformCanvas.getElementsAt(new Point(event.x, event.y));
} }
} }
}); });
// int style = SWT.MULTI | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
// final StyledText text = new StyledText(waveformCanvas, style);
// text.setText("Dragging");
// dragSource.setDragSourceEffect(new DragSourceEffect(text) {
// @Override
// public void dragStart(DragSourceEvent event) {
// event.image = waveformCanvas.getDisplay().getSystemImage(SWT.ICON_WARNING);
// }
// });
} }
private void createWaveformDropTarget(final Canvas canvas) { private void createWaveformDropTarget(final Canvas canvas) {
@ -1223,10 +1217,11 @@ public class WaveformView implements IWaveformView {
DropTarget dropTarget = new DropTarget(canvas, DND.DROP_MOVE); DropTarget dropTarget = new DropTarget(canvas, DND.DROP_MOVE);
dropTarget.setTransfer(types); dropTarget.setTransfer(types);
dropTarget.addDropListener(new DropTargetAdapter() { dropTarget.addDropListener(new DropTargetAdapter() {
@Override
public void drop(DropTargetEvent event) { public void drop(DropTargetEvent event) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)){ if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)){
ISelection sel = LocalSelectionTransfer.getTransfer().getSelection(); ISelection sel = LocalSelectionTransfer.getTransfer().getSelection();
if(sel!=null && sel instanceof IStructuredSelection && if(sel instanceof IStructuredSelection &&
((IStructuredSelection)sel).getFirstElement() instanceof CursorPainter){ ((IStructuredSelection)sel).getFirstElement() instanceof CursorPainter){
CursorPainter painter = (CursorPainter)((IStructuredSelection)sel).getFirstElement(); CursorPainter painter = (CursorPainter)((IStructuredSelection)sel).getFirstElement();
painter.setDragging(false); painter.setDragging(false);
@ -1234,17 +1229,17 @@ public class WaveformView implements IWaveformView {
} }
} }
} }
@Override
public void dropAccept(DropTargetEvent event) { public void dropAccept(DropTargetEvent event) {
Point offset = canvas.toControl(event.x, event.y); Point offset = canvas.toControl(event.x, event.y);
if (event.detail != DND.DROP_MOVE || offset.y > trackVerticalOffset.lastKey() + styleProvider.getTrackHeight()) { if (event.detail != DND.DROP_MOVE || offset.y > trackVerticalOffset.lastKey() + styleProvider.getTrackHeight()) {
event.detail = DND.DROP_NONE; event.detail = DND.DROP_NONE;
} }
} }
@Override
public void dragOver(DropTargetEvent event){ public void dragOver(DropTargetEvent event){
ISelection sel = LocalSelectionTransfer.getTransfer().getSelection(); ISelection sel = LocalSelectionTransfer.getTransfer().getSelection();
if(sel!=null && sel instanceof IStructuredSelection && if(sel instanceof IStructuredSelection &&
((IStructuredSelection)sel).getFirstElement() instanceof CursorPainter){ ((IStructuredSelection)sel).getFirstElement() instanceof CursorPainter){
updateWaveform(canvas, event, (CursorPainter) ((IStructuredSelection)sel).getFirstElement()); updateWaveform(canvas, event, (CursorPainter) ((IStructuredSelection)sel).getFirstElement());
} }
@ -1261,14 +1256,11 @@ public class WaveformView implements IWaveformView {
pcs.firePropertyChange(MARKER_PROPERTY, oldVal, time); pcs.firePropertyChange(MARKER_PROPERTY, oldVal, time);
pcs.firePropertyChange(MARKER_PROPERTY+painter.id, oldVal, time); pcs.firePropertyChange(MARKER_PROPERTY+painter.id, oldVal, time);
} }
canvas.getDisplay().asyncExec(new Runnable() { canvas.getDisplay().asyncExec(() -> {
@Override
public void run() {
if(!canvas.isDisposed()){ if(!canvas.isDisposed()){
canvas.redraw(); canvas.redraw();
updateValueList(); updateValueList();
} }
}
}); });
} }
}); });
@ -1325,8 +1317,8 @@ public class WaveformView implements IWaveformView {
@Override @Override
public String getScaledTime(long time) { public String getScaledTime(long time) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Double dTime=new Double(time); double dTime=time;
Double scaledTime = dTime/waveformCanvas.getScaleFactorPow10(); double scaledTime = dTime/waveformCanvas.getScaleFactorPow10();
return sb.append(df.format(scaledTime)).append(waveformCanvas.getUnitStr()).toString(); return sb.append(df.format(scaledTime)).append(waveformCanvas.getUnitStr()).toString();
} }
@ -1335,11 +1327,11 @@ public class WaveformView implements IWaveformView {
*/ */
@Override @Override
public String[] getZoomLevels(){ public String[] getZoomLevels(){
String[] res = new String[Constants.unitMultiplier.length*Constants.unitString.length]; String[] res = new String[Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length];
int index=0; int index=0;
for(String unit:Constants.unitString){ for(String unit:Constants.UNIT_STRING){
for(int factor:Constants.unitMultiplier){ for(int factor:Constants.UNIT_MULTIPLIER){
res[index++]= new Integer(factor).toString()+unit; res[index++]= Integer.toString(factor)+unit;
} }
} }
return res; return res;
@ -1368,12 +1360,9 @@ public class WaveformView implements IWaveformView {
} }
public void asyncUpdate(Widget widget) { public void asyncUpdate(Widget widget) {
widget.getDisplay().asyncExec(new Runnable() { widget.getDisplay().asyncExec(() -> {
@Override
public void run() {
waveformCanvas.redraw(); waveformCanvas.redraw();
updateValueList(); updateValueList();
}
}); });
} }

View File

@ -1093,7 +1093,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
boolean foundZoom=false; boolean foundZoom=false;
//try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel //try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel
for (int level=0; level<Constants.unitMultiplier.length*Constants.unitString.length; level++){ for (int level=0; level<Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length; level++){
long scaleFactor = (long) Math.pow(10, level/2); long scaleFactor = (long) Math.pow(10, level/2);
if(level%2==1) scaleFactor*=3; if(level%2==1) scaleFactor*=3;
if(scaleFactor*clientAreaWidth >= maxTime) { if(scaleFactor*clientAreaWidth >= maxTime) {
@ -1103,7 +1103,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
} }
} }
//if no zoom level is found, set biggest one available //if no zoom level is found, set biggest one available
if(!foundZoom) setZoomLevel(Constants.unitMultiplier.length*Constants.unitString.length-1); if(!foundZoom) setZoomLevel(Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length-1);
updateAll(); updateAll();
} }