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:jeplus.gui.JPanel_EPlusProjectFiles.java

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

    // Test if the template file is present
    String fn = (String) cboRviFile.getSelectedItem();
    if (fn.startsWith("Select ")) {
        fn = "my.rvx";
    }/* w ww.  ja  v a 2s.  c  om*/
    String templfn = RelativeDirUtil.checkAbsolutePath(txtRviDir.getText() + fn, Project.getBaseDir());
    File ftmpl = new File(templfn);
    if (!ftmpl.exists()) {
        int n = JOptionPane.showConfirmDialog(this,
                "<html><p><center>" + templfn + " does not exist."
                        + "Do you want to copy one from an existing file?</center></p>"
                        + "<p> Alternatively, select 'NO' to create this file. </p>",
                "RVI file not available", JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.YES_OPTION) {
            // Select a file to open
            if (this.chkReadVar.isSelected()) {
                MainGUI.getFileChooser().setFileFilter(EPlusConfig.getFileFilter(EPlusConfig.RVX));
            } else {
                MainGUI.getFileChooser().setFileFilter(EPlusConfig.getFileFilter(EPlusConfig.RVI));
            }
            MainGUI.getFileChooser().setMultiSelectionEnabled(false);
            MainGUI.getFileChooser().setSelectedFile(new File(""));
            String rvidir = RelativeDirUtil.checkAbsolutePath(txtRviDir.getText(), Project.getBaseDir());
            MainGUI.getFileChooser().setCurrentDirectory(new File(rvidir));
            if (MainGUI.getFileChooser().showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = MainGUI.getFileChooser().getSelectedFile();
                try {
                    FileUtils.copyFile(file, new File(templfn));
                    cboRviFile.setModel(new DefaultComboBoxModel(new String[] { fn }));
                    Project.setRVIDir(txtRviDir.getText());
                    Project.setRVIFile(fn);
                } catch (IOException ex) {
                    logger.error("Error copying RVX from source.", ex);
                }
            }
            MainGUI.getFileChooser().resetChoosableFileFilters();
            MainGUI.getFileChooser().setSelectedFile(new File(""));
        } else if (n == JOptionPane.NO_OPTION) {

        } else {
            return;
        }
    }
    int idx = MainGUI.getTpnEditors().indexOfTab(fn);
    if (idx >= 0) {
        MainGUI.getTpnEditors().setSelectedIndex(idx);
    } else {
        EPlusEditorPanel RviFilePanel;
        if (FilenameUtils.getExtension(fn).equals("rvx")) {
            RviFilePanel = new EPlusEditorPanel(MainGUI.getTpnEditors(), fn, templfn,
                    EPlusEditorPanel.FileType.RVX, null);
        } else {
            RviFilePanel = new EPlusEditorPanel(MainGUI.getTpnEditors(), fn, templfn,
                    EPlusEditorPanel.FileType.RVI, null);
        }
        int ti = MainGUI.getTpnEditors().getTabCount();
        MainGUI.getTpnEditors().addTab(fn, RviFilePanel);
        RviFilePanel.setTabId(ti);
        MainGUI.getTpnEditors().setSelectedIndex(ti);
        MainGUI.getTpnEditors().setTabComponentAt(ti,
                new ButtonTabComponent(MainGUI.getTpnEditors(), RviFilePanel));
        MainGUI.getTpnEditors().setToolTipTextAt(ti, templfn);
    }
}

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

public void load() {
    if (_circuit != null && _circuit.isModified()) {
        int replace = askSaveNow();
        if (replace == JOptionPane.CANCEL_OPTION) {
            return;
        }//  w  w  w  . ja  v  a2s . co  m
        if (replace == JOptionPane.YES_OPTION) {
            if (saveAs() == JOptionPane.CANCEL_OPTION) {
                LOGGER.info("save cancelled by user.");
            }
        }
    }
    try {
        if (OPEN_FILE_CHOOSER.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            File file = OPEN_FILE_CHOOSER.getSelectedFile();
            setCircuit(Circuit.fromJSon(FileUtils.readFileToString(file), file.getPath()));
            LOGGER.info("Loaded: " + file.getName() + ".");
            return;
        }
        LOGGER.info("load cancelled by user.");
    } catch (IOException exception) {
        exception.printStackTrace();
    }

}

