Example usage for javax.swing JDialog setDefaultCloseOperation

List of usage examples for javax.swing JDialog setDefaultCloseOperation

Introduction

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

Prototype

@BeanProperty(preferred = true, enumerationValues = { "WindowConstants.DO_NOTHING_ON_CLOSE",
        "WindowConstants.HIDE_ON_CLOSE",
        "WindowConstants.DISPOSE_ON_CLOSE" }, description = "The dialog's default close operation.")
public void setDefaultCloseOperation(int operation) 

Source Link

Document

Sets the operation that will happen by default when the user initiates a "close" on this dialog.

Usage

From source file:org.apache.log4j.chainsaw.LogUI.java

/**
 * Displays a dialog which will provide options for selecting a configuration
 *//* w  w w . ja  v  a2 s .  c om*/
private void showReceiverConfigurationPanel() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            final JDialog dialog = new JDialog(LogUI.this, true);
            dialog.setTitle("Load events into Chainsaw");
            dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

            dialog.setResizable(false);

            receiverConfigurationPanel.setCompletionActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    dialog.setVisible(false);

                    if (receiverConfigurationPanel.getModel().isCancelled()) {
                        return;
                    }
                    applicationPreferenceModel
                            .setShowNoReceiverWarning(!receiverConfigurationPanel.isDontWarnMeAgain());
                    //remove existing plugins
                    List plugins = pluginRegistry.getPlugins();
                    for (Iterator iter = plugins.iterator(); iter.hasNext();) {
                        Plugin plugin = (Plugin) iter.next();
                        //don't stop ZeroConfPlugin if it is registered
                        if (!plugin.getName().toLowerCase(Locale.ENGLISH).contains("zeroconf")) {
                            pluginRegistry.stopPlugin(plugin.getName());
                        }
                    }
                    URL configURL = null;

                    if (receiverConfigurationPanel.getModel().isNetworkReceiverMode()) {
                        int port = receiverConfigurationPanel.getModel().getNetworkReceiverPort();

                        try {
                            Class receiverClass = receiverConfigurationPanel.getModel()
                                    .getNetworkReceiverClass();
                            Receiver networkReceiver = (Receiver) receiverClass.newInstance();
                            networkReceiver.setName(receiverClass.getSimpleName() + "-" + port);

                            Method portMethod = networkReceiver.getClass().getMethod("setPort",
                                    new Class[] { int.class });
                            portMethod.invoke(networkReceiver, new Object[] { new Integer(port) });

                            networkReceiver.setThreshold(Level.TRACE);

                            pluginRegistry.addPlugin(networkReceiver);
                            networkReceiver.activateOptions();
                            receiversPanel.updateReceiverTreeInDispatchThread();
                        } catch (Exception e3) {
                            MessageCenter.getInstance().getLogger().error("Error creating Receiver", e3);
                            MessageCenter.getInstance().getLogger()
                                    .info("An error occurred creating your Receiver");
                        }
                    } else if (receiverConfigurationPanel.getModel().isLog4jConfig()) {
                        File log4jConfigFile = receiverConfigurationPanel.getModel().getLog4jConfigFile();
                        if (log4jConfigFile != null) {
                            try {
                                Map entries = LogFilePatternLayoutBuilder
                                        .getAppenderConfiguration(log4jConfigFile);
                                for (Iterator iter = entries.entrySet().iterator(); iter.hasNext();) {
                                    try {
                                        Map.Entry entry = (Map.Entry) iter.next();
                                        String name = (String) entry.getKey();
                                        Map values = (Map) entry.getValue();
                                        //values: conversion, file
                                        String conversionPattern = values.get("conversion").toString();
                                        File file = new File(values.get("file").toString());
                                        URL fileURL = file.toURI().toURL();
                                        String timestampFormat = LogFilePatternLayoutBuilder
                                                .getTimeStampFormat(conversionPattern);
                                        String receiverPattern = LogFilePatternLayoutBuilder
                                                .getLogFormatFromPatternLayout(conversionPattern);
                                        VFSLogFilePatternReceiver fileReceiver = new VFSLogFilePatternReceiver();
                                        fileReceiver.setName(name);
                                        fileReceiver.setAutoReconnect(true);
                                        fileReceiver.setContainer(LogUI.this);
                                        fileReceiver.setAppendNonMatches(true);
                                        fileReceiver.setFileURL(fileURL.toURI().toString());
                                        fileReceiver.setTailing(true);
                                        fileReceiver.setLogFormat(receiverPattern);
                                        fileReceiver.setTimestampFormat(timestampFormat);
                                        fileReceiver.setThreshold(Level.TRACE);
                                        pluginRegistry.addPlugin(fileReceiver);
                                        fileReceiver.activateOptions();
                                        receiversPanel.updateReceiverTreeInDispatchThread();
                                    } catch (URISyntaxException e1) {
                                        e1.printStackTrace();
                                    }
                                }
                            } catch (IOException e1) {
                                e1.printStackTrace();
                            }
                        }
                    } else if (receiverConfigurationPanel.getModel().isLoadConfig()) {
                        configURL = receiverConfigurationPanel.getModel().getConfigToLoad();
                    } else if (receiverConfigurationPanel.getModel().isLogFileReceiverConfig()) {
                        try {
                            URL fileURL = receiverConfigurationPanel.getModel().getLogFileURL();
                            if (fileURL != null) {
                                VFSLogFilePatternReceiver fileReceiver = new VFSLogFilePatternReceiver();
                                fileReceiver.setName(fileURL.getFile());
                                fileReceiver.setAutoReconnect(true);
                                fileReceiver.setContainer(LogUI.this);
                                fileReceiver.setAppendNonMatches(true);
                                fileReceiver.setFileURL(fileURL.toURI().toString());
                                fileReceiver.setTailing(true);
                                if (receiverConfigurationPanel.getModel().isPatternLayoutLogFormat()) {
                                    fileReceiver.setLogFormat(
                                            LogFilePatternLayoutBuilder.getLogFormatFromPatternLayout(
                                                    receiverConfigurationPanel.getModel().getLogFormat()));
                                } else {
                                    fileReceiver
                                            .setLogFormat(receiverConfigurationPanel.getModel().getLogFormat());
                                }
                                fileReceiver.setTimestampFormat(
                                        receiverConfigurationPanel.getModel().getLogFormatTimestampFormat());
                                fileReceiver.setThreshold(Level.TRACE);

                                pluginRegistry.addPlugin(fileReceiver);
                                fileReceiver.activateOptions();
                                receiversPanel.updateReceiverTreeInDispatchThread();
                            }
                        } catch (Exception e2) {
                            MessageCenter.getInstance().getLogger().error("Error creating Receiver", e2);
                            MessageCenter.getInstance().getLogger()
                                    .info("An error occurred creating your Receiver");
                        }
                    }
                    if (configURL == null && receiverConfigurationPanel.isDontWarnMeAgain()) {
                        //use the saved config file as the config URL if defined
                        if (receiverConfigurationPanel.getModel().getSaveConfigFile() != null) {
                            try {
                                configURL = receiverConfigurationPanel.getModel().getSaveConfigFile().toURI()
                                        .toURL();
                            } catch (MalformedURLException e1) {
                                e1.printStackTrace();
                            }
                        } else {
                            //no saved config defined but don't warn me is checked - use default config
                            configURL = receiverConfigurationPanel.getModel().getDefaultConfigFileURL();
                        }
                    }
                    if (configURL != null) {
                        MessageCenter.getInstance().getLogger()
                                .debug("Initialiazing Log4j with " + configURL.toExternalForm());
                        final URL finalURL = configURL;
                        new Thread(new Runnable() {
                            public void run() {
                                if (receiverConfigurationPanel.isDontWarnMeAgain()) {
                                    applicationPreferenceModel.setConfigurationURL(finalURL.toExternalForm());
                                } else {
                                    try {
                                        if (new File(finalURL.toURI()).exists()) {
                                            loadConfigurationUsingPluginClassLoader(finalURL);
                                        }
                                    } catch (URISyntaxException e) {
                                        //ignore
                                    }
                                }

                                receiversPanel.updateReceiverTreeInDispatchThread();
                            }
                        }).start();
                    }
                    File saveConfigFile = receiverConfigurationPanel.getModel().getSaveConfigFile();
                    if (saveConfigFile != null) {
                        ReceiversHelper.getInstance().saveReceiverConfiguration(saveConfigFile);
                    }
                }
            });

            receiverConfigurationPanel.setDialog(dialog);
            dialog.getContentPane().add(receiverConfigurationPanel);

            dialog.pack();

            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            dialog.setLocation((screenSize.width / 2) - (dialog.getWidth() / 2),
                    (screenSize.height / 2) - (dialog.getHeight() / 2));

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

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);/*from ww w . java  2  s.  com*/
    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);/* ww w  .ja  v  a  2s.  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.deegree.tools.rendering.viewer.File3dImporter.java

public static List<WorldRenderableObject> open(Frame parent, String fileName) {

    if (fileName == null || "".equals(fileName.trim())) {
        throw new InvalidParameterException("the file name may not be null or empty");
    }/*  w  ww  . j  a  v a 2s .  c om*/
    fileName = fileName.trim();

    CityGMLImporter openFile2;
    XMLInputFactory fac = XMLInputFactory.newInstance();
    InputStream in = null;
    try {
        XMLStreamReader reader = fac.createXMLStreamReader(in = new FileInputStream(fileName));
        reader.next();
        String ns = "http://www.opengis.net/citygml/1.0";
        openFile2 = new CityGMLImporter(null, null, null, reader.getNamespaceURI().equals(ns));
    } catch (Throwable t) {
        openFile2 = new CityGMLImporter(null, null, null, false);
    } finally {
        IOUtils.closeQuietly(in);
    }

    final CityGMLImporter openFile = openFile2;

    final JDialog dialog = new JDialog(parent, "Loading", true);

    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(
            new JLabel("<HTML>Loading file:<br>" + fileName + "<br>Please wait!</HTML>", SwingConstants.CENTER),
            BorderLayout.NORTH);
    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progressBar.setIndeterminate(false);
    dialog.getContentPane().add(progressBar, BorderLayout.CENTER);

    dialog.pack();
    dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    dialog.setResizable(false);
    dialog.setLocationRelativeTo(parent);

    final Thread openThread = new Thread() {
        /**
         * Opens the file in a separate thread.
         */
        @Override
        public void run() {
            // openFile.openFile( progressBar );
            if (dialog.isDisplayable()) {
                dialog.setVisible(false);
                dialog.dispose();
            }
        }
    };
    openThread.start();

    dialog.setVisible(true);
    List<WorldRenderableObject> result = null;
    try {
        result = openFile.importFromFile(fileName, 6, 2);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    gm = openFile.getQmList();

    //
    // if ( result != null ) {
    // openGLEventListener.addDataObjectToScene( result );
    // File f = new File( fileName );
    // setTitle( WIN_TITLE + f.getName() );
    // } else {
    // showExceptionDialog( "The file: " + fileName
    // + " could not be read,\nSee error log for detailed information." );
    // }
    return result;
}

