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:com.dragoniade.deviantart.deviation.SearchRss.java

public List<Collection> getCollections() {
    List<Collection> collections = new ArrayList<Collection>();

    if (search.getCollection() == null) {
        collections.add(null);//from w w w  .  j av  a 2  s .c om
        return collections;
    }

    String queryString = "http://" + user + ".deviantart.com/" + search.getCollection() + "/";
    GetMethod method = new GetMethod(queryString);

    try {
        int sc = -1;
        do {
            sc = client.executeMethod(method);
            if (sc != 200) {
                LoggableException ex = new LoggableException(method.getResponseBodyAsString());
                Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex);

                int res = DialogHelper.showConfirmDialog(owner,
                        "An error has occured when contacting deviantART : error " + sc + ". Try again?",
                        "Continue?", JOptionPane.YES_NO_OPTION);
                if (res == JOptionPane.NO_OPTION) {
                    return null;
                }
            }
        } while (sc != 200);

        InputStream is = method.getResponseBodyAsStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte[] buffer = new byte[4096];
        int read = -1;
        while ((read = is.read(buffer)) > -1) {
            baos.write(buffer, 0, read);
            if (baos.size() > 2097152) {
                int res = DialogHelper.showConfirmDialog(owner,
                        "An error has occured: The document is too big (over 2 megabytes) and look suspicious. Abort?",
                        "Continue?", JOptionPane.YES_NO_OPTION);
                if (res == JOptionPane.YES_NO_OPTION) {
                    return null;
                }
            }
        }
        String charsetName = method.getResponseCharSet();
        String body = baos.toString(charsetName);
        String regex = user + ".deviantart.com/" + search.getCollection() + "/([0-9]+)\"[^>]*>([^<]+)<";
        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(body);
        while (matcher.find()) {
            String id = matcher.group(1);
            String name = matcher.group(2);
            Collection c = new Collection(Long.parseLong(id), name);
            collections.add(c);
        }
    } catch (IOException e) {
    } finally {
        method.releaseConnection();
    }

    collections.add(null);
    return collections;
}

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

private void copyAttacksToClipboardAsBBCode() {
    jideRetimeTabbedPane.setSelectedIndex(1);
    try {//from  w  w w.  j  a  v a2  s . c  o  m
        List<Attack> attacks = getSelectedAttacks();
        if (attacks.isEmpty()) {
            showInfo("Keine Angriffe ausgewhlt");
            return;
        }
        boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
                "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
                "Nein", "Ja") == JOptionPane.YES_OPTION);

        StringBuilder buffer = new StringBuilder();
        if (extended) {
            buffer.append("[u][size=12]Angriffsplan[/size][/u]\n\n");
        } else {
            buffer.append("[u]Angriffsplan[/u]\n\n");
        }

        buffer.append(new AttackListFormatter().formatElements(attacks, extended));

        if (extended) {
            buffer.append("\n[size=8]Erstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n");
        } else {
            buffer.append("\nErstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n");
        }

        String b = buffer.toString();
        StringTokenizer t = new StringTokenizer(b, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Die ausgewhlten Angriffe bentigen mehr als 1000 BB-Codes\n"
                            + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?",
                    "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }

        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null);
        String result = "Daten in Zwischenablage kopiert.";
        showSuccess(result);
    } catch (Exception e) {
        logger.error("Failed to copy data to clipboard", e);
        String result = "Fehler beim Kopieren in die Zwischenablage.";
        showError(result);
    }
}

From source file:jmemorize.gui.swing.frames.MainFrame.java

/**
 * If lesson was modified this shows a dialog that asks if the user wants to
 * save the lesson before closing it./*from   ww  w.  ja va 2  s  .com*/
 * 
 * @return <code>true</code> if user chose not to cancel the lesson close
 *         operation. If this method return <code>false</code> the closing
 *         of jMemorize was canceled.
 */
