Search in sources :

Example 11 with JRootPane

use of javax.swing.JRootPane in project omegat by omegat-org.

the class ScriptingWindow method addRunShortcutToOmegaT.

private void addRunShortcutToOmegaT() {
    JRootPane appliRootPane = Core.getMainWindow().getApplicationFrame().getRootPane();
    appliRootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK, false), "RUN_CURRENT_SCRIPT");
    appliRootPane.getActionMap().put("RUN_CURRENT_SCRIPT", new AbstractAction() {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            runScript();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) JRootPane(javax.swing.JRootPane) AbstractAction(javax.swing.AbstractAction)

Example 12 with JRootPane

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

the class FindUnlinkedFilesDialog method createRootPane.

/**
     * Close dialog when pressing escape
     */
@Override
protected JRootPane createRootPane() {
    ActionListener actionListener = actionEvent -> setVisible(false);
    JRootPane rPane = new JRootPane();
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    rPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    return rPane;
}
Also used : Enumeration(java.util.Enumeration) TreeModel(javax.swing.tree.TreeModel) JabRefPreferences(org.jabref.preferences.JabRefPreferences) FileSystemView(javax.swing.filechooser.FileSystemView) Vector(java.util.Vector) ComponentListener(java.awt.event.ComponentListener) MouseAdapter(java.awt.event.MouseAdapter) ChangeListener(javax.swing.event.ChangeListener) JComboBox(javax.swing.JComboBox) Path(java.nio.file.Path) MouseListener(java.awt.event.MouseListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) KeyStroke(javax.swing.KeyStroke) ChangeEvent(javax.swing.event.ChangeEvent) EntryTypes(org.jabref.model.EntryTypes) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) UnlinkedPDFFileFilter(org.jabref.gui.importer.UnlinkedPDFFileFilter) Frame(java.awt.Frame) TreePath(javax.swing.tree.TreePath) BorderFactory(javax.swing.BorderFactory) JabRefGUI(org.jabref.JabRefGUI) GridBagConstraints(java.awt.GridBagConstraints) ComponentEvent(java.awt.event.ComponentEvent) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) BibtexEntryType(org.jabref.model.entry.BibtexEntryType) Component(java.awt.Component) WindowEvent(java.awt.event.WindowEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTaskExecutor(org.jabref.gui.util.DefaultTaskExecutor) Dimension(java.awt.Dimension) List(java.util.List) AbstractAction(javax.swing.AbstractAction) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) LogFactory(org.apache.commons.logging.LogFactory) GridBagLayout(java.awt.GridBagLayout) JabRefExecutorService(org.jabref.JabRefExecutorService) JPanel(javax.swing.JPanel) WindowConstants(javax.swing.WindowConstants) UnlinkedFilesCrawler(org.jabref.gui.importer.UnlinkedFilesCrawler) Insets(java.awt.Insets) ActionListener(java.awt.event.ActionListener) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) TreeNode(javax.swing.tree.TreeNode) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action(javax.swing.Action) SwingConstants(javax.swing.SwingConstants) EntryFromFileCreator(org.jabref.gui.importer.EntryFromFileCreator) ArrayList(java.util.ArrayList) DirectoryDialogConfiguration(org.jabref.gui.util.DirectoryDialogConfiguration) Localization(org.jabref.logic.l10n.Localization) Container(java.awt.Container) LinkedList(java.util.LinkedList) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) JProgressBar(javax.swing.JProgressBar) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) JComponent(javax.swing.JComponent) JRootPane(javax.swing.JRootPane) JButton(javax.swing.JButton) Iterator(java.util.Iterator) Files(java.nio.file.Files) JList(javax.swing.JList) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) JTree(javax.swing.JTree) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) Globals(org.jabref.Globals) ComponentAdapter(java.awt.event.ComponentAdapter) JScrollPane(javax.swing.JScrollPane) FileFilter(java.io.FileFilter) Paths(java.nio.file.Paths) EntryFromFileCreatorManager(org.jabref.gui.importer.EntryFromFileCreatorManager) JLabel(javax.swing.JLabel) Log(org.apache.commons.logging.Log) EntryType(org.jabref.model.entry.EntryType) Collections(java.util.Collections) ActionListener(java.awt.event.ActionListener) KeyStroke(javax.swing.KeyStroke) JRootPane(javax.swing.JRootPane)

