tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / views / latency / listeners / ZoomListener.java
1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11 * Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code
12 *******************************************************************************/
13 package org.eclipse.linuxtools.internal.lttng.ui.views.latency.listeners;
14
15 import org.eclipse.linuxtools.internal.lttng.ui.views.latency.AbstractViewer;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.Canvas;
18 import org.eclipse.swt.widgets.Event;
19 import org.eclipse.swt.widgets.Listener;
20
21 /**
22 * <b><u>ZoomListener</u></b>
23 * <p>
24 *
25 * Canvas zoom listener.
26 *
27 * @author Philippe Sawicki
28 */
29 public class ZoomListener implements Listener {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35 /**
36 * A reference to the observed view.
37 */
38 protected AbstractViewer fView;
39 /**
40 * Default zoom factor.
41 */
42 protected int fZoomFactor;
43 /**
44 * Zoom increment.
45 */
46 protected int fZoomIncrement = 30;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51
52 /**
53 * Constructor.
54 * @param view
55 * A reference to the observed view.
56 * @param defaultZoomFactor
57 * Default zoom factor.
58 */
59 public ZoomListener(AbstractViewer view, int defaultZoomFactor) {
60 fView = view;
61 fZoomFactor = defaultZoomFactor;
62 }
63
64 /**
65 * Constructor.
66 * @param view
67 * A reference to the observed view.
68 */
69 public ZoomListener(AbstractViewer view) {
70 this(view, 1);
71 }
72
73 // ------------------------------------------------------------------------
74 // Accessors
75 // ------------------------------------------------------------------------
76
77 /**
78 * Returns the zoom factor.
79 * @return The zoom factor.
80 */
81 public int getZoomFactor() {
82 if (fZoomFactor < 1)
83 return 1;
84 else
85 return fZoomFactor;
86 }
87
88 /**
89 * Returns the zoom increment.
90 * @return The zoom increment.
91 */
92 public int getZoomIncrement() {
93 return fZoomIncrement;
94 }
95
96 // ------------------------------------------------------------------------
97 // Operations
98 // ------------------------------------------------------------------------
99
100 /*
101 * (non-Javadoc)
102 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
103 */
104 @Override
105 public void handleEvent(Event event) {
106 switch (event.type) {
107 case SWT.MouseWheel:
108 boolean scrollDown = (event.count == 0 ? false : (event.count > 0 ? false : true));
109 int zoomStep = fZoomIncrement;
110 if (scrollDown)
111 zoomStep = -fZoomIncrement;
112 fZoomFactor = Math.max(0, fZoomFactor + zoomStep);
113
114 Canvas canvas = (Canvas) event.widget;
115 if (fView != null) {
116 // clear the background to allow redraw of values of the vertical axis.
117 fView.clearBackground();
118 fView.redrawTitle();
119 fView.askForRedraw();
120 }
121 canvas.redraw();
122 break;
123 }
124 }
125
126 /**
127 * Sets the zoom increment.
128 * @param zoomIncrement
129 * The new zoom increment.
130 */
131 public void setZoomIncrement(int zoomIncrement) {
132 fZoomIncrement = zoomIncrement;
133 }
134 }
This page took 0.038796 seconds and 5 git commands to generate.