/*****************************************************************************
- * Copyright (c) 2007, 2013 Intel Corporation, Ericsson
+ * Copyright (c) 2007, 2014 Intel Corporation, Ericsson
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
import java.util.Date;
import java.util.TimeZone;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
private static final TimeDraw TIMEDRAW_ABS_MONTH = new TimeDrawAbsMonth();
private static final TimeDraw TIMEDRAW_ABS_YEAR = new TimeDrawAbsYear();
private static final TimeDraw TIMEDRAW_NUMBER = new TimeDrawNumber();
+ private static final TimeDraw TIMEDRAW_CYCLES = new TimeDrawCycles();
private static final int DRAG_EXTERNAL = -1;
private static final int NO_BUTTON = 0;
fTimeProvider = timeProvider;
}
+ /**
+ * Get the time provider used by this scale
+ *
+ * @return The time provider
+ * @since 3.1
+ */
+ public ITimeDataProvider getTimeProvider() {
+ return fTimeProvider;
+ }
+
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(wHint, fHeight, changed);
long timeDelta;
double minDelta = (pixelsPerNanoSec == 0) ? YEAR_IN_NS : width / pixelsPerNanoSec;
long unit = 1;
- if (fTimeProvider != null && fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider != null && fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
if (minDelta > 6 * MONTH_IN_NS) {
unit = YEAR_IN_NS;
} else if (minDelta > 3 * MONTH_IN_NS) {
TimeDraw getTimeDraw(long timeDelta) {
TimeDraw timeDraw;
if (fTimeProvider != null) {
-
- if (fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
+ switch (fTimeProvider.getTimeFormat()) {
+ case CALENDAR:
if (timeDelta >= YEAR_IN_NS) {
timeDraw = TIMEDRAW_ABS_YEAR;
} else if (timeDelta >= MONTH_IN_NS) {
timeDraw = TIMEDRAW_ABS_NANOSEC;
}
return timeDraw;
- } else if (fTimeProvider.getTimeFormat() == TimeFormat.NUMBER) {
- timeDraw = TIMEDRAW_NUMBER;
- return timeDraw;
+ case NUMBER:
+ return TIMEDRAW_NUMBER;
+ case CYCLES:
+ return TIMEDRAW_CYCLES;
+ case RELATIVE:
+ default:
}
}
} else {
int x1;
int x2;
- if (fTimeProvider instanceof ITimeDataProvider2) {
- long selectionBegin = ((ITimeDataProvider2) fTimeProvider).getSelectionBegin();
- long selectionEnd = ((ITimeDataProvider2) fTimeProvider).getSelectionEnd();
- x1 = leftSpace + (int) ((selectionBegin - time0) * pixelsPerNanoSec);
- x2 = leftSpace + (int) ((selectionEnd - time0) * pixelsPerNanoSec);
- } else {
- @SuppressWarnings("deprecation")
- long selectedTime = fTimeProvider.getSelectedTime();
- x1 = leftSpace + (int) ((selectedTime - time0) * pixelsPerNanoSec);
- x2 = x1;
- }
+ long selectionBegin = fTimeProvider.getSelectionBegin();
+ long selectionEnd = fTimeProvider.getSelectionEnd();
+ x1 = leftSpace + (int) ((selectionBegin - time0) * pixelsPerNanoSec);
+ x2 = leftSpace + (int) ((selectionEnd - time0) * pixelsPerNanoSec);
drawRangeDecorators(rect0, gc, x1, x2);
}
rect0.width = labelWidth;
long time;
- if (fTimeProvider != null && fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider != null && fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
time = floorToCalendar(time0, timeDelta);
} else {
time = (time0 / timeDelta) * timeDelta;
int y = rect0.y + rect0.height;
- if (fTimeProvider != null && fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider != null && fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
timeDraw.drawAbsHeader(gc, time, absHeaderRect);
}
if (pixelsPerNanoSec == 0 || time > Long.MAX_VALUE - timeDelta || timeDelta == 0) {
break;
}
- if (fTimeProvider != null && fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider != null && fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
if (timeDelta >= YEAR_IN_NS) {
long millis = time / MILLISEC_IN_NS;
GREGORIAN_CALENDAR.setTime(new Date(millis));
int numDigits = 5;
long timeRange = time1 - time0;
- if (fTimeProvider.getTimeFormat().equals(TimeFormat.CALENDAR)) {
+ if (fTimeProvider.getTimeFormat() == TimeFormat.CALENDAR) {
// Calculate the number of digits to represent the minutes provided
// 11:222
// HH:mm:ss
int thousandGroups = (numDigits - 1) / 3;
numDigits += thousandGroups;
numDigits += 12; // .000 000 000
+ if (fTimeProvider.getTimeFormat() == TimeFormat.CYCLES) {
+ numDigits += Messages.Utils_ClockCyclesUnit.length();
+ }
}
return numDigits;
return s + n;
}
- public abstract void draw(GC gc, long time, Rectangle rect);
+ public abstract int draw(GC gc, long time, Rectangle rect);
/**
* Override to draw absolute time header. This is for the time information
class TimeDrawSec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
long sec = nanosec / SEC_IN_NS;
- Utils.drawText(gc, sep(sec), rect, true);
+ return Utils.drawText(gc, sep(sec), rect, true);
}
}
class TimeDrawMillisec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
long millisec = nanosec / MILLISEC_IN_NS;
long ms = millisec % PAD_1000;
long sec = millisec / SEC_IN_MS;
- Utils.drawText(gc, sep(sec) + "." + pad(ms), rect, true); //$NON-NLS-1$
+ return Utils.drawText(gc, sep(sec) + "." + pad(ms), rect, true); //$NON-NLS-1$
}
}
class TimeDrawMicrosec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
long microsec = nanosec / MICROSEC_IN_NS;
long us = microsec % PAD_1000;
long millisec = microsec / MILLISEC_IN_US;
long ms = millisec % PAD_1000;
long sec = millisec / SEC_IN_MS;
- Utils.drawText(gc, sep(sec) + "." + pad(ms) + " " + pad(us), rect, true); //$NON-NLS-1$ //$NON-NLS-2$
+ return Utils.drawText(gc, sep(sec) + "." + pad(ms) + " " + pad(us), rect, true); //$NON-NLS-1$ //$NON-NLS-2$
}
}
class TimeDrawNanosec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
long ns = nanosec % PAD_1000;
long microsec = nanosec / MICROSEC_IN_NS;
long us = microsec % PAD_1000;
long millisec = microsec / MILLISEC_IN_US;
long ms = millisec % PAD_1000;
long sec = millisec / SEC_IN_MS;
- Utils.drawText(gc, sep(sec) + "." + pad(ms) + " " + pad(us) + " " + pad(ns), rect, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return Utils.drawText(gc, sep(sec) + "." + pad(ms) + " " + pad(us) + " " + pad(ns), rect, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
class TimeDrawAbsYear extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = YEAR_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
}
class TimeDrawAbsMonth extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = MONTH_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
}
class TimeDrawAbsDay extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = DAY_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
@Override
class TimeDrawAbsHrs extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = HOURS_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
@Override
class TimeDrawAbsMin extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = MIN_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
@Override
class TimeDrawAbsSec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = SEC_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
}
@Override
class TimeDrawAbsMillisec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = SEC_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
String ns = Utils.formatNs(nanosec, Resolution.MILLISEC);
-
- Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
+ return Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
}
@Override
class TimeDrawAbsMicroSec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = SEC_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
String micr = Utils.formatNs(nanosec, Resolution.MICROSEC);
- Utils.drawText(gc, stime + "." + micr, rect, true); //$NON-NLS-1$
+ return Utils.drawText(gc, stime + "." + micr, rect, true); //$NON-NLS-1$
}
@Override
class TimeDrawAbsNanoSec extends TimeDraw {
@Override
- public void draw(GC gc, long nanosec, Rectangle rect) {
+ public int draw(GC gc, long nanosec, Rectangle rect) {
String stime = SEC_FORMAT.format(new Date(nanosec / MILLISEC_IN_NS));
String ns = Utils.formatNs(nanosec, Resolution.NANOSEC);
- Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
+ return Utils.drawText(gc, stime + "." + ns, rect, true); //$NON-NLS-1$
}
@Override
class TimeDrawNumber extends TimeDraw {
@Override
- public void draw(GC gc, long time, Rectangle rect) {
+ public int draw(GC gc, long time, Rectangle rect) {
String stime = NumberFormat.getInstance().format(time);
- Utils.drawText(gc, stime, rect, true);
+ return Utils.drawText(gc, stime, rect, true);
+ }
+}
+
+class TimeDrawCycles extends TimeDraw {
+ @Override
+ public int draw(GC gc, long time, Rectangle rect) {
+ String stime = Utils.formatTime(time, TimeFormat.CYCLES, Resolution.SECONDS);
+ return Utils.drawText(gc, stime, rect, true);
}
}