List of usage examples for javax.swing ActionMap put
public void put(Object key, Action action)
key
to action
. From source file:net.java.sip.communicator.plugin.propertieseditor.SearchField.java
/** * Creates an instance <tt>SearchField</tt>. * /*from w w w . j a v a2s .com*/ * @param text the text we would like to enter by default * @param sorter the sorter which will be used for filtering. */ public SearchField(String text, JTable table) { super(text); this.table = table; ComponentUI ui = getUI(); if (ui instanceof SearchFieldUI) { SearchFieldUI searchFieldUI = (SearchFieldUI) ui; searchFieldUI.setCallButtonEnabled(false); searchFieldUI.setDeleteButtonEnabled(true); } setBorder(null); setDragEnabled(true); setOpaque(false); setPreferredSize(new Dimension(100, 25)); InputMap imap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); ActionMap amap = getActionMap(); @SuppressWarnings("serial") AbstractAction escapeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { setText(""); } }; amap.put("escape", escapeAction); getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { } public void insertUpdate(DocumentEvent e) { filter(getText()); } public void removeUpdate(DocumentEvent e) { filter(getText()); } }); loadSkin(); }
From source file:net.sf.jabref.wizard.auximport.gui.FromAuxDialog.java
private void jbInit() { JPanel panel1 = new JPanel(); panel1.setLayout(new BorderLayout()); selectInDBButton.setText(Localization.lang("Select")); selectInDBButton.setEnabled(false);//from w ww. j a v a 2 s . c o m selectInDBButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { FromAuxDialog.this.select_actionPerformed(); } }); generateButton.setText(Localization.lang("Generate")); generateButton.setEnabled(false); generateButton.addActionListener(new FromAuxDialog_generate_actionAdapter(this)); cancelButton.setText(Localization.lang("Cancel")); cancelButton.addActionListener(new FromAuxDialog_Cancel_actionAdapter(this)); parseButton.setText(Localization.lang("Parse")); parseButton.addActionListener(new FromAuxDialog_parse_actionAdapter(this)); initPanels(); // insert the buttons ButtonBarBuilder bb = new ButtonBarBuilder(); JPanel buttonPanel = bb.getPanel(); buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); bb.addGlue(); bb.addButton(parseButton); bb.addRelatedGap(); bb.addButton(selectInDBButton); bb.addButton(generateButton); bb.addButton(cancelButton); bb.addGlue(); this.setModal(true); this.setResizable(true); this.setTitle(Localization.lang("AUX file import")); JLabel desc = new JLabel("<html><h3>" + Localization.lang("AUX file import") + "</h3><p>" + Localization.lang("This feature generates a new database based on which entries " + "are needed in an existing LaTeX document.") + "</p>" + "<p>" + Localization.lang("You need to select one of your open databases from which to choose " + "entries, as well as the AUX file produced by LaTeX when compiling your document.") + "</p></html>"); desc.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel1.add(desc, BorderLayout.NORTH); JPanel centerPane = new JPanel(new BorderLayout()); centerPane.add(buttons, BorderLayout.NORTH); centerPane.add(statusPanel, BorderLayout.CENTER); getContentPane().add(panel1, BorderLayout.NORTH); getContentPane().add(centerPane, BorderLayout.CENTER); getContentPane().add(buttonPanel, BorderLayout.SOUTH); // Key bindings: ActionMap am = statusPanel.getActionMap(); InputMap im = statusPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); }
From source file:net.sf.jabref.gui.PreviewPanel.java
private void createKeyBindings() { ActionMap actionMap = this.getActionMap(); InputMap inputMap = this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); final String close = "close"; inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), close); actionMap.put(close, this.closeAction); final String copy = "copy"; inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.COPY_PREVIEW), copy); actionMap.put(copy, this.copyPreviewAction); final String print = "print"; inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.PRINT_ENTRY_PREVIEW), print); actionMap.put(print, this.printAction); }
From source file:net.sf.jabref.importer.ImportCustomizationDialog.java
/** * * @param frame/* ww w .ja va 2s.c o m*/ */ public ImportCustomizationDialog(final JabRefFrame frame) { super(frame, Localization.lang("Manage custom imports"), false); ImportTableModel tableModel = new ImportTableModel(); customImporterTable = new JTable(tableModel); TableColumnModel cm = customImporterTable.getColumnModel(); cm.getColumn(0).setPreferredWidth(COL_0_WIDTH); cm.getColumn(1).setPreferredWidth(COL_1_WIDTH); cm.getColumn(2).setPreferredWidth(COL_2_WIDTH); cm.getColumn(3).setPreferredWidth(COL_3_WIDTH); JScrollPane sp = new JScrollPane(customImporterTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); customImporterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); customImporterTable.setPreferredScrollableViewportSize(getSize()); if (customImporterTable.getRowCount() > 0) { customImporterTable.setRowSelectionInterval(0, 0); } JButton addFromFolderButton = new JButton(Localization.lang("Add from folder")); addFromFolderButton.addActionListener(e -> { CustomImporter importer = new CustomImporter(); importer.setBasePath(FileDialogs.getNewDir(frame, new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), Collections.emptyList(), Localization.lang("Select Classpath of New Importer"), JFileChooser.CUSTOM_DIALOG, false)); String chosenFileStr = null; if (importer.getBasePath() != null) { chosenFileStr = FileDialogs.getNewFile(frame, importer.getFileFromBasePath(), Collections.singletonList(".class"), Localization.lang("Select new ImportFormat subclass"), JFileChooser.CUSTOM_DIALOG, false); } if (chosenFileStr != null) { try { importer.setClassName(pathToClass(importer.getFileFromBasePath(), new File(chosenFileStr))); importer.setName(importer.getInstance().getFormatName()); importer.setCliId(importer.getInstance().getId()); addOrReplaceImporter(importer); customImporterTable.revalidate(); customImporterTable.repaint(); } catch (Exception exc) { JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0", chosenFileStr)); } catch (NoClassDefFoundError exc) { JOptionPane.showMessageDialog(frame, Localization.lang( "Could not instantiate %0. Have you chosen the correct package path?", chosenFileStr)); } } }); addFromFolderButton .setToolTipText(Localization.lang("Add a (compiled) custom ImportFormat class from a class path.") + "\n" + Localization.lang("The path need not be on the classpath of JabRef.")); JButton addFromJarButton = new JButton(Localization.lang("Add from jar")); addFromJarButton.addActionListener(e -> { String basePath = FileDialogs.getNewFile(frame, new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), Arrays.asList(".zip", ".jar"), Localization.lang("Select a Zip-archive"), JFileChooser.CUSTOM_DIALOG, false); if (basePath != null) { try (ZipFile zipFile = new ZipFile(new File(basePath), ZipFile.OPEN_READ)) { ZipFileChooser zipFileChooser = new ZipFileChooser(this, zipFile); zipFileChooser.setVisible(true); customImporterTable.revalidate(); customImporterTable.repaint(10); } catch (IOException exc) { LOGGER.info("Could not open Zip-archive.", exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not open %0", basePath) + "\n" + Localization.lang("Have you chosen the correct package path?")); } catch (NoClassDefFoundError exc) { LOGGER.info("Could not instantiate Zip-archive reader.", exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0", basePath) + "\n" + Localization.lang("Have you chosen the correct package path?")); } } }); addFromJarButton .setToolTipText(Localization.lang("Add a (compiled) custom ImportFormat class from a Zip-archive.") + "\n" + Localization.lang("The Zip-archive need not be on the classpath of JabRef.")); JButton showDescButton = new JButton(Localization.lang("Show description")); showDescButton.addActionListener(e -> { int row = customImporterTable.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer.")); } else { CustomImporter importer = ((ImportTableModel) customImporterTable.getModel()).getImporter(row); try { ImportFormat importFormat = importer.getInstance(); JOptionPane.showMessageDialog(frame, importFormat.getDescription()); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException exc) { LOGGER.warn("Could not instantiate importer " + importer.getName(), exc); JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0 %1", importer.getName() + ":\n", exc.getMessage())); } } }); JButton removeButton = new JButton(Localization.lang("Remove")); removeButton.addActionListener(e -> { int row = customImporterTable.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer.")); } else { customImporterTable.removeRowSelectionInterval(row, row); Globals.prefs.customImports .remove(((ImportTableModel) customImporterTable.getModel()).getImporter(row)); Globals.IMPORT_FORMAT_READER.resetImportFormats(); customImporterTable.revalidate(); customImporterTable.repaint(); } }); Action closeAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }; JButton closeButton = new JButton(Localization.lang("Close")); closeButton.addActionListener(closeAction); JButton helpButton = new HelpAction(HelpFile.CUSTOM_IMPORTS).getHelpButton(); // Key bindings: JPanel mainPanel = new JPanel(); ActionMap am = mainPanel.getActionMap(); InputMap im = mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", closeAction); mainPanel.setLayout(new BorderLayout()); mainPanel.add(sp, BorderLayout.CENTER); JPanel buttons = new JPanel(); ButtonBarBuilder bb = new ButtonBarBuilder(buttons); buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); bb.addGlue(); bb.addButton(addFromFolderButton); bb.addButton(addFromJarButton); bb.addButton(showDescButton); bb.addButton(removeButton); bb.addButton(closeButton); bb.addUnrelatedGap(); bb.addButton(helpButton); bb.addGlue(); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(buttons, BorderLayout.SOUTH); this.setSize(getSize()); pack(); this.setLocationRelativeTo(frame); new FocusRequester(customImporterTable); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java
@Override public void addAction(Action action, int index) { checkNotNullArgument(action, "action must be non null"); int oldIndex = findActionById(actionsOrder, action.getId()); if (oldIndex >= 0) { removeAction(actionsOrder.get(oldIndex)); if (index > oldIndex) { index--;//from w w w .ja v a2s . c om } } actionsOrder.add(index, action); DesktopButton dButton = new DesktopButton(); dButton.setParentEnabled(isEnabledWithParent()); dButton.setShouldBeFocused(false); dButton.setAction(action); dButton.getImpl().setFocusable(false); dButton.getImpl().setText(""); impl.addButton(dButton.getImpl(), index); buttons.add(dButton); // apply Editable after action owner is set if (action instanceof StandardAction) { ((StandardAction) action).setEditable(isEditable()); } updateOrderedShortcuts(); ActionMap actionMap = getImpl().getInputField().getActionMap(); actionMap.put(action.getId(), new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { action.actionPerform(dButton); } }); if (action.getShortcutCombination() != null) { InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED); KeyStroke shortcutKeyStroke = DesktopComponentsHelper .convertKeyCombination(action.getShortcutCombination()); inputMap.put(shortcutKeyStroke, action.getId()); } actionsPermissions.apply(action); }
From source file:net.sf.jabref.gui.FileListEntryEditor.java
public FileListEntryEditor(JabRefFrame frame, FileListEntry entry, boolean showProgressBar, boolean showOpenButton, BibDatabaseContext databaseContext) { this.entry = entry; this.databaseContext = databaseContext; ActionListener okAction = e -> { // If OK button is disabled, ignore this event: if (!ok.isEnabled()) { return; }/* ww w . j av a2 s .c o m*/ // If necessary, ask the external confirm object whether we are ready to close. if (externalConfirm != null) { // Construct an updated FileListEntry: storeSettings(entry); if (!externalConfirm.confirmClose(entry)) { return; } } diag.dispose(); storeSettings(FileListEntryEditor.this.entry); okPressed = true; }; types = new JComboBox<>(); types.addItemListener(itemEvent -> { if (!okDisabledExternally) { ok.setEnabled(types.getSelectedItem() != null); } }); FormBuilder builder = FormBuilder.create().layout(new FormLayout( "left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p")); builder.add(Localization.lang("Link")).xy(1, 1); builder.add(link).xy(3, 1); final BrowseListener browse = new BrowseListener(frame, link); final JButton browseBut = new JButton(Localization.lang("Browse")); browseBut.addActionListener(browse); builder.add(browseBut).xy(5, 1); JButton open = new JButton(Localization.lang("Open")); if (showOpenButton) { builder.add(open).xy(7, 1); } builder.add(Localization.lang("Description")).xy(1, 3); builder.add(description).xyw(3, 3, 3); builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); builder.add(Localization.lang("File type")).xy(1, 5); builder.add(types).xyw(3, 5, 3); if (showProgressBar) { builder.appendRows("2dlu, p"); builder.add(downloadLabel).xy(1, 7); builder.add(prog).xyw(3, 7, 3); } ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addRelatedGap(); bb.addButton(ok); JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); ok.addActionListener(okAction); // Add OK action to the two text fields to simplify entering: link.addActionListener(okAction); description.addActionListener(okAction); open.addActionListener(e -> openFile()); AbstractAction cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { diag.dispose(); } }; cancel.addActionListener(cancelAction); // Key bindings: ActionMap am = builder.getPanel().getActionMap(); InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelAction); link.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent documentEvent) { checkExtension(); } @Override public void removeUpdate(DocumentEvent documentEvent) { // Do nothing } @Override public void changedUpdate(DocumentEvent documentEvent) { checkExtension(); } }); diag = new JDialog(frame, Localization.lang("Save file"), true); diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER); diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); diag.pack(); diag.setLocationRelativeTo(frame); diag.addWindowListener(new WindowAdapter() { @Override public void windowActivated(WindowEvent event) { if (openBrowseWhenShown && !dontOpenBrowseUntilDisposed) { dontOpenBrowseUntilDisposed = true; SwingUtilities.invokeLater(() -> browse.actionPerformed(new ActionEvent(browseBut, 0, ""))); } } @Override public void windowClosed(WindowEvent event) { dontOpenBrowseUntilDisposed = false; } }); setValues(entry); }
From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java
private void enableExitKey() { InputMap rootInput = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap rootAction = getRootPane().getActionMap(); if (SystemUtils.IS_OS_UNIX || SystemUtils.IS_OS_WINDOWS) { rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.CTRL_DOWN_MASK), "exit"); rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK), "exit"); }/* w w w. j a va 2 s. c o m*/ if (SystemUtils.IS_OS_MAC) { rootInput.put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.META_DOWN_MASK), "exit"); } rootAction.put("exit", new KeyAction(actionMapper, "exit")); }
From source file:net.sf.jabref.gui.search.SearchResultsDialog.java
private void init(String title) { diag = new JDialog(frame, title, false); int activePreview = Globals.prefs.getInt(JabRefPreferences.ACTIVE_PREVIEW); String layoutFile = activePreview == 0 ? Globals.prefs.get(JabRefPreferences.PREVIEW_0) : Globals.prefs.get(JabRefPreferences.PREVIEW_1); preview = new PreviewPanel(null, null, layoutFile); sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR)); model = (DefaultEventTableModel<BibEntry>) GlazedListsSwing .eventTableModelWithThreadProxyList(sortedEntries, new EntryTableFormat()); entryTable = new JTable(model); GeneralRenderer renderer = new GeneralRenderer(Color.white); entryTable.setDefaultRenderer(JLabel.class, renderer); entryTable.setDefaultRenderer(String.class, renderer); setWidths();//from w ww. j a v a 2 s . c o m TableComparatorChooser<BibEntry> tableSorter = TableComparatorChooser.install(entryTable, sortedEntries, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); setupComparatorChooser(tableSorter); JScrollPane sp = new JScrollPane(entryTable); final DefaultEventSelectionModel<BibEntry> selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing .eventSelectionModelWithThreadProxyList(sortedEntries); entryTable.setSelectionModel(selectionModel); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); entryTable.addMouseListener(new TableClickListener()); contentPane.setTopComponent(sp); contentPane.setBottomComponent(preview); // Key bindings: AbstractAction closeAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { diag.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); entryTable.getActionMap().put("copy", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (!selectionModel.getSelected().isEmpty()) { List<BibEntry> bes = selectionModel.getSelected(); TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes); // ! look at ClipBoardManager Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, frame.getCurrentBasePanel()); frame.output(Localization.lang("Copied") + ' ' + (bes.size() > 1 ? bes.size() + " " + Localization.lang("entries") : "1 " + Localization.lang("entry") + '.')); } } }); diag.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { contentPane.setDividerLocation(0.5f); } @Override public void windowClosing(WindowEvent event) { Globals.prefs.putInt(JabRefPreferences.SEARCH_DIALOG_WIDTH, diag.getSize().width); Globals.prefs.putInt(JabRefPreferences.SEARCH_DIALOG_HEIGHT, diag.getSize().height); } }); diag.getContentPane().add(contentPane, BorderLayout.CENTER); // Remember and default to last size: diag.setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.SEARCH_DIALOG_WIDTH), Globals.prefs.getInt(JabRefPreferences.SEARCH_DIALOG_HEIGHT))); diag.setLocationRelativeTo(frame); }
From source file:org.nekorp.workflow.desktop.view.CostoServicioView.java
private void setShorcuts() { InputMap im = tablaCostos.getInputMap(JTable.WHEN_FOCUSED); ActionMap am = tablaCostos.getActionMap(); Action deleteAction = new AbstractAction() { @Override/*from w w w . ja v a 2s . c om*/ public void actionPerformed(ActionEvent e) { borrarActionPerformed(e); } }; im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "Delete"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "Delete"); am.put("Delete", deleteAction); Action addAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { borrarActionPerformed(e); } }; im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0), "Add"); am.put("Add", addAction); }
From source file:net.sf.jabref.gui.openoffice.StyleSelectDialog.java
private void init() { setupPopupMenu();/*w ww . j a va 2 s . c o m*/ addButton.addActionListener(actionEvent -> { AddFileDialog addDialog = new AddFileDialog(); addDialog.setDirectoryPath(preferences.getCurrentStyle()); addDialog.setVisible(true); addDialog.getFileName().ifPresent(fileName -> { if (loader.addStyleIfValid(fileName)) { preferences.setCurrentStyle(fileName); } }); updateStyles(); }); addButton.setToolTipText(Localization.lang("Add style file")); removeButton.addActionListener(removeAction); removeButton.setToolTipText(Localization.lang("Remove style")); // Create a preview panel for previewing styles // Must be done before creating the table to avoid NPEs preview = new PreviewPanel(null, null, ""); // Use the test entry from the Preview settings tab in Preferences: preview.setEntry(prevEntry); setupTable(); updateStyles(); // Build dialog diag = new JDialog(frame, Localization.lang("Select style"), true); FormBuilder builder = FormBuilder.create(); builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref", "pref, 4dlu, 100dlu:grow, 4dlu, pref, 4dlu, fill:100dlu")); builder.add(Localization.lang("Select one of the available styles or add a style file from disk.")).xyw(1, 1, 5); builder.add(new JScrollPane(table)).xyw(1, 3, 5); builder.add(addButton).xy(3, 5); builder.add(removeButton).xy(5, 5); builder.add(preview).xyw(1, 7, 5); builder.padding("5dlu, 5dlu, 5dlu, 5dlu"); diag.add(builder.getPanel(), BorderLayout.CENTER); AbstractAction okListener = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { if ((table.getRowCount() == 0) || (table.getSelectedRowCount() == 0)) { JOptionPane.showMessageDialog(diag, Localization.lang("You must select a valid style file."), Localization.lang("Style selection"), JOptionPane.ERROR_MESSAGE); return; } okPressed = true; storeSettings(); diag.dispose(); } }; ok.addActionListener(okListener); Action cancelListener = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { diag.dispose(); } }; cancel.addActionListener(cancelListener); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addButton(ok); bb.addButton(cancel); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); diag.add(bb.getPanel(), BorderLayout.SOUTH); ActionMap am = bb.getPanel().getActionMap(); InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelListener); im.put(KeyStroke.getKeyStroke("ENTER"), "enterOk"); am.put("enterOk", okListener); diag.pack(); PositionWindow pw = new PositionWindow(diag, JabRefPreferences.STYLES_POS_X, JabRefPreferences.STYLES_POS_Y, JabRefPreferences.STYLES_SIZE_X, JabRefPreferences.STYLES_SIZE_Y); pw.setWindowPosition(); }