List of usage examples for javax.swing InputMap put
public void put(KeyStroke keyStroke, Object actionMapKey)
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 www . j a v a 2 s . co m*/ public void actionPerformed(ActionEvent e) { filtraChamado(); } }); }
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 *///from w ww . j av a 2 s . com 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
private void setupToolBar() { JPanel leftPan = new JPanel(); leftPan.setLayout(new BorderLayout()); JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL); toolBar.setBorder(null);/*from w w w . jav a2 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.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./*w ww .j a va2s.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.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./*w w w . ja va 2s . c om*/ * * @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:edmondskarp.Gui.EdmondsKarpGui.java
private void setupUndoHotkeys() { String UNDO = "Undo action key"; String REDO = "Redo action key"; Action undoAction = new AbstractAction() { @Override//from w w w . j ava 2 s.co m public void actionPerformed(ActionEvent e) { controller.restoreState(true); } }; Action redoAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { controller.restoreState(false); } }; myPanel.getActionMap().put(UNDO, undoAction); myPanel.getActionMap().put(REDO, redoAction); InputMap[] inputMaps = new InputMap[] { myPanel.getInputMap(JComponent.WHEN_FOCUSED), myPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT), myPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), }; for (InputMap i : inputMaps) { i.put(KeyStroke.getKeyStroke("control Z"), UNDO); i.put(KeyStroke.getKeyStroke("control Y"), REDO); i.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), UNDO); } }
From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java
private void addKeyEventListener() { // add key listener for press alt key event InputMap inputMap = chartPaneltest.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke metaPressedStroke = KeyStroke.getKeyStroke("alt ALT"); Action metaPressedAction = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { if (!isPressingAlt) { isPressingAlt = true;//w w w . j a v a 2 s.c om chartPaneltest.setIsPressingAlt(true); //System.out.println("key Event EMDemo set " + isPressingAlt); } } }; inputMap.put(metaPressedStroke, "alt ALT"); chartPaneltest.getActionMap().put("alt ALT", metaPressedAction); //System.out.println("binding EMDemo alt ALT key Event"); KeyStroke metaReleasedStroke = KeyStroke.getKeyStroke("released ALT"); Action metaReleasedAction = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { //System.out.println("reseting " + isPressingAlt); if (isPressingAlt) { isPressingAlt = false; chartPaneltest.setIsPressingAlt(false); // System.out.println("key Event EMDemo reset " + isPressingAlt); } } }; inputMap.put(metaReleasedStroke, "released ALT"); chartPaneltest.getActionMap().put("released ALT", metaReleasedAction); //System.out.println("binding EMDemo released ALT key Event"); }
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); //// www .j a v a2 s. co m // inputMapJBcancelar.put(keyStrokeJBcancelar, actionNameJBcancelar); // ActionMap actionMapJBcancelar = jBcancelar.getActionMap(); // actionMapJBcancelar.put(actionMapJBcancelar, acaoJBcancelar); }
From source file:es.darkhogg.hazelnutt.EditorFrame.java
private void initializeGui() { setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setBounds(100, 100, 640, 480);// ww w.j av a2 s . co m addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { actionExit(); } }); fileChooser = new JFileChooser(); //fileChooser.setFileFilter( hlfFileFilter ); hlfFileChooser = new JFileChooser(); hlfFileChooser.setFileFilter(hlfFileFilter); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); mnFile.setMnemonic('F'); menuBar.add(mnFile); menuLoadRom = new JMenuItem("Load ROM..."); menuLoadRom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); menuLoadRom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionOpenRom(null); } }); menuLoadRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_open.png"))); menuLoadRom.setMnemonic('O'); mnFile.add(menuLoadRom); menuSaveRom = new JMenuItem("Save ROM"); menuSaveRom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveRom(); } }); menuSaveRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save.png"))); menuSaveRom.setMnemonic('S'); menuSaveRom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); mnFile.add(menuSaveRom); menuSaveRomAs = new JMenuItem("Save ROM As..."); menuSaveRomAs.setMnemonic('a'); menuSaveRomAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK)); menuSaveRomAs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveRomAs(); } }); menuSaveRomAs .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_as.png"))); mnFile.add(menuSaveRomAs); mnFile.addSeparator(); menuLoadLevel = new JMenuItem("Load Level..."); menuLoadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); menuLoadLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionLoadLevel(); } }); menuLoadLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_load_level.png"))); menuLoadLevel.setMnemonic('L'); mnFile.add(menuLoadLevel); menuReloadLevel = new JMenuItem("Reload Level"); menuReloadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0)); menuReloadLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionReloadLevel(); } }); menuReloadLevel.setMnemonic('R'); menuReloadLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_reload_level.png"))); mnFile.add(menuReloadLevel); menuSaveLevel = new JMenuItem("Save Level"); menuSaveLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0)); menuSaveLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveLevel(); } }); menuSaveLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_level.png"))); menuSaveLevel.setMnemonic('v'); mnFile.add(menuSaveLevel); //* mnFile.addSeparator(); menuImportLevel = new JMenuItem("Import Level..."); menuImportLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)); menuImportLevel.setMnemonic('i'); menuImportLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionImportLevel(); } }); menuImportLevel .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_import.png"))); mnFile.add(menuImportLevel); menuExportLevel = new JMenuItem("Export Level..."); menuExportLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); menuExportLevel.setMnemonic('e'); menuExportLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionExportLevel(); } }); menuExportLevel .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_export.png"))); mnFile.add(menuExportLevel); //*/ mnFile.addSeparator(); menuExit = new JMenuItem("Exit"); menuExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); menuExit.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_exit.png"))); menuExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { actionExit(); } }); menuRecentFiles = new JMenu("Recent Files..."); mnFile.add(menuRecentFiles); mnFile.addSeparator(); menuExit.setMnemonic('X'); mnFile.add(menuExit); JMenu mnEdit = new JMenu("Edit"); mnEdit.setMnemonic('E'); menuBar.add(mnEdit); menuViewSpawn = new JCheckBoxMenuItem("View Spawn Point"); menuViewSpawn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, 0)); menuViewSpawn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuClearLevel = new JMenuItem("Clear Level"); menuClearLevel.setMnemonic('c'); menuClearLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); menuClearLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionClearLevel(); } }); menuClearLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_clear_level.png"))); mnEdit.add(menuClearLevel); mnEdit.addSeparator(); menuViewSpawn .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_spawn.png"))); menuViewSpawn.setMnemonic('S'); menuViewSpawn.setSelected(true); mnEdit.add(menuViewSpawn); menuViewItems = new JCheckBoxMenuItem("View Items"); menuViewItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, 0)); menuViewItems.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuViewItems.setSelected(true); menuViewItems .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_items.png"))); menuViewItems.setMnemonic('I'); mnEdit.add(menuViewItems); menuViewDoorItems = new JCheckBoxMenuItem("View Door Items"); menuViewDoorItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, 0)); menuViewDoorItems.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuViewDoorItems.setSelected(true); menuViewDoorItems.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_door_items.png"))); menuViewDoorItems.setMnemonic('D'); mnEdit.add(menuViewDoorItems); menuViewEnemies = new JCheckBoxMenuItem("View Enemies"); menuViewEnemies.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, 0)); menuViewEnemies.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuViewEnemies.setSelected(true); menuViewEnemies .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_enemies.png"))); menuViewEnemies.setMnemonic('E'); mnEdit.add(menuViewEnemies); menuViewTypes = new JCheckBoxMenuItem("View Combo Types"); menuViewTypes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, 0)); menuViewTypes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuViewTypes.setSelected(true); menuViewTypes.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_combo_infos.png"))); menuViewTypes.setMnemonic('C'); mnEdit.add(menuViewTypes); mnEdit.addSeparator(); scaleMenuItem = new JCheckBoxMenuItem("Scale Level Display"); scaleMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_6, 0)); scaleMenuItem.setMnemonic('l'); scaleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionScale(false); } }); scaleMenuItem.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_x2.png"))); mnEdit.add(scaleMenuItem); gridMenuItem = new JCheckBoxMenuItem("Display grid"); gridMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_7, 0)); gridMenuItem.setMnemonic('G'); gridMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionGrid(false); } }); gridMenuItem.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_grid.png"))); mnEdit.add(gridMenuItem); //mnEdit.addSeparator(); mntmPreferences = new JMenuItem("Preferences..."); mntmPreferences.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionPreferences(); } }); mntmPreferences.setMnemonic('P'); mntmPreferences.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_preferences.png"))); //mnEdit.add(mntmPreferences); mnHelp = new JMenu("Help"); mnHelp.setMnemonic('H'); menuBar.add(mnHelp); mntmCheckUpdates = new JMenuItem("Check for Updates..."); mntmCheckUpdates.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK)); mntmCheckUpdates.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionCheckUpdates(); } }); mntmCheckUpdates.setMnemonic('c'); mntmCheckUpdates .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_update.png"))); mnHelp.add(mntmCheckUpdates); mntmAbout = new JMenuItem("Readme..."); mntmAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); mntmAbout.setMnemonic('r'); mntmAbout.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/about.png"))); mntmAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionAbout(); } }); mnHelp.addSeparator(); mnHelp.add(mntmAbout); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JToolBar toolBar = new JToolBar(); toolBar.setRollover(true); toolBar.setFloatable(false); contentPane.add(toolBar, BorderLayout.NORTH); barLoadRom = new JButton(""); barLoadRom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionOpenRom(null); } }); barLoadRom.setToolTipText("Open"); barLoadRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_open.png"))); toolBar.add(barLoadRom); barSaveRom = new JButton(""); barSaveRom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveRom(); } }); barSaveRom.setToolTipText("Save"); barSaveRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save.png"))); toolBar.add(barSaveRom); toolBar.addSeparator(); barImportLevel = new JButton(""); barImportLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionImportLevel(); } }); barImportLevel.setToolTipText("Import Level"); barImportLevel .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_import.png"))); toolBar.add(barImportLevel); barExportLevel = new JButton(""); barExportLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionExportLevel(); } }); barExportLevel.setToolTipText("Export Level"); barExportLevel .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_export.png"))); toolBar.add(barExportLevel); toolBar.addSeparator(); barLoadLevel = new JButton(""); barLoadLevel.setToolTipText("Load Level"); barLoadLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionLoadLevel(); } }); barLoadLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_load_level.png"))); toolBar.add(barLoadLevel); barReloadLevel = new JButton(""); barReloadLevel.setToolTipText("Reload Current Level"); barReloadLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionReloadLevel(); } }); barReloadLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_reload_level.png"))); toolBar.add(barReloadLevel); barSaveLevel = new JButton(""); barSaveLevel.setToolTipText("Save Level"); barSaveLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveLevel(); } }); barSaveLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_level.png"))); toolBar.add(barSaveLevel); toolBar.addSeparator(); barViewItems = new JToggleButton(""); barViewItems.setToolTipText("Toggle View Items"); barViewItems.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barViewSpawn = new JToggleButton(""); barViewSpawn.setToolTipText("Toggle View Spawn"); barViewSpawn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barClearLevel = new JButton(""); barClearLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionClearLevel(); } }); barClearLevel.setToolTipText("Clear Level"); barClearLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_clear_level.png"))); toolBar.add(barClearLevel); toolBar.addSeparator(); barViewSpawn.setSelected(true); barViewSpawn.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_spawn.png"))); toolBar.add(barViewSpawn); barViewItems.setSelected(true); barViewItems.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_items.png"))); toolBar.add(barViewItems); barViewDoorItems = new JToggleButton(""); barViewDoorItems.setToolTipText("Toggle View Door Items"); barViewDoorItems.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barViewDoorItems.setSelected(true); barViewDoorItems.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_door_items.png"))); toolBar.add(barViewDoorItems); barViewEnemies = new JToggleButton(""); barViewEnemies.setToolTipText("toggle View Enemies"); barViewEnemies.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barViewEnemies.setSelected(true); barViewEnemies .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_enemies.png"))); toolBar.add(barViewEnemies); barViewTypes = new JToggleButton(""); barViewTypes.setToolTipText("Toggle view Combo Help"); barViewTypes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barViewTypes.setSelected(true); barViewTypes.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_combo_infos.png"))); toolBar.add(barViewTypes); barViewSpawn.setSelected(config.getBoolean("Hazelnutt.gui.viewSpawn", true)); barViewItems.setSelected(config.getBoolean("Hazelnutt.gui.viewItems", true)); barViewDoorItems.setSelected(config.getBoolean("Hazelnutt.gui.viewDoorItems", true)); barViewEnemies.setSelected(config.getBoolean("Hazelnutt.gui.viewEnemies", true)); barViewTypes.setSelected(config.getBoolean("Hazelnutt.gui.viewHelp", true)); panel = new JPanel(); contentPane.add(panel, BorderLayout.EAST); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); selectorPanel = new SelectorPanel(); selectorPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Combo & Entity Selector", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213))); panel.add(selectorPanel); propertiesPanel = new PropertiesPanel(null); propertiesPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Level Properties", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213))); panel.add(propertiesPanel); toolBar.addSeparator(); scaleButton = new JToggleButton(""); scaleButton.setToolTipText("Toggle Scale Display"); scaleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionScale(true); } }); scaleButton.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_x2.png"))); toolBar.add(scaleButton); scaleButton.setSelected(config.getBoolean("Hazelnutt.gui.scaled", false)); gridButton = new JToggleButton(""); gridButton.setToolTipText("Display Grid"); gridButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionGrid(true); } }); gridButton.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_grid.png"))); toolBar.add(gridButton); gridButton.setSelected(config.getBoolean("Hazelnutt.gui.grid", false)); Component horizontalGlue = Box.createHorizontalGlue(); toolBar.add(horizontalGlue); Component verticalGlue = Box.createVerticalGlue(); panel.add(verticalGlue); levelWrapper = new JPanel(); levelWrapper.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Level", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213))); contentPane.add(levelWrapper, BorderLayout.CENTER); levelWrapper.setLayout(new BorderLayout(0, 0)); scrollPane = new JScrollPane(); scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0)); levelWrapper.add(scrollPane); levelDisplay = new LevelDisplay(); levelDisplay.addEditListener(new EditListener() { @Override public void leftPressed(int x, int y) { SelectionType st = selectorPanel.getSelectionType(); Object so = selectorPanel.getSelectedObject(); if (st == SelectionType.COMBO) { paintComboAt(x, y, ((Byte) so).byteValue()); } else if (st == SelectionType.SPAWN) { selectedLevel.getRomLevel().setSpawn(new IntVector(x, y)); levelHasChanged = true; } else if (st == SelectionType.ITEM) { Item ent = new Item((ItemType) so, x, y); EntityCollection<Item> ents = selectedLevel.getRomLevel().getItems(); for (Iterator<Item> it = ents.iterator(); it.hasNext();) { Item item = it.next(); if (item.getX() == x && item.getY() == y) { it.remove(); } } if (ents.size() <= ents.maxSize()) { ents.add(ent); levelHasChanged = true; } } else if (st == SelectionType.DOOR_ITEM) { Item ent = new Item((ItemType) so, x, y); EntityCollection<Item> ents = selectedLevel.getRomLevel().getDoorItems(); for (Iterator<Item> it = ents.iterator(); it.hasNext();) { Item item = it.next(); if (item.getX() == x && item.getY() == y) { it.remove(); } } if (ents.size() <= ents.maxSize()) { ents.add(ent); levelHasChanged = true; } } else if (st == SelectionType.ENEMY) { Enemy ent = new Enemy((EnemyType) so, x, y); EntityCollection<Enemy> ents = selectedLevel.getRomLevel().getEnemies(); for (Iterator<Enemy> it = ents.iterator(); it.hasNext();) { Enemy enem = it.next(); if (enem.getX() == x && enem.getY() == y) { it.remove(); } } if (ents.size() <= ents.maxSize()) { ents.add(ent); levelHasChanged = true; } } updateTitle(); levelDisplay.repaint(); levelHasChanged = true; } @Override public void centerPressed(int x, int y) { selectorPanel.forceComboSelection(selectedLevel.getRomLevel().getData()[x][y]); } @Override public void rightPressed(int x, int y) { deleteVisibleEntitiesAt(x, y); } @Override public void leftDragged(int x, int y) { if (selectorPanel.getSelectionType() == SelectionType.COMBO) { paintComboAt(x, y, ((Byte) selectorPanel.getSelectedObject()).byteValue()); } } @Override public void centerDragged(int x, int y) { // Nothing to de here } @Override public void rightDragged(int x, int y) { deleteVisibleEntitiesAt(x, y); } // Utility methods /*private void selectComboAt ( int x, int y ) { }/**/ private void paintComboAt(int x, int y, byte value) { selectedLevel.getRomLevel().getData()[x][y] = value; levelHasChanged = true; updateTitle(); levelDisplay.repaint(); } private void deleteVisibleEntitiesAt(int x, int y) { Collection<Item> items = selectedLevel.getRomLevel().getItems(); Collection<Item> doorItems = selectedLevel.getRomLevel().getDoorItems(); Collection<Enemy> enemies = selectedLevel.getRomLevel().getEnemies(); if (barViewItems.isSelected()) { for (Iterator<Item> it = items.iterator(); it.hasNext();) { Item item = it.next(); if (item.getX() == x && item.getY() == y) { it.remove(); levelHasChanged = true; } } } if (barViewDoorItems.isSelected()) { for (Iterator<Item> it = doorItems.iterator(); it.hasNext();) { Item doorItem = it.next(); if (doorItem.getX() == x && doorItem.getY() == y) { it.remove(); levelHasChanged = true; } } } if (barViewEnemies.isSelected()) { for (Iterator<Enemy> it = enemies.iterator(); it.hasNext();) { Enemy enem = it.next(); if (enem.getX() == x && enem.getY() == y) { it.remove(); levelHasChanged = true; } } } updateTitle(); levelDisplay.repaint(); } }); scrollPane.setViewportView(levelDisplay); updateTitle(); actionToggle(true); actionScale(true); actionGrid(true); setIconImage(Toolkit.getDefaultToolkit() .getImage(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/witch_hazel_big.png"))); setRomFeaturesEnabled(false); setLevelFeaturesEnabled(false); if (config.getBoolean("Hazelnutt.gui.maximum", false)) { setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); } else { int x = config.getInt("Hazelnutt.gui.location.x", Integer.MIN_VALUE); int y = config.getInt("Hazelnutt.gui.location.y", Integer.MIN_VALUE); int w = config.getInt("Hazelnutt.gui.size.width", Integer.MIN_VALUE); int h = config.getInt("Hazelnutt.gui.size.height", Integer.MIN_VALUE); if (x == Integer.MIN_VALUE || x == Integer.MIN_VALUE || w == Integer.MIN_VALUE || h == Integer.MIN_VALUE) { setLocationRelativeTo(null); } else { setLocation(x, y); setSize(w, h); } } propertiesPanel.addApplyListener(new PropertiesPanel.ApplyListener() { @Override public void apply() { levelHasChanged = true; updateTitle(); updateDisplay(); } }); if (config.containsKey("Hazelnutt.gui.lastDirectory")) { File lastDir = new File(config.getString("Hazelnutt.gui.lastDirectory")); if (lastDir.exists() && lastDir.isDirectory()) { //logger.debug( "Resetting the last directory: '" + lastDir + "'" ); fileChooser.setCurrentDirectory(lastDir); } } // Configure the PgUp and PgDn shortcuts InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "PgUp"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "PgDn"); ActionMap am = contentPane.getActionMap(); am.put("PgUp", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { actionLevelUp(); } }); am.put("PgDn", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { actionLevelDown(); } }); // Get the recent files recentFiles = new LinkedList<String>(Arrays.asList(config.getStringArray("Hazelnutt.gui.recentFiles"))); updateRecentFiles(); }
From source file:br.com.atmatech.sac.view.ViewAtendimento.java
private void inicializaAtalhos() { KeyStroke keyStrokeJBalterar = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0); String actionNameJBalterar = "TECLA_F2"; InputMap inputMapJBalterar = jBalterar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBalterar.put(keyStrokeJBalterar, actionNameJBalterar); ActionMap actionMapJBMARCA = jBalterar.getActionMap(); actionMapJBMARCA.put(actionNameJBalterar, 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 AJUDA KeyStroke keyStrokeJBajuda = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0); String actionNameJBajuda = "TECLA_F9"; InputMap inputMapJBajuda = jBajuda.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBajuda.put(keyStrokeJBajuda, actionNameJBajuda); ActionMap actionMapJBajuda = jBajuda.getActionMap(); actionMapJBajuda.put(actionNameJBajuda, acaoJBajuda); //Atalho enter InputMap inputMapJBenter = this.jDcombocliente.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMapJBenter.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "forward"); this.jDcombocliente.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMapJBenter); this.jDcombocliente.getRootPane().getActionMap().put("forward", new AbstractAction() { private static final long serialVersionUID = 1L; @Override//from w w w . ja v a 2 s.c o m public void actionPerformed(ActionEvent e) { selecionaCliente(); } }); }