public boolean allowTheUserToSaveIfClosing() {
    // first check the editCardFrame for unsaved changes
    final EditCardFrame editFrame = EditCardFrame.getInstance();
    if (editFrame.isVisible() && !editFrame.close()) {
        return false; // user canceled closing of edit card frame
    }

    if (!m_newCardManager.closeAllFrames()) // close all addCard frames
    {
        return false;
    }

    // then see if lesson should to be saved
    final Lesson lesson = m_main.getLesson();
    if (lesson.canSave()) {
        final int n = JOptionPane.showConfirmDialog(MainFrame.this, Localization.get("MainFrame.SAVE_MODIFIED"), //$NON-NLS-1$
                "Warning", //$NON-NLS-1$
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);

        if (n == JOptionPane.OK_OPTION) {
            try {
                jMemorizeIO.saveLesson(lesson);

                jMemorizeIO.reset();
            } catch (final Exception exception) {
                final File file = jMemorizeIO.getFile();
                final Object[] args = { file != null ? file.getName() : "?" };
                final MessageFormat form = new MessageFormat(Localization.get(LC.ERROR_SAVE));
                final String msg = form.format(args);
                Main.logThrowable(msg, exception);

                new ErrorDialog(this, msg, exception).setVisible(true);
            }
            // if lesson was saved return true, false otherwise
            return !lesson.canSave();
        }

        // if NO chosen continue, otherwise CANCEL was chosen
        return n == JOptionPane.NO_OPTION;
    }

    return true;
}

From source file:au.org.ala.delta.editor.ui.ImageDetailsPanel.java

private File getMediaFile(FileFilter filter) {
    String imagePath = _dataSet.getImagePath();
    JFileChooser chooser = new JFileChooser(imagePath);
    chooser.setFileFilter(filter);/*from   ww  w  .j a  v a2 s .  c om*/

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File imageFile = chooser.getSelectedFile();

        ImageSettings settings = _dataSet.getImageSettings();
        if (settings.isOnResourcePath(imageFile)) {

            String name = imageFile.getName();
            boolean exists = false;

            if (_selectedImage != null) {
                List<ImageOverlay> existingSounds = _selectedImage.getSounds();
                for (ImageOverlay sound : existingSounds) {
                    if (name.equals(sound.overlayText)) {
                        exists = true;
                        break;
                    }
                }
            }
            if (exists) {
                int result = _messageHelper.confirmDuplicateFileName();
                if (result == JOptionPane.YES_OPTION) {
                    imageFile = new File(imageFile.getAbsolutePath());
                } else if (result == JOptionPane.NO_OPTION) {
                    return getMediaFile(filter);
                } else {
                    imageFile = null;
                }
            } else {
                // Turn the file into a relative one.
                imageFile = new File(name);
            }
        } else {
            // Ask about it or copy it to the image path.
            int result = _messageHelper.confirmNotOnImagePath();
            if (result == JOptionPane.YES_OPTION) {
                imageFile = new File(imageFile.getAbsolutePath());
            } else if (result == JOptionPane.NO_OPTION) {
                return getMediaFile(filter);
            } else {
                imageFile = null;
            }
        }

        return imageFile;
    }

    return null;
}

From source file:gui.QTLResultsPanel.java

void saveTXT() {
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(Prefs.gui_dir));
    fc.setDialogTitle("Save QTL Results");

    while (fc.showSaveDialog(MsgBox.frm) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        // Make sure it has an appropriate extension
        if (!file.exists()) {
            if (file.getName().indexOf(".") == -1) {
                file = new File(file.getPath() + ".csv");
            }/*from ww w  .  j a  v a2s.com*/
        }

        // Confirm overwrite
        if (file.exists()) {
            int response = MsgBox.yesnocan(file + " already exists.\nDo " + "you want to replace it?", 1);

            if (response == JOptionPane.NO_OPTION) {
                continue;
            } else if (response == JOptionPane.CANCEL_OPTION || response == JOptionPane.CLOSED_OPTION) {
                return;
            }
        }

        // Otherwise it's ok to save...
        Prefs.gui_dir = "" + fc.getCurrentDirectory();
        saveTXTFile(file);
        return;
    }
}

From source file:net.lmxm.ute.gui.MainFrame.java

/**
 * Action delete job./*w  w  w  .  j a v a2 s.c  o  m*/
 */
