List of usage examples for javax.swing InputMap get
public Object get(KeyStroke keyStroke)
From source file:org.executequery.gui.editor.autocomplete.QueryEditorAutoCompletePopupProvider.java
private void saveExistingActions(InputMap inputMap) { if (!editorActionsSaved) { existingKeyStrokeDownAction = inputMap.get(KEY_STROKE_DOWN); existingKeyStrokeUpAction = inputMap.get(KEY_STROKE_UP); existingKeyStrokePageDownAction = inputMap.get(KEY_STROKE_PAGE_DOWN); existingKeyStrokePageUpAction = inputMap.get(KEY_STROKE_PAGE_UP); existingKeyStrokeEnterAction = inputMap.get(KEY_STROKE_ENTER); existingKeyStrokeTabAction = inputMap.get(KEY_STROKE_TAB); editorActionsSaved = true;/* ww w . j a v a2 s .c o m*/ } }
From source file:org.isatools.isacreator.gui.formelements.SubForm.java
protected void setupTableTabBehaviour() { InputMap im = scrollTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); // Override the default tab behaviour // Tab to the next editable cell. When no editable cells goto next cell. final Action previousTabAction = scrollTable.getActionMap().get(im.get(tab)); Action newTabAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { int rowSel = scrollTable.getSelectedRow(); int colSel = scrollTable.getSelectedColumn(); if (rowSel == (scrollTable.getRowCount() - 1)) { scrollTable.setRowSelectionInterval(0, 0); if ((colSel + 1) == scrollTable.getColumnCount()) { scrollTable.setColumnSelectionInterval(0, 0); } else { scrollTable.setColumnSelectionInterval(colSel + 1, colSel + 1); }/*from w w w . j a va 2 s . c om*/ } else { rowSel = rowSel + 1; scrollTable.setRowSelectionInterval(rowSel, rowSel); if (colSel > -1) { scrollTable.setColumnSelectionInterval(colSel, colSel); } } scrollTable.scrollRectToVisible(scrollTable.getCellRect(rowSel, colSel, true)); JTable table = (JTable) e.getSource(); int row = table.getSelectedRow(); int originalRow = row; int column = table.getSelectedColumn(); int originalColumn = column; while (!table.isCellEditable(row, column)) { previousTabAction.actionPerformed(e); row = table.getSelectedRow(); column = table.getSelectedColumn(); // Back to where we started, get out. if ((row == originalRow) && (column == originalColumn)) { break; } } if (table.editCellAt(row, column)) { table.getEditorComponent().requestFocusInWindow(); } } }; scrollTable.getActionMap().put(im.get(tab), newTabAction); }
From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java
/** * Setup the JTable with its desired characteristics */// w ww . jav a 2 s .co m private void setupTable() { table = new CustomTable(spreadsheetModel); table.setShowGrid(true); table.setGridColor(Color.BLACK); table.setShowVerticalLines(true); table.setShowHorizontalLines(true); table.setGridColor(UIHelper.LIGHT_GREEN_COLOR); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(true); table.setAutoCreateColumnsFromModel(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getSelectionModel().addListSelectionListener(this); table.getColumnModel().getSelectionModel().addListSelectionListener(this); table.getTableHeader().setReorderingAllowed(true); table.getColumnModel().addColumnModelListener(this); try { table.setDefaultRenderer(Class.forName("java.lang.Object"), new SpreadsheetCellRenderer()); } catch (ClassNotFoundException e) { // ignore this error } table.addMouseListener(this); table.getTableHeader().addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent event) { } public void mouseMoved(MouseEvent event) { // display a tooltip when user hovers over a column. tooltip is derived // from the description of a field from the TableReferenceObject. JTable table = ((JTableHeader) event.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int colIndex = colModel.getColumnIndexAtX(event.getX()); // greater than 1 to account for the row no. being the first col if (colIndex >= 1) { TableColumn tc = colModel.getColumn(colIndex); if (tc != null) { try { table.getTableHeader().setToolTipText(getFieldDescription(tc)); } catch (Exception e) { // ignore this error } } } } }); //table.getColumnModel().addColumnModelListener(this); InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); // Override the default tab behaviour // Tab to the next editable cell. When no editable cells goto next cell. final Action previousTabAction = table.getActionMap().get(im.get(tab)); Action newTabAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { // maintain previous tab action procedure previousTabAction.actionPerformed(e); JTable table = (JTable) e.getSource(); int row = table.getSelectedRow(); int originalRow = row; int column = table.getSelectedColumn(); int originalColumn = column; while (!table.isCellEditable(row, column)) { previousTabAction.actionPerformed(e); row = table.getSelectedRow(); column = table.getSelectedColumn(); // Back to where we started, get out. if ((row == originalRow) && (column == originalColumn)) { break; } } if (table.editCellAt(row, column)) { table.getEditorComponent().requestFocusInWindow(); } } }; table.getActionMap().put(im.get(tab), newTabAction); TableColumnModel model = table.getColumnModel(); String previousColumnName = null; for (int columnIndex = 0; columnIndex < tableReferenceObject.getHeaders().size(); columnIndex++) { if (!model.getColumn(columnIndex).getHeaderValue().toString() .equals(TableReferenceObject.ROW_NO_TEXT)) { model.getColumn(columnIndex).setHeaderRenderer(columnRenderer); model.getColumn(columnIndex).setPreferredWidth(spreadsheetFunctions .calcColWidths(model.getColumn(columnIndex).getHeaderValue().toString())); // add appropriate cell editor for cell. spreadsheetFunctions.addCellEditor(model.getColumn(columnIndex), previousColumnName); previousColumnName = model.getColumn(columnIndex).getHeaderValue().toString(); } else { model.getColumn(columnIndex).setHeaderRenderer(new RowNumberCellRenderer()); } } JTableHeader header = table.getTableHeader(); header.setBackground(UIHelper.BG_COLOR); header.addMouseListener(new HeaderListener(header, columnRenderer)); table.addNotify(); }
From source file:org.lisapark.octopus.swing.BaseFormattedTextField.java
/** * Invoked to process the key bindings for <code>ks</code> as the result * of the <code>KeyEvent</code> <code>e</code>. We override this method to make * sure that the text field has the proper action for when the user presses * the enter key// w w w .ja v a2s . com * * @param ks the <code>KeyStroke</code> queried * @param e the <code>KeyEvent</code> * @param condition one of the following values: * <ul> * <li>JComponent.WHEN_FOCUSED * <li>JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT * <li>JComponent.WHEN_IN_FOCUSED_WINDOW * </ul> * @param pressed true if the key is pressed * @return true if there was a binding to an action, and the action * was enabled */ protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { // we need to override this method to allow for handling of the delete key properly if (e.getKeyCode() == KeyEvent.VK_ENTER) { InputMap map = getInputMap(condition); ActionMap am = getActionMap(); if (map != null && am != null && isEnabled()) { Object binding = map.get(ks); Action action; // replace the nofify action if necessary if (binding != null && binding.equals(JTextField.notifyAction)) { action = am.get(binding); if (action != commitOnEnterAction) { am.put(JTextField.notifyAction, commitOnEnterAction); } } } } return super.processKeyBinding(ks, e, condition, pressed); }
From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java
/** * Test of bindKeyStrokes method, of class PropertiesShortcuts. */// www .j a v a 2s . c om @Test public void testBindKeyStrokes_InputMap_ObjectArr() { // bind InputMap inputMap = new InputMap(); shotcuts.bindKeyStrokes(inputMap, TEST_SAVE, TEST_CUT, TEST_USER_1); // test map size long expSize = 3; long size = inputMap.size(); assertEquals(expSize, size); // test keys KeyStroke[] expResults = new KeyStroke[] { CTRL_S, CTRL_X, CTRL_P }; KeyStroke[] results = inputMap.keys(); assertArrayEquals(expResults, results); // test entry1 exists Object expResult = TEST_SAVE; Object result = inputMap.get(CTRL_S); assertEquals(expResult, result); // test entry2 exists expResult = TEST_CUT; result = inputMap.get(CTRL_X); assertEquals(expResult, result); // test entry3 exists expResult = TEST_USER_1; result = inputMap.get(CTRL_P); assertEquals(expResult, result); // test remove entry with null shortcut inputMap.put(CTRL_D, TEST_DELETE); // put target expResult = TEST_DELETE; result = inputMap.get(CTRL_D); assertEquals(expResult, result); // target exists before remove shotcuts.bindKeyStrokes(inputMap, TEST_DELETE); // key to be removed as null result = inputMap.get(CTRL_D); assertNull(result); // target will be null after removed // test map size again expSize = 3; size = inputMap.size(); assertEquals(expSize, size); // ensure no affect for entry1 after removing expResult = TEST_SAVE; result = inputMap.get(CTRL_S); assertEquals(expResult, result); // ensure no affect for entry2 after removing expResult = TEST_CUT; result = inputMap.get(CTRL_X); assertEquals(expResult, result); // ensure no affect for entry3 after removing expResult = TEST_USER_1; result = inputMap.get(CTRL_P); assertEquals(expResult, result); }
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(// w w w .ja v a2s . co m 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); }//from w w w . j a v a2s . c om 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); /*// w w w .ja va 2 s . com 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")); }