Example usage for javax.swing JOptionPane NO_OPTION

List of usage examples for javax.swing JOptionPane NO_OPTION

Introduction

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

Prototype

int NO_OPTION

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

Click Source Link

Document

Return value from class method if NO is chosen.

Usage

From source file:org.executequery.gui.ReadOnlyTextPanePopUpMenu.java

public void saveToFile(ActionEvent e) {

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);

    fileChooser.setDialogTitle("Select Output File Path");
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select");
    if (result == JFileChooser.CANCEL_OPTION) {

        return;/*from w  w  w  .  j  ava  2 s  .c om*/
    }

    File file = fileChooser.getSelectedFile();
    if (file.exists()) {

        result = GUIUtilities.displayConfirmCancelDialog("The selected file exists.\nOverwrite existing file?");

        if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.NO_OPTION) {

            saveToFile(e);
            return;
        }

    }

    try {

        FileUtils.writeFile(file.getAbsolutePath(), readOnlyTextArea.getText());

    } catch (IOException e1) {

        GUIUtilities.displayErrorMessage("Error writing output pane contents to file.\n" + e1.getMessage());
    }
}

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

/**
 * Asks the user if she wishes to save the file before exiting PUCK.
 *///from   ww  w.j a  v  a2  s  . c  o  m
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.geopublishing.atlasStyler.swing.AtlasStylerSaveAsLayerToSLDAction.java

@Override
public void actionPerformed(ActionEvent e) {

    boolean backup = false;

    File startWithFile = new File(System.getProperty("user.home"), styledLayer.getTitle().toString() + ".sld");

    if (styledLayer.getSldFile() != null)
        startWithFile = styledLayer.getSldFile();

    File exportFile = AsSwingUtil.chooseFileSave(owner, startWithFile,
            ASUtil.R("StyledLayerSLD.ChooseFileLocationDialog.Title"),
            new FileExtensionFilter(ASUtil.FILTER_SLD));

    if (exportFile == null)
        return;/*from  w  ww.j a  v a2  s .  com*/

    if (!(exportFile.getName().toLowerCase().endsWith(".sld")
            || exportFile.getName().toLowerCase().endsWith(".xml"))) {
        exportFile = new File(exportFile.getParentFile(), exportFile.getName() + ".sld");
    }

    styledLayer.setSldFile(exportFile);

    if (styledLayer.getSldFile().exists()) {
        try {
            FileUtils.copyFile(styledLayer.getSldFile(),
                    IOUtil.changeFileExt(styledLayer.getSldFile(), "sld.bak"));
            backup = true;
        } catch (IOException e1) {
            LOGGER.warn("could not create a backup of the existing .sld", e1);
            return;
        }
    }

    try {
        StylingUtil.saveStyleToSld(styledLayer.getStyle(), styledLayer.getSldFile());
        StylingUtil.saveStyleToSld(styledLayer.getStyle(),
                ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()), true,
                getOptimizedTitle(styledLayer));

        Object[] options = { "OK", ASUtil.R("AtlasStylerSaveLayerToSLD.OpenFile"),
                ASUtil.R("AtlasStylerSaveLayerToSLD.OpenProductive") };
        int dialogValue = 0;

        if (backup) {
            dialogValue = JOptionPane.showOptionDialog(owner,
                    ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccessAndBackedUp",
                            IOUtil.escapePath(styledLayer.getSldFile())),
                    "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
        } else {
            dialogValue = JOptionPane.showOptionDialog(owner,
                    ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccess",
                            IOUtil.escapePath(styledLayer.getSldFile())),
                    "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
        }
        if (dialogValue == JOptionPane.NO_OPTION) {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(styledLayer.getSldFile());
        }
        if (dialogValue == JOptionPane.CANCEL_OPTION) {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()));
        }

        List<Exception> es = StylingUtil.validateSld(new FileInputStream(styledLayer.getSldFile()));
        if (es.size() > 0) {
            ExceptionDialog.show(owner,
                    new IllegalStateException(ASUtil.R("AtlasStylerExport.WarningSLDNotValid",
                            IOUtil.escapePath(styledLayer.getSldFile())), es.get(0)));
        }

    } catch (Exception e1) {
        LOGGER.error("saveStyleToSLD", e1);
        ExceptionDialog.show(owner, e1);
        return;
    }
}