Example 13 with JRootPane

use of javax.swing.JRootPane in project JMRI by JMRI.

the class JmriJFrame method setEscapeKeyAction.

/**
     * Bind an action to the Escape key.
     * <p>
     * Binds an AbstractAction to the Escape key. If an action is already bound
     * to the Escape key, that action will be replaced. Passing
     * <code>null</code> unbinds any existing actions from the Escape key.
     * <p>
     * Note that binding the Escape key to any action may break expected or
     * standardized behaviors. See <a
     * href="http://java.sun.com/products/jlf/ed2/book/Appendix.A.html">Keyboard
     * Shortcuts, Mnemonics, and Other Keyboard Operations</a> in the Java Look
     * and Feel Design Guidelines for standardized behaviors.
     *
     * @param action The AbstractAction to bind to.
     * @see #getEscapeKeyAction()
     * @see #setEscapeKeyClosesWindow(boolean)
     */
public void setEscapeKeyAction(AbstractAction action) {
    JRootPane root = this.getRootPane();
    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    // setEscapeKeyClosesWindow will set to true as needed
    escapeKeyActionClosesWindow = false;
    if (action != null) {
        root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, escapeKeyAction);
        root.getActionMap().put(escapeKeyAction, action);
    } else {
        root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(escape);
        root.getActionMap().remove(escapeKeyAction);
    }
}
Also used : KeyStroke(javax.swing.KeyStroke) JRootPane(javax.swing.JRootPane)

Example 14 with JRootPane

use of javax.swing.JRootPane in project JMRI by JMRI.

the class LayoutTurnout method editLayoutTurnout.

/**
     * Edit a Layout Turnout
     */
