Search in sources :

Example 61 with JRootPane

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

the class LevelXing method editLevelXing.

/**
     * Edit a Level Crossing
     */
protected void editLevelXing(LevelXing o) {
    if (editOpen) {
        editLevelXingFrame.setVisible(true);
        return;
    }
    // Initialize if needed
    if (editLevelXingFrame == null) {
        editLevelXingFrame = new JmriJFrame(rb.getString("EditXing"), false, true);
        editLevelXingFrame.addHelpMenu("package.jmri.jmrit.display.EditLevelXing", true);
        editLevelXingFrame.setLocation(50, 30);
        Container contentPane = editLevelXingFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        JPanel panel33 = new JPanel();
        panel33.setLayout(new FlowLayout());
        hiddenBox.setToolTipText(rb.getString("HiddenToolTip"));
        panel33.add(hiddenBox);
        contentPane.add(panel33);
        // setup block 1 name
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        JLabel block1NameLabel = new JLabel(Bundle.getMessage("Block_ID", 1));
        panel1.add(block1NameLabel);
        panel1.add(block1NameComboBox);
        layoutEditor.setupComboBox(block1NameComboBox, false, true);
        block1NameComboBox.setToolTipText(rb.getString("EditBlockNameHint"));
        contentPane.add(panel1);
        // setup block 2 name
        JPanel panel2 = new JPanel();
        panel2.setLayout(new FlowLayout());
        JLabel block2NameLabel = new JLabel(Bundle.getMessage("Block_ID", 2));
        panel2.add(block2NameLabel);
        panel2.add(block2NameComboBox);
        layoutEditor.setupComboBox(block2NameComboBox, false, true);
        block2NameComboBox.setToolTipText(rb.getString("EditBlockNameHint"));
        contentPane.add(panel2);
        // set up Edit 1 Block and Edit 2 Block buttons
        JPanel panel4 = new JPanel();
        panel4.setLayout(new FlowLayout());
        // Edit 1 Block
        panel4.add(xingEdit1Block = new JButton(Bundle.getMessage("EditBlock", 1)));
        xingEdit1Block.addActionListener((ActionEvent e) -> {
            xingEdit1BlockPressed(e);
        });
        // empty value for block 1
        xingEdit1Block.setToolTipText(Bundle.getMessage("EditBlockHint", ""));
        // Edit 2 Block
        panel4.add(xingEdit2Block = new JButton(Bundle.getMessage("EditBlock", 2)));
        xingEdit2Block.addActionListener((ActionEvent e) -> {
            xingEdit2BlockPressed(e);
        });
        // empty value for block 1
        xingEdit2Block.setToolTipText(Bundle.getMessage("EditBlockHint", ""));
        contentPane.add(panel4);
        // set up Done and Cancel buttons
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout());
        panel5.add(xingEditDone = new JButton(Bundle.getMessage("ButtonDone")));
        xingEditDone.addActionListener((ActionEvent e) -> {
            xingEditDonePressed(e);
        });
        xingEditDone.setToolTipText(Bundle.getMessage("DoneHint", 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(xingEditDone);
            rootPane.setDefaultButton(xingEditDone);
        });
        // Cancel
        panel5.add(xingEditCancel = new JButton(Bundle.getMessage("ButtonCancel")));
        xingEditCancel.addActionListener((ActionEvent e) -> {
            xingEditCancelPressed(e);
        });
        xingEditCancel.setToolTipText(Bundle.getMessage("CancelHint", Bundle.getMessage("ButtonCancel")));
        contentPane.add(panel5);
    }
    hiddenBox.setSelected(hidden);
    // Set up for Edit
    block1NameComboBox.getEditor().setItem(blockNameAC);
    block2NameComboBox.getEditor().setItem(blockNameBD);
    editLevelXingFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            xingEditCancelPressed(null);
        }
    });
    editLevelXingFrame.pack();
    editLevelXingFrame.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) Container(java.awt.Container) JmriJFrame(jmri.util.JmriJFrame) JRootPane(javax.swing.JRootPane)

Example 62 with JRootPane

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

the class LayoutSlip method editLayoutSlip.

/**
     * Edit a Slip
     */