From source file:org.geopublishing.atlasStyler.swing.AtlasStylerSaveLayerToSLDAction.java

@Override
public void actionPerformed(ActionEvent e) {

    boolean backup = false;

    if (styledLayer.getSldFile().exists()) {

        // if (StylingUtil.isStyleDifferent(styledLayer.getStyle(),
        // styledLayer.getSldFile())){
        // return;
        // }/*from  ww w .  j  av a  2 s .  c  o m*/

        try {
            FileUtils.copyFile(styledLayer.getSldFile(),
                    IOUtil.changeFileExt(styledLayer.getSldFile(), "sld.bak"));
            backup = true;
        } catch (IOException e1) {
            LOGGER.warn("could not create a backup of the existing .sld", e1);
            return;
        }
    }

    try {
        StylingUtil.saveStyleToSld(styledLayer.getStyle(), styledLayer.getSldFile());
        StylingUtil.saveStyleToSld(styledLayer.getStyle(),
                ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()), true,
                "AtlasStyler " + ReleaseUtil.getVersionInfo(AtlasStyler.class) + ", Layer:"
                        + styledLayer.getTitle() + ", Export-Mode: PRODUCTION");

        Object[] options = { "OK", ASUtil.R("AtlasStylerSaveLayerToSLD.OpenFile"),
                ASUtil.R("AtlasStylerSaveLayerToSLD.OpenProductive") };
        int dialogValue = 0;
        if (backup) {
            dialogValue = JOptionPane.showOptionDialog(owner,
                    ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccessAndBackedUp",
                            IOUtil.escapePath(styledLayer.getSldFile())),
                    "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
        } else {
            dialogValue = JOptionPane.showOptionDialog(owner,
                    ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccess",
                            IOUtil.escapePath(styledLayer.getSldFile())),
                    "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
        }
        if (dialogValue == JOptionPane.NO_OPTION) {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(styledLayer.getSldFile());
        }
        if (dialogValue == JOptionPane.CANCEL_OPTION) {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()));
        }
        List<Exception> es = StylingUtil.validateSld(new FileInputStream(styledLayer.getSldFile()));
        if (es.size() > 0) {
            ExceptionDialog.show(owner,
                    new IllegalStateException(ASUtil.R("AtlasStylerExport.WarningSLDNotValid",
                            IOUtil.escapePath(styledLayer.getSldFile())), es.get(0)));
        }

    } catch (Exception e1) {
        LOGGER.error("saveStyleToSLD", e1);
        ExceptionDialog.show(owner, e1);
        return;
    }
}

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

public void executeSqlFile() {

    // Get selected schema
    String schema = MainDao.getSchema();
    if (schema == null || schema.equals("")) {
        String msg = Utils.getBundleString("MenuController.project_not_selected_backup2"); //$NON-NLS-1$
        MainClass.mdi.showMessage(msg);/*from   ww w .  jav a2  s . c  om*/
        return;
    }

    // Get SQL file to execute
    String filePath = chooseSqlFile(false);
    if (filePath.equals(""))
        return;

    // Get schema SRID
    String srid = MainDao.getSrid(schema);

    // Ask for confirmation
    int answer = Utils.showYesNoDialog(mainFrame, "MenuController.file_launcher_warning");
    if (answer == JOptionPane.NO_OPTION)
        return;

    try {

        // Copy file to users folder
        String tempPath = Utils.getLogFolder() + "temp.sql";
        Utils.copyFile(filePath, tempPath);

        // Search if we have _PARAM in the file
        // If found, ask user to input param value. Replace _PARAM_ with this value
        String msgAbort = Utils.getBundleString("MenuController.abort_process");
        String content = Utils.readFile(tempPath);
        if (content.contains("_PARAM")) {
            // Get parameters list
            HashMap<String, String> mapParams = new HashMap<String, String>();
            int i = 0;
            int offset = 0;
            while (offset > -1) {
                offset = content.indexOf("_PARAM", i);
                if (offset > -1) {
                    int aux = content.indexOf("_", offset + 1);
                    String paramName = content.substring(offset, aux + 1);
                    // If is a new one, ask user for its value
                    if (!mapParams.containsKey(paramName)) {
                        String msg = Utils.getBundleString("MenuController.parameter_found") + " '" + paramName
                                + "' " + Utils.getBundleString("MenuController.parameter_found2");
                        String value = null;
                        while (value == null || value.equals("")) {
                            value = Utils.showInputDialog(mainFrame, msg);
                            if (value == null) {
                                answer = Utils.showYesNoDialog(mainFrame, msgAbort);
                                if (answer == JOptionPane.YES_OPTION)
                                    return;
                            }
                        }
                        content = content.replace(paramName, value);
                        mapParams.put(paramName, value);
                    }
                }
            }
        }

        // Execute task: FileLauncher
        FileLauncherTask task = new FileLauncherTask(content, schema, srid);
        task.addPropertyChangeListener(this);
        task.execute();

    } catch (IOException e) {
        Utils.showError(e, filePath);
    }

}

