Search in sources :

Example 41 with AbstractAction

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

the class ContentSelectorDialog method setupActions.

private void setupActions() {
    wordList.addListSelectionListener(e -> {
        wordEditField.setText(wordList.getSelectedValue());
        wordEditField.selectAll();
        wordEditField.requestFocus();
    });
    newWord.addActionListener(e -> newWordAction());
    ActionListener wordEditFieldListener = e -> actOnWordEdit();
    wordEditField.addActionListener(wordEditFieldListener);
    removeWord.addActionListener(e -> {
        int index = wordList.getSelectedIndex();
        if (index == -1) {
            return;
        }
        wordListModel.remove(index);
        wordEditField.setText("");
        if (!wordListModel.isEmpty()) {
            wordList.setSelectedIndex(Math.min(index, wordListModel.size() - 1));
        }
    });
    fieldList.addListSelectionListener(e -> {
        currentField = fieldList.getSelectedValue();
        fieldNameField.setText("");
        setupWordSelector();
    });
    newField.addActionListener(e -> {
        if (!fieldListModel.get(0).equals(FIELD_FIRST_LINE)) {
            fieldListModel.add(0, FIELD_FIRST_LINE);
        }
        fieldList.setSelectedIndex(0);
        fPane.getVerticalScrollBar().setValue(0);
        fieldNameField.setEnabled(true);
        fieldNameField.setText(currentField);
        fieldNameField.selectAll();
        fieldNameField.requestFocus();
    });
    fieldNameField.addActionListener(e -> fieldNameField.transferFocus());
    fieldNameField.addFocusListener(new FieldNameFocusAdapter());
    removeField.addActionListener(e -> {
        int index = fieldList.getSelectedIndex();
        if (index == -1) {
            return;
        }
        String fieldName = fieldListModel.get(index);
        removedFields.add(fieldName);
        fieldListModel.remove(index);
        wordListModels.remove(fieldName);
        fieldNameField.setText("");
        if (!fieldListModel.isEmpty()) {
            fieldList.setSelectedIndex(Math.min(index, wordListModel.size() - 1));
        }
    });
    ok.addActionListener(e -> {
        try {
            applyChanges();
            dispose();
        } catch (Exception ex) {
            LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex);
            JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes."));
        }
    });
    apply.addActionListener(e -> {
        if (!"".equals(wordEditField.getText())) {
            wordEditFieldListener.actionPerformed(null);
        }
        try {
            applyChanges();
        } catch (Exception ex) {
            LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex);
            JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes."));
        }
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    cancelAction.putValue(Action.NAME, Localization.lang("Cancel"));
    cancel.setAction(cancelAction);
}
Also used : Insets(java.awt.Insets) ActionListener(java.awt.event.ActionListener) SortedSet(java.util.SortedSet) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) ContentSelector(org.jabref.model.metadata.ContentSelector) HashMap(java.util.HashMap) ContentSelectors(org.jabref.model.metadata.ContentSelectors) Action(javax.swing.Action) BasePanel(org.jabref.gui.BasePanel) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FocusAdapter(java.awt.event.FocusAdapter) JabRefFrame(org.jabref.gui.JabRefFrame) Map(java.util.Map) MetaData(org.jabref.model.metadata.MetaData) Localization(org.jabref.logic.l10n.Localization) KeyBinder(org.jabref.gui.keyboard.KeyBinder) HelpFile(org.jabref.logic.help.HelpFile) JButton(javax.swing.JButton) Window(java.awt.Window) JList(javax.swing.JList) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) JScrollPane(javax.swing.JScrollPane) List(java.util.List) JabRefDialog(org.jabref.gui.JabRefDialog) DefaultListModel(javax.swing.DefaultListModel) AbstractAction(javax.swing.AbstractAction) FocusEvent(java.awt.event.FocusEvent) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) HelpAction(org.jabref.gui.help.HelpAction) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) HelpAction(org.jabref.gui.help.HelpAction) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 42 with AbstractAction

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

the class JTextAreaWithHighlighting method setupUndoRedo.

