use of javax.swing.ActionMap in project jabref by JabRef.
the class SearchResultFrame method init.
private void init(String title) {
searchResultFrame = new JFrame();
searchResultFrame.setTitle(title);
searchResultFrame.setIconImages(IconTheme.getLogoSet());
preview = new PreviewPanel(null, null);
sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR));
model = (DefaultEventTableModel<BibEntry>) GlazedListsSwing.eventTableModelWithThreadProxyList(sortedEntries, new EntryTableFormat());
entryTable = new JTable(model);
GeneralRenderer renderer = new GeneralRenderer(Color.white);
entryTable.setDefaultRenderer(JLabel.class, renderer);
entryTable.setDefaultRenderer(String.class, renderer);
setWidths();
TableComparatorChooser<BibEntry> tableSorter = TableComparatorChooser.install(entryTable, sortedEntries, AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
setupComparatorChooser(tableSorter);
JScrollPane sp = new JScrollPane(entryTable);
final DefaultEventSelectionModel<BibEntry> selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing.eventSelectionModelWithThreadProxyList(sortedEntries);
entryTable.setSelectionModel(selectionModel);
selectionModel.getSelected().addListEventListener(new EntrySelectionListener());
entryTable.addMouseListener(new TableClickListener());
contentPane.setTopComponent(sp);
contentPane.setBottomComponent(preview);
// Key bindings:
AbstractAction closeAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
};
ActionMap actionMap = contentPane.getActionMap();
InputMap inputMap = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DATABASE), "close");
actionMap.put("close", closeAction);
actionMap = entryTable.getActionMap();
inputMap = entryTable.getInputMap();
//Override 'selectNextColumnCell' and 'selectPreviousColumnCell' to move rows instead of cells on TAB
actionMap.put("selectNextColumnCell", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectNextEntry();
}
});
actionMap.put("selectPreviousColumnCell", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectPreviousEntry();
}
});
actionMap.put("selectNextRow", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectNextEntry();
}
});
actionMap.put("selectPreviousRow", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectPreviousEntry();
}
});
String selectFirst = "selectFirst";
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_FIRST_ENTRY), selectFirst);
actionMap.put(selectFirst, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
selectFirstEntry();
}
});
String selectLast = "selectLast";
inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_LAST_ENTRY), selectLast);
actionMap.put(selectLast, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent event) {
selectLastEntry();
}
});
actionMap.put("copy", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!selectionModel.getSelected().isEmpty()) {
List<BibEntry> bes = selectionModel.getSelected();
TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
// ! look at ClipBoardManager
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, frame.getCurrentBasePanel());
frame.output(Localization.lang("Copied") + ' ' + (bes.size() > 1 ? bes.size() + " " + Localization.lang("entries") : "1 " + Localization.lang("entry") + '.'));
}
}
});
// override standard enter-action; enter opens the selected entry
entryTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
actionMap.put("Enter", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ae) {
BibEntry entry = sortedEntries.get(entryTable.getSelectedRow());
selectEntryInBasePanel(entry);
}
});
searchResultFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
contentPane.setDividerLocation(0.5f);
}
@Override
public void windowClosing(WindowEvent event) {
dispose();
}
});
searchResultFrame.getContentPane().add(contentPane, BorderLayout.CENTER);
// Remember and default to last size:
SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
searchResultFrame.setSize(searchPreferences.getSeachDialogWidth(), searchPreferences.getSeachDialogHeight());
searchResultFrame.setLocation(searchPreferences.getSearchDialogPosX(), searchPreferences.getSearchDialogPosY());
searchResultFrame.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
new SearchPreferences(Globals.prefs).setSearchDialogWidth(searchResultFrame.getSize().width).setSearchDialogHeight(searchResultFrame.getSize().height);
}
@Override
public void componentMoved(ComponentEvent e) {
new SearchPreferences(Globals.prefs).setSearchDialogPosX(searchResultFrame.getLocation().x).setSearchDialogPosY(searchResultFrame.getLocation().y);
}
});
}
use of javax.swing.ActionMap in project jabref by JabRef.
the class MergeDialog method jbInit.
private void jbInit() {
panel1.setLayout(borderLayout1);
ok.setText(Localization.lang("OK"));
ok.addActionListener(e -> {
okPressed = true;
dispose();
});
cancel.setText(Localization.lang("Cancel"));
cancel.addActionListener(e -> dispose());
jPanel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
jPanel1.setLayout(gridBagLayout1);
entries.setSelected(true);
entries.setText(Localization.lang("Import entries"));
strings.setSelected(true);
strings.setText(Localization.lang("Import strings"));
groups.setText(Localization.lang("Import group definitions"));
selector.setText(Localization.lang("Import word selector definitions"));
this.setModal(true);
this.setResizable(false);
getContentPane().add(panel1);
panel1.add(jPanel2, BorderLayout.SOUTH);
jPanel2.add(ok, null);
jPanel2.add(cancel, null);
panel1.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(entries, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(strings, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(groups, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(selector, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
// Key bindings:
ActionMap am = jPanel1.getActionMap();
InputMap im = jPanel1.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) {
dispose();
}
});
}
use of javax.swing.ActionMap in project binnavi by google.
the class CGraphHotkeys method registerHotKeys.
/**
* Register the default hotkeys of a graph view.
*
* @param parent Parent window used for dialogs.
* @param panel The panel where the view is shown.
* @param debuggerProvider Provides the debugger used by some hotkeys.
* @param searchField The search field that is shown in the graph panel.
* @param addressField The address field that is shown in the graph panel.
*/
public static void registerHotKeys(final JFrame parent, final CGraphPanel panel, final IFrontEndDebuggerProvider debuggerProvider, final CGraphSearchField searchField, final CGotoAddressField addressField) {
Preconditions.checkNotNull(parent, "IE01606: Parent argument can not be null");
Preconditions.checkNotNull(panel, "IE01607: Panel argument can not be null");
Preconditions.checkNotNull(searchField, "IE01608: Search field argument can not be null");
Preconditions.checkNotNull(addressField, "IE01609: Address field argument can not be null");
final InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
final ActionMap actionMap = panel.getActionMap();
inputMap.put(HotKeys.GRAPH_GOTO_ADDRESS_FIELD_KEY.getKeyStroke(), "GOTO_ADDRESS_FIELD");
actionMap.put("GOTO_ADDRESS_FIELD", new AbstractAction() {
/**
* Used for serialization.
*/
private static final long serialVersionUID = -8994014581850287793L;
@Override
public void actionPerformed(final ActionEvent event) {
addressField.requestFocusInWindow();
}
});
inputMap.put(HotKeys.GRAPH_SHOW_HOTKEYS_ACCELERATOR_KEY.getKeyStroke(), "SHOW_HOTKEYS");
actionMap.put("SHOW_HOTKEYS", new CShowHotkeysAction(parent));
registerSearchKeys(panel.getModel().getGraph().getView(), searchField, inputMap, actionMap);
registerDebuggerKeys(panel.getModel().getParent(), panel.getModel().getGraph(), debuggerProvider, inputMap, actionMap);
}
use of javax.swing.ActionMap in project binnavi by google.
the class CRegisterHotKeys method register.
public static <NodeType extends ZyGraphNode<?>> void register(final AbstractZyGraph<NodeType, ?> graph) {
final Graph2DView view = graph.getView();
final Graph2DViewActions actions = new Graph2DViewActions(view);
final ActionMap amap = actions.createActionMap();
final InputMap imap = actions.createDefaultInputMap(amap);
view.setActionMap(amap);
view.setInputMap(JComponent.WHEN_FOCUSED, imap);
view.getCanvasComponent().setActionMap(amap);
view.getCanvasComponent().setInputMap(JComponent.WHEN_FOCUSED, imap);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "DOWN");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "UP");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "LEFT");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "RIGHT");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0), "+");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0), "-");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_M, 0), "m");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_S, 0), "s");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LESS, 0), "<");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK), "SELECT_VISIBLE_NODES");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK), "COPY_CONTENT_FROM_SELECTED_NODES");
amap.remove(Graph2DViewActions.DELETE_SELECTION);
amap.remove(Graph2DViewActions.EDIT_LABEL);
registerActions(graph);
}
use of javax.swing.ActionMap in project binnavi by google.
the class CRegisterHotKeys method registerActions.
public static <NodeType extends ZyGraphNode<?>> void registerActions(final AbstractZyGraph<NodeType, ?> graph) {
final ActionMap amap = graph.getView().getCanvasComponent().getActionMap();
amap.put("DOWN", new CActionHotKey<NodeType>("DOWN", graph));
amap.put("UP", new CActionHotKey<NodeType>("UP", graph));
amap.put("LEFT", new CActionHotKey<NodeType>("LEFT", graph));
amap.put("RIGHT", new CActionHotKey<NodeType>("RIGHT", graph));
amap.put("+", new CActionHotKey<NodeType>("+", graph));
amap.put("-", new CActionHotKey<NodeType>("-", graph));
amap.put("m", new CActionHotKey<NodeType>("m", graph));
amap.put("s", new CActionHotKey<NodeType>("s", graph));
amap.put("<", new CActionHotKey<NodeType>("<", graph));
amap.put("SELECT_VISIBLE_NODES", new CActionHotKey<NodeType>("SELECT_VISIBLE_NODES", graph));
amap.put("COPY_CONTENT_FROM_SELECTED_NODES", new CActionHotKey<NodeType>("COPY_CONTENT_FROM_SELECTED_NODES", graph));
graph.getView().setActionMap(amap);
graph.getView().getCanvasComponent().setActionMap(amap);
}
Aggregations