Example usage for javax.swing JDialog getRootPane

List of usage examples for javax.swing JDialog getRootPane

Introduction

In this page you can find the example usage for javax.swing JDialog getRootPane.

Prototype

@BeanProperty(bound = false, hidden = true, description = "the RootPane object for this dialog.")
public JRootPane getRootPane() 

Source Link

Document

Returns the rootPane object for this dialog.

Usage

From source file:edu.umich.robot.GuiApplication.java

public void connectSuperdroidRobotDialog() {
    final int defaultPort = 3192;

    FormLayout layout = new FormLayout("right:pref, 4dlu, 35dlu, 4dlu, 35dlu",
            "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref");

    final JDialog dialog = new JDialog(frame, "Connect to Superdroid", true);
    dialog.setLayout(layout);/*w w w .java2  s .  co  m*/
    final JTextField namefield = new JTextField("charlie");
    final JTextField hostfield = new JTextField("192.168.1.165");
    final JTextField portfield = new JTextField(Integer.toString(defaultPort));
    final JButton cancel = new JButton("Cancel");
    final JButton ok = new JButton("OK");

    CellConstraints cc = new CellConstraints();
    dialog.add(new JLabel("Name"), cc.xy(1, 1));
    dialog.add(namefield, cc.xyw(3, 1, 3));
    dialog.add(new JLabel("Host"), cc.xy(1, 3));
    dialog.add(hostfield, cc.xyw(3, 3, 3));
    dialog.add(new JLabel("Port"), cc.xy(1, 5));
    dialog.add(portfield, cc.xyw(3, 5, 3));
    dialog.add(cancel, cc.xy(3, 7));
    dialog.add(ok, cc.xy(5, 7));

    portfield.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            int p = defaultPort;
            try {
                p = Integer.parseInt(portfield.getText());
                if (p < 1)
                    p = 1;
                if (p > 65535)
                    p = 65535;
            } catch (NumberFormatException ex) {
            }
            portfield.setText(Integer.toString(p));
        }
    });

    final ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String robotName = namefield.getText().trim();
            if (robotName.isEmpty()) {
                logger.error("Connect Superdroid: robot name empty");
                return;
            }

            for (char c : robotName.toCharArray()) {
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create Superdroid: illegal robot name");
                    return;
                }
            }

            try {
                controller.createRealSuperdroid(robotName, hostfield.getText(),
                        Integer.valueOf(portfield.getText()));
            } catch (UnknownHostException ex) {
                ex.printStackTrace();
                logger.error("Connect Superdroid: " + ex);
            } catch (SocketException ex) {
                ex.printStackTrace();
                logger.error("Connect Superdroid: " + ex);
            }
            dialog.dispose();
        }
    };

    namefield.addActionListener(okListener);
    hostfield.addActionListener(okListener);
    portfield.addActionListener(okListener);
    ok.addActionListener(okListener);

    ActionListener cancelAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);

    dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    dialog.setLocationRelativeTo(frame);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:com.marginallyclever.makelangelo.MainGUI.java

protected void AdjustGraphics() {
    final Preferences graphics_prefs = Preferences.userRoot().node("DrawBot").node("Graphics");

    final JDialog driver = new JDialog(mainframe, translator.get("MenuGraphicsTitle"), true);
    driver.setLayout(new GridBagLayout());

    //final JCheckBox allow_metrics = new JCheckBox(String.valueOf("I want to add the distance drawn to the // total"));
    //allow_metrics.setSelected(allowMetrics);

    final JCheckBox show_pen_up = new JCheckBox(translator.get("MenuGraphicsPenUp"));
    final JCheckBox antialias_on = new JCheckBox(translator.get("MenuGraphicsAntialias"));
    final JCheckBox speed_over_quality = new JCheckBox(translator.get("MenuGraphicsSpeedVSQuality"));
    final JCheckBox draw_all_while_running = new JCheckBox(translator.get("MenuGraphicsDrawWhileRunning"));

    show_pen_up.setSelected(graphics_prefs.getBoolean("show pen up", false));
    antialias_on.setSelected(graphics_prefs.getBoolean("antialias", true));
    speed_over_quality.setSelected(graphics_prefs.getBoolean("speed over quality", true));
    draw_all_while_running.setSelected(graphics_prefs.getBoolean("Draw all while running", true));

    final JButton cancel = new JButton(translator.get("Cancel"));
    final JButton save = new JButton(translator.get("Save"));

    GridBagConstraints c = new GridBagConstraints();
    //c.gridwidth=4;    c.gridx=0;  c.gridy=0;  driver.add(allow_metrics,c);

    int y = 0;/*from   w w  w  .  ja  va 2 s  .  c om*/

    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y;
    driver.add(show_pen_up, c);
    y++;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y;
    driver.add(draw_all_while_running, c);
    y++;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y;
    driver.add(antialias_on, c);
    y++;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y;
    driver.add(speed_over_quality, c);
    y++;

    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 2;
    c.gridy = y;
    driver.add(save, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = y;
    driver.add(cancel, c);

    ActionListener driveButtons = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == save) {
                //allowMetrics = allow_metrics.isSelected();
                graphics_prefs.putBoolean("show pen up", show_pen_up.isSelected());
                graphics_prefs.putBoolean("antialias", antialias_on.isSelected());
                graphics_prefs.putBoolean("speed over quality", speed_over_quality.isSelected());
                graphics_prefs.putBoolean("Draw all while running", draw_all_while_running.isSelected());

                previewPane.setShowPenUp(show_pen_up.isSelected());
                driver.dispose();
            }
            if (subject == cancel) {
                driver.dispose();
            }
        }
    };

    save.addActionListener(driveButtons);
    cancel.addActionListener(driveButtons);
    driver.getRootPane().setDefaultButton(save);
    driver.pack();
    driver.setVisible(true);
}