From source file:org.fhaes.fhsamplesize.view.FHSampleSize.java

/**
 * TODO//  w ww .j a  va  2 s  . c o m
 */
@Override
public void actionPerformed(ActionEvent evt) {

    if (evt.getActionCommand().equals("Reset")) {
        // Reset the GUI for a new run
        int response = JOptionPane.showConfirmDialog(this, "Are you sure you want to start a new analysis?");
        if (response != JOptionPane.YES_OPTION)
            return;

        this.txtInputFile.setText(null);
        this.cboEventType.setSelectedIndex(0);
        this.spnSimulations.setValue(1000);
        this.spnSeed.setValue(30188);
        this.cboResampling.setSelectedIndex(0);
        this.cboThresholdType.setSelectedIndex(0);
        this.spnThresholdValueGT.setValue(1);
        segmentationPanel.chkSegmentation.setSelected(false);
        segmentationPanel.table.tableModel.clearSegments();
        this.panelChart.removeAll();
        this.panelChart.repaint();
        this.simulationsTable.removeAllRows();
        this.cboChartMetric.setEnabled(false);
        this.cboSegment.setEnabled(false);
    } else if (evt.getActionCommand().equals("NewFileTyped")) {
        // A new file name was typed
        try {
            if (filePathHasValidFile(txtInputFile.getText())) {
                actionRun.setEnabled(true);
                actionSaveTable.setEnabled(true);
                segmentationPanel.chkSegmentation.setEnabled(true);
            } else {
                actionRun.setEnabled(false);
                actionSaveTable.setEnabled(false);
                segmentationPanel.chkSegmentation.setEnabled(false);
            }
        } catch (Exception ex) {
            actionRun.setEnabled(false);
            actionSaveTable.setEnabled(false);
            segmentationPanel.chkSegmentation.setEnabled(false);
        }
    } else if (evt.getActionCommand().equals("UpdateChart")) {
        updateChart();
    } else if (evt.getActionCommand().equals("CancelAnalysis")) {
        // Cancel the analysis that is currently running
        taskWasCancelled = true;
        task.cancel(true);
    } else if (evt.getActionCommand().equals("LessThanThresholdStatus")) {
        setGUIForThresholdStatus();
    }
}

From source file:de.mendelson.comm.as2.client.AS2Gui.java

/**
 * Deletes the actual selected AS2 rows from the database, filesystem etc
 *//*from www  .ja  v a2 s . co m*/
private void deleteSelectedMessages() {
    if (this.runtimeConnection == null) {
        return;
    }
    int requestValue = JOptionPane.showConfirmDialog(this,
            this.rb.getResourceString("dialog.msg.delete.message"),
            this.rb.getResourceString("dialog.msg.delete.title"), JOptionPane.YES_NO_OPTION);
    if (requestValue != JOptionPane.YES_OPTION) {
        return;
    }
    int[] selectedRows = this.jTableMessageOverview.getSelectedRows();
    AS2Message[] overviewRows = ((TableModelMessageOverview) this.jTableMessageOverview.getModel())
            .getRows(selectedRows);
    List<AS2MessageInfo> deleteList = new ArrayList<AS2MessageInfo>();
    for (AS2Message message : overviewRows) {
        deleteList.add((AS2MessageInfo) message.getAS2Info());
    }
    DeleteMessageRequest request = new DeleteMessageRequest();
    request.setDeleteList(deleteList);
    this.getBaseClient().sendAsync(request);
}

From source file:model.settings.ReadSettings.java

