Example usage for javax.swing JOptionPane CANCEL_OPTION

List of usage examples for javax.swing JOptionPane CANCEL_OPTION

Introduction

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

Prototype

int CANCEL_OPTION

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

Click Source Link

Document

Return value from class method if CANCEL is chosen.

Usage

From source file:com.pianobakery.complsa.MainGui.java

public void addTopicCorpusMethod() {

    logger.debug("Numeric?: " + StringUtils.isNumeric(amountOfSentencesPerTextField.getText()));
    logger.debug("Chunk selected: " + createChunksCheckBox.isSelected());

    if (createChunksCheckBox.isSelected() && !StringUtils.isNumeric(amountOfSentencesPerTextField.getText())) {

        JOptionPane.showMessageDialog(null, "Enter Number");
        return;/*from  ww  w  .  j ava  2s  . com*/

    }
    if (trainSentModels.size() == 0) {
        JOptionPane.showMessageDialog(null, "Download Sentence Models first");
        return;
    }

    File folder = chooseAddCorpusFolder();

    if (folder != null) {

        File newDir = new File(wDir + File.separator + topicFolder + File.separator + folder.getName());
        logger.debug("Corpus Folder: " + folder.toString());
        logger.debug("Import Folder: " + newDir.toString());
        logger.debug("Working Folder : " + wDir.toString());
        logger.debug("Corpus Folder recursive is: " + addCorpRecursiveCheckBox.isSelected());

        //Create Corpus Folder
        if (!newDir.exists()) {

            logger.debug("Creating directory: " + newDir);
            boolean result = false;

            try {
                FileUtils.forceMkdir(newDir);
                addRemoveItemToTopicSearchBoxTaskWithBar(getProgressBarWithTitleLater("Please wait...", false),
                        newDir, true, true);
                //addRemoveItemToTopicBox(newDir, true, true);
                result = true;
            } catch (SecurityException se) {
                JOptionPane.showMessageDialog(null, "No permission or File Exists");

                //return Boolean.FALSE;
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            if (result) {
                logger.debug("DIR created");
            }
        } else {

            int result = JOptionPane.showConfirmDialog(new JFrame(),
                    "Folder exists, add to your Topic Corpus? You have to re-train!");
            logger.debug("DIR not created");
            if (result == JOptionPane.NO_OPTION | result == JOptionPane.CANCEL_OPTION) {
                return;
            }

        }

        //Run import
        if (folder != null) {
            addTopicCorpTaskWithBar(getProgressBarWithTitleLater("Add Topic Corpus", true), folder, newDir,
                    addCorpRecursiveCheckBox.isSelected(),
                    Integer.parseInt(amountOfSentencesPerTextField.getText()),
                    createChunksCheckBox.isSelected());

        }

    }

}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

private static void processExporterAsLongTask(final JFrame frame, final String taskDescription,
        final Exporter exporter, final File theFile) {
    if (theFile.exists()) {
        if (JOptionPane.showConfirmDialog(frame, "Override existing file '" + theFile.getName() + "'?",
                "File exists", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
            return;
        }/*from w ww  .j ava  2s  .c  om*/
    }

    new LongTaskDialog(frame, taskDescription, new Runnable() {

        @Override
        public void run() {
            Log.info("Started export: " + taskDescription);
            try {
                exporter.export(theFile);
                Log.info("Export has been completed: " + taskDescription);
            } catch (ExportException ex) {
                Log.error("Can't make export for error", ex);
                JOptionPane.showMessageDialog(frame, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            } catch (Exception ex) {
                Log.error("Can't make export for error", ex);
                JOptionPane.showMessageDialog(frame, "Can't  make export for error, see the log", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }).startTask();
}

From source file:edu.ku.brc.specify.tasks.subpane.security.SecurityAdminPane.java

@Override
public boolean aboutToShutdown() {
    boolean result = true;
    if (formHasChanged()) {
        String msg = String.format(getResourceString("SaveChanges"), getTitle());
        JFrame topFrame = (JFrame) UIRegistry.getTopWindow();

        int rv = JOptionPane.showConfirmDialog(topFrame, msg, getResourceString("SaveChangesTitle"),
                JOptionPane.YES_NO_CANCEL_OPTION);
        if (rv == JOptionPane.YES_OPTION) {
            doSave(false);/*from  w  w w  . j a v a 2s .co m*/
        } else if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
            return false;
        } else if (rv == JOptionPane.NO_OPTION) {
            // nothing
        }
    }
    return result;
}

From source file:com.pianobakery.complsa.MainGui.java

public void removeTopicCorpusMethod() {

    File theFile = trainCorp.get(selectTrainCorp.getSelectedItem());

    int result = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (result == JOptionPane.NO_OPTION || result == JOptionPane.CANCEL_OPTION) {
        return;/*from w  w w.  ja va  2  s. c o  m*/
    }

    if (theFile != null) {

        addRemoveItemToTopicSearchBoxTaskWithBar(getProgressBarWithTitleLater("Please wait...", false), theFile,
                false, true);
        //addRemoveItemToTopicBox(theFile, false, true);
        //updateIndexFileFolder();

    } else if (theFile == null) {

        try {
            selectTrainCorp.removeItemAt(0);
            System.out.printf("Items of selectTrainingCorp: " + selectTrainCorp.getItemAt(0));
            try {
                updateIndexFileFolder();
            } catch (IOException e1) {
                e1.printStackTrace();
            }

        } catch (ArrayIndexOutOfBoundsException e2) {
            JOptionPane.showMessageDialog(null, "Keine Topic Corps mehr vorhanden");
        }

    }

}

From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java

/**
 * @return true if no unsaved changes are present
 * else return results of prompt to save
 *//*from  w w  w .  j  a  va2 s.  co m*/
protected boolean checkForChanges() {
    int s = termList.getSelectedIndex();
    if (s != -1) {
        StrLocaleEntry entry = srcFile.getKey(s);
        entry.setDstStr(textField.getText());
    }
    if (srcFile.isEdited()) {
        int response = JOptionPane.showOptionDialog((Frame) getTopWindow(),
                String.format(getResourceString("StrLocalizerApp.SaveChangesMsg"), destFile.getPath()),
                getResourceString("StrLocalizerApp.SaveChangesTitle"), JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.YES_OPTION);
        if (response == JOptionPane.CANCEL_OPTION) {
            return false;
        }
        if (response == JOptionPane.YES_OPTION) {
            doSave();
            return true; //what if it fails? 
        }
    }
    return true;
}

From source file:com.t3.client.ui.T3Frame.java

public void closingMaintenance() {
    if (AppPreferences.getSaveReminder()) {
        if (TabletopTool.getPlayer().isGM()) {
            int result = TabletopTool.confirmImpl(I18N.getText("msg.title.saveCampaign"),
                    JOptionPane.YES_NO_CANCEL_OPTION, "msg.confirm.saveCampaign", (Object[]) null);
            //            int result = JOptionPane.showConfirmDialog(TabletopTool.getFrame(), I18N.getText("msg.confirm.saveCampaign"), I18N.getText("msg.title.saveCampaign"), JOptionPane.YES_NO_CANCEL_OPTION);

            if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
                return;
            }/*from   w  w  w .j  a  v a  2s. c  o m*/
            if (result == JOptionPane.YES_OPTION) {
                final Observer callback = new Observer() {
                    @Override
                    public void update(java.util.Observable o, Object arg) {
                        if (arg instanceof String) {
                            // There was an error during the save -- don't terminate TabletopTool!
                        } else {
                            TabletopTool.getFrame().close();
                        }
                    }
                };
                ActionEvent ae = new ActionEvent(callback, 0, "close");
                AppActions.SAVE_CAMPAIGN.actionPerformed(ae);
                return;
            }
        } else {
            if (!TabletopTool.confirm("msg.confirm.disconnecting")) {
                return;
            }
        }
    }
    close();
}

From source file:net.sf.jabref.gui.BasePanel.java

private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
        SavePreferences.DatabaseSaveType saveType) throws SaveException {
    SaveSession session;/* w  ww  .ja v a2 s  . co  m*/
    frame.block();
    final String SAVE_DATABASE = Localization.lang("Save database");
    try {
        SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(enc)
                .withSaveType(saveType);
        BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
        if (selectedOnly) {
            session = databaseWriter.savePartOfDatabase(bibDatabaseContext, mainTable.getSelectedEntries(),
                    prefs);
        } else {
            session = databaseWriter.saveDatabase(bibDatabaseContext, prefs);
        }

        registerUndoableChanges(session);

    } catch (UnsupportedCharsetException ex2) {
        JOptionPane.showMessageDialog(frame,
                Localization.lang("Could not save file.") + ' '
                        + Localization.lang("Character encoding '%0' is not supported.", enc.displayName()),
                SAVE_DATABASE, JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");
    } catch (SaveException ex) {
        if (ex.specificEntry()) {
            // Error occurred during processing of
            // be. Highlight it:
            final int row = mainTable.findEntry(ex.getEntry());
            final int topShow = Math.max(0, row - 3);
            mainTable.setRowSelectionInterval(row, row);
            mainTable.scrollTo(topShow);
            showEntry(ex.getEntry());
        } else {
            LOGGER.warn("Could not save", ex);
        }

        JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + "\n" + ex.getMessage(),
                SAVE_DATABASE, JOptionPane.ERROR_MESSAGE);
        throw new SaveException("rt");

    } finally {
        frame.unblock();
    }

    boolean commit = true;
    if (!session.getWriter().couldEncodeAll()) {
        FormBuilder builder = FormBuilder.create()
                .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref"));
        JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
        ta.setEditable(false);
        builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:",
                session.getEncoding().displayName())).xy(1, 1);
        builder.add(ta).xy(3, 1);
        builder.add(Localization.lang("What do you want to do?")).xy(1, 3);
        String tryDiff = Localization.lang("Try different encoding");
        int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), SAVE_DATABASE,
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
                new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff);

        if (answer == JOptionPane.NO_OPTION) {
            // The user wants to use another encoding.
            Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"),
                    SAVE_DATABASE, JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, enc);
            if (choice == null) {
                commit = false;
            } else {
                Charset newEncoding = Charset.forName((String) choice);
                return saveDatabase(file, selectedOnly, newEncoding, saveType);

            }
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            commit = false;
        }

    }

    if (commit) {
        session.commit(file.toPath());
        this.bibDatabaseContext.getMetaData().setEncoding(enc); // Make sure to remember which encoding we used.
    } else {
        session.cancel();
    }

    return commit;
}

