Example usage for javax.swing JOptionPane showOptionDialog

List of usage examples for javax.swing JOptionPane showOptionDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException 

Source Link

Document

Brings up a dialog with a specified icon, where the initial choice is determined by the initialValue parameter and the number of choices is determined by the optionType parameter.

Usage

From source file:tvbrowser.ui.mainframe.MainFrame.java

public void copySettingsToSystem() {
    if (TVBrowser.isTransportable()) {
        String[] options = { mLocalizer.msg("copy", "Copy"), mLocalizer.msg("dontCopy", "Don't copy") };
        String title = mLocalizer.msg("copyToSystemTitle", "Copy settings and data to system");
        String msg = mLocalizer.msg("copyToSystemMsg",
                "Should the settings and TV data be copied to the system?\nTV-Browser will therefor will be quit automatically.");

        if (JOptionPane.showOptionDialog(this, msg, title, JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, options, options[1]) == JOptionPane.YES_OPTION) {
            quit(true, true);/*from ww w .  j  a va2s .  c o  m*/
        }
    }
}

From source file:tvbrowser.ui.mainframe.MainFrame.java

/**
 * Starts the TV listings update with the given reason shown in the dialog
 *
 * @param numberOfDays/* w ww  . j a  v a  2s . co  m*/
 * @param reason The reason for initiating the download
 */
