use of org.jabref.gui.autocompleter.AutoCompleteListener 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);
}
Aggregations