From source file:org.giswater.dao.MainDao.java

public static void checkSchemaVersion() {

    if (schema == null || schema.equals(""))
        return;/*  w  w w  .  j  a  v  a 2 s. c om*/

    Integer schemaVersion = getSchemaVersion();
    Integer updateVersion = updateMap.get(waterSoftware);
    Utils.getLogger().info("Schema: " + schema + " (" + schemaVersion + ")");
    if (updateVersion == null || updateVersion == -1)
        return;

    // Get project_update value from Properties file
    String projectUpd = PropertiesDao.getPropertiesFile().get("PROJECT_UPDATE", "ask");
    if (updateVersion > schemaVersion && !projectUpd.equals("never")) {
        if (projectUpd.equals("ask")) {
            String msg = Utils.getBundleString("MainDao.would_like_update") + schema //$NON-NLS-1$
                    + Utils.getBundleString("MainDao.current_version") + //$NON-NLS-1$
                    Utils.getBundleString("MainDao.advisable_backup"); //$NON-NLS-1$
            int answer = Utils.showYesNoDialog(msg, Utils.getBundleString("MainDao.update_project")); //$NON-NLS-1$
            if (answer == JOptionPane.NO_OPTION) {
                Utils.getLogger().info("User chose not to update");
                return;
            }
        }
        if (schemaVersion == -1) {
            String sql = "CREATE TABLE IF NOT EXISTS " + schema + ".version ("
                    + " id SERIAL, giswater varchar(16), wsoftware varchar(16), postgres varchar(512),"
                    + " postgis varchar(512),   date timestamp(6) DEFAULT now(), CONSTRAINT version_pkey PRIMARY KEY (id))";
            executeSql(sql, true);
        }
        if (updateSchema(schemaVersion)) {
            String sql = "INSERT INTO " + schema + ".version (giswater, wsoftware, postgres, postgis, date)"
                    + " VALUES ('" + getGiswaterVersion() + "', '" + waterSoftware + "', '"
                    + getPostgreVersion() + "', '" + getPostgisVersion() + "', now())";
            Utils.getLogger().info(sql);
            executeSql(sql, true);
            MainClass.mdi.showMessage(Utils.getBundleString("MainDao.project_updated")); //$NON-NLS-1$
            schemaMap.remove(schema);
        } else {
            MainClass.mdi.showError(Utils.getBundleString("MainDao.project_not_updated")); //$NON-NLS-1$
        }
    }

}

From source file:org.jajuk.util.UpgradeManager.java

/**
 * Require user to perform a deep scan.//w w w .  ja  v a  2  s.com
 */
