Search in sources :

Example 41 with InputMap

use of javax.swing.InputMap in project jabref by JabRef.

the class BasicAction method jbInit.

private void jbInit() {
    getContentPane().setLayout(new BorderLayout());
    StringBuilder typeStr = new StringBuilder("Plain text import");
    if (entry.getType() != null) {
        typeStr.append(' ').append(Localization.lang("for")).append(' ').append(entry.getType());
    }
    this.setTitle(typeStr.toString());
    getContentPane().add(panel1, BorderLayout.CENTER);
    initRawPanel();
    initButtonPanel();
    initSourcePanel();
    JTabbedPane tabbed = new JTabbedPane();
    tabbed.add(rawPanel, Localization.lang("Raw source"));
    tabbed.add(sourcePanel, Localization.lang("%0 source", frame.getCurrentBasePanel().getBibDatabaseContext().getMode().getFormattedName()));
    // Panel Layout
    panel1.setLayout(new BorderLayout());
    panel1.add(tabbed, BorderLayout.CENTER);
    panel1.add(buttons, BorderLayout.SOUTH);
    // Key bindings:
    ActionMap am = buttons.getActionMap();
    InputMap im = buttons.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();
        }
    });
}
Also used : BorderLayout(java.awt.BorderLayout) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 42 with InputMap

use of javax.swing.InputMap in project jabref by JabRef.

the class ProtectedTermsDialog method init.

private void init() {
    setupPopupMenu();
    loadButton.addActionListener(actionEvent -> {
        AddFileDialog addDialog = new AddFileDialog();
        addDialog.setVisible(true);
        addDialog.getFileName().ifPresent(fileName -> loader.addProtectedTermsListFromFile(fileName, true));
        tableModel.fireTableDataChanged();
    });
    loadButton.setToolTipText(Localization.lang("Add protected terms file"));
    removeButton.addActionListener(removeAction);
    removeButton.setToolTipText(Localization.lang("Remove protected terms file"));
    newButton.addActionListener(actionEvent -> {
        NewProtectedTermsFileDialog newDialog = new NewProtectedTermsFileDialog(diag, loader);
        newDialog.setVisible(true);
        tableModel.fireTableDataChanged();
    });
    newButton.setToolTipText(Localization.lang("New protected terms file"));
    setupTable();
    // Build dialog
    diag = new JDialog(frame, Localization.lang("Manage protected terms files"), true);
    FormBuilder builder = FormBuilder.create();
    builder.layout(new FormLayout("fill:pref:grow, 4dlu, left:pref, 4dlu, left:pref, 4dlu, left:pref", "100dlu:grow, 4dlu, pref"));
    builder.add(new JScrollPane(table)).xyw(1, 1, 7);
    builder.add(newButton).xy(3, 3);
    builder.add(loadButton).xy(5, 3);
    builder.add(removeButton).xy(7, 3);
    builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
    diag.add(builder.getPanel(), BorderLayout.CENTER);
    AbstractAction okListener = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // Write changes to preferences
            storePreferences();
            diag.dispose();
        }
    };
    ok.addActionListener(okListener);
    Action cancelListener = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // Restore from preferences
            loader.update(Globals.prefs.getProtectedTermsPreferences());
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelListener);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.add(bb.getPanel(), BorderLayout.SOUTH);
    ActionMap am = bb.getPanel().getActionMap();
    InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelListener);
    im.put(KeyStroke.getKeyStroke("ENTER"), "enterOk");
    am.put("enterOk", okListener);
    diag.pack();
    WindowLocation pw = new WindowLocation(diag, JabRefPreferences.TERMS_POS_X, JabRefPreferences.TERMS_POS_Y, JabRefPreferences.TERMS_SIZE_X, JabRefPreferences.TERMS_SIZE_Y);
    pw.displayWindowAtStoredLocation();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JScrollPane(javax.swing.JScrollPane) FormBuilder(com.jgoodies.forms.builder.FormBuilder) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) InputMap(javax.swing.InputMap) WindowLocation(org.jabref.gui.util.WindowLocation) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 43 with InputMap

use of javax.swing.InputMap in project jabref by JabRef.

the class PushToApplicationButton method showSettingsDialog.

