Example usage for javax.swing JOptionPane QUESTION_MESSAGE

List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE

Introduction

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

Prototype

int QUESTION_MESSAGE

To view the source code for javax.swing JOptionPane QUESTION_MESSAGE.

Click Source Link

Document

Used for questions.

Usage

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java

/**
 * Performs the real work of downloading files by comparing the download candidates against
 * existing files, prompting the user whether to overwrite any pre-existing file versions,
 * and starting {@link S3ServiceMulti#downloadObjects} where the real work is done.
 *
 *//*from ww  w  .j a  v a  2  s.c o  m*/
private DownloadPackage[] buildDownloadPackageList(FileComparerResults comparisonResults,
        Map s3DownloadObjectsMap) throws Exception {
    // Determine which files to download, prompting user whether to over-write existing files
    List objectKeysForDownload = new ArrayList();
    objectKeysForDownload.addAll(comparisonResults.onlyOnServerKeys);

    int newFiles = comparisonResults.onlyOnServerKeys.size();
    int unchangedFiles = comparisonResults.alreadySynchronisedKeys.size();
    int changedFiles = comparisonResults.updatedOnClientKeys.size()
            + comparisonResults.updatedOnServerKeys.size();

    if (unchangedFiles > 0 || changedFiles > 0) {
        // Ask user whether to replace existing unchanged and/or existing changed files.
        log.debug(
                "Files for download clash with existing local files, prompting user to choose which files to replace");
        List options = new ArrayList();
        String message = "Of the " + (newFiles + unchangedFiles + changedFiles)
                + " objects being downloaded:\n\n";

        if (newFiles > 0) {
            message += newFiles + " files are new.\n\n";
            options.add(DOWNLOAD_NEW_FILES_ONLY);
        }
        if (changedFiles > 0) {
            message += changedFiles + " files have changed.\n\n";
            options.add(DOWNLOAD_NEW_AND_CHANGED_FILES);
        }
        if (unchangedFiles > 0) {
            message += unchangedFiles + " files already exist and are unchanged.\n\n";
            options.add(DOWNLOAD_ALL_FILES);
        }
        message += "Please choose which files you wish to download:";

        Object response = JOptionPane.showInputDialog(ownerFrame, message, "Replace files?",
                JOptionPane.QUESTION_MESSAGE, null, options.toArray(), DOWNLOAD_NEW_AND_CHANGED_FILES);

        if (response == null) {
            return null;
        }

        if (DOWNLOAD_NEW_FILES_ONLY.equals(response)) {
            // No change required to default objectKeysForDownload list.
        } else if (DOWNLOAD_ALL_FILES.equals(response)) {
            objectKeysForDownload.addAll(comparisonResults.updatedOnClientKeys);
            objectKeysForDownload.addAll(comparisonResults.updatedOnServerKeys);
            objectKeysForDownload.addAll(comparisonResults.alreadySynchronisedKeys);
        } else if (DOWNLOAD_NEW_AND_CHANGED_FILES.equals(response)) {
            objectKeysForDownload.addAll(comparisonResults.updatedOnClientKeys);
            objectKeysForDownload.addAll(comparisonResults.updatedOnServerKeys);
        } else {
            // Download cancelled.
            return null;
        }
    }

    log.debug("Downloading " + objectKeysForDownload.size() + " objects");
    if (objectKeysForDownload.size() == 0) {
        return null;
    }

    // Create array of objects for download.
    S3Object[] objects = new S3Object[objectKeysForDownload.size()];
    int objectIndex = 0;
    for (Iterator iter = objectKeysForDownload.iterator(); iter.hasNext();) {
        objects[objectIndex++] = (S3Object) s3DownloadObjectsMap.get(iter.next());
    }

    Map downloadObjectsToFileMap = new HashMap();
    ArrayList downloadPackageList = new ArrayList();

    // Setup files to write to, creating parent directories when necessary.
    for (int i = 0; i < objects.length; i++) {
        File file = new File(downloadDirectory, objects[i].getKey());

        // Encryption password must be null if no password is set.
        String encryptionPassword = null;
        if (cockpitPreferences.isEncryptionPasswordSet()) {
            encryptionPassword = cockpitPreferences.getEncryptionPassword();
        }

        // Create local directories corresponding to objects flagged as dirs.
        if (Mimetypes.MIMETYPE_JETS3T_DIRECTORY.equals(objects[i].getContentType())) {
            file.mkdirs();
        }

        DownloadPackage downloadPackage = ObjectUtils.createPackageForDownload(objects[i], file, true, true,
                encryptionPassword);

        if (downloadPackage != null) {
            downloadObjectsToFileMap.put(objects[i].getKey(), file);
            downloadPackageList.add(downloadPackage);
        }

    }

    return (DownloadPackage[]) downloadPackageList.toArray(new DownloadPackage[downloadPackageList.size()]);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java

private S3Object[] buildUploadObjectsList(FileComparerResults comparisonResults, Map uploadingFilesMap)
        throws Exception {
    // Determine which files to upload, prompting user whether to over-write existing files
    List fileKeysForUpload = new ArrayList();
    fileKeysForUpload.addAll(comparisonResults.onlyOnClientKeys);

    int newFiles = comparisonResults.onlyOnClientKeys.size();
    int unchangedFiles = comparisonResults.alreadySynchronisedKeys.size();
    int changedFiles = comparisonResults.updatedOnClientKeys.size()
            + comparisonResults.updatedOnServerKeys.size();

    if (unchangedFiles > 0 || changedFiles > 0) {
        // Ask user whether to replace existing unchanged and/or existing changed files.
        log.debug(//from   w  w w  . ja va2  s . c  o  m
                "Files for upload clash with existing S3 objects, prompting user to choose which files to replace");
        List options = new ArrayList();
        String message = "Of the " + uploadingFilesMap.size() + " files being uploaded:\n\n";

        if (newFiles > 0) {
            message += newFiles + " files are new.\n\n";
            options.add(UPLOAD_NEW_FILES_ONLY);
        }
        if (changedFiles > 0) {
            message += changedFiles + " files have changed.\n\n";
            options.add(UPLOAD_NEW_AND_CHANGED_FILES);
        }
        if (unchangedFiles > 0) {
            message += unchangedFiles + " files already exist and are unchanged.\n\n";
            options.add(UPLOAD_ALL_FILES);
        }
        message += "Please choose which files you wish to upload:";

        Object response = JOptionPane.showInputDialog(ownerFrame, message, "Replace files?",
                JOptionPane.QUESTION_MESSAGE, null, options.toArray(), UPLOAD_NEW_AND_CHANGED_FILES);

        if (response == null) {
            return null;
        }

        if (UPLOAD_NEW_FILES_ONLY.equals(response)) {
            // No change required to default fileKeysForUpload list.
        } else if (UPLOAD_ALL_FILES.equals(response)) {
            fileKeysForUpload.addAll(comparisonResults.updatedOnClientKeys);
            fileKeysForUpload.addAll(comparisonResults.updatedOnServerKeys);
            fileKeysForUpload.addAll(comparisonResults.alreadySynchronisedKeys);
        } else if (UPLOAD_NEW_AND_CHANGED_FILES.equals(response)) {
            fileKeysForUpload.addAll(comparisonResults.updatedOnClientKeys);
            fileKeysForUpload.addAll(comparisonResults.updatedOnServerKeys);
        } else {
            // Upload cancelled.
            stopProgressDialog();
            return null;
        }
    }

    if (fileKeysForUpload.size() == 0) {
        return null;
    }

    final String[] statusText = new String[1];
    statusText[0] = "Prepared 0 of " + fileKeysForUpload.size() + " files for upload";
    startProgressDialog(statusText[0], "", 0, 100, null, null);

    long bytesToProcess = 0;
    for (Iterator iter = fileKeysForUpload.iterator(); iter.hasNext();) {
        File file = (File) uploadingFilesMap.get(iter.next().toString());
        bytesToProcess += file.length() * (cockpitPreferences.isUploadEncryptionActive()
                || cockpitPreferences.isUploadCompressionActive() ? 3 : 1);
    }

    BytesProgressWatcher progressWatcher = new BytesProgressWatcher(bytesToProcess) {
        public void updateBytesTransferred(long byteCount) {
            super.updateBytesTransferred(byteCount);

            String detailsText = formatBytesProgressWatcherDetails(this, false);
            int progressValue = (int) ((double) getBytesTransferred() * 100 / getBytesToTransfer());
            updateProgressDialog(statusText[0], detailsText, progressValue);
        }
    };

    // Populate S3Objects representing upload files with metadata etc.
    final S3Object[] objects = new S3Object[fileKeysForUpload.size()];
    int objectIndex = 0;
    for (Iterator iter = fileKeysForUpload.iterator(); iter.hasNext();) {
        String fileKey = iter.next().toString();
        File file = (File) uploadingFilesMap.get(fileKey);

        S3Object newObject = ObjectUtils.createObjectForUpload(fileKey, file,
                (cockpitPreferences.isUploadEncryptionActive() ? encryptionUtil : null),
                cockpitPreferences.isUploadCompressionActive(), progressWatcher);

        String aclPreferenceString = cockpitPreferences.getUploadACLPermission();
        if (CockpitPreferences.UPLOAD_ACL_PERMISSION_PRIVATE.equals(aclPreferenceString)) {
            // Objects are private by default, nothing more to do.
        } else if (CockpitPreferences.UPLOAD_ACL_PERMISSION_PUBLIC_READ.equals(aclPreferenceString)) {
            newObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
        } else if (CockpitPreferences.UPLOAD_ACL_PERMISSION_PUBLIC_READ_WRITE.equals(aclPreferenceString)) {
            newObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ_WRITE);
        } else {
            log.warn("Ignoring unrecognised upload ACL permission setting: " + aclPreferenceString);
        }

        statusText[0] = "Prepared " + (objectIndex + 1) + " of " + fileKeysForUpload.size()
                + " files for upload";

        objects[objectIndex++] = newObject;
    }

    stopProgressDialog();

    return objects;
}