synchronized public void updateTvData(final int numberOfDays, final String reason) {
    if (mIsAskingUpdate) {
        return;
    }
    if (TvDataUpdater.getInstance().isDownloading()) {
        return;
    }
    if (downloadingThread != null && downloadingThread.isAlive()) {
        return;
    }
    mIsAskingUpdate = true;
    try {
        if (ChannelList.getNumberOfSubscribedChannels() == 0) {
            int result = JOptionPane.showOptionDialog(this, mLocalizer.msg("subscribeBeforeUpdate.msg",
                    "You have not defined any channels.\n\nDo you want to subscribe to some channels before starting the data update?"),
                    mLocalizer.msg("subscribeBeforeUpdate.title", "No subscribed channels"),
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
            if (result == JOptionPane.YES_OPTION) {
                showSettingsDialog(SettingsItem.CHANNELS);
            }
        } else {
            if (TvDataUpdater.getInstance().isDownloading()) {
                TvDataUpdater.getInstance().stopDownload();
            } else {
                UpdateDlg dlg = new UpdateDlg(this, true, reason);
                if (numberOfDays > 0) {
                    dlg.setNumberOfDays(numberOfDays);
                }
                dlg.pack();
                UiUtilities.centerAndShow(dlg);

                int daysToDownload = dlg.getResult();
                if (daysToDownload != UpdateDlg.CANCEL
                        && licenseForTvDataServicesWasAccepted(dlg.getSelectedTvDataServices())) {
                    runUpdateThread(daysToDownload, dlg.getSelectedTvDataServices(), false);
                }
            }
        }
    } finally {
        mIsAskingUpdate = false;
    }
}

From source file:tvbrowser.ui.mainframe.MainFrame.java

public void showUpdatePluginsDlg(boolean noQuestion) {
    int answer = JOptionPane.YES_OPTION;

    if (!noQuestion) {
        Object[] options = { mLocalizer.msg("checknow", "Check now"),
                Localizer.getLocalization(Localizer.I18N_CANCEL) };
        String msg = mLocalizer.msg("question.1", "do you want to check for new plugins");
        answer = JOptionPane.showOptionDialog(this, msg, mLocalizer.msg("title.1", "update plugins"),
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
    }// w w w  .  j  a  v  a 2s . com

    if (answer == JOptionPane.YES_OPTION) {
        updatePlugins(PluginAutoUpdater.DEFAULT_PLUGINS_DOWNLOAD_URL, false, mStatusBar.getLabel(), false);
    }
}

From source file:uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetDisplay.java

public void actionPerformed(ActionEvent ae) {

    /*   if (ae.getActionCommand().equals("plot")) {
            /*  w w w  . j a  v  a  2 s  . c  om*/
          drawScatterPlot();         
       }
    */
    if (ae.getActionCommand().equals("save_image")) {
        ImageSaver.saveImage(scatterPlotPanel);
    }

    else if (ae.getActionCommand().equals("swap_plot")) {

        if (storesQuantitated()) {

            plotPanel.remove(scatterPlotPanel);

            if (scatterPlotPanel instanceof GeneSetScatterPlotPanel) {
                scatterPlotPanel = new ZScoreScatterPlotPanel(fromStore, toStore, probes,
                        currentSelectedProbeList, dotSizeSlider.getValue(), zScoreLookupTable);
                plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
                swapPlotButton.setText("Display standard scatterplot");
            } else if (scatterPlotPanel instanceof ZScoreScatterPlotPanel) {
                scatterPlotPanel = new GeneSetScatterPlotPanel(fromStore, toStore, startingProbeList,
                        currentSelectedProbeList, true, dotSizeSlider.getValue(), customRegressionValues,
                        simpleRegression);
                plotPanel.add(scatterPlotPanel, BorderLayout.CENTER);
                swapPlotButton.setText("Display z-score plot");
            }
        }
    }

    else if (ae.getActionCommand().equals("close")) {

        /*   if(currentSelectedProbeList != null){
              currentSelectedProbeList[0].delete();
              //currentSelectedProbeList = null;
                      
           }
        */ this.dispose();

    } else if (ae.getActionCommand().equals("select_all")) {

        if (selectAllButton.isSelected()) {

            for (int i = 0; i < tableModel.selected.length; i++) {

                tableModel.selected[i] = true;

                tableModel.fireTableCellUpdated(i, 0);
            }
            selectAllButton.setText("deselect all");
        } else {

            for (int i = 0; i < tableModel.selected.length; i++) {

                tableModel.selected[i] = false;
                tableModel.fireTableCellUpdated(i, 0);
            }
            selectAllButton.setText("select all");
        }

    }

    else if (ae.getActionCommand().equals("save_selected_probelists")) {

        boolean[] selectedListsBoolean = tableModel.selected;

        if (selectedListsBoolean.length != filterResultsPVals.length) {
            System.err.println("not adding up here");
        }

        else {

            ArrayList<MappedGeneSetTTestValue> selectedListsArrayList = new ArrayList<MappedGeneSetTTestValue>();

            for (int i = 0; i < selectedListsBoolean.length; i++) {

                if (selectedListsBoolean[i] == true) {
                    selectedListsArrayList.add(filterResultsPVals[i]);
                }
            }

            MappedGeneSetTTestValue[] selectedLists = selectedListsArrayList
                    .toArray(new MappedGeneSetTTestValue[0]);

            if (selectedLists.length == 0) {

                JOptionPane.showMessageDialog(SeqMonkApplication.getInstance(), "No probe lists were selected",
                        "No probe lists selected", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            saveProbeLists(selectedLists);

            if (currentSelectedProbeList != null) {
                currentSelectedProbeList[0].delete();
                currentSelectedProbeList = null;
            }
        }
    }

    else if (ae.getActionCommand().equals("save_table")) {
        JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation());
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileFilter(new FileFilter() {

            public String getDescription() {
                return "Text files";
            }

            public boolean accept(File f) {
                if (f.isDirectory() || f.getName().toLowerCase().endsWith(".txt")) {
                    return true;
                } else {
                    return false;
                }
            }

        });

        int result = chooser.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION)
            return;

        File file = chooser.getSelectedFile();
        if (!file.getPath().toLowerCase().endsWith(".txt")) {
            file = new File(file.getPath() + ".txt");
        }

        SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file);

        // Check if we're stepping on anyone's toes...
        if (file.exists()) {
            int answer = JOptionPane.showOptionDialog(this,
                    file.getName() + " exists.  Do you want to overwrite the existing file?", "Overwrite file?",
                    0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" },
                    "Overwrite and Save");

            if (answer > 0) {
                return;
            }
        }

        try {
            PrintWriter p = new PrintWriter(new FileWriter(file));

            TableModel model = table.getModel();

            int rowCount = model.getRowCount();
            int colCount = model.getColumnCount();

            // Do the headers first
            StringBuffer b = new StringBuffer();
            for (int c = 1; c < colCount; c++) {
                b.append(model.getColumnName(c));
                if (c + 1 != colCount) {
                    b.append("\t");
                }
            }

            p.println(b);

            for (int r = 0; r < rowCount; r++) {
                b = new StringBuffer();
                for (int c = 1; c < colCount; c++) {
                    b.append(model.getValueAt(r, c));
                    if (c + 1 != colCount) {
                        b.append("\t");
                    }
                }
                p.println(b);

            }
            p.close();

        }

        catch (FileNotFoundException e) {
            new CrashReporter(e);
        } catch (IOException e) {
            new CrashReporter(e);
        }

    }

    else {
        throw new IllegalArgumentException("Unknown command " + ae.getActionCommand());
    }
}