From source file:org.geopublishing.atlasViewer.GpCoreUtil.java

public static JDialog getWaitDialog(final Component owner, final String msg) {
    final JDialog waitFrame = new JDialog(SwingUtil.getParentWindow(owner));

    waitFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    final JPanel cp = new JPanel(new MigLayout());
    final JLabel label = new JLabel(msg, Icons.ICON_TASKRUNNING_BIG, SwingConstants.LEADING);
    cp.add(label);//from w  w  w . ja va  2s .  c om
    waitFrame.setContentPane(cp);

    waitFrame.setAlwaysOnTop(true);
    waitFrame.pack();
    SwingUtil.centerFrameOnScreen(waitFrame);
    waitFrame.setVisible(true);

    return waitFrame;
}

From source file:org.giswater.controller.MenuController.java

public void downloadNewVersion() {

    Utils.getLogger().info("Downloading last version...");

    if (ftp == null)
        return;/*from w  w w  . jav  a2 s . com*/

    String ftpVersion = ftp.getFtpVersion();
    String remoteName = UPDATE_FILE + ftpVersion + ".exe";
    // Choose file to download
    mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    String localePath = chooseFileSetup(remoteName);
    if (!localePath.equals("")) {
        DownloadPanel panel = new DownloadPanel(remoteName, localePath, ftp);
        JDialog downloadDialog = Utils.openDialogForm(panel, mainFrame,
                Utils.getBundleString("MenuController.download_process"), 290, 135); //$NON-NLS-1$
        downloadDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        downloadDialog.setVisible(true);
        mainFrame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }

}

