Search in sources :

Example 36 with AbstractAction

use of javax.swing.AbstractAction in project jabref by JabRef.

the class SearchResultFrame method init.

private void init(String title) {
    searchResultFrame = new JFrame();
    searchResultFrame.setTitle(title);
    searchResultFrame.setIconImages(IconTheme.getLogoSet());
    preview = new PreviewPanel(null, null);
    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();
    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) {
            dispose();
        }
    };
    ActionMap actionMap = contentPane.getActionMap();
    InputMap inputMap = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DATABASE), "close");
    actionMap.put("close", closeAction);
    actionMap = entryTable.getActionMap();
    inputMap = entryTable.getInputMap();
    //Override 'selectNextColumnCell' and 'selectPreviousColumnCell' to move rows instead of cells on TAB
    actionMap.put("selectNextColumnCell", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectNextEntry();
        }
    });
    actionMap.put("selectPreviousColumnCell", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectPreviousEntry();
        }
    });
    actionMap.put("selectNextRow", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectNextEntry();
        }
    });
    actionMap.put("selectPreviousRow", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectPreviousEntry();
        }
    });
    String selectFirst = "selectFirst";
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_FIRST_ENTRY), selectFirst);
    actionMap.put(selectFirst, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            selectFirstEntry();
        }
    });
    String selectLast = "selectLast";
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_LAST_ENTRY), selectLast);
    actionMap.put(selectLast, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            selectLastEntry();
        }
    });
    actionMap.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") + '.'));
            }
        }
    });
    // override standard enter-action; enter opens the selected entry
    entryTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
    actionMap.put("Enter", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            BibEntry entry = sortedEntries.get(entryTable.getSelectedRow());
            selectEntryInBasePanel(entry);
        }
    });
    searchResultFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            contentPane.setDividerLocation(0.5f);
        }

        @Override
        public void windowClosing(WindowEvent event) {
            dispose();
        }
    });
    searchResultFrame.getContentPane().add(contentPane, BorderLayout.CENTER);
    // Remember and default to last size:
    SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
    searchResultFrame.setSize(searchPreferences.getSeachDialogWidth(), searchPreferences.getSeachDialogHeight());
    searchResultFrame.setLocation(searchPreferences.getSearchDialogPosX(), searchPreferences.getSearchDialogPosY());
    searchResultFrame.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            new SearchPreferences(Globals.prefs).setSearchDialogWidth(searchResultFrame.getSize().width).setSearchDialogHeight(searchResultFrame.getSize().height);
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            new SearchPreferences(Globals.prefs).setSearchDialogPosX(searchResultFrame.getLocation().x).setSearchDialogPosY(searchResultFrame.getLocation().y);
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) GeneralRenderer(org.jabref.gui.renderer.GeneralRenderer) WindowAdapter(java.awt.event.WindowAdapter) PreviewPanel(org.jabref.gui.PreviewPanel) JFrame(javax.swing.JFrame) SortedList(ca.odell.glazedlists.SortedList) List(java.util.List) BasicEventList(ca.odell.glazedlists.BasicEventList) EventList(ca.odell.glazedlists.EventList) AbstractAction(javax.swing.AbstractAction) ComponentAdapter(java.awt.event.ComponentAdapter) JScrollPane(javax.swing.JScrollPane) BibEntry(org.jabref.model.entry.BibEntry) ActionMap(javax.swing.ActionMap) TransferableBibtexEntry(org.jabref.gui.TransferableBibtexEntry) DefaultEventSelectionModel(ca.odell.glazedlists.swing.DefaultEventSelectionModel) SearchPreferences(org.jabref.preferences.SearchPreferences) EntryComparator(org.jabref.logic.bibtex.comparator.EntryComparator) JTable(javax.swing.JTable) WindowEvent(java.awt.event.WindowEvent) InputMap(javax.swing.InputMap) ComponentEvent(java.awt.event.ComponentEvent)

Example 37 with AbstractAction

use of javax.swing.AbstractAction in project jabref by JabRef.

the class ConnectToSharedDatabaseDialog method setupActions.

/**
     * Defines and sets the different actions up.
     */
private void setupActions() {
    Action openAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                checkFields();
                connectionProperties = new DBMSConnectionProperties();
                connectionProperties.setType((DBMSType) dbmsTypeDropDown.getSelectedItem());
                connectionProperties.setHost(hostField.getText());
                connectionProperties.setPort(Integer.parseInt(portField.getText()));
                connectionProperties.setDatabase(databaseField.getText());
                connectionProperties.setUser(userField.getText());
                //JPasswordField.getPassword() does not return a String, but a char array.
                connectionProperties.setPassword(new String(passwordField.getPassword()));
                openSharedDatabase();
            } catch (JabRefException exception) {
                JOptionPane.showMessageDialog(ConnectToSharedDatabaseDialog.this, exception.getMessage(), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
            }
        }
    };
    connectButton.addActionListener(openAction);
    cancelButton.addActionListener(e -> dispose());
    /**
         * Set up a listener which updates the default port number once the selection in dbmsTypeDropDown has changed.
         */
    Action dbmsTypeDropDownAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            portField.setText(Integer.toString(((DBMSType) dbmsTypeDropDown.getSelectedItem()).getDefaultPort()));
        }
    };
    dbmsTypeDropDown.addActionListener(dbmsTypeDropDownAction);
    // Add enter button action listener
    connectButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter_pressed");
    connectButton.getActionMap().put("Enter_pressed", openAction);
    browseButton.addActionListener(e -> showFileChooser());
    autosaveFile.addActionListener(e -> updateEnableState());
}
Also used : SaveDatabaseAction(org.jabref.gui.exporter.SaveDatabaseAction) AbstractAction(javax.swing.AbstractAction) HelpAction(org.jabref.gui.help.HelpAction) Action(javax.swing.Action) JabRefException(org.jabref.JabRefException) ActionEvent(java.awt.event.ActionEvent) DBMSType(org.jabref.shared.DBMSType) AbstractAction(javax.swing.AbstractAction) DBMSConnectionProperties(org.jabref.shared.DBMSConnectionProperties)

