Example usage for javax.swing JOptionPane YES_NO_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_OPTION

Introduction

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

Prototype

int YES_NO_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:edu.clemson.cs.nestbed.client.gui.TestbedManagerFrame.java

private boolean confirmDelete(String text) {
    int choice;//  www. j  av a  2  s .  c  o  m

    choice = JOptionPane.showConfirmDialog(this, "Do you wisth to delete '" + text + "'?",
            "Delete Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    return (choice == JOptionPane.YES_OPTION);
}

From source file:dataviewer.DataViewer.java

private void btn_removeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_removeActionPerformed
    String name = "./db/" + cb_table.getSelectedItem().toString() + ".db";
    if (new File(name).exists()) {
        int dialogResult = JOptionPane
                .showConfirmDialog(null,
                        "Selected file [" + cb_table.getSelectedItem().toString()
                                + "] will be removed and not recoverable.",
                        "Are you sure?", JOptionPane.YES_NO_OPTION);
        if (dialogResult == JOptionPane.YES_OPTION) {
            (new File(name)).delete();
            cb_table.removeItem(cb_table.getSelectedItem());
            cb_table.setSelectedItem(null);
            tp_sql.setText("");
            tb_columns.setModel(new DefaultTableModel());
        }/*from ww w.j  av  a2  s .  c  o m*/
    }

}

From source file:UserInterface.ViewPatientJPanel.java

private void btnDeleteVitalSignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteVitalSignActionPerformed

    int selectedRow = tblVitalSigns.getSelectedRow();

    if (selectedRow >= 0) {
        int dialogButton = JOptionPane.YES_NO_OPTION;
        int dialogResult = JOptionPane.showConfirmDialog(null, "Would you like to delete this?", "Warning",
                dialogButton);/*w  w w  .ja  v a2  s. com*/

        if (dialogResult == JOptionPane.YES_OPTION) {
            VitalSign vs = (VitalSign) tblVitalSigns.getValueAt(selectedRow, 0);
            patient.vitalSignHistory.removeVitalSign(vs);
            populateTable();
            resetFields();
        }
    } else {
        JOptionPane.showMessageDialog(null, "Please select a row to delete!");
    }

}

From source file:course_generator.param.frmEditCurve.java

/**
 * Delete the selected curve//from   w  ww.ja v a  2s.c o  m
 */
