Commit | Line | Data |
---|---|---|
6e512b93 ASL |
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 | { | |
f05aabed FC |
26 | private ParentHistogramCanvas parentCanvas = null; |
27 | private boolean isShiftPressed = false; | |
6e512b93 ASL |
28 | |
29 | /** | |
30 | * HistogramCanvasKeyListener constructor | |
31 | * | |
32 | * @param newCanvas Related canvas | |
33 | */ | |
f05aabed | 34 | public HistogramCanvasKeyListener(ParentHistogramCanvas newCanvas) { |
6e512b93 ASL |
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 | */ | |
d4011df2 | 47 | @Override |
6e512b93 ASL |
48 | public void keyPressed(KeyEvent event) { |
49 | switch (event.keyCode) { | |
50 | case SWT.SHIFT: | |
51 | isShiftPressed = true; | |
52 | break; | |
53 | case SWT.ARROW_LEFT: | |
54 | moveWindowPosition(HistogramConstant.BASIC_DISPLACEMENT_FACTOR * -1); | |
55 | break; | |
56 | case SWT.ARROW_RIGHT: | |
57 | moveWindowPosition(HistogramConstant.BASIC_DISPLACEMENT_FACTOR); | |
58 | break; | |
59 | default: | |
60 | break; | |
61 | } | |
62 | } | |
63 | ||
64 | /** | |
65 | * Function that is called when a key is released.<p> | |
66 | * Possible actions : | |
67 | * - Shift : turn off "fast move" mode. | |
68 | * | |
69 | * @param event The KeyEvent generated when the key was pressed. | |
70 | */ | |
d4011df2 | 71 | @Override |
6e512b93 ASL |
72 | public void keyReleased(KeyEvent event) { |
73 | switch (event.keyCode) { | |
74 | case SWT.SHIFT: | |
75 | isShiftPressed = false; | |
76 | break; | |
77 | default: | |
78 | break; | |
79 | } | |
80 | } | |
81 | ||
82 | /** | |
83 | * Function to move the window position of a given displacemnt.<p> | |
84 | * | |
85 | * @param displacementFactor The basic displacement to perform (positive or negative value) | |
86 | */ | |
1406f802 | 87 | public void moveWindowPosition(int displacementFactor) { |
6e512b93 ASL |
88 | |
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); | |
92 | } | |
93 | ||
94 | parentCanvas.moveWindow(displacementFactor); | |
95 | } | |
96 | ||
97 | } |