- added conext menu

- added option to remove waves
- fixed painting errors
This commit is contained in:
ejentzsx 2015-01-29 11:02:03 +01:00
parent 8c60a53ebe
commit 310c9bbb8f
9 changed files with 537 additions and 219 deletions

View File

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database.swt; package com.minres.scviewer.database.swt;
import java.awt.PageAttributes.OriginType;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.HashMap; import java.util.HashMap;
@ -29,6 +30,15 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
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.MouseEvent; import org.eclipse.swt.events.MouseEvent;
@ -50,6 +60,7 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.wb.swt.SWTResourceManager;
import swing2swt.layout.BorderLayout; import swing2swt.layout.BorderLayout;
@ -110,19 +121,24 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
top.setLayout(new FillLayout(SWT.HORIZONTAL)); top.setLayout(new FillLayout(SWT.HORIZONTAL));
SashForm topSash = new SashForm(top, SWT.SMOOTH); SashForm topSash = new SashForm(top, SWT.SMOOTH);
topSash.setBackground(topSash.getDisplay().getSystemColor( SWT.COLOR_GRAY)); topSash.setBackground(topSash.getDisplay().getSystemColor(
SWT.COLOR_GRAY));
Composite composite = new Composite(topSash, SWT.NONE); Composite composite = new Composite(topSash, SWT.NONE);
composite.setLayout(new FillLayout(SWT.HORIZONTAL)); composite.setLayout(new FillLayout(SWT.HORIZONTAL));
SashForm leftSash = new SashForm(composite, SWT.SMOOTH); SashForm leftSash = new SashForm(composite, SWT.SMOOTH);
leftSash.setBackground(leftSash.getDisplay().getSystemColor( SWT.COLOR_GRAY)); leftSash.setBackground(leftSash.getDisplay().getSystemColor(
SWT.COLOR_GRAY));
Composite namePane = createTextPane(leftSash, "Name"); Composite namePane = createTextPane(leftSash, "Name");
namePane.setBackground(namePane.getDisplay().getSystemColor( SWT.COLOR_WIDGET_BACKGROUND)); namePane.setBackground(namePane.getDisplay().getSystemColor(
SWT.COLOR_WIDGET_BACKGROUND));
nameListScrolled = new ScrolledComposite(namePane, SWT.H_SCROLL | SWT.V_SCROLL); nameListScrolled = new ScrolledComposite(namePane, SWT.H_SCROLL
nameListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); | SWT.V_SCROLL);
nameListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true, 1, 1));
nameListScrolled.setExpandHorizontal(true); nameListScrolled.setExpandHorizontal(true);
nameListScrolled.setExpandVertical(true); nameListScrolled.setExpandVertical(true);
nameListScrolled.setAlwaysShowScrollBars(true); nameListScrolled.setAlwaysShowScrollBars(true);
@ -152,9 +168,12 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
nameListScrolled.setContent(nameList); nameListScrolled.setContent(nameList);
Composite valuePane = createTextPane(leftSash, "Value"); Composite valuePane = createTextPane(leftSash, "Value");
valuePane.setBackground(valuePane.getDisplay().getSystemColor( SWT.COLOR_WIDGET_BACKGROUND)); valuePane.setBackground(valuePane.getDisplay().getSystemColor(
valueListScrolled = new ScrolledComposite(valuePane, SWT.H_SCROLL | SWT.V_SCROLL); SWT.COLOR_WIDGET_BACKGROUND));
valueListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); valueListScrolled = new ScrolledComposite(valuePane, SWT.H_SCROLL
| SWT.V_SCROLL);
valueListScrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true, 1, 1));
valueListScrolled.setExpandHorizontal(true); valueListScrolled.setExpandHorizontal(true);
valueListScrolled.setExpandVertical(true); valueListScrolled.setExpandVertical(true);
valueListScrolled.setAlwaysShowScrollBars(true); valueListScrolled.setAlwaysShowScrollBars(true);
@ -193,23 +212,28 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
trackList.setStreams(streams); trackList.setStreams(streams);
trackList.setRuler(ruler); trackList.setRuler(ruler);
trackList.addPainter(new TrackPainter(trackList)); trackList.addPainter(new TrackPainter(trackList));
CursorPainter cp = new CursorPainter(trackList, trackList.getScaleFactor()*10); CursorPainter cp = new CursorPainter(trackList,
trackList.getScaleFactor() * 10);
trackList.addPainter(cp); trackList.addPainter(cp);
cursorPainters.add(cp); cursorPainters.add(cp);
trackList.setMaxTime(1); trackList.setMaxTime(1);
trackList.addMouseListener(this); trackList.addMouseListener(this);
nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() { nameListScrolled.getVerticalBar().addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int y = ((ScrollBar) e.widget).getSelection(); int y = ((ScrollBar) e.widget).getSelection();
valueListScrolled.setOrigin(valueListScrolled.getOrigin().x, y); valueListScrolled.setOrigin(
valueListScrolled.getOrigin().x, y);
trackList.scrollToY(y); trackList.scrollToY(y);
} }
}); });
valueListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() { valueListScrolled.getVerticalBar().addSelectionListener(
new SelectionAdapter() {
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);
trackList.scrollToY(y); trackList.scrollToY(y);
} }
}); });
@ -222,10 +246,13 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
}); });
topSash.setWeights(new int[] { 30, 70 }); topSash.setWeights(new int[] { 30, 70 });
leftSash.setWeights(new int[] { 75, 25 }); leftSash.setWeights(new int[] { 75, 25 });
createDragSource(nameList);
createDragSource(valueList);
createDropTarget(nameList);
createDropTarget(valueList);
} }
private Composite createTextPane(SashForm leftSash, String text) { private Composite createTextPane(SashForm leftSash, String text) {
Composite namePane = new Composite(leftSash, SWT.NONE); Composite namePane = new Composite(leftSash, SWT.NONE);
GridLayout gl_namePane = new GridLayout(1, false); GridLayout gl_namePane = new GridLayout(1, false);
@ -236,7 +263,8 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
namePane.setLayout(gl_namePane); namePane.setLayout(gl_namePane);
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 gd_nameLabel = new GridData(SWT.CENTER, SWT.CENTER, true,
false, 1, 1);
gd_nameLabel.heightHint = Ruler.height - 2; gd_nameLabel.heightHint = Ruler.height - 2;
nameLabel.setLayoutData(gd_nameLabel); nameLabel.setLayoutData(gd_nameLabel);
nameLabel.setText(text); nameLabel.setText(text);
@ -244,7 +272,8 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
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 gd_nameSep = new GridData(SWT.FILL, SWT.CENTER, true, false,
1, 1);
gd_nameSep.heightHint = 2; gd_nameSep.heightHint = 2;
nameSep.setLayoutData(gd_nameSep); nameSep.setLayoutData(gd_nameSep);
return namePane; return namePane;
@ -261,7 +290,7 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
protected void updateTracklist() { protected void updateTracklist() {
int yoffs = 0; int yoffs = 0;
int nameMaxWidth = 0; int nameMaxWidth = 0;
int previousHeight=trackVerticalOffset.size()==0?0: trackVerticalOffset.lastKey();
IWaveformPainter painter = null; IWaveformPainter painter = null;
trackVerticalOffset.clear(); trackVerticalOffset.clear();
actualValues.clear(); actualValues.clear();
@ -276,7 +305,8 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
painter = new StreamPainter(trackList, even, height, (ITxStream<? extends ITxEvent>) waveform); painter = new StreamPainter(trackList, even, height, (ITxStream<? extends ITxEvent>) waveform);
actualValues.put(waveform, ""); actualValues.put(waveform, "");
} else if (waveform instanceof ISignal<?>) { } else if (waveform instanceof ISignal<?>) {
painter= new SignalPainter(trackList, even, height, (ISignal<?>) waveform); painter = new SignalPainter(trackList, even, height,
(ISignal<?>) waveform);
actualValues.put(waveform, "---"); actualValues.put(waveform, "---");
} }
trackList.addWavefromPainter(yoffs, painter); trackList.addWavefromPainter(yoffs, painter);
@ -294,6 +324,10 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
valueList.redraw(); valueList.redraw();
trackList.redraw(); trackList.redraw();
top.layout(new Control[] { valueList, nameList, trackList }); top.layout(new Control[] { valueList, nameList, trackList });
if(previousHeight>trackVerticalOffset.lastKey()){
trackList.scrollToY(trackList.getOrigin().y-(previousHeight-trackVerticalOffset.lastKey()));
}
setSelection(new StructuredSelection());
} }
private int calculateValueWidth() { private int calculateValueWidth() {
@ -313,10 +347,15 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
} }
@Override @Override
public void removeSelectionChangedListener(ISelectionChangedListener listener) { public void removeSelectionChangedListener(
ISelectionChangedListener listener) {
listeners.remove(listener); listeners.remove(listener);
} }
public Control getControl(){
return top;
}
@Override @Override
public ISelection getSelection() { public ISelection getSelection() {
if (currentSelection != null) if (currentSelection != null)
@ -337,16 +376,21 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
currentSelection = (ITx) sel; currentSelection = (ITx) sel;
currentWaveformSelection = currentSelection.getStream(); currentWaveformSelection = currentSelection.getStream();
selectionChanged = true; selectionChanged = true;
} else if(sel instanceof IWaveform<?> && currentWaveformSelection!=sel){ } else if (sel instanceof IWaveform<?>
&& currentWaveformSelection != sel) {
currentSelection = null; currentSelection = null;
currentWaveformSelection = (IWaveform<? extends IWaveformEvent>) sel; currentWaveformSelection = (IWaveform<? extends IWaveformEvent>) sel;
selectionChanged = true; selectionChanged = true;
} }
} else { } else {
if(currentSelection!=null || currentWaveformSelection!=null) selectionChanged=true; if (currentSelection != null || currentWaveformSelection != null)
selectionChanged = true;
currentSelection = null; currentSelection = null;
currentWaveformSelection = null; currentWaveformSelection = null;
} }
if(currentWaveformSelection!=null && !streams.contains(currentWaveformSelection)){
streams.add(currentWaveformSelection);
}
if (selectionChanged) { if (selectionChanged) {
trackList.setSelected(currentSelection, currentWaveformSelection); trackList.setSelected(currentSelection, currentWaveformSelection);
nameList.setData(SELECTION, currentWaveformSelection); nameList.setData(SELECTION, currentWaveformSelection);
@ -402,16 +446,22 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@Override @Override
public void mouseDown(MouseEvent e) { public void mouseDown(MouseEvent e) {
if(e.button==1 || e.button==3){
if (e.widget == trackList) { if (e.widget == trackList) {
Object o = trackList.getClicked(new Point(e.x, e.y)); Object o = trackList.getClicked(new Point(e.x, e.y));
if (o != null) if (o != null)
setSelection(new StructuredSelection(o)); setSelection(new StructuredSelection(o));
} else if (e.widget == valueList || e.widget == nameList) { } else if (e.widget == valueList || e.widget == nameList) {
Entry<Integer, IWaveform<? extends IWaveformEvent>> entry = trackVerticalOffset.floorEntry(e.y); Entry<Integer, IWaveform<? extends IWaveformEvent>> entry = trackVerticalOffset
.floorEntry(e.y);
if (entry != null) if (entry != null)
setSelection(new StructuredSelection(entry.getValue())); setSelection(new StructuredSelection(entry.getValue()));
} }
} }
if(e.button==3){
top.getMenu().setVisible(true);
}
}
@Override @Override
public void mouseUp(MouseEvent e) { public void mouseUp(MouseEvent e) {
@ -424,23 +474,33 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
protected void paintNames(GC gc, Rectangle rect) { protected void paintNames(GC gc, Rectangle rect) {
if (streams.size() > 0) { if (streams.size() > 0) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
IWaveform<? extends IWaveformEvent> wave = (IWaveform<? extends IWaveformEvent>) nameList.getData(SELECTION); IWaveform<? extends IWaveformEvent> wave = (IWaveform<? extends IWaveformEvent>) nameList
.getData(SELECTION);
Integer firstKey = trackVerticalOffset.floorKey(rect.y); Integer firstKey = trackVerticalOffset.floorKey(rect.y);
if(firstKey==null) firstKey=trackVerticalOffset.firstKey(); if (firstKey == null)
Integer lastKey = trackVerticalOffset.floorKey(rect.y+rect.height); firstKey = trackVerticalOffset.firstKey();
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, trackList.getTrackHeight()); Integer lastKey = trackVerticalOffset
.floorKey(rect.y + rect.height);
Rectangle subArea = new Rectangle(rect.x, 0, rect.width,
trackList.getTrackHeight());
if (lastKey == firstKey) { if (lastKey == firstKey) {
IWaveform<? extends IWaveformEvent> w = trackVerticalOffset.get(firstKey); IWaveform<? extends IWaveformEvent> w = trackVerticalOffset
.get(firstKey);
if (w instanceof ITxStream<?>) if (w instanceof ITxStream<?>)
subArea.height *= ((ITxStream<?>) w).getMaxConcurrency(); subArea.height *= ((ITxStream<?>) w).getMaxConcurrency();
drawTextFormat(gc, subArea, firstKey, w.getFullName(), wave!=null && w.getId()==wave.getId()); drawTextFormat(gc, subArea, firstKey, w.getFullName(),
wave != null && w.getId() == wave.getId());
} else { } else {
for(Entry<Integer, IWaveform<? extends IWaveformEvent>> entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()){ for (Entry<Integer, IWaveform<? extends IWaveformEvent>> entry : trackVerticalOffset
.subMap(firstKey, true, lastKey, true).entrySet()) {
IWaveform<? extends IWaveformEvent> w = entry.getValue(); IWaveform<? extends IWaveformEvent> w = entry.getValue();
subArea.height = trackList.getTrackHeight(); subArea.height = trackList.getTrackHeight();
if (w instanceof ITxStream<?>) if (w instanceof ITxStream<?>)
subArea.height*=((ITxStream<?>)w).getMaxConcurrency(); subArea.height *= ((ITxStream<?>) w)
drawTextFormat(gc, subArea, entry.getKey(), w.getFullName(), wave!=null && w.getId()==wave.getId()); .getMaxConcurrency();
drawTextFormat(gc, subArea, entry.getKey(),
w.getFullName(),
wave != null && w.getId() == wave.getId());
} }
} }
} }
@ -449,41 +509,61 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void paintValues(GC gc, Rectangle rect) { protected void paintValues(GC gc, Rectangle rect) {
if (streams.size() > 0) { if (streams.size() > 0) {
IWaveform<? extends IWaveformEvent> wave = (IWaveform<? extends IWaveformEvent>) nameList.getData(SELECTION); IWaveform<? extends IWaveformEvent> wave = (IWaveform<? extends IWaveformEvent>) nameList
.getData(SELECTION);
Integer firstKey = trackVerticalOffset.floorKey(rect.y); Integer firstKey = trackVerticalOffset.floorKey(rect.y);
if(firstKey==null) firstKey=trackVerticalOffset.firstKey(); if (firstKey == null)
Integer lastKey = trackVerticalOffset.floorKey(rect.y+rect.height); firstKey = trackVerticalOffset.firstKey();
Rectangle subArea = new Rectangle(rect.x, 0, rect.width, trackList.getTrackHeight()); Integer lastKey = trackVerticalOffset
.floorKey(rect.y + rect.height);
Rectangle subArea = new Rectangle(rect.x, 0, rect.width,
trackList.getTrackHeight());
if (lastKey == firstKey) { if (lastKey == firstKey) {
IWaveform<? extends IWaveformEvent> w = trackVerticalOffset.get(firstKey); IWaveform<? extends IWaveformEvent> w = trackVerticalOffset
.get(firstKey);
if (w instanceof ITxStream<?>) if (w instanceof ITxStream<?>)
subArea.height *= ((ITxStream<?>) w).getMaxConcurrency(); subArea.height *= ((ITxStream<?>) w).getMaxConcurrency();
drawTextFormat(gc, subArea, firstKey, actualValues.get(w), wave!=null && w.getId()==wave.getId()); drawTextFormat(gc, subArea, firstKey, actualValues.get(w),
wave != null && w.getId() == wave.getId());
} else { } else {
for(Entry<Integer, IWaveform<? extends IWaveformEvent>> entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()){ for (Entry<Integer, IWaveform<? extends IWaveformEvent>> entry : trackVerticalOffset
.subMap(firstKey, true, lastKey, true).entrySet()) {
IWaveform<? extends IWaveformEvent> w = entry.getValue(); IWaveform<? extends IWaveformEvent> w = entry.getValue();
subArea.height = trackList.getTrackHeight(); subArea.height = trackList.getTrackHeight();
if (w instanceof ITxStream<?>) if (w instanceof ITxStream<?>)
subArea.height*=((ITxStream<?>)w).getMaxConcurrency(); subArea.height *= ((ITxStream<?>) w)
drawTextFormat(gc, subArea, entry.getKey(), actualValues.get(w), wave!=null && w.getId()==wave.getId()); .getMaxConcurrency();
drawTextFormat(gc, subArea, entry.getKey(),
actualValues.get(w), wave != null
&& w.getId() == wave.getId());
} }
} }
} }
} }
protected void drawTextFormat(GC gc, Rectangle subArea, int yOffset, String value, boolean highlite) { protected void drawTextFormat(GC gc, Rectangle subArea, int yOffset,
String value, boolean highlite) {
Point size = gc.textExtent(value); Point size = gc.textExtent(value);
if (highlite) { if (highlite) {
gc.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION)); gc.setBackground(SWTResourceManager
gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION_TEXT)); .getColor(SWT.COLOR_LIST_SELECTION));
gc.fillRectangle(subArea.x, subArea.y+yOffset, subArea.width, subArea.height); gc.setForeground(SWTResourceManager
.getColor(SWT.COLOR_LIST_SELECTION_TEXT));
gc.fillRectangle(subArea.x, subArea.y + yOffset, subArea.width,
subArea.height);
gc.setFont(nameFontB); gc.setFont(nameFontB);
} else { } else {
gc.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND)); gc.setBackground(SWTResourceManager
gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_FOREGROUND)); .getColor(SWT.COLOR_LIST_BACKGROUND));
gc.setForeground(SWTResourceManager
.getColor(SWT.COLOR_LIST_FOREGROUND));
gc.setFont(nameFont); gc.setFont(nameFont);
} }
gc.drawText(value, subArea.x+5, subArea.y + yOffset+(trackList.getTrackHeight()-size.y)/2, true); gc.drawText(
value,
subArea.x + 5,
subArea.y + yOffset + (trackList.getTrackHeight() - size.y) / 2,
true);
} }
public long getMaxTime() { public long getMaxTime() {
@ -501,7 +581,66 @@ public class TxDisplay implements PropertyChangeListener, ISelectionProvider, Mo
public int getZoomLevel() { public int getZoomLevel() {
return trackList.getZoomLevel(); return trackList.getZoomLevel();
} }
// public long getScaleFactor(){
// return trackList.getScaleFactor(); private void createDragSource(final Canvas sourceText) {
// } Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
DragSource dragSource = new DragSource(sourceText, DND.DROP_MOVE);
dragSource.setTransfer(types);
dragSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
if (event.y < trackVerticalOffset.lastKey() + trackList.getTrackHeight()) {
// event.data = trackVerticalOffset.floorEntry(event.y).getValue().getFullName();
event.doit = true;
// System.out.println("dragStart at location "+new Point(event.x, event.y));
}
}
public void dragSetData(DragSourceEvent event) {
event.data = trackVerticalOffset.floorEntry(event.y).getValue().getFullName();
// System.out.println("dragSetData with data " + event.data);
}
public void dragFinished(DragSourceEvent event) {
// do nothing
}
});
}
private void createDropTarget(final Canvas targetText) {
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
DropTarget dropTarget = new DropTarget(targetText, DND.DROP_MOVE);
dropTarget.setTransfer(types);
dropTarget.addDropListener(new DropTargetListener() {
public void dragEnter(DropTargetEvent event) {
}
public void dragLeave(DropTargetEvent event) {
}
public void dragOperationChanged(DropTargetEvent event) {
}
public void dragOver(DropTargetEvent event) {
}
public void drop(DropTargetEvent event) {
Object data = event.data;
DropTarget tgt = (DropTarget) event.widget;
Point dropPoint = ((Canvas)tgt.getControl()).toControl(event.x, event.y);
String fullname1 = trackVerticalOffset.floorEntry(dropPoint.y).getValue().getFullName();
// System.out.println("drop with data '" + event.data +"' at location "+dropPoint + " and origin " + nameListScrolled.getOrigin());
// System.out.println("drop on " + fullname1);
}
public void dropAccept(DropTargetEvent event) {
if (event.detail != DND.DROP_MOVE || event.y > trackVerticalOffset.lastKey() + trackList.getTrackHeight()) {
event.detail = DND.DROP_NONE;
}
}
});
}
} }

