add drag area to wavefrom view

This commit is contained in:
Eyck Jentzsch 2020-03-13 19:51:07 +01:00
parent 18f2a110f0
commit 2b7c9a240f
2 changed files with 48 additions and 25 deletions

View File

@ -40,6 +40,7 @@ import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource; import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceAdapter; import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent; import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget; import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter; import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent; import org.eclipse.swt.dnd.DropTargetEvent;
@ -50,6 +51,9 @@ import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
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.Font; import org.eclipse.swt.graphics.Font;
@ -140,13 +144,20 @@ public class WaveformViewer implements IWaveformViewer {
} }
}; };
protected MouseListener waveformMouseListener = new MouseAdapter(){ class WaveformMouseListener implements MouseMoveListener, MouseListener, PaintListener {
Point start; Point start, end;
List<Object> initialSelected; List<Object> initialSelected;
boolean down=false;
@Override
public void mouseDoubleClick(MouseEvent e) {
}
@Override @Override
public void mouseDown(MouseEvent e) { public void mouseDown(MouseEvent e) {
start=new Point(e.x, e.y); start=new Point(e.x, e.y);
end=new Point(e.x, e.y);
down=true;
if((e.stateMask&SWT.MODIFIER_MASK)!=0) return; //don't react on modifier if((e.stateMask&SWT.MODIFIER_MASK)!=0) return; //don't react on modifier
if (e.button == 1) { if (e.button == 1) {
initialSelected = waveformCanvas.getClicked(start); initialSelected = waveformCanvas.getClicked(start);
@ -156,11 +167,35 @@ public class WaveformViewer implements IWaveformViewer {
} }
} }
@Override
public void mouseMove(MouseEvent e) {
if(down) {
end=new Point(e.x, e.y);
asyncUpdate(e.widget);
}
}
@Override
public void paintControl(PaintEvent e) {
if(down) {
GC gc = e.gc;
gc.setAlpha(128);
int minX = Math.min(start.x, end.x);
int maxX = Math.max(start.x, end.x);
int width = maxX - minX;
gc.fillRectangle(minX, 0, width, e.height);
}
}
@Override @Override
public void mouseUp(MouseEvent e) { public void mouseUp(MouseEvent e) {
down=false;
if(start==null) return; if(start==null) return;
if((e.stateMask&SWT.MODIFIER_MASK&~SWT.SHIFT)!=0) return; //don't react on modifier if((e.stateMask&SWT.MODIFIER_MASK&~SWT.SHIFT)!=0) return; //don't react on modifier except shift
if (e.button == 1 && ((e.stateMask&SWT.SHIFT)==0)) { if(!start.equals(end)){
asyncUpdate(e.widget);
} else if (e.button == 1 && ((e.stateMask&SWT.SHIFT)==0)) {
// set cursor (button 1 and no shift)
if(Math.abs(e.x-start.x)<3 && Math.abs(e.y-start.y)<3){ if(Math.abs(e.x-start.x)<3 && Math.abs(e.y-start.y)<3){
// first set cursor time // first set cursor time
setCursorTime(snapOffsetToEvent(e)); setCursorTime(snapOffsetToEvent(e));
@ -169,6 +204,7 @@ public class WaveformViewer implements IWaveformViewer {
asyncUpdate(e.widget); asyncUpdate(e.widget);
} }
}else if (e.button == 2 ||(e.button==1 && (e.stateMask&SWT.SHIFT)!=0)) { }else if (e.button == 2 ||(e.button==1 && (e.stateMask&SWT.SHIFT)!=0)) {
// set marker (button 1 and shift)
setMarkerTime(snapOffsetToEvent(e), selectedMarker); setMarkerTime(snapOffsetToEvent(e), selectedMarker);
asyncUpdate(e.widget); asyncUpdate(e.widget);
} }
@ -209,7 +245,9 @@ public class WaveformViewer implements IWaveformViewer {
} }
return time; return time;
} }
}; };
protected WaveformMouseListener waveformMouseListener = new WaveformMouseListener();
public WaveformViewer(Composite parent) { public WaveformViewer(Composite parent) {
pcs=new PropertyChangeSupport(this); pcs=new PropertyChangeSupport(this);
@ -309,6 +347,8 @@ public class WaveformViewer implements IWaveformViewer {
waveformCanvas.setMaxTime(1); waveformCanvas.setMaxTime(1);
waveformCanvas.addMouseListener(waveformMouseListener); waveformCanvas.addMouseListener(waveformMouseListener);
waveformCanvas.addMouseMoveListener(waveformMouseListener);
waveformCanvas.addPaintListener(waveformMouseListener);
nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() { nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {

View File

@ -65,16 +65,12 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.MouseWheelListener;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
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.Event;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxEvent; import com.minres.scviewer.database.ITxEvent;
@ -281,38 +277,30 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
} }
} }
}); });
/*
waveformPane.getWaveformControl().addMouseTrackListener(new MouseTrackListener() { waveformPane.getWaveformControl().addMouseTrackListener(new MouseTrackListener() {
@Override @Override
public void mouseHover(MouseEvent e) { public void mouseHover(MouseEvent e) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void mouseExit(MouseEvent e) { public void mouseExit(MouseEvent e) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void mouseEnter(MouseEvent e) { public void mouseEnter(MouseEvent e) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
}); });
waveformPane.getWaveformControl().addMouseWheelListener(new MouseWheelListener() { waveformPane.getWaveformControl().addMouseWheelListener(new MouseWheelListener() {
@Override @Override
public void mouseScrolled(MouseEvent e) { public void mouseScrolled(MouseEvent e) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
}); });
*/
waveformPane.getWaveformControl().addListener(SWT.KeyDown, new Listener() { waveformPane.getWaveformControl().addListener(SWT.KeyDown, new Listener() {
@SuppressWarnings("null") @SuppressWarnings("null")
@Override @Override
public void handleEvent(Event e) { public void handleEvent(Event e) {
@ -616,8 +604,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
} }
public void saveState(String fileName){ public void saveState(String fileName){
Map<String, String> persistedState = new HashMap<>(); Map<String, String> persistedState = new HashMap<>();
persistedState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size())); //$NON-NLS-1$ persistedState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size())); //$NON-NLS-1$
Integer index = 0; Integer index = 0;
@ -634,8 +620,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
FileOutputStream out = new FileOutputStream(fileName); FileOutputStream out = new FileOutputStream(fileName);
props.store(out, "Written by SCViewer"); //$NON-NLS-1$ props.store(out, "Written by SCViewer"); //$NON-NLS-1$
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1043,7 +1027,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
* Sets the zoom fit. * Sets the zoom fit.
*/ */
public void setZoomFit() { public void setZoomFit() {
//actual max time of signal //actual max time of signal
long maxTime = waveformPane.getMaxTime(); long maxTime = waveformPane.getMaxTime();