From source file:com.marginallyclever.makelangelo.MainGUI.java

protected void AdjustSounds() {
    final JDialog driver = new JDialog(mainframe, translator.get("MenuSoundsTitle"), true);
    driver.setLayout(new GridBagLayout());

    final JTextField sound_connect = new JTextField(prefs.get("sound_connect", ""), 32);
    final JTextField sound_disconnect = new JTextField(prefs.get("sound_disconnect", ""), 32);
    final JTextField sound_conversion_finished = new JTextField(prefs.get("sound_conversion_finished", ""), 32);
    final JTextField sound_drawing_finished = new JTextField(prefs.get("sound_drawing_finished", ""), 32);

    final JButton change_sound_connect = new JButton(translator.get("MenuSoundsConnect"));
    final JButton change_sound_disconnect = new JButton(translator.get("MenuSoundsDisconnect"));
    final JButton change_sound_conversion_finished = new JButton(translator.get("MenuSoundsFinishConvert"));
    final JButton change_sound_drawing_finished = new JButton(translator.get("MenuSoundsFinishDraw"));

    //final JCheckBox allow_metrics = new JCheckBox(String.valueOf("I want to add the distance drawn to the // total"));
    //allow_metrics.setSelected(allowMetrics);

    final JButton cancel = new JButton(translator.get("Cancel"));
    final JButton save = new JButton(translator.get("Save"));

    GridBagConstraints c = new GridBagConstraints();
    //c.gridwidth=4;    c.gridx=0;  c.gridy=0;  driver.add(allow_metrics,c);

    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;//from  w  ww .  j a  va  2  s.c o  m
    c.gridx = 0;
    c.gridy = 3;
    driver.add(change_sound_connect, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 3;
    driver.add(sound_connect, c);
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 4;
    driver.add(change_sound_disconnect, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 4;
    driver.add(sound_disconnect, c);
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 5;
    driver.add(change_sound_conversion_finished, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 5;
    driver.add(sound_conversion_finished, c);
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 6;
    driver.add(change_sound_drawing_finished, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 6;
    driver.add(sound_drawing_finished, c);

    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 2;
    c.gridy = 12;
    driver.add(save, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = 12;
    driver.add(cancel, c);

    ActionListener driveButtons = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == change_sound_connect)
                sound_connect.setText(SelectFile());
            if (subject == change_sound_disconnect)
                sound_disconnect.setText(SelectFile());
            if (subject == change_sound_conversion_finished)
                sound_conversion_finished.setText(SelectFile());
            if (subject == change_sound_drawing_finished)
                sound_drawing_finished.setText(SelectFile());

            if (subject == save) {
                //allowMetrics = allow_metrics.isSelected();
                prefs.put("sound_connect", sound_connect.getText());
                prefs.put("sound_disconnect", sound_disconnect.getText());
                prefs.put("sound_conversion_finished", sound_conversion_finished.getText());
                prefs.put("sound_drawing_finished", sound_drawing_finished.getText());
                machineConfiguration.SaveConfig();
                driver.dispose();
            }
            if (subject == cancel) {
                driver.dispose();
            }
        }
    };

    change_sound_connect.addActionListener(driveButtons);
    change_sound_disconnect.addActionListener(driveButtons);
    change_sound_conversion_finished.addActionListener(driveButtons);
    change_sound_drawing_finished.addActionListener(driveButtons);

    save.addActionListener(driveButtons);
    cancel.addActionListener(driveButtons);
    driver.getRootPane().setDefaultButton(save);
    driver.pack();
    driver.setVisible(true);
}

From source file:com.marginallyclever.makelangelo.MainGUI.java

protected boolean ChooseImageConversionOptions(boolean isDXF) {
    final JDialog driver = new JDialog(mainframe, translator.get("ConversionOptions"), true);
    driver.setLayout(new GridBagLayout());

    final String[] choices = machineConfiguration.getKnownMachineNames();
    final JComboBox<String> machine_choice = new JComboBox<String>(choices);
    machine_choice.setSelectedIndex(machineConfiguration.getCurrentMachineIndex());

    final JSlider input_paper_margin = new JSlider(JSlider.HORIZONTAL, 0, 50,
            100 - (int) (machineConfiguration.paper_margin * 100));
    input_paper_margin.setMajorTickSpacing(10);
    input_paper_margin.setMinorTickSpacing(5);
    input_paper_margin.setPaintTicks(false);
    input_paper_margin.setPaintLabels(true);

    //final JCheckBox allow_metrics = new JCheckBox(String.valueOf("I want to add the distance drawn to the // total"));
    //allow_metrics.setSelected(allowMetrics);

    final JCheckBox reverse_h = new JCheckBox(translator.get("FlipForGlass"));
    reverse_h.setSelected(machineConfiguration.reverseForGlass);
    final JButton cancel = new JButton(translator.get("Cancel"));
    final JButton save = new JButton(translator.get("Start"));

    String[] filter_names = new String[image_converters.size()];
    Iterator<Filter> fit = image_converters.iterator();
    int i = 0;/*from w w w  . j a v  a 2 s .co  m*/
    while (fit.hasNext()) {
        Filter f = fit.next();
        filter_names[i++] = f.GetName();
    }

    final JComboBox<String> input_draw_style = new JComboBox<String>(filter_names);
    input_draw_style.setSelectedIndex(GetDrawStyle());

    GridBagConstraints c = new GridBagConstraints();
    //c.gridwidth=4;    c.gridx=0;  c.gridy=0;  driver.add(allow_metrics,c);

    int y = 0;
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = y;
    driver.add(new JLabel(translator.get("MenuLoadMachineConfig")), c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 2;
    c.gridx = 1;
    c.gridy = y++;
    driver.add(machine_choice, c);

    if (!isDXF) {
        c.anchor = GridBagConstraints.EAST;
        c.gridwidth = 1;
        c.gridx = 0;
        c.gridy = y;
        driver.add(new JLabel(translator.get("ConversionStyle")), c);
        c.anchor = GridBagConstraints.WEST;
        c.gridwidth = 3;
        c.gridx = 1;
        c.gridy = y++;
        driver.add(input_draw_style, c);
    }

    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = y;
    driver.add(new JLabel(translator.get("PaperMargin")), c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = y++;
    driver.add(input_paper_margin, c);

    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y++;
    driver.add(reverse_h, c);
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 2;
    c.gridy = y;
    driver.add(save, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = y++;
    driver.add(cancel, c);

    startConvertingNow = false;

    ActionListener driveButtons = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == save) {
                long new_uid = Long.parseLong(choices[machine_choice.getSelectedIndex()]);
                machineConfiguration.LoadConfig(new_uid);
                SetDrawStyle(input_draw_style.getSelectedIndex());
                machineConfiguration.paper_margin = (100 - input_paper_margin.getValue()) * 0.01;
                machineConfiguration.reverseForGlass = reverse_h.isSelected();
                machineConfiguration.SaveConfig();

                // if we aren't connected, don't show the new 
                if (connectionToRobot != null && !connectionToRobot.isRobotConfirmed()) {
                    // Force update of graphics layout.
                    previewPane.updateMachineConfig();
                    // update window title
                    mainframe.setTitle(
                            translator.get("TitlePrefix") + Long.toString(machineConfiguration.robot_uid)
                                    + translator.get("TitleNotConnected"));
                }
                startConvertingNow = true;
                driver.dispose();
            }
            if (subject == cancel) {
                driver.dispose();
            }
        }
    };

    save.addActionListener(driveButtons);
    cancel.addActionListener(driveButtons);
    driver.getRootPane().setDefaultButton(save);
    driver.pack();
    driver.setVisible(true);

    return startConvertingNow;
}

From source file:org.apache.cayenne.modeler.util.CayenneController.java

/**
 * If this view or a parent view is a JDialog, makes it closeable on ESC hit. Dialog
 * "defaultCloseOperation" property is taken into account when processing ESC button
 * click./*  w  w  w .java  2 s .  c o m*/
 */
protected void makeCloseableOnEscape() {

    Window window = getWindow();
    if (!(window instanceof JDialog)) {
        return;
    }

    final JDialog dialog = (JDialog) window;

    KeyStroke escReleased = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
    ActionListener closeAction = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (dialog.isVisible()) {
                switch (dialog.getDefaultCloseOperation()) {
                case JDialog.HIDE_ON_CLOSE:
                    dialog.setVisible(false);
                    break;
                case JDialog.DISPOSE_ON_CLOSE:
                    dialog.setVisible(false);
                    dialog.dispose();
                    break;
                case JDialog.DO_NOTHING_ON_CLOSE:
                default:
                    break;
                }
            }
        }
    };
    dialog.getRootPane().registerKeyboardAction(closeAction, escReleased, JComponent.WHEN_IN_FOCUSED_WINDOW);
}