protected void editLayoutSlip(LayoutTurnout o) {
    if (editOpen) {
        editLayoutTurnoutFrame.setVisible(true);
        return;
    }
    // Initialize if needed
    if (editLayoutTurnoutFrame == null) {
        editLayoutTurnoutFrame = new JmriJFrame(rb.getString("EditSlip"), false, true);
        editLayoutTurnoutFrame.addHelpMenu("package.jmri.jmrit.display.EditLayoutSlip", true);
        editLayoutTurnoutFrame.setLocation(50, 30);
        Container contentPane = editLayoutTurnoutFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        JLabel turnoutNameLabel = new JLabel(Bundle.getMessage("BeanNameTurnout") + " A " + Bundle.getMessage("Name"));
        turnoutAComboBox = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance(), getTurnout(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
        panel1.add(turnoutNameLabel);
        panel1.add(turnoutAComboBox);
        contentPane.add(panel1);
        JPanel panel1a = new JPanel();
        panel1a.setLayout(new FlowLayout());
        JLabel turnoutBNameLabel = new JLabel(Bundle.getMessage("BeanNameTurnout") + " B " + Bundle.getMessage("Name"));
        turnoutBComboBox = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance(), getTurnoutB(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
        panel1a.add(turnoutBNameLabel);
        panel1a.add(turnoutBComboBox);
        contentPane.add(panel1a);
        JPanel panel2 = new JPanel();
        panel2.setLayout(new GridLayout(0, 3, 2, 2));
        panel2.add(new Label("   "));
        panel2.add(new Label(Bundle.getMessage("BeanNameTurnout") + " A:"));
        panel2.add(new Label(Bundle.getMessage("BeanNameTurnout") + " B:"));
        for (Entry<Integer, TurnoutState> ts : turnoutStates.entrySet()) {
            SampleStates draw = new SampleStates(ts.getKey());
            draw.repaint();
            draw.setPreferredSize(new Dimension(40, 40));
            panel2.add(draw);
            panel2.add(ts.getValue().getComboA());
            panel2.add(ts.getValue().getComboB());
        }
        testPanel = new TestState();
        testPanel.setSize(40, 40);
        testPanel.setPreferredSize(new Dimension(40, 40));
        panel2.add(testPanel);
        JButton testButton = new JButton("Test");
        testButton.addActionListener((ActionEvent e) -> {
            toggleStateTest();
        });
        panel2.add(testButton);
        contentPane.add(panel2);
        JPanel panel33 = new JPanel();
        panel33.setLayout(new FlowLayout());
        hiddenBox.setToolTipText(rb.getString("HiddenToolTip"));
        panel33.add(hiddenBox);
        contentPane.add(panel33);
        // setup block name
        JPanel panel3 = new JPanel();
        panel3.setLayout(new FlowLayout());
        JLabel block1NameLabel = new JLabel(rb.getString("BlockID"));
        panel3.add(block1NameLabel);
        panel3.add(blockNameComboBox);
        layoutEditor.setupComboBox(blockNameComboBox, false, true);
        blockNameComboBox.setToolTipText(rb.getString("EditBlockNameHint"));
        contentPane.add(panel3);
        // set up Edit Block buttons
        JPanel panel4 = new JPanel();
        panel4.setLayout(new FlowLayout());
        // Edit Block
        panel4.add(turnoutEditBlock = new JButton(Bundle.getMessage("EditBlock", "")));
        turnoutEditBlock.addActionListener((ActionEvent event) -> {
            turnoutEditBlockPressed(event);
        });
        // empty value for block 1
        turnoutEditBlock.setToolTipText(Bundle.getMessage("EditBlockHint", ""));
        contentPane.add(panel4);
        // set up Done and Cancel buttons
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout());
        panel5.add(slipEditDone = 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(slipEditDone);
            rootPane.setDefaultButton(slipEditDone);
        });
        slipEditDone.addActionListener((ActionEvent event) -> {
            slipEditDonePressed(event);
        });
        slipEditDone.setToolTipText(Bundle.getMessage("DoneHint", Bundle.getMessage("ButtonDone")));
        // Cancel
        panel5.add(slipEditCancel = new JButton(Bundle.getMessage("ButtonCancel")));
        slipEditCancel.addActionListener((ActionEvent event) -> {
            slipEditCancelPressed(event);
        });
        slipEditCancel.setToolTipText(Bundle.getMessage("CancelHint", Bundle.getMessage("ButtonCancel")));
        contentPane.add(panel5);
    }
    hiddenBox.setSelected(hidden);
    // Set up for Edit
    blockNameComboBox.getEditor().setItem(blockName);
    editLayoutTurnoutFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            slipEditCancelPressed(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) Label(java.awt.Label) JLabel(javax.swing.JLabel) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Container(java.awt.Container) JmriBeanComboBox(jmri.util.swing.JmriBeanComboBox) GridLayout(java.awt.GridLayout) JmriJFrame(jmri.util.JmriJFrame) JRootPane(javax.swing.JRootPane)

Example 63 with JRootPane

use of javax.swing.JRootPane in project pcgen by PCGen.

the class Utility method installEscapeCloseOperation.

/**
	 * Add a keyboard shortcut to allow ESC to close the dialog.
	 *
	 * @param dialog The dialog to be updated.
	 */
public static void installEscapeCloseOperation(final JDialog dialog) {
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey);
    Action dispatchClosing = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing);
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) JRootPane(javax.swing.JRootPane) AbstractAction(javax.swing.AbstractAction)

Example 64 with JRootPane

use of javax.swing.JRootPane in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method createJSONEditorComposite.