protected void DeleteCurve() {
    if (!bEditMode) {
        int index = ListCurves.getSelectedIndex();
        if (index >= 0) {
            String s = Paramfile = (String) model.getElementAt(index);
            if (s.toUpperCase() != "DEFAULT") {
                Object[] options = { " " + bundle.getString("frmEditCurve.DeleteYes") + " ",
                        " " + bundle.getString("frmEditCurve.DeleteNo") + " " };
                int ret = JOptionPane.showOptionDialog(this,
                        bundle.getString("frmEditCurve.DeleteCurveMessage"),
                        bundle.getString("frmEditCurve.DeleteCurveTitle"), JOptionPane.YES_NO_OPTION,
                        JOptionPane.WARNING_MESSAGE, null, options, options[1]);

                if (ret == JOptionPane.YES_OPTION) {
                    File f = new File(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/" + s + ".par");
                    f.delete();
                    LoadCurve(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/default.par");
                    Paramfile = "Default";
                    RefreshView();
                    RefreshCurveList();
                }
            }
        }
    }
}

From source file:com._17od.upm.gui.DatabaseActions.java

public void showDatabaseProperties()
        throws ProblemReadingDatabaseFile, IOException, CryptoException, PasswordDatabaseException {
    try {/*w  w w  .  ja  v  a 2s. co m*/
        if (getLatestVersionOfDatabase()) {
            DatabasePropertiesDialog dbPropsDialog = new DatabasePropertiesDialog(mainWindow, getAccountNames(),
                    database);
            dbPropsDialog.pack();
            dbPropsDialog.setLocationRelativeTo(mainWindow);
            dbPropsDialog.show();
            if (dbPropsDialog.getDatabaseNeedsSaving()) {
                saveDatabase();
            }
        }
    } catch (TransportException e) {
        int response = JOptionPane.showConfirmDialog(mainWindow,
                Translator.translate("problemRetrievingRemoteDB"), Translator.translate("detachDatabase"),
                JOptionPane.YES_NO_OPTION);
        if (response == JOptionPane.YES_OPTION) {
            database.getDbOptions().setRemoteLocation("");
            database.getDbOptions().setAuthDBEntry("");
            saveDatabase();
        }
    }
}

From source file:AltiConsole.AltiConsoleMainScreen.java

/**
 * Handles all the actions./*from w  w  w  .  j a v  a 2 s. c o m*/
 * 
 * @param e
 *            the action event.
 */
public void actionPerformed(final ActionEvent e) {
    final Translator trans = Application.getTranslator();

    if (e.getActionCommand().equals("EXIT")) {
        System.out.println("exit and disconnecting\n");
        if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.ClosingWindow"),
                trans.get("AltiConsoleMainScreen.ReallyClosing"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            DisconnectFromAlti();
            System.exit(0);
        }
    } else if (e.getActionCommand().equals("ABOUT")) {
        AboutDialog.showPreferences(AltiConsoleMainScreen.this);
    }
    // ERASE_FLIGHT
    else if (e.getActionCommand().equals("ERASE_FLIGHT")) {

        if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.eraseAllflightData"),
                trans.get("AltiConsoleMainScreen.eraseAllflightDataTitle"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            System.out.println("erasing flight\n");
            ErasingFlight();
        }

    } else if (e.getActionCommand().equals("RETRIEVE_FLIGHT")) {

        System.out.println("retrieving flight\n");
        RetrievingFlight();

    } else
    // SAVE_FLIGHT
    if (e.getActionCommand().equals("SAVE_FLIGHT")) {
        System.out.println("Saving current flight\n");
        SavingFlight();
    } else
    // RETRIEVE_ALTI_CFG
    if (e.getActionCommand().equals("RETRIEVE_ALTI_CFG")) {
        System.out.println("retrieving alti config\n");
        AltiConfigData pAlticonfig = retrieveAltiConfig();
        if (pAlticonfig != null)
            AltiConfigDlg.showPreferences(AltiConsoleMainScreen.this, pAlticonfig, Serial);

    }
    // LICENSE
    else if (e.getActionCommand().equals("LICENSE")) {

        LicenseDialog.showPreferences(AltiConsoleMainScreen.this);
    }
    // comPorts
    else if (e.getActionCommand().equals("comPorts")) {
        DisconnectFromAlti();
        String currentPort;
        //e.
        currentPort = (String) comPorts.getSelectedItem();
        if (Serial != null)
            Serial.searchForPorts();

        System.out.println("We have a new selected value for comport\n");
        comPorts.setSelectedItem(currentPort);
    }
    // UPLOAD_FIRMWARE
    else if (e.getActionCommand().equals("UPLOAD_FIRMWARE")) {
        System.out.println("upload firmware\n");
        //make sure to disconnect first
        DisconnectFromAlti();
        JFileChooser fc = new JFileChooser();
        String hexfile = null;
        File startFile = new File(System.getProperty("user.dir"));
        //FileNameExtensionFilter filter;

        fc.setDialogTitle("Select firmware");
        //fc.set
        fc.setCurrentDirectory(startFile);
        //fc.addChoosableFileFilter(new FileNameExtensionFilter("*.HEX", "hex"));
        fc.setFileFilter(new FileNameExtensionFilter("*.hex", "hex"));
        //fc.fil
        int action = fc.showOpenDialog(SwingUtilities.windowForComponent(this));
        if (action == JFileChooser.APPROVE_OPTION) {
            hexfile = fc.getSelectedFile().getAbsolutePath();
        }
        if (hexfile != null) {

            String exefile = UserPref.getAvrdudePath();

            String conffile = UserPref.getAvrdudeConfigPath();

            String opts = " -v -v -v -v -patmega328p -carduino -P\\\\.\\"
                    + (String) this.comPorts.getSelectedItem() + " -b115200 -D -V ";

            String cmd = exefile + " -C" + conffile + opts + " -Uflash:w:" + hexfile + ":i";
            System.out.println(cmd);

            try {
                Process p = Runtime.getRuntime().exec(cmd);
                AfficheurFlux fluxSortie = new AfficheurFlux(p.getInputStream(), this);
                AfficheurFlux fluxErreur = new AfficheurFlux(p.getErrorStream(), this);

                new Thread(fluxSortie).start();
                new Thread(fluxErreur).start();

                p.waitFor();
            } catch (IOException e1) {
                e1.printStackTrace();
            } catch (InterruptedException e2) {
                e2.printStackTrace();
            }
        }
    }
    // ON_LINE_HELP
    else if (e.getActionCommand().equals("ON_LINE_HELP")) {
        Desktop d = Desktop.getDesktop();
        System.out.println("Online help \n");
        try {
            d.browse(new URI(trans.get("help.url")));
        } catch (URISyntaxException e1) {

            System.out.println("Illegal URL:  " + trans.get("help.url") + " " + e1.getMessage());
        } catch (IOException e1) {
            System.out.println("Unable to launch browser: " + e1.getMessage());
        }

    }
}

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

protected void loadLogFile() {
    fileChooser.setMultiSelectionEnabled(true);
    if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this))
        return;//  ww  w  . j a  v  a  2 s.  c o m
    boolean isPolSet = polfTable.isSet();
    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, false);

                boolean resetColumns = false;
                if (logThtlAngleColIdx >= 0 || logAfLearningColIdx >= 0 || logAfCorrectionColIdx >= 0
                        || logMafvColIdx >= 0 || logAfrColIdx >= 0 || logRpmColIdx >= 0 || logLoadColIdx >= 0
                        || logCommandedAfrCol >= 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 || logThtlAngleColIdx < 0 || logAfLearningColIdx < 0
                        || logAfCorrectionColIdx < 0 || logMafvColIdx < 0 || logAfrColIdx < 0
                        || logRpmColIdx < 0 || logLoadColIdx < 0 || (logCommandedAfrCol < 0 && !isPolSet)) {
                    ColumnsFiltersSelection selectionWindow = new OLColumnsFiltersSelection(isPolSet);
                    if (!selectionWindow.getUserSettings(elements) || !getColumnsFilters(elements, isPolSet))
                        return;
                }

                String[] flds;
                String[] afrflds;
                boolean wotFlag = true;
                boolean foundWot = false;
                double throttle;
                double stft;
                double ltft;
                double afr;
                double rpm;
                double load;
                double mafv;
                double cmdafr = 0;
                double afrErr = 0;
                int skipRowCount = 0;
                int row = 0;
                int i = 0;
                int j = 0;
                for (; i < runTables.length; ++i) {
                    if (runTables[i].getValueAt(0, 0).toString().isEmpty())
                        break;
                }
                if (i == runTables.length)
                    return;
                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));
                }
                while (line != null && buffer.size() > afrRowOffset) {
                    afrflds = buffer.getFirst();
                    flds = buffer.removeLast();
                    line = br.readLine();
                    if (line != null)
                        buffer.addFirst(line.split(",", -1));

                    try {
                        throttle = Double.valueOf(flds[logThtlAngleColIdx]);
                        if (row == 0 && throttle < 99)
                            wotFlag = false;
                        if (throttle < wotPoint) {
                            if (wotFlag == true) {
                                wotFlag = false;
                                skipRowCount = 0;
                                j -= 1;
                                while (j > 0 && skipRowCount < skipRowsOnTransition) {
                                    runTables[i].setValueAt("", j, 0);
                                    runTables[i].setValueAt("", j, 1);
                                    runTables[i].setValueAt("", j, 2);
                                    skipRowCount += 1;
                                    j -= 1;
                                }
                                skipRowCount = 0;
                            }
                        } else {
                            if (wotFlag == false) {
                                wotFlag = true;
                                skipRowCount = 0;
                                if (foundWot) {
                                    i += 1;
                                    if (i == runTables.length)
                                        return;
                                }
                                if (row > 0)
                                    j = 0;
                            }
                            if (skipRowCount >= skipRowsOnTransition) {
                                mafv = Double.valueOf(flds[logMafvColIdx]);
                                if (minMafV <= mafv) {
                                    foundWot = true;
                                    stft = Double.valueOf(flds[logAfCorrectionColIdx]);
                                    ltft = Double.valueOf(flds[logAfLearningColIdx]);
                                    afr = Double.valueOf(afrflds[logAfrColIdx]);
                                    rpm = Double.valueOf(flds[logRpmColIdx]);
                                    load = Double.valueOf(flds[logLoadColIdx]);

                                    afr = afr / ((100.0 - (ltft + stft)) / 100.0);

                                    if (logCommandedAfrCol >= 0)
                                        cmdafr = Double.valueOf(flds[logCommandedAfrCol]);
                                    else if (isPolSet)
                                        cmdafr = Utils.calculateCommandedAfr(rpm, load, minWotEnrichment,
                                                polfTable);
                                    else {
                                        JOptionPane.showMessageDialog(null,
                                                "Please set either \"Commanded AFR\" column or \"Primary Open Loop Fueling\" table",
                                                "Error", JOptionPane.ERROR_MESSAGE);
                                        return;
                                    }

                                    afrErr = (afr - cmdafr) / cmdafr * 100.0;
                                    if (Math.abs(afrErr) <= afrErrPrct) {
                                        Utils.ensureRowCount(j + 1, runTables[i]);
                                        runTables[i].setValueAt(rpm, j, 0);
                                        runTables[i].setValueAt(mafv, j, 1);
                                        runTables[i].setValueAt(afrErr, j, 2);
                                        j += 1;
                                    }
                                }
                            }
                            skipRowCount += 1;
                        }
                    } catch (NumberFormatException e) {
                        logger.error(e);
                        JOptionPane.showMessageDialog(null,
                                "Error parsing number at " + file.getName() + " line " + (row + 1) + ": " + e,
                                "Error processing file", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    row += 1;
                }

                if (!foundWot) {
                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                    JOptionPane.showMessageDialog(null, "Sorry, no WOT pulls were found in the log file",
                            "No WOT data", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        } catch (Exception e) {
            logger.error(e);
            JOptionPane.showMessageDialog(null, e, "Error opening file", JOptionPane.ERROR_MESSAGE);
        } finally {
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    logger.error(e);
                }
            }
        }
    }
}