From source file:com.pianobakery.complsa.MainGui.java

public void impSearchCorpMethod() {

    logger.debug("Numeric?: " + StringUtils.isNumeric(amountSearchCorpSent.getText()));
    logger.debug("Chunk selected: " + splitSearchCorpCheckBox.isSelected());

    if (splitSearchCorpCheckBox.isSelected() && !StringUtils.isNumeric(amountSearchCorpSent.getText())) {

        JOptionPane.showMessageDialog(null, "Enter Number");
        return;/*from   w w  w.  j av a  2s  .  c om*/

    }

    File folder = chooseAddCorpusFolder();

    if (folder != null) {

        File newDir = new File(wDir + File.separator + searchFolder + File.separator + folder.getName());
        logger.debug("Corpus Folder: " + folder.toString());
        logger.debug("Import Folder: " + newDir.toString());
        logger.debug("Working Folder : " + wDir.toString());
        logger.debug("Corpus Folder recursive is: " + impSearchCorpRecursiveCheckBox.isSelected());

        //Create Corpus Folder
        if (!newDir.exists()) {

            logger.debug("Creating directory: " + newDir);
            boolean result = false;

            try {
                FileUtils.forceMkdir(newDir);
                addRemoveItemToTopicSearchBoxTaskWithBar(getProgressBarWithTitleLater("Please wait...", false),
                        newDir, true, false);
                //addRemoveItemToTopicBox(newDir, true, false);
                result = true;
            } catch (SecurityException se) {
                JOptionPane.showMessageDialog(null, "No permission or File Exists");

                //return Boolean.FALSE;
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            if (result) {
                logger.debug("DIR created");
            }
        } else {

            int result = JOptionPane.showConfirmDialog(new JFrame(),
                    "Folder exists, add to your Search Corpus?");
            logger.debug("DIR not created");
            if (result == JOptionPane.NO_OPTION | result == JOptionPane.CANCEL_OPTION) {
                return;
            }

        }

        //Run import
        if (folder != null) {
            addTopicCorpTaskWithBar(getProgressBarWithTitleLater("Add Topic Corpus", true), folder, newDir,
                    addCorpRecursiveCheckBox.isSelected(), Integer.parseInt(amountSearchCorpSent.getText()),
                    splitSearchCorpCheckBox.isSelected());

        }

    }

}

From source file:com.pianobakery.complsa.MainGui.java

public void removeSearchCorpMethod() {
    File theFile = searchCorpusModel.get(searchCorpComboBox.getSelectedItem());

    int result = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (result == JOptionPane.NO_OPTION || result == JOptionPane.CANCEL_OPTION) {
        return;//from w w w  .  j a  v  a2s . c  om
    }

    if (theFile != null) {
        addRemoveItemToTopicSearchBoxTaskWithBar(getProgressBarWithTitleLater("Please wait...", false), theFile,
                false, false);
        //addRemoveItemToTopicBox(theFile, false, false);
    } else if (theFile == null) {

        try {
            searchCorpComboBox.removeItemAt(0);
            System.out.printf("Items of select Search Corps: " + searchCorpComboBox.getItemAt(0));

        } catch (ArrayIndexOutOfBoundsException e2) {
            JOptionPane.showMessageDialog(null, "Keine Search Corps mehr vorhanden");
        }

    }

}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

public void closingMaintenance() {
    if (AppPreferences.getSaveReminder()) {
        if (MapTool.getPlayer().isGM()) {
            int result = MapTool.confirmImpl(I18N.getText("msg.title.saveCampaign"),
                    JOptionPane.YES_NO_CANCEL_OPTION, "msg.confirm.saveCampaign", (Object[]) null);
            //            int result = JOptionPane.showConfirmDialog(MapTool.getFrame(), I18N.getText("msg.confirm.saveCampaign"), I18N.getText("msg.title.saveCampaign"), JOptionPane.YES_NO_CANCEL_OPTION);

            if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
                return;
            }/*  ww w  .j  a  v a 2s  .co  m*/
            if (result == JOptionPane.YES_OPTION) {
                final Observer callback = new Observer() {
                    public void update(java.util.Observable o, Object arg) {
                        if (arg instanceof String) {
                            // There was an error during the save -- don't terminate MapTool!
                        } else {
                            MapTool.getFrame().close();
                        }
                    }
                };
                ActionEvent ae = new ActionEvent(callback, 0, "close");
                AppActions.SAVE_CAMPAIGN.actionPerformed(ae);
                return;
            }
        } else {
            if (!MapTool.confirm("msg.confirm.disconnecting")) {
                return;
            }
        }
    }
    close();
}