diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformCanvas.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformCanvas.java index e96ee6c..fe50833 100644 --- a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformCanvas.java +++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/internal/WaveformCanvas.java @@ -179,8 +179,11 @@ public class WaveformCanvas extends Canvas { } public void setZoomLevel(int level, long centerTime) { + if(level<0) { + level = findFitZoomLevel(); + if(level<0) level = 0; + } //FIXME: keep center if zoom-out and cursor is not in view - if(level<0) level = 0; long xc=centerTime/this.scaleFactor; // cursor total x-offset if(level>1); @@ -208,6 +211,24 @@ public class WaveformCanvas extends Canvas { } } + private int findFitZoomLevel() { + //get area actually capable of displaying data, i.e. area of the receiver which is capable of displaying data + Rectangle clientArea = getClientArea(); + long clientAreaWidth = clientArea.width; + //try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel + int magnitude_factor=1; + for(int magnitude=0; magnitude= maxTime) + return tempLevel; + } + magnitude_factor*=1000; + } + return -1; + } + public long getScaleFactor() { return scaleFactor; } diff --git a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java index 40b389c..2a31471 100644 --- a/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java +++ b/plugins/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/WaveformViewer.java @@ -570,6 +570,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis (result.isMultiStatus() && result.getChildren().length > 0 && result.getChildren()[0].getCode() != Status.OK_STATUS.getCode() ) ){ // kill editor and pop up warning for user sync.asyncExec(() -> { + if(myParent.isDisposed()) return; final Display display = myParent.getDisplay(); MessageDialog.openWarning(display.getActiveShell(), "Error loading database", "Database cannot be loaded. Aborting..."); ePartService.hidePart(myPart, true); @@ -1026,32 +1027,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis * Sets the zoom fit. */ public void setZoomFit() { - //actual max time of signal - long maxTime = waveformPane.getMaxTime(); - - //get area actually capable of displaying data, i.e. area of the receiver which is capable of displaying data - Rectangle clientArea = myParent.getClientArea(); - long clientAreaWidth = clientArea.width; - - boolean foundZoom=false; - //try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel - int magnitude_factor=1; - for(int magnitude=0; magnitude= maxTime) { - setZoomLevel(level); - foundZoom=true; - break; - } - } - if(foundZoom) break; - magnitude_factor*=1000; - } - //if no zoom level is found, set biggest one available - if(!foundZoom) setZoomLevel(Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length-1); - + waveformPane.setZoomLevel(-1); updateAll(); }