1 /*******************************************************************************
2 * Copyright (c) 2011 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 * 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
;
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
;
22 * <b><u>ZoomListener</u></b>
25 * Canvas zoom listener.
27 * @author Philippe Sawicki
29 public class ZoomListener
implements Listener
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
36 * A reference to the observed view.
38 protected AbstractViewer fView
;
40 * Default zoom factor.
42 protected int fZoomFactor
;
46 protected int fZoomIncrement
= 30;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
55 * A reference to the observed view.
56 * @param defaultZoomFactor
57 * Default zoom factor.
59 public ZoomListener(AbstractViewer view
, int defaultZoomFactor
) {
61 fZoomFactor
= defaultZoomFactor
;
67 * A reference to the observed view.
69 public ZoomListener(AbstractViewer view
) {
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * Returns the zoom factor.
79 * @return The zoom factor.
81 public int getZoomFactor() {
89 * Returns the zoom increment.
90 * @return The zoom increment.
92 public int getZoomIncrement() {
93 return fZoomIncrement
;
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
102 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
105 public void handleEvent(Event event
) {
106 switch (event
.type
) {
108 boolean scrollDown
= (event
.count
== 0 ?
false : (event
.count
> 0 ?
false : true));
109 int zoomStep
= fZoomIncrement
;
111 zoomStep
= -fZoomIncrement
;
112 fZoomFactor
= Math
.max(0, fZoomFactor
+ zoomStep
);
114 Canvas canvas
= (Canvas
) event
.widget
;
116 // clear the background to allow redraw of values of the vertical axis.
117 fView
.clearBackground();
119 fView
.askForRedraw();
127 * Sets the zoom increment.
128 * @param zoomIncrement
129 * The new zoom increment.
131 public void setZoomIncrement(int zoomIncrement
) {
132 fZoomIncrement
= zoomIncrement
;
This page took 0.038796 seconds and 5 git commands to generate.