import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
*/
protected TmfView fParentView;
- private Composite fParent;
+ private Composite fComposite;
private Font fFont;
// Histogram text fields
*/
public Histogram(final TmfView view, final Composite parent) {
fParentView = view;
- fParent = parent;
- createWidget(parent);
+ fComposite = createWidget(parent);
fDataModel = new HistogramDataModel();
fDataModel.addHistogramListener(this);
clear();
fDataModel.removeHistogramListener(this);
}
- private void createWidget(final Composite parent) {
+ private Composite createWidget(final Composite parent) {
final Color labelColor = parent.getBackground();
fFont = adjustFont(parent);
fTimeRangeStartText = new Text(composite, SWT.READ_ONLY);
fTimeRangeStartText.setFont(fFont);
fTimeRangeStartText.setBackground(labelColor);
- fTimeRangeStartText.setText(TmfTimestamp.ZERO.toString());
fTimeRangeStartText.setLayoutData(gridData);
// Window range end time
fTimeRangeEndText = new Text(composite, SWT.READ_ONLY);
fTimeRangeEndText.setFont(fFont);
fTimeRangeEndText.setBackground(labelColor);
- fTimeRangeEndText.setText(TmfTimestamp.ZERO.toString());
fTimeRangeEndText.setLayoutData(gridData);
+
+ return composite;
}
private static Font adjustFont(final Composite composite) {
synchronized(fDataModel) {
if (fScaledData != null) {
fCanvas.redraw();
- // Display histogram and update X-,Y-axis labels
- fTimeRangeStartText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime()));
- fTimeRangeEndText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()));
+ if (fDataModel.getNbEvents() != 0) {
+ // Display histogram and update X-,Y-axis labels
+ fTimeRangeStartText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime()));
+ fTimeRangeEndText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()));
+ } else {
+ fTimeRangeStartText.setText(""); //$NON-NLS-1$
+ fTimeRangeEndText.setText(""); //$NON-NLS-1$
+ }
fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue));
// The Y-axis area might need to be re-sized
fMaxNbEventsText.getParent().layout();
*/
@TmfSignalHandler
public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) {
- Point size = fTimeRangeStartText.getSize();
+ if (fDataModel.getNbEvents() == 0) {
+ return;
+ }
+
String newTS = TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime());
- size.x = getTextSize(newTS);
- fTimeRangeStartText.setSize(size);
fTimeRangeStartText.setText(newTS);
newTS = TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime());
- Rectangle rect = fTimeRangeEndText.getBounds();
- int newWidth = getTextSize(newTS);
- rect.x += rect.width - newWidth;
- rect.width = newWidth;
- fTimeRangeEndText.setBounds(rect);
fTimeRangeEndText.setText(newTS);
- }
-
- /**
- * Compute the width of a String.
- *
- * @param text the Text to measure
- * @return The result size
- * @since 2.0
- */
- private int getTextSize(final String text) {
- GC controlGC = new GC(fParent);
- controlGC.setFont(fFont);
-
- int textSize = 0;
- for (int pos = 0; pos < text.length(); pos++) {
- textSize += controlGC.getAdvanceWidth(text.charAt(pos));
- }
- // Add an extra space
- textSize += controlGC.getAdvanceWidth(' ');
-
- controlGC.dispose();
- return textSize;
+ fComposite.layout();
}
}
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
-import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.swt.widgets.Composite;
*/
public class HistogramCurrentTimeControl extends HistogramTextControl {
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private long fTraceStartTime;
-
// ------------------------------------------------------------------------
// Construction
// ------------------------------------------------------------------------
@Override
protected void updateValue() {
+ if (getValue() == Long.MIN_VALUE) {
+ fTextValue.setText(""); //$NON-NLS-1$
+ return;
+ }
String string = fTextValue.getText();
long value = 0;
try {
@Override
public void setValue(long time) {
- super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString());
- }
-
- // ------------------------------------------------------------------------
- // Signal Handlers
- // ------------------------------------------------------------------------
-
- /**
- * Update the initial time value
- *
- * @param signal the time range signal
- * @since 2.0
- */
- @TmfSignalHandler
- public void traceUpdated(final TmfTraceUpdatedSignal signal) {
- fTraceStartTime = signal.getTrace().getTimeRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+ if (time != Long.MIN_VALUE) {
+ super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString());
+ } else {
+ super.setValue(time, ""); //$NON-NLS-1$
+ }
}
// ------------------------------------------------------------------------
gridData.verticalAlignment = SWT.CENTER;
fCurrentEventTimeControl = new HistogramCurrentTimeControl(this, controlsComposite, currentEventLabel, 0L);
fCurrentEventTimeControl.setLayoutData(gridData);
- fCurrentEventTimeControl.setValue(0L);
+ fCurrentEventTimeControl.setValue(Long.MIN_VALUE);
// Window span time control
gridData = new GridData();
gridData.verticalAlignment = SWT.CENTER;
fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, windowSpanLabel, 0L);
fTimeSpanControl.setLayoutData(gridData);
- fTimeSpanControl.setValue(0L);
+ fTimeSpanControl.setValue(Long.MIN_VALUE);
// --------------------------------------------------------------------
// Time range histogram
// Clear the UI widgets
fFullTraceHistogram.clear();
fTimeRangeHistogram.clear();
- fCurrentEventTimeControl.setValue(0L);
+ fCurrentEventTimeControl.setValue(Long.MIN_VALUE);
- fTimeSpanControl.setValue(0);
+ fTimeSpanControl.setValue(Long.MIN_VALUE);
}
/**