Example usage for javax.swing JOptionPane showInternalConfirmDialog

List of usage examples for javax.swing JOptionPane showInternalConfirmDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showInternalConfirmDialog.

Prototype

public static int showInternalConfirmDialog(Component parentComponent, Object message, String title,
        int optionType) 

Source Link

Document

Brings up a internal dialog panel where the number of choices is determined by the optionType parameter.

Usage

From source file:InternalFrameTest.java

/**
 * Creates an internal frame on the desktop.
 * @param c the component to display in the internal frame
 * @param t the title of the internal frame.
 *//*from  w w  w .j a v  a 2  s . com*/
public void createInternalFrame(Component c, String t) {
    final JInternalFrame iframe = new JInternalFrame(t, true, // resizable
            true, // closable
            true, // maximizable
            true); // iconifiable

    iframe.add(c, BorderLayout.CENTER);
    desktop.add(iframe);

    iframe.setFrameIcon(new ImageIcon("document.gif"));

    // add listener to confirm frame closing
    iframe.addVetoableChangeListener(new VetoableChangeListener() {
        public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
            String name = event.getPropertyName();
            Object value = event.getNewValue();

            // we only want to check attempts to close a frame
            if (name.equals("closed") && value.equals(true)) {
                // ask user if it is ok to close
                int result = JOptionPane.showInternalConfirmDialog(iframe, "OK to close?", "Select an Option",
                        JOptionPane.YES_NO_OPTION);

                // if the user doesn't agree, veto the close
                if (result != JOptionPane.YES_OPTION)
                    throw new PropertyVetoException("User canceled close", event);
            }
        }
    });

    // position frame
    int width = desktop.getWidth() / 2;
    int height = desktop.getHeight() / 2;
    iframe.reshape(nextFrameX, nextFrameY, width, height);

    iframe.show();

    // select the frame--might be vetoed
    try {
        iframe.setSelected(true);
    } catch (PropertyVetoException e) {
    }

    frameDistance = iframe.getHeight() - iframe.getContentPane().getHeight();

    // compute placement for next frame

    nextFrameX += frameDistance;
    nextFrameY += frameDistance;
    if (nextFrameX + width > desktop.getWidth())
        nextFrameX = 0;
    if (nextFrameY + height > desktop.getHeight())
        nextFrameY = 0;
}

From source file:canreg.client.gui.management.CanReg4MigrationInternalFrame.java

