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);
}
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);
}
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);
}
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");
}
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;
}
Aggregations