public static void showSettingsDialog(JFrame parent, PushToApplication toApp, JPanel options) {
    final BooleanHolder okPressed = new BooleanHolder(false);
    final JDialog diag = new JDialog(parent, Localization.lang("Settings"), true);
    options.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.getContentPane().add(options, BorderLayout.CENTER);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    ok.addActionListener(e -> {
        okPressed.value = true;
        diag.dispose();
    });
    cancel.addActionListener(e -> diag.dispose());
    // Key bindings:
    ActionMap am = bb.getPanel().getActionMap();
    InputMap im = bb.getPanel().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) {
            diag.dispose();
        }
    });
    diag.pack();
    diag.setLocationRelativeTo(parent);
    // Show the dialog:
    diag.setVisible(true);
    // to store its settings:
    if (okPressed.value) {
        toApp.storeSettings();
    }
}
Also used : ActionMap(javax.swing.ActionMap) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 44 with InputMap

use of javax.swing.InputMap in project adempiere by adempiere.

the class AdempiereButtonListener method updateMnemonicBindingX.

//	propertyChange
/**
	 * 	Update Mnemonic Binding
	 *	@param b button
	 */
void updateMnemonicBindingX(AbstractButton b) {
    int m = b.getMnemonic();
    if (m != 0) {
        InputMap map = SwingUtilities.getUIInputMap(b, JComponent.WHEN_IN_FOCUSED_WINDOW);
        if (map == null) {
            map = new ComponentInputMapUIResource(b);
            SwingUtilities.replaceUIInputMap(b, JComponent.WHEN_IN_FOCUSED_WINDOW, map);
        }
        map.clear();
        String className = b.getClass().getName();
        //	Default Buttons
        int mask = InputEvent.ALT_MASK;
        if (//	In Tab
        b instanceof JCheckBox || className.indexOf("VButton") != -1)
            mask = InputEvent.SHIFT_MASK + InputEvent.CTRL_MASK;
        map.put(KeyStroke.getKeyStroke(m, mask, false), "pressed");
        map.put(KeyStroke.getKeyStroke(m, mask, true), "released");
        map.put(KeyStroke.getKeyStroke(m, 0, true), "released");
    } else {
        InputMap map = SwingUtilities.getUIInputMap(b, JComponent.WHEN_IN_FOCUSED_WINDOW);
        if (map != null)
            map.clear();
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) ComponentInputMapUIResource(javax.swing.plaf.ComponentInputMapUIResource) InputMap(javax.swing.InputMap)

Example 45 with InputMap

use of javax.swing.InputMap in project adempiere by adempiere.

the class AdempiereLabelUI method installKeyboardActions.

//	createUI
/**
	 * 	Install Keyboard Actions
	 *	@param l label
	 */
protected void installKeyboardActions(JLabel l) {
    //	super.installKeyboardActions(l);
    int dka = l.getDisplayedMnemonic();
    if (dka != 0) {
        Component lf = l.getLabelFor();
        if (lf != null) {
            ActionMap actionMap = l.getActionMap();
            actionMap.put(PRESS, ACTION_PRESS);
            InputMap inputMap = SwingUtilities.getUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW);
            if (inputMap == null) {
                inputMap = new ComponentInputMapUIResource(l);
                SwingUtilities.replaceUIInputMap(l, JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);
            }
            inputMap.clear();
            inputMap.put(KeyStroke.getKeyStroke(dka, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK, false), PRESS);
        }
    }
}
Also used : ComponentInputMapUIResource(javax.swing.plaf.ComponentInputMapUIResource) ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

InputMap (javax.swing.InputMap)59 ActionMap (javax.swing.ActionMap)38 AbstractAction (javax.swing.AbstractAction)32 ActionEvent (java.awt.event.ActionEvent)30 Action (javax.swing.Action)18 JButton (javax.swing.JButton)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 BorderLayout (java.awt.BorderLayout)9 JPanel (javax.swing.JPanel)9 JCheckBox (javax.swing.JCheckBox)8 JDialog (javax.swing.JDialog)8 JScrollPane (javax.swing.JScrollPane)8 JTextField (javax.swing.JTextField)7 KeyStroke (javax.swing.KeyStroke)7 JComponent (javax.swing.JComponent)6 JRootPane (javax.swing.JRootPane)6 FormBuilder (com.jgoodies.forms.builder.FormBuilder)5 FormLayout (com.jgoodies.forms.layout.FormLayout)5 ComponentInputMapUIResource (javax.swing.plaf.ComponentInputMapUIResource)5 Insets (java.awt.Insets)4