Search in sources :

Example 31 with AbstractAction

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

the class ManageKeywordsAction method createDialog.

private void createDialog() {
    if (diag != null) {
        return;
    }
    // keyword to add
    JTextField keyword = new JTextField();
    keywordListModel = new DefaultListModel<>();
    JList<Keyword> keywordList = new JList<>(keywordListModel);
    keywordList.setVisibleRowCount(8);
    JScrollPane kPane = new JScrollPane(keywordList);
    diag = new JDialog(frame, Localization.lang("Manage keywords"), true);
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    JButton add = new JButton(Localization.lang("Add"));
    JButton remove = new JButton(Localization.lang("Remove"));
    keywordList.setVisibleRowCount(10);
    intersectKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ALL entries"));
    mergeKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ANY entry"));
    ButtonGroup group = new ButtonGroup();
    group.add(intersectKeywords);
    group.add(mergeKeywords);
    ActionListener stateChanged = e -> fillKeyWordList();
    intersectKeywords.addActionListener(stateChanged);
    mergeKeywords.addActionListener(stateChanged);
    intersectKeywords.setSelected(true);
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:200dlu:grow, 4dlu, fill:pref", "pref, 2dlu, pref, 1dlu, pref, 2dlu, fill:100dlu:grow, 4dlu, pref, 4dlu, pref, "));
    builder.addSeparator(Localization.lang("Keywords of selected entries")).xyw(1, 1, 3);
    builder.add(intersectKeywords).xyw(1, 3, 3);
    builder.add(mergeKeywords).xyw(1, 5, 3);
    builder.add(kPane).xywh(1, 7, 1, 3);
    builder.add(remove).xy(3, 9);
    builder.add(keyword).xy(1, 11);
    builder.add(add).xy(3, 11);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    ok.addActionListener(e -> {
        canceled = false;
        diag.dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            canceled = true;
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    final ActionListener addActionListener = arg0 -> addButtonActionListener(keyword);
    add.addActionListener(addActionListener);
    final ActionListener removeActionListenter = arg0 -> {
        List<Keyword> values = keywordList.getSelectedValuesList();
        for (Keyword val : values) {
            keywordListModel.removeElement(val);
        }
    };
    remove.addActionListener(removeActionListenter);
    keywordList.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent arg0) {
        // Do nothing
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        // Do nothing
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_DELETE) {
                removeActionListenter.actionPerformed(null);
            }
        }
    });
    AutoCompleter<String> autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters().get(FieldName.KEYWORDS);
    AutoCompleteListener acl = new AutoCompleteListener(autoComp);
    keyword.addKeyListener(acl);
    keyword.addFocusListener(acl);
    keyword.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        // Do nothing
        }

        @Override
        public void keyReleased(KeyEvent e) {
        // Do nothing
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                addActionListener.actionPerformed(null);
            }
        }
    });
    // 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);
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
}
Also used : KeyListener(java.awt.event.KeyListener) ActionListener(java.awt.event.ActionListener) NamedCompound(org.jabref.gui.undo.NamedCompound) AutoCompleter(org.jabref.logic.autocompleter.AutoCompleter) Enumeration(java.util.Enumeration) JDialog(javax.swing.JDialog) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) StringUtil(org.jabref.model.strings.StringUtil) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) Action(javax.swing.Action) BasePanel(org.jabref.gui.BasePanel) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) Keyword(org.jabref.model.entry.Keyword) BorderLayout(java.awt.BorderLayout) SpecialFieldsUtils(org.jabref.logic.specialfields.SpecialFieldsUtils) ActionMap(javax.swing.ActionMap) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) ButtonGroup(javax.swing.ButtonGroup) BibEntry(org.jabref.model.entry.BibEntry) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) JabRefGUI(org.jabref.JabRefGUI) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) JScrollPane(javax.swing.JScrollPane) FieldChange(org.jabref.model.FieldChange) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) AbstractAction(javax.swing.AbstractAction) FormLayout(com.jgoodies.forms.layout.FormLayout) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) Optional(java.util.Optional) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) InputMap(javax.swing.InputMap) KeyBinding(org.jabref.gui.keyboard.KeyBinding) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) KeyEvent(java.awt.event.KeyEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) JList(javax.swing.JList) List(java.util.List) AbstractAction(javax.swing.AbstractAction) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) Keyword(org.jabref.model.entry.Keyword) ActionMap(javax.swing.ActionMap) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) KeyListener(java.awt.event.KeyListener) InputMap(javax.swing.InputMap) JList(javax.swing.JList) JDialog(javax.swing.JDialog)

Example 32 with AbstractAction

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

the class EntryEditor method setupToolBar.