From source file:org.apache.marmotta.splash.common.ui.MessageDialog.java

public static void show(String title, String message, String description) {
    final JDialog dialog = new JDialog((Frame) null, title);
    dialog.setModal(true);//w ww  . j a  v  a  2 s  . c  o  m
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final JPanel root = new JPanel(new GridBagLayout());
    root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    dialog.getRootPane().setContentPane(root);

    final JButton close = new JButton("OK");
    close.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
        }
    });
    GridBagConstraints cClose = new GridBagConstraints();
    cClose.gridx = 0;
    cClose.gridy = 2;
    cClose.gridwidth = 2;
    cClose.weightx = 1;
    cClose.weighty = 0;
    cClose.insets = new Insets(5, 5, 5, 5);

    root.add(close, cClose);
    dialog.getRootPane().setDefaultButton(close);

    Icon icon = loadIcon(MARMOTTA_ICON);
    if (icon != null) {
        JLabel lblIcn = new JLabel(icon);

        GridBagConstraints cIcon = new GridBagConstraints();
        cIcon.gridx = 1;
        cIcon.gridy = 0;
        cIcon.gridheight = 2;
        cIcon.fill = GridBagConstraints.NONE;
        cIcon.weightx = 0;
        cIcon.weighty = 1;
        cIcon.anchor = GridBagConstraints.NORTH;
        cIcon.insets = new Insets(10, 5, 5, 0);
        root.add(lblIcn, cIcon);
    }

    JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>"));
    lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f));
    GridBagConstraints cLabel = new GridBagConstraints();
    cLabel.gridx = 0;
    cLabel.gridy = 0;
    cLabel.fill = GridBagConstraints.BOTH;
    cLabel.weightx = 1;
    cLabel.weighty = 0.5;
    cLabel.insets = new Insets(5, 5, 5, 5);
    root.add(lblMsg, cLabel);

    JLabel lblDescr = new JLabel(
            "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>"));
    cLabel.gridy++;
    cLabel.insets = new Insets(0, 5, 5, 5);
    root.add(lblDescr, cLabel);

    dialog.pack();
    dialog.setLocationRelativeTo(null);

    dialog.setVisible(true);
    dialog.dispose();
}

