add zoom levels

This commit is contained in:
Eyck Jentzsch 2021-11-16 14:12:10 +01:00
parent 524ffb189c
commit 3572f683e3
8 changed files with 37 additions and 42 deletions

View File

@ -5,8 +5,10 @@ import java.text.DecimalFormat;
public class Constants {
public static final String[] UNIT_STRING={"fs", "ps", "ns", "us", "ms"};//, "s"};
public static final long[] UNIT_MULTIPLIER={1, 1000, 1000*1000, 1000*1000*1000, 1000*1000*1000*1000, 1000*1000*1000*1000*1000 };
public static final int[] UNIT_MULTIPLIER={1, 3, 10, 30, 100, 300};
//public static final int[] UNIT_MULTIPLIER={1, 3, 10, 30, 100, 300};
public static final long[] SCALE_MULTIPLIER={1, 2, 5, 10, 20, 50, 100, 200, 500};
public static final String CONTENT_PROVIDER_TAG = "TOOLTIP_CONTENT_PROVIDER";
public static final String HELP_PROVIDER_TAG = "TOOLTIP_HELP_PROVIDER";
@ -17,14 +19,18 @@ public class Constants {
public static final DecimalFormat TIME_FORMAT_US = new DecimalFormat("#.0#####");
public static final DecimalFormat TIME_FORMAT_MS = new DecimalFormat("#.0#####");
public static final DecimalFormat[] TIME_FORMAT = {
TIME_FORMAT_FS, TIME_FORMAT_FS, TIME_FORMAT_FS, TIME_FORMAT_FS, TIME_FORMAT_FS, TIME_FORMAT_FS,
TIME_FORMAT_PS, TIME_FORMAT_PS, TIME_FORMAT_PS, TIME_FORMAT_PS, TIME_FORMAT_PS, TIME_FORMAT_PS,
TIME_FORMAT_NS, TIME_FORMAT_NS, TIME_FORMAT_NS, TIME_FORMAT_NS, TIME_FORMAT_NS, TIME_FORMAT_NS,
TIME_FORMAT_US, TIME_FORMAT_US, TIME_FORMAT_US, TIME_FORMAT_US, TIME_FORMAT_US, TIME_FORMAT_US,
TIME_FORMAT_MS, TIME_FORMAT_MS, TIME_FORMAT_MS, TIME_FORMAT_MS, TIME_FORMAT_MS, TIME_FORMAT_MS,
};
public static DecimalFormat getTimeFormatForLevel(int level) {
switch(level/SCALE_MULTIPLIER.length) {
case 0: return TIME_FORMAT_FS;
case 1: return TIME_FORMAT_PS;
case 2: return TIME_FORMAT_NS;
case 3: return TIME_FORMAT_US;
case 4: return TIME_FORMAT_MS;
default:
return TIME_FORMAT_FS;
}
}
private Constants() {}
}

View File

@ -24,7 +24,6 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.tx.ITx;

View File

@ -85,7 +85,7 @@ public class CursorPainter implements IPainter, ICursor {
proj.setBackground(drawColor);
proj.setForeground(textColor);
double dTime=time;
proj.drawText(Constants.TIME_FORMAT[waveCanvas.getZoomLevel()].format(dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top);
proj.drawText(Constants.getTimeFormatForLevel(waveCanvas.getZoomLevel()).format(dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top);
}
}
}

View File

@ -10,8 +10,6 @@
*******************************************************************************/
package com.minres.scviewer.database.ui.swt.internal;
import java.text.DecimalFormat;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
@ -40,7 +38,7 @@ public class RulerPainter implements IPainter {
if(headerBgColor.isDisposed())
headerBgColor=SWTResourceManager.getColor(255,255,255);
String unit=waveCanvas.getUnitStr();
int unitMultiplier=waveCanvas.getUnitMultiplier();
long unitMultiplier=waveCanvas.getUnitMultiplier();
long scaleFactor=waveCanvas.getScaleFactor();
long startPos=area.x*scaleFactor;
@ -69,7 +67,7 @@ public class RulerPainter implements IPainter {
boolean allMarker=true;
for (long pos = startMinorIncrPos, tick = startMinorIncrVal; pos < endPos; pos+= rulerTickMinor, tick += rulerTickMinor) {
if ((tick % rulerTickMajor) == 0) {
String text = Constants.TIME_FORMAT[waveCanvas.getZoomLevel()].format(tick/scaleFactor*unitMultiplier);
String text = Constants.getTimeFormatForLevel(waveCanvas.getZoomLevel()).format(tick/scaleFactor*unitMultiplier);
if(text.length()>8) allMarker=false;
}
}
@ -79,7 +77,7 @@ public class RulerPainter implements IPainter {
long x0Val = tick/scaleFactor;
if ((tick % rulerTickMajor) == 0) {
if(allMarker || drawText)
gc.drawText(Constants.TIME_FORMAT[waveCanvas.getZoomLevel()].format(x0Val*unitMultiplier)+unit, x0Pos, area.y+textY);
gc.drawText(Constants.getTimeFormatForLevel(waveCanvas.getZoomLevel()).format(x0Val*unitMultiplier)+unit, x0Pos, area.y+textY);
gc.drawLine(x0Pos, area.y+majorTickY, x0Pos,area.y+ bottom);
drawText=!drawText;
} else {

View File

@ -170,7 +170,7 @@ public class WaveformCanvas extends Canvas {
}
public int getMaxZoomLevel(){
return Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length-1;
return Constants.SCALE_MULTIPLIER.length*Constants.UNIT_STRING.length-1;
}
public void setZoomLevel(int level) {
@ -190,9 +190,10 @@ public class WaveformCanvas extends Canvas {
if(level<0) level = 0;
}
//FIXME: keep center if zoom-out and cursor is not in view
if(level<Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length){
this.scaleFactor = (long) Math.pow(10, level>>1);
if(level%2==1) this.scaleFactor*=3;
if(level<Constants.SCALE_MULTIPLIER.length*Constants.UNIT_STRING.length){
int scale = level%Constants.SCALE_MULTIPLIER.length;
int unit = level/Constants.SCALE_MULTIPLIER.length;
this.scaleFactor = Constants.UNIT_MULTIPLIER[unit]*Constants.SCALE_MULTIPLIER[scale];
ITx tx = arrowPainter.getTx();
arrowPainter.setTx(null);
/*
@ -223,14 +224,13 @@ public class WaveformCanvas extends Canvas {
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
final long[] UNIT_STRING_MULT={1, 1000, 1000*1000, 1000*1000*1000, 1000*1000*1000*1000, 1000*1000*1000*1000*1000 };
for(int magnitude=0; magnitude<Constants.UNIT_STRING.length; magnitude++) {
long magnitudeMultiplier = UNIT_STRING_MULT[magnitude];
for (int multiplier=0; multiplier<Constants.UNIT_MULTIPLIER.length; multiplier++){
long scaleFactor = magnitudeMultiplier * Constants.UNIT_MULTIPLIER[multiplier];
for(int unitIdx=0; unitIdx<Constants.UNIT_STRING.length; unitIdx++) {
long magnitudeMultiplier = Constants.UNIT_MULTIPLIER[unitIdx];
for (int scaleIdx=0; scaleIdx<Constants.SCALE_MULTIPLIER.length; scaleIdx++){
long scaleFactor = magnitudeMultiplier * Constants.SCALE_MULTIPLIER[scaleIdx];
long range = scaleFactor*clientAreaWidth;
if( range >= duration)
return magnitude*Constants.UNIT_MULTIPLIER.length+multiplier;
return unitIdx*Constants.SCALE_MULTIPLIER.length+scaleIdx;
}
}
return -1;
@ -241,17 +241,17 @@ public class WaveformCanvas extends Canvas {
}
public long getScaleFactorPow10() {
int scale = level/Constants.UNIT_MULTIPLIER.length;
int scale = level/Constants.SCALE_MULTIPLIER.length;
double res = Math.pow(1000, scale);
return (long) res;
}
public String getUnitStr(){
return Constants.UNIT_STRING[level/Constants.UNIT_MULTIPLIER.length];
return Constants.UNIT_STRING[level/Constants.SCALE_MULTIPLIER.length];
}
public int getUnitMultiplier(){
return Constants.UNIT_MULTIPLIER[level%Constants.UNIT_MULTIPLIER.length];
public long getUnitMultiplier(){
return Constants.SCALE_MULTIPLIER[level%Constants.SCALE_MULTIPLIER.length];
}
public long getTimeForOffset(int xOffset){

View File

@ -13,7 +13,6 @@ package com.minres.scviewer.database.ui.swt.internal;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -1475,7 +1474,7 @@ public class WaveformView implements IWaveformView {
StringBuilder sb = new StringBuilder();
double dTime = time;
double scaledTime = dTime / waveformCanvas.getScaleFactorPow10();
return sb.append(Constants.TIME_FORMAT[waveformCanvas.getZoomLevel()].format(scaledTime)).append(waveformCanvas.getUnitStr()).toString();
return sb.append(Constants.getTimeFormatForLevel(waveformCanvas.getZoomLevel()).format(scaledTime)).append(waveformCanvas.getUnitStr()).toString();
}
/*
@ -1485,11 +1484,11 @@ public class WaveformView implements IWaveformView {
*/
@Override
public String[] getZoomLevels() {
String[] res = new String[Constants.UNIT_MULTIPLIER.length * Constants.UNIT_STRING.length];
String[] res = new String[Constants.SCALE_MULTIPLIER.length * Constants.UNIT_STRING.length];
int index = 0;
for (String unit : Constants.UNIT_STRING) {
for (int factor : Constants.UNIT_MULTIPLIER) {
res[index++] = Integer.toString(factor) + unit;
for (long factor : Constants.SCALE_MULTIPLIER) {
res[index++] = Long.toString(factor) + unit;
}
}
return res;

View File

@ -5,9 +5,6 @@ import java.io.File;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ResourceLocator;
@ -17,8 +14,6 @@ import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@ -26,7 +21,6 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

View File

@ -19,7 +19,6 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
/**
* The Class TxDbContentProvider providing the tree content of a database for the respective viewer.