private static boolean checkForUpdate(final View _view, final boolean _showNoUpdateMSG) {
    try {/*from   ww w . j a v a 2 s .c om*/
        // Create a URL for the desired page
        URL url = new URL("http://juliushuelsmann.github.io/paint/currentRelease");

        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String version = in.readLine();
        in.close();

        final String[] result = Version.getMilestonePercentageDone(version);
        if (result == null) {
            // error
            return false;
        }

        final String MS = result[0];
        final String perc = result[1];

        try {

            // parse information to integer.
            int new_milestone = Integer.parseInt(MS);
            int new_percentage = Integer.parseInt(perc);

            int crrnt_milestone = Integer.parseInt(Version.MILESTONE);
            int crrnt_percentage = Integer.parseInt(Version.PERCENTAGE_DONE);

            if (new_milestone > crrnt_milestone
                    || (new_percentage > crrnt_percentage && new_milestone == crrnt_milestone)) {

                int d = JOptionPane.showConfirmDialog(_view,
                        "A new version of paint has been found:\n" + "Used Version:\t" + "" + crrnt_milestone
                                + "." + "" + crrnt_percentage + "\n" + "New  Version:\t" + "" + new_milestone
                                + "." + "" + new_percentage + "\n\n"
                                + "Do you want to download it right now? \n"
                                + "This operation will close paint and restart \n"
                                + "the new version in about one minute.",
                        "Update", JOptionPane.YES_NO_OPTION);

                return d == JOptionPane.YES_OPTION;
            } else {

                if (_showNoUpdateMSG) {

                    JOptionPane.showMessageDialog(_view, "No updates found.", "Update",
                            JOptionPane.INFORMATION_MESSAGE);

                }

                return false;
            }

        } catch (NumberFormatException _nex) {

            // received version number corrupted.
            final String err_msg = "Failed to check for updates, \n"
                    + "the fetched version number is currupted.\n"
                    + "This error is server-related and will be \n"
                    + "fixed after it has been noticed by the \n" + "programmer ;).";

            // report error via logger.
            model.settings.State.getLogger().severe(err_msg);

            // notify the user if this the message call isn't silent.
            if (_showNoUpdateMSG) {

                JOptionPane.showMessageDialog(_view, err_msg, "Update", JOptionPane.INFORMATION_MESSAGE);

            }
            return false;
        }

    } catch (Exception e) {

        // update page not found, probably due to network problems.
        final String err_msg = "Connection to update page failed. \n"
                + "Either you are not corrected to the internet or \n"
                + "the update page has been removed accidently. \n"
                + "If you are able to connect to any other web-page,\n"
                + "the error is server-related and will be \n" + "fixed after being noticed by the \n"
                + "programmer ;).";

        // report error via logger.
        State.getLogger().warning(err_msg);

        // notify the user if this the message call isn't silent.
        if (_showNoUpdateMSG) {

            JOptionPane.showMessageDialog(_view, err_msg, "Update", JOptionPane.INFORMATION_MESSAGE);
        }
        return false;
    }
}

From source file:com.lottery.gui.MainLotteryForm.java

private void btnBuyTicketActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuyTicketActionPerformed
    if (StringUtils.isBlank(tfBuyerName.getText().trim())) {
        JOptionPane.showMessageDialog(this, "Buyer name is blank!");
        tfBuyerName.requestFocusInWindow();
        return;/* w w w  . j a va  2 s  . c o  m*/
    }

    if (StringUtils.isBlank(ftfBuyStartDate.getText().trim())) {
        JOptionPane.showMessageDialog(this, "Start date is invalid (dd/MM/yyyy)!");
        ftfBuyStartDate.requestFocusInWindow();
        return;
    }

    Date startDate = null;

    try {
        startDate = LotteryUtils.getDate(ftfBuyStartDate.getText().trim());
    } catch (ParseException ex) {
        JOptionPane.showMessageDialog(this, "Start date is invalid (dd/MM/yyyy)!");
        ftfBuyStartDate.requestFocusInWindow();
        LOGGER.error(ex);
        return;
    }

    Date targetDate = LotteryUtils.getTargetDate(startDate);

    Date today = new Date();
    if (today.after(startDate)) {
        JOptionPane.showMessageDialog(this, "Start date must be greater than today!");
        tfBuyerName.requestFocusInWindow();
        return;
    }

    int dialogResult = JOptionPane.showConfirmDialog(this,
            "Would You Like to generate ticket for: " + tfBuyerName.getText() + "?", "Warning",
            JOptionPane.YES_OPTION);
    if (dialogResult == JOptionPane.NO_OPTION) {
        return;
    }

    //        Date today = new Date();
    //        Date startDate = LotteryUtils.getNextDate(today);

    //        int startDay = LotteryUtils.getDayOfMonth(startDate);
    //        int maxDayOfMonth = LotteryUtils.getLastDayOfMonth(startDate);
    //
    //        buyerService.getAll();

    Buyer buyer = new Buyer();
    buyer.setName(tfBuyerName.getText().trim());
    buyer.setIc(tfBuyerIc.getText().trim());

    List<String> linesBallsDb = new ArrayList<>();
    List<Ticket> newTickets = new ArrayList<>();
    Date queryDate = startDate;

    int count = 0;
    try {
        //            for (int dayOfMonth = startDay; dayOfMonth <= maxDayOfMonth; dayOfMonth++) {
        for (; queryDate.before(targetDate);) {

            List<TicketTable> ticketTables = ticketTableService.getByDate(queryDate);
            linesBallsDb = LotteryUtils.getAllLinesBalls(ticketTables);
            Ticket newTicket = LotteryUtils.generateTicket(linesBallsDb, queryDate, count++);
            newTicket.setBuyer(buyer);
            newTickets.add(newTicket);
            queryDate = LotteryUtils.getNextDate(queryDate);

        }

        buyer.setTickets(newTickets);

        LotteryUtils.generatePhysicalTicket(buyer, System.currentTimeMillis() + "_" + buyer.getName() + ".xls");

        buyerService.saveOrUpdate(buyer);
        JOptionPane.showMessageDialog(this, "Generate ticket successfully for " + tfBuyerName.getText() + "!");

        btnResetActionPerformed(null);
    } catch (LotteryException ex) {
        LOGGER.error("Generate ticket exception: ", ex);
        JOptionPane.showMessageDialog(this, "Please help to try again!");
    } catch (Exception ex2) {
        LOGGER.error("Generate ticket exception: ", ex2);
        JOptionPane.showMessageDialog(this,
                "Something goes wrong! Please try again or report to administrator!");
    }

}

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