From source file:org.executequery.gui.browser.SSHTunnelConnectionPanel.java

public boolean canConnect() {

    if (useSshCheckbox.isSelected()) {

        if (!hasValue(userNameField)) {

            GUIUtilities/* ww  w . ja  va2 s.c  o m*/
                    .displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH user name");
            return false;
        }

        if (!hasValue(portField)) {

            GUIUtilities.displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH port");
            return false;
        }

        if (!hasValue(passwordField)) {

            final JPasswordField field = WidgetFactory.createPasswordField();

            JOptionPane optionPane = new JOptionPane(field, JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.OK_CANCEL_OPTION);
            JDialog dialog = optionPane.createDialog("Enter SSH password");

            dialog.addWindowFocusListener(new WindowAdapter() {
                @Override
                public void windowGainedFocus(WindowEvent e) {
                    field.requestFocusInWindow();
                }
            });

            dialog.pack();
            dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize()));
            dialog.setVisible(true);
            dialog.dispose();

            int result = Integer.parseInt(optionPane.getValue().toString());
            if (result == JOptionPane.OK_OPTION) {

                String password = MiscUtils.charsToString(field.getPassword());
                if (StringUtils.isNotBlank(password)) {

                    passwordField.setText(password);
                    return true;

                } else {

                    GUIUtilities.displayErrorMessage(
                            "You have selected SSH Tunnel but have not provided an SSH password");

                    // send back here and force them to select cancel if they want to bail

                    return canConnect();
                }

            }
            return false;
        }

    }

    return true;
}

