Moved commonly used constants to own class
This commit is contained in:
parent
408138c27c
commit
4a17108ccc
|
@ -0,0 +1,9 @@
|
|||
package com.minres.scviewer.database.swt;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public final static String[] unitString={"fs", "ps", "ns", "us", "ms"};//, "s"};
|
||||
|
||||
public final static int[] unitMultiplier={1, 3, 10, 30, 100, 300};
|
||||
|
||||
}
|
|
@ -41,6 +41,7 @@ import com.minres.scviewer.database.ITx;
|
|||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.swt.Constants;
|
||||
import com.minres.scviewer.database.ui.IWaveformViewer;
|
||||
import com.minres.scviewer.database.ui.TrackEntry;
|
||||
import com.minres.scviewer.database.ui.WaveformColors;
|
||||
|
@ -56,11 +57,7 @@ public class WaveformCanvas extends Canvas {
|
|||
String unit="ns";
|
||||
|
||||
private int level = 12;
|
||||
|
||||
public final static String[] unitString={"fs", "ps", "ns", "us", "ms"};//, "s"};
|
||||
|
||||
public final static int[] unitMultiplier={1, 3, 10, 30, 100, 300};
|
||||
|
||||
|
||||
private long maxTime;
|
||||
|
||||
protected Point origin; /* original size */
|
||||
|
@ -225,12 +222,12 @@ public class WaveformCanvas extends Canvas {
|
|||
}
|
||||
|
||||
public int getMaxZoomLevel(){
|
||||
return unitMultiplier.length*unitString.length-1;
|
||||
return Constants.unitMultiplier.length*Constants.unitString.length-1;
|
||||
}
|
||||
|
||||
public void setZoomLevel(int level) {
|
||||
long oldScaleFactor=scaleFactor;
|
||||
if(level<unitMultiplier.length*unitString.length){
|
||||
if(level<Constants.unitMultiplier.length*Constants.unitString.length){
|
||||
this.level = level;
|
||||
this.scaleFactor = (long) Math.pow(10, level/2);
|
||||
if(level%2==1) this.scaleFactor*=3;
|
||||
|
@ -262,17 +259,17 @@ public class WaveformCanvas extends Canvas {
|
|||
}
|
||||
|
||||
public long getScaleFactorPow10() {
|
||||
int scale = level/unitMultiplier.length;
|
||||
int scale = level/Constants.unitMultiplier.length;
|
||||
double res = Math.pow(1000, scale);
|
||||
return (long) res;
|
||||
}
|
||||
|
||||
public String getUnitStr(){
|
||||
return unitString[level/unitMultiplier.length];
|
||||
return Constants.unitString[level/Constants.unitMultiplier.length];
|
||||
}
|
||||
|
||||
public int getUnitMultiplier(){
|
||||
return unitMultiplier[level%unitMultiplier.length];
|
||||
return Constants.unitMultiplier[level%Constants.unitMultiplier.length];
|
||||
}
|
||||
|
||||
public long getTimeForOffset(int xOffset){
|
||||
|
|
|
@ -82,6 +82,7 @@ import com.minres.scviewer.database.ITxStream;
|
|||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.swt.Constants;
|
||||
import com.minres.scviewer.database.ui.GotoDirection;
|
||||
import com.minres.scviewer.database.ui.ICursor;
|
||||
import com.minres.scviewer.database.ui.IWaveformViewer;
|
||||
|
@ -1194,10 +1195,10 @@ public class WaveformViewer implements IWaveformViewer {
|
|||
*/
|
||||
@Override
|
||||
public String[] getZoomLevels(){
|
||||
String[] res = new String[WaveformCanvas.unitMultiplier.length*WaveformCanvas.unitString.length];
|
||||
String[] res = new String[Constants.unitMultiplier.length*Constants.unitString.length];
|
||||
int index=0;
|
||||
for(String unit:WaveformCanvas.unitString){
|
||||
for(int factor:WaveformCanvas.unitMultiplier){
|
||||
for(String unit:Constants.unitString){
|
||||
for(int factor:Constants.unitMultiplier){
|
||||
res[index++]= new Integer(factor).toString()+unit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
|
|||
@Override
|
||||
public boolean load(IWaveformDb db, File file) throws Exception {
|
||||
this.db=db;
|
||||
this.maxTime=0;
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[dateBytes.length];
|
||||
int read = fis.read(buffer, 0, dateBytes.length);
|
||||
|
|
|
@ -75,6 +75,7 @@ import com.minres.scviewer.database.IWaveformDb;
|
|||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.swt.Constants;
|
||||
import com.minres.scviewer.database.swt.WaveformViewerFactory;
|
||||
import com.minres.scviewer.database.ui.GotoDirection;
|
||||
import com.minres.scviewer.database.ui.ICursor;
|
||||
|
@ -865,12 +866,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
updateAll();
|
||||
}
|
||||
|
||||
//FIXME: need to use unitString and unitMultiplier from class WaveformCanvas which is located in >com.minres.scviewer.database.swt.internal.
|
||||
//Trying to import com.minres.scviewer.database.swt.internal.WaveformCanvas results in the error:
|
||||
//'Access restriction: The type 'WaveformCanvas' is not API (restriction on required project 'com.minres.scviewer.database.ui.swt')'.
|
||||
public final static String[] unitString={"fs", "ps", "ns", "<EFBFBD>s", "ms"};//, "s"};
|
||||
public final static int[] unitMultiplier={1, 3, 10, 30, 100, 300};
|
||||
|
||||
/**
|
||||
* Sets the zoom fit.
|
||||
*/
|
||||
|
@ -882,15 +877,10 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
//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;
|
||||
|
||||
//System.out.println("ZoomLevel[] Array (Length " + zoomLevel.length + "): " + Arrays.toString(zoomLevel));
|
||||
//System.out.println("ClientArea myParent: " + myParent.getClientArea());
|
||||
//System.out.println("MaxTime: " + maxTime);
|
||||
//System.out.println("clientAreaWidth: " + clientAreaWidth);
|
||||
|
||||
|
||||
boolean foundZoom=false;
|
||||
//try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel
|
||||
for (int level=0; level<unitMultiplier.length*unitString.length; level++){
|
||||
for (int level=0; level<Constants.unitMultiplier.length*Constants.unitString.length; level++){
|
||||
long scaleFactor = (long) Math.pow(10, level/2);
|
||||
if(level%2==1) scaleFactor*=3;
|
||||
if(scaleFactor*clientAreaWidth >= maxTime) {
|
||||
|
@ -900,7 +890,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
}
|
||||
}
|
||||
//if no zoom level is found, set biggest one available
|
||||
if(!foundZoom) setZoomLevel(unitMultiplier.length*unitString.length-1);
|
||||
if(!foundZoom) setZoomLevel(Constants.unitMultiplier.length*Constants.unitString.length-1);
|
||||
|
||||
updateAll();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue