001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.gui.action;
020:
021: import java.awt.event.KeyEvent;
022:
023: import javax.swing.KeyStroke;
024:
025: /*
026: * Collect all the keystrokes together in one place.
027: * This helps to ensure that there are no duplicates.
028: */
029: public final class KeyStrokes {
030: // Prevent instantiation
031: private KeyStrokes() {
032: }
033:
034: public static final KeyStroke CUT = KeyStroke.getKeyStroke(
035: KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK);
036: public static final KeyStroke COPY = KeyStroke.getKeyStroke(
037: KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK);
038: public static final KeyStroke PASTE = KeyStroke.getKeyStroke(
039: KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK);
040: public static final KeyStroke REMOVE = KeyStroke.getKeyStroke(
041: KeyEvent.VK_DELETE, 0);
042: public static final KeyStroke SAVE_GRAPHICS = KeyStroke
043: .getKeyStroke(KeyEvent.VK_G, KeyEvent.CTRL_DOWN_MASK);
044: public static final KeyStroke SAVE_GRAPHICS_ALL = KeyStroke
045: .getKeyStroke(KeyEvent.VK_G, KeyEvent.CTRL_DOWN_MASK
046: | KeyEvent.SHIFT_DOWN_MASK);
047: public static final KeyStroke HELP = KeyStroke.getKeyStroke(
048: KeyEvent.VK_H, KeyEvent.CTRL_DOWN_MASK);
049: public static final KeyStroke WHAT_CLASS = KeyStroke.getKeyStroke(
050: KeyEvent.VK_W, KeyEvent.CTRL_DOWN_MASK);
051: public static final KeyStroke DEBUG_ON = KeyStroke.getKeyStroke(
052: KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK
053: | KeyEvent.SHIFT_DOWN_MASK);
054: public static final KeyStroke DEBUG_OFF = KeyStroke.getKeyStroke(
055: KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK);
056: public static final KeyStroke FUNCTIONS = KeyStroke.getKeyStroke(
057: KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK);
058: public static final KeyStroke SSL_MANAGER = KeyStroke.getKeyStroke(
059: KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK);
060: public static final KeyStroke ACTION_START = KeyStroke
061: .getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK);
062: public static final KeyStroke ACTION_STOP = KeyStroke.getKeyStroke(
063: KeyEvent.VK_PERIOD, KeyEvent.CTRL_DOWN_MASK);
064: public static final KeyStroke ACTION_SHUTDOWN = KeyStroke
065: .getKeyStroke(KeyEvent.VK_COMMA, KeyEvent.CTRL_DOWN_MASK);
066: public static final KeyStroke CLEAR = KeyStroke.getKeyStroke(
067: KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK
068: | KeyEvent.SHIFT_DOWN_MASK);
069: public static final KeyStroke CLEAR_ALL = KeyStroke.getKeyStroke(
070: KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK);
071: public static final KeyStroke REMOTE_START_ALL = KeyStroke
072: .getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK
073: | KeyEvent.SHIFT_DOWN_MASK);
074: public static final KeyStroke REMOTE_STOP_ALL = KeyStroke
075: .getKeyStroke(KeyEvent.VK_X, KeyEvent.ALT_DOWN_MASK);
076: public static final KeyStroke SAVE = KeyStroke.getKeyStroke(
077: KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK);
078: public static final KeyStroke SAVE_ALL_AS = KeyStroke.getKeyStroke(
079: KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK
080: | KeyEvent.SHIFT_DOWN_MASK);
081: public static final KeyStroke OPEN = KeyStroke.getKeyStroke(
082: KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK);
083: public static final KeyStroke CLOSE = KeyStroke.getKeyStroke(
084: KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK);
085: public static final KeyStroke EXIT = KeyStroke.getKeyStroke(
086: KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK);
087: public static final KeyStroke COLLAPSE_ALL = KeyStroke
088: .getKeyStroke(KeyEvent.VK_MINUS, KeyEvent.CTRL_DOWN_MASK);
089: // VK_PLUS + CTRL_DOWN_MASK did not work...
090: public static final KeyStroke EXPAND_ALL = KeyStroke.getKeyStroke(
091: KeyEvent.VK_MINUS, KeyEvent.CTRL_DOWN_MASK
092: | KeyEvent.SHIFT_DOWN_MASK);
093:
094: /**
095: * Check if an event matches the KeyStroke definition.
096: *
097: * @param e event
098: * @param k keystroke
099: * @return true if event matches the keystroke definition
100: */
101: public static boolean matches(KeyEvent e, KeyStroke k) {
102: final int modifiersEx = e.getModifiersEx() | e.getModifiers();// Hack to get full modifier value
103: return e.getKeyCode() == k.getKeyCode()
104: && modifiersEx == k.getModifiers();
105: }
106: }
|