From source file:org.apache.marmotta.splash.common.ui.SelectionDialog.java

public static int select(String title, String message, String description, List<Option> options,
        int defaultOption) {
    final JDialog dialog = new JDialog((Frame) null, title);
    dialog.setModal(true);//from   w w w .  ja v a 2  s  . com
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final AtomicInteger result = new AtomicInteger(Math.max(defaultOption, -1));

    JButton defaultBtn = null;

    final JPanel root = new JPanel(new GridBagLayout());
    root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    dialog.getRootPane().setContentPane(root);

    JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>"));
    lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f));
    GridBagConstraints cLabel = new GridBagConstraints();
    cLabel.gridx = 0;
    cLabel.gridy = 0;
    cLabel.fill = GridBagConstraints.BOTH;
    cLabel.weightx = 1;
    cLabel.weighty = 0.5;
    cLabel.insets = new Insets(5, 5, 5, 5);
    root.add(lblMsg, cLabel);

    JLabel lblDescr = new JLabel(
            "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>"));
    cLabel.gridy++;
    cLabel.insets = new Insets(0, 5, 5, 5);
    root.add(lblDescr, cLabel);

    // All the options
    cLabel.ipadx = 10;
    cLabel.ipady = 10;
    cLabel.insets = new Insets(5, 15, 0, 15);
    for (int i = 0; i < options.size(); i++) {
        cLabel.gridy++;

        final Option o = options.get(i);
        final JButton btn = new JButton(
                "<html>" + StringEscapeUtils.escapeHtml3(o.label).replaceAll("\\n", "<br>"),
                MessageDialog.loadIcon(o.icon));
        if (StringUtils.isNotBlank(o.info)) {
            btn.setToolTipText("<html>" + StringEscapeUtils.escapeHtml3(o.info).replaceAll("\\n", "<br>"));
        }

        btn.setHorizontalAlignment(AbstractButton.LEADING);
        btn.setVerticalTextPosition(AbstractButton.CENTER);
        btn.setHorizontalTextPosition(AbstractButton.TRAILING);

        final int myAnswer = i;
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                result.set(myAnswer);
                dialog.setVisible(false);
            }
        });

        root.add(btn, cLabel);
        if (i == defaultOption) {
            dialog.getRootPane().setDefaultButton(btn);
            defaultBtn = btn;
        }
    }

    final Icon icon = MessageDialog.loadIcon();
    if (icon != null) {
        JLabel lblIcn = new JLabel(icon);

        GridBagConstraints cIcon = new GridBagConstraints();
        cIcon.gridx = 1;
        cIcon.gridy = 0;
        cIcon.gridheight = 2 + options.size();
        cIcon.fill = GridBagConstraints.NONE;
        cIcon.weightx = 0;
        cIcon.weighty = 1;
        cIcon.anchor = GridBagConstraints.NORTH;
        cIcon.insets = new Insets(10, 5, 5, 0);
        root.add(lblIcn, cIcon);
    }

    final JButton close = new JButton("Cancel");
    close.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            result.set(-1);
            dialog.setVisible(false);
        }
    });
    GridBagConstraints cClose = new GridBagConstraints();
    cClose.gridx = 0;
    cClose.gridy = 2 + options.size();
    cClose.gridwidth = 2;
    cClose.weightx = 1;
    cClose.weighty = 0;
    cClose.insets = new Insets(15, 5, 5, 5);

    root.add(close, cClose);
    if (defaultOption < 0) {
        dialog.getRootPane().setDefaultButton(close);
        defaultBtn = close;
    }

    dialog.pack();
    dialog.setLocationRelativeTo(null);
    defaultBtn.requestFocusInWindow();

    dialog.setVisible(true);
    dialog.dispose();

    return result.get();
}

