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:com.alvermont.terraj.fracplanet.ui.AbstractTerrainViewerFrame.java

private void saveParamsItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveParamsItemActionPerformed
{//GEN-HEADEREND:event_saveParamsItemActionPerformed

    final int choice = this.xmlChooser.showSaveDialog(this);

    if (choice == JFileChooser.APPROVE_OPTION) {
        if (!this.xmlChooser.getSelectedFile().isFile() || (JOptionPane.showConfirmDialog(this,
                "This file already exists. Do you want to\n" + "overwrite it?", "Replace File?",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)) {
            try {
                final File target = FileUtils.addExtension(this.xmlChooser.getSelectedFile(), ".xml");

                final XMLEncoder enc = new XMLEncoder(new FileOutputStream(target));

                getParameters().getRenderParameters().setCameraPosition(display.getCameraPosition());
                getParameters().getCameraPositionParameters().setPositions(this.cameraPosDialog.getPositions());

                enc.setPersistenceDelegate(TerrainParameters.ObjectTypeEnum.class,
                        new EnumDelegate<TerrainParameters.ObjectTypeEnum>(
                                TerrainParameters.ObjectTypeEnum.class));

                enc.writeObject(getParameters());

                enc.close();/*from   www.  j  a v  a  2s. c  om*/
            } catch (IOException ioe) {
                log.error("Error writing xml file", ioe);

                JOptionPane.showMessageDialog(this,
                        "Error: " + ioe.getMessage() + "\nCheck log file for full details", "Error Saving",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}

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

public boolean deleteSelection(boolean pAsk) {
    List<Attack> selectedAttacks = getSelectedAttacks();

    if (pAsk) {/*from w  w  w  .j a  v a 2  s  .c  o m*/
        String message = ((selectedAttacks.size() == 1) ? "Angriff " : (selectedAttacks.size() + " Angriffe "))
                + "wirklich lschen?";
        if (selectedAttacks.isEmpty() || JOptionPaneHelper.showQuestionConfirmBox(this, message,
                "Angriffe lschen", "Nein", "Ja") != JOptionPane.YES_OPTION) {
            return false;
        }
    }

    jAttackTable.editingCanceled(new ChangeEvent(this));
    AttackManager.getSingleton().removeElements(AttackManager.MANUAL_ATTACK_PLAN, selectedAttacks);
    ((DoItYourselfAttackTableModel) jAttackTable.getModel()).fireTableDataChanged();
    showSuccess(selectedAttacks.size() + " Angriff(e) gelscht");
    return true;
}

From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java

private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveMenuItemActionPerformed
{//GEN-HEADEREND:event_saveMenuItemActionPerformed

    final int choice = this.xmlChooser.showSaveDialog(this);

    if (choice == JFileChooser.APPROVE_OPTION) {
        if (!this.xmlChooser.getSelectedFile().exists() || (JOptionPane.showConfirmDialog(this,
                "This file already exists. Do you want to\n" + "overwrite it?", "Replace File?",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)) {
            try {
                final File target = FileUtils.addExtension(this.xmlChooser.getSelectedFile(), ".xml");

                final XMLEncoder enc = new XMLEncoder(new FileOutputStream(target));

                enc.writeObject(this.parameters);

                enc.close();/*from ww w  .  ja  v a 2s  .  c om*/
            } catch (IOException ioe) {
                log.error("Error writing xml file", ioe);

                JOptionPane.showMessageDialog(this,
                        "Error: " + ioe.getMessage() + "\nCheck log file for full details", "Error Saving",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }
}

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

private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
    // TODO add your handling code here:
    String palabra = "";
    String palabra2 = "";
    if (accion == 1) {
        palabra = "registrar";
        palabra2 = "registrado";

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

            bienControlador.getSeleccionado().setNombre(nombreField.getText().toUpperCase());
            //                bienControlador.getSeleccionado().setCodigo(idField.getText());
            bienControlador.getSeleccionado().setDescripcion(descripcionField.getText().toUpperCase());
            bienControlador.getSeleccionado().setFoto(fotoField.getText());

            //                Clase clase = (Clase) cmbClase.getSelectedItem();
            //                bienControlador.getSeleccionado().setClase(clase);
            bienControlador.accion(accion);
            lista.add(bienControlador.getSeleccionado());

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

            } else {
                JOptionPane.showMessageDialog(null, "Bien no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }/*from   w ww  .java2 s  .c  o m*/
        } else {

            JOptionPane.showMessageDialog(null, "Bien no " + palabra2, "Mensaje del Sistema",
                    JOptionPane.ERROR_MESSAGE);
        }
    } else if (accion == 2) {
        palabra = "modificar";
        palabra2 = "modificado";

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

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

                lista.clear();
                bienControlador.getSeleccionado().setNombre(nombreField.getText().toUpperCase());
                //                    bienControlador.getSeleccionado().setCodigo(nombreField.getText());
                bienControlador.getSeleccionado().setDescripcion(descripcionField.getText().toUpperCase());
                bienControlador.getSeleccionado().setFoto(fotoField.getText());

                //                    Clase clase = (Clase) cmbClase.getSelectedItem();
                //                    bienControlador.getSeleccionado().setClase(clase);
                bienControlador.accion(accion);
                listar();

            } else {
                JOptionPane.showMessageDialog(null, "Bien no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Bien no " + palabra2, "Mensaje del Sistema",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

    for (DetalleBienCampo detalle : lista3) {
        detalle.setBien(bienControlador.getSeleccionado());
        detalleControlador.setSeleccionado(detalle);
        detalleControlador.accion(Controlador.MODIFICAR);
    }

    lista3.clear();
    FormularioUtil.activarComponente(panelOpciones, true);
    FormularioUtil.activarComponente(panelGuardar, false);
    FormularioUtil.activarComponente(panelDatos, false);
    FormularioUtil.limpiarComponente(panelDatos);
    fotoLbl.setIcon(null);
    descripcionField.setText(null);

}

From source file:com.iucosoft.eavertizare.gui.MainJFrame.java

private void sendAvertizare(String tipAvertizare) {
    int selectedRowIndex = jTableClients.getSelectedRow();
    Client client = null;//from   ww  w . j a v  a2s. c o  m
    int contor = 0;
    String mesaj = "";
    Icon icon = new ImageIcon(getClass().getResource("/images/help_and_support.png"));
    if (selectedRowIndex != -1) {

        int rez = JOptionPane.showConfirmDialog(this, "Doriti sa modificati mesajul ?", "Question",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, icon);
        switch (rez) {
        case JOptionPane.YES_OPTION:
            client = cientForIndex(selectedRowIndex);

            sendAvertizareJFrame(client.getFirma(), client, tipAvertizare);
            break;

        case JOptionPane.NO_OPTION:
            client = cientForIndex(selectedRowIndex);
            SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
            String mesajClient = client.getFirma().getMesajPentruClienti()
                    .replaceFirst("nume", client.getNume()).replaceFirst("prenume", client.getPrenume())
                    .replaceFirst("data", sdf.format(client.getDateExpirare()).toString())
                    .replaceFirst("compania", client.getFirma().getNumeFirma());
            switch (tipAvertizare) {
            case "SMS AND E-MAIL":
                mesaj = "Sms si e-mail";

            {
                try {

                    client.setTrimis(true);
                    clientsDao.update(client.getFirma(), client);
                    smsSender.sendSms(client.getNrTelefon(), mesajClient);
                    mailSender.sendMail(client.getEmail(), "E-avetizare", mesajClient);
                } catch (Exception ex) {
                    //Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(new JFrame(), "Verificai conexiunea la internet!\n" + ex,
                            "Error", JOptionPane.ERROR_MESSAGE);
                    contor = 1;
                }

            }

                clientiTableModel.refreshModel();
                break;
            case "SMS":
                mesaj = "Sms";

                try {
                    smsSender.sendSms(client.getNrTelefon(), mesajClient);
                } catch (Exception ex) {
                    //Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(new JFrame(), "Verificai conexiunea la internet!\n" + ex,
                            "Error", JOptionPane.ERROR_MESSAGE);
                    contor = 1;
                }

                break;
            case "E-MAIL":
                mesaj = "E-mail";
                try {
                    mailSender.sendMail(client.getEmail(), "E-avetizare", mesajClient);
                } catch (Exception ex) {
                    //Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(new JFrame(), "Verificai conexiunea la internet!\n" + ex,
                            "Error", JOptionPane.ERROR_MESSAGE);
                    contor = 1;
                }

                break;
            }
            if (contor != 1) {
                JOptionPane.showMessageDialog(MainJFrame.this, mesaj + " transmis cu succes!", "Info",
                        JOptionPane.INFORMATION_MESSAGE);
            }

            break;

        case JOptionPane.CLOSED_OPTION:
            break;

        }
    } else {
        JOptionPane.showMessageDialog(this, "Selectati clientul!", "Info", JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:brainflow.app.toplevel.BrainFlow.java

private void register(IImageSource dataSource) {
    DataSourceManager manager = DataSourceManager.get();
    boolean alreadyRegistered = manager.isRegistered(dataSource);

    try {/*from  ww w .java2s  .c  o m*/
        if (alreadyRegistered) {
            long lastModified = dataSource.getDataFile().getContent().getLastModifiedTime();
            long lastRead = dataSource.whenRead();

            if (lastModified > lastRead) {
                StringBuffer sb = new StringBuffer();
                sb.append("Image " + dataSource.getDataFile().getName().getBaseName());
                sb.append(
                        "has already been loaded in BrainFlow, but has changed on disk.  Would you like to reload?");

                Integer ret = JOptionPane.showConfirmDialog(brainFrame, sb.toString(),
                        "Image has been modified", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

                if (ret == JOptionPane.YES_OPTION) {
                    dataSource.releaseData();
                }
            } else {
                log.info(dataSource.getStem() + " is already registered ...");
            }

        } else {
            manager.register(dataSource);
        }
    } catch (FileSystemException e) {
        JOptionPane.showMessageDialog(brainFrame, "Error accessing file information: " + e.getMessage());
    }

}

From source file:ded.ui.DiagramController.java

/** Prompt user for file name and save to it. */
public void chooseAndSaveToFile() {
    // Prompt for a file name, confirming if the file already exists.
    String result = this.fileName;
    while (true) {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(this.currentFileChooserDirectory);
        chooser.addChoosableFileFilter(new FileNameExtensionFilter("Diagram Editor Files (.ded)", "ded"));
        int res = chooser.showSaveDialog(this);
        if (res != JFileChooser.APPROVE_OPTION) {
            return;
        }//from   ww w.  j a v  a2 s.c o m
        this.currentFileChooserDirectory = chooser.getCurrentDirectory();
        result = chooser.getSelectedFile().getAbsolutePath();

        if (new File(result).exists()) {
            res = JOptionPane.showConfirmDialog(this,
                    "A file called \"" + result + "\" already exists.  Overwrite it?", "Confirm Overwrite",
                    JOptionPane.YES_NO_OPTION);
            if (res != JOptionPane.YES_OPTION) {
                continue; // Ask again.
            }
        }

        break;
    }

    // Save to the chosen file.
    this.saveToNamedFile(result);
}

From source file:edu.ku.brc.specify.tasks.ReportsBaseTask.java

/**
 * Processes all Commands of type LABELS.
 * @param cmdAction the command to be processed
 *//*from ww  w  . j ava 2s . c  o  m*/
protected void processReportCommands(final CommandAction cmdAction) {

    //---------------------------------------------------------------------------
    // This Code here needs to be refactored and moved to the NavBoxAction
    // so it can happen in a single generic place (Each task has this code)
    //---------------------------------------------------------------------------
    /*if (cmdAction.getData() instanceof RecordSetIFace)
    {
    if (((RecordSetIFace)cmdAction.getData()).getDbTableId() != cmdAction.getTableId())
    {
        JOptionPane.showMessageDialog(null, getResourceString("ERROR_RECORDSET_TABLEID"), getResourceString("Error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    }*/

    Object data = cmdAction.getData();
    UsageTracker.incrUsageCount(
            "RP." + cmdAction.getType() + (data != null ? ("." + data.getClass().getSimpleName()) : ""));

    if (cmdAction.isAction(NEWRECORDSET_ACTION)) {
        if (cmdAction.getData() instanceof GhostActionable) {
            GhostActionable ga = (GhostActionable) cmdAction.getData();
            GhostMouseInputAdapter gpa = ga.getMouseInputAdapter();

            for (NavBoxItemIFace nbi : reportsList) {
                if (nbi instanceof GhostActionable) {
                    gpa.addGhostDropListener(new GhostActionableDropManager(UIRegistry.getGlassPane(),
                            nbi.getUIComponent(), ga));
                }
            }
        }
    } else if (cmdAction.isAction(PRINT_REPORT)) {
        if (data instanceof CommandAction && ((CommandAction) data).isAction(RUN_REPORT)) {
            runReport(cmdAction);
        }
        //            if (cmdAction.getData() instanceof CommandAction && ((CommandAction)cmdAction.getData()).isAction(OPEN_EDITOR))
        //            {
        //                openIReportEditor(cmdAction);
        //            }
        if (cmdAction.getData() instanceof RecordSetIFace) {
            RecordSetIFace rs = (RecordSetIFace) cmdAction.getData();
            if (rs.getDbTableId() != null && rs.getDbTableId() == SpReport.getClassTableId()
                    || cmdAction.getProperty("spreport") != null) {
                runReport(cmdAction);
            } else {
                printReport(cmdAction);
            }
        } else {
            if (data instanceof CommandAction && ((CommandAction) data).isAction(PRINT_REPORT)) {
                printReport((CommandAction) data);
            } else {
                printReport(cmdAction);
            }
        }
    }
    //        else if (cmdAction.isAction(OPEN_EDITOR))
    //        {
    //            openIReportEditor(cmdAction);
    //        }
    else if (cmdAction.isAction(RUN_REPORT)) {
        boolean doRun = true;
        if (data instanceof CommandAction && ((CommandAction) data).isAction(PRINT_REPORT)) {
            doRun = ((CommandAction) data).getProperty("spreport") != null;
        }
        if (doRun) {
            runReport(cmdAction);
        } else {
            printReport((CommandAction) data);
        }
    } else if (cmdAction.isAction(REFRESH)) {
        refreshCommands();

    } else if (cmdAction.isAction(IMPORT)) {
        importReport();

    } else if (cmdAction.isAction(PRINT_GRID)) {
        printGrid(cmdAction);

    } else if (cmdAction.isAction(DELETE_CMD_ACT)) {
        RecordSetIFace recordSet = null;
        if (cmdAction.getData() instanceof RecordSetIFace) {
            recordSet = (RecordSetIFace) cmdAction.getData();

        } else if (cmdAction.getData() instanceof RolloverCommand) {
            RolloverCommand roc = (RolloverCommand) cmdAction.getData();
            if (roc.getData() instanceof RecordSetIFace) {
                recordSet = (RecordSetIFace) roc.getData();
            }
        }
        if (recordSet != null || cmdAction.getProperties().get("name") != null) {
            String theName;
            String theTitle;
            if (recordSet != null) {
                theName = recordSet.getName();
                theTitle = theName;
            } else {
                theName = cmdAction.getProperties().getProperty("name");
                //currently the description of the appResource is used as the 'title' for the command button.
                //theTitle = ((AppResourceIFace)cmdAction.getProperties().get("appresource")).getDescription();
                theTitle = cmdAction.getProperties().getProperty("title");
            }
            int option = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(),
                    String.format(UIRegistry.getResourceString("REP_CONFIRM_DELETE"), theName),
                    UIRegistry.getResourceString("REP_CONFIRM_DELETE_TITLE"), JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION); // I18N

            if (option == JOptionPane.YES_OPTION) {
                Integer resId = Integer.class.cast(cmdAction.getProperty("spappresourceid"));
                Integer resOrRepId = null;
                Integer repId = null;
                if (resId != null) {
                    resOrRepId = resId;
                }
                RecordSetItemIFace item = recordSet == null ? null : recordSet.getOnlyItem();
                if (item != null) {
                    repId = item.getRecordId();
                    resOrRepId = repId;
                }
                deleteReportAndResource(repId, resId);
                deleteReportFromUI(theTitle);
                if (resOrRepId != null) {
                    CommandDispatcher.dispatch(new CommandAction(REPORTS, REPORT_DELETED, resOrRepId));
                } else {
                    //what can you do?
                }
            }
        }
    }
}

From source file:pi.bestdeal.gui.InterfacePrincipale.java

private void Display_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Display_ButtonActionPerformed
    DealDAO dealdao = DealDAO.getInstance();
    PanelAffichage panneauAffichage = new PanelAffichage();
    Affichage affichage = new Affichage();
    Deal abc = new Deal();
    Deal deal = new Deal();
    int idd = (int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0);
    List<Deal> listdeal = dealdao.displayDealById(idd);
    for (Deal a : listdeal) {
        abc = a;//from  ww  w .jav  a  2  s .  c  om
    }

    affichage.txtTitre.setText(abc.getTitreDeal_Deal());
    affichage.txtDesc.setText(abc.getDescDeal_Deal());
    affichage.txtPrix.setText(abc.getPrixDeal_Deal().toString());
    affichage.txtValidation.setText(String.valueOf(abc.getNbrAchatValidation()));
    affichage.jdateDebut.setDate(abc.getDateDebutDeal_Deal());
    affichage.jdateFin.setDate(abc.getDateFinDeal_Deal());
    affichage.txtVendeurAffichage.setText(null);
    if (abc.isStatutDeal() == true) {
        affichage.txtStatutAffichage.setText("Deal Confirm");
    } else {
        affichage.txtStatutAffichage.setText("Deal non Confirm");
    }
    Vendeur vendeur = new Vendeur();
    VendeurDAO daov = VendeurDAO.getInstance();
    int idv = (int) jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0);
    affichage.txtVendeurAffichage.setText(daov.displayvendeurByID(idv).getNomCommercial());
    affichage.txtEtat.setText(abc.getEtatDeal_Deal());
    affichage.txtCategorie.setText(abc.getCategorie_Deal());
    affichage.txtAffichage.setText(String.valueOf(abc.getNbrAffichage_Deal()));
    affichage.txtAchatActuel.setText(String.valueOf(abc.getNbrAchatActuelDeal_Deal()));
    ImageDeal img = new ImageDeal();

    ImageDAO im = new ImageDAO();
    Deal dea = new Deal();

    System.out.println(x);
    System.out.println(jTable1.getSelectedRow());
    affichage.a = idd;

    if (im.DisplayAllImage(idd).size() > 0) {
        img = im.DisplayAllImage(idd).get(0);
        ImageIcon icon = new ImageIcon(img.getImage());

        affichage.jLabel8.setIcon(icon);

    } else {
        System.out.println("aucune image trouve");
        affichage.jLabel8.setText("aucune image trouve");
    }

    JOptionPane.showMessageDialog(null, affichage, "Affichage", JOptionPane.YES_OPTION);

}

From source file:userinterface.Citizen.CitizenWorkAreaJPanel.java

private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
    int selectedRow = vitalSigntable.getSelectedRow();
    if (selectedRow >= 0) {
        int dialogButton = JOptionPane.YES_NO_OPTION;
        int dialogResult = JOptionPane.showConfirmDialog(null, "Would you like to delete Vital Sign?",
                "Warning", dialogButton);
        if (dialogResult == JOptionPane.YES_OPTION) {
            VitalSign vs = (VitalSign) vitalSigntable.getValueAt(selectedRow, 0);
            account.getCitizen().getHealthReport().deleteVitalSign(vs);
            populateTable();/*from   w  w  w . ja  va  2s . c  om*/
            resetfields();

        }
    } else {
        JOptionPane.showMessageDialog(null, "Please select a row from the table first", "Warning",
                JOptionPane.WARNING_MESSAGE);
    }
}