checkpoint development

This commit is contained in:
Eyck Jentzsch 2022-01-05 21:51:57 +01:00
parent f9be6758e2
commit 71da420d86
11 changed files with 219 additions and 419 deletions

View File

@ -13,6 +13,7 @@ package com.minres.scviewer.database.ui.swt;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.wb.swt.SWTResourceManager;
import org.osgi.framework.BundleContext;
public class DatabaseUiPlugin extends Plugin {
@ -24,6 +25,7 @@ public class DatabaseUiPlugin extends Plugin {
@Override
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..."));
}
}

View File

@ -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();
}

View File

@ -1,7 +0,0 @@
package com.minres.scviewer.database.ui.swt.internal;
public interface IWaveformScrollBarProvider {
IScrollBar getHorizontalSb();
IScrollBar getVerticalSb();
}

View File

@ -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();
}
}

View File

@ -19,7 +19,7 @@ import org.eclipse.swt.graphics.Rectangle;
import com.minres.scviewer.database.ui.WaveformColors;
public class TrackAreaPainter implements IPainter {
/**
*
*/
@ -35,14 +35,15 @@ public class TrackAreaPainter implements IPainter {
}
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));
proj.setBackground(this.waveCanvas.styleProvider.getColor(WaveformColors.TRACK_BG_EVEN));
proj.setFillRule(SWT.FILL_EVEN_ODD);
proj.fillRectangle(area);
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.setFillRule(SWT.FILL_EVEN_ODD);
proj.fillRectangle(area);
if(trackVerticalOffset.size()>0){
Integer firstKey=trackVerticalOffset.floorKey(area.y);
if(firstKey==null) firstKey=trackVerticalOffset.firstKey();
Integer lastKey = trackVerticalOffset.floorKey(area.y+area.height);
//if(lastKey==null) lastKey= trackVerticalOffset.lastKey();
Rectangle subArea = new Rectangle(area.x, 0, area.width, 0);
if(lastKey.equals(firstKey)){
subArea.y=firstKey;
@ -61,9 +62,9 @@ public class TrackAreaPainter implements IPainter {
public void addTrackPainter(IWaveformPainter trackPainter){
trackVerticalOffset.put(trackPainter.getVerticalOffset()+waveCanvas.rulerHeight, trackPainter);
}
public int getHeight(){
if(trackVerticalOffset.size()==0) return 1;
return trackVerticalOffset.lastKey() + trackVerticalOffset.lastEntry().getValue().getHeight();

View File

@ -31,6 +31,7 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ScrollBar;
import com.google.common.collect.Lists;
import com.minres.scviewer.database.EventEntry;
@ -45,21 +46,22 @@ import com.minres.scviewer.database.ui.IWaveformZoom;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.ZoomKind;
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 static final long ZOOM_FIT = -2;
public static final long ZOOM_FULL = -1;
private boolean doubleBuffering = true;
IWaveformStyleProvider styleProvider;
private int scaleMagnitude = 6;
private long scaleFactor = Constants.POWERS_OF_TEN[scaleMagnitude];
private long maxTime;
protected Point origin; /* original size */
@ -80,8 +82,9 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
private List<CursorPainter> cursorPainters;
IScrollBar horizontal;
IScrollBar vertical;
private TimeZoomScrollbar horizontal;
private ScrollBar vertical;
HashMap<IWaveform, IWaveformPainter> wave2painterMap;
/**
@ -92,13 +95,13 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
* @param style
* the style of this control.
*/
public WaveformCanvas(final Composite parent, int style, IWaveformStyleProvider styleProvider, IWaveformScrollBarProvider scrollbarProvider) {
super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND);
public WaveformCanvas(final Composite parent, int style, IWaveformStyleProvider styleProvider, TimeZoomScrollbar.IProvider scrollbarProvider) {
super(parent, (style & ~SWT.H_SCROLL) | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.V_SCROLL );
this.styleProvider=styleProvider;
addControlListener(new ControlAdapter() { /* resize listener. */
@Override
public void controlResized(ControlEvent event) {
syncScrollBars();
syncSb();
}
});
addPaintListener((final PaintEvent event) -> paint(event.gc));
@ -108,8 +111,8 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
cursorPainters= new ArrayList<>();
wave2painterMap=new HashMap<>();
horizontal = (style& SWT.H_SCROLL)==0?scrollbarProvider.getHorizontalSb() : new ScrollBarAdapter(getHorizontalBar());
vertical = (style& SWT.V_SCROLL)==0?scrollbarProvider.getVerticalSb() : new ScrollBarAdapter(getVerticalBar());
horizontal = scrollbarProvider.getScrollBar();
vertical = getVerticalBar();
initScrollBars();
// order is important: it is bottom to top
trackAreaPainter=new TrackAreaPainter(this);
@ -118,10 +121,10 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
painterList.add(arrowPainter);
rulerPainter=new RulerPainter(this);
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);
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);
cursorPainters.add(marker);
wave2painterMap=new HashMap<>();
@ -154,12 +157,12 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
public void setOrigin(int x, int y) {
checkWidget();
if(x<=0) horizontal.setSelection(-x);
x = -horizontal.getSelection();
x = -horizontal.getSelection()[0];
if(y<=0) vertical.setSelection(-y);
y = -vertical.getSelection();
origin.x = x;
origin.y = y;
syncScrollBars();
syncSb();
}
@Override
@ -169,14 +172,14 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
public void setMaxTime(long maxTime) {
this.maxTime = maxTime;
syncScrollBars();
syncSb();
}
@Override
public long getScale() {
return scaleFactor;
}
@Override
public void setScale(long factor) {
setScalingFactor(factor, (getMaxVisibleTime()+getMinVisibleTime())/2);
@ -208,37 +211,41 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
factor=1;
else if(factor>maxFactor)
factor=maxFactor;
if(factor!=scaleFactor || (getMaxVisibleTime()+getMinVisibleTime()/2) != centerTime) {
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;
}
}
if(factor!=getScale() || (getMaxVisibleTime()+getMinVisibleTime()/2) != centerTime) {
updateScaleFactor(factor);
ITx tx = arrowPainter.getTx();
arrowPainter.setTx(null);
/*
* xc = tc/oldScaleFactor
* xoffs = xc+origin.x
* xcn = tc/newScaleFactor
* t0n = (xcn-xoffs)*scaleFactor
* t0n = (xcn-xoffs)*getScale()
*/
long xoffs = clientAreaWidth/2;
long xcn=centerTime/scaleFactor; // new total x-offset
long xcn=centerTime/getScale(); // new total x-offset
long originX=xcn-xoffs;
if(originX>0) {
origin.x=(int) -originX; // new cursor time offset relative to left border
}else {
origin.x=0;
}
syncScrollBars();
syncSb();
arrowPainter.setTx(tx);
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
public String timeToString(long time) {
int idx = scaleMagnitude/3;
@ -247,7 +254,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
}
public long getTimeForOffset(int xOffset){
return (xOffset-origin.x) * scaleFactor;
return (xOffset-origin.x) * getScale();
}
public void addPainter(IPainter painter) {
@ -267,7 +274,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
void clearAllWaveformPainter(boolean update) {
trackAreaPainter.trackVerticalOffset.clear();
wave2painterMap.clear();
if(update) syncScrollBars();
if(update) syncSb();
}
public void addWaveformPainter(IWaveformPainter painter) {
@ -277,7 +284,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
void addWaveformPainter(IWaveformPainter painter, boolean update) {
trackAreaPainter.addTrackPainter(painter);
wave2painterMap.put(painter.getTrackEntry().waveform, painter);
if(update) syncScrollBars();
if(update) syncSb();
}
public List<CursorPainter> getCursorPainters() {
@ -291,9 +298,18 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
horizontal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (painterList.isEmpty())
return;
setOrigin(-horizontal.getSelection(), origin.y);
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));
}
origin.x=-sel[0];
syncSb();
}
}
});
vertical.setEnabled(false);
@ -301,9 +317,10 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
vertical.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (painterList.isEmpty())
return;
setOrigin(origin.x, -vertical.getSelection());
if (!painterList.isEmpty()) {
origin.y=-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
* :<b> transform, image size, client area</b>.
*/
public void syncScrollBars() {
if (painterList.isEmpty()) {
redraw();
return;
public void syncSb() {
if (!painterList.isEmpty()) {
syncHSb();
syncVSb();
fireSelectionEvent();
}
int height = trackAreaPainter.getHeight(); // incl. Ruler
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);
this.getDisplay().asyncExec(() -> {redraw();});
}
int clientHeighth = clientArea.height;
vertical.setIncrement(clientHeighth / 100);
vertical.setPageIncrement(clientHeighth/2);
if (height > clientHeighth) { /* image is higher than client area */
private void syncVSb() {
Rectangle clientArea=getClientArea();
int height = trackAreaPainter.getHeight(); // incl. Ruler
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.setMaximum(height);
vertical.setEnabled(true);
if ( -origin.y > vertical.getMaximum() - clientHeighth) {
origin.y = -vertical.getMaximum() + clientHeighth;
if ( -origin.y > vertical.getMaximum() - clientHeight) {
origin.y = -vertical.getMaximum() + clientHeight;
}
} else { /* image is less higher than client area */
vertical.setMaximum(clientHeighth);
vertical.setMaximum(clientHeight);
vertical.setEnabled(false);
}
vertical.setThumb(clientHeighth);
vertical.setThumb(clientHeight);
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 */
@ -404,7 +423,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
result.add(entry.getValue().getTrackEntry());
}
} 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);
}
}
@ -432,8 +451,8 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
}
public void reveal(ITx tx) {
int lower = (int) (tx.getBeginTime() / scaleFactor);
int higher = (int) (tx.getEndTime() / scaleFactor);
int lower = (int) (tx.getBeginTime() / getScale());
int higher = (int) (tx.getEndTime() / getScale());
Point size = getSize();
size.x -= vertical.getSize().x + 2;
size.y -= horizontal.getSize().y;
@ -479,7 +498,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
}
public void reveal(long time) {
int scaledTime = (int) (time / scaleFactor);
int scaledTime = (int) (time / getScale());
Point size = getSize();
size.x -= vertical.getSize().x + 2;
size.y -= horizontal.getSize().y;
@ -492,7 +511,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
@Override
public void centerAt(long time) {
int scaledTime = (int) (time / scaleFactor);
int scaledTime = (int) (time / getScale());
int newX = -scaledTime+getWidth()/2;
setOrigin(newX>0?0:newX, origin.y);
}
@ -529,15 +548,15 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
}
}
@Override
public long getMaxVisibleTime() {
return (getClientArea().width-origin.x)*scaleFactor;
return (getClientArea().width-origin.x)*getScale();
}
@Override
public long getMinVisibleTime() {
return -origin.x * scaleFactor;
return -origin.x * getScale();
}
@Override
@ -545,7 +564,7 @@ public class WaveformCanvas extends Canvas implements IWaveformZoom{
long duration = getMaxVisibleTime()-getMinVisibleTime();
if(time>0) {
if((time+duration)<getMaxTime()) {
int scaledTime = (int) (time / scaleFactor);
int scaledTime = (int) (time / getScale());
setOrigin(-scaledTime, origin.y);
}
} else {

View File

@ -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();
}
}

