1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Changed to updated histogram data model
12 * Francois Chouinard - Reformat histogram labels on format change
13 * Patrick Tasse - Support selection range
14 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalManager
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimestampFormatUpdateSignal
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestampFormat
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.events
.ControlEvent
;
27 import org
.eclipse
.swt
.events
.ControlListener
;
28 import org
.eclipse
.swt
.events
.FocusAdapter
;
29 import org
.eclipse
.swt
.events
.FocusEvent
;
30 import org
.eclipse
.swt
.events
.FocusListener
;
31 import org
.eclipse
.swt
.events
.KeyEvent
;
32 import org
.eclipse
.swt
.events
.KeyListener
;
33 import org
.eclipse
.swt
.events
.MouseEvent
;
34 import org
.eclipse
.swt
.events
.MouseListener
;
35 import org
.eclipse
.swt
.events
.MouseTrackListener
;
36 import org
.eclipse
.swt
.events
.MouseWheelListener
;
37 import org
.eclipse
.swt
.events
.PaintEvent
;
38 import org
.eclipse
.swt
.events
.PaintListener
;
39 import org
.eclipse
.swt
.graphics
.Color
;
40 import org
.eclipse
.swt
.graphics
.Font
;
41 import org
.eclipse
.swt
.graphics
.FontData
;
42 import org
.eclipse
.swt
.graphics
.GC
;
43 import org
.eclipse
.swt
.graphics
.Image
;
44 import org
.eclipse
.swt
.layout
.FillLayout
;
45 import org
.eclipse
.swt
.layout
.GridData
;
46 import org
.eclipse
.swt
.layout
.GridLayout
;
47 import org
.eclipse
.swt
.widgets
.Canvas
;
48 import org
.eclipse
.swt
.widgets
.Composite
;
49 import org
.eclipse
.swt
.widgets
.Display
;
50 import org
.eclipse
.swt
.widgets
.Label
;
51 import org
.eclipse
.swt
.widgets
.Text
;
54 * Re-usable histogram widget.
56 * It has the following features:
58 * <li>Y-axis labels displaying min/max count values
59 * <li>X-axis labels displaying time range
60 * <li>a histogram displaying the distribution of values over time (note that
61 * the histogram might not necessarily fill the whole canvas)
63 * The widget also has 2 'markers' to identify:
65 * <li>a red dashed line over the bar that contains the currently selected event
66 * <li>a dark red dashed line that delimits the right end of the histogram (if
67 * it doesn't fill the canvas)
69 * Clicking on the histogram will select the current event at the mouse
72 * Once the histogram is selected, there is some limited keyboard support:
74 * <li>Home: go to the first histogram bar
75 * <li>End: go to the last histogram bar
76 * <li>Left: go to the previous histogram
77 * <li>Right: go to the next histogram bar
79 * Finally, when the mouse hovers over the histogram, a tool tip showing the
80 * following information about the corresponding histogram bar time range:
82 * <li>start of the time range
83 * <li>end of the time range
84 * <li>number of events in that time range
88 * @author Francois Chouinard
90 public abstract class Histogram
implements ControlListener
, PaintListener
, KeyListener
, MouseListener
, MouseTrackListener
, IHistogramModelListener
{
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
97 private final Color fBackgroundColor
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
);
98 private final Color fSelectionForegroundColor
= Display
.getCurrent().getSystemColor(SWT
.COLOR_BLUE
);
99 private final Color fSelectionBackgroundColor
= Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_BACKGROUND
);
100 private final Color fLastEventColor
= Display
.getCurrent().getSystemColor(SWT
.COLOR_DARK_RED
);
101 private final Color fHistoBarColor
= new Color(Display
.getDefault(), 74, 112, 139);
102 private final Color fLostEventColor
= new Color(Display
.getCurrent(), 208, 62, 120);
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
109 * The parent TMF view.
111 protected TmfView fParentView
;
113 private Composite fComposite
;
116 // Histogram text fields
117 private Text fMaxNbEventsText
;
118 private Text fMinNbEventsText
;
119 private Text fTimeRangeStartText
;
120 private Text fTimeRangeEndText
;
123 * Histogram drawing area
125 protected Canvas fCanvas
;
128 * The histogram data model.
130 protected final HistogramDataModel fDataModel
;
133 * The histogram data model scaled to current resolution and screen width.
135 protected HistogramScaledData fScaledData
;
138 * The current event value
140 protected long fCurrentEventTime
= 0L;
143 * The current selection begin time
145 private long fSelectionBegin
= 0L;
148 * The current selection end time
150 private long fSelectionEnd
= 0L;
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
159 * @param view A reference to the parent TMF view.
160 * @param parent A parent composite
162 public Histogram(final TmfView view
, final Composite parent
) {
165 fComposite
= createWidget(parent
);
166 fDataModel
= new HistogramDataModel();
167 fDataModel
.addHistogramListener(this);
170 fCanvas
.addControlListener(this);
171 fCanvas
.addPaintListener(this);
172 fCanvas
.addKeyListener(this);
173 fCanvas
.addMouseListener(this);
174 fCanvas
.addMouseTrackListener(this);
176 TmfSignalManager
.register(this);
180 * Dispose resources and unregisters listeners.
182 public void dispose() {
183 TmfSignalManager
.deregister(this);
185 fHistoBarColor
.dispose();
186 fLastEventColor
.dispose();
187 fDataModel
.removeHistogramListener(this);
190 private Composite
createWidget(final Composite parent
) {
192 final Color labelColor
= parent
.getBackground();
193 fFont
= adjustFont(parent
);
195 final int initalWidth
= 10;
197 // --------------------------------------------------------------------
198 // Define the histogram
199 // --------------------------------------------------------------------
201 final GridLayout gridLayout
= new GridLayout();
202 gridLayout
.numColumns
= 3;
203 gridLayout
.marginHeight
= 0;
204 gridLayout
.marginWidth
= 0;
205 gridLayout
.marginTop
= 0;
206 gridLayout
.horizontalSpacing
= 0;
207 gridLayout
.verticalSpacing
= 0;
208 gridLayout
.marginLeft
= 0;
209 gridLayout
.marginRight
= 0;
210 final Composite composite
= new Composite(parent
, SWT
.FILL
);
211 composite
.setLayout(gridLayout
);
213 // Use all the horizontal space
214 GridData gridData
= new GridData();
215 gridData
.horizontalAlignment
= SWT
.FILL
;
216 gridData
.verticalAlignment
= SWT
.FILL
;
217 gridData
.grabExcessHorizontalSpace
= true;
218 composite
.setLayoutData(gridData
);
221 gridData
= new GridData();
222 gridData
.horizontalAlignment
= SWT
.RIGHT
;
223 gridData
.verticalAlignment
= SWT
.TOP
;
224 fMaxNbEventsText
= new Text(composite
, SWT
.READ_ONLY
| SWT
.RIGHT
);
225 fMaxNbEventsText
.setFont(fFont
);
226 fMaxNbEventsText
.setBackground(labelColor
);
227 fMaxNbEventsText
.setEditable(false);
228 fMaxNbEventsText
.setText("0"); //$NON-NLS-1$
229 fMaxNbEventsText
.setLayoutData(gridData
);
232 Composite canvasComposite
= new Composite(composite
, SWT
.BORDER
);
233 gridData
= new GridData();
234 gridData
.horizontalSpan
= 2;
235 gridData
.verticalSpan
= 2;
236 gridData
.horizontalAlignment
= SWT
.FILL
;
237 gridData
.verticalAlignment
= SWT
.FILL
;
238 gridData
.grabExcessHorizontalSpace
= true;
239 canvasComposite
.setLayoutData(gridData
);
240 canvasComposite
.setLayout(new FillLayout());
241 fCanvas
= new Canvas(canvasComposite
, SWT
.DOUBLE_BUFFERED
);
243 // Y-axis min event (always 0...)
244 gridData
= new GridData();
245 gridData
.horizontalAlignment
= SWT
.RIGHT
;
246 gridData
.verticalAlignment
= SWT
.BOTTOM
;
247 fMinNbEventsText
= new Text(composite
, SWT
.READ_ONLY
| SWT
.RIGHT
);
248 fMinNbEventsText
.setFont(fFont
);
249 fMinNbEventsText
.setBackground(labelColor
);
250 fMinNbEventsText
.setEditable(false);
251 fMinNbEventsText
.setText("0"); //$NON-NLS-1$
252 fMinNbEventsText
.setLayoutData(gridData
);
255 gridData
= new GridData(initalWidth
, SWT
.DEFAULT
);
256 gridData
.horizontalAlignment
= SWT
.RIGHT
;
257 gridData
.verticalAlignment
= SWT
.BOTTOM
;
258 final Label dummyLabel
= new Label(composite
, SWT
.NONE
);
259 dummyLabel
.setLayoutData(gridData
);
261 // Window range start time
262 gridData
= new GridData();
263 gridData
.horizontalAlignment
= SWT
.LEFT
;
264 gridData
.verticalAlignment
= SWT
.BOTTOM
;
265 fTimeRangeStartText
= new Text(composite
, SWT
.READ_ONLY
);
266 fTimeRangeStartText
.setFont(fFont
);
267 fTimeRangeStartText
.setBackground(labelColor
);
268 fTimeRangeStartText
.setLayoutData(gridData
);
270 // Window range end time
271 gridData
= new GridData();
272 gridData
.horizontalAlignment
= SWT
.RIGHT
;
273 gridData
.verticalAlignment
= SWT
.BOTTOM
;
274 fTimeRangeEndText
= new Text(composite
, SWT
.READ_ONLY
);
275 fTimeRangeEndText
.setFont(fFont
);
276 fTimeRangeEndText
.setBackground(labelColor
);
277 fTimeRangeEndText
.setLayoutData(gridData
);
279 FocusListener listener
= new FocusAdapter() {
281 public void focusGained(FocusEvent e
) {
285 fMaxNbEventsText
.addFocusListener(listener
);
286 fMinNbEventsText
.addFocusListener(listener
);
287 fTimeRangeStartText
.addFocusListener(listener
);
288 fTimeRangeEndText
.addFocusListener(listener
);
293 private static Font
adjustFont(final Composite composite
) {
294 // Reduce font size for a more pleasing rendering
295 final int fontSizeAdjustment
= -2;
296 final Font font
= composite
.getFont();
297 final FontData fontData
= font
.getFontData()[0];
298 return new Font(font
.getDevice(), fontData
.getName(), fontData
.getHeight() + fontSizeAdjustment
, fontData
.getStyle());
301 // ------------------------------------------------------------------------
303 // ------------------------------------------------------------------------
306 * Returns the start time (equal first bucket time)
307 * @return the start time.
309 public long getStartTime() {
310 return fDataModel
.getFirstBucketTime();
314 * Returns the end time.
315 * @return the end time.
317 public long getEndTime() {
318 return fDataModel
.getEndTime();
322 * Returns the time limit (end of last bucket)
323 * @return the time limit.
325 public long getTimeLimit() {
326 return fDataModel
.getTimeLimit();
330 * Returns a data model reference.
331 * @return data model.
333 public HistogramDataModel
getDataModel() {
338 * Returns the text control for the maximum of events in one bar
340 * @return the text control
343 public Text
getMaxNbEventsText() {
344 return fMaxNbEventsText
;
347 // ------------------------------------------------------------------------
349 // ------------------------------------------------------------------------
351 * Updates the time range.
352 * @param startTime A start time
353 * @param endTime A end time.
355 public abstract void updateTimeRange(long startTime
, long endTime
);
358 * Clear the histogram and reset the data
360 public void clear() {
362 synchronized (fDataModel
) {
368 * Increase the histogram bucket corresponding to [timestamp]
370 * @param eventCount The new event count
371 * @param timestamp The latest timestamp
373 public void countEvent(final long eventCount
, final long timestamp
) {
374 fDataModel
.countEvent(eventCount
, timestamp
);
378 * Sets the current event time and refresh the display
380 * @param timestamp The time of the current event
381 * @deprecated As of 2.1, use {@link #setSelection(long, long)}
384 public void setCurrentEvent(final long timestamp
) {
385 fSelectionBegin
= (timestamp
> 0) ? timestamp
: 0;
386 fSelectionEnd
= (timestamp
> 0) ? timestamp
: 0;
387 fDataModel
.setSelectionNotifyListeners(timestamp
, timestamp
);
391 * Sets the current selection time range and refresh the display
393 * @param beginTime The begin time of the current selection
394 * @param endTime The end time of the current selection
397 public void setSelection(final long beginTime
, final long endTime
) {
398 fSelectionBegin
= (beginTime
> 0) ? beginTime
: 0;
399 fSelectionEnd
= (endTime
> 0) ? endTime
: 0;
400 fDataModel
.setSelectionNotifyListeners(beginTime
, endTime
);
404 * Computes the timestamp of the bucket at [offset]
406 * @param offset offset from the left on the histogram
407 * @return the start timestamp of the corresponding bucket
409 public synchronized long getTimestamp(final int offset
) {
410 assert offset
> 0 && offset
< fScaledData
.fWidth
;
412 return fDataModel
.getFirstBucketTime() + fScaledData
.fBucketDuration
* offset
;
413 } catch (final Exception e
) {
414 return 0; // TODO: Fix that racing condition (NPE)
419 * Computes the offset of the timestamp in the histogram
421 * @param timestamp the timestamp
422 * @return the offset of the corresponding bucket (-1 if invalid)
424 public synchronized int getOffset(final long timestamp
) {
425 if (timestamp
< fDataModel
.getFirstBucketTime() || timestamp
> fDataModel
.getEndTime()) {
428 return (int) ((timestamp
- fDataModel
.getFirstBucketTime()) / fScaledData
.fBucketDuration
);
432 * Move the currently selected bar cursor to a non-empty bucket.
434 * @param keyCode the SWT key code
436 protected void moveCursor(final int keyCode
) {
443 while (index
< fScaledData
.fLastBucket
&& fScaledData
.fData
[index
] == 0) {
446 if (index
< fScaledData
.fLastBucket
) {
447 fScaledData
.fSelectionBeginBucket
= index
;
451 case SWT
.ARROW_RIGHT
:
452 index
= Math
.max(0, fScaledData
.fSelectionBeginBucket
+ 1);
453 while (index
< fScaledData
.fWidth
&& fScaledData
.fData
[index
] == 0) {
456 if (index
< fScaledData
.fLastBucket
) {
457 fScaledData
.fSelectionBeginBucket
= index
;
462 index
= fScaledData
.fLastBucket
;
463 while (index
>= 0 && fScaledData
.fData
[index
] == 0) {
467 fScaledData
.fSelectionBeginBucket
= index
;
472 index
= Math
.min(fScaledData
.fLastBucket
- 1, fScaledData
.fSelectionBeginBucket
- 1);
473 while (index
>= 0 && fScaledData
.fData
[index
] == 0) {
477 fScaledData
.fSelectionBeginBucket
= index
;
485 fScaledData
.fSelectionEndBucket
= fScaledData
.fSelectionBeginBucket
;
486 fSelectionBegin
= getTimestamp(fScaledData
.fSelectionBeginBucket
);
487 fSelectionEnd
= fSelectionBegin
;
488 updateSelectionTime();
492 * Refresh the histogram display
495 public void modelUpdated() {
496 if (!fCanvas
.isDisposed() && fCanvas
.getDisplay() != null) {
497 fCanvas
.getDisplay().asyncExec(new Runnable() {
500 if (!fCanvas
.isDisposed()) {
501 // Retrieve and normalize the data
502 final int canvasWidth
= fCanvas
.getBounds().width
;
503 final int canvasHeight
= fCanvas
.getBounds().height
;
504 if (canvasWidth
<= 0 || canvasHeight
<= 0) {
507 fDataModel
.setSelection(fSelectionBegin
, fSelectionEnd
);
508 fScaledData
= fDataModel
.scaleTo(canvasWidth
, canvasHeight
, 1);
509 synchronized (fDataModel
) {
510 if (fScaledData
!= null) {
512 if (fDataModel
.getNbEvents() != 0) {
513 // Display histogram and update X-,Y-axis
515 fTimeRangeStartText
.setText(TmfTimestampFormat
.getDefaulTimeFormat().format(fDataModel
.getFirstBucketTime()));
516 fTimeRangeEndText
.setText(TmfTimestampFormat
.getDefaulTimeFormat().format(fDataModel
.getEndTime()));
518 fTimeRangeStartText
.setText(""); //$NON-NLS-1$
519 fTimeRangeEndText
.setText(""); //$NON-NLS-1$
521 long maxNbEvents
= HistogramScaledData
.hideLostEvents ? fScaledData
.fMaxValue
: fScaledData
.fMaxCombinedValue
;
522 fMaxNbEventsText
.setText(Long
.toString(maxNbEvents
));
523 // The Y-axis area might need to be re-sized
524 fMaxNbEventsText
.getParent().layout();
534 * Add a mouse wheel listener to the histogram
535 * @param listener the mouse wheel listener
538 public void addMouseWheelListener(MouseWheelListener listener
) {
539 fCanvas
.addMouseWheelListener(listener
);
543 * Remove a mouse wheel listener from the histogram
544 * @param listener the mouse wheel listener
547 public void removeMouseWheelListener(MouseWheelListener listener
) {
548 fCanvas
.removeMouseWheelListener(listener
);
551 // ------------------------------------------------------------------------
553 // ------------------------------------------------------------------------
555 private void updateSelectionTime() {
556 ((HistogramView
) fParentView
).updateSelectionTime(fSelectionBegin
, fSelectionEnd
);
559 // ------------------------------------------------------------------------
561 // ------------------------------------------------------------------------
563 * Image key string for the canvas.
565 protected final String IMAGE_KEY
= "double-buffer-image"; //$NON-NLS-1$
568 public void paintControl(final PaintEvent event
) {
571 final int canvasWidth
= fCanvas
.getBounds().width
;
572 final int canvasHeight
= fCanvas
.getBounds().height
;
574 // Make sure we have something to draw upon
575 if (canvasWidth
<= 0 || canvasHeight
<= 0) {
579 // Retrieve image; re-create only if necessary
580 Image image
= (Image
) fCanvas
.getData(IMAGE_KEY
);
581 if (image
== null || image
.getBounds().width
!= canvasWidth
|| image
.getBounds().height
!= canvasHeight
) {
582 image
= new Image(event
.display
, canvasWidth
, canvasHeight
);
583 fCanvas
.setData(IMAGE_KEY
, image
);
586 // Draw the histogram on its canvas
587 final GC imageGC
= new GC(image
);
588 formatImage(imageGC
, image
);
589 event
.gc
.drawImage(image
, 0, 0);
593 private void formatImage(final GC imageGC
, final Image image
) {
595 if (fScaledData
== null) {
599 final HistogramScaledData scaledData
= new HistogramScaledData(fScaledData
);
602 // Get drawing boundaries
603 final int width
= image
.getBounds().width
;
604 final int height
= image
.getBounds().height
;
606 // Clear the drawing area
607 imageGC
.setBackground(fBackgroundColor
);
608 imageGC
.fillRectangle(0, 0, image
.getBounds().width
+ 1, image
.getBounds().height
+ 1);
610 // Draw the histogram bars
611 final int limit
= width
< scaledData
.fWidth ? width
: scaledData
.fWidth
;
612 double factor
= HistogramScaledData
.hideLostEvents ? scaledData
.fScalingFactor
: scaledData
.fScalingFactorCombined
;
613 for (int i
= 0; i
< limit
; i
++) {
614 imageGC
.setForeground(fHistoBarColor
);
615 final int value
= (int) Math
.ceil(scaledData
.fData
[i
] * factor
);
616 imageGC
.drawLine(i
, height
- value
, i
, height
);
618 if (!HistogramScaledData
.hideLostEvents
) {
619 imageGC
.setForeground(fLostEventColor
);
620 final int lostEventValue
= (int) Math
.ceil(scaledData
.fLostEventsData
[i
] * factor
);
621 if (lostEventValue
!= 0) {
622 if (lostEventValue
== 1) {
623 // in linux, a line from x to x is not drawn, in windows it is.
624 imageGC
.drawPoint(i
, height
- value
- 1);
626 // drawing a line is inclusive, so we need to remove 1 from the destination to have the correct length
627 imageGC
.drawLine(i
, height
- value
- lostEventValue
, i
, height
- value
- 1);
633 // Add a dashed line as a delimiter (at the right of the last bar)
634 int lastEventIndex
= limit
- 1;
635 while (lastEventIndex
>= 0 && scaledData
.fData
[lastEventIndex
] == 0) {
638 lastEventIndex
+= (lastEventIndex
< limit
- 1) ?
1 : 0;
639 drawDelimiter(imageGC
, fLastEventColor
, height
, lastEventIndex
);
641 // Draw the selection bars
642 int alpha
= imageGC
.getAlpha();
643 imageGC
.setAlpha(100);
644 imageGC
.setForeground(fSelectionForegroundColor
);
645 imageGC
.setBackground(fSelectionBackgroundColor
);
646 final int beginBucket
= scaledData
.fSelectionBeginBucket
;
647 if (beginBucket
>= 0 && beginBucket
< limit
) {
648 imageGC
.drawLine(beginBucket
, 0, beginBucket
, height
);
650 final int endBucket
= Math
.min(lastEventIndex
, scaledData
.fSelectionEndBucket
);
651 if (endBucket
>= 0 && endBucket
< limit
&& endBucket
!= beginBucket
) {
652 imageGC
.drawLine(endBucket
, 0, endBucket
, height
);
654 if (endBucket
- beginBucket
> 1) {
655 imageGC
.fillRectangle(beginBucket
+ 1, 0, endBucket
- beginBucket
- 1, height
);
657 imageGC
.setAlpha(alpha
);
658 } catch (final Exception e
) {
663 private static void drawDelimiter(final GC imageGC
, final Color color
,
664 final int height
, final int index
) {
665 imageGC
.setBackground(color
);
666 final int dash
= height
/ 4;
667 imageGC
.fillRectangle(index
, 0 * dash
, 1, dash
- 1);
668 imageGC
.fillRectangle(index
, 1 * dash
, 1, dash
- 1);
669 imageGC
.fillRectangle(index
, 2 * dash
, 1, dash
- 1);
670 imageGC
.fillRectangle(index
, 3 * dash
, 1, height
- 3 * dash
);
673 // ------------------------------------------------------------------------
675 // ------------------------------------------------------------------------
678 public void keyPressed(final KeyEvent event
) {
679 moveCursor(event
.keyCode
);
683 public void keyReleased(final KeyEvent event
) {
686 // ------------------------------------------------------------------------
688 // ------------------------------------------------------------------------
691 public void mouseDoubleClick(final MouseEvent event
) {
695 public void mouseDown(final MouseEvent event
) {
696 if (fDataModel
.getNbEvents() > 0 && fScaledData
.fLastBucket
>= event
.x
) {
697 if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == 0) {
698 fScaledData
.fSelectionBeginBucket
= event
.x
;
699 fScaledData
.fSelectionEndBucket
= event
.x
;
700 fSelectionBegin
= getTimestamp(event
.x
);
701 fSelectionEnd
= fSelectionBegin
;
702 } else if ((event
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
) {
703 if (fSelectionBegin
== fSelectionEnd
) {
704 if (event
.x
< fScaledData
.fSelectionBeginBucket
) {
705 fScaledData
.fSelectionBeginBucket
= event
.x
;
706 fSelectionBegin
= getTimestamp(event
.x
);
708 fScaledData
.fSelectionEndBucket
= event
.x
;
709 fSelectionEnd
= getTimestamp(event
.x
);
711 } else if (Math
.abs(event
.x
- fScaledData
.fSelectionBeginBucket
) <= Math
.abs(event
.x
- fScaledData
.fSelectionEndBucket
)) {
712 fScaledData
.fSelectionBeginBucket
= event
.x
;
713 fSelectionBegin
= getTimestamp(event
.x
);
715 fScaledData
.fSelectionEndBucket
= event
.x
;
716 fSelectionEnd
= getTimestamp(event
.x
);
719 updateSelectionTime();
724 public void mouseUp(final MouseEvent event
) {
727 // ------------------------------------------------------------------------
728 // MouseTrackListener
729 // ------------------------------------------------------------------------
732 public void mouseEnter(final MouseEvent event
) {
736 public void mouseExit(final MouseEvent event
) {
740 public void mouseHover(final MouseEvent event
) {
741 if (fDataModel
.getNbEvents() > 0 && fScaledData
!= null && fScaledData
.fLastBucket
>= event
.x
) {
742 final String tooltip
= formatToolTipLabel(event
.x
);
743 fCanvas
.setToolTipText(tooltip
);
745 fCanvas
.setToolTipText(null);
749 private String
formatToolTipLabel(final int index
) {
750 long startTime
= fScaledData
.getBucketStartTime(index
);
751 // negative values are possible if time values came into the model in decreasing order
755 final long endTime
= fScaledData
.getBucketEndTime(index
);
756 final int nbEvents
= (index
>= 0) ? fScaledData
.fData
[index
] : 0;
757 final String newLine
= System
.getProperty("line.separator"); //$NON-NLS-1$
758 final StringBuffer buffer
= new StringBuffer();
759 buffer
.append("Range = ["); //$NON-NLS-1$
760 buffer
.append(new TmfTimestamp(startTime
, ITmfTimestamp
.NANOSECOND_SCALE
).toString());
762 buffer
.append(new TmfTimestamp(endTime
, ITmfTimestamp
.NANOSECOND_SCALE
).toString());
764 buffer
.append(newLine
);
765 buffer
.append("Event count = "); //$NON-NLS-1$
766 buffer
.append(nbEvents
);
767 if (!HistogramScaledData
.hideLostEvents
) {
768 final int nbLostEvents
= (index
>= 0) ? fScaledData
.fLostEventsData
[index
] : 0;
769 buffer
.append(newLine
);
770 buffer
.append("Lost events count = "); //$NON-NLS-1$
771 buffer
.append(nbLostEvents
);
773 return buffer
.toString();
776 // ------------------------------------------------------------------------
778 // ------------------------------------------------------------------------
781 public void controlMoved(final ControlEvent event
) {
782 fDataModel
.complete();
786 public void controlResized(final ControlEvent event
) {
787 fDataModel
.complete();
790 // ------------------------------------------------------------------------
792 // ------------------------------------------------------------------------
795 * Format the timestamp and update the display
798 * the incoming signal
802 public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal
) {
803 if (fDataModel
.getNbEvents() == 0) {
807 String newTS
= TmfTimestampFormat
.getDefaulTimeFormat().format(fDataModel
.getFirstBucketTime());
808 fTimeRangeStartText
.setText(newTS
);
810 newTS
= TmfTimestampFormat
.getDefaulTimeFormat().format(fDataModel
.getEndTime());
811 fTimeRangeEndText
.setText(newTS
);