unify time printing (#69)
This commit is contained in:
parent
4a315722b1
commit
52cf9daeec
|
@ -1,5 +1,7 @@
|
|||
package com.minres.scviewer.database.ui.swt;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final String[] UNIT_STRING={"fs", "ps", "ns", "us", "ms"};//, "s"};
|
||||
|
@ -9,6 +11,20 @@ public class Constants {
|
|||
public static final String CONTENT_PROVIDER_TAG = "TOOLTIP_CONTENT_PROVIDER";
|
||||
public static final String HELP_PROVIDER_TAG = "TOOLTIP_HELP_PROVIDER";
|
||||
|
||||
public static final DecimalFormat TIME_FORMAT_FS = new DecimalFormat("#");
|
||||
public static final DecimalFormat TIME_FORMAT_PS = new DecimalFormat("#");
|
||||
public static final DecimalFormat TIME_FORMAT_NS = new DecimalFormat("#.0##");
|
||||
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,
|
||||
};
|
||||
|
||||
private Constants() {}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.swt.graphics.Rectangle;
|
|||
|
||||
import com.minres.scviewer.database.ui.ICursor;
|
||||
import com.minres.scviewer.database.ui.WaveformColors;
|
||||
import com.minres.scviewer.database.ui.swt.Constants;
|
||||
|
||||
public class CursorPainter implements IPainter, ICursor {
|
||||
|
||||
|
@ -84,7 +85,7 @@ public class CursorPainter implements IPainter, ICursor {
|
|||
proj.setBackground(drawColor);
|
||||
proj.setForeground(textColor);
|
||||
double dTime=time;
|
||||
proj.drawText((dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top);
|
||||
proj.drawText(Constants.TIME_FORMAT[waveCanvas.getZoomLevel()].format(dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@ import org.eclipse.swt.graphics.GC;
|
|||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.wb.swt.SWTResourceManager;
|
||||
|
||||
import com.minres.scviewer.database.ui.swt.Constants;
|
||||
|
||||
public class RulerPainter implements IPainter {
|
||||
protected final WaveformCanvas waveCanvas;
|
||||
|
||||
static final int RULER_TICK_MINOR = 10;
|
||||
static final int RULER_TICK_MAJOR = 100;
|
||||
|
||||
static final DecimalFormat df = new DecimalFormat("#.00####");
|
||||
|
||||
public RulerPainter(WaveformCanvas waveCanvas) {
|
||||
this.waveCanvas=waveCanvas;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class RulerPainter implements IPainter {
|
|||
|
||||
int minorTickY = waveCanvas.rulerHeight-5;
|
||||
int majorTickY = waveCanvas.rulerHeight-15;
|
||||
int textY=waveCanvas.rulerHeight-20;
|
||||
int textY=waveCanvas.rulerHeight-30;
|
||||
int baselineY=waveCanvas.rulerHeight - 1;
|
||||
int bottom=waveCanvas.rulerHeight - 2;
|
||||
|
||||
|
@ -66,13 +66,22 @@ public class RulerPainter implements IPainter {
|
|||
gc.fillRectangle(new Rectangle(area.x, area.y, area.width, baselineY));
|
||||
gc.setForeground(headerFgColor);
|
||||
gc.drawLine(area.x, area.y+bottom, area.x+area.width, area.y+bottom);
|
||||
|
||||
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);
|
||||
if(text.length()>8) allMarker=false;
|
||||
}
|
||||
}
|
||||
boolean drawText = true;
|
||||
for (long pos = startMinorIncrPos, tick = startMinorIncrVal; pos < endPos; pos+= rulerTickMinor, tick += rulerTickMinor) {
|
||||
int x0Pos = (int) (pos/scaleFactor);
|
||||
long x0Val = tick/scaleFactor;
|
||||
if ((tick % rulerTickMajor) == 0) {
|
||||
gc.drawText(df.format(x0Val*unitMultiplier)+unit, x0Pos, area.y+textY);
|
||||
if(allMarker || drawText)
|
||||
gc.drawText(Constants.TIME_FORMAT[waveCanvas.getZoomLevel()].format(x0Val*unitMultiplier)+unit, x0Pos, area.y+textY);
|
||||
gc.drawLine(x0Pos, area.y+majorTickY, x0Pos,area.y+ bottom);
|
||||
drawText=!drawText;
|
||||
} else {
|
||||
gc.drawLine(x0Pos, area.y+minorTickY, x0Pos, area.y+bottom);
|
||||
}
|
||||
|
|
|
@ -99,8 +99,6 @@ public class WaveformView implements IWaveformView {
|
|||
|
||||
private PropertyChangeSupport pcs;
|
||||
|
||||
static final DecimalFormat df = new DecimalFormat("#0.00####");
|
||||
|
||||
private ITx currentTxSelection;
|
||||
|
||||
private ArrayList<TrackEntry> currentWaveformSelection = new ArrayList<>();
|
||||
|
@ -1477,7 +1475,7 @@ public class WaveformView implements IWaveformView {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
double dTime = time;
|
||||
double scaledTime = dTime / waveformCanvas.getScaleFactorPow10();
|
||||
return sb.append(df.format(scaledTime)).append(waveformCanvas.getUnitStr()).toString();
|
||||
return sb.append(Constants.TIME_FORMAT[waveformCanvas.getZoomLevel()].format(scaledTime)).append(waveformCanvas.getUnitStr()).toString();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue