Example usage for javax.swing JOptionPane YES_OPTION

List of usage examples for javax.swing JOptionPane YES_OPTION

Introduction

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

Prototype

int YES_OPTION

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

Click Source Link

Document

Return value from class method if YES is chosen.

Usage

From source file:de.ailis.xadrian.components.ComplexEditor.java

/**
 * Prompts for a file name and saves the complex there.
 *///from  w  ww  . j a  v a2s.c o  m
public void saveAs() {
    final SaveComplexDialog dialog = SaveComplexDialog.getInstance();
    dialog.setSelectedFile(getSuggestedFile());
    File file = dialog.open();
    if (file != null) {
        // Add file extension if none present
        if (FileUtils.getExtension(file) == null)
            file = new File(file.getPath() + ".x3c");

        // Save the file if it does not yet exists are user confirms
        // overwrite
        if (!file.exists() || JOptionPane.showConfirmDialog(null, I18N.getString("confirm.overwrite"),
                I18N.getString("confirm.title"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            save(file);
        }
    }
}

From source file:de.fhg.igd.mapviewer.server.file.FileTiler.java

/**
 * Ask the user for an image file for that a tiled map shall be created
 *///  www  .jav  a 2s.  co m
public void run() {
    JFileChooser fileChooser = new JFileChooser();

    // load current dir
    fileChooser.setCurrentDirectory(
            new File(pref.get(PREF_DIR, fileChooser.getCurrentDirectory().getAbsolutePath())));

    // open
    int returnVal = fileChooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        // save current dir
        pref.put(PREF_DIR, fileChooser.getCurrentDirectory().getAbsolutePath());

        // get file
        File imageFile = fileChooser.getSelectedFile();

        // get image dimension
        Dimension size = getSize(imageFile);
        log.info("Image size: " + size);

        // ask for min tile size
        int minTileSize = 0;
        while (minTileSize <= 0) {
            try {
                minTileSize = Integer.parseInt(
                        JOptionPane.showInputDialog("Minimal tile size", String.valueOf(DEF_MIN_TILE_SIZE)));
            } catch (Exception e) {
                minTileSize = 0;
            }
        }

        // determine min map width
        int width = size.width;

        while (width / 2 > minTileSize && width % 2 == 0) {
            width = width / 2;
        }
        int minMapWidth = width; // min map width

        log.info("Minimal map width: " + minMapWidth);

        // determine min map height
        int height = size.height;

        while (height / 2 > minTileSize && height % 2 == 0) {
            height = height / 2; // min map height
        }
        int minMapHeight = height;

        log.info("Minimal map height: " + minMapHeight);

        // ask for min map size
        int minMapSize = 0;
        while (minMapSize <= 0) {
            try {
                minMapSize = Integer.parseInt(
                        JOptionPane.showInputDialog("Minimal map size", String.valueOf(DEF_MIN_MAP_SIZE)));
            } catch (Exception e) {
                minMapSize = 0;
            }
        }

        // determine zoom levels
        int zoomLevels = 1;

        width = size.width;
        height = size.height;

        while (width % 2 == 0 && height % 2 == 0 && width / 2 >= Math.max(minMapWidth, minMapSize)
                && height / 2 >= Math.max(minMapHeight, minMapSize)) {
            zoomLevels++;
            width = width / 2;
            height = height / 2;
        }

        log.info("Number of zoom levels: " + zoomLevels);

        // determine tile width
        width = minMapWidth;
        int tileWidth = minMapWidth;
        for (int i = 3; i < Math.sqrt(minMapWidth) && width > minTileSize;) {
            tileWidth = width;
            if (width % i == 0) {
                width = width / i;
            } else
                i++;
        }

        // determine tile height
        height = minMapHeight;
        int tileHeight = minMapHeight;
        for (int i = 3; i < Math.sqrt(minMapHeight) && height > minTileSize;) {
            tileHeight = height;
            if (height % i == 0) {
                height = height / i;
            } else
                i++;
        }

        // create tiles for each zoom level
        if (JOptionPane.showConfirmDialog(null,
                "Create tiles (" + tileWidth + "x" + tileHeight + ") for " + zoomLevels + " zoom levels?",
                "Create tiles", JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            int currentWidth = size.width;
            int currentHeight = size.height;
            File currentImage = imageFile;

            Properties properties = new Properties();
            properties.setProperty(PROP_TILE_WIDTH, String.valueOf(tileWidth));
            properties.setProperty(PROP_TILE_HEIGHT, String.valueOf(tileHeight));
            properties.setProperty(PROP_ZOOM_LEVELS, String.valueOf(zoomLevels));

            List<File> files = new ArrayList<File>();

            for (int i = 0; i < zoomLevels; i++) {
                int mapWidth = currentWidth / tileWidth;
                int mapHeight = currentHeight / tileHeight;

                log.info("Creating tiles for zoom level " + i);
                log.info("Map width: " + currentWidth + " pixels, " + mapWidth + " tiles");
                log.info("Map height: " + currentHeight + " pixels, " + mapHeight + " tiles");

                // create tiles
                tile(currentImage, TILE_FILE_PREFIX + i + TILE_FILE_SEPARATOR + "%d", TILE_FILE_EXTENSION,
                        tileWidth, tileHeight);

                // add files to list
                for (int num = 0; num < mapWidth * mapHeight; num++) {
                    files.add(new File(imageFile.getParentFile().getAbsolutePath() + File.separator
                            + TILE_FILE_PREFIX + i + TILE_FILE_SEPARATOR + num + TILE_FILE_EXTENSION));
                }

                // store map width and height at current zoom
                properties.setProperty(PROP_MAP_WIDTH + i, String.valueOf(mapWidth));
                properties.setProperty(PROP_MAP_HEIGHT + i, String.valueOf(mapHeight));

                // create image for next zoom level
                currentWidth /= 2;
                currentHeight /= 2;
                // create temp image file name
                File nextImage = suffixFile(imageFile, i + 1);
                // resize image
                convert(currentImage, nextImage, currentWidth, currentHeight, 100);
                // delete previous temp file
                if (!currentImage.equals(imageFile)) {
                    if (!currentImage.delete()) {
                        log.warn("Error deleting " + imageFile.getAbsolutePath());
                    }
                }

                currentImage = nextImage;
            }

            // delete previous temp file
            if (!currentImage.equals(imageFile)) {
                if (!currentImage.delete()) {
                    log.warn("Error deleting " + imageFile.getAbsolutePath());
                }
            }

            // write properties file
            File propertiesFile = new File(
                    imageFile.getParentFile().getAbsolutePath() + File.separator + MAP_PROPERTIES_FILE);
            try {
                FileWriter propertiesWriter = new FileWriter(propertiesFile);
                try {
                    properties.store(propertiesWriter, "Map generated from " + imageFile.getName());
                    // add properties file to list
                    files.add(propertiesFile);
                } finally {
                    propertiesWriter.close();
                }
            } catch (IOException e) {
                log.error("Error writing map properties file", e);
            }

            // add a converter properties file
            String convProperties = askForPath(fileChooser, new ExactFileFilter(CONVERTER_PROPERTIES_FILE),
                    "Select a converter properties file");
            File convFile = null;
            if (convProperties != null) {
                convFile = new File(convProperties);
                files.add(convFile);
            }

            // create jar file
            log.info("Creating jar archive...");
            if (createJarArchive(replaceExtension(imageFile, MAP_ARCHIVE_EXTENSION), files)) {
                log.info("Archive successfully created, deleting tiles...");
                // don't delete converter properties
                if (convFile != null)
                    files.remove(files.size() - 1);
                // delete files
                for (File file : files) {
                    if (!file.delete()) {
                        log.warn("Error deleting " + file.getAbsolutePath());
                    }
                }
            }

            log.info("Fin.");
        }
    }
}

From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java

private boolean promptForUnsavedChanges() {
    if (currentGroupOrUserEditPanel != null && (currentGroupOrUserEditPanel.hasUnsavedChanges())) {

        int option = JOptionPane.showConfirmDialog(getPanel(),
                "You have not saved all of your changes,\n" + "do you want to save them now?", "",
                JOptionPane.INFORMATION_MESSAGE);

        if (option == JOptionPane.YES_OPTION) {
            currentGroupOrUserEditPanel.applyChanges();
            return true;
        }/*from   w  ww . j  ava2 s.  c om*/

        if (option == JOptionPane.NO_OPTION) {
            return true;
        }

        if (option == JOptionPane.CANCEL_OPTION) {
            return false;
        }
    }

    return true;
}

From source file:com.mirth.connect.manager.ManagerController.java

/**
 * Alerts the user with a yes/no option with the passed in 'message'
 *///from w  w w. j av  a2  s .c o m
public boolean alertOptionDialog(Component parent, String message) {
    int option = JOptionPane.showConfirmDialog(parent, message, "Select an Option", JOptionPane.YES_NO_OPTION);
    if (option == JOptionPane.YES_OPTION) {
        return true;
    } else {
        return false;
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchReportFrame.java

private void cleanupReports() {
    Village source;//  w ww .  java2s.c  o  m
    Village target;
    ReportTableTab tab = getActiveTab();
    if (tab == null) {
        return;
    }
    String set = tab.getReportSet();
    List<FightReport> old = new LinkedList<>();
    int currentIndex = 0;
    for (ManageableType elem : ReportManager.getSingleton().getAllElements(set)) {
        FightReport r = (FightReport) elem;
        if (!old.contains(r)) {
            source = r.getSourceVillage();
            target = r.getTargetVillage();
            FarmInformation info = FarmManager.getSingleton().getFarmInformation(target);
            boolean removeByFarmInfo = false;
            if (info != null) {
                if (info.getLastReport() > r.getTimestamp()) {
                    old.add(r);
                    removeByFarmInfo = true;
                }
            }

            if (!removeByFarmInfo) {
                long time = r.getTimestamp();
                int secondaryIndex = 0;
                for (ManageableType elem2 : ReportManager.getSingleton().getAllElements(set)) {
                    FightReport r1 = (FightReport) elem2;
                    if (!old.contains(r1) && r1.getSourceVillage().equals(source)
                            && r1.getTargetVillage().equals(target)) {
                        if (currentIndex != secondaryIndex) {
                            if (r1.getTimestamp() > time || r.equals(r1)) {
                                old.add(r);
                                break;
                            } else {
                                old.add(r1);
                            }
                        }
                    }
                    secondaryIndex++;
                }
            }
        }
        currentIndex++;
    }

    if (!old.isEmpty()) {
        if (JOptionPaneHelper.showQuestionConfirmBox(this,
                old.size() + " veraltete Berichte gefunden. Jetzt lschen?", "Lschen", "Nein",
                "Ja") == JOptionPane.YES_OPTION) {
            ReportManager.getSingleton().removeElements(set, old);
        }
        tab.showInfo(old.size() + " Berichte gelscht");
    } else {
        tab.showInfo("Keine alten Berichte gefunden");
    }
}

From source file:gda.gui.mca.McaGUI.java

private void makeAdcControlDialog() {
    if (adcControlPanel == null) {
        adcControlPanel = new AdcPanel();
        adcDialog = new JDialog();
        Object[] options = { "OK" };
        Object[] array = { adcControlPanel };

        // Create the JOptionPane.
        final JOptionPane optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION,
                null, options, options[0]);
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {

            @Override/*from w w  w  .  j a  v a2s.  c  o  m*/
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();

                if (isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop)
                        || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if ("OK".equals(value)) {

                        adcDialog.setVisible(false);
                    }
                }

            }

        });
        adcDialog.setContentPane(optionPane);
        adcDialog.pack();
        adcDialog.setTitle("ADC Controls");
        adcDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    }

}

From source file:ffx.ui.KeywordPanel.java

/**
 * Give the user a File Dialog Box so they can select a key file.
 *//*from ww  w  .  ja va 2s.  co  m*/
public void keyOpen() {
    if (fileOpen && KeywordComponent.isKeywordModified()) {
        int option = JOptionPane.showConfirmDialog(this, "Save Changes First", "Opening New File",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (option == JOptionPane.CANCEL_OPTION) {
            return;
        } else if (option == JOptionPane.YES_OPTION) {
            keySave(currentKeyFile);
        }
        keyClear();
    }
    JFileChooser d = MainPanel.resetFileChooser();
    if (currentSystem != null) {
        File cwd = currentSystem.getFile();
        if (cwd != null && cwd.getParentFile() != null) {
            d.setCurrentDirectory(cwd.getParentFile());
        }
    }
    d.setAcceptAllFileFilterUsed(false);
    d.setFileFilter(MainPanel.keyFileFilter);
    d.setDialogTitle("Open KEY File");
    int result = d.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        File newKeyFile = d.getSelectedFile();
        if (newKeyFile != null && newKeyFile.exists() && newKeyFile.canRead()) {
            keyOpen(newKeyFile);
        }
    }
}

From source file:org.datacleaner.bootstrap.Bootstrap.java

private FileObject[] downloadFiles(String[] urls, FileObject targetDirectory, String[] targetFilenames,
        WindowContext windowContext, MonitorHttpClient httpClient, MonitorConnection monitorConnection) {
    final DownloadFilesActionListener downloadAction = new DownloadFilesActionListener(urls, targetDirectory,
            targetFilenames, null, windowContext, httpClient);
    try {/* w w w.j a  v  a  2  s  .c o m*/
        downloadAction.actionPerformed(null);
        FileObject[] files = downloadAction.getFiles();
        if (logger.isInfoEnabled()) {
            logger.info("Succesfully downloaded urls: {}", Arrays.toString(urls));
        }
        return files;
    } catch (SSLPeerUnverifiedException e) {
        downloadAction.cancelDownload(true);
        if (monitorConnection == null || monitorConnection.isAcceptUnverifiedSslPeers()) {
            throw new IllegalStateException("Failed to verify SSL peer", e);
        }
        if (logger.isInfoEnabled()) {
            logger.info("SSL peer not verified. Asking user for confirmation to accept urls: {}",
                    Arrays.toString(urls));
        }
        int confirmation = JOptionPane.showConfirmDialog(null,
                "Unverified SSL peer.\n\n"
                        + "The certificate presented by the server could not be verified.\n\n"
                        + "Do you want to continue, accepting the unverified certificate?",
                "Unverified SSL peer", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);
        if (confirmation != JOptionPane.YES_OPTION) {
            throw new IllegalStateException(e);
        }
        monitorConnection.setAcceptUnverifiedSslPeers(true);
        httpClient = monitorConnection.getHttpClient();

        return downloadFiles(urls, targetDirectory, targetFilenames, windowContext, httpClient,
                monitorConnection);
    }
}

From source file:com.vgi.mafscaling.VECalc.java

protected void loadLogFile() {
    fileChooser.setMultiSelectionEnabled(true);
    if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this))
        return;// w w  w  .  ja v  a  2s .  c om
    File[] files = fileChooser.getSelectedFiles();
    for (File file : files) {
        BufferedReader br = null;
        ArrayDeque<String[]> buffer = new ArrayDeque<String[]>();
        try {
            br = new BufferedReader(new FileReader(file.getAbsoluteFile()));
            String line = br.readLine();
            if (line != null) {
                String[] elements = line.split("(\\s*)?,(\\s*)?", -1);
                getColumnsFilters(elements);

                boolean resetColumns = false;
                if (logThrottleAngleColIdx >= 0 || logFfbColIdx >= 0 || logSdColIdx >= 0
                        || (logWbAfrColIdx >= 0 && isOl) || (logStockAfrColIdx >= 0 && !isOl)
                        || (logAfLearningColIdx >= 0 && !isOl) || (logAfCorrectionColIdx >= 0 && !isOl)
                        || logRpmColIdx >= 0 || logMafColIdx >= 0 || logIatColIdx >= 0 || logMpColIdx >= 0) {
                    if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null,
                            "Would you like to reset column names or filter values?", "Columns/Filters Reset",
                            JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE))
                        resetColumns = true;
                }

                if (resetColumns || logThrottleAngleColIdx < 0 || logFfbColIdx < 0 || logSdColIdx < 0
                        || (logWbAfrColIdx < 0 && isOl) || (logStockAfrColIdx < 0 && !isOl)
                        || (logAfLearningColIdx < 0 && !isOl) || (logAfCorrectionColIdx < 0 && !isOl)
                        || logRpmColIdx < 0 || logMafColIdx < 0 || logIatColIdx < 0 || logMpColIdx < 0) {
                    ColumnsFiltersSelection selectionWindow = new VEColumnsFiltersSelection(false);
                    if (!selectionWindow.getUserSettings(elements) || !getColumnsFilters(elements))
                        return;
                }

                if (logClOlStatusColIdx == -1)
                    clValue = -1;

                String[] flds;
                String[] afrflds;
                boolean removed = false;
                int i = 2;
                int clol = -1;
                int row = getLogTableEmptyRow();
                double thrtlMaxChange2 = thrtlMaxChange + thrtlMaxChange / 2.0;
                double throttle = 0;
                double pThrottle = 0;
                double ppThrottle = 0;
                double afr = 0;
                double rpm;
                double ffb;
                double iat;
                clearRunTables();
                setCursor(new Cursor(Cursor.WAIT_CURSOR));
                for (int k = 0; k <= afrRowOffset && line != null; ++k) {
                    line = br.readLine();
                    if (line != null)
                        buffer.addFirst(line.split(",", -1));
                }
                try {
                    while (line != null && buffer.size() > afrRowOffset) {
                        afrflds = buffer.getFirst();
                        flds = buffer.removeLast();
                        line = br.readLine();
                        if (line != null)
                            buffer.addFirst(line.split(",", -1));
                        ppThrottle = pThrottle;
                        pThrottle = throttle;
                        throttle = Double.valueOf(flds[logThrottleAngleColIdx]);
                        try {
                            if (row > 0 && Math.abs(pThrottle - throttle) > thrtlMaxChange) {
                                if (!removed)
                                    Utils.removeRow(row--, logDataTable);
                                removed = true;
                            } else if (row <= 0 || Math.abs(ppThrottle - throttle) <= thrtlMaxChange2) {
                                // Filters
                                afr = (isOl ? Double.valueOf(afrflds[logWbAfrColIdx])
                                        : Double.valueOf(afrflds[logStockAfrColIdx]));
                                rpm = Double.valueOf(flds[logRpmColIdx]);
                                ffb = Double.valueOf(flds[logFfbColIdx]);
                                iat = Double.valueOf(flds[logIatColIdx]);
                                if (clValue != -1)
                                    clol = Integer.valueOf(flds[logClOlStatusColIdx]);
                                boolean flag = isOl ? ((afr <= afrMax || throttle >= thrtlMin) && afr <= afrMax)
                                        : (afrMin <= afr);
                                if (flag && clol == clValue && rpmMin <= rpm && ffbMin <= ffb && ffb <= ffbMax
                                        && iat <= iatMax) {
                                    removed = false;
                                    if (!isOl)
                                        trims.add(Double.valueOf(flds[logAfLearningColIdx])
                                                + Double.valueOf(flds[logAfCorrectionColIdx]));
                                    Utils.ensureRowCount(row + 1, logDataTable);
                                    logDataTable.setValueAt(rpm, row, 0);
                                    logDataTable.setValueAt(iat, row, 1);
                                    logDataTable.setValueAt(Double.valueOf(flds[logMpColIdx]), row, 2);
                                    logDataTable.setValueAt(ffb, row, 3);
                                    logDataTable.setValueAt(afr, row, 4);
                                    logDataTable.setValueAt(Double.valueOf(flds[logMafColIdx]), row, 5);
                                    logDataTable.setValueAt(Double.valueOf(flds[logSdColIdx]), row, 6);
                                    row += 1;
                                } else
                                    removed = true;
                            } else
                                removed = true;
                        } catch (NumberFormatException e) {
                            logger.error(e);
                            JOptionPane.showMessageDialog(null,
                                    "Error parsing number at " + file.getName() + " line " + i + ": " + e,
                                    "Error processing file", JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                        i += 1;
                    }
                } finally {
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                }
            }
        } catch (Exception e) {
            logger.error(e);
            JOptionPane.showMessageDialog(null, e, "Error opening file", JOptionPane.ERROR_MESSAGE);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    logger.error(e);
                }
            }
        }
    }
}

From source file:de.juwimm.cms.gui.admin.PanUnitGroupPerUser.java

public boolean exitPerformed(ExitEvent e) {
    try {/*w w w  .ja v a  2  s .co  m*/
        if (unitPickData.isModified() || groupPickData.isModified()) {
            int i = JOptionPane.showConfirmDialog(this, rb.getString("dialog.wantToSave"),
                    rb.getString("dialog.title"), JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
            if (i == JOptionPane.YES_OPTION) {
                saveChanges(currentSelected);
            } else if (i == JOptionPane.CANCEL_OPTION) {
                return false;
            }
        }
    } catch (Exception ex) {
    }
    return true;
}