View File

@ -54,9 +54,7 @@ import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
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.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
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.IWaveformZoom;
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.RangeSlider;
import com.minres.scviewer.database.ui.swt.internal.slider.ZoomingScrollbar;
import com.minres.scviewer.database.ui.swt.sb.FlatScrollBar;
import com.minres.scviewer.database.ui.swt.internal.slider.TimeZoomScrollbar;
public class WaveformView implements IWaveformView {
@ -344,21 +339,16 @@ public class WaveformView implements IWaveformView {
gl_waveformPane.marginHeight = 0;
waveformPane.setLayout(gl_waveformPane);
IWaveformScrollBarProvider sbProvider = new IWaveformScrollBarProvider() {
@Override
public IScrollBar getVerticalSb() {
return null;
}
waveformCanvas = new WaveformCanvas(waveformPane, SWT.NONE | SWT.V_SCROLL /*| SWT.H_SCROLL*/, styleProvider, new TimeZoomScrollbar.IProvider() {
@Override
public IScrollBar getHorizontalSb() {
ZoomingScrollbar timeSliderPane = new ZoomingScrollbar(waveformPane, SWT.NONE);
public TimeZoomScrollbar getScrollBar() {
TimeZoomScrollbar timeSliderPane = new TimeZoomScrollbar(waveformPane, SWT.NONE);
GridData gd_timeSliderPane = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1);
timeSliderPane.setLayoutData(gd_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));
// create the name pane
@ -551,7 +541,7 @@ public class WaveformView implements IWaveformView {
tracksVerticalHeight += streamEntry.height;
even = !even;
}
waveformCanvas.syncScrollBars();
waveformCanvas.syncSb();
nameList.setSize(nameMaxWidth + 15, tracksVerticalHeight);
nameListScrolled.setMinSize(nameMaxWidth + 15, tracksVerticalHeight);
nameList.redraw();

View File

@ -15,6 +15,7 @@ public class ImageButton extends Composite
private Image hoverImage;
private Image normalImage;
private Image pressedImage;
private Image disabledImage;
private int width;
private int height;
private boolean hover;
@ -24,8 +25,7 @@ public class ImageButton extends Composite
private ActionTimer.TimerAction timerAction;
public ImageButton(Composite parent, int style) {
super(parent, style);
super(parent, style);
timerAction = new ActionTimer.TimerAction() {
@Override
public void run() {
@ -37,30 +37,28 @@ public class ImageButton extends Composite
}
};
actionTimer = new ActionTimer(timerAction, this.getDisplay() );
addListener(SWT.Dispose, event -> {
if (hoverImage != null) hoverImage.dispose();
if (normalImage != null) normalImage.dispose();
if (pressedImage != null) pressedImage.dispose();
if (disabledImage != null) disabledImage.dispose();
});
addListener(SWT.Paint, event -> {
paintControl(event);
});
addListener(SWT.MouseDown, event -> {
if(!isEnabled()) return;
pressed=true;
notifyListeners();
if(autoFire) actionTimer.activate();
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;
@ -71,47 +69,38 @@ public class ImageButton extends Composite
private void paintControl(Event event) {
GC gc = event.gc;
if (hoverImage != null) {
if(pressed)
gc.drawImage(pressedImage, 1, 1);
else if(hover) {
gc.drawImage(hoverImage, 1, 1);
} else {
} else if(isEnabled()){
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();
hoverImage = new Image(d, imgs[0], SWT.IMAGE_COPY);
normalImage = imgs.length>1?
new Image(d, imgs[1], SWT.IMAGE_COPY):
new Image(d,imgs[0],SWT.IMAGE_GRAY);
pressedImage = imgs.length>2?
new Image(d, imgs[2], SWT.IMAGE_COPY):
new Image(d,imgs[0],SWT.IMAGE_DISABLE);
normalImage = new Image(d, imgs[0], SWT.IMAGE_COPY);
hoverImage = new Image(d, imgs[1], SWT.IMAGE_COPY);
pressedImage = new Image(d, imgs[2], SWT.IMAGE_COPY);
disabledImage = new Image(d, imgs[0], SWT.IMAGE_DISABLE);
width = imgs[0].getBounds().width;
height = imgs[0].getBounds().height;
redraw();
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed)
{
public Point computeSize(int wHint, int hHint, boolean changed) {
int overallWidth = width;
int overallHeight = height;
/* Consider hints */
if (wHint != SWT.DEFAULT && wHint < overallWidth)
overallWidth = wHint;
if (hHint != SWT.DEFAULT && hHint < overallHeight)
overallHeight = hHint;
/* Return computed dimensions plus border */
return new Point(overallWidth + 2, overallHeight + 2);
}
/**
@ -185,6 +174,4 @@ public class ImageButton extends Composite
public void setAutoFire(boolean autoFire) {
this.autoFire = autoFire;
}
}

View File

@ -55,6 +55,7 @@ public class RangeSlider extends Canvas {
private static int minWidth = 18;
private static int minHeight = 18;
private static int imgWidth = 8;
private static int minThumbWidth = 5;
private int minimum;
private int maximum;
private int lowerValue;
@ -143,17 +144,6 @@ public class RangeSlider extends Canvas {
isOn = (style & SWT.ON) == SWT.ON;
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();
addListener(SWT.Resize, event -> {
});
@ -300,14 +290,14 @@ public class RangeSlider extends Canvas {
} else if ((selectedElement & UPPER) != 0) {
upperValue = (int) Math.round((x - 9d) / computePixelSizeForHorizontalSlider()) + minimum;
if (!isSmooth) {
upperValue = (int) (Math.ceil(upperValue / increment) * increment) - increment;
upperValue = Math.min(lowerValue, (int) (Math.ceil(upperValue / increment) * increment) - increment);
}
checkUpperValue();
handleToolTip(upperValue);
} else {
lowerValue = (int) Math.round((x - 9d) / computePixelSizeForHorizontalSlider()) + minimum;
if (!isSmooth) {
lowerValue = (int) (Math.ceil(lowerValue / increment) * increment) - increment;
lowerValue = Math.max(upperValue, (int) (Math.ceil(lowerValue / increment) * increment) - increment);
}
checkLowerValue();
handleToolTip(lowerValue);
@ -380,11 +370,12 @@ public class RangeSlider extends Canvas {
return;
}
final Image img = orientation == SWT.HORIZONTAL ? slider[0] : vSlider;
final Rectangle imgBounds = img.getBounds();
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) && //
x >= coordUpper.x && x <= coordUpper.x + img.getBounds().width && //
y >= coordUpper.y && y <= coordUpper.y + img.getBounds().height;
x >= coordUpper.x && x <= coordUpper.x + imgBounds.width && //
y >= coordUpper.y && y <= coordUpper.y + imgBounds.height;
lowerHover &= (e.stateMask & SWT.CTRL) != 0 || !upperHover;
if (!lowerHover && !upperHover && isFullSelection && isBetweenKnobs(x, y)) {
lowerHover = upperHover = true;
@ -403,7 +394,7 @@ public class RangeSlider extends Canvas {
int value = -1;
final Rectangle clientArea = getClientArea();
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;
}
} 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) {
lowerValue = minimum;
}
if (lowerValue > maximum) {
lowerValue = maximum;
if (lowerValue > (maximum-minThumbWidth)) {
lowerValue = (maximum-minThumbWidth);
}
if (lowerValue > upperValue) {
lowerValue = upperValue;
if (lowerValue > (upperValue-minThumbWidth)) {
lowerValue = (upperValue-minThumbWidth);
}
}
@ -591,14 +582,14 @@ public class RangeSlider extends Canvas {
* Check if the upper value is in ranges
*/
private void checkUpperValue() {
if (upperValue < minimum) {
upperValue = minimum;
if (upperValue < (minimum+minThumbWidth)) {
upperValue = minimum+minThumbWidth;
}
if (upperValue > maximum) {
upperValue = maximum;
}
if (upperValue < lowerValue) {
upperValue = lowerValue;
if (upperValue < (lowerValue+minThumbWidth)) {
upperValue = lowerValue+minThumbWidth;
}
}
@ -1422,10 +1413,19 @@ public class RangeSlider extends Canvas {
* @see #getMaximum()
*/
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();
if (lowerValue <= upperValue && lowerValue >= minimum && upperValue <= maximum && (this.lowerValue != lowerValue || this.upperValue != upperValue)) {
this.lowerValue = lowerValue;
this.upperValue = upperValue;
if(update) {
Event e = new Event();
e.type=SWT.Selection;
e.doit=true;
validateNewValues(e);
}
redraw();
}
}

View File

@ -1,5 +1,7 @@
package com.minres.scviewer.database.ui.swt.internal.slider;
import java.text.Format;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
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.wb.swt.SWTResourceManager;
import com.minres.scviewer.database.ui.swt.internal.IScrollBar;
public class TimeZoomScrollbar extends Composite {
static public interface IProvider {
TimeZoomScrollbar getScrollBar();
}
public class ZoomingScrollbar extends Composite implements IScrollBar {
RangeSlider timeSlider;
final RangeSlider timeSlider;
final ImageButton leftButton;
final ImageButton rightButton;
/**
* Create the composite.
* @param parent
* @param style
*/
public ZoomingScrollbar(Composite parent, int style) {
public TimeZoomScrollbar(Composite parent, int style) {
super(parent, SWT.NO_FOCUS);
GridLayout gridLayout = new GridLayout(3, false);
gridLayout.horizontalSpacing = 0;
@ -27,84 +34,100 @@ public class ZoomingScrollbar extends Composite implements IScrollBar {
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
setLayout(gridLayout);
//setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
ImageButton b1 = new ImageButton(this, SWT.NONE);
GridData gd_b1 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_b1.widthHint=14;
gd_b1.heightHint=18;
b1.setLayoutData(gd_b1);
b1.setImage(new Image[] {
SWTResourceManager.getImage(this.getClass(), "arrow_left_hover.png"),
leftButton = new ImageButton(this, SWT.NONE);
GridData gd_leftButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_leftButton.widthHint=14;
gd_leftButton.heightHint=18;
leftButton.setLayoutData(gd_leftButton);
leftButton.setImage(new Image[] {
SWTResourceManager.getImage(this.getClass(), "arrow_left.png"),
SWTResourceManager.getImage(this.getClass(), "arrow_left_hover.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
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);
timeSlider.setSelection(newLow, newLow+diff, true);
}
});
timeSlider = new RangeSlider(this, /*SWT.ON|*/SWT.HIGH|SWT.SMOOTH|SWT.CONTROL);
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() {
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);
timeSlider.setSelection(newHigh-diff, newHigh, true);
}
});
}
@Override
public void setSelection(int i) {
timeSlider.setLowerValue(i);
public void setEnabled (boolean enabled) {
timeSlider.setEnabled(enabled);
leftButton.setEnabled(enabled);
rightButton.setEnabled(enabled);
super.setEnabled(enabled);
redraw();
}
@Override
public int getSelection() {
return timeSlider.getLowerValue();
public void setButtonsEnabled (boolean enabled) {
leftButton.setEnabled(enabled);
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) {
timeSlider.addSelectionListener(selectionListener);
}
@Override
public void setIncrement(int value) {
timeSlider.setIncrement(value);
}
@Override
public void setPageIncrement(int value) {
timeSlider.setPageIncrement(value);
}
@Override
public void setMinimum(int value) {
timeSlider.setMinimum(value);
}
@Override
public void setMaximum(int value) {
timeSlider.setMaximum(value);
}
@Override
public int getMaximum() {
return timeSlider.getMaximum();
}
@Override
public void setThumb(int w) {
timeSlider.setUpperValue(timeSlider.getLowerValue()+w);
public int getMinimum() {
return timeSlider.getMinimum();
}
}