add next increment - basically working

This commit is contained in:
Eyck Jentzsch 2022-01-06 17:48:40 +01:00
parent 71da420d86
commit bd0629301b
26 changed files with 330 additions and 1124 deletions

View File

@ -84,6 +84,8 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
private TimeZoomScrollbar horizontal; private TimeZoomScrollbar horizontal;
private int[] lastHorSelection;
private ScrollBar vertical; private ScrollBar vertical;
HashMap<IWaveform, IWaveformPainter> wave2painterMap; HashMap<IWaveform, IWaveformPainter> wave2painterMap;
@ -156,10 +158,10 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
public void setOrigin(int x, int y) { public void setOrigin(int x, int y) {
checkWidget(); checkWidget();
if(x<=0) horizontal.setSelection(-x); // if(x<=0) horizontal.setSelection(-x);
x = -horizontal.getSelection()[0]; // x = -horizontal.getSelection()[0];
if(y<=0) vertical.setSelection(-y); // if(y<=0) vertical.setSelection(-y);
y = -vertical.getSelection(); // y = -vertical.getSelection();
origin.x = x; origin.x = x;
origin.y = y; origin.y = y;
syncSb(); syncSb();
@ -300,18 +302,24 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
if (!painterList.isEmpty()) { if (!painterList.isEmpty()) {
int[] sel = horizontal.getSelection(); int[] sel = horizontal.getSelection();
//long width = maxTime / getScale(); long lowerTime = sel[0]*maxTime/horizontal.getMaximum();
int currentThumbWidth = getClientArea().width; long upperTime = sel[1]*maxTime/horizontal.getMaximum();
int newThumbWidth = sel[1]-sel[0]; if(sel[1]-sel[0] != lastHorSelection[1]-lastHorSelection[0]) {
if(currentThumbWidth!=newThumbWidth) { long time_diff = upperTime-lowerTime;
long newScaleFactor =getScale()*newThumbWidth/currentThumbWidth; long factor = time_diff/getClientArea().width;
updateScaleFactor(Math.max(1, newScaleFactor)); setScalingFactor(factor, lowerTime+time_diff/2);
} else {
origin.x = -(int) (lowerTime / getScale());
event.widget.getDisplay().asyncExec(() -> {redraw();});
} }
origin.x=-sel[0]; lastHorSelection=sel;
syncSb();
} }
} }
}); });
horizontal.setMinimum(0);
horizontal.setMaximum(10000);
lastHorSelection = horizontal.getSelection();
vertical.setEnabled(false); vertical.setEnabled(false);
vertical.setVisible(true); vertical.setVisible(true);
vertical.addSelectionListener(new SelectionAdapter() { vertical.addSelectionListener(new SelectionAdapter() {
@ -319,7 +327,8 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
if (!painterList.isEmpty()) { if (!painterList.isEmpty()) {
origin.y=-vertical.getSelection(); 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() { private void syncHSb() {
horizontal.setEnabled(wave2painterMap.size()>0); horizontal.setEnabled(wave2painterMap.size()>0);
Rectangle clientArea=getClientArea(); Rectangle clientArea=getClientArea();
long width = maxTime / getScale();
int clientWidth = clientArea.width; int clientWidth = clientArea.width;
horizontal.setIncrement(clientWidth / 100); if(maxTime>0) {
horizontal.setPageIncrement(clientWidth/2); int lower = (int) ( -origin.x * getScale() * horizontal.getMaximum() / maxTime);
horizontal.setMinimum(0); int upper = (int) ((clientWidth-origin.x) * getScale() * horizontal.getMaximum() / maxTime);
horizontal.setMaximum((int)width); int[] curSel = horizontal.getSelection();
if (width>0 && -origin.x > horizontal.getMaximum() - clientWidth) { lastHorSelection = new int[] {Math.max(lower,0), Math.min(upper, horizontal.getMaximum())};
origin.x = -horizontal.getMaximum() + clientWidth; 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); horizontal.setButtonsEnabled(width > clientWidth);
} }

View File

@ -267,11 +267,24 @@ public class WaveformView implements IWaveformView {
switch (e.type) { switch (e.type) {
case SWT.MouseWheel: case SWT.MouseWheel:
if((e.stateMask & SWT.CTRL) != 0) { if((e.stateMask & SWT.CTRL) != 0) {
if(e.count<0) if(e.count<0) // up scroll
waveformCanvas.setScale(waveformCanvas.getScale()*11/10); waveformCanvas.setScale(waveformCanvas.getScale()*11/10);
else else // down scroll
waveformCanvas.setScale(waveformCanvas.getScale()*10/11); 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; break;
case SWT.MouseDown: case SWT.MouseDown:
start = new Point(e.x, e.y); start = new Point(e.x, e.y);

View File

@ -2,6 +2,9 @@ package com.minres.scviewer.database.ui.swt.internal.slider;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException; 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.events.SelectionListener;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@ -46,24 +49,36 @@ public class ImageButton extends Composite
addListener(SWT.Paint, event -> { addListener(SWT.Paint, event -> {
paintControl(event); paintControl(event);
}); });
addListener(SWT.MouseDown, event -> { addMouseTrackListener(new MouseTrackAdapter() {
if(!isEnabled()) return; public void mouseEnter(MouseEvent arg0) {
pressed=true; if(isEnabled()) {
notifyListeners(); hover=true;
if(autoFire) actionTimer.activate(); redraw();
redraw(); }
}
public void mouseExit(MouseEvent arg0) {
if(isEnabled()) {
hover=false;
redraw();
}
}
}); });
addListener(SWT.MouseUp, event -> { addMouseListener(new MouseAdapter() {
pressed=false; @Override
redraw(); public void mouseDown(MouseEvent e) {
}); if(isEnabled()) {
addListener(SWT.MouseMove, event -> { pressed=true;
if(!isEnabled()) return; notifyListeners();
Point sz = ((ImageButton)event.widget).getSize(); if(autoFire) actionTimer.activate();
final boolean within_x = event.x>0 && event.x<sz.x-1; redraw();
final boolean within_y = event.y>0 && event.y<sz.y-1; }
hover= within_x && within_y; }
redraw();
@Override
public void mouseUp(MouseEvent e) {
pressed=false;
redraw();
}
}); });
} }

View File

@ -64,18 +64,18 @@ public class TimeZoomScrollbar extends Composite {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int[] value = timeSlider.getSelection(); int[] value = timeSlider.getSelection();
int diff = value[1]-value[0]; int incr=timeSlider.getIncrement();
int newLow = Math.max(0, value[0]-Math.max(1, diff/10)); int lower = Math.max(timeSlider.getMinimum(), value[0]-incr);
timeSlider.setSelection(newLow, newLow+diff, true); timeSlider.setValues(lower, lower + (value[1]-value[0]), true);
} }
}); });
rightButton.addSelectionListener(new SelectionAdapter() { rightButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
int[] value = timeSlider.getSelection(); int[] value = timeSlider.getSelection();
int diff = value[1]-value[0]; int incr=timeSlider.getIncrement();
int newHigh = Math.min(timeSlider.getMaximum(), value[1] + diff/10); int upper = Math.min(timeSlider.getMaximum(), value[1]+incr);
timeSlider.setSelection(newHigh-diff, newHigh, true); timeSlider.setValues(upper - (value[1]-value[0]), upper, true);
} }
}); });
@ -104,7 +104,7 @@ public class TimeZoomScrollbar extends Composite {
} }
public void setSelection(int[] sel) { public void setSelection(int[] sel) {
assert(sel.length==2); assert(sel.length==2);
timeSlider.setSelection(sel[0], sel[1]); timeSlider.setValues(sel[0], sel[1]);
} }
public int[] getSelection() { public int[] getSelection() {
return timeSlider.getSelection(); return timeSlider.getSelection();
@ -112,12 +112,6 @@ public class TimeZoomScrollbar extends Composite {
public void addSelectionListener(SelectionListener selectionListener) { public void addSelectionListener(SelectionListener selectionListener) {
timeSlider.addSelectionListener(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) { public void setMinimum(int value) {
timeSlider.setMinimum(value); timeSlider.setMinimum(value);
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 374 B

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

After

Width:  |  Height:  |  Size: 329 B

View File

@ -787,18 +787,15 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
protected void restoreWaveformViewerState(Map<String, String> state) { 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$ 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> trackEntries = new LinkedList<>();
List<TrackEntry> selectedTrackEntries = new LinkedList<>();
for (int i = 0; i < waves; i++) { for (int i = 0; i < waves; i++) {
IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i)); IWaveform waveform = database.getStreamByName(state.get(SHOWN_WAVEFORM + i));
if (waveform != null) { if (waveform != null) {
TrackEntry trackEntry = waveformPane.addWaveform(waveform, -1); TrackEntry trackEntry = waveformPane.addWaveform(waveform, -1);
//check if t is selected //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); 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); String v = state.get(SHOWN_WAVEFORM + i + VALUE_DISPLAY);
if(v!=null) if(v!=null)
trackEntry.valueDisplay=ValueDisplay.valueOf(v); trackEntry.valueDisplay=ValueDisplay.valueOf(v);
@ -856,6 +853,8 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
} }
ISelection sel = new StructuredSelection(selectedTrackEntries);
waveformPane.setSelection(sel);
updateAll(); updateAll();
} }