1 /*******************************************************************************
2 * Copyright (c) 2009 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 * William Bourque - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.histogram
;
14 import org
.eclipse
.swt
.events
.FocusEvent
;
15 import org
.eclipse
.swt
.events
.FocusListener
;
16 import org
.eclipse
.swt
.widgets
.Canvas
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Display
;
20 public class TraceCanvas
extends Canvas
implements FocusListener
22 protected static Long MINIMUM_WINDOW_SIZE
= 1L;
23 protected static Double ZOOM_FACTOR
= 0.1;
25 protected asyncCanvasRedrawer canvasRedrawer
= null;
27 protected HistogramContent histogramContent
= null;
28 protected TraceCanvasPaintListener paintListener
= null;
29 protected TraceCanvasMouseListener mouseListener
= null;
30 protected TraceCanvasKeyListener keyListener
= null;
32 protected Integer columnWidth
= 0;
33 protected Integer columnMaxHeight
= 0;
35 protected HistogramSelectedWindow currentWindow
= null;
37 public TraceCanvas(Composite parent
, int style
, int widthPerColumn
, int columnHeight
) {
38 super (parent
, style
);
40 columnWidth
= widthPerColumn
;
41 columnMaxHeight
= columnHeight
;
46 public void addNeededListeners() {
47 canvasRedrawer
= new asyncCanvasRedrawer(this);
49 paintListener
= new TraceCanvasPaintListener(getHistogramContent(), getColumnWidth(), getColumnMaxHeight() );
50 mouseListener
= new TraceCanvasMouseListener(this);
51 keyListener
= new TraceCanvasKeyListener(this);
53 this.addPaintListener( paintListener
);
54 this.addMouseListener(mouseListener
);
55 this.addMouseMoveListener(mouseListener
);
56 this.addMouseWheelListener(mouseListener
);
57 this.addKeyListener(keyListener
);
58 this.addFocusListener(this);
61 public void createNewHistogramContent(long windowSize
, double maxBarsDifferenceToAverage
) {
62 histogramContent
= new HistogramContent( getSize().x
/ columnWidth
, getSize().x
, columnMaxHeight
, maxBarsDifferenceToAverage
);
65 // paintlistener need to know about the new content...
66 // This is nowhere near elegant, change me.
67 paintListener
.setHistogramContent(histogramContent
);
69 // New selected window, not visible by default
70 createNewSelectedWindow(windowSize
);
74 public HistogramSelectedWindow
createNewSelectedWindow(Long windowTimeDuration
) {
75 HistogramSelectedWindow returnedWindow
= new HistogramSelectedWindow(histogramContent
);
76 setCurrentWindow( returnedWindow
);
78 currentWindow
.setWindowTimeWidth(windowTimeDuration
);
79 currentWindow
.setWindowCenterXPosition(0);
81 return returnedWindow
;
84 public Long
getSelectedWindowSize() {
85 return currentWindow
.getWindowTimeWidth();
88 public void setSelectedWindowSize(Long newSelectedWindowSize
) {
90 if ( newSelectedWindowSize
< MINIMUM_WINDOW_SIZE
) {
91 newSelectedWindowSize
= MINIMUM_WINDOW_SIZE
;
93 else if ( newSelectedWindowSize
> histogramContent
.getFullTraceInterval() ) {
94 newSelectedWindowSize
= histogramContent
.getFullTraceInterval();
97 currentWindow
.setWindowTimeWidth(newSelectedWindowSize
);
100 public HistogramSelectedWindow
getCurrentWindow() {
101 return currentWindow
;
104 public void setCurrentWindow(HistogramSelectedWindow newCurrentWindow
) {
105 this.currentWindow
= newCurrentWindow
;
106 paintListener
.setSelectedWindow(newCurrentWindow
);
109 public void slideWindow(int newRelativeXPosition
) {
110 // Nothing : function is a place holder
113 public void positionWindow(int newAbsoluteXPosition
) {
114 // Nothing : function is a place holder
117 public void resizeWindowByFactor(int newFactor
) {
118 // Nothing : function is a place holder
121 public boolean checkIfTimeWindowChanged(int newPosition
) {
122 // Nothing : function is a place holder
126 public void notifyTimeWindowChanged() {
127 // Nothing : function is a place holder
130 public void updateParentInformation() {
131 // Nothing : function is a place holder
134 public void redrawAsynchronously() {
136 if ( canvasRedrawer
== null ) {
137 canvasRedrawer
= new asyncCanvasRedrawer(this);
140 canvasRedrawer
.asynchronousRedraw();
144 public HistogramContent
getHistogramContent() {
145 return histogramContent
;
148 public int getColumnWidth() {
152 public int getColumnMaxHeight() {
153 return columnMaxHeight
;
156 public void focusGained(FocusEvent e
) {
157 System
.out
.println("focusGained");
160 public void focusLost(FocusEvent e
) {
161 System
.out
.println("focusLost");
165 class asyncCanvasRedrawer
{
167 private TraceCanvas parentCanvas
= null;
169 public asyncCanvasRedrawer(TraceCanvas newCanvas
) {
170 parentCanvas
= newCanvas
;
173 public void asynchronousRedraw() {
174 Display display
= parentCanvas
.getDisplay();
175 display
.asyncExec(new Runnable() {
177 parentCanvas
.updateParentInformation();
178 parentCanvas
.redraw();