(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / histogram / HistogramCanvasKeyListener.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * William Bourque - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.views.histogram;
13
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.KeyEvent;
16 import org.eclipse.swt.events.KeyListener;
17
18 /**
19 * <b><u>HistogramCanvasKeyListener</u></b>
20 * <p>
21 * Implementation of a KeyListener for the need of the HistogramCanvas
22 * <p>
23 */
24 public class HistogramCanvasKeyListener implements KeyListener
25 {
26 protected HistogramCanvas parentCanvas = null;
27 protected boolean isShiftPressed = false;
28
29 /**
30 * HistogramCanvasKeyListener constructor
31 *
32 * @param newCanvas Related canvas
33 */
34 public HistogramCanvasKeyListener(HistogramCanvas newCanvas) {
35 parentCanvas = newCanvas;
36 }
37
38 /**
39 * Function that is called when a key is pressed.<p>
40 * Possible actions :
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>
44 *
45 * @param event The KeyEvent generated when the key was pressed.
46 */
47 public void keyPressed(KeyEvent event) {
48 switch (event.keyCode) {
49 case SWT.SHIFT:
50 isShiftPressed = true;
51 break;
52 case SWT.ARROW_LEFT:
53 moveWindowPosition(HistogramConstant.BASIC_DISPLACEMENT_FACTOR * -1);
54 break;
55 case SWT.ARROW_RIGHT:
56 moveWindowPosition(HistogramConstant.BASIC_DISPLACEMENT_FACTOR);
57 break;
58 default:
59 break;
60 }
61 }
62
63 /**
64 * Function that is called when a key is released.<p>
65 * Possible actions :
66 * - Shift : turn off "fast move" mode.
67 *
68 * @param event The KeyEvent generated when the key was pressed.
69 */
70 public void keyReleased(KeyEvent event) {
71 switch (event.keyCode) {
72 case SWT.SHIFT:
73 isShiftPressed = false;
74 break;
75 default:
76 break;
77 }
78 }
79
80 /**
81 * Function to move the window position of a given displacemnt.<p>
82 *
83 * @param displacementFactor The basic displacement to perform (positive or negative value)
84 */
85 public void moveWindowPosition(int displacementFactor) {
86
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);
90 }
91
92 parentCanvas.moveWindow(displacementFactor);
93 }
94
95 }
This page took 0.043935 seconds and 5 git commands to generate.