List of usage examples for java.awt.event KeyEvent KEY_PRESSED
int KEY_PRESSED
To view the source code for java.awt.event KeyEvent KEY_PRESSED.
Click Source Link
From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java
/** * {@inheritDoc}/*from www .j a v a 2 s . c o m*/ */ public void keyStroke(String keyStrokeSpec) throws RobotException { try { KeyTyper.getInstance().type(keyStrokeSpec, m_interceptor, new DefaultAwtEventMatcher(KeyEvent.KEY_PRESSED), new KeyReleasedEventMatcher()); } catch (AWTException e) { throw new RobotException(e); } }
From source file:org.executequery.gui.editor.QueryEditorTextPane.java
/** * Overrides <code>processKeyEvent</code> to additional process events. *///from w w w . jav a 2 s . c o m protected void processKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { int keyCode = e.getKeyCode(); // add the processing for SHIFT-TAB if (e.isShiftDown() && keyCode == KeyEvent.VK_TAB) { // int currentPosition = getCurrentPosition(); int selectionStart = getSelectionStart(); int selectionEnd = getSelectionEnd(); if (selectionStart == selectionEnd) { int start = getCurrentRowStart(); int end = getCurrentRowEnd(); shiftTextLeft(start, end); /* int newPosition = currentPosition - QueryEditorSettings.getTabSize(); int currentRowPosition = getCurrentRowStart(); if (!isAtStartOfRow()) { if (newPosition < 0) { setCaretPosition(0); } else if (newPosition < currentRowPosition) { setCaretPosition(currentRowPosition); } else { setCaretPosition(newPosition); } } */ } else { document.shiftTabEvent(selectionStart, selectionEnd); } } else if (keyCode == KeyEvent.VK_INSERT && e.getModifiers() == 0) { // toggle insert mode on the document int insertMode = document.getInsertMode(); if (insertMode == SqlMessages.INSERT_MODE) { document.setInsertMode(SqlMessages.OVERWRITE_MODE); editorPanel.getStatusBar().setInsertionMode("OVR"); } else { document.setInsertMode(SqlMessages.INSERT_MODE); editorPanel.getStatusBar().setInsertionMode("INS"); } ((EditorCaret) getCaret()).modeChanged(); } else if (keyCode == KeyEvent.VK_SPACE) { checkForShortcutText(); } } super.processKeyEvent(e); updateLineBorder(); }
From source file:org.nuclos.client.ui.collect.SubForm.java
/** * create an Tablecelleditor for the given component * @param clctcomp/*ww w. j ava 2 s.c om*/ * @return the newly created table cell editor */ private CollectableComponentTableCellEditor createTableCellEditor(final CollectableComponent clctcomp) { if (getColumn(clctcomp.getFieldName()) != null) { final Map<String, Object> properties = getColumn(clctcomp.getFieldName()).getProperties(); for (String property : properties.keySet()) { clctcomp.setProperty(property, properties.get(property)); } } final CollectableComponentTableCellEditor result = new CollectableComponentTableCellEditor(clctcomp, clctcomp.isSearchComponent()); result.addCollectableComponentModelListener(getCollectableTableCellEditorChangeListener()); // @see NUCLOS-603. checkboxes and options should setvalue directly. if (clctcomp instanceof CollectableCheckBox) { ((CollectableCheckBox) clctcomp).getJCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { SwingUtilities.invokeLater(new Runnable() { //@see NUCLOSINT-1635 public void run() { try { if (getSubformTable().getModel() instanceof SubFormTableModel) { int row = getSubformTable().getSelectedRow(); int column = ((SubFormTableModel) getSubformTable().getModel()) .findColumnByFieldName(clctcomp.getFieldName()); if (row != -1 && column != -1) { if (getSubformTable().getModel() instanceof SearchConditionTableModel) getSubformTable().setValueAt(clctcomp.getSearchCondition(), row, column); else getSubformTable().setValueAt(clctcomp.getField(), row, column); } } } catch (CollectableFieldFormatException e1) { LOG.warn("could not set value for " + clctcomp.getFieldName(), e1); } } }); } }); } if (clctcomp instanceof CollectableOptionGroup) { ((CollectableOptionGroup) clctcomp).getOptionGroup().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { if (getSubformTable().getModel() instanceof SubFormTableModel) { int row = getSubformTable().getSelectedRow(); int column = ((SubFormTableModel) getSubformTable().getModel()) .findColumnByFieldName(clctcomp.getFieldName()); if (row != -1 && column != -1) getSubformTable().setValueAt(clctcomp.getField(), row, column); } } catch (CollectableFieldFormatException e1) { LOG.warn("could not set value for " + clctcomp.getFieldName(), e1); } } }); } // textarea have to handle Tab in an subform differently. if (clctcomp instanceof NuclosCollectableTextArea) { ((NuclosCollectableTextArea) clctcomp).overrideActionMap(new AbstractAction() { @Override public void actionPerformed(ActionEvent evt) { Component c = (Component) ((NuclosCollectableTextArea) clctcomp).getJTextArea().getParent(); c.dispatchEvent( new KeyEvent(c, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, KeyEvent.VK_TAB)); } }, new AbstractAction() { @Override public void actionPerformed(ActionEvent evt) { Component c = (Component) ((NuclosCollectableTextArea) clctcomp).getJTextArea().getParent(); c.dispatchEvent(new KeyEvent(c, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.SHIFT_MASK, KeyEvent.VK_TAB)); } }); } if (clctcomp instanceof DynamicRowHeightChangeProvider) { ((DynamicRowHeightChangeProvider) clctcomp).addDynamicRowHeightChangeListener(this); } return result; }
From source file:org.sikuli.ide.SikuliIDE.java
private void initShortcutKeys() { final int scMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { private boolean isKeyNextTab(java.awt.event.KeyEvent ke) { if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_TAB && ke.getModifiers() == InputEvent.CTRL_MASK) { return true; }/* w w w. j a v a 2 s . c om*/ if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_CLOSE_BRACKET && ke.getModifiers() == (InputEvent.META_MASK | InputEvent.SHIFT_MASK)) { return true; } return false; } private boolean isKeyPrevTab(java.awt.event.KeyEvent ke) { if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_TAB && ke.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)) { return true; } if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_OPEN_BRACKET && ke.getModifiers() == (InputEvent.META_MASK | InputEvent.SHIFT_MASK)) { return true; } return false; } public void eventDispatched(AWTEvent e) { java.awt.event.KeyEvent ke = (java.awt.event.KeyEvent) e; //Debug.log(ke.toString()); if (ke.getID() == java.awt.event.KeyEvent.KEY_PRESSED) { if (isKeyNextTab(ke)) { nextTab(); } else if (isKeyPrevTab(ke)) { prevTab(); } } } }, AWTEvent.KEY_EVENT_MASK); }
From source file:org.wings.plaf.css.FrameCG.java
private void appendStrokes(StringBuilder builder, SComponent component, int condition, InputMap inputMap) { KeyStroke[] keyStrokes = inputMap.keys(); if (keyStrokes != null) { for (int i = 0; i < keyStrokes.length; i++) { KeyStroke keyStroke = keyStrokes[i]; Object binding = inputMap.get(keyStroke); switch (keyStroke.getKeyEventType()) { case KeyEvent.KEY_PRESSED: builder.append("kss.push(new ks('"); builder.append(component.getName()); builder.append("',"); builder.append(/*from w w w . j ava 2 s . c om*/ condition == SComponent.WHEN_FOCUSED_OR_ANCESTOR_OF_FOCUSED_COMPONENT ? "!0" : "!1"); builder.append(",'"); builder.append(binding); builder.append("',"); builder.append(keyStroke.getKeyCode()); builder.append(','); builder.append((keyStroke.getModifiers() & InputEvent.SHIFT_DOWN_MASK) != 0 ? "!0" : "!1"); builder.append(','); builder.append((keyStroke.getModifiers() & InputEvent.CTRL_DOWN_MASK) != 0 ? "!0" : "!1"); builder.append(','); builder.append((keyStroke.getModifiers() & InputEvent.ALT_DOWN_MASK) != 0 ? "!0" : "!1"); builder.append("));\n"); break; case KeyEvent.KEY_TYPED: break; case KeyEvent.KEY_RELEASED: break; } } } }
From source file:org.wings.plaf.css.InputMapScriptListener.java
public static void install(SComponent component) { ScriptListener[] scriptListeners = component.getScriptListeners(); for (int i = 0; i < scriptListeners.length; i++) { ScriptListener scriptListener = scriptListeners[i]; if (scriptListener instanceof InputMapScriptListener) component.removeScriptListener(scriptListener); }/*w w w.j a va2 s .c o m*/ InputMap inputMap = component.getInputMap(); if (inputMap.size() == 0) return; // we're done StringBuffer pressed = new StringBuffer(); StringBuffer typed = new StringBuffer(); StringBuffer released = new StringBuffer(); KeyStroke[] keyStrokes = inputMap.keys(); for (int i = 0; i < keyStrokes.length; i++) { KeyStroke keyStroke = keyStrokes[i]; Object binding = inputMap.get(keyStroke); /* writeMatch(typed, keyStroke); writeRequest(typed, binding); */ switch (keyStroke.getKeyEventType()) { case KeyEvent.KEY_PRESSED: writeMatch(pressed, keyStroke); writeRequest(pressed, binding); break; case KeyEvent.KEY_TYPED: writeMatch(typed, keyStroke); writeRequest(typed, binding); log.debug("typed binding = " + binding); break; case KeyEvent.KEY_RELEASED: writeMatch(released, keyStroke); writeRequest(released, binding); log.debug("released binding = " + binding); break; } } if (pressed.length() > 0) component.addScriptListener( new InputMapScriptListener("onkeydown", "return pressed_" + component.getName() + "(event)", "function pressed_" + component.getName() + "(event) {\n " + "event = getEvent(event);\n " + pressed.toString() + " return true;\n}\n")); if (typed.length() > 0) component.addScriptListener( new InputMapScriptListener("onkeypress", "return typed_" + component.getName() + "(event)", "function typed_" + component.getName() + "(event) {\n " + "event = getEvent(event);\n " + typed.toString() + " return true;\n}\n")); if (released.length() > 0) component.addScriptListener( new InputMapScriptListener("onkeyup", "return released_" + component.getName() + "(event)", "function released_" + component.getName() + "(event) {\n" + "event = getEvent(event);\n " + released.toString() + " return true;\n}\n")); }
From source file:org.wings.plaf.css.InputMapScriptListener.java
public static void installToFrame(SFrame frame, SComponent component) { InputMap inputMap = component.getInputMap(SComponent.WHEN_IN_FOCUSED_FRAME); StringBuffer pressed = new StringBuffer(); StringBuffer typed = new StringBuffer(); StringBuffer released = new StringBuffer(); KeyStroke[] keyStrokes = inputMap.keys(); for (int i = 0; i < keyStrokes.length; i++) { KeyStroke keyStroke = keyStrokes[i]; Object binding = inputMap.get(keyStroke); /*//from w ww . ja v a2s . c om writeMatch(typed, keyStroke); writeRequest(typed, binding); */ switch (keyStroke.getKeyEventType()) { case KeyEvent.KEY_PRESSED: writeMatch(pressed, keyStroke); writeRequestForFrame(pressed, binding, component.getName()); break; case KeyEvent.KEY_TYPED: writeMatch(typed, keyStroke); writeRequestForFrame(typed, binding, component.getName()); log.debug("typed binding = " + binding); break; case KeyEvent.KEY_RELEASED: writeMatch(released, keyStroke); writeRequestForFrame(released, binding, component.getName()); log.debug("released binding = " + binding); break; } } if (pressed.length() > 0) frame.addScriptListener( new InputMapScriptListener("onkeydown", "pressed_frame_" + component.getName() + "(event)", "function pressed_frame_" + component.getName() + "(event) {\n " + "event = getEvent(event);\n " + pressed.toString() + " return true;\n}\n")); if (typed.length() > 0) frame.addScriptListener( new InputMapScriptListener("onkeypress", "typed_frame_" + component.getName() + "(event)", "function typed_frame_" + component.getName() + "(event) {\n " + "event = getEvent(event);\n " + typed.toString() + " return true;\n}\n")); if (released.length() > 0) frame.addScriptListener( new InputMapScriptListener("onkeyup", "released_frame_" + component.getName() + "(event)", "function released_frame_" + component.getName() + "(event) {\n" + "event = getEvent(event);\n " + released.toString() + " return true;\n}\n")); }
From source file:ru.goodfil.catalog.ui.forms.FiltersPanel.java
private void globalHotkeys() { class FiltersPanelGlobalHotkey extends EventQueue { protected void dispatchEvent(AWTEvent event) { if (event instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent) event; if (keyEvent.getKeyCode() == KeyEvent.VK_F1 && keyEvent.getID() == KeyEvent.KEY_PRESSED) { } else { super.dispatchEvent(event); }//from ww w . j a va2 s. com } else { super.dispatchEvent(event); } } } EventQueue ev = Toolkit.getDefaultToolkit().getSystemEventQueue(); ev.push(new FiltersPanelGlobalHotkey()); }
From source file:thesaurusEditor.gui.graph.MainGraph.java
public void keyEventHappened(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { graphMouse.getModeKeyListener().keyPressed(e); }//from ww w. java 2s . c o m if (e.getID() == KeyEvent.KEY_RELEASED) { graphMouse.getModeKeyListener().keyReleased(e); ; } }
From source file:view.MainWindow.java
@Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { if (e.isControlDown()) { if (e.getKeyCode() == KeyEvent.VK_W) { closeDocument(true);// w w w .j a va 2s . com } else if (e.getKeyCode() == KeyEvent.VK_ADD) { workspacePanel.zoomIn(); } else if (e.getKeyCode() == KeyEvent.VK_SUBTRACT) { workspacePanel.zoomOut(); } else if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_RIGHT) { workspacePanel.pageUp(); } else if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_LEFT) { workspacePanel.pageDown(); } if (e.isShiftDown()) { if (e.getKeyCode() == KeyEvent.VK_S) { workspacePanel.changeCard(WorkspacePanel.CardEnum.SIGN_PANEL, true); } else if (e.getKeyCode() == KeyEvent.VK_V) { workspacePanel.changeCard(WorkspacePanel.CardEnum.VALIDATE_PANEL, true); } } } } else if (e.getID() == KeyEvent.KEY_RELEASED) { } else if (e.getID() == KeyEvent.KEY_TYPED) { } return false; }