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