Example 38 with AbstractAction

use of javax.swing.AbstractAction in project JMRI by JMRI.

the class JmriJFrame method addWindowCloseShortCut.

/**
     * Adds a "Close Window" key short cut to close window on op-W.
     */
void addWindowCloseShortCut() {
    // modelled after code in JavaDev mailing list item by Bill Tschumy <bill@otherwise.com> 08 Dec 2004
    AbstractAction act = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // log.debug("keystroke requested close window ", JmriJFrame.this.getTitle());
            JmriJFrame.this.processWindowEvent(new java.awt.event.WindowEvent(JmriJFrame.this, java.awt.event.WindowEvent.WINDOW_CLOSING));
        }
    };
    getRootPane().getActionMap().put("close", act);
    int stdMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    // We extract the modifiers as a string, then add the I18N string, and
    // build a key code
    String modifier = KeyStroke.getKeyStroke(KeyEvent.VK_W, stdMask).toString();
    String keyCode = modifier.substring(0, modifier.length() - 1) + Bundle.getMessage("VkKeyWindowClose").substring(0, 1);
    // NOI18N
    im.put(KeyStroke.getKeyStroke(keyCode), "close");
// im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
}
Also used : ActionEvent(java.awt.event.ActionEvent) InputMap(javax.swing.InputMap) JmriAbstractAction(jmri.util.swing.JmriAbstractAction) AbstractAction(javax.swing.AbstractAction)

Example 39 with AbstractAction

use of javax.swing.AbstractAction in project JMRI by JMRI.

the class MultiPaneWindow method makeNavTreePane.

protected JScrollPane makeNavTreePane(String treeFile) {
    final JTree tree;
    TreeNode topNode;
    rightTopWI = new PanedInterface(this);
    topNode = makeNavTreeTopNode(treeFile, rightTopWI);
    tree = new JTree(topNode);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    // allow multiple roots
    tree.setRootVisible(false);
    // install listener
    tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {

        @Override
        public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node == null) {
                //Nothing is selected.	
                return;
            }
            if (node.getUserObject() == null) {
                // Not an interesting node
                return;
            }
            if (node.getUserObject() instanceof AbstractAction) {
                AbstractAction action = (AbstractAction) node.getUserObject();
                action.actionPerformed(null);
            }
        }
    });
    // install in scroll area
    JScrollPane treeView = new JScrollPane(tree);
    treeView.setMinimumSize(new Dimension(0, 0));
    treeView.setPreferredSize(new Dimension(150, 600));
    return treeView;
}
Also used : JScrollPane(javax.swing.JScrollPane) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Dimension(java.awt.Dimension) AbstractAction(javax.swing.AbstractAction)

Example 40 with AbstractAction

use of javax.swing.AbstractAction in project jabref by JabRef.

the class MergeDialog method jbInit.

private void jbInit() {
    panel1.setLayout(borderLayout1);
    ok.setText(Localization.lang("OK"));
    ok.addActionListener(e -> {
        okPressed = true;
        dispose();
    });
    cancel.setText(Localization.lang("Cancel"));
    cancel.addActionListener(e -> dispose());
    jPanel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    jPanel1.setLayout(gridBagLayout1);
    entries.setSelected(true);
    entries.setText(Localization.lang("Import entries"));
    strings.setSelected(true);
    strings.setText(Localization.lang("Import strings"));
    groups.setText(Localization.lang("Import group definitions"));
    selector.setText(Localization.lang("Import word selector definitions"));
    this.setModal(true);
    this.setResizable(false);
    getContentPane().add(panel1);
    panel1.add(jPanel2, BorderLayout.SOUTH);
    jPanel2.add(ok, null);
    jPanel2.add(cancel, null);
    panel1.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(entries, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(strings, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(groups, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    jPanel1.add(selector, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    // Key bindings:
    ActionMap am = jPanel1.getActionMap();
    InputMap im = jPanel1.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();
        }
    });
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Aggregations

AbstractAction (javax.swing.AbstractAction)174 ActionEvent (java.awt.event.ActionEvent)162 Action (javax.swing.Action)42 InputMap (javax.swing.InputMap)34 JButton (javax.swing.JButton)33 JMenu (javax.swing.JMenu)30 JPanel (javax.swing.JPanel)30 ActionListener (java.awt.event.ActionListener)24 JMenuItem (javax.swing.JMenuItem)24 ActionMap (javax.swing.ActionMap)23 JScrollPane (javax.swing.JScrollPane)16 JPopupMenu (javax.swing.JPopupMenu)15 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)14 BorderLayout (java.awt.BorderLayout)14 BoxLayout (javax.swing.BoxLayout)12 JSeparator (javax.swing.JSeparator)12 JDialog (javax.swing.JDialog)11 WindowEvent (java.awt.event.WindowEvent)9 JMenuBar (javax.swing.JMenuBar)9 JTextField (javax.swing.JTextField)9