List of usage examples for javax.swing ActionMap put
public void put(Object key, Action action)
key
to action
. From source file:net.sf.jabref.EntryEditor.java
protected void setupSwingComponentKeyBindings(JComponent component) { // Set up key bindings and focus listener for the FieldEditor. InputMap im = component.getInputMap(JComponent.WHEN_FOCUSED); ActionMap am = component.getActionMap(); im.put(prefs.getKey("Entry editor, store field"), "store"); am.put("store", storeFieldAction); im.put(prefs.getKey("Entry editor, next panel"), "right"); im.put(prefs.getKey("Entry editor, next panel 2"), "right"); am.put("right", switchRightAction); im.put(prefs.getKey("Entry editor, previous panel"), "left"); im.put(prefs.getKey("Entry editor, previous panel 2"), "left"); am.put("left", switchLeftAction); im.put(prefs.getKey("Help"), "help"); am.put("help", helpAction); im.put(prefs.getKey("Save database"), "save"); am.put("save", saveDatabaseAction); im.put(Globals.prefs.getKey("Next tab"), "nexttab"); am.put("nexttab", frame.nextTab); im.put(Globals.prefs.getKey("Previous tab"), "prevtab"); am.put("prevtab", frame.prevTab); }
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
/** * @param map//from w w w . j a v a 2s .c o m * @param actions */ public static void addActionsToMap(ActionMap map, Action[] actions) { if ((map != null) && (actions != null)) { for (Action a : actions) { String cmd = (String) a.getValue(Action.ACTION_COMMAND_KEY); if (cmd == null) { cmd = (String) a.getValue(Action.NAME); } map.put(cmd, a); } } }
From source file:net.sf.jabref.EntryEditor.java
/** * Create toolbar for entry editor./* w w w . j a v a2s . c o m*/ */ private void setupToolBar() { JToolBar tlb = new JToolBar(JToolBar.VERTICAL); CloseAction closeAction = new CloseAction(); ; StoreFieldAction storeFieldAction = new StoreFieldAction(); DeleteAction deleteAction = new DeleteAction(); UndoAction undoAction = new UndoAction(); RedoAction redoAction = new RedoAction(); tlb.setBorder(null); tlb.setRollover(true); tlb.setMargin(new Insets(0, 0, 0, 2)); tlb.setFloatable(false); tlb.addSeparator(); tlb.add(deleteAction); tlb.addSeparator(); tlb.add(prevEntryAction); tlb.add(nextEntryAction); tlb.addSeparator(); tlb.add(helpAction); for (Component comp : tlb.getComponents()) { ((JComponent) comp).setOpaque(false); } // The toolbar carries all the key bindings that are valid for the whole window. ActionMap am = tlb.getActionMap(); InputMap im = tlb.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(prefs.getKey("Close entry editor"), "close"); am.put("close", closeAction); im.put(prefs.getKey("Entry editor, store field"), "store"); am.put("store", storeFieldAction); im.put(prefs.getKey("Entry editor, previous entry"), "prev"); am.put("prev", prevEntryAction); im.put(prefs.getKey("Entry editor, next entry"), "next"); am.put("next", nextEntryAction); im.put(prefs.getKey("Undo"), "undo"); am.put("undo", undoAction); im.put(prefs.getKey("Redo"), "redo"); am.put("redo", redoAction); im.put(prefs.getKey("Help"), "help"); am.put("help", helpAction); // Add actions (and thus buttons) JButton closeBut = new JButton(closeAction); closeBut.setText(null); closeBut.setBorder(null); // Create type-label TypeLabel typeLabel = new TypeLabel(entry.getType().getName()); JPanel leftPan = new JPanel(); leftPan.setLayout(new BorderLayout()); leftPan.add(closeBut, BorderLayout.NORTH); leftPan.add(typeLabel, BorderLayout.CENTER); leftPan.add(tlb, BorderLayout.SOUTH); add(leftPan, BorderLayout.WEST); }
From source file:br.com.atmatech.sac.view.ViewListaAtendimento.java
private void inicializaAtalhos() { KeyStroke keyStrokeJBnovo = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0); String actionNameJBnovo = "TECLA_F1"; InputMap inputMapJBnovo = jBnovo.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBnovo.put(keyStrokeJBnovo, actionNameJBnovo); ActionMap actionMapJBMARCA = jBnovo.getActionMap(); actionMapJBMARCA.put(actionNameJBnovo, acaojBnovo); //Atalho excluir KeyStroke keyStrokeJBexcluir = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0); String actionNameJBexcluir = "F4"; InputMap inputMapJBexcluir = jBexcluir.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBexcluir.put(keyStrokeJBexcluir, actionNameJBexcluir); ActionMap actionMapJBexcluir = jBexcluir.getActionMap(); actionMapJBexcluir.put(actionNameJBexcluir, acaoJBexcluir); //Atalho atualizar KeyStroke keyStrokeJBatualizar = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0); String actionNameJBatualizar = "F5"; InputMap inputMapJBatualizar = jBpesquisa.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBatualizar.put(keyStrokeJBatualizar, actionNameJBatualizar); ActionMap actionMapJBatualizar = jBpesquisa.getActionMap(); actionMapJBatualizar.put(actionNameJBatualizar, acaoJBpesquisa); //Atalho enter InputMap inputMapJBenter = this.jDconsulta.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBenter.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "forward"); this.jDconsulta.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMapJBenter); this.jDconsulta.getRootPane().getActionMap().put("forward", new AbstractAction() { private static final long serialVersionUID = 1L; @Override//from w ww. j a va2 s . com public void actionPerformed(ActionEvent e) { filtraChamado(); } }); }
From source file:com.googlecode.vfsjfilechooser2.plaf.basic.BasicVFSFileChooserUI.java
protected ActionMap createActionMap() { ActionMap map = new ActionMapUIResource(); Action refreshAction = new AbstractVFSUIAction(VFSFilePane.ACTION_REFRESH) { public void actionPerformed(ActionEvent evt) { getFileChooser().rescanCurrentDirectory(); }// www . ja v a2 s. c o m }; map.put(VFSFilePane.ACTION_APPROVE_SELECTION, getApproveSelectionAction()); map.put(VFSFilePane.ACTION_CANCEL, getCancelSelectionAction()); map.put(VFSFilePane.ACTION_REFRESH, refreshAction); map.put(VFSFilePane.ACTION_CHANGE_TO_PARENT_DIRECTORY, getChangeToParentDirectoryAction()); return map; }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java
/** * Replaces the Ctrl+Enter send command with simple Enter. * * @param isEnter indicates if the new send command is enter or cmd-enter *//*w w w .jav a 2 s. c o m*/ public void changeSendCommand(boolean isEnter) { ActionMap actionMap = editorPane.getActionMap(); actionMap.put("send", new SendMessageAction()); actionMap.put("newLine", new NewLineAction()); InputMap im = this.editorPane.getInputMap(); if (isEnter) { im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "send"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK), "newLine"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK), "newLine"); this.setToolTipText("<html>" + GuiActivator.getResources().getI18NString("service.gui.SEND_MESSAGE") + " - Enter <br> " + "Use Ctrl-Enter or Shift-Enter to make a new line" + "</html>"); } else { im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK), "send"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "newLine"); this.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.SEND_MESSAGE") + " Ctrl-Enter"); } }
From source file:net.sf.jabref.gui.entryeditor.EntryEditor.java
/** * NOTE: This method is only used for the source panel, not for the * other tabs. Look at EntryEditorTab for the setup of text components * in the other tabs.//from w w w . jav a2 s. c o m */ private void setupJTextComponent(JTextComponent textComponent) { // Set up key bindings and focus listener for the FieldEditor. InputMap inputMap = textComponent.getInputMap(JComponent.WHEN_FOCUSED); ActionMap actionMap = textComponent.getActionMap(); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store"); actionMap.put("store", getStoreFieldAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL), "right"); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL_2), "right"); actionMap.put("right", getSwitchRightAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL), "left"); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL_2), "left"); actionMap.put("left", getSwitchLeftAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); actionMap.put("help", getHelpAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE), "save"); actionMap.put("save", getSaveDatabaseAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB), "nexttab"); actionMap.put("nexttab", frame.nextTab); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB), "prevtab"); actionMap.put("prevtab", frame.prevTab); Set<AWTKeyStroke> keys = new HashSet<>( textComponent.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB")); textComponent.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); keys = new HashSet<>(textComponent.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(KeyStroke.getKeyStroke("shift pressed TAB")); textComponent.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys); textComponent.addFocusListener(new FieldListener()); }
From source file:net.sf.jabref.gui.entryeditor.EntryEditor.java
private void setupToolBar() { JPanel leftPan = new JPanel(); leftPan.setLayout(new BorderLayout()); JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL); toolBar.setBorder(null);//from w ww. j a va 2 s . c om toolBar.setRollover(true); toolBar.setMargin(new Insets(0, 0, 0, 2)); // The toolbar carries all the key bindings that are valid for the whole // window. ActionMap actionMap = toolBar.getActionMap(); InputMap inputMap = toolBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_ENTRY_EDITOR), "close"); actionMap.put("close", closeAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store"); actionMap.put("store", getStoreFieldAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), "generateKey"); actionMap.put("generateKey", getGenerateKeyAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOMATICALLY_LINK_FILES), "autoLink"); actionMap.put("autoLink", autoLinkAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_ENTRY), "prev"); actionMap.put("prev", getPrevEntryAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_ENTRY), "next"); actionMap.put("next", getNextEntryAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.UNDO), "undo"); actionMap.put("undo", undoAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.REDO), "redo"); actionMap.put("redo", redoAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); actionMap.put("help", getHelpAction()); toolBar.setFloatable(false); // Add actions (and thus buttons) JButton closeBut = new JButton(closeAction); closeBut.setText(null); closeBut.setBorder(null); closeBut.setMargin(new Insets(8, 0, 8, 0)); leftPan.add(closeBut, BorderLayout.NORTH); // Create type-label TypedBibEntry typedEntry = new TypedBibEntry(entry, Optional.empty(), panel.getBibDatabaseContext().getMode()); leftPan.add(new TypeLabel(typedEntry.getTypeForDisplay()), BorderLayout.CENTER); TypeButton typeButton = new TypeButton(); toolBar.add(typeButton); toolBar.add(getGenerateKeyAction()); toolBar.add(autoLinkAction); toolBar.add(writeXmp); toolBar.addSeparator(); toolBar.add(deleteAction); toolBar.add(getPrevEntryAction()); toolBar.add(getNextEntryAction()); toolBar.addSeparator(); toolBar.add(getHelpAction()); Component[] comps = toolBar.getComponents(); for (Component comp : comps) { ((JComponent) comp).setOpaque(false); } leftPan.add(toolBar, BorderLayout.SOUTH); add(leftPan, BorderLayout.WEST); }
From source file:net.sf.jabref.gui.ImportInspectionDialog.java
/** * Creates a dialog that displays the given list of fields in the table. The * dialog allows another process to add entries dynamically while the dialog * is shown./*from w w w. jav a 2s . co m*/ * * @param frame * @param panel */ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoName, boolean newDatabase) { this.frame = frame; this.panel = panel; this.bibDatabaseContext = (panel == null) ? null : panel.getBibDatabaseContext(); this.undoName = undoName; this.newDatabase = newDatabase; setIconImage(new ImageIcon(IconTheme.getIconUrl("jabrefIcon48")).getImage()); preview = new PreviewPanel(null, bibDatabaseContext, Globals.prefs.get(JabRefPreferences.PREVIEW_0)); duplLabel.setToolTipText(Localization.lang("Possible duplicate of existing entry. Click to resolve.")); sortedList = new SortedList<>(entries); DefaultEventTableModel<BibEntry> tableModelGl = (DefaultEventTableModel<BibEntry>) GlazedListsSwing .eventTableModelWithThreadProxyList(sortedList, new EntryTableFormat()); glTable = new EntryTable(tableModelGl); GeneralRenderer renderer = new GeneralRenderer(Color.white); glTable.setDefaultRenderer(JLabel.class, renderer); glTable.setDefaultRenderer(String.class, renderer); glTable.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.DELETE_ENTRY), "delete"); DeleteListener deleteListener = new DeleteListener(); glTable.getActionMap().put("delete", deleteListener); selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing .eventSelectionModelWithThreadProxyList(sortedList); glTable.setSelectionModel(selectionModel); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); comparatorChooser = TableComparatorChooser.install(glTable, sortedList, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); setupComparatorChooser(); glTable.addMouseListener(new TableClickListener()); setWidths(); getContentPane().setLayout(new BorderLayout()); progressBar.setIndeterminate(true); JPanel centerPan = new JPanel(); centerPan.setLayout(new BorderLayout()); contentPane.setTopComponent(new JScrollPane(glTable)); contentPane.setBottomComponent(preview); centerPan.add(contentPane, BorderLayout.CENTER); centerPan.add(progressBar, BorderLayout.SOUTH); popup.add(deleteListener); popup.addSeparator(); if (!newDatabase && (bibDatabaseContext != null)) { GroupTreeNode node = bibDatabaseContext.getMetaData().getGroups(); JMenu groupsAdd = new JMenu(Localization.lang("Add to group")); groupsAdd.setEnabled(false); // Will get enabled if there are groups that can be added to. insertNodes(groupsAdd, node); popup.add(groupsAdd); } // Add "Attach file" menu choices to right click menu: popup.add(new LinkLocalFile()); popup.add(new DownloadFile()); popup.add(new AutoSetLinks()); popup.add(new AttachUrl()); getContentPane().add(centerPan, BorderLayout.CENTER); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addButton(ok); bb.addButton(stop); JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addRelatedGap(); JButton help = new HelpAction(HelpFile.IMPORT_INSPECTION).getHelpButton(); bb.addButton(help); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); ButtonStackBuilder builder = new ButtonStackBuilder(); JButton selectAll = new JButton(Localization.lang("Select all")); builder.addButton(selectAll); JButton deselectAll = new JButton(Localization.lang("Deselect all")); builder.addButton(deselectAll); builder.addButton(deselectAllDuplicates); builder.addRelatedGap(); JButton delete = new JButton(Localization.lang("Delete")); builder.addButton(delete); builder.addRelatedGap(); builder.addFixed(autoGenerate); builder.addButton(generate); builder.getPanel().setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); centerPan.add(builder.getPanel(), BorderLayout.WEST); ok.setEnabled(false); generate.setEnabled(false); ok.addActionListener(new OkListener()); cancel.addActionListener(e -> { signalStopFetching(); dispose(); frame.output(Localization.lang("Import canceled by user")); }); generate.addActionListener(e -> { generate.setEnabled(false); generatedKeys = true; // To prevent the button from getting // enabled again. generateKeys(); // Generate the keys. }); stop.addActionListener(e -> { signalStopFetching(); entryListComplete(); }); selectAll.addActionListener(new SelectionButton(true)); deselectAll.addActionListener(new SelectionButton(false)); deselectAllDuplicates.addActionListener(e -> { for (int i = 0; i < glTable.getRowCount(); i++) { if (glTable.getValueAt(i, DUPL_COL) != null) { glTable.setValueAt(false, i, 0); } } glTable.repaint(); }); deselectAllDuplicates.setEnabled(false); delete.addActionListener(deleteListener); getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); // Remember and default to last size: setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH), Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT))); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { contentPane.setDividerLocation(0.5f); } @Override public void windowClosed(WindowEvent e) { Globals.prefs.putInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH, getSize().width); Globals.prefs.putInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT, getSize().height); } }); // Key bindings: Action closeAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }; ActionMap am = contentPane.getActionMap(); InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", closeAction); }
From source file:br.com.atmatech.sac.view.ViewPessoa.java
private void inicializaAtalhos() { //Atalho novo KeyStroke keyStrokeJBnovo = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0); String actionNameJBnovo = "F1"; InputMap inputMapJBnovo = jBnovo.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBnovo.put(keyStrokeJBnovo, actionNameJBnovo); ActionMap actionMapJBnovo = jBnovo.getActionMap(); actionMapJBnovo.put(actionNameJBnovo, acaoJBnovo); //Atalho alterar KeyStroke keyStrokeJBalterar = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0); String actionNameJBalterar = "F3"; InputMap inputMapJBalterar = jBalterar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBalterar.put(keyStrokeJBalterar, actionNameJBalterar); ActionMap actionMapJBalterar = jBalterar.getActionMap(); actionMapJBalterar.put(actionNameJBalterar, acaoJBalterar); //Atalho salvar KeyStroke keyStrokeJBsalvar = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0); String actionNameJBsalvar = "F2"; InputMap inputMapJBsalvar = jBsalvar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBsalvar.put(keyStrokeJBsalvar, actionNameJBsalvar); ActionMap actionMapJBsalvar = jBsalvar.getActionMap(); actionMapJBsalvar.put(actionNameJBsalvar, acaoJBsalvar); //Atalho excluir KeyStroke keyStrokeJBexcluir = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0); String actionNameJBexcluir = "F4"; InputMap inputMapJBexcluir = jBexcluir.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBexcluir.put(keyStrokeJBexcluir, actionNameJBexcluir); ActionMap actionMapJBexcluir = jBexcluir.getActionMap(); actionMapJBexcluir.put(actionNameJBexcluir, acaoJBexcluir); //Atalho cancelar // KeyStroke keyStrokeJBcancelar = KeyStroke.getKeyStroke(KeyEvent.VK_F5,0); // String actionNameJBcancelar = "F5"; // InputMap inputMapJBcancelar = jBcancelar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ///*from w w w . ja v a2 s . c o m*/ // inputMapJBcancelar.put(keyStrokeJBcancelar, actionNameJBcancelar); // ActionMap actionMapJBcancelar = jBcancelar.getActionMap(); // actionMapJBcancelar.put(actionMapJBcancelar, acaoJBcancelar); }