From source file:org.javaswift.cloudie.CloudiePanel.java

public void onLogin() {
    final JDialog loginDialog = new JDialog(owner, "Login");
    final LoginPanel loginPanel = new LoginPanel(new LoginCallback() {
        @Override//from   ww  w.ja v a  2 s  . co  m
        public void doLogin(AccountConfig accountConfig) {
            CloudieCallback cb = GuiTreadingUtils.guiThreadSafe(CloudieCallback.class,
                    new CloudieCallbackWrapper(callback) {
                        @Override
                        public void onLoginSuccess() {
                            loginDialog.setVisible(false);
                            super.onLoginSuccess();
                        }

                        @Override
                        public void onError(CommandException ex) {
                            JOptionPane.showMessageDialog(loginDialog, "Login Failed\n" + ex.toString(),
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    });
            ops.login(accountConfig, cb);
        }
    }, credentialsStore);
    try {
        loginPanel.setOwner(loginDialog);
        loginDialog.getContentPane().add(loginPanel);
        loginDialog.setModal(true);
        loginDialog.setSize(480, 340);
        loginDialog.setResizable(false);
        loginDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        center(loginDialog);
        loginDialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                loginPanel.onCancel();
            }

            @Override
            public void windowOpened(WindowEvent e) {
                loginPanel.onShow();
            }
        });
        loginDialog.setVisible(true);
    } finally {
        loginDialog.dispose();
    }
}