From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java

private void outputGATEXML() throws SQLException {
    // TODO add your handling code here:
    if (XMLradioButton.isSelected()) {
        Utils.checkGateInit(this.gateHomeDir, GlobalParameters.debugOn);
        Corpus allDocs;/*w  ww .j av  a  2 s  .  com*/
        if (gateXMLjRadioButton.isSelected()) {
            expressModeRadioButton.setEnabled(true);
            changeMode();
            tab2SQLEditorPane.setText(getAnnotationsXMLOutputSQL);
            if (withKeyAnnotationsRadioButton.isSelected() & outputFullDocumentsRadioButton.isSelected()) {
                allDocs = mkCorpusFromDB2(getAnnotationsXMLOutputSQL, true, true, -1);
            } else if (noKeyAnnotationsRadioButton.isSelected() & outputFullDocumentsRadioButton.isSelected()) {
                allDocs = mkCorpusFromDB2(getAnnotationsXMLOutputSQL, false, true, -1);
            } else if (withKeyAnnotationsRadioButton.isSelected() & outputContextOnlyRadioButton.isSelected()) {
                allDocs = mkCorpusFromDB2(getAnnotationsXMLOutputSQL, true, false, -1);
            } else {
                allDocs = mkCorpusFromDB2(getAnnotationsXMLOutputSQL, false, false, -1);
            }
            int i = 1; //index for doc count
            for (gate.Document doc : allDocs) {
                try {
                    gate.corpora.DocumentStaxUtils.writeDocument(doc,
                            new File(outputFileChooser.getCurrentDirectory() + File.separator + i + "_"
                                    + doc.getName()));
                } catch (XMLStreamException | IOException ex) {
                    infoBox(ex.getMessage(), "error");
                    Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
                }
                i++;
            }
        } else if (knowtatorXMLjRadioButton.isSelected()) {
            allDocs = getContextStringsFromDB(tab2SQLEditorPane.getText());
            File knowtatorAnnotsDir = new File(outputFileChooser.getCurrentDirectory() + "knowtatorAnnots");
            int n = 0;
            if (knowtatorAnnotsDir.exists()) {
                Object[] options = { "OK", "Cancel" };
                n = JOptionPane.showOptionDialog(null,
                        "An annotation folder already exists. Do you want to delete it?\n" + projectLocation,
                        "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                        options[1]);
            }
            if (n == 0) {
                for (int i = 0; i <= 5; i++) {
                    try {
                        Thread.sleep(500);
                        FileUtils.deleteDirectory(knowtatorAnnotsDir);
                    } catch (IOException ex) {
                        System.out.println("Attempting deletion " + i);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                if (knowtatorAnnotsDir.exists()) {
                    try {
                        FileUtils.deleteDirectory(knowtatorAnnotsDir);
                    } catch (IOException ex) {
                        Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
            knowtatorAnnotsDir.mkdir();
            int instanceSuffix = 1;
            for (gate.Document doc : allDocs) {
                try (BufferedWriter bw = new BufferedWriter(new FileWriter(
                        new File(outputFileChooser.getCurrentDirectory() + File.separator + doc.getName())))) {
                    bw.write(doc.getContent().toString());
                    org.jdom.Document xmlOutDoc = new org.jdom.Document();
                    instanceSuffix++;
                    Utils.buildKnowtatorXMLDocumentFromGATEXML(xmlOutDoc, doc, instanceSuffix, targetTableName);
                    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
                    xmlOut.output(xmlOutDoc, new FileOutputStream(
                            new File(knowtatorAnnotsDir, doc.getName() + ".knowtator.xml")));

                } catch (IOException ex) {
                    Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        System.out.println("XML output complete");
    } else {
        try {
            Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = statement.executeQuery(SQLCommands.getInstance().getResultsForCSV());
            BufferedWriter bw = new BufferedWriter(new FileWriter(
                    outputFileChooser.getCurrentDirectory() + File.separator + GlobalParameters.OUTPUTTSV));
            ResultSetMetaData rsmd = rs.getMetaData();
            int colCount = rsmd.getColumnCount();
            for (int i = 1; i <= colCount - 1; i++) {
                bw.write(rsmd.getColumnName(i) + "\t");
            }
            bw.write(rsmd.getColumnName(colCount) + System.lineSeparator());
            bw.flush();
            int flushIndex = 0;
            int index = 0;
            while (rs.next()) {
                for (int i = 1; i <= colCount - 1; i++) {
                    bw.write(rs.getString(i) + "\t");
                }
                bw.write(rs.getString(colCount) + System.lineSeparator());
                index++;
                if (index > flushIndex + 50) {
                    bw.flush();
                    flushIndex = index;
                }
            }
            bw.close();
        } catch (SQLException | IOException ex) {
            Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java

private boolean createNewProject() {
    try {/*from   w ww. jav  a  2 s . c o  m*/
        //key files for a project
        unloadProject();
    } catch (SQLException ex) {
        Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
    }
    String newTargetTableName = Utils.cleanTargetTableName(newProjectJTextField.getText());
    targetTableTextField.setText(newTargetTableName);
    changeMode();
    File app = new File(relFilePath + File.separator + "resources" + File.separator + "generic_app");
    File newApp = new File(projectLocation + File.separator + "generic_app");
    File xml = new File(projectLocation + File.separator + "XML");
    File results = new File(projectLocation + File.separator + "results");
    File newProject = new File(projectLocation);
    // if file doesnt exists, then create it

    int n = 0;
    if (newProject.exists()) {
        Object[] options = { "OK", "Cancel" };
        n = JOptionPane.showOptionDialog(null,
                "A project already exists with this name. Do you want to delete it?\n" + projectLocation,
                "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
    }
    if (n == 0) {
        for (int i = 0; i <= 5; i++) {
            try {
                Thread.sleep(500);
                FileUtils.deleteDirectory(newProject);
            } catch (IOException ex) {
                System.out.println("Attempting deletion " + i);
            } catch (InterruptedException ex) {
                Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (newProject.exists()) {
            try {
                FileUtils.deleteDirectory(newProject);
            } catch (IOException ex) {
                Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    if (newProject.mkdir()) {
        try {
            newApp.mkdir();
            Utils.copyFolder(app, newApp);
            xml.mkdir();
            results.mkdir();
            updateInfoTextPane("Project created");
        } catch (IOException ex) {
            Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        updateInfoTextPane("Project is not created");

    }
    ProjectXMLhandler.makeNewProject(targetTableName, projectLocation);
    try {
        projectXML = new ProjectXMLhandler(projectLocation + File.separator + targetTableName + ".xml");
    } catch (FileNotFoundException ex) {
        infoBox("Project " + ex + " not found", "Error");
    } catch (IOException ex) {
        Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
    }

    embeddedMode = !this.connectToExternalDatabaseCheckBox.isSelected();
    con = connectToDB();
    //check for existence of project table and drop if asked.
    if (embeddedMode) {
        if (Utils.checkForTable(con, targetTableName)) {
            Object[] options = { "OK", "Cancel" };
            n = JOptionPane.showOptionDialog(null,
                    "A table already exists with this name. Do you want to delete it?\n"
                            + "note, this will delete ALL existing manual annotations for this project!"
                            + projectLocation,
                    "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                    options[1]);
            if (n == 0) {
                Utils.dropTable(con, targetTableName);
                Utils.dropTable(con, targetTableName + "_DOCUMENTS");
                Utils.dropIndex(con, targetTableName + "_DOCUMENTS_ID_INDEX");
                Utils.dropIndex(con, targetTableName + "_ID_INDEX");
                Utils.dropIndex(con, targetTableName + "_DOC_ID_INDEX");
                Utils.dropIndex(con, targetTableName + "_CONTEXTSTRING_INDEX");
                Utils.createFullDocsTable(con, targetTableName);
                Utils.createAnnotationsTable(con, targetTableName);
            }
        } else {
            Utils.createFullDocsTable(con, targetTableName);
            Utils.createAnnotationsTable(con, targetTableName);
        }
    }
    try {
        saveProject();
        loadProjectJFileChooser.rescanCurrentDirectory();
        this.tableToWorkOnjTextField.setText(this.targetTableName);
        projectLoaded = true;
        updateProjectSummary();
        return true;
    } catch (IOException ex) {
        Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
    }

    return false;

}

From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java

private void quitProgram() {
    int n;/*from ww  w . j  a v a2s  . co  m*/
    try {
        if (projectLoaded) {
            System.out.println("quitting program...");
            Object[] options = { "Yes", "No", "Cancel" };
            n = JOptionPane.showOptionDialog(null,
                    "Do you wish to save your project before exiting?\n" + projectLocation, "Warning",
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

            if (n == 0) {
                saveProject();
                shutDownProcedure();
                System.exit(0);
            } else if (n == 1) {
                shutDownProcedure();
                System.exit(0);
            }
        } else {
            System.exit(0);
        }
    } catch (IOException ex) {
        Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:uk.chromis.pos.admin.RolesViewTree.java

/**
 *
 * @return @throws BasicException//from   w  w  w .  java2s  .  c  o m
 */
@Override
public Object createValue() throws BasicException {
    Object[] role = new Object[4];
    role = new Object[4];
    role[0] = m_oId == null ? UUID.randomUUID().toString() : m_oId;
    role[1] = m_jName.getText();
    role[2] = Formats.BYTEA.parseValue(buildPermissionsStr());
    role[3] = jRightsLevel.getValue();

    if (!hasPermissions) {
        Object[] options = { AppLocal.getIntString("Button.Yes"), AppLocal.getIntString("Button.No") };
        if (JOptionPane.showOptionDialog(this,
                AppLocal.getIntString("Message.adminpermissions1") + m_jName.getText() + " "
                        + AppLocal.getIntString("Message.adminpermissions2"),
                AppLocal.getIntString("Message.adminwarning"), JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[1]) == 1) {
            // Re-instate original permissions for this role
            role = new Object[4];
            role[0] = m_oId == null ? UUID.randomUUID().toString() : m_oId;
            role[1] = m_jName.getText();
            role[2] = Formats.BYTEA.parseValue(m_dlAdmin.findRolePermissions(role[0].toString()));
            role[3] = m_dlAdmin.getRightsLevel(m_jName.getText());
            return role;
        }
    }
    return role;
}

From source file:uk.chromis.pos.inventory.ProductsEditor.java

private void m_jRetiredActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jRetiredActionPerformed
    if (m_jRetired.isSelected()) {
        Object[] options = { AppLocal.getIntString("Button.Yes"), AppLocal.getIntString("Button.No") };

        if (JOptionPane.showOptionDialog(this, AppLocal.getIntString("message.retiringproduct"),
                AppLocal.getIntString("Menu.Products"), JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE, null, options, options[1]) == 0) {

            m_jInCatalog.setSelected(false);
            m_jAlwaysAvailable.setSelected(false);
        } else {//from w  w  w .ja v  a  2  s.c o  m
            m_jRetired.setSelected(false);
        }
    }
}

From source file:us.ihmc.codecs.loader.OpenH264Downloader.java

private static void acceptLicenseGUI() {

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    JTextArea license = new JTextArea(getLicenseText());
    license.setEditable(false);/* ww w  .  j  a  va 2 s. c om*/
    license.setLineWrap(true);
    license.setWrapStyleWord(true);
    JScrollPane scroll = new JScrollPane(license);
    scroll.setPreferredSize(new Dimension(500, 500));
    panel.add(scroll);
    panel.add(new JLabel("Do you accept the OpenH264 License?"));

    if (JOptionPane.showOptionDialog(null, panel, "OpenH264 Video Codec provided by Cisco Systems, Inc.",
            JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null) != JOptionPane.YES_OPTION) {
        JOptionPane.showMessageDialog(null, "User did not accept OpenH264 license", "License not accepted",
                JOptionPane.ERROR_MESSAGE);
        System.exit(-1);
    }

}