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
.SWT
;
15 import org
.eclipse
.swt
.events
.KeyEvent
;
16 import org
.eclipse
.swt
.events
.KeyListener
;
19 * <b><u>HistogramCanvasKeyListener</u></b>
21 * Implementation of a KeyListener for the need of the HistogramCanvas
24 public class HistogramCanvasKeyListener
implements KeyListener
26 protected HistogramCanvas parentCanvas
= null;
27 protected boolean isShiftPressed
= false;
30 * HistogramCanvasKeyListener constructor
32 * @param newCanvas Related canvas
34 public HistogramCanvasKeyListener(HistogramCanvas newCanvas
) {
35 parentCanvas
= newCanvas
;
39 * Function that is called when a key is pressed.<p>
41 * - Left arrow : move the selection window left.<p>
42 * - Right arrow : move the selection window right.<p>
43 * - Shift : turn on "fast move" mode.<p>
45 * @param event The KeyEvent generated when the key was pressed.
47 public void keyPressed(KeyEvent event
) {
48 switch (event
.keyCode
) {
50 isShiftPressed
= true;
53 moveWindowPosition(HistogramConstant
.BASIC_DISPLACEMENT_FACTOR
* -1);
56 moveWindowPosition(HistogramConstant
.BASIC_DISPLACEMENT_FACTOR
);
64 * Function that is called when a key is released.<p>
66 * - Shift : turn off "fast move" mode.
68 * @param event The KeyEvent generated when the key was pressed.
70 public void keyReleased(KeyEvent event
) {
71 switch (event
.keyCode
) {
73 isShiftPressed
= false;
81 * Function to move the window position of a given displacemnt.<p>
83 * @param displacementFactor The basic displacement to perform (positive or negative value)
85 public void moveWindowPosition(int displacementFactor
) {
87 // If we are in "fast move mode", multiply the basic displacement by a factor
88 if ( isShiftPressed
== true ) {
89 displacementFactor
= (int)((double)displacementFactor
* HistogramConstant
.FAST_DISPLACEMENT_MULTIPLE
);
92 parentCanvas
.moveWindow(displacementFactor
);