View File

@ -102,7 +102,9 @@ public class StreamPainter implements IWaveformPainter{
(int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+upper, (int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+upper,
(int)((tx.getEndTime()-tx.getBeginTime())/this.waveCanvas.getScaleFactor()), txHeight); (int)((tx.getEndTime()-tx.getBeginTime())/this.waveCanvas.getScaleFactor()), txHeight);
if(bb.x+bb.width<area.x || bb.x>area.x+area.width) return; if(bb.x+bb.width<area.x || bb.x>area.x+area.width) return;
if(bb.width<10){ if(bb.width==0){
gc.drawLine(bb.x, bb.y, bb.x, bb.y+bb.height);
} else if(bb.width<10){
gc.fillRectangle(bb); gc.fillRectangle(bb);
gc.drawRectangle(bb); gc.drawRectangle(bb);
} else { } else {
@ -129,6 +131,14 @@ public class StreamPainter implements IWaveformPainter{
return stream; return stream;
} }
public ITxStream<? extends ITxEvent> getStream() {
return stream;
}
public void setStream(ITxStream<? extends ITxEvent> stream) {
this.stream = stream;
}
protected ITx getTxFromEntry(int lane, Entry<Long, List<ITxEvent>> firstTx) { protected ITx getTxFromEntry(int lane, Entry<Long, List<ITxEvent>> firstTx) {
for(ITxEvent evt:firstTx.getValue()){ for(ITxEvent evt:firstTx.getValue()){
if(evt.getType()==ITxEvent.Type.BEGIN && evt.getTransaction().getConcurrencyIndex()==lane){ if(evt.getType()==ITxEvent.Type.BEGIN && evt.getTransaction().getConcurrencyIndex()==lane){

View File

@ -12,6 +12,7 @@ package com.minres.scviewer.database.swt.internal;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
@ -30,6 +31,9 @@ public class TrackPainter implements IPainter {
} }
public void paintArea(GC gc, Rectangle area) { public void paintArea(GC gc, Rectangle area) {
gc.setBackground(this.waveCanvas.colors[WaveformCanvas.Colors.TRACK_BG_EVEN.ordinal()]);
gc.setFillRule(SWT.FILL_EVEN_ODD);
gc.fillRectangle(area);
if(this.waveCanvas.streams.size()>0){ if(this.waveCanvas.streams.size()>0){
Integer firstKey=this.waveCanvas.trackVerticalOffset.floorKey(area.y); Integer firstKey=this.waveCanvas.trackVerticalOffset.floorKey(area.y);
if(firstKey==null) firstKey=this.waveCanvas.trackVerticalOffset.firstKey(); if(firstKey==null) firstKey=this.waveCanvas.trackVerticalOffset.firstKey();

View File

@ -144,7 +144,7 @@ public class WaveformCanvas extends Canvas {
this.ruler=ruler; this.ruler=ruler;
} }
public Object getOrigin() { public Point getOrigin() {
return origin; return origin;
} }
@ -350,19 +350,31 @@ public class WaveformCanvas extends Canvas {
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.getBeginTime(), currentSelection.getEndTime()); if(currentSelection!=null) reveal(currentSelection);
redraw(); redraw();
} }
public void reveal(Long beginTime, Long endTime) { public void reveal(ITx tx){
int lower = (int) (beginTime/scaleFactor); int lower = (int) (tx.getBeginTime()/scaleFactor);
int higher=(int) (endTime/scaleFactor); int higher=(int) (tx.getEndTime()/scaleFactor);
Point size = getSize(); Point size = getSize();
if(lower<-origin.x){ if(lower<-origin.x){
scrollToX(lower); scrollToX(lower);
} else if(higher>(size.x-origin.x)){ } else if(higher>(size.x-origin.x)){
scrollToX(higher-size.x); scrollToX(higher-size.x);
} }
for(Entry<Integer, IWaveformPainter> entry:trackVerticalOffset.entrySet()){
if(entry.getValue() instanceof StreamPainter && ((StreamPainter)entry.getValue()).getStream()==tx.getStream()){
int top = entry.getKey()+trackHeight*tx.getConcurrencyIndex();
int bottom = top+trackHeight*(tx.getConcurrencyIndex()+1);
if(top<-origin.y){
scrollToY(bottom);
} else if(bottom>(size.y-origin.y)){
scrollToY(bottom-size.y);
}
}
}
} }
} }

View File

@ -4,4 +4,5 @@ org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -289,6 +289,70 @@
</parameter> </parameter>
</command> </command>
</menuContribution> </menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:com.minres.scviewer.ui.TxEditorPart">
<command
commandId="com.minres.scviewer.ui.removeWave"
label="Remove"
style="push"
tooltip="Go to next event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoomin"
label="Zoom in"
style="push"
tooltip="Zoom into">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoomout"
label="Zoom out"
style="push"
tooltip="Zoom out of">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.gotoPrev"
label="Prev"
style="push"
tooltip="Go to previous event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.gotoNext"
label="Next"
style="push"
tooltip="Go to next event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.commands"> point="org.eclipse.ui.commands">
@ -321,6 +385,10 @@
id="com.minres.scviewer.ui.zoomout" id="com.minres.scviewer.ui.zoomout"
name="Zoom out"> name="Zoom out">
</command> </command>
<command
id="com.minres.scviewer.ui.removeWave"
name="Remove wave">
</command>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.handlers"> point="org.eclipse.ui.handlers">
@ -329,7 +397,7 @@
commandId="com.minres.scviewer.ui.gotoPrev"> commandId="com.minres.scviewer.ui.gotoPrev">
<enabledWhen> <enabledWhen>
<reference <reference
definitionId="com.minres.scviewer.ui.oneElementSeleted"> definitionId="com.minres.scviewer.ui.oneTxSeleted">
</reference> </reference>
</enabledWhen> </enabledWhen>
</handler> </handler>
@ -338,7 +406,7 @@
commandId="com.minres.scviewer.ui.gotoNext"> commandId="com.minres.scviewer.ui.gotoNext">
<enabledWhen> <enabledWhen>
<reference <reference
definitionId="com.minres.scviewer.ui.oneElementSeleted"> definitionId="com.minres.scviewer.ui.oneTxSeleted">
</reference> </reference>
</enabledWhen> </enabledWhen>
</handler> </handler>
@ -360,11 +428,35 @@
</reference> </reference>
</enabledWhen> </enabledWhen>
</handler> </handler>
<handler
class="com.minres.scviewer.ui.handler.RemoveHandler"
commandId="com.minres.scviewer.ui.removeWave">
<enabledWhen>
<reference
definitionId="com.minres.scviewer.ui.oneWaveSeleted">
</reference>
</enabledWhen>
</handler>
</extension> </extension>
<extension <extension
point="org.eclipse.core.expressions.definitions"> point="org.eclipse.core.expressions.definitions">
<definition <definition
id="com.minres.scviewer.ui.oneElementSeleted"> id="com.minres.scviewer.ui.oneWaveSeleted">
<with
variable="selection">
<and>
<count
value="1">
</count>
<iterate
operator="or">
<instanceof value="com.minres.scviewer.database.IWaveform"/>
</iterate>
</and>
</with>
</definition>
<definition
id="com.minres.scviewer.ui.oneTxSeleted">
<with <with
variable="selection"> variable="selection">
<and> <and>
@ -412,6 +504,10 @@
commandId="com.minres.scviewer.ui.zoomout" commandId="com.minres.scviewer.ui.zoomout"
icon="res/images/zoom_out.png"> icon="res/images/zoom_out.png">
</image> </image>
<image
commandId="com.minres.scviewer.ui.removeWave"
icon="res/images/cross.png">
</image>
</extension> </extension>
</plugin> </plugin>

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

View File

@ -22,11 +22,13 @@ import java.util.regex.Pattern;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineContributionItem; import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars; import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IEditorSite;
@ -110,6 +112,18 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
} }
}).run(); }).run();
zoomStatusLineItem.setText("Zoom level: "+zoomLevel[txDisplay.getZoomLevel()]); zoomStatusLineItem.setText("Zoom level: "+zoomLevel[txDisplay.getZoomLevel()]);
MenuManager menuMgr = new MenuManager("#PopupMenu");
// menuMgr.setRemoveAllWhenShown(true);
// menuMgr.addMenuListener(new IMenuListener() {
// public void menuAboutToShow(IMenuManager manager) {
// fillContextMenu(manager);
// }
// });
Menu menu = menuMgr.createContextMenu(txDisplay.getControl());
txDisplay.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, txDisplay);
} }
/* /*
@ -332,6 +346,10 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
}); });
} }
public ISelection getSelection(){
return txDisplay.getSelection();
}
@Override @Override
public String getContributorId() { public String getContributorId() {
return getSite().getId(); return getSite().getId();
@ -353,4 +371,9 @@ public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPage
return txDisplay.getZoomLevel(); return txDisplay.getZoomLevel();
} }
public void removeSelected() {
// TODO Auto-generated method stub
}
} }

View File

@ -0,0 +1,33 @@
package com.minres.scviewer.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.internal.misc.StringMatcher;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformEvent;
import com.minres.scviewer.ui.TxEditorPart;
public class RemoveHandler extends AbstractHandler {
@SuppressWarnings("unchecked")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if(editor instanceof TxEditorPart){
TxEditorPart editorPart = (TxEditorPart) editor;
ISelection selection =editorPart.getSelection();
if(selection instanceof StructuredSelection && ((StructuredSelection)selection).getFirstElement() instanceof IWaveform<?>){
editorPart.removeStreamFromList((IWaveform<? extends IWaveformEvent>) ((StructuredSelection)selection).getFirstElement());
editorPart.setSelection(new StructuredSelection());
}
}
return null;
}
}