From source file:cl.almejo.vsim.gui.SimWindow.java

private int askOverwrite() {
    return JOptionPane.showConfirmDialog(this, Messages.t("file.replace.message"),
            Messages.t("file.replace.title"), JOptionPane.YES_NO_OPTION);
}

From source file:agendapoo.View.FrmMinhaAtividade.java

private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnRemoveActionPerformed
{//GEN-HEADEREND:event_btnRemoveActionPerformed
    try {//from  w  ww .  j av  a 2  s .co m
        int i = JOptionPane.showConfirmDialog(this, "Tem certeza que desejas remover essa atividade?", "Aviso",
                JOptionPane.YES_NO_OPTION);
        switch (i) {
        case JOptionPane.YES_OPTION:
            deleteAtividade();
            JOptionPane.showMessageDialog(this, "Atividade removida com sucesso! :)");
            usuarioMain.loadAtividades();
            this.dispose();
            break;
        }
    } catch (SQLException | IOException | ClassNotFoundException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage());
    } catch (EmailException ex) {
        JOptionPane.showMessageDialog(this,
                "No foi possvel enviar o e-mail para os convidados, por favor, "
                        + "verifique sua conexo com a internet e tente novamente.",
                "Problema ao enviar e-mail", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:keel.GraphInterKeel.datacf.visualizeData.VisualizePanelCharts2D.java

private void topdfjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_topdfjButtonActionPerformed
    // Save chart as a PDF file
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Save chart");
    KeelFileFilter fileFilter = new KeelFileFilter();
    fileFilter.addExtension("pdf");
    fileFilter.setFilterName("PDF images (.pdf)");
    chooser.setFileFilter(fileFilter);/*w ww . java2s.  c  om*/
    chooser.setCurrentDirectory(Path.getFilePath());
    int opcion = chooser.showSaveDialog(this);
    Path.setFilePath(chooser.getCurrentDirectory());
    if (opcion == JFileChooser.APPROVE_OPTION) {
        String nombre = chooser.getSelectedFile().getAbsolutePath();
        if (!nombre.toLowerCase().endsWith(".pdf")) {
            // Add correct extension
            nombre += ".pdf";
        }
        File tmp = new File(nombre);
        if (!tmp.exists() || JOptionPane.showConfirmDialog(this,
                "File " + nombre + " already exists. Do you want to replace it?", "Confirm",
                JOptionPane.YES_NO_OPTION, 3) == JOptionPane.YES_OPTION) {
            try {
                Document document = new Document();
                PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(nombre));
                document.addAuthor("KEEL");
                document.addSubject("Attribute comparison");
                document.open();
                PdfContentByte cb = writer.getDirectContent();
                PdfTemplate tp = cb.createTemplate(550, 412);
                Graphics2D g2 = tp.createGraphics(550, 412, new DefaultFontMapper());
                Rectangle2D r2D = new Rectangle2D.Double(0, 0, 550, 412);
                chart2.setBackgroundPaint(Color.white);
                chart2.draw(g2, r2D);
                g2.dispose();
                cb.addTemplate(tp, 20, 350);
                document.close();
            } catch (Exception exc) {
            }
        }
    }
}