protected void editLayoutTurnout() {
    if (editOpen) {
        editLayoutTurnoutFrame.setVisible(true);
        return;
    }
    // Initialize if needed
    if (editLayoutTurnoutFrame == null) {
        editLayoutTurnoutFrame = new JmriJFrame(rb.getString("EditTurnout"), false, true);
        editLayoutTurnoutFrame.addHelpMenu("package.jmri.jmrit.display.EditLayoutTurnout", true);
        editLayoutTurnoutFrame.setLocation(50, 30);
        Container contentPane = editLayoutTurnoutFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        // setup turnout name
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        JLabel turnoutNameLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanNameTurnout")));
        panel1.add(turnoutNameLabel);
        // add combobox to select turnout
        firstTurnoutComboBox = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance(), getTurnout(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
        layoutEditor.setupComboBox(firstTurnoutComboBox, true, true);
        panel1.add(firstTurnoutComboBox);
        contentPane.add(panel1);
        JPanel panel1a = new JPanel();
        panel1a.setLayout(new BoxLayout(panel1a, BoxLayout.Y_AXIS));
        secondTurnoutComboBox = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance(), getSecondTurnout(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
        layoutEditor.setupComboBox(secondTurnoutComboBox, true, false);
        additionalTurnout.addActionListener((ActionEvent e) -> {
            if (additionalTurnout.isSelected()) {
                secondTurnoutLabel.setEnabled(true);
                secondTurnoutComboBox.setEnabled(true);
            } else {
                secondTurnoutLabel.setEnabled(false);
                secondTurnoutComboBox.setEnabled(false);
            }
        });
        if ((type != DOUBLE_XOVER) && (type != RH_XOVER) && (type != LH_XOVER)) {
            additionalTurnout.setText(rb.getString("ThrowTwoTurnouts"));
        }
        panel1a.add(additionalTurnout);
        contentPane.add(panel1a);
        secondTurnoutLabel = new JLabel(Bundle.getMessage("Supporting", Bundle.getMessage("BeanNameTurnout")));
        secondTurnoutLabel.setEnabled(false);
        secondTurnoutComboBox.setEnabled(false);
        JPanel panel1b = new JPanel();
        panel1b.add(secondTurnoutLabel);
        panel1b.add(secondTurnoutComboBox);
        contentPane.add(panel1b);
        // add continuing state choice, if not crossover
        if ((type != DOUBLE_XOVER) && (type != RH_XOVER) && (type != LH_XOVER)) {
            JPanel panel3 = new JPanel();
            panel3.setLayout(new FlowLayout());
            stateBox.removeAllItems();
            stateBox.addItem(InstanceManager.turnoutManagerInstance().getClosedText());
            turnoutClosedIndex = 0;
            stateBox.addItem(InstanceManager.turnoutManagerInstance().getThrownText());
            turnoutThrownIndex = 1;
            stateBox.setToolTipText(rb.getString("StateToolTip"));
            panel3.add(new JLabel(rb.getString("ContinuingState")));
            panel3.add(stateBox);
            contentPane.add(panel3);
        }
        JPanel panel33 = new JPanel();
        panel33.setLayout(new FlowLayout());
        hiddenBox.setToolTipText(rb.getString("HiddenToolTip"));
        panel33.add(hiddenBox);
        contentPane.add(panel33);
        TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
        border.setTitle(Bundle.getMessage("BeanNameBlock"));
        // setup block name
        JPanel panel2 = new JPanel();
        panel2.setBorder(border);
        panel2.setLayout(new FlowLayout());
        panel2.add(blockNameComboBox);
        layoutEditor.setupComboBox(blockNameComboBox, false, true);
        blockNameComboBox.setToolTipText(rb.getString("EditBlockNameHint"));
        panel2.add(turnoutEditBlock = new JButton(rb.getString("CreateEdit")));
        turnoutEditBlock.addActionListener((ActionEvent e) -> {
            turnoutEditBlockPressed(e);
        });
        contentPane.add(panel2);
        if ((type == DOUBLE_XOVER) || (type == RH_XOVER) || (type == LH_XOVER)) {
            JPanel panel21 = new JPanel();
            panel21.setLayout(new FlowLayout());
            TitledBorder borderblk2 = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
            borderblk2.setTitle(Bundle.getMessage("BeanNameBlock") + " 2");
            panel21.setBorder(borderblk2);
            layoutEditor.setupComboBox(blockBNameComboBox, false, true);
            blockBNameComboBox.setToolTipText(rb.getString("EditBlockBNameHint"));
            panel21.add(blockBNameComboBox);
            panel21.add(turnoutEditBlockB = new JButton(rb.getString("CreateEdit")));
            turnoutEditBlockB.addActionListener((ActionEvent e) -> {
                turnoutEditBlockBPressed(e);
            });
            turnoutEditBlockB.setToolTipText(Bundle.getMessage("EditBlockHint", "2"));
            contentPane.add(panel21);
            JPanel panel22 = new JPanel();
            panel22.setLayout(new FlowLayout());
            TitledBorder borderblk3 = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
            borderblk3.setTitle(Bundle.getMessage("BeanNameBlock") + " 3");
            panel22.setBorder(borderblk3);
            layoutEditor.setupComboBox(blockCNameComboBox, false, true);
            blockCNameComboBox.setToolTipText(rb.getString("EditBlockCNameHint"));
            panel22.add(blockCNameComboBox);
            panel22.add(turnoutEditBlockC = new JButton(rb.getString("CreateEdit")));
            turnoutEditBlockC.addActionListener((ActionEvent e) -> {
                turnoutEditBlockCPressed(e);
            });
            turnoutEditBlockC.setToolTipText(Bundle.getMessage("EditBlockHint", "3"));
            contentPane.add(panel22);
            JPanel panel23 = new JPanel();
            panel23.setLayout(new FlowLayout());
            TitledBorder borderblk4 = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
            borderblk4.setTitle(Bundle.getMessage("BeanNameBlock") + " 4");
            panel23.setBorder(borderblk4);
            layoutEditor.setupComboBox(blockDNameComboBox, false, true);
            blockDNameComboBox.setToolTipText(rb.getString("EditBlockDNameHint"));
            panel23.add(blockDNameComboBox);
            panel23.add(turnoutEditBlockD = new JButton(rb.getString("CreateEdit")));
            turnoutEditBlockD.addActionListener((ActionEvent e) -> {
                turnoutEditBlockDPressed(e);
            });
            turnoutEditBlockD.setToolTipText(Bundle.getMessage("EditBlockHint", "4"));
            contentPane.add(panel23);
        }
        // set up Edit Block, Done and Cancel buttons
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout());
        // Edit Block
        // empty value for block 1
        turnoutEditBlock.setToolTipText(Bundle.getMessage("EditBlockHint", ""));
        // Done
        panel5.add(turnoutEditDone = new JButton(Bundle.getMessage("ButtonDone")));
        // make this button the default button (return or enter activates)
        // Note: We have to invoke this later because we don't currently have a root pane
        SwingUtilities.invokeLater(() -> {
            JRootPane rootPane = SwingUtilities.getRootPane(turnoutEditDone);
            rootPane.setDefaultButton(turnoutEditDone);
        });
        turnoutEditDone.addActionListener((ActionEvent e) -> {
            turnoutEditDonePressed(e);
        });
        turnoutEditDone.setToolTipText(Bundle.getMessage("DoneHint", Bundle.getMessage("ButtonDone")));
        // Cancel
        panel5.add(turnoutEditCancel = new JButton(Bundle.getMessage("ButtonCancel")));
        turnoutEditCancel.addActionListener((ActionEvent e) -> {
            turnoutEditCancelPressed(e);
        });
        turnoutEditCancel.setToolTipText(Bundle.getMessage("CancelHint", Bundle.getMessage("ButtonCancel")));
        contentPane.add(panel5);
    }
    hiddenBox.setSelected(hidden);
    // Set up for Edit
    blockNameComboBox.getEditor().setItem(blockName);
    if ((type == DOUBLE_XOVER) || (type == RH_XOVER) || (type == LH_XOVER)) {
        blockBNameComboBox.getEditor().setItem(blockBName);
        blockCNameComboBox.getEditor().setItem(blockCName);
        blockDNameComboBox.getEditor().setItem(blockDName);
    }
    firstTurnoutComboBox.setSelectedItem(turnoutName);
    if (secondNamedTurnout != null) {
        additionalTurnout.setSelected(true);
        secondTurnoutLabel.setEnabled(true);
        secondTurnoutComboBox.setEnabled(true);
    }
    if ((type != DOUBLE_XOVER) && (type != RH_XOVER) && (type != LH_XOVER)) {
        if (continuingSense == Turnout.CLOSED) {
            stateBox.setSelectedIndex(turnoutClosedIndex);
        } else {
            stateBox.setSelectedIndex(turnoutThrownIndex);
        }
    }
    editLayoutTurnoutFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            turnoutEditCancelPressed(null);
        }
    });
    editLayoutTurnoutFrame.pack();
    editLayoutTurnoutFrame.setVisible(true);
    editOpen = true;
    needsBlockUpdate = false;
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) TitledBorder(javax.swing.border.TitledBorder) Container(java.awt.Container) JmriBeanComboBox(jmri.util.swing.JmriBeanComboBox) JmriJFrame(jmri.util.JmriJFrame) JRootPane(javax.swing.JRootPane)

