Java Code Examples for javax.swing.JDialog#getRootPane()

The following examples show how to use javax.swing.JDialog#getRootPane() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChatWindow.java    From ChatGameFontificator with The Unlicense 6 votes vote down vote up
/**
 * Does the work required to make the parameter JDialog be hidden when pressing escape
 * 
 * @param popup
 */
public static void setupHideOnEscape(final JDialog popup)
{
    Action aa = new AbstractAction()
    {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent event)
        {
            popup.setVisible(false);
        }
    };
    final String mapKey = "escapePressed";
    JRootPane root = popup.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, mapKey);
    root.getActionMap().put(mapKey, aa);
}
 
Example 2
Source File: CapabilityResponsePopUp.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static void installEscapeCloseOperation(final JDialog dialog) {
	Action dispatchClosing = new AbstractAction() {
		public void actionPerformed(ActionEvent event) {
			dialog.dispatchEvent(new WindowEvent(
					dialog, WindowEvent.WINDOW_CLOSING
			));
		}
	};
	JRootPane root = dialog.getRootPane();
	root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
			escapeStroke, dispatchWindowClosingActionMapKey
	);
	root.getActionMap().put( dispatchWindowClosingActionMapKey, dispatchClosing
	);
}
 
Example 3
Source File: ProgressPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void open(JComponent progressComponent) {
    holder.add(progressComponent, BorderLayout.CENTER);

    DialogDescriptor dd = new DialogDescriptor(
            this,
            NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"),
            true,
            new Object[0],
            DialogDescriptor.NO_OPTION,
            DialogDescriptor.DEFAULT_ALIGN,
            null,
            null,
            true);
    dialog = DialogDisplayer.getDefault().createDialog(dd);
    if (dialog instanceof JDialog) {
        JDialog jDialog = ((JDialog)dialog);
        jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        JRootPane rootPane = jDialog.getRootPane();
        rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NOI18N
        rootPane.getActionMap().put("cancel", new AbstractAction() { // NOI18N
            public void actionPerformed(ActionEvent event) {
                if (cancelButton.isEnabled()) {
                    cancelButton.doClick();
                }
            }
        });
    }
    dialog.setResizable(false);
    dialog.setVisible(true);
}
 
Example 4
Source File: ProgressPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void open(JComponent progressComponent) {
    holder.add(progressComponent, BorderLayout.CENTER);

    DialogDescriptor dd = new DialogDescriptor(
            this,
            NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"),
            true,
            new Object[0],
            DialogDescriptor.NO_OPTION,
            DialogDescriptor.DEFAULT_ALIGN,
            null,
            null,
            true);
    dialog = DialogDisplayer.getDefault().createDialog(dd);
    if (dialog instanceof JDialog) {
        JDialog jDialog = ((JDialog) dialog);
        jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        JRootPane rootPane = jDialog.getRootPane();
        rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NOI18N
        rootPane.getActionMap().put("cancel", new AbstractAction() { // NOI18N
            @Override
            public void actionPerformed(ActionEvent event) {
                if (cancelButton.isEnabled()) {
                    cancelButton.doClick();
                }
            }
        });
    }
    dialog.setResizable(false);
    dialog.setVisible(true);
}
 
Example 5
Source File: ProgressPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void open(JComponent progressComponent) {
    holder.add(progressComponent, BorderLayout.CENTER);

    DialogDescriptor dd = new DialogDescriptor(
            this,
            NbBundle.getMessage (ProgressPanel.class, "MSG_PleaseWait"),
            true,
            new Object[0],
            DialogDescriptor.NO_OPTION,
            DialogDescriptor.DEFAULT_ALIGN,
            null,
            null,
            true);
    dialog = DialogDisplayer.getDefault().createDialog(dd);
    if (dialog instanceof JDialog) {
        JDialog jDialog = ((JDialog)dialog);
        jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        JRootPane rootPane = jDialog.getRootPane();
        rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NOI18N
        rootPane.getActionMap().put("cancel", new AbstractAction() { // NOI18N
            public void actionPerformed(ActionEvent event) {
                if (cancelButton.isEnabled()) {
                    cancelButton.doClick();
                }
            }
        });
    }
    dialog.setResizable(false);
    dialog.setVisible(true);
}
 
Example 6
Source File: Utility.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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(ESCAPE_STROKE, DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY);
	Action dispatchClosing = new AbstractAction()
	{
		@Override
		public void actionPerformed(ActionEvent event)
		{
			dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
		}
	};
	root.getActionMap().put(DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY, dispatchClosing);
}
 
Example 7
Source File: SwingUtils.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
public static void installEscapeCloseOperation(final JDialog dialog) {
	Action dispatchClosing = new AbstractAction() {
		public void actionPerformed(ActionEvent event) {
			dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
		}
	};
	JRootPane root = dialog.getRootPane();
	installCloseAction(dispatchClosing, root);
}
 
Example 8
Source File: DialogHelper.java    From Girinoscope with Apache License 2.0 5 votes vote down vote up
public static void installEscapeCloseOperation(final JDialog dialog) {
    @SuppressWarnings("serial")
    Action dispatchClosing = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_STROKE, DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY);
    root.getActionMap().put(DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY, dispatchClosing);
}
 
Example 9
Source File: Utility.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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(ESCAPE_STROKE, DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY);
	Action dispatchClosing = new AbstractAction()
	{
		@Override
		public void actionPerformed(ActionEvent event)
		{
			dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
		}
	};
	root.getActionMap().put(DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY, dispatchClosing);
}
 
Example 10
Source File: View.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public static void installEscapeCloseOperation(final JDialog dialog) {
    Action dispatchClosing = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(
                    dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
            escapeStroke, dispatchWindowClosingActionMapKey);
    root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing);
}