From source file:org.exist.launcher.Launcher.java

protected void signalStarted() {
    if (isSystemTraySupported()) {
        final int port = jetty.isPresent() ? jetty.get().getPrimaryPort() : 8080;
        trayIcon.setToolTip("eXist-db server running on port " + port);
        startItem.setEnabled(false);//from ww w .  j  ava 2  s . c o  m
        stopItem.setEnabled(true);
        checkInstalledApps();
        registerObserver();
    }
    if (!inServiceInstall && !runningAsService.isPresent() && SystemUtils.IS_OS_WINDOWS) {
        inServiceInstall = true;
        SwingUtilities.invokeLater(() -> {
            if (JOptionPane.showConfirmDialog(splash, "It is recommended to run eXist as a service on "
                    + "Windows.\nNot doing so may lead to data loss if you shut down the computer before "
                    + "eXist.\n\nWould you like to install the service?", "Install as Service?",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                installAsService();
            }
        });
    }
}

From source file:org.f2o.absurdum.puck.gui.PuckFrame.java

/**
 * Asks the user if she wishes to save the file before exiting PUCK.
 *//*  w w w  .j  a v a  2s  . com*/
public void askSaveExitCancel() {
    int option = JOptionPane.showConfirmDialog(PuckFrame.this,
            UIMessages.getInstance().getMessage("confirm.saveonexit.text"),
            UIMessages.getInstance().getMessage("confirm.saveonexit.title"), JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    if (option == JOptionPane.YES_OPTION) {
        try {
            boolean done;
            if (editingFileName != null) {
                saveChangesInCurrentFile();
                done = true;
            } else {
                done = saveAs();
            }
            if (done)
                exit();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!",
                    JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }
    } else if (option == JOptionPane.NO_OPTION) {
        exit();
    }
}

From source file:org.f2o.absurdum.puck.gui.PuckFrame.java

/**
 * Shows exit confirmation dialog and exits PUCK if user selects "Yes".
 *///  w  w w  .  j  ava 2 s .  co  m
public void exitIfConfirmed() {

    int opt = JOptionPane.showConfirmDialog(PuckFrame.this,
            UIMessages.getInstance().getMessage("exit.sure.text"),
            UIMessages.getInstance().getMessage("exit.sure.title"), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE);

    if (opt == JOptionPane.YES_OPTION) {
        exit();
    }
}

From source file:org.fhaes.gui.AnalysisResultsPanel.java

/**
 * Save a file to disk, asking the user for a filename. Add the selected FileFilter to the save dialog box.
 * /* w  w w . j  a  v a2s.co  m*/
 * @param fileToSave
 * @param filter
 */
private void saveFileToDisk(File fileToSave, FileFilter filter) {

    File outfile = IOUtil.getOutputFile(filter);

    if (outfile == null)
        return;

    if (outfile.exists()) {
        Object[] options = { "Overwrite", "No", "Cancel" };
        int response = JOptionPane.showOptionDialog(App.mainFrame,
                "This file already exists.  Are you sure you want to overwrite?", "Confirm",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon
                options, // the titles of buttons
                options[0]); // default button title

        if (response != JOptionPane.YES_OPTION) {
            return;
        }

    }

    try {
        FileUtils.copyFile(fileToSave, outfile);
    } catch (IOException e) {
        JOptionPane.showMessageDialog(App.mainFrame, "Error saving file:\n" + e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.fhaes.gui.ShapeFileDialog.java

/**
 * Prompt the user for an output filename
 * //from   w ww . j  av a  2  s  . c om
 * @param filter
 * @return
 */
private File getOutputFile(FileFilter filter) {

    String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null);
    File outputFile;

    // Create a file chooser
    final JFileChooser fc = new JFileChooser(lastVisitedFolder);

    fc.setAcceptAllFileFilterUsed(true);

    if (filter != null) {
        fc.addChoosableFileFilter(filter);
        fc.setFileFilter(filter);
    }

    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);
    fc.setDialogTitle("Save as...");

    // In response to a button click:
    int returnVal = fc.showSaveDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        outputFile = fc.getSelectedFile();

        if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") {
            log.debug("Output file extension not set by user");

            if (fc.getFileFilter().getDescription().equals(new SHPFileFilter().getDescription())) {
                log.debug("Adding shp extension to output file name");
                outputFile = new File(outputFile.getAbsolutePath() + ".shp");
            }
        } else {
            log.debug("Output file extension set my user to '"
                    + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'");
        }

        App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath());
    } else {
        return null;
    }

    if (outputFile.exists()) {
        Object[] options = { "Overwrite", "No", "Cancel" };
        int response = JOptionPane.showOptionDialog(this,
                "The file '" + outputFile.getName() + "' already exists.  Are you sure you want to overwrite?",
                "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon
                options, // the titles of buttons
                options[0]); // default button title

        if (response != JOptionPane.YES_OPTION) {
            return null;
        }
    }

    return outputFile;
}

From source file:org.fuin.kickstart4j.Kickstart4J.java

private static boolean isAnswerYes(final String message) {
    final int result = ThreadSafeJOptionPane.showConfirmDialog(null, message, "TITLE",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    return result == JOptionPane.YES_OPTION;
}

From source file:org.gcaldaemon.gui.ConfigEditor.java

public final boolean question(String title, String message) {
    status(message);/*from   w  w  w .  j  av  a2  s.c om*/
    String[] options = new String[2];
    options[0] = Messages.getString("ok"); //$NON-NLS-1$
    options[1] = Messages.getString("cancel"); //$NON-NLS-1$
    return (0 == JOptionPane.showOptionDialog(this, message, title, JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, null));
}