private void topngjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_topngjButtonActionPerformed
    // Save chart as a PNG image
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Save chart");
    KeelFileFilter fileFilter = new KeelFileFilter();
    fileFilter.addExtension("png");
    fileFilter.setFilterName("PNG images (.png)");
    chooser.setFileFilter(fileFilter);//from  ww  w  . j a va2s  . c  o m
    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(".png")) {
            // Add correct extension
            nombre += ".png";
        }
        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 {
                chart2.setBackgroundPaint(Color.white);
                ChartUtilities.saveChartAsPNG(new File(nombre), chart2, 1024, 768);
            } catch (Exception exc) {
            }
        }
    }
}

From source file:com.proyecto.vista.MantenimientoEmpleado.java

private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
    // TODO add your handling code here:
    List<Integer> array = new ArrayList();

    array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.LETRA, this.telefonoField, "telefono"));
    array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.apellidoMField,
            "apellido materno"));
    array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.apellidoPField,
            "apellido paterno"));
    array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.nombreField, "nombre"));
    array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.LETRA, this.idField, "DNI"));

    FormularioUtil.validar2(array);/*from   ww w  .  j a v a  2s  .  c o  m*/

    if (FormularioUtil.error) {
        JOptionPane.showMessageDialog(null, FormularioUtil.mensaje, "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
        FormularioUtil.mensaje = "";
        FormularioUtil.error = false;
    } else {
        String palabra = "";
        String palabra2 = "";
        if (accion == 1) {
            palabra = "registrar";
            palabra2 = "registrado";

            if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " el Empleado?",
                    "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                empleadoControlador.getSeleccionado().setDni(idField.getText().toUpperCase());
                empleadoControlador.getSeleccionado().setNombres(nombreField.getText().toUpperCase());
                empleadoControlador.getSeleccionado()
                        .setApellidoPaterno(apellidoPField.getText().toUpperCase());
                empleadoControlador.getSeleccionado()
                        .setApellidoMaterno(apellidoMField.getText().toUpperCase());
                empleadoControlador.getSeleccionado().setTelefono(telefonoField.getText().toUpperCase());

                empleadoControlador.accion(accion);
                lista.add(empleadoControlador.getSeleccionado());

                if (accion == 1) {
                    JOptionPane.showMessageDialog(null, "Empleado " + palabra2 + " correctamente",
                            "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);
                    FormularioUtil.limpiarComponente(panelDatos);
                } else {
                    JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                FormularioUtil.limpiarComponente(panelDatos);
                JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        } else if (accion == 2) {
            palabra = "modificar";
            palabra2 = "modificado";

            if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " el Empleado?",
                    "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                if (accion == 2) {
                    JOptionPane.showMessageDialog(null, "Empleado " + palabra2 + " correctamente",
                            "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);

                    lista.clear();
                    empleadoControlador.getSeleccionado().setDni(idField.getText().toUpperCase());
                    empleadoControlador.getSeleccionado().setNombres(nombreField.getText().toUpperCase());
                    empleadoControlador.getSeleccionado()
                            .setApellidoPaterno(apellidoPField.getText().toUpperCase());
                    empleadoControlador.getSeleccionado()
                            .setApellidoMaterno(apellidoMField.getText().toUpperCase());
                    empleadoControlador.getSeleccionado().setTelefono(telefonoField.getText().toUpperCase());
                    empleadoControlador.accion(accion);
                    listar();

                    FormularioUtil.limpiarComponente(panelDatos);

                } else {
                    JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                FormularioUtil.limpiarComponente(panelDatos);
                JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }

        FormularioUtil.limpiarComponente(panelDatos);
        FormularioUtil.activarComponente(panelOpciones, true);
        FormularioUtil.activarComponente(panelGuardar, false);
        FormularioUtil.activarComponente(panelDatos, false);
    }
}

From source file:serial.ChartFromSerial.java

public void createSerialThread(SerialPort desiredPort) {
    //Create Serial Scanning Thread
    serialThread = new Thread() {
        @Override/*w  w  w .  ja va  2 s  .com*/
        public void run() {
            try (Scanner serialScanner = new Scanner(desiredPort.getInputStream())) {
                int numIn;
                while (serialScanner.hasNextLine()) {
                    String textIn = serialScanner.nextLine();
                    try {
                        numIn = Integer.parseInt(textIn);
                        defaultSeries.add(samples, numIn);
                        text.append(samples++ + ": " + numIn + "\n");
                        if (autoScrollEnabled) {
                            text.setCaretPosition(text.getDocument().getLength());
                        }
                    } catch (NumberFormatException e) {
                        System.out.println("Unexpected value at " + desiredPort.getSystemPortName() + ": \""
                                + textIn + "\"");
                    }
                }
            } catch (Exception e) {
                System.out.println(e);
                samples = 0;
                if (JOptionPane.showConfirmDialog(rootPane,
                        "The serial connection has fialed.\n Would you like to refresh?",
                        "Serial connection failed.", JOptionPane.YES_NO_OPTION,
                        JOptionPane.ERROR_MESSAGE) == JOptionPane.YES_OPTION) {
                    hardRefresh();
                    defaultSeries.clear();
                    text.setText("");
                } else {
                    buttonsOff();
                }
            }
        }
    };
    serialThread.start();
}

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

private void removeSelection(boolean pAsk) {
    int[] selectedRows = jAttacksTable.getSelectedRows();
    if (selectedRows == null || selectedRows.length < 1) {
        showInfo("Keine Angriffe ausgewhlt");
        return;/*from ww  w. j av a  2s  . c  om*/
    }

    if (!pAsk || JOptionPaneHelper.showQuestionConfirmBox(this,
            "Willst du " + ((selectedRows.length == 1) ? "den gewhlten Angriff " : "die gewhlten Angriffe ")
                    + "wirklich lschen?",
            "Lschen", "Nein", "Ja") == JOptionPane.YES_OPTION) {

        DefenseToolModel model = TableHelper.getTableModel(jAttacksTable);
        int numRows = selectedRows.length;
        List<DefenseInformation> toRemove = new LinkedList<>();
        for (int row : selectedRows) {
            toRemove.add(model.getRows()[jAttacksTable.convertRowIndexToModel(row)]);
        }

        //remove model rows
        for (DefenseInformation defense : toRemove) {
            model.removeRow(defense);
        }

        //update SOS requests
        for (ManageableType e : SOSManager.getSingleton().getAllElements()) {
            SOSRequest r = (SOSRequest) e;
            for (DefenseInformation defense : toRemove) {
                r.removeTarget(defense.getTarget());
            }
        }

        model.fireTableDataChanged();
        showSuccess(((numRows == 1) ? "Angriff" : numRows + " Angriffe") + " gelscht");
    }
}