add next increment - basically working
@ -84,6 +84,8 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||
|
||||
private TimeZoomScrollbar horizontal;
|
||||
|
||||
private int[] lastHorSelection;
|
||||
|
||||
private ScrollBar vertical;
|
||||
|
||||
HashMap<IWaveform, IWaveformPainter> wave2painterMap;
|
||||
@ -156,10 +158,10 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||
|
||||
public void setOrigin(int x, int y) {
|
||||
checkWidget();
|
||||
if(x<=0) horizontal.setSelection(-x);
|
||||
x = -horizontal.getSelection()[0];
|
||||
if(y<=0) vertical.setSelection(-y);
|
||||
y = -vertical.getSelection();
|
||||
// if(x<=0) horizontal.setSelection(-x);
|
||||
// x = -horizontal.getSelection()[0];
|
||||
// if(y<=0) vertical.setSelection(-y);
|
||||
// y = -vertical.getSelection();
|
||||
origin.x = x;
|
||||
origin.y = y;
|
||||
syncSb();
|
||||
@ -300,18 +302,24 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
if (!painterList.isEmpty()) {
|
||||
int[] sel = horizontal.getSelection();
|
||||
//long width = maxTime / getScale();
|
||||
int currentThumbWidth = getClientArea().width;
|
||||
int newThumbWidth = sel[1]-sel[0];
|
||||
if(currentThumbWidth!=newThumbWidth) {
|
||||
long newScaleFactor =getScale()*newThumbWidth/currentThumbWidth;
|
||||
updateScaleFactor(Math.max(1, newScaleFactor));
|
||||
long lowerTime = sel[0]*maxTime/horizontal.getMaximum();
|
||||
long upperTime = sel[1]*maxTime/horizontal.getMaximum();
|
||||
if(sel[1]-sel[0] != lastHorSelection[1]-lastHorSelection[0]) {
|
||||
long time_diff = upperTime-lowerTime;
|
||||
long factor = time_diff/getClientArea().width;
|
||||
setScalingFactor(factor, lowerTime+time_diff/2);
|
||||
} else {
|
||||
origin.x = -(int) (lowerTime / getScale());
|
||||
event.widget.getDisplay().asyncExec(() -> {redraw();});
|
||||
}
|
||||
origin.x=-sel[0];
|
||||
syncSb();
|
||||
lastHorSelection=sel;
|
||||
}
|
||||
}
|
||||
});
|
||||
horizontal.setMinimum(0);
|
||||
horizontal.setMaximum(10000);
|
||||
lastHorSelection = horizontal.getSelection();
|
||||
|
||||
vertical.setEnabled(false);
|
||||
vertical.setVisible(true);
|
||||
vertical.addSelectionListener(new SelectionAdapter() {
|
||||
@ -319,7 +327,8 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
if (!painterList.isEmpty()) {
|
||||
origin.y=-vertical.getSelection();
|
||||
syncSb();
|
||||
fireSelectionEvent();
|
||||
event.widget.getDisplay().asyncExec(() -> {redraw();});
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -363,16 +372,15 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||
private void syncHSb() {
|
||||
horizontal.setEnabled(wave2painterMap.size()>0);
|
||||
Rectangle clientArea=getClientArea();
|
||||
long width = maxTime / getScale();
|
||||
int clientWidth = clientArea.width;
|
||||
horizontal.setIncrement(clientWidth / 100);
|
||||
horizontal.setPageIncrement(clientWidth/2);
|
||||
horizontal.setMinimum(0);
|
||||
horizontal.setMaximum((int)width);
|
||||
if (width>0 && -origin.x > horizontal.getMaximum() - clientWidth) {
|
||||
origin.x = -horizontal.getMaximum() + clientWidth;
|
||||
if(maxTime>0) {
|
||||
int lower = (int) ( -origin.x * getScale() * horizontal.getMaximum() / maxTime);
|
||||
int upper = (int) ((clientWidth-origin.x) * getScale() * horizontal.getMaximum() / maxTime);
|
||||
int[] curSel = horizontal.getSelection();
|
||||
lastHorSelection = new int[] {Math.max(lower,0), Math.min(upper, horizontal.getMaximum())};
|
||||
horizontal.setSelection(lastHorSelection);
|
||||
}
|
||||
horizontal.setSelection(new int[] {Math.max(-origin.x,0), Math.min(clientWidth-origin.x, horizontal.getMaximum())});
|
||||
long width = maxTime / getScale();
|
||||
horizontal.setButtonsEnabled(width > clientWidth);
|
||||
}
|
||||
|
||||
|
@ -267,11 +267,24 @@ public class WaveformView implements IWaveformView {
|
||||
switch (e.type) {
|
||||
case SWT.MouseWheel:
|
||||
if((e.stateMask & SWT.CTRL) != 0) {
|
||||
if(e.count<0)
|
||||
if(e.count<0) // up scroll
|
||||
waveformCanvas.setScale(waveformCanvas.getScale()*11/10);
|
||||
else
|
||||
else // down scroll
|
||||
waveformCanvas.setScale(waveformCanvas.getScale()*10/11);
|
||||
}
|
||||
e.doit=false;
|
||||
} else if((e.stateMask & SWT.SHIFT) != 0) {
|
||||
long upper = waveformCanvas.getMaxVisibleTime();
|
||||
long lower = waveformCanvas.getMinVisibleTime();
|
||||
long duration = upper-lower;
|
||||
if(e.count<0) { // up scroll
|
||||
long newLower = Math.min(waveformCanvas.getMaxTime()-duration, lower+duration/10);
|
||||
waveformCanvas.setMinVisibleTime(newLower);
|
||||
} else {// down scroll
|
||||
long newLower = Math.max(0, lower-duration/10);
|
||||
waveformCanvas.setMinVisibleTime(newLower);
|
||||
}
|
||||
e.doit=false;
|
||||
}
|
||||
break;
|
||||
case SWT.MouseDown:
|
||||
start = new Point(e.x, e.y);
|
||||
|
@ -2,6 +2,9 @@ package com.minres.scviewer.database.ui.swt.internal.slider;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.SWTException;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseTrackAdapter;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
@ -46,24 +49,36 @@ public class ImageButton extends Composite
|
||||
addListener(SWT.Paint, event -> {
|
||||
paintControl(event);
|
||||
});
|
||||
addListener(SWT.MouseDown, event -> {
|
||||
if(!isEnabled()) return;
|
||||
pressed=true;
|
||||
notifyListeners();
|
||||
if(autoFire) actionTimer.activate();
|
||||
redraw();
|
||||
addMouseTrackListener(new MouseTrackAdapter() {
|
||||
public void mouseEnter(MouseEvent arg0) {
|
||||
if(isEnabled()) {
|
||||
hover=true;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
public void mouseExit(MouseEvent arg0) {
|
||||
if(isEnabled()) {
|
||||
hover=false;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
});
|
||||
addListener(SWT.MouseUp, event -> {
|
||||
pressed=false;
|
||||
redraw();
|
||||
});
|
||||
addListener(SWT.MouseMove, event -> {
|
||||
if(!isEnabled()) return;
|
||||
Point sz = ((ImageButton)event.widget).getSize();
|
||||
final boolean within_x = event.x>0 && event.x<sz.x-1;
|
||||
final boolean within_y = event.y>0 && event.y<sz.y-1;
|
||||
hover= within_x && within_y;
|
||||
redraw();
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseDown(MouseEvent e) {
|
||||
if(isEnabled()) {
|
||||
pressed=true;
|
||||
notifyListeners();
|
||||
if(autoFire) actionTimer.activate();
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUp(MouseEvent e) {
|
||||
pressed=false;
|
||||
redraw();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -64,18 +64,18 @@ public class TimeZoomScrollbar extends Composite {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int[] value = timeSlider.getSelection();
|
||||
int diff = value[1]-value[0];
|
||||
int newLow = Math.max(0, value[0]-Math.max(1, diff/10));
|
||||
timeSlider.setSelection(newLow, newLow+diff, true);
|
||||
int incr=timeSlider.getIncrement();
|
||||
int lower = Math.max(timeSlider.getMinimum(), value[0]-incr);
|
||||
timeSlider.setValues(lower, lower + (value[1]-value[0]), true);
|
||||
}
|
||||
});
|
||||
rightButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int[] value = timeSlider.getSelection();
|
||||
int diff = value[1]-value[0];
|
||||
int newHigh = Math.min(timeSlider.getMaximum(), value[1] + diff/10);
|
||||
timeSlider.setSelection(newHigh-diff, newHigh, true);
|
||||
int incr=timeSlider.getIncrement();
|
||||
int upper = Math.min(timeSlider.getMaximum(), value[1]+incr);
|
||||
timeSlider.setValues(upper - (value[1]-value[0]), upper, true);
|
||||
}
|
||||
});
|
||||
|
||||
@ -104,7 +104,7 @@ public class TimeZoomScrollbar extends Composite {
|
||||
}
|
||||
public void setSelection(int[] sel) {
|
||||
assert(sel.length==2);
|
||||
timeSlider.setSelection(sel[0], sel[1]);
|
||||
timeSlider.setValues(sel[0], sel[1]);
|
||||
}
|
||||
public int[] getSelection() {
|
||||
return timeSlider.getSelection();
|
||||
@ -112,12 +112,6 @@ public class TimeZoomScrollbar extends Composite {
|
||||
public void addSelectionListener(SelectionListener selectionListener) {
|
||||
timeSlider.addSelectionListener(selectionListener);
|
||||
}
|
||||
public void setIncrement(int value) {
|
||||
timeSlider.setIncrement(value);
|
||||
}
|
||||
public void setPageIncrement(int value) {
|
||||
timeSlider.setPageIncrement(value);
|
||||
}
|
||||
public void setMinimum(int value) {
|
||||
timeSlider.setMinimum(value);
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 374 B After Width: | Height: | Size: 350 B |
Before Width: | Height: | Size: 353 B |
Before Width: | Height: | Size: 343 B |
After Width: | Height: | Size: 336 B |
Before Width: | Height: | Size: 385 B |
After Width: | Height: | Size: 352 B |
Before Width: | Height: | Size: 358 B After Width: | Height: | Size: 329 B |
Before Width: | Height: | Size: 386 B |
Before Width: | Height: | Size: 366 B |
After Width: | Height: | Size: 326 B |
Before Width: | Height: | Size: 345 B |
After Width: | Height: | Size: 349 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 430 B |
@ -787,18 +787,15 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
protected void restoreWaveformViewerState(Map<String, String> state) {
|
||||
Integer waves = state.containsKey(SHOWN_WAVEFORM+"S") ? Integer.parseInt(state.get(SHOWN_WAVEFORM + "S")):0; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
List<TrackEntry> trackEntries = new LinkedList<>();
|
||||
List<TrackEntry> selectedTrackEntries = new LinkedList<>();
|
||||
for (int i = 0; i < waves; i++) {
|
||||
IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i));
|
||||
if (waveform != null) {
|
||||
TrackEntry trackEntry = waveformPane.addWaveform(waveform, -1);
|
||||
//check if t is selected
|
||||
boolean isSelected = Boolean.parseBoolean(state.get(SHOWN_WAVEFORM + i + WAVEFORM_SELECTED));
|
||||
if(isSelected) {
|
||||
trackEntry.selected = true;
|
||||
} else {
|
||||
trackEntry.selected = false;
|
||||
}
|
||||
trackEntries.add(trackEntry);
|
||||
if(Boolean.parseBoolean(state.get(SHOWN_WAVEFORM + i + WAVEFORM_SELECTED)))
|
||||
selectedTrackEntries.add(trackEntry);
|
||||
String v = state.get(SHOWN_WAVEFORM + i + VALUE_DISPLAY);
|
||||
if(v!=null)
|
||||
trackEntry.valueDisplay=ValueDisplay.valueOf(v);
|
||||
@ -856,6 +853,8 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
ISelection sel = new StructuredSelection(selectedTrackEntries);
|
||||
waveformPane.setSelection(sel);
|
||||
updateAll();
|
||||
}
|
||||
|
||||
|