- fixed scrolling sync issue

- fixed duplicate db entries
This commit is contained in:
ejentzsx 2015-02-04 16:20:59 +01:00
parent 310c9bbb8f
commit ac942481e3
11 changed files with 849 additions and 844 deletions

View File

@ -179,7 +179,11 @@ public class Tx implements ITx {
@Override @Override
public int compareTo(ITx o) { public int compareTo(ITx o) {
return this.getBeginTime().compareTo(o.getBeginTime()); int res = this.getBeginTime().compareTo(o.getBeginTime());
if(res!=0)
return res;
else
return this.getId().compareTo(o.getId());
} }
@Override @Override

View File

@ -68,35 +68,37 @@ public class StreamPainter implements IWaveformPainter{
for(int y1=area.y+this.waveCanvas.getTrackHeight()/2; y1<area.y+totalHeight; y1+=this.waveCanvas.getTrackHeight()) for(int y1=area.y+this.waveCanvas.getTrackHeight()/2; y1<area.y+totalHeight; y1+=this.waveCanvas.getTrackHeight())
gc.drawLine(area.x, y1, area.x+area.width, y1); gc.drawLine(area.x, y1, area.x+area.width, y1);
if(firstTx==lastTx) if(firstTx==lastTx)
for(ITxEvent x:(Collection<? extends ITxEvent>)firstTx.getValue()) for(ITxEvent txEvent:(Collection<? extends ITxEvent>)firstTx.getValue())
drawTx(gc, area, x.getTransaction()); drawTx(gc, area, txEvent.getTransaction());
else{ else{
seenTx.clear(); seenTx.clear();
NavigableMap<Long,?> entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true); NavigableMap<Long,?> entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true);
for(Entry<Long, ?> tx: entries.entrySet()) boolean highlighed=false;
for(ITxEvent x:(Collection<? extends ITxEvent>)tx.getValue()){ gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.LINE.ordinal()]);
if(x.getType()==ITxEvent.Type.BEGIN) gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TX_BG.ordinal()]);
seenTx.add(x.getTransaction()); for(Entry<Long, ?> entry: entries.entrySet())
if(x.getType()==ITxEvent.Type.END){ for(ITxEvent txEvent:(Collection<? extends ITxEvent>)entry.getValue()){
drawTx(gc, area, x.getTransaction()); if(txEvent.getType()==ITxEvent.Type.BEGIN)
seenTx.remove(x.getTransaction()); seenTx.add(txEvent.getTransaction());
if(txEvent.getType()==ITxEvent.Type.END){
ITx tx = txEvent.getTransaction();
highlighed|=waveCanvas.currentSelection!=null && waveCanvas.currentSelection.getId()==tx.getId();
drawTx(gc, area, tx);
seenTx.remove(tx);
} }
} }
for(ITx tx:seenTx){ for(ITx tx:seenTx){
drawTx(gc, area, tx); drawTx(gc, area, tx);
} }
if(highlighed){
gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.LINE_HIGHLITE.ordinal()]);
gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TX_BG_HIGHLITE.ordinal()]);
drawTx(gc, area, waveCanvas.currentSelection);
}
} }
} }
protected void drawTx(GC gc, Rectangle area, ITx tx) { protected void drawTx(GC gc, Rectangle area, ITx tx) {
if(waveCanvas.currentSelection!=null && waveCanvas.currentSelection.getId()==tx.getId()){
gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.LINE_HIGHLITE.ordinal()]);
gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TX_BG_HIGHLITE.ordinal()]);
}else {
gc.setForeground(this.waveCanvas.colors[WaveformCanvas.Colors.LINE.ordinal()]);
gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TX_BG.ordinal()]);
}
int offset = tx.getConcurrencyIndex()*this.waveCanvas.getTrackHeight(); int offset = tx.getConcurrencyIndex()*this.waveCanvas.getTrackHeight();
Rectangle bb = new Rectangle( Rectangle bb = new Rectangle(
(int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+upper, (int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+upper,

View File

@ -32,6 +32,7 @@ import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.wb.swt.SWTResourceManager;
@ -41,340 +42,348 @@ import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformEvent; import com.minres.scviewer.database.IWaveformEvent;
public class WaveformCanvas extends Canvas { public class WaveformCanvas extends Canvas {
public enum Colors { public enum Colors {
LINE, LINE, LINE_HIGHLITE, TRACK_BG_EVEN, TRACK_BG_HIGHLITE, TRACK_BG_ODD, TX_BG, TX_BG_HIGHLITE, TX_BORDER, SIGNAL0, SIGNAL1, SIGNALZ, SIGNALX, SIGNAL_TEXT, CURSOR
LINE_HIGHLITE, }
TRACK_BG_EVEN,
TRACK_BG_HIGHLITE,
TRACK_BG_ODD,
TX_BG,
TX_BG_HIGHLITE,
TX_BORDER,
SIGNAL0,
SIGNAL1,
SIGNALZ,
SIGNALX,
SIGNAL_TEXT,
CURSOR
}
Color[] colors=new Color[Colors.values().length]; Color[] colors = new Color[Colors.values().length];
private int trackHeight = 50;
private long scaleFactor = 1000000L;
private int level=6;
private long maxTime;
protected Point origin; /* original size */
protected Transform transform;
protected Ruler ruler;
protected List<IPainter> painterList;
TreeMap<Integer, IWaveformPainter> trackVerticalOffset;
protected List<IWaveform<? extends IWaveformEvent>> streams;
ITx currentSelection; private int trackHeight = 50;
IWaveform<? extends IWaveformEvent> currentWaveformSelection; private long scaleFactor = 1000000L;
private int level = 6;
private long maxTime;
protected Point origin; /* original size */
protected Transform transform;
protected Ruler ruler;
protected List<IPainter> painterList;
TreeMap<Integer, IWaveformPainter> trackVerticalOffset;
protected List<IWaveform<? extends IWaveformEvent>> streams;
/** ITx currentSelection;
* Constructor for ScrollableCanvas. IWaveform<? extends IWaveformEvent> currentWaveformSelection;
* @param parent the parent of this control.
* @param style the style of this control.
*/
public WaveformCanvas(final Composite parent, int style) {
super( parent, style |SWT.DOUBLE_BUFFERED| SWT.NO_BACKGROUND|SWT.NO_REDRAW_RESIZE|SWT.V_SCROLL|SWT.H_SCROLL);
addControlListener(new ControlAdapter() { /* resize listener. */
public void controlResized(ControlEvent event) {
syncScrollBars();
}
});
addPaintListener(new PaintListener() { /* paint listener. */
public void paintControl(final PaintEvent event) {
paint(event.gc);
}
});
painterList=new LinkedList<IPainter>();
origin=new Point(0,0);
transform = new Transform(getDisplay());
trackVerticalOffset=new TreeMap<Integer, IWaveformPainter>();
initScrollBars();
initColors(null);
}
private void initColors(HashMap<Colors, RGB> colourMap){ private List<SelectionAdapter> selectionListeners;
Display d = getDisplay();
if(colourMap!=null){
for(Colors c:Colors.values()){
if(colourMap.containsKey(c)){
colors[c.ordinal()].dispose();
colors[c.ordinal()]=new Color(d, colourMap.get(c));
}
}
} else {
colors[Colors.LINE.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_RED);
colors[Colors.LINE_HIGHLITE.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_CYAN);
colors[Colors.TRACK_BG_EVEN.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_BLACK);
colors[Colors.TRACK_BG_ODD.ordinal()]=SWTResourceManager.getColor(40,40,40);
colors[Colors.TRACK_BG_HIGHLITE.ordinal()]=SWTResourceManager.getColor(40,40,80);
colors[Colors.TX_BG.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_GREEN);
colors[Colors.TX_BG_HIGHLITE.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
colors[Colors.TX_BORDER.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_RED);
colors[Colors.SIGNAL0.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
colors[Colors.SIGNAL1.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
colors[Colors.SIGNALZ.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_GRAY);
colors[Colors.SIGNALX.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_RED);
colors[Colors.SIGNAL_TEXT.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_WHITE);
colors[Colors.CURSOR.ordinal()]=SWTResourceManager.getColor(SWT.COLOR_YELLOW);
}
}
public List<IWaveform<? extends IWaveformEvent>> getStreams() { /**
return streams; * Constructor for ScrollableCanvas.
} *
* @param parent
* the parent of this control.
* @param style
* the style of this control.
*/
public WaveformCanvas(final Composite parent, int style) {
super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL);
addControlListener(new ControlAdapter() { /* resize listener. */
public void controlResized(ControlEvent event) {
syncScrollBars();
}
});
addPaintListener(new PaintListener() { /* paint listener. */
public void paintControl(final PaintEvent event) {
paint(event.gc);
}
});
painterList = new LinkedList<IPainter>();
origin = new Point(0, 0);
transform = new Transform(getDisplay());
trackVerticalOffset = new TreeMap<Integer, IWaveformPainter>();
selectionListeners = new LinkedList<>();
initScrollBars();
initColors(null);
}
public void setStreams(List<IWaveform<? extends IWaveformEvent>> streams) { private void initColors(HashMap<Colors, RGB> colourMap) {
this.streams = streams; Display d = getDisplay();
} if (colourMap != null) {
for (Colors c : Colors.values()) {
if (colourMap.containsKey(c)) {
colors[c.ordinal()].dispose();
colors[c.ordinal()] = new Color(d, colourMap.get(c));
}
}
} else {
colors[Colors.LINE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
colors[Colors.LINE_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_CYAN);
colors[Colors.TRACK_BG_EVEN.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_BLACK);
colors[Colors.TRACK_BG_ODD.ordinal()] = SWTResourceManager.getColor(40, 40, 40);
colors[Colors.TRACK_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(40, 40, 80);
colors[Colors.TX_BG.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GREEN);
colors[Colors.TX_BG_HIGHLITE.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
colors[Colors.TX_BORDER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
colors[Colors.SIGNAL0.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
colors[Colors.SIGNAL1.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
colors[Colors.SIGNALZ.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_GRAY);
colors[Colors.SIGNALX.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_RED);
colors[Colors.SIGNAL_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE);
colors[Colors.CURSOR.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_YELLOW);
}
}
public Ruler getRuler(){ public List<IWaveform<? extends IWaveformEvent>> getStreams() {
return ruler; return streams;
} }
public void setRuler(Ruler ruler) {
this.ruler=ruler;
}
public Point getOrigin() { public void setStreams(List<IWaveform<? extends IWaveformEvent>> streams) {
return origin; this.streams = streams;
} }
public long getMaxTime() { public Ruler getRuler() {
return maxTime; return ruler;
} }
public void setMaxTime(long maxTime){ public void setRuler(Ruler ruler) {
this.maxTime=maxTime; this.ruler = ruler;
syncScrollBars(); }
}
public int getTrackHeight() { public Point getOrigin() {
return trackHeight; return origin;
} }
public void setTrackHeight(int trackHeight) { public void setOrigin(Point origin) {
this.trackHeight = trackHeight; setOrigin(origin.x, origin.y);
syncScrollBars(); }
}
public void setZoomLevel(int level) { public void setOrigin(int x, int y) {
this.level=level; checkWidget();
this.scaleFactor = (long) Math.pow(10, level); ScrollBar hBar = getHorizontalBar();
if(ruler!=null) ruler.setStartPoint(-origin.x*scaleFactor); hBar.setSelection(-x);
syncScrollBars(); x = -hBar.getSelection();
} ScrollBar vBar = getVerticalBar();
vBar.setSelection(-y);
y = -vBar.getSelection();
origin.x = x;
origin.y = y;
syncScrollBars();
}
public int getZoomLevel() { public long getMaxTime() {
return level; return maxTime;
} }
public long getScaleFactor() {
return scaleFactor;
}
public void addPainter(IPainter painter) { public void setMaxTime(long maxTime) {
painterList.add(painter); this.maxTime = maxTime;
redraw(); syncScrollBars();
} }
public void removePainter(IPainter painter){ public int getTrackHeight() {
painterList.remove(painter); return trackHeight;
redraw(); }
}
public void clearAllWavefromPainter() { public void setTrackHeight(int trackHeight) {
trackVerticalOffset.clear(); this.trackHeight = trackHeight;
syncScrollBars(); syncScrollBars();
} }
public void addWavefromPainter(int yoffs, IWaveformPainter painter) { public void setZoomLevel(int level) {
trackVerticalOffset.put(yoffs, painter); this.level = level;
syncScrollBars(); this.scaleFactor = (long) Math.pow(10, level);
} if (ruler != null)
ruler.setStartPoint(-origin.x * scaleFactor);
syncScrollBars();
}
/** public int getZoomLevel() {
* Dispose the garbage here return level;
*/ }
public void dispose() {
transform.dispose();
for(Colors c:Colors.values()) colors[c.ordinal()].dispose();
super.dispose();
}
public void scrollToY(int y){ public long getScaleFactor() {
ScrollBar vBar = getVerticalBar(); return scaleFactor;
vBar.setSelection(y); }
scrollVertically(vBar);
}
public void scrollToX(int x){ public void addPainter(IPainter painter) {
ScrollBar hBar = getHorizontalBar(); painterList.add(painter);
hBar.setSelection(x); redraw();
scrollHorizontally(hBar); }
}
/* Scroll horizontally */
private void scrollHorizontally(ScrollBar scrollBar) {
if (painterList.size()==0) return;
origin.x= -scrollBar.getSelection();
if(ruler!=null) ruler.setStartPoint(-origin.x*scaleFactor);
syncScrollBars();
}
/* Scroll vertically */ public void removePainter(IPainter painter) {
private void scrollVertically(ScrollBar scrollBar) { painterList.remove(painter);
if (painterList.size()==0) return; redraw();
origin.y = -scrollBar.getSelection(); }
syncScrollBars();
}
/* Initalize the scrollbar and register listeners. */ public void clearAllWavefromPainter() {
private void initScrollBars() { trackVerticalOffset.clear();
ScrollBar horizontal = getHorizontalBar(); syncScrollBars();
horizontal.setEnabled(false); }
horizontal.setVisible(true);
horizontal.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollHorizontally((ScrollBar) event.widget);
}
});
ScrollBar vertical = getVerticalBar();
vertical.setEnabled(false);
vertical.setVisible(true);
vertical.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
scrollVertically((ScrollBar) event.widget);
}
});
}
/** public void addWavefromPainter(int yoffs, IWaveformPainter painter) {
* Synchronize the scrollbar with the image. If the transform is out trackVerticalOffset.put(yoffs, painter);
* of range, it will correct it. This function considers only following syncScrollBars();
* factors :<b> transform, image size, client area</b>. }
*/
private void syncScrollBars() {
if (painterList.size()==0) {
redraw();
return;
}
int height=1;
if(trackVerticalOffset.size()>0)
height=trackVerticalOffset.lastKey()+trackVerticalOffset.lastEntry().getValue().getMinHeight();
int width = (int) (maxTime/scaleFactor);
ScrollBar horizontal = getHorizontalBar();
horizontal.setIncrement((int) (getClientArea().width / 100));
horizontal.setPageIncrement(getClientArea().width);
int cw = getClientArea().width;
if (width > cw) { /* image is wider than client area */
horizontal.setMaximum(width);
horizontal.setEnabled(true);
if (((int) - origin.x) > horizontal.getMaximum() - cw)
origin.x = -horizontal.getMaximum() + cw;
} else { /* image is narrower than client area */
horizontal.setEnabled(false);
}
horizontal.setSelection(-origin.x);
horizontal.setThumb(cw);
ScrollBar vertical = getVerticalBar(); /**
vertical.setIncrement((int) (getClientArea().height / 100)); * Dispose the garbage here
vertical.setPageIncrement((int) (getClientArea().height)); */
int ch = getClientArea().height; public void dispose() {
if (height> ch) { /* image is higher than client area */ transform.dispose();
vertical.setMaximum(height); for (Colors c : Colors.values())
vertical.setEnabled(true); colors[c.ordinal()].dispose();
if (((int) - origin.y) > vertical.getMaximum() - ch) super.dispose();
origin.y = -vertical.getMaximum() + ch; }
} else { /* image is less higher than client area */
vertical.setMaximum((int) (ch));
vertical.setEnabled(false);
}
vertical.setSelection(-origin.y);
vertical.setThumb(ch);
ruler.setScaleFactor(scaleFactor);
redraw();
}
/* Paint function */ /* Initalize the scrollbar and register listeners. */
private void paint(GC gc) { private void initScrollBars() {
Rectangle clientRect = getClientArea(); /* Canvas' painting area */ ScrollBar horizontal = getHorizontalBar();
clientRect.x=-origin.x; horizontal.setEnabled(false);
clientRect.y=-origin.y; horizontal.setVisible(true);
// reset the transform horizontal.addSelectionListener(new SelectionAdapter() {
transform.identity(); public void widgetSelected(SelectionEvent event) {
// shift the content if (painterList.size() == 0)
transform.translate(origin.x, origin.y); return;
gc.setTransform(transform); setOrigin(-((ScrollBar) event.widget).getSelection(), origin.y);
if (ruler != null)
ruler.setStartPoint(-origin.x * scaleFactor);
}
});
ScrollBar vertical = getVerticalBar();
vertical.setEnabled(false);
vertical.setVisible(true);
vertical.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (painterList.size() == 0)
return;
setOrigin(origin.x, -((ScrollBar) event.widget).getSelection());
}
});
}
/**
* Synchronize the scrollbar with the image. If the transform is out of
* range, it will correct it. This function considers only following factors
* :<b> transform, image size, client area</b>.
*/
private void syncScrollBars() {
if (painterList.size() == 0) {
redraw();
return;
}
int height = 1;
if (trackVerticalOffset.size() > 0)
height = trackVerticalOffset.lastKey() + trackVerticalOffset.lastEntry().getValue().getMinHeight();
int width = (int) (maxTime / scaleFactor);
ScrollBar horizontal = getHorizontalBar();
horizontal.setIncrement((int) (getClientArea().width / 100));
horizontal.setPageIncrement(getClientArea().width);
int cw = getClientArea().width;
if (width > cw) { /* image is wider than client area */
horizontal.setMaximum(width);
horizontal.setEnabled(true);
if (((int) -origin.x) > horizontal.getMaximum() - cw)
origin.x = -horizontal.getMaximum() + cw;
} else { /* image is narrower than client area */
horizontal.setEnabled(false);
}
horizontal.setSelection(-origin.x);
horizontal.setThumb(cw);
ScrollBar vertical = getVerticalBar();
vertical.setIncrement((int) (getClientArea().height / 100));
vertical.setPageIncrement((int) (getClientArea().height));
int ch = getClientArea().height;
if (height > ch) { /* image is higher than client area */
vertical.setMaximum(height);
vertical.setEnabled(true);
if (((int) -origin.y) > vertical.getMaximum() - ch)
origin.y = -vertical.getMaximum() + ch;
} else { /* image is less higher than client area */
vertical.setMaximum((int) (ch));
vertical.setEnabled(false);
}
vertical.setSelection(-origin.y);
vertical.setThumb(ch);
ruler.setScaleFactor(scaleFactor);
redraw();
Event e = new Event();
e.widget = this;
SelectionEvent ev = new SelectionEvent(e);
ev.x = origin.x;
ev.y = origin.y;
for (SelectionAdapter a : selectionListeners) {
a.widgetSelected(ev);
}
}
/* Paint function */
private void paint(GC gc) {
Rectangle clientRect = getClientArea(); /* Canvas' painting area */
clientRect.x = -origin.x;
clientRect.y = -origin.y;
// reset the transform
transform.identity();
// shift the content
transform.translate(origin.x, origin.y);
gc.setTransform(transform);
gc.setClipping(clientRect); gc.setClipping(clientRect);
if (painterList.size()>0 && trackVerticalOffset.size()>0) { if (painterList.size() > 0 && trackVerticalOffset.size() > 0) {
for(IPainter painter: painterList) for (IPainter painter : painterList)
painter.paintArea(gc, clientRect); painter.paintArea(gc, clientRect);
} else { } else {
gc.fillRectangle(clientRect); gc.fillRectangle(clientRect);
initScrollBars(); initScrollBars();
} }
} }
public Object getClicked(Point point) { public Object getClicked(Point point) {
for(IPainter p:Lists.reverse(painterList)){ for (IPainter p : Lists.reverse(painterList)) {
if(p instanceof TrackPainter){ if (p instanceof TrackPainter) {
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 = trackVerticalOffset.floorEntry(y); Entry<Integer, IWaveformPainter> entry = trackVerticalOffset.floorEntry(y);
if(entry!=null){ if (entry != null) {
if(entry.getValue() instanceof StreamPainter){ if (entry.getValue() instanceof StreamPainter) {
return ((StreamPainter)entry.getValue()).getClicked(new Point(x,y-entry.getKey())); return ((StreamPainter) entry.getValue()).getClicked(new Point(x, y - entry.getKey()));
}else if(entry.getValue() instanceof SignalPainter) } else if (entry.getValue() instanceof SignalPainter)
return ((SignalPainter)entry.getValue()).getSignal(); return ((SignalPainter) entry.getValue()).getSignal();
} }
}else if(p instanceof CursorPainter){ } else if (p instanceof CursorPainter) {
if(Math.abs(point.x*scaleFactor-((CursorPainter)p).getTime())<2){ if (Math.abs(point.x * scaleFactor - ((CursorPainter) p).getTime()) < 2) {
return p; return p;
} }
} }
} }
return null; return null;
} }
public void setSelected(ITx currentSelection, IWaveform<? extends IWaveformEvent> currentWaveformSelection) { public void setSelected(ITx currentSelection, IWaveform<? extends IWaveformEvent> currentWaveformSelection) {
this.currentSelection=currentSelection; this.currentSelection = currentSelection;
this.currentWaveformSelection=currentWaveformSelection; this.currentWaveformSelection = currentWaveformSelection;
if(currentSelection!=null) reveal(currentSelection); if (currentSelection != null)
redraw(); reveal(currentSelection);
} redraw();
}
public void reveal(ITx tx){ public void reveal(ITx tx) {
int lower = (int) (tx.getBeginTime()/scaleFactor); int lower = (int) (tx.getBeginTime() / scaleFactor);
int higher=(int) (tx.getEndTime()/scaleFactor); int higher = (int) (tx.getEndTime() / scaleFactor);
Point size = getSize(); Point size = getSize();
if(lower<-origin.x){ size.x -= getVerticalBar().getSize().x + 2;
scrollToX(lower); size.y -= getHorizontalBar().getSize().y;
} else if(higher>(size.x-origin.x)){ if (lower < -origin.x) {
scrollToX(higher-size.x); setOrigin(-lower, origin.y);
} } else if (higher > (size.x - origin.x)) {
for(Entry<Integer, IWaveformPainter> entry:trackVerticalOffset.entrySet()){ setOrigin(size.x - higher, origin.y);
if(entry.getValue() instanceof StreamPainter && ((StreamPainter)entry.getValue()).getStream()==tx.getStream()){ }
int top = entry.getKey()+trackHeight*tx.getConcurrencyIndex(); for (Entry<Integer, IWaveformPainter> entry : trackVerticalOffset.entrySet()) {
int bottom = top+trackHeight*(tx.getConcurrencyIndex()+1); if (entry.getValue() instanceof StreamPainter && ((StreamPainter) entry.getValue()).getStream() == tx.getStream()) {
if(top<-origin.y){ int top = entry.getKey() + trackHeight * tx.getConcurrencyIndex();
scrollToY(bottom); int bottom = top + trackHeight;
} else if(bottom>(size.y-origin.y)){ if (top < -origin.y) {
scrollToY(bottom-size.y); setOrigin(origin.x, -top);
} } else if (bottom > (size.y - origin.y)) {
setOrigin(origin.x, size.y - bottom);
} }
} }
} }
}
public void addSelectionListener(SelectionAdapter selectionAdapter) {
selectionListeners.add(selectionAdapter);
}
public void removeSelectionListener(SelectionAdapter selectionAdapter) {
selectionListeners.remove(selectionAdapter);
}
} }

View File

@ -53,6 +53,7 @@ public class TextDbLoader implements IWaveformDbLoader{
@Override @Override
boolean load(IWaveformDb db, File file) throws Exception { boolean load(IWaveformDb db, File file) throws Exception {
this.db=db this.db=db
this.streams=[]
FileInputStream fis = new FileInputStream(file) FileInputStream fis = new FileInputStream(file)
byte[] buffer = new byte[x.size()] byte[] buffer = new byte[x.size()]
def readCnt = fis.read(buffer, 0, x.size()) def readCnt = fis.read(buffer, 0, x.size())

View File

@ -51,7 +51,11 @@ class Tx implements ITx {
@Override @Override
public int compareTo(ITx o) { public int compareTo(ITx o) {
return beginTime.compareTo(o.beginTime) def res =beginTime.compareTo(o.beginTime)
if(res!=0)
return res
else
return id.compareTo(o.id)
} }
} }

View File

@ -8,12 +8,15 @@ class TxEvent implements ITxEvent {
final ITxEvent.Type type; final ITxEvent.Type type;
Tx transaction; final Tx transaction;
final Long time
TxEvent(ITxEvent.Type type, ITx transaction) { TxEvent(ITxEvent.Type type, ITx transaction) {
super(); super();
this.type = type; this.type = type;
this.transaction = transaction; this.transaction = transaction;
this.time = type==ITxEvent.Type.BEGIN?transaction.beginTime:transaction.endTime
} }
@Override @Override
@ -23,15 +26,11 @@ class TxEvent implements ITxEvent {
@Override @Override
int compareTo(IWaveformEvent o) { int compareTo(IWaveformEvent o) {
time.compareTo(o.getTime()) time.compareTo(o.time)
} }
Long getTime(){ @Override
type==ITxEvent.Type.BEGIN?transaction.beginTime:transaction.endTime
}
@Override
String toString() { String toString() {
type.toString()+"@"+getTime()+" of tx #"+transaction.id; type.toString()+"@"+time+" of tx #"+transaction.id;
} }
} }

View File

@ -92,8 +92,10 @@ class TxStream extends HierNode implements ITxStream {
} }
private putEvent(ITxEvent event){ private putEvent(ITxEvent event){
if(!events.containsKey(event.time)) events.put(event.time, []) if(!events.containsKey(event.time))
events[event.time]<<event events.put(event.time, [event])
else
events[event.time]<<event
} }
@Override @Override

View File

@ -8,3 +8,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: com.minres.scviewer.database Export-Package: com.minres.scviewer.database
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/component.xml Service-Component: OSGI-INF/component.xml
Require-Bundle: org.eclipse.equinox.ds;bundle-version="1.4.200",
org.eclipse.equinox.util;bundle-version="1.0.500",
org.eclipse.osgi.services;bundle-version="3.4.0"

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.database"> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.database">
<implementation class="com.minres.scviewer.database.WaveformDb"/> <implementation class="com.minres.scviewer.database.WaveformDb"/>
<reference bind="bind" cardinality="0..n" interface="com.minres.scviewer.database.IWaveformDbLoader" name="IWaveformDbLoader" policy="dynamic" unbind="unbind"/> <reference bind="bind" cardinality="1..n" interface="com.minres.scviewer.database.IWaveformDbLoader" name="IWaveformDbLoader" policy="dynamic" unbind="unbind"/>
</scr:component> </scr:component>

View File

@ -29,11 +29,11 @@ http://www.eclipse.org/legal/epl-v10.html
</url> </url>
<requires> <requires>
<import plugin="org.eclipse.equinox.ds" version="1.4.200" match="greaterOrEqual"/>
<import plugin="org.eclipse.equinox.util" version="1.0.500" match="greaterOrEqual"/>
<import plugin="org.eclipse.osgi.services" version="3.4.0" match="greaterOrEqual"/>
<import plugin="com.minres.scviewer.database" version="1.0.0" match="greaterOrEqual"/> <import plugin="com.minres.scviewer.database" version="1.0.0" match="greaterOrEqual"/>
<import plugin="org.codehaus.groovy" version="1.8.6" match="greaterOrEqual"/> <import plugin="org.codehaus.groovy" version="1.8.6" match="greaterOrEqual"/>
<import plugin="org.eclipse.equinox.util" version="1.0.500" match="greaterOrEqual"/>
<import plugin="org.eclipse.equinox.ds" version="1.4.200" match="greaterOrEqual"/>
<import plugin="org.eclipse.osgi.services" version="3.4.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.osgi"/> <import plugin="org.eclipse.osgi"/>
<import plugin="org.eclipse.core.runtime"/> <import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.core.resources"/> <import plugin="org.eclipse.core.resources"/>
@ -43,9 +43,14 @@ http://www.eclipse.org/legal/epl-v10.html
<import plugin="org.eclipse.ui.ide"/> <import plugin="org.eclipse.ui.ide"/>
<import plugin="org.eclipse.ui.views.properties.tabbed"/> <import plugin="org.eclipse.ui.views.properties.tabbed"/>
<import plugin="org.eclipse.swt"/> <import plugin="org.eclipse.swt"/>
<import plugin="org.eclipse.ui.views"/>
<import plugin="org.apache.ant"/> <import plugin="org.apache.ant"/>
<import plugin="com.google.guava" version="15.0.0" match="greaterOrEqual"/>
<import plugin="com.minres.scviewer.database.swt" version="1.0.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.expressions" version="3.4.600" match="greaterOrEqual"/>
<import plugin="org.eclipse.jface"/>
<import plugin="org.junit"/> <import plugin="org.junit"/>
<import plugin="org.eclipse.swt" version="3.103.1" match="greaterOrEqual"/>
<import plugin="org.eclipse.equinox.registry"/>
</requires> </requires>
<plugin <plugin
@ -96,4 +101,17 @@ http://www.eclipse.org/legal/epl-v10.html
version="0.0.0" version="0.0.0"
unpack="false"/> unpack="false"/>
<plugin
id="org.junit"
download-size="0"
install-size="0"
version="0.0.0"/>
<plugin
id="org.hamcrest.core"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature> </feature>