Example 15 with JRootPane

use of javax.swing.JRootPane in project JMRI by JMRI.

the class LayoutTurntable method editTurntable.

/**
     * Edit a Turntable
     */
protected void editTurntable(LayoutTurntable x) {
    if (editOpen) {
        editTurntableFrame.setVisible(true);
        return;
    }
    needsRedraw = false;
    // Initialize if needed
    if (editTurntableFrame == null) {
        editTurntableFrame = new JmriJFrame(rb.getString("EditTurntable"), false, true);
        editTurntableFrame.addHelpMenu("package.jmri.jmrit.display.EditTurntable", true);
        editTurntableFrame.setLocation(50, 30);
        Container contentPane = editTurntableFrame.getContentPane();
        JPanel headerPane = new JPanel();
        JPanel footerPane = new JPanel();
        headerPane.setLayout(new BoxLayout(headerPane, BoxLayout.Y_AXIS));
        footerPane.setLayout(new BoxLayout(footerPane, BoxLayout.Y_AXIS));
        contentPane.setLayout(new BorderLayout());
        contentPane.add(headerPane, BorderLayout.NORTH);
        contentPane.add(footerPane, BorderLayout.SOUTH);
        // setup radius
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        JLabel radiusLabel = new JLabel(rb.getString("TurntableRadius"));
        panel1.add(radiusLabel);
        panel1.add(radiusField);
        radiusField.setToolTipText(rb.getString("TurntableRadiusHint"));
        headerPane.add(panel1);
        // setup add ray track
        JPanel panel2 = new JPanel();
        panel2.setLayout(new FlowLayout());
        JLabel rayAngleLabel = new JLabel(rb.getString("RayAngle"));
        panel2.add(rayAngleLabel);
        panel2.add(angleField);
        angleField.setToolTipText(rb.getString("RayAngleHint"));
        headerPane.add(panel2);
        JPanel panel3 = new JPanel();
        panel3.setLayout(new FlowLayout());
        panel3.add(addRayTrack = new JButton(rb.getString("AddRayTrack")));
        addRayTrack.setToolTipText(rb.getString("AddRayTrackHint"));
        addRayTrack.addActionListener((ActionEvent e) -> {
            addRayTrackPressed(e);
            updateRayPanel();
        });
        panel3.add(dccControlled = new JCheckBox(rb.getString("TurntableDCCControlled")));
        dccControlled.setSelected(isTurnoutControlled());
        dccControlled.addActionListener((ActionEvent e) -> {
            setTurnoutControlled(dccControlled.isSelected());
            for (RayTrack rt : rayList) {
                rt.showTurnoutDetails();
            }
            editTurntableFrame.pack();
        });
        headerPane.add(panel3);
        // set up Done and Cancel buttons
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout());
        panel5.add(turntableEditDone = new JButton(Bundle.getMessage("ButtonDone")));
        turntableEditDone.addActionListener((ActionEvent e) -> {
            turntableEditDonePressed(e);
        });
        // make this button the default button (return or enter activates)
        // Note: We have to invoke this later because we don't currently have a root pane
        SwingUtilities.invokeLater(() -> {
            JRootPane rootPane = SwingUtilities.getRootPane(turntableEditDone);
            rootPane.setDefaultButton(turntableEditDone);
        });
        turntableEditDone.setToolTipText(Bundle.getMessage("DoneHint", Bundle.getMessage("ButtonDone")));
        // Cancel
        panel5.add(turntableEditCancel = new JButton(Bundle.getMessage("ButtonCancel")));
        turntableEditCancel.addActionListener((ActionEvent e) -> {
            turntableEditCancelPressed(e);
        });
        turntableEditCancel.setToolTipText(Bundle.getMessage("CancelHint", Bundle.getMessage("ButtonCancel")));
        footerPane.add(panel5);
        rayPanel = new JPanel();
        rayPanel.setLayout(new BoxLayout(rayPanel, BoxLayout.Y_AXIS));
        for (RayTrack rt : rayList) {
            rayPanel.add(rt.getPanel());
        }
        JScrollPane rayScrollPane = new JScrollPane(rayPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        contentPane.add(rayScrollPane, BorderLayout.CENTER);
    } else {
        updateRayPanel();
    }
    // Set up for Edit
    radiusField.setText(" " + radius);
    oldRadius = radiusField.getText();
    angleField.setText("0");
    editTurntableFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            turntableEditCancelPressed(null);
        }
    });
    editTurntableFrame.pack();
    editTurntableFrame.setVisible(true);
    editOpen = true;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) JmriJFrame(jmri.util.JmriJFrame) JRootPane(javax.swing.JRootPane)

Aggregations

JRootPane (javax.swing.JRootPane)90 ActionEvent (java.awt.event.ActionEvent)48 KeyStroke (javax.swing.KeyStroke)35 AbstractAction (javax.swing.AbstractAction)32 Action (javax.swing.Action)29 InputMap (javax.swing.InputMap)26 JPanel (javax.swing.JPanel)16 BorderLayout (java.awt.BorderLayout)14 JButton (javax.swing.JButton)13 ActionListener (java.awt.event.ActionListener)12 JLabel (javax.swing.JLabel)12 Container (java.awt.Container)10 FlowLayout (java.awt.FlowLayout)10 Dimension (java.awt.Dimension)9 Insets (java.awt.Insets)9 BoxLayout (javax.swing.BoxLayout)9 Component (java.awt.Component)8 Frame (java.awt.Frame)7 JScrollPane (javax.swing.JScrollPane)7 GridBagConstraints (java.awt.GridBagConstraints)6