private void actionDeleteJob() {
    final Object userObject = getMainTree().getSelectedTreeObject();
    if (!(userObject instanceof Job)) {
        return;
    }

    final Job job = (Job) userObject;

    if (job.getTasks().size() > 0) {
        final int result = OptionPaneFactory.showConfirmation(this, ConfirmationResourceType.DELETE_JOB,
                job.getId(), job.getTasks().size());

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

    configuration.getJobs().remove(job);
    mainTree.deleteJob(job);
}

From source file:com.t3.client.TabletopTool.java

/**
 * This method is specific to deleting a token, but it can be used as a
 * basis for any other method which wants to be turned off via a property.
 * /* w  ww.  j  av a  2  s.  c  o m*/
 * @return true if the token should be deleted.
 */
public static boolean confirmTokenDelete() {
    if (!AppPreferences.getTokensWarnWhenDeleted()) {
        return true;
    }

    String msg = I18N.getText("msg.confirm.deleteToken");
    log.debug(msg);
    Object[] options = { I18N.getText("msg.title.messageDialog.yes"),
            I18N.getText("msg.title.messageDialog.no"), I18N.getText("msg.title.messageDialog.dontAskAgain") };
    String title = I18N.getText("msg.title.messageDialogConfirm");
    int val = JOptionPane.showOptionDialog(clientFrame, msg, title, JOptionPane.NO_OPTION,
            JOptionPane.WARNING_MESSAGE, null, options, options[0]);

    // "Yes, don't show again" Button
    if (val == 2) {
        showInformation("msg.confirm.deleteToken.removed");
        AppPreferences.setTokensWarnWhenDeleted(false);
    }
    // Any version of 'Yes'...
    if (val == JOptionPane.YES_OPTION || val == 2) {
        return true;
    }
    // Assume 'No' response
    return false;
}

From source file:com.dragoniade.deviantart.favorites.FavoritesDownloader.java

private STATUS downloadFile(Deviation da, String downloadUrl, String filename, boolean reportError,
        YesNoAllDialog matureMoveDialog, YesNoAllDialog overwriteDialog, YesNoAllDialog overwriteNewerDialog,
        YesNoAllDialog deleteEmptyDialog) {

    AtomicBoolean download = new AtomicBoolean(true);
    File art = getFile(da, downloadUrl, filename, download, matureMoveDialog, overwriteDialog,
            overwriteNewerDialog, deleteEmptyDialog);
    if (art == null) {
        return null;
    }//ww  w  . j a  va2s.  c o  m

    if (download.get()) {
        File parent = art.getParentFile();
        if (!parent.exists()) {
            if (!parent.mkdirs()) {
                showMessageDialog(owner, "Unable to create '" + parent.getPath() + "'.", "Error",
                        JOptionPane.ERROR_MESSAGE);
                return null;
            }
        }

        GetMethod method = new GetMethod(downloadUrl);
        try {
            int sc = -1;
            do {
                sc = client.executeMethod(method);
                requestCount++;
                if (sc != 200) {
                    if (sc == 404 || sc == 403) {
                        method.releaseConnection();
                        return STATUS.NOTFOUND;
                    } else {
                        LoggableException ex = new LoggableException(method.getResponseBodyAsString());
                        Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(),
                                ex);

                        int res = showConfirmDialog(owner,
                                "An error has occured when contacting deviantART : error " + sc
                                        + ". Try again?",
                                "Continue?", JOptionPane.YES_NO_CANCEL_OPTION);
                        if (res == JOptionPane.NO_OPTION) {
                            String text = "<br/><a style=\"color:red;\" href=\"" + da.getUrl() + "\">"
                                    + downloadUrl + " has an error" + "</a>";
                            setPaneText(text);
                            method.releaseConnection();
                            progress.incremTotal();
                            return STATUS.SKIP;
                        }
                        if (res == JOptionPane.CANCEL_OPTION) {
                            return null;
                        }
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            } while (sc != 200);

            int length = (int) method.getResponseContentLength();
            int copied = 0;
            progress.setUnitMax(length);
            InputStream is = method.getResponseBodyAsStream();
            File tmpFile = new File(art.getParentFile(), art.getName() + ".tmp");
            FileOutputStream fos = new FileOutputStream(tmpFile, false);
            byte[] buffer = new byte[16184];
            int read = -1;

            while ((read = is.read(buffer)) > 0) {
                fos.write(buffer, 0, read);
                copied += read;
                progress.setUnitValue(copied);

                if (progress.isCancelled()) {
                    is.close();
                    method.releaseConnection();
                    tmpFile.delete();
                    return null;
                }
            }
            fos.close();
            method.releaseConnection();

            if (art.exists()) {
                if (!art.delete()) {
                    showMessageDialog(owner, "Unable to delete '" + art.getPath() + "'.", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return null;
                }
            }
            if (!tmpFile.renameTo(art)) {
                showMessageDialog(owner,
                        "Unable to rename '" + tmpFile.getPath() + "' to '" + art.getPath() + "'.", "Error",
                        JOptionPane.ERROR_MESSAGE);
                return null;
            }
            art.setLastModified(da.getTimestamp().getTime());
            return STATUS.DOWNLOADED;
        } catch (HttpException e) {
            showMessageDialog(owner, "Error contacting deviantART: " + e.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
            return null;
        } catch (IOException e) {
            showMessageDialog(owner, "Error contacting deviantART: " + e.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
            return null;
        }
    } else {
        progress.setText("Skipping file '" + filename + "' from " + da.getArtist());
        return STATUS.SKIP;
    }
}

From source file:net.rptools.maptool.client.MapTool.java

public static boolean confirmDrawDelete() {
    if (!AppPreferences.getDrawWarnWhenDeleted()) {
        return true;
    }/*w w w . j  a  v a 2  s .  com*/

    String msg = I18N.getText("msg.confirm.deleteDraw");
    log.debug(msg);
    Object[] options = { I18N.getText("msg.title.messageDialog.yes"),
            I18N.getText("msg.title.messageDialog.no"), I18N.getText("msg.title.messageDialog.dontAskAgain") };
    String title = I18N.getText("msg.title.messageDialogConfirm");
    int val = JOptionPane.showOptionDialog(clientFrame, msg, title, JOptionPane.NO_OPTION,
            JOptionPane.WARNING_MESSAGE, null, options, options[0]);

    // "Yes, don't show again" Button
    if (val == 2) {
        showInformation("msg.confirm.deleteDraw.removed");
        AppPreferences.setDrawWarnWhenDeleted(false);
    }
    // Any version of 'Yes'...
    if (val == JOptionPane.YES_OPTION || val == 2) {
        return true;
    }
    // Assume 'No' response
    return false;
}

From source file:serial.ChartFromSerial.java

private void pause_jBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pause_jBtnActionPerformed
    if ("Play".equals(pause_jBtn.getText())) {
        while (!chosenPort.openPort()) {
            if (JOptionPane.showConfirmDialog(rootPane,
                    "Error at " + portList_jCombo.getSelectedItem().toString() + "\nWould you like to refresh?",
                    "Trouble connecting to " + portList_jCombo.getSelectedItem().toString(),
                    JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.NO_OPTION) {
                buttonsOff();/* w  w w .j a  v a 2 s. c o m*/
                return;
            } else {
                portNames = SerialPort.getCommPorts();
                if (portNames.length > 0) {
                    if (portNames.length >= 1) {
                        Object[] possibilities = new Object[portNames.length];
                        for (int i = 0; i < portNames.length; i++) {
                            possibilities[i] = portNames[i].getSystemPortName();
                        }
                        String s = (String) JOptionPane.showInputDialog(rootPane,
                                "Other ports are available.\nSelect one to continue on that port or cancel to disconnect.",
                                "Another port is available", JOptionPane.PLAIN_MESSAGE, null, possibilities,
                                null);
                        chosenPort.closePort();
                        if (s != null) {
                            chosenPort = SerialPort.getCommPort(s);
                            chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                            chosenPort.setBaudRate(
                                    Integer.parseInt(baudRate_jCombo.getSelectedItem().toString()));
                            softRefresh();
                            portList_jCombo.setSelectedItem(s);
                            if (chosenPort.openPort()) {
                                createSerialThread(chosenPort);
                                pause_jBtn.setText("Pause");
                                connect_jBtn.setEnabled(true);
                                return;
                            }
                        } else {
                            buttonsOff();
                            return;
                        }
                    } else {
                        if (JOptionPane.showConfirmDialog(rootPane,
                                portNames[0].getSystemPortName()
                                        + " is available. Would you like to use it instead?",
                                "Another port is available",
                                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                            chosenPort.closePort();
                            chosenPort = SerialPort.getCommPort(portNames[0].getSystemPortName());
                            chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                            chosenPort.setBaudRate(
                                    Integer.parseInt(baudRate_jCombo.getSelectedItem().toString()));
                            softRefresh();
                            portList_jCombo.setSelectedItem(portNames[0].getSystemPortName());
                            if (chosenPort.openPort()) {
                                createSerialThread(chosenPort);
                                pause_jBtn.setText("Pause");
                                connect_jBtn.setEnabled(true);
                                return;
                            }
                        } else {
                            buttonsOff();
                            return;
                        }
                    }
                } else {
                    JOptionPane.showMessageDialog(rootPane, "You are currently not connected to any devices.",
                            "No devices found", JOptionPane.INFORMATION_MESSAGE);
                    softRefresh();
                    buttonsOff();
                    return;
                }
            }

        }
        createSerialThread(chosenPort);
        pause_jBtn.setText("Pause");
    } else {
        chosenPort.closePort();
        pause_jBtn.setText("Play");
    }
}