private Composite createJSONEditorComposite(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    if (isWindows()) {
        Composite embedComposite = new Composite(composite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
        final GridLayout gridLayout = new GridLayout();
        gridLayout.verticalSpacing = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginHeight = 0;
        gridLayout.horizontalSpacing = 0;
        embedComposite.setLayout(gridLayout);
        embedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        Frame frame = SWT_AWT.new_Frame(embedComposite);
        Panel heavyWeightPanel = new Panel();
        heavyWeightPanel.setLayout(new BoxLayout(heavyWeightPanel, BoxLayout.Y_AXIS));
        frame.add(heavyWeightPanel);
        frame.setFocusTraversalKeysEnabled(false);
        // Use JApplet with JRootPane as layer in between heavyweightPanel and RTextScrollPane
        // This reduces flicker on resize in RSyntaxTextArea
        JApplet applet = new JApplet();
        JRootPane root = applet.getRootPane();
        Container contentPane = root.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        heavyWeightPanel.add(applet);
        m_textArea = new RSyntaxTextArea(10, 60);
        m_textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
        m_textArea.setCodeFoldingEnabled(true);
        m_textArea.setAntiAliasingEnabled(true);
        RTextScrollPane sp = new RTextScrollPane(m_textArea);
        sp.setDoubleBuffered(true);
        m_textArea.setText(m_jsonDocument);
        m_textArea.setEditable(true);
        m_textArea.setEnabled(true);
        contentPane.add(sp);
        Dimension size = sp.getPreferredSize();
        embedComposite.setSize(size.width, size.height);
        // forward focus to RSyntaxTextArea
        embedComposite.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(final FocusEvent e) {
                ViewUtils.runOrInvokeLaterInEDT(new Runnable() {

                    @Override
                    public void run() {
                        m_textArea.requestFocus();
                        m_textArea.setCaretPosition(m_caretPosition);
                    }
                });
            }

            @Override
            public void focusLost(final FocusEvent e) {
            // do nothing
            }
        });
        // delete content of status line, when something is inserted or deleted
        m_textArea.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void changedUpdate(final DocumentEvent arg0) {
                if (!composite.isDisposed()) {
                    composite.getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (m_statusLine != null && !m_statusLine.isDisposed()) {
                                m_statusLine.setText("");
                                updateModelFromJson();
                            }
                        }
                    });
                }
            }

            @Override
            public void insertUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }

            @Override
            public void removeUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }
        });
        // remember caret position
        m_textArea.addCaretListener(new CaretListener() {

            @Override
            public void caretUpdate(final CaretEvent arg0) {
                m_caretPosition = arg0.getDot();
            }
        });
    } else {
        m_text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        GridData layoutData = new GridData(GridData.FILL_BOTH);
        layoutData.widthHint = 600;
        layoutData.heightHint = 400;
        m_text.setLayoutData(layoutData);
        m_text.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                m_jsonDocument = m_text.getText();
                if (m_statusLine != null && !m_statusLine.isDisposed()) {
                    m_statusLine.setText("");
                    updateModelFromJson();
                }
            }
        });
        m_text.setText(m_jsonDocument);
    }
    // add status line
    m_statusLine = new Label(composite, SWT.SHADOW_NONE | SWT.WRAP);
    GridData statusGridData = new GridData(SWT.LEFT | SWT.FILL, SWT.BOTTOM, true, false);
    int maxHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(3);
    statusGridData.heightHint = maxHeight + 5;
    // seems to have no impact on the layout. The height will still be 3 rows (at least on Windows 8)
    statusGridData.minimumHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(1);
    m_statusLine.setLayoutData(statusGridData);
    compareNodeIDs();
    return composite;
}
Also used : CaretEvent(javax.swing.event.CaretEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) DocumentListener(javax.swing.event.DocumentListener) Frame(java.awt.Frame) ModifyListener(org.eclipse.swt.events.ModifyListener) BoxLayout(javax.swing.BoxLayout) Label(org.eclipse.swt.widgets.Label) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) JApplet(javax.swing.JApplet) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) Container(java.awt.Container) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Text(org.eclipse.swt.widgets.Text) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) Point(org.eclipse.swt.graphics.Point) Panel(java.awt.Panel) CaretListener(javax.swing.event.CaretListener) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) JRootPane(javax.swing.JRootPane) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Example 65 with JRootPane

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

the class MoveSelectedNodeAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final IMapSelection selection = Controller.getCurrentController().getSelection();
    final Component mapView = Controller.getCurrentController().getMapViewManager().getMapViewComponent();
    final JRootPane rootPane = SwingUtilities.getRootPane(mapView);
    if (!rootPane.isValid()) {
        rootPane.revalidate();
    }
    if (ResourceController.getResourceController().getBooleanProperty(MOVE_SLOWLY_PROPERTY))
        selection.slowlyMoveNodeTo(selection.getSelected(), nodePosition);
    else
        selection.moveNodeTo(selection.getSelected(), nodePosition);
}
Also used : IMapSelection(org.freeplane.features.map.IMapSelection) JRootPane(javax.swing.JRootPane) Component(java.awt.Component)

Aggregations

JRootPane (javax.swing.JRootPane)89 ActionEvent (java.awt.event.ActionEvent)48 KeyStroke (javax.swing.KeyStroke)34 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 FlowLayout (java.awt.FlowLayout)10 Container (java.awt.Container)9 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