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 private ParentHistogramCanvas parentCanvas
= null;
27 private boolean isShiftPressed
= false;
30 * HistogramCanvasKeyListener constructor
32 * @param newCanvas Related canvas
34 public HistogramCanvasKeyListener(ParentHistogramCanvas 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.
48 public void keyPressed(KeyEvent event
) {
49 switch (event
.keyCode
) {
51 isShiftPressed
= true;
54 moveWindowPosition(HistogramConstant
.BASIC_DISPLACEMENT_FACTOR
* -1);
57 moveWindowPosition(HistogramConstant
.BASIC_DISPLACEMENT_FACTOR
);
65 * Function that is called when a key is released.<p>
67 * - Shift : turn off "fast move" mode.
69 * @param event The KeyEvent generated when the key was pressed.
72 public void keyReleased(KeyEvent event
) {
73 switch (event
.keyCode
) {
75 isShiftPressed
= false;
83 * Function to move the window position of a given displacemnt.<p>
85 * @param displacementFactor The basic displacement to perform (positive or negative value)
87 public void moveWindowPosition(int displacementFactor
) {
89 // If we are in "fast move mode", multiply the basic displacement by a factor
90 if ( isShiftPressed
== true ) {
91 displacementFactor
= (int)((double)displacementFactor
* HistogramConstant
.FAST_DISPLACEMENT_MULTIPLE
);
94 parentCanvas
.moveWindow(displacementFactor
);