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, int messageType) 

Source Link

Document

Brings up an internal dialog panel where the number of choices is determined by the optionType parameter, where the messageType parameter determines the icon to display.

Usage

From source file:canreg.client.gui.analysis.ExportReportInternalFrame.java

/**
 *
 * @return/*w  ww  .j av  a2 s.c om*/
 */
@Action
public Task writeFileAction() {
    if (chooser == null) {
        path = localSettings.getProperty("export_data_path");
        if (path == null) {
            chooser = new JFileChooser();
        } else {
            chooser = new JFileChooser(path);
        }
    }
    // Get filename
    int returnVal = chooser.showSaveDialog(this);
    fileName = "";
    String separatingString = "\t";
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            //set the file name
            fileName = chooser.getSelectedFile().getCanonicalPath();

            // TODO: Make this dynamic
            if (fileFormatComboBox.getSelectedIndex() == 0) {
                separatingString = ",";
                // append standard file extension
                if (!(fileName.endsWith(".csv") || fileName.endsWith(".CSV"))) {
                    fileName += ".csv";
                }
            } else {
                if (fileFormatComboBox.getSelectedIndex() == 1) {
                    separatingString = "\t";
                } else {
                    separatingString = fileFormatComboBox.getSelectedItem().toString();
                }
                // append standard file extension
                if (!(fileName.endsWith(".tsv") || fileName.endsWith(".TSV"))
                        && !(fileName.endsWith(".csv") || fileName.endsWith(".CSV"))
                        && !(fileName.endsWith(".txt") || fileName.endsWith(".TXT"))) {
                    fileName += ".txt";
                }
            }

            File file = new File(fileName);
            if (file.exists()) {
                int choice = JOptionPane.showInternalConfirmDialog(
                        CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                        java.util.ResourceBundle
                                .getBundle("canreg/client/gui/analysis/resources/ExportReportInternalFrame")
                                .getString("FILE_EXISTS")
                                + ": " + fileName + ".\n"
                                + java.util.ResourceBundle.getBundle(
                                        "canreg/client/gui/analysis/resources/ExportReportInternalFrame")
                                        .getString("OVERWRITE?"),
                        java.util.ResourceBundle
                                .getBundle("canreg/client/gui/analysis/resources/ExportReportInternalFrame")
                                .getString("FILE_EXISTS") + ".",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (choice == JOptionPane.CANCEL_OPTION) {
                    return null;
                } else if (choice == JOptionPane.NO_OPTION) {
                    // choose a new file
                    writeFileAction();
                    return null;
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(ExportReportInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        return null;
    }
    return new WriteFileActionTask(fileName,
            org.jdesktop.application.Application.getInstance(canreg.client.CanRegClientApp.class),
            separatingString);
}