@Action
public void cancelAction() throws RemoteException, IOException {
    isPaused = true;//from   ww  w. j ava  2  s  .  c  om
    if (cTask != null) {
        if (JOptionPane.showInternalConfirmDialog(
                CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                        .getString("REALLY_CANCEL?"),
                java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                        .getString("PLEASE_CONFIRM."),
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            cTask.cancel(true);
            JOptionPane.showInternalMessageDialog(
                    CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                    java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                            .getString("IMPORT_OF_FILE_INTERUPTED"),
                    java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                            .getString("WARNING"),
                    JOptionPane.WARNING_MESSAGE);
            cTask = null;
            this.dispose();
        } else {
            isPaused = false;
        }
    } else {
        this.dispose();
    }
}

From source file:canreg.client.gui.management.CanReg4MigrationInternalFrame.java

@Action
public void MigrationAction() {
    okButton.setEnabled(false);//from   ww w  .j  a va2 s . c o m
    doneButton.setEnabled(false);
    cancelButton.setEnabled(true);
    jList1.setEnabled(false);
    EditDatabaseVariableTableAssociationInternalFrame edvif = new EditDatabaseVariableTableAssociationInternalFrame();
    int addServer = JOptionPane.showInternalConfirmDialog(
            CanRegClientApp.getApplication().getMainFrame().getContentPane(),
            java.util.ResourceBundle
                    .getBundle("canreg/client/gui/management/resources/CanReg4SystemConverterInternalFrame")
                    .getString("SUCCESSFULLY_CREATED_XML: ") + "\'" + Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER
                    + Globals.FILE_SEPARATOR + regcode + "\'.\n"
                    + java.util.ResourceBundle.getBundle(
                            "canreg/client/gui/management/resources/CanReg4SystemConverterInternalFrame")
                            .getString("ADD_IT_TO_FAV_SERVERS?"),
            "Success", JOptionPane.YES_NO_OPTION);
    if (addServer == JOptionPane.YES_OPTION) {
        localSettings = CanRegClientApp.getApplication().getLocalSettings();
        localSettings.addServerToServerList(dlm.get(list.getSelectedIndex()), "localhost", Globals.DEFAULT_PORT,
                regcode);
        localSettings.writeSettings();
    }
    try {
        edvif.setTitle("Variables and Tables for "
                + WordUtils.capitalize(dlm.get(list.getSelectedIndex()).toLowerCase()));
        edvif.loadSystemDefinition(
                Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode + ".xml");
        edvif.setDesktopPane(desktopPane);
        CanRegClientView.showAndPositionInternalFrame(desktopPane, edvif);
    } catch (IOException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(CanReg4SystemConverterInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

    edvif.saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //logout from canreg system before conversion
            if (CanRegClientApp.getApplication().loggedIn) {
                try {
                    CanRegClientApp.getApplication().logOut();
                } catch (RemoteException ex) {
                    Logger.getLogger(CanReg4MigrationInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            //check to see if there is a database already - rename it
            File databaseFolder = new File(
                    Globals.CANREG_SERVER_DATABASE_FOLDER + Globals.FILE_SEPARATOR + regcode);
            if (databaseFolder.exists()) {
                int i = 0;
                File folder2 = databaseFolder;
                while (folder2.exists()) {
                    i++;
                    folder2 = new File(
                            Globals.CANREG_SERVER_DATABASE_FOLDER + Globals.FILE_SEPARATOR + regcode + i);
                }
                databaseFolder.renameTo(folder2);
                debugOut("database: " + databaseFolder);
                try {
                    canreg.common.Tools.fileCopy(
                            Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode
                                    + ".xml",
                            Globals.CANREG_SERVER_SYSTEM_CONFIG_FOLDER + Globals.FILE_SEPARATOR + regcode + i
                                    + ".xml");
                } catch (IOException ex) {
                    Logger.getLogger(CanReg4MigrationInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            ProgressBar.setStringPainted(true);
            cTask = new ProgressTask(
                    org.jdesktop.application.Application.getInstance(canreg.client.CanRegClientApp.class));
            cTask.execute();
            cTask.addPropertyChangeListener(new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if ("progress".equals(evt.getPropertyName())) {
                        ProgressBar.setValue((Integer) evt.getNewValue());
                        ProgressBar.setString(evt.getNewValue().toString() + "%");
                    }
                }
            });
        }
    });
}

From source file:canreg.client.gui.dataentry.ImportView.java

/**
 *
 *///from  ww  w .ja v a  2  s.  com
@Action
public void cancelAction() {
    if (importTask != null) {
        if (JOptionPane.showInternalConfirmDialog(
                CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                        .getString("REALLY_CANCEL?"),
                java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                        .getString("PLEASE_CONFIRM."),
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            importTask.cancel(true);
            JOptionPane.showInternalMessageDialog(
                    CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                    java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                            .getString("IMPORT_OF_FILE_INTERUPTED"),
                    java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/ImportView")
                            .getString("WARNING"),
                    JOptionPane.WARNING_MESSAGE);
            importTask = null;
            this.dispose();
        }
    } else {
        this.dispose();
    }
}

From source file:canreg.client.gui.dataentry.PDSEditorInternalFrame.java

@Action
public void deletePopulationDataSetAction() {
    int result = JOptionPane.showInternalConfirmDialog(
            CanRegClientApp.getApplication().getMainFrame().getContentPane(),
            java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                    .getString("REALLY_DELETE:_") + pds.getPopulationDatasetName() + ".",
            java.util.ResourceBundle.getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                    .getString("REALLY_DELETE?"),
            JOptionPane.YES_NO_OPTION);
    if (result == JOptionPane.YES_OPTION) {
        try {//from w w w. ja v a2  s  .  c  o m
            CanRegClientApp.getApplication().deletePopulationDataset(pds.getPopulationDatasetID());
            JOptionPane.showInternalMessageDialog(
                    CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                    java.util.ResourceBundle
                            .getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                            .getString("SUCCESSFULLY_DELETED_PDS:_") + pds.getPopulationDatasetName() + ".",
                    java.util.ResourceBundle
                            .getBundle("canreg/client/gui/dataentry/resources/PDSEditorInternalFrame")
                            .getString("PDS_SAVED."),
                    JOptionPane.INFORMATION_MESSAGE);
            if (listener != null) {
                listener.actionPerformed(new ActionEvent(this, 1, "refresh"));
            }
        } catch (SQLException | RemoteException | SecurityException ex) {
            Logger.getLogger(PDSEditorInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}