Example usage for javax.swing JToolBar getInputMap

List of usage examples for javax.swing JToolBar getInputMap

Introduction

In this page you can find the example usage for javax.swing JToolBar getInputMap.

Prototype

public final InputMap getInputMap(int condition) 

Source Link

Document

Returns the InputMap that is used during condition.

Usage

From source file:net.sf.jabref.gui.entryeditor.EntryEditor.java

private void setupToolBar() {
    JPanel leftPan = new JPanel();
    leftPan.setLayout(new BorderLayout());
    JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL);

    toolBar.setBorder(null);//from  ww  w .  j  a v a 2s  .co m
    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", getStoreFieldAction());
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), "generateKey");
    actionMap.put("generateKey", getGenerateKeyAction());
    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", getPrevEntryAction());
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_ENTRY), "next");
    actionMap.put("next", getNextEntryAction());
    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", getHelpAction());

    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, Optional.empty(),
            panel.getBibDatabaseContext().getMode());
    leftPan.add(new TypeLabel(typedEntry.getTypeForDisplay()), BorderLayout.CENTER);
    TypeButton typeButton = new TypeButton();

    toolBar.add(typeButton);
    toolBar.add(getGenerateKeyAction());
    toolBar.add(autoLinkAction);

    toolBar.add(writeXmp);

    toolBar.addSeparator();

    toolBar.add(deleteAction);
    toolBar.add(getPrevEntryAction());
    toolBar.add(getNextEntryAction());

    toolBar.addSeparator();

    toolBar.add(getHelpAction());

    Component[] comps = toolBar.getComponents();

    for (Component comp : comps) {
        ((JComponent) comp).setOpaque(false);
    }

    leftPan.add(toolBar, BorderLayout.SOUTH);
    add(leftPan, BorderLayout.WEST);
}

From source file:net.sf.jabref.EntryEditor.java

/**
 * Create toolbar for entry editor./*from  w  w  w  .  j a  v a 2  s .com*/
 */
private void setupToolBar() {
    JToolBar tlb = new JToolBar(JToolBar.VERTICAL);
    CloseAction closeAction = new CloseAction();
    ;
    StoreFieldAction storeFieldAction = new StoreFieldAction();
    DeleteAction deleteAction = new DeleteAction();
    UndoAction undoAction = new UndoAction();
    RedoAction redoAction = new RedoAction();

    tlb.setBorder(null);
    tlb.setRollover(true);
    tlb.setMargin(new Insets(0, 0, 0, 2));
    tlb.setFloatable(false);
    tlb.addSeparator();
    tlb.add(deleteAction);
    tlb.addSeparator();
    tlb.add(prevEntryAction);
    tlb.add(nextEntryAction);
    tlb.addSeparator();
    tlb.add(helpAction);
    for (Component comp : tlb.getComponents()) {
        ((JComponent) comp).setOpaque(false);
    }

    // The toolbar carries all the key bindings that are valid for the whole window.
    ActionMap am = tlb.getActionMap();
    InputMap im = tlb.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(prefs.getKey("Close entry editor"), "close");
    am.put("close", closeAction);
    im.put(prefs.getKey("Entry editor, store field"), "store");
    am.put("store", storeFieldAction);
    im.put(prefs.getKey("Entry editor, previous entry"), "prev");
    am.put("prev", prevEntryAction);
    im.put(prefs.getKey("Entry editor, next entry"), "next");
    am.put("next", nextEntryAction);
    im.put(prefs.getKey("Undo"), "undo");
    am.put("undo", undoAction);
    im.put(prefs.getKey("Redo"), "redo");
    am.put("redo", redoAction);
    im.put(prefs.getKey("Help"), "help");
    am.put("help", helpAction);

    // Add actions (and thus buttons)
    JButton closeBut = new JButton(closeAction);
    closeBut.setText(null);
    closeBut.setBorder(null);

    // Create type-label
    TypeLabel typeLabel = new TypeLabel(entry.getType().getName());

    JPanel leftPan = new JPanel();
    leftPan.setLayout(new BorderLayout());
    leftPan.add(closeBut, BorderLayout.NORTH);
    leftPan.add(typeLabel, BorderLayout.CENTER);
    leftPan.add(tlb, BorderLayout.SOUTH);

    add(leftPan, BorderLayout.WEST);
}