List of usage examples for javax.swing KeyStroke getKeyStroke
public static KeyStroke getKeyStroke(String s)
KeyStroke
. From source file:TextAreaDemo.java
public TextAreaDemo() { super("TextAreaDemo"); initComponents();/*from w w w . j av a2 s. c o m*/ textArea.getDocument().addDocumentListener(this); InputMap im = textArea.getInputMap(); ActionMap am = textArea.getActionMap(); im.put(KeyStroke.getKeyStroke("ENTER"), COMMIT_ACTION); am.put(COMMIT_ACTION, new CommitAction()); words = new ArrayList<String>(5); words.add("spark"); words.add("special"); words.add("spectacles"); words.add("spectacular"); words.add("swing"); }
From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeImpl.java
protected void initButtonsKeyBinding() { InputMap im = (InputMap) UIManager.get("Button.focusInputMap"); im.put(KeyStroke.getKeyStroke("ENTER"), "pressed"); im.put(KeyStroke.getKeyStroke("released ENTER"), "released"); }
From source file:org.jdal.swing.table.TablePanel.java
/** * Initialize TablePanel after property set. Usally called by container. *///ww w .j ava 2 s. c om public void init() { // Header this.add(createFilterBox(), BorderLayout.NORTH); this.add(createTableBox(), BorderLayout.CENTER); if (filterView != null) table.setFilter(filterView.getModel()); if (guiFactory != null) table.setGuiFactory(guiFactory); // Key Bindings getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F2"), "addAction"); getActionMap().put("addAction", new AddAction()); }
From source file:com.maddyhome.idea.vim.helper.StringHelper.java
@NotNull public static List<KeyStroke> stringToKeys(@NotNull String s) { final List<KeyStroke> res = new ArrayList<KeyStroke>(); for (int i = 0; i < s.length(); i++) { res.add(KeyStroke.getKeyStroke(s.charAt(i))); }/* w w w . j av a 2 s.co m*/ return res; }
From source file:TextFieldDemo.java
public TextFieldDemo() { initComponents();//w ww . j a va 2 s .c o m InputStream in = getClass().getResourceAsStream("content.txt"); try { textArea.read(new InputStreamReader(in), null); } catch (IOException e) { e.printStackTrace(); } hilit = new DefaultHighlighter(); painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR); textArea.setHighlighter(hilit); entryBg = entry.getBackground(); entry.getDocument().addDocumentListener(this); InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap am = entry.getActionMap(); im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION); am.put(CANCEL_ACTION, new CancelAction()); }
From source file:net.pandoragames.far.ui.swing.component.UndoHistoryPopupMenu.java
private void init(SwingConfig config, ComponentRepository componentRepository) { // COPY// w ww . j a v a 2s .c om JMenuItem copy = new JMenuItem(config.getLocalizer().localize("label.copy")); copy.setAccelerator(KeyStroke.getKeyStroke("control C")); copy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String selection = textComponent.getSelectedText(); if (selection != null) { StringSelection textTransfer = new StringSelection(selection); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(textTransfer, null); } } }); this.add(copy); // PASTE JMenuItem paste = new JMenuItem(config.getLocalizer().localize("label.paste")); paste.setAccelerator(KeyStroke.getKeyStroke("control V")); paste.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Transferable transfer = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); try { if (transfer != null && transfer.isDataFlavorSupported(DataFlavor.stringFlavor)) { String text = (String) transfer.getTransferData(DataFlavor.stringFlavor); String selected = textComponent.getSelectedText(); if (selected == null) { int insertAt = textComponent.getCaretPosition(); textComponent.getDocument().insertString(insertAt, text, null); } else { int start = textComponent.getSelectionStart(); int end = textComponent.getSelectionEnd(); textComponent.getDocument().remove(start, end - start); textComponent.getDocument().insertString(start, text, null); } } } catch (UnsupportedFlavorException e) { LogFactory.getLog(this.getClass()).error("UnsupportedFlavorException reading from clipboard", e); } catch (IOException iox) { LogFactory.getLog(this.getClass()).error("IOException reading from clipboard", iox); } catch (BadLocationException blx) { LogFactory.getLog(this.getClass()).error("BadLocationException reading from clipboard", blx); } } }); this.add(paste); // UNDO Action undoAction = textComponent.getActionMap().get(UndoHistory.ACTION_KEY_UNDO); if (undoAction != null) { undoAction.putValue(Action.NAME, config.getLocalizer().localize("label.undo")); this.add(undoAction); } // REDO Action redoAction = textComponent.getActionMap().get(UndoHistory.ACTION_KEY_REDO); if (redoAction != null) { redoAction.putValue(Action.NAME, config.getLocalizer().localize("label.redo")); this.add(redoAction); } // PREVIOUS Action prevAction = textComponent.getActionMap().get(UndoHistory.ACTION_KEY_PREVIOUS); if (prevAction != null) { prevAction.putValue(Action.NAME, config.getLocalizer().localize("label.previous")); this.add(prevAction); } // NEXT Action nextAction = textComponent.getActionMap().get(UndoHistory.ACTION_KEY_NEXT); if (nextAction != null) { nextAction.putValue(Action.NAME, config.getLocalizer().localize("label.next")); this.add(nextAction); } }
From source file:edu.ku.brc.af.ui.forms.validation.ValTextArea.java
public void init() { bgColor = getBackground();//from w w w .java2 s.com if (valTextColor == null || requiredFieldColor == null) { valTextColor = AppPrefsCache.getColorWrapper("ui", "formatting", "valtextcolor"); requiredFieldColor = AppPrefsCache.getColorWrapper("ui", "formatting", "requiredfieldcolor"); } AppPrefsCache.addChangeListener("ui.formatting.requiredfieldcolor", this); initDocument(); addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { isNew = false; repaint(); } }); // Enable being able to TAB out of TextArea getInputMap().put(KeyStroke.getKeyStroke("TAB"), "none"); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if (event.getKeyCode() == KeyEvent.VK_TAB) { if (event.isShiftDown()) { transferFocusBackward(); } else { transferFocus(); } } } }); }
From source file:com.quinsoft.zeidon.objectbrowser.EntitySquare.java
EntitySquare(OiDisplay display, BrowserEnvironment environment, EntityDefLayout layout) { super();/* w ww. j a v a 2s. c om*/ this.env = environment; oiDisplay = display; entityDefLayout = layout; size = new Dimension(SMALLEST_WIDTH * env.getPainterScaleFactor(), SMALLEST_HEIGHT * env.getPainterScaleFactor()); paddedSize = new Dimension((SMALLEST_WIDTH + HORIZONTAL_PAD * 2) * env.getPainterScaleFactor(), (SMALLEST_HEIGHT + VERTICAL_PAD * 2) * env.getPainterScaleFactor()); setSize(size); font = new Font(Font.SANS_SERIF, Font.PLAIN, env.getPainterScaleFactor()); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); addMouseListener(this); getInputMap().put(KeyStroke.getKeyStroke("HOME"), "setFirst"); getActionMap().put("setFirst", new SetCursorAction(CursorPosition.FIRST)); getInputMap().put(KeyStroke.getKeyStroke("PAGE_UP"), "setPrev"); getActionMap().put("setPrev", new SetCursorAction(CursorPosition.PREV)); getInputMap().put(KeyStroke.getKeyStroke("PAGE_DOWN"), "setNext"); getActionMap().put("setNext", new SetCursorAction(CursorPosition.NEXT)); getInputMap().put(KeyStroke.getKeyStroke("END"), "setLast"); getActionMap().put("setLast", new SetCursorAction(CursorPosition.LAST)); getInputMap().put(KeyStroke.getKeyStroke("UP"), "moveUp"); getActionMap().put("moveUp", new ChangeSelectedEntityDefAction(1)); getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "moveDown"); getActionMap().put("moveDown", new ChangeSelectedEntityDefAction(2)); getInputMap().put(KeyStroke.getKeyStroke("LEFT"), "moveLeft"); getActionMap().put("moveLeft", new ChangeSelectedEntityDefAction(3)); getInputMap().put(KeyStroke.getKeyStroke("RIGHT"), "moveRight"); getActionMap().put("moveRight", new ChangeSelectedEntityDefAction(4)); getInputMap().put(KeyStroke.getKeyStroke("ctrl DOWN"), "resetParent"); getActionMap().put("resetParent", new ChangeSelectedEntityDefAction(5)); getInputMap().put(KeyStroke.getKeyStroke("ctrl UP"), "setSubobject"); getActionMap().put("setSubobject", new ChangeSelectedEntityDefAction(6)); }
From source file:ja.centre.gui.resources.Resources.java
public KeyStroke stroke(String key) { String fullKey = key + SUFFIX_KEY; String value = getValue(fullKey); KeyStroke keyStroke = KeyStroke.getKeyStroke(value); if (keyStroke == null) { Arguments.doThrow("Incorrectly formatted key \"" + fullKey + "\": \"" + value + "\""); }//from w ww.j ava2s.co m return keyStroke; }
From source file:lisong_mechlab.view.graphs.DamageGraph.java
/** * Creates and displays the {@link DamageGraph}. * // w ww . j a v a2 s. c o m * @param aLoadout * Which load out the diagram is for. * @param anXbar * A {@link MessageXBar} to listen for changes to the loadout on. * @param aMaxSustainedDpsMetric * A {@link MaxSustainedDPS} instance to use in calculation. */ public DamageGraph(LoadoutBase<?> aLoadout, MessageXBar anXbar, MaxSustainedDPS aMaxSustainedDpsMetric) { super("Max Sustained DPS over range for " + aLoadout); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); anXbar.attach(this); loadout = aLoadout; maxSustainedDPS = aMaxSustainedDpsMetric; chartPanel = new ChartPanel(makechart()); setContentPane(chartPanel); chartPanel.getChart().getLegend().setHorizontalAlignment(HorizontalAlignment.RIGHT); chartPanel.getChart().getLegend().setVerticalAlignment(VerticalAlignment.TOP); LegendTitle legendTitle = chartPanel.getChart().getLegend(); XYTitleAnnotation titleAnnotation = new XYTitleAnnotation(0.98, 0.98, legendTitle, RectangleAnchor.TOP_RIGHT); titleAnnotation.setMaxWidth(0.4); ((XYPlot) (chartPanel.getChart().getPlot())).addAnnotation(titleAnnotation); chartPanel.getChart().removeLegend(); chartPanel.setLayout(new OverlayLayout(chartPanel)); JButton button = new JButton( new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w'))); button.setMargin(new Insets(10, 10, 10, 10)); button.setFocusable(false); button.setAlignmentX(Component.RIGHT_ALIGNMENT); button.setAlignmentY(Component.BOTTOM_ALIGNMENT); chartPanel.add(button); setIconImage(ProgramInit.programIcon); setSize(800, 600); setVisible(true); }