From source file:org.openflexo.view.controller.FlexoInspectorController.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    final JDialog dialog = new JDialog(frame);
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    JButton button = new JButton("Show dialog");
    button.addActionListener(new ActionListener() {

        @Override/*from  w ww .j ava2 s.  c om*/
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(true);
        }
    });
    JLabel label = new JLabel("coucou");
    dialog.add(label);
    dialog.pack();
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(button);
    panel.setPreferredSize(new Dimension(500, 400));
    frame.add(panel);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
  * Creates a modal JDialog containing the specified JComponent
  * for the specified parent.// ww w . j  a  v  a  2s . co  m
  * The newly created dialog is then centered on the screen and made visible.
 *
  * @param parent The parent component.
  * @param title  The title of the dialog.
  * @param c      The component to display.
  * @see #centerAndShow(Component)
 */
public static void makeForDialog(Component parent, String title, JComponent c) {
    if (c == null)
        return;
    JDialog dialog = null;
    if (parent instanceof Frame)
        dialog = new JDialog((Frame) parent);
    else if (parent instanceof Dialog)
        dialog = new JDialog((Dialog) parent);
    else if (dialog == null)
        dialog = new JDialog(); //no parent
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setModal(true);
    dialog.setTitle(title);
    dialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
    Container container = dialog.getContentPane();
    container.setLayout(new BorderLayout(0, 0));
    container.add(c, BorderLayout.CENTER);
    centerAndShow(dialog);
}