checkpoint development
This commit is contained in:
parent
f9be6758e2
commit
71da420d86
|
@ -13,6 +13,7 @@ package com.minres.scviewer.database.ui.swt;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Plugin;
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.wb.swt.SWTResourceManager;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
public class DatabaseUiPlugin extends Plugin {
|
public class DatabaseUiPlugin extends Plugin {
|
||||||
|
@ -24,6 +25,7 @@ public class DatabaseUiPlugin extends Plugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop(BundleContext context) throws Exception {
|
public void stop(BundleContext context) throws Exception {
|
||||||
|
SWTResourceManager.dispose();
|
||||||
getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Stopping org.eclipse.e4.core bundle..."));
|
getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Stopping org.eclipse.e4.core bundle..."));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,37 +0,0 @@
|
||||||
package com.minres.scviewer.database.ui.swt.internal;
|
|
||||||
|
|
||||||
import org.eclipse.swt.events.SelectionAdapter;
|
|
||||||
import org.eclipse.swt.events.SelectionListener;
|
|
||||||
import org.eclipse.swt.graphics.Point;
|
|
||||||
|
|
||||||
public interface IScrollBar {
|
|
||||||
|
|
||||||
void setSelection(int i);
|
|
||||||
|
|
||||||
int getSelection();
|
|
||||||
|
|
||||||
void setEnabled(boolean b);
|
|
||||||
|
|
||||||
void setVisible(boolean b);
|
|
||||||
|
|
||||||
void addSelectionListener(SelectionListener selectionListener);
|
|
||||||
|
|
||||||
void setIncrement(int i);
|
|
||||||
|
|
||||||
void setPageIncrement(int width);
|
|
||||||
|
|
||||||
void setMinimum(int i);
|
|
||||||
|
|
||||||
void setMaximum(int width);
|
|
||||||
|
|
||||||
int getMaximum();
|
|
||||||
|
|
||||||
void setThumb(int clientWidthw);
|
|
||||||
|
|
||||||
Point getSize();
|
|
||||||
|
|
||||||
int getStyle();
|
|
||||||
|
|
||||||
boolean isVisible();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package com.minres.scviewer.database.ui.swt.internal;
|
|
||||||
|
|
||||||
public interface IWaveformScrollBarProvider {
|
|
||||||
|
|
||||||
IScrollBar getHorizontalSb();
|
|
||||||
IScrollBar getVerticalSb();
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
package com.minres.scviewer.database.ui.swt.internal;
|
|
||||||
|
|
||||||
import org.eclipse.swt.events.SelectionListener;
|
|
||||||
import org.eclipse.swt.graphics.Point;
|
|
||||||
import org.eclipse.swt.widgets.ScrollBar;
|
|
||||||
|
|
||||||
public class ScrollBarAdapter implements IScrollBar {
|
|
||||||
|
|
||||||
ScrollBar delegate;
|
|
||||||
public ScrollBarAdapter(ScrollBar delegate) {
|
|
||||||
this.delegate=delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSelection(int i) {
|
|
||||||
delegate.setSelection(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSelection() {
|
|
||||||
return delegate.getSelection();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEnabled(boolean b) {
|
|
||||||
delegate.setEnabled(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setVisible(boolean b) {
|
|
||||||
delegate.setVisible(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addSelectionListener(SelectionListener selectionListener) {
|
|
||||||
delegate.addSelectionListener(selectionListener); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIncrement(int i) {
|
|
||||||
delegate.setIncrement(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPageIncrement(int width) {
|
|
||||||
delegate.setPageIncrement(width);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMinimum(int i) {
|
|
||||||
delegate.setMinimum(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMaximum(int width) {
|
|
||||||
delegate.setMaximum(width);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMaximum() {
|
|
||||||
return delegate.getMaximum();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setThumb(int clientWidthw) {
|
|
||||||
delegate.setThumb(clientWidthw);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Point getSize() {
|
|
||||||
return delegate.getSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getStyle() {
|
|
||||||
return delegate.getStyle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible() {
|
|
||||||
return delegate.isVisible();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -35,14 +35,15 @@ public class TrackAreaPainter implements IPainter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintArea(Projection proj, Rectangle a) {
|
public void paintArea(Projection proj, Rectangle a) {
|
||||||
Rectangle area = proj.unProject(new Rectangle(a.x, a.y+waveCanvas.rulerHeight, a.width, a.height-waveCanvas.rulerHeight));
|
Rectangle area = proj.unProject(new Rectangle(a.x, a.y+waveCanvas.rulerHeight, a.width, a.height-waveCanvas.rulerHeight));
|
||||||
proj.setBackground(this.waveCanvas.styleProvider.getColor(WaveformColors.TRACK_BG_EVEN));
|
proj.setBackground(this.waveCanvas.styleProvider.getColor(WaveformColors.TRACK_BG_EVEN));
|
||||||
proj.setFillRule(SWT.FILL_EVEN_ODD);
|
proj.setFillRule(SWT.FILL_EVEN_ODD);
|
||||||
proj.fillRectangle(area);
|
proj.fillRectangle(area);
|
||||||
if(trackVerticalOffset.size()>0){
|
if(trackVerticalOffset.size()>0){
|
||||||
Integer firstKey=trackVerticalOffset.floorKey(area.y);
|
Integer firstKey=trackVerticalOffset.floorKey(area.y);
|
||||||
if(firstKey==null) firstKey=trackVerticalOffset.firstKey();
|
if(firstKey==null) firstKey=trackVerticalOffset.firstKey();
|
||||||
Integer lastKey = trackVerticalOffset.floorKey(area.y+area.height);
|
Integer lastKey = trackVerticalOffset.floorKey(area.y+area.height);
|
||||||
|
//if(lastKey==null) lastKey= trackVerticalOffset.lastKey();
|
||||||
Rectangle subArea = new Rectangle(area.x, 0, area.width, 0);
|
Rectangle subArea = new Rectangle(area.x, 0, area.width, 0);
|
||||||
if(lastKey.equals(firstKey)){
|
if(lastKey.equals(firstKey)){
|
||||||
subArea.y=firstKey;
|
subArea.y=firstKey;
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.swt.graphics.Rectangle;
|
||||||
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.Event;
|
import org.eclipse.swt.widgets.Event;
|
||||||
|
import org.eclipse.swt.widgets.ScrollBar;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.minres.scviewer.database.EventEntry;
|
import com.minres.scviewer.database.EventEntry;
|
||||||
|
@ -45,6 +46,7 @@ import com.minres.scviewer.database.ui.IWaveformZoom;
|
||||||
import com.minres.scviewer.database.ui.TrackEntry;
|
import com.minres.scviewer.database.ui.TrackEntry;
|
||||||
import com.minres.scviewer.database.ui.ZoomKind;
|
import com.minres.scviewer.database.ui.ZoomKind;
|
||||||
import com.minres.scviewer.database.ui.swt.Constants;
|
import com.minres.scviewer.database.ui.swt.Constants;
|
||||||
|
import com.minres.scviewer.database.ui.swt.internal.slider.TimeZoomScrollbar;
|
||||||
|
|
||||||
public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
|
|
||||||
|
@ -80,8 +82,9 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
|
|
||||||
private List<CursorPainter> cursorPainters;
|
private List<CursorPainter> cursorPainters;
|
||||||
|
|
||||||
IScrollBar horizontal;
|
private TimeZoomScrollbar horizontal;
|
||||||
IScrollBar vertical;
|
|
||||||
|
private ScrollBar vertical;
|
||||||
|
|
||||||
HashMap<IWaveform, IWaveformPainter> wave2painterMap;
|
HashMap<IWaveform, IWaveformPainter> wave2painterMap;
|
||||||
/**
|
/**
|
||||||
|
@ -92,13 +95,13 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
* @param style
|
* @param style
|
||||||
* the style of this control.
|
* the style of this control.
|
||||||
*/
|
*/
|
||||||
public WaveformCanvas(final Composite parent, int style, IWaveformStyleProvider styleProvider, IWaveformScrollBarProvider scrollbarProvider) {
|
public WaveformCanvas(final Composite parent, int style, IWaveformStyleProvider styleProvider, TimeZoomScrollbar.IProvider scrollbarProvider) {
|
||||||
super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND);
|
super(parent, (style & ~SWT.H_SCROLL) | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.V_SCROLL );
|
||||||
this.styleProvider=styleProvider;
|
this.styleProvider=styleProvider;
|
||||||
addControlListener(new ControlAdapter() { /* resize listener. */
|
addControlListener(new ControlAdapter() { /* resize listener. */
|
||||||
@Override
|
@Override
|
||||||
public void controlResized(ControlEvent event) {
|
public void controlResized(ControlEvent event) {
|
||||||
syncScrollBars();
|
syncSb();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addPaintListener((final PaintEvent event) -> paint(event.gc));
|
addPaintListener((final PaintEvent event) -> paint(event.gc));
|
||||||
|
@ -108,8 +111,8 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
cursorPainters= new ArrayList<>();
|
cursorPainters= new ArrayList<>();
|
||||||
wave2painterMap=new HashMap<>();
|
wave2painterMap=new HashMap<>();
|
||||||
|
|
||||||
horizontal = (style& SWT.H_SCROLL)==0?scrollbarProvider.getHorizontalSb() : new ScrollBarAdapter(getHorizontalBar());
|
horizontal = scrollbarProvider.getScrollBar();
|
||||||
vertical = (style& SWT.V_SCROLL)==0?scrollbarProvider.getVerticalSb() : new ScrollBarAdapter(getVerticalBar());
|
vertical = getVerticalBar();
|
||||||
initScrollBars();
|
initScrollBars();
|
||||||
// order is important: it is bottom to top
|
// order is important: it is bottom to top
|
||||||
trackAreaPainter=new TrackAreaPainter(this);
|
trackAreaPainter=new TrackAreaPainter(this);
|
||||||
|
@ -118,10 +121,10 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
painterList.add(arrowPainter);
|
painterList.add(arrowPainter);
|
||||||
rulerPainter=new RulerPainter(this);
|
rulerPainter=new RulerPainter(this);
|
||||||
painterList.add(rulerPainter);
|
painterList.add(rulerPainter);
|
||||||
CursorPainter cp = new CursorPainter(this, scaleFactor * 10, cursorPainters.size()-1);
|
CursorPainter cp = new CursorPainter(this, getScale() * 10, cursorPainters.size()-1);
|
||||||
painterList.add(cp);
|
painterList.add(cp);
|
||||||
cursorPainters.add(cp);
|
cursorPainters.add(cp);
|
||||||
CursorPainter marker = new CursorPainter(this, scaleFactor * 100, cursorPainters.size()-1);
|
CursorPainter marker = new CursorPainter(this, getScale() * 100, cursorPainters.size()-1);
|
||||||
painterList.add(marker);
|
painterList.add(marker);
|
||||||
cursorPainters.add(marker);
|
cursorPainters.add(marker);
|
||||||
wave2painterMap=new HashMap<>();
|
wave2painterMap=new HashMap<>();
|
||||||
|
@ -154,12 +157,12 @@ 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();
|
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;
|
||||||
syncScrollBars();
|
syncSb();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -169,7 +172,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
|
|
||||||
public void setMaxTime(long maxTime) {
|
public void setMaxTime(long maxTime) {
|
||||||
this.maxTime = maxTime;
|
this.maxTime = maxTime;
|
||||||
syncScrollBars();
|
syncSb();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -208,37 +211,41 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
factor=1;
|
factor=1;
|
||||||
else if(factor>maxFactor)
|
else if(factor>maxFactor)
|
||||||
factor=maxFactor;
|
factor=maxFactor;
|
||||||
if(factor!=scaleFactor || (getMaxVisibleTime()+getMinVisibleTime()/2) != centerTime) {
|
if(factor!=getScale() || (getMaxVisibleTime()+getMinVisibleTime()/2) != centerTime) {
|
||||||
scaleFactor = factor;
|
updateScaleFactor(factor);
|
||||||
scaleMagnitude = 0;
|
|
||||||
for(int i=Constants.POWERS_OF_TEN.length-1; i>0; i--) {
|
|
||||||
if(scaleFactor>=Constants.POWERS_OF_TEN[i]) {
|
|
||||||
scaleMagnitude = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ITx tx = arrowPainter.getTx();
|
ITx tx = arrowPainter.getTx();
|
||||||
arrowPainter.setTx(null);
|
arrowPainter.setTx(null);
|
||||||
/*
|
/*
|
||||||
* xc = tc/oldScaleFactor
|
* xc = tc/oldScaleFactor
|
||||||
* xoffs = xc+origin.x
|
* xoffs = xc+origin.x
|
||||||
* xcn = tc/newScaleFactor
|
* xcn = tc/newScaleFactor
|
||||||
* t0n = (xcn-xoffs)*scaleFactor
|
* t0n = (xcn-xoffs)*getScale()
|
||||||
*/
|
*/
|
||||||
long xoffs = clientAreaWidth/2;
|
long xoffs = clientAreaWidth/2;
|
||||||
long xcn=centerTime/scaleFactor; // new total x-offset
|
long xcn=centerTime/getScale(); // new total x-offset
|
||||||
long originX=xcn-xoffs;
|
long originX=xcn-xoffs;
|
||||||
if(originX>0) {
|
if(originX>0) {
|
||||||
origin.x=(int) -originX; // new cursor time offset relative to left border
|
origin.x=(int) -originX; // new cursor time offset relative to left border
|
||||||
}else {
|
}else {
|
||||||
origin.x=0;
|
origin.x=0;
|
||||||
}
|
}
|
||||||
syncScrollBars();
|
syncSb();
|
||||||
arrowPainter.setTx(tx);
|
arrowPainter.setTx(tx);
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateScaleFactor(long factor) {
|
||||||
|
scaleFactor = factor;
|
||||||
|
scaleMagnitude = 0;
|
||||||
|
for(int i=Constants.POWERS_OF_TEN.length-1; i>0; i--) {
|
||||||
|
if(scaleFactor>=Constants.POWERS_OF_TEN[i]) {
|
||||||
|
scaleMagnitude = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String timeToString(long time) {
|
public String timeToString(long time) {
|
||||||
int idx = scaleMagnitude/3;
|
int idx = scaleMagnitude/3;
|
||||||
|
@ -247,7 +254,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimeForOffset(int xOffset){
|
public long getTimeForOffset(int xOffset){
|
||||||
return (xOffset-origin.x) * scaleFactor;
|
return (xOffset-origin.x) * getScale();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPainter(IPainter painter) {
|
public void addPainter(IPainter painter) {
|
||||||
|
@ -267,7 +274,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
void clearAllWaveformPainter(boolean update) {
|
void clearAllWaveformPainter(boolean update) {
|
||||||
trackAreaPainter.trackVerticalOffset.clear();
|
trackAreaPainter.trackVerticalOffset.clear();
|
||||||
wave2painterMap.clear();
|
wave2painterMap.clear();
|
||||||
if(update) syncScrollBars();
|
if(update) syncSb();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWaveformPainter(IWaveformPainter painter) {
|
public void addWaveformPainter(IWaveformPainter painter) {
|
||||||
|
@ -277,7 +284,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
void addWaveformPainter(IWaveformPainter painter, boolean update) {
|
void addWaveformPainter(IWaveformPainter painter, boolean update) {
|
||||||
trackAreaPainter.addTrackPainter(painter);
|
trackAreaPainter.addTrackPainter(painter);
|
||||||
wave2painterMap.put(painter.getTrackEntry().waveform, painter);
|
wave2painterMap.put(painter.getTrackEntry().waveform, painter);
|
||||||
if(update) syncScrollBars();
|
if(update) syncSb();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CursorPainter> getCursorPainters() {
|
public List<CursorPainter> getCursorPainters() {
|
||||||
|
@ -291,9 +298,18 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
horizontal.addSelectionListener(new SelectionAdapter() {
|
horizontal.addSelectionListener(new SelectionAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void widgetSelected(SelectionEvent event) {
|
public void widgetSelected(SelectionEvent event) {
|
||||||
if (painterList.isEmpty())
|
if (!painterList.isEmpty()) {
|
||||||
return;
|
int[] sel = horizontal.getSelection();
|
||||||
setOrigin(-horizontal.getSelection(), origin.y);
|
//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));
|
||||||
|
}
|
||||||
|
origin.x=-sel[0];
|
||||||
|
syncSb();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
vertical.setEnabled(false);
|
vertical.setEnabled(false);
|
||||||
|
@ -301,9 +317,10 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
vertical.addSelectionListener(new SelectionAdapter() {
|
vertical.addSelectionListener(new SelectionAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void widgetSelected(SelectionEvent event) {
|
public void widgetSelected(SelectionEvent event) {
|
||||||
if (painterList.isEmpty())
|
if (!painterList.isEmpty()) {
|
||||||
return;
|
origin.y=-vertical.getSelection();
|
||||||
setOrigin(origin.x, -vertical.getSelection());
|
syncSb();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -313,48 +330,50 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
* range, it will correct it. This function considers only following factors
|
* range, it will correct it. This function considers only following factors
|
||||||
* :<b> transform, image size, client area</b>.
|
* :<b> transform, image size, client area</b>.
|
||||||
*/
|
*/
|
||||||
public void syncScrollBars() {
|
public void syncSb() {
|
||||||
if (painterList.isEmpty()) {
|
if (!painterList.isEmpty()) {
|
||||||
redraw();
|
syncHSb();
|
||||||
return;
|
syncVSb();
|
||||||
|
fireSelectionEvent();
|
||||||
}
|
}
|
||||||
int height = trackAreaPainter.getHeight(); // incl. Ruler
|
this.getDisplay().asyncExec(() -> {redraw();});
|
||||||
long width = maxTime / scaleFactor;
|
}
|
||||||
Rectangle clientArea=getClientArea();
|
|
||||||
int clientWidthw = clientArea.width;
|
|
||||||
horizontal.setIncrement(clientWidthw / 100);
|
|
||||||
horizontal.setPageIncrement(clientWidthw/2);
|
|
||||||
if (width > clientWidthw) { /* image is wider than client area */
|
|
||||||
horizontal.setMinimum(0);
|
|
||||||
horizontal.setMaximum((int)width);
|
|
||||||
horizontal.setEnabled(true);
|
|
||||||
if (-origin.x > horizontal.getMaximum() - clientWidthw) {
|
|
||||||
origin.x = -horizontal.getMaximum() + clientWidthw;
|
|
||||||
}
|
|
||||||
} else { /* image is narrower than client area */
|
|
||||||
horizontal.setEnabled(false);
|
|
||||||
}
|
|
||||||
horizontal.setThumb(clientWidthw);
|
|
||||||
horizontal.setSelection(-origin.x);
|
|
||||||
|
|
||||||
int clientHeighth = clientArea.height;
|
private void syncVSb() {
|
||||||
vertical.setIncrement(clientHeighth / 100);
|
Rectangle clientArea=getClientArea();
|
||||||
vertical.setPageIncrement(clientHeighth/2);
|
int height = trackAreaPainter.getHeight(); // incl. Ruler
|
||||||
if (height > clientHeighth) { /* image is higher than client area */
|
int clientHeight = clientArea.height;
|
||||||
|
vertical.setIncrement(clientHeight / 100);
|
||||||
|
vertical.setPageIncrement(clientHeight/2);
|
||||||
|
if (height > clientHeight) { /* image is higher than client area */
|
||||||
vertical.setMinimum(0);
|
vertical.setMinimum(0);
|
||||||
vertical.setMaximum(height);
|
vertical.setMaximum(height);
|
||||||
vertical.setEnabled(true);
|
vertical.setEnabled(true);
|
||||||
if ( -origin.y > vertical.getMaximum() - clientHeighth) {
|
if ( -origin.y > vertical.getMaximum() - clientHeight) {
|
||||||
origin.y = -vertical.getMaximum() + clientHeighth;
|
origin.y = -vertical.getMaximum() + clientHeight;
|
||||||
}
|
}
|
||||||
} else { /* image is less higher than client area */
|
} else { /* image is less higher than client area */
|
||||||
vertical.setMaximum(clientHeighth);
|
vertical.setMaximum(clientHeight);
|
||||||
vertical.setEnabled(false);
|
vertical.setEnabled(false);
|
||||||
}
|
}
|
||||||
vertical.setThumb(clientHeighth);
|
vertical.setThumb(clientHeight);
|
||||||
vertical.setSelection(-origin.y);
|
vertical.setSelection(-origin.y);
|
||||||
redraw();
|
}
|
||||||
fireSelectionEvent();
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
horizontal.setSelection(new int[] {Math.max(-origin.x,0), Math.min(clientWidth-origin.x, horizontal.getMaximum())});
|
||||||
|
horizontal.setButtonsEnabled(width > clientWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Paint function */
|
/* Paint function */
|
||||||
|
@ -404,7 +423,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
result.add(entry.getValue().getTrackEntry());
|
result.add(entry.getValue().getTrackEntry());
|
||||||
}
|
}
|
||||||
} else if (p instanceof CursorPainter) {
|
} else if (p instanceof CursorPainter) {
|
||||||
if (Math.abs(point.x - origin.x - ((CursorPainter) p).getTime()/scaleFactor) < 2) {
|
if (Math.abs(point.x - origin.x - ((CursorPainter) p).getTime()/getScale()) < 2) {
|
||||||
result.add(p);
|
result.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -432,8 +451,8 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reveal(ITx tx) {
|
public void reveal(ITx tx) {
|
||||||
int lower = (int) (tx.getBeginTime() / scaleFactor);
|
int lower = (int) (tx.getBeginTime() / getScale());
|
||||||
int higher = (int) (tx.getEndTime() / scaleFactor);
|
int higher = (int) (tx.getEndTime() / getScale());
|
||||||
Point size = getSize();
|
Point size = getSize();
|
||||||
size.x -= vertical.getSize().x + 2;
|
size.x -= vertical.getSize().x + 2;
|
||||||
size.y -= horizontal.getSize().y;
|
size.y -= horizontal.getSize().y;
|
||||||
|
@ -479,7 +498,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reveal(long time) {
|
public void reveal(long time) {
|
||||||
int scaledTime = (int) (time / scaleFactor);
|
int scaledTime = (int) (time / getScale());
|
||||||
Point size = getSize();
|
Point size = getSize();
|
||||||
size.x -= vertical.getSize().x + 2;
|
size.x -= vertical.getSize().x + 2;
|
||||||
size.y -= horizontal.getSize().y;
|
size.y -= horizontal.getSize().y;
|
||||||
|
@ -492,7 +511,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void centerAt(long time) {
|
public void centerAt(long time) {
|
||||||
int scaledTime = (int) (time / scaleFactor);
|
int scaledTime = (int) (time / getScale());
|
||||||
int newX = -scaledTime+getWidth()/2;
|
int newX = -scaledTime+getWidth()/2;
|
||||||
setOrigin(newX>0?0:newX, origin.y);
|
setOrigin(newX>0?0:newX, origin.y);
|
||||||
}
|
}
|
||||||
|
@ -532,12 +551,12 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getMaxVisibleTime() {
|
public long getMaxVisibleTime() {
|
||||||
return (getClientArea().width-origin.x)*scaleFactor;
|
return (getClientArea().width-origin.x)*getScale();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getMinVisibleTime() {
|
public long getMinVisibleTime() {
|
||||||
return -origin.x * scaleFactor;
|
return -origin.x * getScale();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -545,7 +564,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
|
||||||
long duration = getMaxVisibleTime()-getMinVisibleTime();
|
long duration = getMaxVisibleTime()-getMinVisibleTime();
|
||||||
if(time>0) {
|
if(time>0) {
|
||||||
if((time+duration)<getMaxTime()) {
|
if((time+duration)<getMaxTime()) {
|
||||||
int scaledTime = (int) (time / scaleFactor);
|
int scaledTime = (int) (time / getScale());
|
||||||
setOrigin(-scaledTime, origin.y);
|
setOrigin(-scaledTime, origin.y);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
package com.minres.scviewer.database.ui.swt.internal;
|
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
|
||||||
import org.eclipse.swt.events.MouseAdapter;
|
|
||||||
import org.eclipse.swt.events.SelectionAdapter;
|
|
||||||
import org.eclipse.swt.events.SelectionEvent;
|
|
||||||
import org.eclipse.swt.graphics.Color;
|
|
||||||
import org.eclipse.swt.graphics.GC;
|
|
||||||
import org.eclipse.swt.layout.GridData;
|
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
|
||||||
import org.eclipse.swt.widgets.Button;
|
|
||||||
import org.eclipse.swt.widgets.Composite;
|
|
||||||
import org.eclipse.swt.widgets.Slider;
|
|
||||||
import org.eclipse.wb.swt.SWTResourceManager;
|
|
||||||
|
|
||||||
public class WaveformSlider extends Composite {
|
|
||||||
|
|
||||||
Slider slider;
|
|
||||||
|
|
||||||
Color buttonColor;
|
|
||||||
|
|
||||||
public WaveformSlider(Composite parent, int style) {
|
|
||||||
super(parent, style);
|
|
||||||
GridLayout gridLayout = new GridLayout(3, false);
|
|
||||||
gridLayout.horizontalSpacing = 0;
|
|
||||||
gridLayout.verticalSpacing = 0;
|
|
||||||
gridLayout.marginWidth = 0;
|
|
||||||
gridLayout.marginHeight = 0;
|
|
||||||
setLayout(gridLayout);
|
|
||||||
|
|
||||||
buttonColor = getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
|
|
||||||
|
|
||||||
Button scrlLeft = new Button(this, /*SWT.BORDER |*/ SWT.FLAT | SWT.CENTER);
|
|
||||||
scrlLeft.setFont(SWTResourceManager.getFont("Sans", 5, SWT.NORMAL));
|
|
||||||
GridData gd_scrlLeft = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
|
|
||||||
gd_scrlLeft.heightHint = 16;
|
|
||||||
gd_scrlLeft.widthHint = 16;
|
|
||||||
scrlLeft.setLayoutData(gd_scrlLeft);
|
|
||||||
scrlLeft.addPaintListener(paintEvent -> {
|
|
||||||
GC gc = paintEvent.gc;
|
|
||||||
gc.setBackground(buttonColor);
|
|
||||||
gc.setForeground(buttonColor);
|
|
||||||
int left = paintEvent.x+4;
|
|
||||||
int top = paintEvent.y+5;
|
|
||||||
int width=paintEvent.width-11;
|
|
||||||
int height= paintEvent.height-10;
|
|
||||||
int[] triangle = new int[] {
|
|
||||||
left, top+height/2,
|
|
||||||
left+width, top,
|
|
||||||
left+width, top+height};
|
|
||||||
gc.fillPolygon( triangle );
|
|
||||||
gc.drawPolygon( triangle );
|
|
||||||
});
|
|
||||||
scrlLeft.addSelectionListener(new SelectionAdapter() {
|
|
||||||
public void widgetSelected (SelectionEvent e){
|
|
||||||
slider.setSelection(slider.getSelection()-10);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
scrlLeft.redraw();
|
|
||||||
|
|
||||||
slider = new Slider(this, SWT.NONE);
|
|
||||||
slider.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
|
|
||||||
GridData gd_canvas = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
|
|
||||||
gd_canvas.heightHint = 16;
|
|
||||||
slider.setLayoutData(gd_canvas);
|
|
||||||
|
|
||||||
Button scrlRight = new Button(this, /*SWT.BORDER |*/ SWT.FLAT | SWT.CENTER);
|
|
||||||
scrlRight.setAlignment(SWT.CENTER);
|
|
||||||
GridData gd_scrlRight = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
|
||||||
gd_scrlRight.heightHint = 16;
|
|
||||||
gd_scrlRight.widthHint = 16;
|
|
||||||
scrlRight.setLayoutData(gd_scrlRight);
|
|
||||||
scrlRight.addPaintListener(paintEvent -> {
|
|
||||||
GC gc = paintEvent.gc;
|
|
||||||
gc.setBackground(buttonColor);
|
|
||||||
gc.setForeground(buttonColor);
|
|
||||||
int left = paintEvent.x+6;
|
|
||||||
int top = paintEvent.y+5;
|
|
||||||
int width=paintEvent.width-11;
|
|
||||||
int height= paintEvent.height-10;
|
|
||||||
int[] triangle = new int[] {
|
|
||||||
left, top,
|
|
||||||
left+width, top+height/2,
|
|
||||||
left, top+height};
|
|
||||||
gc.fillPolygon( triangle );
|
|
||||||
gc.drawPolygon( triangle );
|
|
||||||
});
|
|
||||||
scrlRight.addSelectionListener(new SelectionAdapter() {
|
|
||||||
public void widgetSelected (SelectionEvent e){
|
|
||||||
slider.setSelection(slider.getSelection()+10);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -54,9 +54,7 @@ import org.eclipse.swt.events.PaintEvent;
|
||||||
import org.eclipse.swt.events.PaintListener;
|
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.Color;
|
|
||||||
import org.eclipse.swt.graphics.GC;
|
import org.eclipse.swt.graphics.GC;
|
||||||
import org.eclipse.swt.graphics.Image;
|
|
||||||
import org.eclipse.swt.graphics.Point;
|
import org.eclipse.swt.graphics.Point;
|
||||||
import org.eclipse.swt.graphics.Rectangle;
|
import org.eclipse.swt.graphics.Rectangle;
|
||||||
import org.eclipse.swt.graphics.TextLayout;
|
import org.eclipse.swt.graphics.TextLayout;
|
||||||
|
@ -93,10 +91,7 @@ import com.minres.scviewer.database.ui.IWaveformStyleProvider;
|
||||||
import com.minres.scviewer.database.ui.IWaveformView;
|
import com.minres.scviewer.database.ui.IWaveformView;
|
||||||
import com.minres.scviewer.database.ui.IWaveformZoom;
|
import com.minres.scviewer.database.ui.IWaveformZoom;
|
||||||
import com.minres.scviewer.database.ui.TrackEntry;
|
import com.minres.scviewer.database.ui.TrackEntry;
|
||||||
import com.minres.scviewer.database.ui.swt.internal.slider.ImageButton;
|
import com.minres.scviewer.database.ui.swt.internal.slider.TimeZoomScrollbar;
|
||||||
import com.minres.scviewer.database.ui.swt.internal.slider.RangeSlider;
|
|
||||||
import com.minres.scviewer.database.ui.swt.internal.slider.ZoomingScrollbar;
|
|
||||||
import com.minres.scviewer.database.ui.swt.sb.FlatScrollBar;
|
|
||||||
|
|
||||||
public class WaveformView implements IWaveformView {
|
public class WaveformView implements IWaveformView {
|
||||||
|
|
||||||
|
@ -344,21 +339,16 @@ public class WaveformView implements IWaveformView {
|
||||||
gl_waveformPane.marginHeight = 0;
|
gl_waveformPane.marginHeight = 0;
|
||||||
waveformPane.setLayout(gl_waveformPane);
|
waveformPane.setLayout(gl_waveformPane);
|
||||||
|
|
||||||
IWaveformScrollBarProvider sbProvider = new IWaveformScrollBarProvider() {
|
waveformCanvas = new WaveformCanvas(waveformPane, SWT.NONE | SWT.V_SCROLL /*| SWT.H_SCROLL*/, styleProvider, new TimeZoomScrollbar.IProvider() {
|
||||||
@Override
|
|
||||||
public IScrollBar getVerticalSb() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IScrollBar getHorizontalSb() {
|
public TimeZoomScrollbar getScrollBar() {
|
||||||
ZoomingScrollbar timeSliderPane = new ZoomingScrollbar(waveformPane, SWT.NONE);
|
TimeZoomScrollbar timeSliderPane = new TimeZoomScrollbar(waveformPane, SWT.NONE);
|
||||||
GridData gd_timeSliderPane = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1);
|
GridData gd_timeSliderPane = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1);
|
||||||
timeSliderPane.setLayoutData(gd_timeSliderPane);
|
timeSliderPane.setLayoutData(gd_timeSliderPane);
|
||||||
return timeSliderPane;
|
return timeSliderPane;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
waveformCanvas = new WaveformCanvas(waveformPane, SWT.NONE | SWT.V_SCROLL /*| SWT.H_SCROLL*/, styleProvider, sbProvider);
|
|
||||||
waveformCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
waveformCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
||||||
|
|
||||||
// create the name pane
|
// create the name pane
|
||||||
|
@ -551,7 +541,7 @@ public class WaveformView implements IWaveformView {
|
||||||
tracksVerticalHeight += streamEntry.height;
|
tracksVerticalHeight += streamEntry.height;
|
||||||
even = !even;
|
even = !even;
|
||||||
}
|
}
|
||||||
waveformCanvas.syncScrollBars();
|
waveformCanvas.syncSb();
|
||||||
nameList.setSize(nameMaxWidth + 15, tracksVerticalHeight);
|
nameList.setSize(nameMaxWidth + 15, tracksVerticalHeight);
|
||||||
nameListScrolled.setMinSize(nameMaxWidth + 15, tracksVerticalHeight);
|
nameListScrolled.setMinSize(nameMaxWidth + 15, tracksVerticalHeight);
|
||||||
nameList.redraw();
|
nameList.redraw();
|
||||||
|
|
|
@ -15,6 +15,7 @@ public class ImageButton extends Composite
|
||||||
private Image hoverImage;
|
private Image hoverImage;
|
||||||
private Image normalImage;
|
private Image normalImage;
|
||||||
private Image pressedImage;
|
private Image pressedImage;
|
||||||
|
private Image disabledImage;
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
private boolean hover;
|
private boolean hover;
|
||||||
|
@ -25,7 +26,6 @@ public class ImageButton extends Composite
|
||||||
|
|
||||||
public ImageButton(Composite parent, int style) {
|
public ImageButton(Composite parent, int style) {
|
||||||
super(parent, style);
|
super(parent, style);
|
||||||
|
|
||||||
timerAction = new ActionTimer.TimerAction() {
|
timerAction = new ActionTimer.TimerAction() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -37,30 +37,28 @@ public class ImageButton extends Composite
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
actionTimer = new ActionTimer(timerAction, this.getDisplay() );
|
actionTimer = new ActionTimer(timerAction, this.getDisplay() );
|
||||||
|
|
||||||
addListener(SWT.Dispose, event -> {
|
addListener(SWT.Dispose, event -> {
|
||||||
if (hoverImage != null) hoverImage.dispose();
|
if (hoverImage != null) hoverImage.dispose();
|
||||||
if (normalImage != null) normalImage.dispose();
|
if (normalImage != null) normalImage.dispose();
|
||||||
if (pressedImage != null) pressedImage.dispose();
|
if (pressedImage != null) pressedImage.dispose();
|
||||||
|
if (disabledImage != null) disabledImage.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
addListener(SWT.Paint, event -> {
|
addListener(SWT.Paint, event -> {
|
||||||
paintControl(event);
|
paintControl(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
addListener(SWT.MouseDown, event -> {
|
addListener(SWT.MouseDown, event -> {
|
||||||
|
if(!isEnabled()) return;
|
||||||
pressed=true;
|
pressed=true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
if(autoFire) actionTimer.activate();
|
if(autoFire) actionTimer.activate();
|
||||||
redraw();
|
redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
addListener(SWT.MouseUp, event -> {
|
addListener(SWT.MouseUp, event -> {
|
||||||
pressed=false;
|
pressed=false;
|
||||||
redraw();
|
redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
addListener(SWT.MouseMove, event -> {
|
addListener(SWT.MouseMove, event -> {
|
||||||
|
if(!isEnabled()) return;
|
||||||
Point sz = ((ImageButton)event.widget).getSize();
|
Point sz = ((ImageButton)event.widget).getSize();
|
||||||
final boolean within_x = event.x>0 && event.x<sz.x-1;
|
final boolean within_x = event.x>0 && event.x<sz.x-1;
|
||||||
final boolean within_y = event.y>0 && event.y<sz.y-1;
|
final boolean within_y = event.y>0 && event.y<sz.y-1;
|
||||||
|
@ -71,47 +69,38 @@ public class ImageButton extends Composite
|
||||||
|
|
||||||
private void paintControl(Event event) {
|
private void paintControl(Event event) {
|
||||||
GC gc = event.gc;
|
GC gc = event.gc;
|
||||||
|
|
||||||
if (hoverImage != null) {
|
if (hoverImage != null) {
|
||||||
if(pressed)
|
if(pressed)
|
||||||
gc.drawImage(pressedImage, 1, 1);
|
gc.drawImage(pressedImage, 1, 1);
|
||||||
else if(hover) {
|
else if(hover) {
|
||||||
gc.drawImage(hoverImage, 1, 1);
|
gc.drawImage(hoverImage, 1, 1);
|
||||||
} else {
|
} else if(isEnabled()){
|
||||||
gc.drawImage(normalImage, 1, 1);
|
gc.drawImage(normalImage, 1, 1);
|
||||||
}
|
} else
|
||||||
|
gc.drawImage(disabledImage, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImage(Image[] imgs)
|
public void setImage(Image[] imgs) {
|
||||||
{
|
assert(imgs.length==3);
|
||||||
Display d = Display.getDefault();
|
Display d = Display.getDefault();
|
||||||
hoverImage = new Image(d, imgs[0], SWT.IMAGE_COPY);
|
normalImage = new Image(d, imgs[0], SWT.IMAGE_COPY);
|
||||||
normalImage = imgs.length>1?
|
hoverImage = new Image(d, imgs[1], SWT.IMAGE_COPY);
|
||||||
new Image(d, imgs[1], SWT.IMAGE_COPY):
|
pressedImage = new Image(d, imgs[2], SWT.IMAGE_COPY);
|
||||||
new Image(d,imgs[0],SWT.IMAGE_GRAY);
|
disabledImage = new Image(d, imgs[0], SWT.IMAGE_DISABLE);
|
||||||
pressedImage = imgs.length>2?
|
|
||||||
new Image(d, imgs[2], SWT.IMAGE_COPY):
|
|
||||||
new Image(d,imgs[0],SWT.IMAGE_DISABLE);
|
|
||||||
width = imgs[0].getBounds().width;
|
width = imgs[0].getBounds().width;
|
||||||
height = imgs[0].getBounds().height;
|
height = imgs[0].getBounds().height;
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Point computeSize(int wHint, int hHint, boolean changed)
|
public Point computeSize(int wHint, int hHint, boolean changed) {
|
||||||
{
|
|
||||||
int overallWidth = width;
|
int overallWidth = width;
|
||||||
int overallHeight = height;
|
int overallHeight = height;
|
||||||
|
|
||||||
/* Consider hints */
|
|
||||||
if (wHint != SWT.DEFAULT && wHint < overallWidth)
|
if (wHint != SWT.DEFAULT && wHint < overallWidth)
|
||||||
overallWidth = wHint;
|
overallWidth = wHint;
|
||||||
|
|
||||||
if (hHint != SWT.DEFAULT && hHint < overallHeight)
|
if (hHint != SWT.DEFAULT && hHint < overallHeight)
|
||||||
overallHeight = hHint;
|
overallHeight = hHint;
|
||||||
|
|
||||||
/* Return computed dimensions plus border */
|
|
||||||
return new Point(overallWidth + 2, overallHeight + 2);
|
return new Point(overallWidth + 2, overallHeight + 2);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -185,6 +174,4 @@ public class ImageButton extends Composite
|
||||||
public void setAutoFire(boolean autoFire) {
|
public void setAutoFire(boolean autoFire) {
|
||||||
this.autoFire = autoFire;
|
this.autoFire = autoFire;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class RangeSlider extends Canvas {
|
||||||
private static int minWidth = 18;
|
private static int minWidth = 18;
|
||||||
private static int minHeight = 18;
|
private static int minHeight = 18;
|
||||||
private static int imgWidth = 8;
|
private static int imgWidth = 8;
|
||||||
|
private static int minThumbWidth = 5;
|
||||||
private int minimum;
|
private int minimum;
|
||||||
private int maximum;
|
private int maximum;
|
||||||
private int lowerValue;
|
private int lowerValue;
|
||||||
|
@ -143,17 +144,6 @@ public class RangeSlider extends Canvas {
|
||||||
isOn = (style & SWT.ON) == SWT.ON;
|
isOn = (style & SWT.ON) == SWT.ON;
|
||||||
selectedElement = isFullSelection ? BOTH : LOWER;
|
selectedElement = isFullSelection ? BOTH : LOWER;
|
||||||
|
|
||||||
// addListener(SWT.Dispose, event -> {
|
|
||||||
// SWTResourceManager.dsafeDispose(slider);
|
|
||||||
// SWTGraphicUtil.safeDispose(sliderHover);
|
|
||||||
// SWTGraphicUtil.safeDispose(sliderDrag);
|
|
||||||
// SWTGraphicUtil.safeDispose(sliderSelected);
|
|
||||||
//
|
|
||||||
// SWTGraphicUtil.safeDispose(vSlider);
|
|
||||||
// SWTGraphicUtil.safeDispose(vSliderHover);
|
|
||||||
// SWTGraphicUtil.safeDispose(vSliderDrag);
|
|
||||||
// SWTGraphicUtil.safeDispose(vSliderSelected);
|
|
||||||
// });
|
|
||||||
addMouseListeners();
|
addMouseListeners();
|
||||||
addListener(SWT.Resize, event -> {
|
addListener(SWT.Resize, event -> {
|
||||||
});
|
});
|
||||||
|
@ -300,14 +290,14 @@ public class RangeSlider extends Canvas {
|
||||||
} else if ((selectedElement & UPPER) != 0) {
|
} else if ((selectedElement & UPPER) != 0) {
|
||||||
upperValue = (int) Math.round((x - 9d) / computePixelSizeForHorizontalSlider()) + minimum;
|
upperValue = (int) Math.round((x - 9d) / computePixelSizeForHorizontalSlider()) + minimum;
|
||||||
if (!isSmooth) {
|
if (!isSmooth) {
|
||||||
upperValue = (int) (Math.ceil(upperValue / increment) * increment) - increment;
|
upperValue = Math.min(lowerValue, (int) (Math.ceil(upperValue / increment) * increment) - increment);
|
||||||
}
|
}
|
||||||
checkUpperValue();
|
checkUpperValue();
|
||||||
handleToolTip(upperValue);
|
handleToolTip(upperValue);
|
||||||
} else {
|
} else {
|
||||||
lowerValue = (int) Math.round((x - 9d) / computePixelSizeForHorizontalSlider()) + minimum;
|
lowerValue = (int) Math.round((x - 9d) / computePixelSizeForHorizontalSlider()) + minimum;
|
||||||
if (!isSmooth) {
|
if (!isSmooth) {
|
||||||
lowerValue = (int) (Math.ceil(lowerValue / increment) * increment) - increment;
|
lowerValue = Math.max(upperValue, (int) (Math.ceil(lowerValue / increment) * increment) - increment);
|
||||||
}
|
}
|
||||||
checkLowerValue();
|
checkLowerValue();
|
||||||
handleToolTip(lowerValue);
|
handleToolTip(lowerValue);
|
||||||
|
@ -380,11 +370,12 @@ public class RangeSlider extends Canvas {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Image img = orientation == SWT.HORIZONTAL ? slider[0] : vSlider;
|
final Image img = orientation == SWT.HORIZONTAL ? slider[0] : vSlider;
|
||||||
|
final Rectangle imgBounds = img.getBounds();
|
||||||
final int x = e.x, y = e.y;
|
final int x = e.x, y = e.y;
|
||||||
lowerHover = x >= coordLower.x && x <= coordLower.x + img.getBounds().width && y >= coordLower.y && y <= coordLower.y + img.getBounds().height;
|
lowerHover = x >= coordLower.x && x <= coordLower.x + imgBounds.width && y >= coordLower.y && y <= coordLower.y + imgBounds.height;
|
||||||
upperHover = ((e.stateMask & (SWT.CTRL | SWT.SHIFT)) != 0 || !lowerHover) && //
|
upperHover = ((e.stateMask & (SWT.CTRL | SWT.SHIFT)) != 0 || !lowerHover) && //
|
||||||
x >= coordUpper.x && x <= coordUpper.x + img.getBounds().width && //
|
x >= coordUpper.x && x <= coordUpper.x + imgBounds.width && //
|
||||||
y >= coordUpper.y && y <= coordUpper.y + img.getBounds().height;
|
y >= coordUpper.y && y <= coordUpper.y + imgBounds.height;
|
||||||
lowerHover &= (e.stateMask & SWT.CTRL) != 0 || !upperHover;
|
lowerHover &= (e.stateMask & SWT.CTRL) != 0 || !upperHover;
|
||||||
if (!lowerHover && !upperHover && isFullSelection && isBetweenKnobs(x, y)) {
|
if (!lowerHover && !upperHover && isFullSelection && isBetweenKnobs(x, y)) {
|
||||||
lowerHover = upperHover = true;
|
lowerHover = upperHover = true;
|
||||||
|
@ -403,7 +394,7 @@ public class RangeSlider extends Canvas {
|
||||||
int value = -1;
|
int value = -1;
|
||||||
final Rectangle clientArea = getClientArea();
|
final Rectangle clientArea = getClientArea();
|
||||||
if (orientation == SWT.HORIZONTAL) {
|
if (orientation == SWT.HORIZONTAL) {
|
||||||
if (x < 9 + clientArea.width - 20 && x >= 9 && y >= 9 && y <= 9 + clientArea.height - 20) {
|
if (x < clientArea.width - 2*imgWidth && x >= imgWidth && y >= minHeight/3 && y <= clientArea.height - minHeight/3) {
|
||||||
value = (int) Math.round((x - 9d) / computePixelSizeForHorizontalSlider()) + minimum;
|
value = (int) Math.round((x - 9d) / computePixelSizeForHorizontalSlider()) + minimum;
|
||||||
}
|
}
|
||||||
} else if (y < 9 + clientArea.height - 20 && y >= 9 && x >= 9 && x <= 9 + clientArea.width - 20) {
|
} else if (y < 9 + clientArea.height - 20 && y >= 9 && x >= 9 && x <= 9 + clientArea.width - 20) {
|
||||||
|
@ -579,11 +570,11 @@ public class RangeSlider extends Canvas {
|
||||||
if (lowerValue < minimum) {
|
if (lowerValue < minimum) {
|
||||||
lowerValue = minimum;
|
lowerValue = minimum;
|
||||||
}
|
}
|
||||||
if (lowerValue > maximum) {
|
if (lowerValue > (maximum-minThumbWidth)) {
|
||||||
lowerValue = maximum;
|
lowerValue = (maximum-minThumbWidth);
|
||||||
}
|
}
|
||||||
if (lowerValue > upperValue) {
|
if (lowerValue > (upperValue-minThumbWidth)) {
|
||||||
lowerValue = upperValue;
|
lowerValue = (upperValue-minThumbWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,14 +582,14 @@ public class RangeSlider extends Canvas {
|
||||||
* Check if the upper value is in ranges
|
* Check if the upper value is in ranges
|
||||||
*/
|
*/
|
||||||
private void checkUpperValue() {
|
private void checkUpperValue() {
|
||||||
if (upperValue < minimum) {
|
if (upperValue < (minimum+minThumbWidth)) {
|
||||||
upperValue = minimum;
|
upperValue = minimum+minThumbWidth;
|
||||||
}
|
}
|
||||||
if (upperValue > maximum) {
|
if (upperValue > maximum) {
|
||||||
upperValue = maximum;
|
upperValue = maximum;
|
||||||
}
|
}
|
||||||
if (upperValue < lowerValue) {
|
if (upperValue < (lowerValue+minThumbWidth)) {
|
||||||
upperValue = lowerValue;
|
upperValue = lowerValue+minThumbWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1422,10 +1413,19 @@ public class RangeSlider extends Canvas {
|
||||||
* @see #getMaximum()
|
* @see #getMaximum()
|
||||||
*/
|
*/
|
||||||
public void setSelection(final int lowerValue, final int upperValue) {
|
public void setSelection(final int lowerValue, final int upperValue) {
|
||||||
|
setSelection(lowerValue, upperValue, false);
|
||||||
|
}
|
||||||
|
public void setSelection(final int lowerValue, final int upperValue, boolean update) {
|
||||||
checkWidget();
|
checkWidget();
|
||||||
if (lowerValue <= upperValue && lowerValue >= minimum && upperValue <= maximum && (this.lowerValue != lowerValue || this.upperValue != upperValue)) {
|
if (lowerValue <= upperValue && lowerValue >= minimum && upperValue <= maximum && (this.lowerValue != lowerValue || this.upperValue != upperValue)) {
|
||||||
this.lowerValue = lowerValue;
|
this.lowerValue = lowerValue;
|
||||||
this.upperValue = upperValue;
|
this.upperValue = upperValue;
|
||||||
|
if(update) {
|
||||||
|
Event e = new Event();
|
||||||
|
e.type=SWT.Selection;
|
||||||
|
e.doit=true;
|
||||||
|
validateNewValues(e);
|
||||||
|
}
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.minres.scviewer.database.ui.swt.internal.slider;
|
package com.minres.scviewer.database.ui.swt.internal.slider;
|
||||||
|
|
||||||
|
import java.text.Format;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.events.SelectionAdapter;
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
import org.eclipse.swt.events.SelectionEvent;
|
import org.eclipse.swt.events.SelectionEvent;
|
||||||
|
@ -10,16 +12,21 @@ import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.wb.swt.SWTResourceManager;
|
import org.eclipse.wb.swt.SWTResourceManager;
|
||||||
|
|
||||||
import com.minres.scviewer.database.ui.swt.internal.IScrollBar;
|
public class TimeZoomScrollbar extends Composite {
|
||||||
|
|
||||||
public class ZoomingScrollbar extends Composite implements IScrollBar {
|
static public interface IProvider {
|
||||||
RangeSlider timeSlider;
|
TimeZoomScrollbar getScrollBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
final RangeSlider timeSlider;
|
||||||
|
final ImageButton leftButton;
|
||||||
|
final ImageButton rightButton;
|
||||||
/**
|
/**
|
||||||
* Create the composite.
|
* Create the composite.
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param style
|
* @param style
|
||||||
*/
|
*/
|
||||||
public ZoomingScrollbar(Composite parent, int style) {
|
public TimeZoomScrollbar(Composite parent, int style) {
|
||||||
super(parent, SWT.NO_FOCUS);
|
super(parent, SWT.NO_FOCUS);
|
||||||
GridLayout gridLayout = new GridLayout(3, false);
|
GridLayout gridLayout = new GridLayout(3, false);
|
||||||
gridLayout.horizontalSpacing = 0;
|
gridLayout.horizontalSpacing = 0;
|
||||||
|
@ -27,84 +34,100 @@ public class ZoomingScrollbar extends Composite implements IScrollBar {
|
||||||
gridLayout.marginWidth = 0;
|
gridLayout.marginWidth = 0;
|
||||||
gridLayout.marginHeight = 0;
|
gridLayout.marginHeight = 0;
|
||||||
setLayout(gridLayout);
|
setLayout(gridLayout);
|
||||||
//setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
|
|
||||||
|
|
||||||
ImageButton b1 = new ImageButton(this, SWT.NONE);
|
leftButton = new ImageButton(this, SWT.NONE);
|
||||||
GridData gd_b1 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
GridData gd_leftButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
||||||
gd_b1.widthHint=14;
|
gd_leftButton.widthHint=14;
|
||||||
gd_b1.heightHint=18;
|
gd_leftButton.heightHint=18;
|
||||||
b1.setLayoutData(gd_b1);
|
leftButton.setLayoutData(gd_leftButton);
|
||||||
b1.setImage(new Image[] {
|
leftButton.setImage(new Image[] {
|
||||||
SWTResourceManager.getImage(this.getClass(), "arrow_left_hover.png"),
|
|
||||||
SWTResourceManager.getImage(this.getClass(), "arrow_left.png"),
|
SWTResourceManager.getImage(this.getClass(), "arrow_left.png"),
|
||||||
|
SWTResourceManager.getImage(this.getClass(), "arrow_left_hover.png"),
|
||||||
SWTResourceManager.getImage(this.getClass(), "arrow_left_pressed.png")});
|
SWTResourceManager.getImage(this.getClass(), "arrow_left_pressed.png")});
|
||||||
b1.addSelectionListener(new SelectionAdapter() {
|
leftButton.setAutoFire(true);
|
||||||
|
|
||||||
|
timeSlider = new RangeSlider(this, SWT.ON|SWT.HIGH|SWT.SMOOTH|SWT.CONTROL);
|
||||||
|
timeSlider.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||||
|
|
||||||
|
rightButton = new ImageButton(this, SWT.NONE);
|
||||||
|
GridData gd_rightButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
||||||
|
gd_rightButton.widthHint=18;
|
||||||
|
gd_rightButton.heightHint=18;
|
||||||
|
rightButton.setLayoutData(gd_rightButton);
|
||||||
|
rightButton.setImage(new Image[] {
|
||||||
|
SWTResourceManager.getImage(this.getClass(), "arrow_right.png"),
|
||||||
|
SWTResourceManager.getImage(this.getClass(), "arrow_right_hover.png"),
|
||||||
|
SWTResourceManager.getImage(this.getClass(), "arrow_right_pressed.png")});
|
||||||
|
rightButton.setAutoFire(true);
|
||||||
|
|
||||||
|
leftButton.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 diff = value[1]-value[0];
|
||||||
int newLow = Math.max(0, value[0]-Math.max(1, diff/10));
|
int newLow = Math.max(0, value[0]-Math.max(1, diff/10));
|
||||||
timeSlider.setSelection(newLow, newLow+diff);
|
timeSlider.setSelection(newLow, newLow+diff, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
timeSlider = new RangeSlider(this, /*SWT.ON|*/SWT.HIGH|SWT.SMOOTH|SWT.CONTROL);
|
rightButton.addSelectionListener(new SelectionAdapter() {
|
||||||
GridData gd_timeSlide = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
|
|
||||||
timeSlider.setLayoutData(gd_timeSlide);
|
|
||||||
|
|
||||||
ImageButton b2 = new ImageButton(this, SWT.NONE);
|
|
||||||
GridData gd_b2 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
|
||||||
gd_b2.widthHint=18;
|
|
||||||
gd_b2.heightHint=18;
|
|
||||||
b2.setLayoutData(gd_b2);
|
|
||||||
b2.setImage(new Image[] {
|
|
||||||
SWTResourceManager.getImage(this.getClass(), "arrow_right_hover.png"),
|
|
||||||
SWTResourceManager.getImage(this.getClass(), "arrow_right.png"),
|
|
||||||
SWTResourceManager.getImage(this.getClass(), "arrow_right_pressed.png")});
|
|
||||||
b2.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 diff = value[1]-value[0];
|
||||||
int newHigh = Math.min(timeSlider.getMaximum(), value[1] + diff/10);
|
int newHigh = Math.min(timeSlider.getMaximum(), value[1] + diff/10);
|
||||||
timeSlider.setSelection(newHigh-diff, newHigh);
|
timeSlider.setSelection(newHigh-diff, newHigh, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setSelection(int i) {
|
public void setEnabled (boolean enabled) {
|
||||||
timeSlider.setLowerValue(i);
|
timeSlider.setEnabled(enabled);
|
||||||
|
leftButton.setEnabled(enabled);
|
||||||
|
rightButton.setEnabled(enabled);
|
||||||
|
super.setEnabled(enabled);
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
@Override
|
public void setButtonsEnabled (boolean enabled) {
|
||||||
public int getSelection() {
|
leftButton.setEnabled(enabled);
|
||||||
return timeSlider.getLowerValue();
|
rightButton.setEnabled(enabled);
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
public void setToolTipFormatter(Format formatter){
|
||||||
|
timeSlider.setToolTipFormatter(formatter);
|
||||||
|
}
|
||||||
|
public void setToolTipText(String string) {
|
||||||
|
timeSlider.setToolTipText(string);
|
||||||
|
}
|
||||||
|
public void setSelection(int sel) {
|
||||||
|
timeSlider.setLowerValue(sel);
|
||||||
|
}
|
||||||
|
public void setSelection(int[] sel) {
|
||||||
|
assert(sel.length==2);
|
||||||
|
timeSlider.setSelection(sel[0], sel[1]);
|
||||||
|
}
|
||||||
|
public int[] getSelection() {
|
||||||
|
return timeSlider.getSelection();
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void addSelectionListener(SelectionListener selectionListener) {
|
public void addSelectionListener(SelectionListener selectionListener) {
|
||||||
timeSlider.addSelectionListener(selectionListener);
|
timeSlider.addSelectionListener(selectionListener);
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void setIncrement(int value) {
|
public void setIncrement(int value) {
|
||||||
timeSlider.setIncrement(value);
|
timeSlider.setIncrement(value);
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void setPageIncrement(int value) {
|
public void setPageIncrement(int value) {
|
||||||
timeSlider.setPageIncrement(value);
|
timeSlider.setPageIncrement(value);
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void setMinimum(int value) {
|
public void setMinimum(int value) {
|
||||||
timeSlider.setMinimum(value);
|
timeSlider.setMinimum(value);
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void setMaximum(int value) {
|
public void setMaximum(int value) {
|
||||||
timeSlider.setMaximum(value);
|
timeSlider.setMaximum(value);
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public int getMaximum() {
|
public int getMaximum() {
|
||||||
return timeSlider.getMaximum();
|
return timeSlider.getMaximum();
|
||||||
}
|
}
|
||||||
@Override
|
public int getMinimum() {
|
||||||
public void setThumb(int w) {
|
return timeSlider.getMinimum();
|
||||||
timeSlider.setUpperValue(timeSlider.getLowerValue()+w);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue