Search in sources :

Example 36 with JRootPane

use of javax.swing.JRootPane in project com.revolsys.open by revolsys.

the class ValueField method showDialog.

@SuppressWarnings("unchecked")
public <V> V showDialog(final Component parent) {
    Window window;
    if (parent == null) {
        window = SwingUtil.getActiveWindow();
    } else if (parent instanceof Window) {
        window = (Window) parent;
    } else {
        window = SwingUtilities.windowForComponent(parent);
    }
    final JDialog dialog = new JDialog(window, this.title, ModalityType.APPLICATION_MODAL);
    if (this.iconImage != null) {
        dialog.setIconImage(this.iconImage);
    }
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    dialog.setLayout(new BorderLayout());
    dialog.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                cancel(dialog);
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                save(dialog);
            }
        }

        @Override
        public void keyReleased(final KeyEvent e) {
        }

        @Override
        public void keyTyped(final KeyEvent e) {
        }
    });
    dialog.add(this, BorderLayout.CENTER);
    final JRootPane rootPane = dialog.getRootPane();
    final InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    final ActionMap actionMap = rootPane.getActionMap();
    final JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final Runnable cancelRunnable = () -> cancel(dialog);
    buttons.add(RunnableAction.newButton("Cancel", cancelRunnable));
    final KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    inputMap.put(escapeStroke, "cancel");
    actionMap.put("cancel", new RunnableAction(cancelRunnable));
    final Runnable saveRunnable = () -> save(dialog);
    buttons.add(RunnableAction.newButton("OK", saveRunnable));
    dialog.add(buttons, BorderLayout.SOUTH);
    final KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    inputMap.put(enterStroke, "save");
    actionMap.put("save", new RunnableAction(saveRunnable));
    dialog.pack();
    SwingUtil.autoAdjustPosition(window, dialog);
    this.saved = false;
    dialog.setVisible(true);
    final V value = (V) getFieldValue();
    SwingUtil.dispose(dialog);
    return value;
}
Also used : Window(java.awt.Window) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionMap(javax.swing.ActionMap) RunnableAction(com.revolsys.swing.action.RunnableAction) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) KeyStroke(javax.swing.KeyStroke) KeyListener(java.awt.event.KeyListener) JRootPane(javax.swing.JRootPane) InputMap(javax.swing.InputMap) JDialog(javax.swing.JDialog)

Example 37 with JRootPane

use of javax.swing.JRootPane in project LAN-Messenger by harshitbudhraja.

the class Messaging method messagefieldFocusGained.

// GEN-LAST:event_sendbuttonActionPerformed
private void messagefieldFocusGained(java.awt.event.FocusEvent evt) {
    // GEN-FIRST:event_messagefieldFocusGained
    // TODO add your handling code here:
    JRootPane rootPane = SwingUtilities.getRootPane(sendbutton);
    rootPane.setDefaultButton(sendbutton);
}
Also used : JRootPane(javax.swing.JRootPane)

Example 38 with JRootPane

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

the class DockingRegionContainer method hideDragControl.

void hideDragControl() {
    // System.err.println("hideDragControl()");
    JRootPane rootPane = getRootPane();
    rootPane.setGlassPane(oldGlass);
    oldGlass = null;
    // overlayPanel = null;
    rootPane.revalidate();
    rootPane.repaint();
}
Also used : JRootPane(javax.swing.JRootPane)

Example 39 with JRootPane

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

the class GuiUtil method installEscapeCloseOperation.

public static void installEscapeCloseOperation(final JDialog dialog) {
    Action closingAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_STROKE, CLOSE_DIALOG_ACTION_MAP_KEY);
    root.getActionMap().put(CLOSE_DIALOG_ACTION_MAP_KEY, closingAction);
}
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 40 with JRootPane

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

the class EditNodeWYSIWYG method createHtmlEditor.

public HTMLDialog createHtmlEditor(final RootPaneContainer frame) throws Exception {
    final JRootPane rootPane = ((RootPaneContainer) frame).getRootPane();
    HTMLDialog htmlEditorWindow = (HTMLDialog) rootPane.getClientProperty(HTMLDialog.class);
    if (htmlEditorWindow == null) {
        htmlEditorWindow = new HTMLDialog(this, "", "", frame);
        rootPane.putClientProperty(HTMLDialog.class, htmlEditorWindow);
        // make sure that SHTML gets notified of relevant config changes!
        ResourceController.getResourceController().addPropertyChangeListener(new FreeplaneToSHTMLPropertyChangeAdapter(htmlEditorWindow.getHtmlEditorPanel()));
    }
    return htmlEditorWindow;
}
Also used : RootPaneContainer(javax.swing.RootPaneContainer) 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