private void setupUndoRedo() {
    undo = new UndoManager();
    Document doc = getDocument();
    // Listen for undo and redo events
    doc.addUndoableEditListener(evt -> undo.addEdit(evt.getEdit()));
    // Create an undo action and add it to the text component
    getActionMap().put("Undo", new AbstractAction("Undo") {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undo.canUndo()) {
                    undo.undo();
                }
            } catch (CannotUndoException ignored) {
            // Ignored
            }
        }
    });
    // Bind the undo action to ctl-Z
    getInputMap().put(Globals.getKeyPrefs().getKey(org.jabref.gui.keyboard.KeyBinding.UNDO), "Undo");
    // Create a redo action and add it to the text component
    getActionMap().put("Redo", new AbstractAction(Actions.REDO) {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undo.canRedo()) {
                    undo.redo();
                }
            } catch (CannotRedoException ignored) {
            // Ignored
            }
        }
    });
    // Bind the redo action to ctrl-Y
    boolean bind = true;
    KeyStroke redoKey = Globals.getKeyPrefs().getKey(org.jabref.gui.keyboard.KeyBinding.REDO);
    if (Globals.prefs.getBoolean(JabRefPreferences.EDITOR_EMACS_KEYBINDINGS)) {
        // If emacs is enabled, check if we have a conflict at keys
        // If yes, do not bind
        // Typically, we have: CTRL+y is "yank" in emacs and REDO in 'normal' settings
        // The Emacs key bindings are stored in the keymap, not in the input map.
        Keymap keymap = getKeymap();
        KeyStroke[] keys = keymap.getBoundKeyStrokes();
        int i = 0;
        while ((i < keys.length) && !keys[i].equals(redoKey)) {
            i++;
        }
        if (i < keys.length) {
            // conflict found -> do not bind
            bind = false;
        }
    }
    if (bind) {
        getInputMap().put(redoKey, "Redo");
    }
}
Also used : UndoManager(javax.swing.undo.UndoManager) ActionEvent(java.awt.event.ActionEvent) CannotRedoException(javax.swing.undo.CannotRedoException) KeyStroke(javax.swing.KeyStroke) CannotUndoException(javax.swing.undo.CannotUndoException) Document(javax.swing.text.Document) AbstractAction(javax.swing.AbstractAction) Keymap(javax.swing.text.Keymap)

Example 43 with AbstractAction

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

the class FileListEditor method initKeyBindings.

private void initKeyBindings() {
    // Add an input/action pair for deleting entries:
    getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "delete");
    getActionMap().put("delete", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            int row = getSelectedRow();
            removeEntries();
            row = Math.min(row, getRowCount() - 1);
            if (row >= 0) {
                setRowSelectionInterval(row, row);
            }
        }
    });
    // Add input/action pair for moving an entry up:
    getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.FILE_LIST_EDITOR_MOVE_ENTRY_UP), "move up");
    getActionMap().put("move up", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            moveEntry(-1);
        }
    });
    // Add input/action pair for moving an entry down:
    getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.FILE_LIST_EDITOR_MOVE_ENTRY_DOWN), "move down");
    getActionMap().put("move down", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            moveEntry(1);
        }
    });
    getInputMap().put(KeyStroke.getKeyStroke("F4"), "open file");
    getActionMap().put("open file", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            openSelectedFile();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 44 with AbstractAction

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

the class ImportInspectionDialog method getAction.

private AbstractAction getAction(GroupTreeNode node) {
    AbstractAction action = new AddToGroupAction(node);
    action.setEnabled(node.getGroup() instanceof GroupEntryChanger);
    return action;
}
Also used : GroupEntryChanger(org.jabref.model.groups.GroupEntryChanger) AbstractAction(javax.swing.AbstractAction)

Example 45 with AbstractAction

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

the class NewProtectedTermsFileDialog method setupDialog.

private void setupDialog() {
    JButton browse = new JButton(Localization.lang("Browse"));
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.TERMS).withDefaultExtension(FileExtensions.TERMS).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    browse.addActionListener(e -> {
        Optional<Path> file = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));
        file.ifPresent(f -> newFile.setText(f.toAbsolutePath().toString()));
    });
    // Build content panel
    FormBuilder builder = FormBuilder.create();
    builder.layout(new FormLayout("left:pref, 4dlu, fill:100dlu:grow, 4dlu, pref", "p, 4dlu, p, 4dlu, p"));
    builder.add(Localization.lang("Description")).xy(1, 1);
    builder.add(newDescription).xyw(3, 1, 3);
    builder.add(Localization.lang("File")).xy(1, 3);
    builder.add(newFile).xy(3, 3);
    builder.add(browse).xy(5, 3);
    builder.add(enabled).xyw(1, 5, 5);
    enabled.setSelected(true);
    builder.padding("10dlu, 10dlu, 10dlu, 10dlu");
    getContentPane().add(builder.build(), BorderLayout.CENTER);
    // Buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    JButton addOKButton = new JButton(Localization.lang("OK"));
    JButton addCancelButton = new JButton(Localization.lang("Cancel"));
    bb.addGlue();
    bb.addButton(addOKButton);
    bb.addButton(addCancelButton);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    addOKButton.addActionListener(e -> {
        addOKPressed = true;
        loader.addNewProtectedTermsList(newDescription.getText(), newFile.getText(), enabled.isSelected());
        dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addOKPressed = false;
            dispose();
        }
    };
    addCancelButton.addActionListener(cancelAction);
    // Key bindings:
    bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    bb.getPanel().getActionMap().put("close", cancelAction);
    pack();
}
Also used : Path(java.nio.file.Path) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) FXDialogService(org.jabref.gui.FXDialogService) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) 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