From source file:org.executequery.components.FileChooserDialog.java

protected JDialog createDialog(Component parent) throws HeadlessException {

    Frame frame = parent instanceof Frame ? (Frame) parent
            : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    String title = getUI().getDialogTitle(this);

    JDialog dialog = new JDialog(frame, title, true);

    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(this, BorderLayout.CENTER);

    setPreferredSize(new Dimension(700, getPreferredSize().height));

    // add any custom panel
    if (customPanel != null) {
        contentPane.add(customPanel, BorderLayout.SOUTH);
    }/*from   w ww.ja va  2 s .com*/

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();

        if (supportsWindowDecorations) {
            dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
        }

    }

    setFileView(new DefaultFileView());
    dialog.pack();

    dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize()));
    return dialog;
}

From source file:org.notebook.gui.widget.GuiUtils.java

/**
 * Adds the close action with escape key.
 * /*from  www. j  a  v a  2s. c  o m*/
 * @param dialog
 *            the dialog
 */
public static void addCloseActionWithEscapeKey(final JDialog dialog) {
    //  Handle escape key to close the dialog

    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    Action escapeAction = new AbstractAction() {
        private static final long serialVersionUID = 0L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
        }
    };
    dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
    dialog.getRootPane().getActionMap().put("ESCAPE", escapeAction);
}

From source file:org.notebook.gui.widget.GuiUtils.java

/**
 * Adds the dispose action with escape key.
 * /*ww w . ja v  a 2s.com*/
 * @param dialog
 *            the dialog
 */
public static void addDisposeActionWithEscapeKey(final JDialog dialog) {
    //  Handle escape key to close the dialog

    KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    Action disposeAction = new AbstractAction() {
        private static final long serialVersionUID = 0L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
    dialog.getRootPane().getActionMap().put("ESCAPE", disposeAction);
}