private void setupToolBar() {
    JPanel leftPan = new JPanel();
    leftPan.setLayout(new BorderLayout());
    JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL);
    toolBar.setBorder(null);
    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", storeFieldAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), "generateKey");
    actionMap.put("generateKey", generateKeyAction);
    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", prevEntryAction);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_ENTRY), "next");
    actionMap.put("next", nextEntryAction);
    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", helpAction);
    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, panel.getBibDatabaseContext().getMode());
    leftPan.add(new TypeLabel(typedEntry.getTypeForDisplay()), BorderLayout.CENTER);
    TypeButton typeButton = new TypeButton();
    toolBar.add(typeButton);
    toolBar.add(generateKeyAction);
    toolBar.add(autoLinkAction);
    toolBar.add(writeXmp);
    JPopupMenu fetcherPopup = new JPopupMenu();
    for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(Globals.prefs.getImportFormatPreferences())) {
        fetcherPopup.add(new JMenuItem(new AbstractAction(fetcher.getName()) {

            @Override
            public void actionPerformed(ActionEvent e) {
                new EntryFetchAndMergeWorker(panel, getEntry(), fetcher).execute();
            }
        }));
    }
    JButton fetcherButton = new JButton(IconTheme.JabRefIcon.REFRESH.getIcon());
    fetcherButton.setToolTipText(Localization.lang("Update with bibliographic information from the web"));
    fetcherButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            fetcherPopup.show(e.getComponent(), e.getX(), e.getY());
        }
    });
    toolBar.add(fetcherButton);
    toolBar.addSeparator();
    toolBar.add(deleteAction);
    toolBar.add(prevEntryAction);
    toolBar.add(nextEntryAction);
    toolBar.addSeparator();
    toolBar.add(helpAction);
    Component[] comps = toolBar.getComponents();
    for (Component comp : comps) {
        ((JComponent) comp).setOpaque(false);
    }
    leftPan.add(toolBar, BorderLayout.SOUTH);
    add(leftPan, BorderLayout.WEST);
}
Also used : JPanel(javax.swing.JPanel) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) JComponent(javax.swing.JComponent) EntryFetchAndMergeWorker(org.jabref.gui.mergeentries.EntryFetchAndMergeWorker) JToolBar(javax.swing.JToolBar) TypedBibEntry(org.jabref.logic.TypedBibEntry) JPopupMenu(javax.swing.JPopupMenu) BorderLayout(java.awt.BorderLayout) OSXCompatibleToolbar(org.jabref.gui.OSXCompatibleToolbar) InputMap(javax.swing.InputMap) EntryBasedFetcher(org.jabref.logic.importer.EntryBasedFetcher) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) AbstractAction(javax.swing.AbstractAction)

Example 33 with AbstractAction

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

the class GroupAddRemoveDialog method action.

@Override
public void action() throws Exception {
    Optional<GroupTreeNode> groups = panel.getBibDatabaseContext().getMetaData().getGroups();
    if (!groups.isPresent()) {
        return;
    }
    selection = panel.getSelectedEntries();
    final JDialog diag = new JDialog(panel.frame(), (add ? (move ? Localization.lang("Move to group") : Localization.lang("Add to group")) : Localization.lang("Remove from group")), true);
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    tree = new JTree(new GroupTreeNodeViewModel(groups.get()));
    tree.setCellRenderer(new AddRemoveGroupTreeCellRenderer());
    tree.setVisibleRowCount(22);
    //        tree.setPreferredSize(new Dimension(200, tree.getPreferredSize().height));
    //      The scrollbar appears when the preferred size of a component is greater than the size of the viewport. If one hard coded the preferred size, it will never change according to the expansion/collapse. Thus the scrollbar cannot appear accordingly.
    //tree.setSelectionModel(new VetoableTreeSelectionModel());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addTreeSelectionListener(e -> {
        GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) e.getNewLeadSelectionPath().getLastPathComponent();
        ok.setEnabled(checkGroupEnable(node));
    });
    //STA add expand and collapse all buttons
    JButton jbExpandAll = new JButton("Expand All");
    jbExpandAll.addActionListener(e -> expandAll(tree, true));
    JButton jbCollapseAll = new JButton("Collapse All");
    jbCollapseAll.addActionListener(e -> expandAll(tree, false));
    //END add expand and collapse all buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addButton(jbExpandAll);
    bb.addButton(jbCollapseAll);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    ok.addActionListener(actionEvent -> {
        if (doAddOrRemove()) {
            diag.dispose();
        }
    });
    cancel.addActionListener(actionEvent -> diag.dispose());
    ok.setEnabled(false);
    JScrollPane sp = new JScrollPane(tree);
    // Key bindings:
    ActionMap am = sp.getActionMap();
    InputMap im = sp.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) {
            diag.dispose();
        }
    });
    diag.getContentPane().add(sp, BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();
    diag.setLocationRelativeTo(panel.frame());
    diag.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) JTree(javax.swing.JTree) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 34 with AbstractAction

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

the class TextField 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 ctl-Y
    getInputMap().put(Globals.getKeyPrefs().getKey(org.jabref.gui.keyboard.KeyBinding.REDO), "Redo");
}
Also used : UndoManager(javax.swing.undo.UndoManager) ActionEvent(java.awt.event.ActionEvent) CannotRedoException(javax.swing.undo.CannotRedoException) CannotUndoException(javax.swing.undo.CannotUndoException) Document(javax.swing.text.Document) AbstractAction(javax.swing.AbstractAction)

Example 35 with AbstractAction

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

the class EditorMenus method getDOIMenu.

public static List<MenuItem> getDOIMenu(TextArea textArea) {
    AbstractAction copyDoiUrlAction = new CopyDoiUrlAction(textArea);
    MenuItem copyDoiUrlMenuItem = new MenuItem((String) copyDoiUrlAction.getValue(Action.NAME));
    copyDoiUrlMenuItem.setOnAction(event -> copyDoiUrlAction.actionPerformed(null));
    List<MenuItem> menuItems = new ArrayList<>();
    menuItems.add(copyDoiUrlMenuItem);
    menuItems.add(new SeparatorMenuItem());
    return menuItems;
}
Also used : ArrayList(java.util.ArrayList) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) AbstractAction(javax.swing.AbstractAction) CopyDoiUrlAction(org.jabref.gui.actions.CopyDoiUrlAction)

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