private static void deepScanRequest() {
    int reply = Messages.getChoice(Messages.getString("Warning.7"), JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.WARNING_MESSAGE);
    if (reply == JOptionPane.CANCEL_OPTION || reply == JOptionPane.NO_OPTION) {
        return;
    }
    if (reply == JOptionPane.YES_OPTION) {
        final Thread t = new Thread("Device Refresh Thread after upgrade") {
            @Override
            public void run() {
                List<Device> devices = DeviceManager.getInstance().getDevices();
                for (Device device : devices) {
                    if (device.isReady()) {
                        device.manualRefresh(false, false, true, null);
                    }
                }
            }
        };
        t.setPriority(Thread.MIN_PRIORITY);
        t.start();
    }
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

private void deleteSelectedObjects() {
    final S3Object[] objects = getSelectedObjects();

    if (objects.length == 0) {
        log.warn("Ignoring delete object(s) command, no currently selected objects");
        return;//from  www  .  j a  v a  2 s  . c  o m
    }

    int response = JOptionPane.showConfirmDialog(ownerFrame,
            (objects.length == 1 ? "Are you sure you want to delete '" + objects[0].getKey() + "'?"
                    : "Are you sure you want to delete " + objects.length + " object(s)"),
            "Delete Object(s)?", JOptionPane.YES_NO_OPTION);

    if (response == JOptionPane.NO_OPTION) {
        return;
    }

    new Thread() {
        @Override
        public void run() {
            try {
                SignatureRequest[] signatureRequests = requestSignedRequests(
                        SignatureRequest.SIGNATURE_TYPE_DELETE, objects);

                if (signatureRequests != null) {
                    String[] signedRequests = new String[signatureRequests.length];
                    for (int i = 0; i < signedRequests.length; i++) {
                        signedRequests[i] = signatureRequests[i].getSignedUrl();
                    }

                    s3ServiceMulti.deleteObjects(signedRequests);
                } else {
                    ErrorDialog.showDialog(ownerFrame, null, cockpitLiteProperties.getProperties(),
                            "Sorry, you do not have the permission to delete files", null);
                }
            } catch (Exception e) {
                stopProgressDialog();
                log.error("Gatekeeper permissions check failed", e);
                ErrorDialog.showDialog(ownerFrame, null, cockpitLiteProperties.getProperties(),
                        "Permissions check failed, please try again", e);
            }
        }
    }.start();
}

From source file:org.kepler.gui.KeplerGraphFrame.java

/**
 * Open a dialog to prompt the user to save a KAR. Return false if the user
 * clicks "cancel", and otherwise return true.
 * /*from w  w w  . ja  v  a  2  s  . co  m*/
 * Overrides Top._queryForSave()
 * 
 * @return _SAVED if the file is saved, _DISCARDED if the modifications are
 *         discarded, _CANCELED if the operation is canceled by the user,
 *         and _FAILED if the user selects save and the save fails.
 */
@Override
protected int _queryForSave() {
    Object[] options = { "Save", "Discard changes", "Cancel" };

    // making more generic since other items to go in the KAR
    // may be the reason for querying to save
    // String query = "Save changes to " + StringUtilities.split(_getName())
    // + "?";
    String query = "Save changes to KAR?";

    // Show the MODAL dialog
    int selected = JOptionPane.showOptionDialog(this, query, "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

    if (selected == JOptionPane.YES_OPTION) {

        JButton saveButton = new JButton("Save Kar");
        ExportArchiveAction eaa = new ExportArchiveAction(this);
        eaa.setRefreshFrameAfterSave(false);
        // if the file already exists, call ExportArchiveAction.setSave()
        // so that the save as file dialog does is not used.
        KARFile karFile = KARManager.getInstance().get(this);
        if (karFile != null) {
            File file = karFile.getFileLocation();
            if (file.canWrite()) {
                eaa.setSaveFile(file);
            }
        }
        saveButton.addActionListener(eaa);
        saveButton.doClick();

        if (eaa.saveSucceeded()) {
            setModified(false);
            return _SAVED;
        } else {
            return _FAILED;
        }

    }

    if (selected == JOptionPane.NO_OPTION) {
        return _DISCARDED;
    }

    return _CANCELED;
}

From source file:org.modelibra.util.FileSelector.java

/**
 * Prompts a user to decide if the file should be replaced: yes or no.
 * //from   www  .j  a  va 2  s .  co m
 * @param parentFrame
 *            parent window
 * @param lang
 *            language
 * @return <code>true</code> if a user chooses yes
 */
public boolean replaceFile(JFrame parentFrame, NatLang lang) {
    // Custom button text
    Object[] options = { lang.getText("yes"), lang.getText("no") };
    JOptionPane.setDefaultLocale(lang.getLocale());
    int response = JOptionPane.showOptionDialog(parentFrame, // parent
            // frame
            lang.getText("replaceFile"), // message
            lang.getText("fileExists"), // title
            JOptionPane.YES_NO_OPTION, // option type
            JOptionPane.QUESTION_MESSAGE, // message type
            null, // don't use a custom icon
            options, // the titles of buttons
            options[0]); // default button title

    if (response == JOptionPane.NO_OPTION) {
        return false;
    }

    return true;
}