List of usage examples for java.awt.event KeyEvent getKeyText
public static String getKeyText(int keyCode)
From source file:org.eclipse.jubula.client.ui.rcp.constants.InputCodeHelper.java
/** * private constructor/*from w ww. ja va 2 s .c o m*/ * */ private InputCodeHelper() { m_modifier[0] = InputEvent.CTRL_DOWN_MASK; m_modifier[1] = InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK; m_modifier[2] = InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK; m_modifier[3] = InputEvent.ALT_DOWN_MASK; m_modifier[4] = InputEvent.ALT_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK; m_modifier[5] = 0; // no modifier pressed List<UserInput> inputList = new ArrayList<UserInput>(); List<String> inputStringList = new ArrayList<String>(); for (int i = KeyEvent.VK_0; i <= KeyEvent.VK_9; i++) { inputList.add(new UserInput(i, InputConstants.TYPE_KEY_PRESS)); inputStringList.add(KeyEvent.getKeyText(i)); } for (int i = KeyEvent.VK_A; i <= KeyEvent.VK_Z; i++) { inputList.add(new UserInput(i, InputConstants.TYPE_KEY_PRESS)); inputStringList.add(KeyEvent.getKeyText(i)); } for (int i = KeyEvent.VK_NUMPAD0; i <= KeyEvent.VK_ADD; i++) { inputList.add(new UserInput(i, InputConstants.TYPE_KEY_PRESS)); inputStringList.add(KeyEvent.getKeyText(i)); } for (int i = KeyEvent.VK_SUBTRACT; i <= KeyEvent.VK_DIVIDE; i++) { inputList.add(new UserInput(i, InputConstants.TYPE_KEY_PRESS)); inputStringList.add(KeyEvent.getKeyText(i)); } for (int i = KeyEvent.VK_F1; i <= KeyEvent.VK_F12; i++) { inputList.add(new UserInput(i, InputConstants.TYPE_KEY_PRESS)); inputStringList.add(KeyEvent.getKeyText(i)); } m_modifierString = new String[m_modifier.length]; for (int i = 0; i < m_modifier.length; i++) { m_modifierString[i] = InputEvent.getModifiersExText(m_modifier[i]); } m_keys = inputList.toArray(new UserInput[inputList.size()]); m_keyStrings = inputStringList.toArray(new String[inputStringList.size()]); inputList.add(new UserInput(InputConstants.MOUSE_BUTTON_LEFT, InputConstants.TYPE_MOUSE_CLICK)); inputList.add(new UserInput(InputConstants.MOUSE_BUTTON_MIDDLE, InputConstants.TYPE_MOUSE_CLICK)); inputList.add(new UserInput(InputConstants.MOUSE_BUTTON_RIGHT, InputConstants.TYPE_MOUSE_CLICK)); inputStringList.add(Messages.ObjectMappingPreferencePageMouseButton1); inputStringList.add(Messages.ObjectMappingPreferencePageMouseButton2); inputStringList.add(Messages.ObjectMappingPreferencePageMouseButton3); m_inputs = inputList.toArray(new UserInput[inputList.size()]); m_inputStrings = inputStringList.toArray(new String[inputStringList.size()]); }
From source file:org.eclipse.jubula.rc.common.driver.KeyTyper.java
/** * Types the given keystroke./* w ww .j a va 2 s .c o m*/ * If any of the intercepting and event matching arguments are * <code>null</code>, this method will not wait for event confirmation. It * will simply assume that the events were received correctly. Otherwise, * this method will use the given interceptor and event matcher arguments to * handle event confirmation. * * @param keyStroke The key stroke. May not be null. * @param interceptor The interceptor that will be used to wait for event * confirmation. * @param keyDownMatcher The event matcher to be used for key press event * confirmation. * @param keyUpMatcher The event matcher to be used for key release event * confirmation. */ public void type(KeyStroke keyStroke, IRobotEventInterceptor interceptor, IEventMatcher keyDownMatcher, IEventMatcher keyUpMatcher) { try { Validate.notNull(keyStroke); boolean waitForConfirm = interceptor != null && keyDownMatcher != null && keyUpMatcher != null; InterceptorOptions options = new InterceptorOptions(new long[] { AWTEvent.KEY_EVENT_MASK }); List keycodes = modifierKeyCodes(keyStroke); keycodes.add(new Integer(keyStroke.getKeyCode())); if (log.isDebugEnabled()) { String keyModifierText = KeyEvent.getKeyModifiersText(keyStroke.getModifiers()); String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode()); log.debug("Key stroke: " + keyStroke); //$NON-NLS-1$ log.debug("Modifiers, Key: " + keyModifierText + ", " + keyText); //$NON-NLS-1$//$NON-NLS-2$ log.debug("number of keycodes: " + keycodes.size()); //$NON-NLS-1$ } m_robot.setAutoWaitForIdle(true); // FIXME Hack for MS Windows for keys that also appear on the numpad. // Turns NumLock off. Does nothing if locking key functionality // isn't implemented for the operating system. boolean isNumLockToggled = hackWindowsNumpadKeys1(keyStroke.getKeyCode()); // first press all keys, then release all keys, but // avoid to press and release any key twice (even if perhaps alt // and meta should have the same keycode(??) Set alreadyDown = new HashSet(); ListIterator i = keycodes.listIterator(); try { while (i.hasNext()) { Integer keycode = (Integer) i.next(); if (log.isDebugEnabled()) { log.debug("trying to press: " + keycode); //$NON-NLS-1$ } if (!alreadyDown.contains(keycode)) { IRobotEventConfirmer confirmer = null; if (waitForConfirm) { confirmer = interceptor.intercept(options); } if (log.isDebugEnabled()) { log.debug("pressing: " + keycode); //$NON-NLS-1$ } alreadyDown.add(keycode); m_robot.keyPress(keycode.intValue()); if (waitForConfirm) { confirmer.waitToConfirm(null, keyDownMatcher); } } } } finally { releaseKeys(options, alreadyDown, i, interceptor, keyUpMatcher); // FIXME Hack for MS Windows for keys that also appear on the numpad. // Turns NumLock back on, if necessary. if (isNumLockToggled) { hackWindowsNumpadKeys2(); } } } catch (IllegalArgumentException e) { throw new RobotException(e); } }
From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java
/** * creates CAP for KeyCominations like ENTER, BACKSPACE, SHIFT+TAB etc * @param id IComponentIdentifier/*from ww w.j a v a 2 s . co m*/ * @param ke KeyEvent * @param keycode int */ protected void keyComboApp(IComponentIdentifier id, KeyEvent ke, int keycode) { Action a = new Action(); a = m_recordHelper.compSysToAction(id, "CompSystem.KeyStroke"); //$NON-NLS-1$ List parameterValues = new LinkedList(); String modifierKey = null; if (ke.getModifiers() == 0) { modifierKey = "none"; //$NON-NLS-1$ } else { modifierKey = RecordHelper.getModifierName(ke.getModifiers()); if (modifierKey != null) { modifierKey = modifierKey.toLowerCase().replace('+', ' '); } } String baseKey = null; baseKey = RecordHelper.getKeyName(keycode); if (baseKey == null) { baseKey = KeyEvent.getKeyText(keycode).toUpperCase(); } if (baseKey != null && modifierKey != null) { parameterValues.add(modifierKey); parameterValues.add(baseKey); createCAP(a, id, parameterValues); } }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.ImportDialog.java
/** * Initializes the components composing the display. * /*from ww w. j ava 2s. c om*/ * @param filters The filters to handle. * @param importerAction The cancel-all-imports action. */ private void initComponents(FileFilter[] filters, ImporterAction importerAction) { canvas = new QuotaCanvas(); sizeImportLabel = new JLabel(); diskSpacePane = new JPanel(); diskSpacePane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); diskSpacePane.add(UIUtilities.setTextFont(TEXT_FREE_SPACE)); diskSpacePane.add(canvas); showThumbnails = new JCheckBox(TEXT_SHOW_THUMBNAILS); showThumbnails.setVisible(false); Registry registry = ImporterAgent.getRegistry(); Boolean loadThumbnails = (Boolean) registry.lookup(LOAD_THUMBNAIL); if (loadThumbnails != null) { if (loadThumbnails.booleanValue()) { showThumbnails.setVisible(true); showThumbnails.setSelected(loadThumbnails.booleanValue()); } } if (!isFastConnection()) // slow connection showThumbnails.setSelected(false); long groupId = -1; if (model.getSelectedGroup() != null) groupId = model.getSelectedGroup().getGroupId(); if (groupId < 0) groupId = ImporterAgent.getUserDetails().getGroupId(); locationDialog = new LocationDialog(owner, selectedContainer, type, objects, model, groupId, true); locationDialog.addPropertyChangeListener(this); int plugin = ImporterAgent.runAsPlugin(); if (plugin == LookupNames.IMAGE_J_IMPORT || plugin == LookupNames.IMAGE_J) { detachedDialog = new LocationDialog(owner, selectedContainer, type, objects, model, groupId, false); detachedDialog.addPropertyChangeListener(this); } tagSelectionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src instanceof JButton) { TagAnnotationData tag = tagsMap.get(src); if (tag != null) { tagsMap.remove(src); handleTagsSelection(tagsMap.values()); } } } }; tabbedPane = new JTabbedPane(); numberOfFolders = new NumericalTextField(); numberOfFolders.setMinimum(0); numberOfFolders.setText("0"); numberOfFolders.setColumns(3); numberOfFolders.addPropertyChangeListener(this); tagsMap = new LinkedHashMap<JButton, TagAnnotationData>(); IconManager icons = IconManager.getInstance(); refreshFilesButton = new JButton(TEXT_REFRESH_FILES); refreshFilesButton.setBackground(UIUtilities.BACKGROUND); refreshFilesButton.setToolTipText(TOOLTIP_REFRESH_FILES); refreshFilesButton.setActionCommand("" + CMD_REFRESH_FILES); refreshFilesButton.addActionListener(this); tagButton = new JButton(icons.getIcon(IconManager.PLUS_12)); UIUtilities.unifiedButtonLookAndFeel(tagButton); tagButton.addActionListener(this); tagButton.setActionCommand("" + CMD_TAG); tagButton.setToolTipText(TOOLTIP_ADD_TAGS); tagsPane = new JPanel(); tagsPane.setLayout(new BoxLayout(tagsPane, BoxLayout.Y_AXIS)); overrideName = new JCheckBox(TEXT_OVERRIDE_FILE_NAMING); overrideName.setToolTipText(UIUtilities.formatToolTipText(WARNING)); overrideName.setSelected(true); ButtonGroup group = new ButtonGroup(); fullName = new JRadioButton(TEXT_NAMING_FULL_PATH); group.add(fullName); partialName = new JRadioButton(); partialName.setText(TEXT_NAMING_PARTIAL_PATH); partialName.setSelected(true); group.add(partialName); table = new FileSelectionTable(this); table.addPropertyChangeListener(this); chooser = new GenericFileChooser(); JList list = (JList) UIUtilities.findComponent(chooser, JList.class); KeyAdapter ka = new KeyAdapter() { /** * Adds the files to the import queue. * * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { handleEnterKeyPressed(e.getSource()); } } }; if (list != null) list.addKeyListener(ka); if (list == null) { JTable t = (JTable) UIUtilities.findComponent(chooser, JTable.class); if (t != null) t.addKeyListener(ka); } try { File f = UIUtilities.getDefaultFolder(); if (f != null) chooser.setCurrentDirectory(f); } catch (Exception e) { // Ignore: could not set the default container } chooser.addPropertyChangeListener(this); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setControlButtonsAreShown(false); chooser.setApproveButtonText(TEXT_IMPORT); chooser.setApproveButtonToolTipText(TOOLTIP_IMPORT); bioFormatsFileFilters = new ArrayList<FileFilter>(); if (filters != null) { chooser.setAcceptAllFileFilterUsed(false); for (FileFilter fileFilter : filters) { if (fileFilter instanceof ComboFileFilter) { bioFormatsFileFiltersCombined = fileFilter; ComboFileFilter comboFilter = (ComboFileFilter) fileFilter; FileFilter[] extensionFilters = comboFilter.getFilters(); for (FileFilter combinedFilter : extensionFilters) { bioFormatsFileFilters.add(combinedFilter); } break; } } chooser.addChoosableFileFilter(bioFormatsFileFiltersCombined); for (FileFilter fileFilter : bioFormatsFileFilters) { chooser.addChoosableFileFilter(fileFilter); } chooser.setFileFilter(bioFormatsFileFiltersCombined); } else { chooser.setAcceptAllFileFilterUsed(true); } closeButton = new JButton(TEXT_CLOSE); closeButton.setToolTipText(TOOLTIP_CLOSE); closeButton.setActionCommand("" + CMD_CLOSE); closeButton.addActionListener(this); cancelImportButton = new JButton(importerAction); importerAction.setEnabled(false); importButton = new JButton(TEXT_IMPORT); importButton.setToolTipText(TOOLTIP_IMPORT); importButton.setActionCommand("" + CMD_IMPORT); importButton.addActionListener(this); importButton.setEnabled(false); pixelsSize = new ArrayList<NumericalTextField>(); NumericalTextField field; for (int i = 0; i < 3; i++) { field = new NumericalTextField(); field.setNumberType(Double.class); field.setColumns(2); pixelsSize.add(field); } List<Component> boxes = UIUtilities.findComponents(chooser, JComboBox.class); if (boxes != null) { JComboBox box; JComboBox filterBox = null; Iterator<Component> i = boxes.iterator(); while (i.hasNext()) { box = (JComboBox) i.next(); Object o = box.getItemAt(0); if (o instanceof FileFilter) { filterBox = box; break; } } if (filterBox != null) { filterBox.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { String value = KeyEvent.getKeyText(e.getKeyCode()); JComboBox box = (JComboBox) e.getSource(); int n = box.getItemCount(); FileFilter filter; FileFilter selectedFilter = null; String d; for (int j = 0; j < n; j++) { filter = (FileFilter) box.getItemAt(j); d = filter.getDescription(); if (d.startsWith(value)) { selectedFilter = filter; break; } } if (selectedFilter != null) box.setSelectedItem(selectedFilter); } }); } } }
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
/** * Press down a Key by Java Robot. Call {@link #keyRelease(int)} to release the key. * @param keycode int, keycode to press (e.g. <code>KeyEvent.VK_A</code>) * @throws SeleniumPlusException if fail * @see #keyRelease(int)//from w w w.ja v a 2 s. c om */ public static void keyPress(int keycode) throws SeleniumPlusException { try { RemoteDriver wd = null; try { wd = (RemoteDriver) getWebDriver(); } catch (Exception x) { } if (wd == null || wd.isLocalServer()) { if (!Robot.keyPress(keycode)) { throw new SeleniumPlusException("SAFS Robot Fail to press key " + KeyEvent.getKeyText(keycode)); } } else { //try RMI server. wd.rmiAgent.remoteKeyPress(keycode); } } catch (Exception e) { throw new SeleniumPlusException("Unable to successfully complete keyPress due to " + e.getMessage(), e); } }
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
/** * Release a Key by Java Robot. Release the key pressed by {@link #keyPress(int)}. * @param keycode int, keycode to release (e.g. <code>KeyEvent.VK_A</code>) * @throws SeleniumPlusException if fail * @see #keyPress(int)/*from ww w .ja va 2 s.c om*/ */ public static void keyRelease(int keycode) throws SeleniumPlusException { try { RemoteDriver wd = null; try { wd = (RemoteDriver) getWebDriver(); } catch (Exception x) { } if (wd == null || wd.isLocalServer()) { if (!Robot.keyRelease(keycode)) { throw new SeleniumPlusException( "SAFS Robot Fail to release key " + KeyEvent.getKeyText(keycode)); } } else { //try RMI server. wd.rmiAgent.remoteKeyRelease(keycode); } } catch (Exception e) { throw new SeleniumPlusException("Unable to successfully complete keyRelease due to " + e.getMessage(), e); } }
From source file:org.underworldlabs.swing.plaf.base.AcceleratorToolTipUI.java
private String getAcceleratorString(JToolTip tip) { String acceleratorString = null; Action action = ((AbstractButton) tip.getComponent()).getAction(); if (action != null) { KeyStroke keyStroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); if (keyStroke != null) { int mod = keyStroke.getModifiers(); acceleratorString = KeyEvent.getKeyModifiersText(mod); if (!MiscUtils.isNull(acceleratorString)) { acceleratorString += DELIMITER; }/* w w w . jav a2s . c om*/ String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode()); if (!MiscUtils.isNull(keyText)) { acceleratorString += keyText; } } } return acceleratorString; }