use of javax.swing.InputMap in project jmeter by apache.
the class SavePropertyDialog method createRootPane.
@Override
protected JRootPane createRootPane() {
JRootPane rootPane = new JRootPane();
Action escapeAction = new AbstractAction("ESCAPE") {
/**
*
*/
private static final long serialVersionUID = 2208129319916921772L;
@Override
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
};
InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME));
rootPane.getActionMap().put(escapeAction.getValue(Action.NAME), escapeAction);
return rootPane;
}
use of javax.swing.InputMap in project jmeter by apache.
the class SearchTreePanel method init.
private void init() {
// WARNING: called from ctor so must not be overridden (i.e. must be private or final)
setLayout(new BorderLayout(10, 10));
//$NON-NLS-1$
searchTF = new JTextField(20);
InputMap im = searchTF.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(KeyStrokes.ENTER, SEARCH_TEXT_COMMAND);
ActionMap am = searchTF.getActionMap();
am.put(SEARCH_TEXT_COMMAND, new EnterAction());
//$NON-NLS-1$
isRegexpCB = new JCheckBox(JMeterUtils.getResString("search_text_chkbox_regexp"), false);
//$NON-NLS-1$
isCaseSensitiveCB = new JCheckBox(JMeterUtils.getResString("search_text_chkbox_case"), false);
isRegexpCB.setFont(FONT_SMALL);
isCaseSensitiveCB.setFont(FONT_SMALL);
//$NON-NLS-1$
searchButton = new JButton(JMeterUtils.getResString("search"));
searchButton.addActionListener(this);
//$NON-NLS-1$
resetButton = new JButton(JMeterUtils.getResString("reset"));
resetButton.addActionListener(this);
JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
searchPanel.add(new JLabel(JMeterUtils.getResString("search_text_field")));
searchPanel.add(searchTF);
searchPanel.add(isCaseSensitiveCB);
searchPanel.add(isRegexpCB);
searchPanel.add(searchButton);
searchPanel.add(resetButton);
add(searchPanel);
}
use of javax.swing.InputMap 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.InputMap in project jabref by JabRef.
the class EntryEditor method setupJTextComponent.
/**
* NOTE: This method is only used for the source panel, not for the
* other tabs. Look at EntryEditorTab for the setup of text components
* in the other tabs.
*/
private void setupJTextComponent(JTextComponent textComponent) {
// Set up key bindings and focus listener for the FieldEditor.
InputMap inputMap = textComponent.getInputMap(JComponent.WHEN_FOCUSED);
ActionMap actionMap = textComponent.getActionMap();
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store");
actionMap.put("store", storeFieldAction);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL), "right");
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL_2), "right");
actionMap.put("right", switchRightAction);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL), "left");
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL_2), "left");
actionMap.put("left", switchLeftAction);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help");
actionMap.put("help", helpAction);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB), "nexttab");
actionMap.put("nexttab", frame.nextTab);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB), "prevtab");
actionMap.put("prevtab", frame.prevTab);
Set<AWTKeyStroke> keys = new HashSet<>(textComponent.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
keys.clear();
keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB"));
textComponent.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys);
keys = new HashSet<>(textComponent.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
keys.clear();
keys.add(KeyStroke.getKeyStroke("shift pressed TAB"));
textComponent.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys);
textComponent.addFocusListener(new FieldListener());
}
use of javax.swing.InputMap 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);
}
Aggregations