Example usage for javax.swing JOptionPane YES_NO_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_CANCEL_OPTION

Introduction

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

Prototype

int YES_NO_CANCEL_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:net.atomique.ksar.ui.GraphView.java

private String askSaveFilename(String title, File chdirto) {
    String filename = null;// ww w. j  av a 2  s  . co m
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(title);
    if (chdirto != null) {
        chooser.setCurrentDirectory(chdirto);
    }
    int returnVal = chooser.showSaveDialog(GlobalOptions.getUI());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        filename = chooser.getSelectedFile().getAbsolutePath();
    }

    if (filename == null) {
        return null;
    }

    if (new File(filename).exists()) {
        String[] choix = { "Yes", "No" };
        int resultat = JOptionPane.showOptionDialog(null, "Overwrite " + filename + " ?", "File Exist",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choix, choix[1]);
        if (resultat != 0) {
            return null;
        }
    }
    return filename;
}

From source file:net.sf.jabref.external.AutoSetExternalFileForEntries.java

@Override
public void run() {
    if (!goOn) {/*  ww  w  . j a  v a 2s .  c  o m*/
        panel.output(Localization.lang("No entries selected."));
        return;
    }
    panel.frame().setProgressBarValue(0);
    panel.frame().setProgressBarVisible(true);
    int weightAutoSet = 10; // autoSet takes 10 (?) times longer than checkExisting
    int progressBarMax = (autoSet ? weightAutoSet * sel.length : 0) + (checkExisting ? sel.length : 0);
    panel.frame().setProgressBarMaximum(progressBarMax);
    int progress = 0;
    entriesChanged = 0;
    int brokenLinks = 0;
    NamedCompound ce = new NamedCompound(Localization.lang("Autoset %0 field", fieldName));

    final OpenFileFilter off = Util.getFileFilterForField(fieldName);

    ExternalFilePanel extPan = new ExternalFilePanel(fieldName, panel.metaData(), null, null, off);
    TextField editor = new TextField(fieldName, "", false);

    // Find the default directory for this field type:
    String[] dirs = panel.metaData().getFileDirectory(fieldName);

    // First we try to autoset fields
    if (autoSet) {
        for (BibtexEntry aSel : sel) {
            progress += weightAutoSet;
            panel.frame().setProgressBarValue(progress);

            final String old = aSel.getField(fieldName);
            // Check if a extension is already set, and if so, if we are allowed to overwrite it:
            if (old != null && !old.equals("") && !overWriteAllowed) {
                continue;
            }
            extPan.setEntry(aSel, panel.getDatabase());
            editor.setText(old != null ? old : "");
            JabRefExecutorService.INSTANCE.executeAndWait(extPan.autoSetFile(fieldName, editor));
            // If something was found, entriesChanged it:
            if (!editor.getText().equals("") && !editor.getText().equals(old)) {
                // Store an undo edit:
                //System.out.println("Setting: "+sel[i].getCiteKey()+" "+editor.getText());
                ce.addEdit(new UndoableFieldChange(aSel, fieldName, old, editor.getText()));
                aSel.setField(fieldName, editor.getText());
                entriesChanged++;
            }
        }
    }
    //System.out.println("Done setting");
    // The following loop checks all external links that are already set.
    if (checkExisting) {
        mainLoop: for (BibtexEntry aSel : sel) {
            panel.frame().setProgressBarValue(progress++);
            final String old = aSel.getField(fieldName);
            // Check if a extension is set:
            if (old != null && !old.equals("")) {
                // Get an absolute path representation:
                File file = FileUtil.expandFilename(old, dirs);

                if (file == null || !file.exists()) {

                    int answer = JOptionPane.showOptionDialog(panel.frame(),
                            Localization.lang("<HTML>Could not find file '%0'<BR>linked from entry '%1'</HTML>",
                                    new String[] { old, aSel.getCiteKey() }),
                            Localization.lang("Broken link"), JOptionPane.YES_NO_CANCEL_OPTION,
                            JOptionPane.QUESTION_MESSAGE, null, brokenLinkOptions, brokenLinkOptions[0]);
                    switch (answer) {
                    case 1:
                        // Assign new file.
                        AttachFileDialog afd = new AttachFileDialog(panel.frame(), panel.metaData(), aSel,
                                fieldName);
                        Util.placeDialog(afd, panel.frame());
                        afd.setVisible(true);
                        if (!afd.cancelled()) {
                            ce.addEdit(new UndoableFieldChange(aSel, fieldName, old, afd.getValue()));
                            aSel.setField(fieldName, afd.getValue());
                            entriesChanged++;
                        }
                        break;
                    case 2:
                        // Clear field
                        ce.addEdit(new UndoableFieldChange(aSel, fieldName, old, null));
                        aSel.setField(fieldName, null);
                        entriesChanged++;
                        break;
                    case 3:
                        // Cancel
                        break mainLoop;
                    }
                    brokenLinks++;
                }

            }
        }
    }

    //log brokenLinks if some were found
    if (brokenLinks > 0) {
        log.warn(Localization.lang("Found %0 broken links", brokenLinks + ""));
    }

    if (entriesChanged > 0) {
        // Add the undo edit:
        ce.end();
        panel.undoManager.addEdit(ce);
    }
}

From source file:VoteDialog.java

private JPanel createSimpleDialogBox() {
    final int numButtons = 4;
    JRadioButton[] radioButtons = new JRadioButton[numButtons];

    final ButtonGroup group = new ButtonGroup();

    JButton voteButton = null;// w w  w .j a va 2 s  . c o  m

    final String defaultMessageCommand = "default";
    final String yesNoCommand = "yesno";
    final String yeahNahCommand = "yeahnah";
    final String yncCommand = "ync";

    radioButtons[0] = new JRadioButton("<html>Candidate 1: <font color=red>Sparky the Dog</font></html>");
    radioButtons[0].setActionCommand(defaultMessageCommand);

    radioButtons[1] = new JRadioButton("<html>Candidate 2: <font color=green>Shady Sadie</font></html>");
    radioButtons[1].setActionCommand(yesNoCommand);

    radioButtons[2] = new JRadioButton("<html>Candidate 3: <font color=blue>R.I.P. McDaniels</font></html>");
    radioButtons[2].setActionCommand(yeahNahCommand);

    radioButtons[3] = new JRadioButton(
            "<html>Candidate 4: <font color=maroon>Duke the Java<font size=-2><sup>TM</sup></font size> Platform Mascot</font></html>");
    radioButtons[3].setActionCommand(yncCommand);

    for (int i = 0; i < numButtons; i++) {
        group.add(radioButtons[i]);
    }
    // Select the first button by default.
    radioButtons[0].setSelected(true);

    voteButton = new JButton("Vote");

    voteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String command = group.getSelection().getActionCommand();

            // ok dialog
            if (command == defaultMessageCommand) {
                JOptionPane.showMessageDialog(frame, "This candidate is a dog. Invalid vote.");

                // yes/no dialog
            } else if (command == yesNoCommand) {
                int n = JOptionPane.showConfirmDialog(frame,
                        "This candidate is a convicted felon. \nDo you still want to vote for her?",
                        "A Follow-up Question", JOptionPane.YES_NO_OPTION);
                if (n == JOptionPane.YES_OPTION) {
                    setLabel("OK. Keep an eye on your wallet.");
                } else if (n == JOptionPane.NO_OPTION) {
                    setLabel("Whew! Good choice.");
                } else {
                    setLabel("It is your civic duty to cast your vote.");
                }

                // yes/no (with customized wording)
            } else if (command == yeahNahCommand) {
                Object[] options = { "Yes, please", "No, thanks" };
                int n = JOptionPane.showOptionDialog(frame,
                        "This candidate is deceased. \nDo you still want to vote for him?",
                        "A Follow-up Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                        options, options[0]);
                if (n == JOptionPane.YES_OPTION) {
                    setLabel("I hope you don't expect much from your candidate.");
                } else if (n == JOptionPane.NO_OPTION) {
                    setLabel("Whew! Good choice.");
                } else {
                    setLabel("It is your civic duty to cast your vote.");
                }

                // yes/no/cancel (with customized wording)
            } else if (command == yncCommand) {
                Object[] options = { "Yes!", "No, I'll pass", "Well, if I must" };
                int n = JOptionPane.showOptionDialog(frame,
                        "Duke is a cartoon mascot. \nDo you  " + "still want to cast your vote?",
                        "A Follow-up Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
                        null, options, options[2]);
                if (n == JOptionPane.YES_OPTION) {
                    setLabel("Excellent choice.");
                } else if (n == JOptionPane.NO_OPTION) {
                    setLabel("Whatever you say. It's your vote.");
                } else if (n == JOptionPane.CANCEL_OPTION) {
                    setLabel("Well, I'm certainly not going to make you vote.");
                } else {
                    setLabel("It is your civic duty to cast your vote.");
                }
            }
            return;
        }
    });
    System.out.println("calling createPane");
    return createPane(simpleDialogDesc + ":", radioButtons, voteButton);
}

From source file:fi.smaa.jsmaa.gui.JSMAAMainFrame.java

private boolean checkSaveCurrentModel() {
    if (!modelManager.getSaved()) {
        int conf = JOptionPane.showConfirmDialog(this, "Current model not saved. Do you want do save changes?",
                "Save changed", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
                ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_STOP));
        if (conf == JOptionPane.CANCEL_OPTION) {
            return false;
        } else if (conf == JOptionPane.YES_OPTION) {
            if (!save()) {
                return false;
            }//from   ww w  .  j  a v a  2s.  c o  m
        }
    }
    return true;
}

From source file:GUI.ListOfOffres1.java

private static WebPanel createOffresPanel(final String url, final String title, String body, final int id,
        final int myId) throws IOException {

    final WebPanel offresPanel = new WebPanel(true);
    offresPanel.setPaintFocus(false);//  ww  w. j a va  2s . co m
    WebLookAndFeel.install();
    WebLookAndFeel.setDecorateAllWindows(true);
    offresPanel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            // Opening dialog
            Icon blueIcon = new ImageIcon("yourFile.gif");
            Object stringArray[] = { "Ovrir", "No" };
            int returnValue = JOptionPane.showOptionDialog(offresPanel, "Ouvrir Offre?",
                    "Vous voulez ouvrir une offre", JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray, stringArray[0]);
            switch (returnValue) {
            //                            case 0 :
            //                                openPleaseWait();
            //                                try {
            //                                    System.out.print("tehe id is :"+id);
            //                                    new OffreDAO().deleteOffre(id);
            //                                    openListOfOffresFrameagn(0,"");
            //                                } catch (IOException ex) {
            //                                    Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex);
            //                                }
            case 0:
                System.out.println("The return value" + returnValue);

                try {
                    //openPleaseWait();
                    new OneOffre().openListOfOffresFrameagn(id, myId);
                } catch (IOException ex) {
                    Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
            System.out.println("The return value" + returnValue);
            WebLookAndFeel.setDecorateDialogs(true);
        }
    });

    final WebPanel descPanel = new WebPanel(false);

    descPanel.add();
    descPanel.setOpaque(true);
    WebLabel descLabel = new WebLabel("<html>\n" + "<body>\n" + "\n" + "<h2>" + title + "</h2>\n" + "\n" + "<p>"
            + body + "</p>\n" + "\n" + "</body>\n" + "</html>");

    descPanel.add(descLabel);
    offresPanel.setPaintFocus(true);
    offresPanel.setMargin(10);
    // load the image once
    try {
        BufferedImage bi = ImageIO.read(new URL(url));
        ImageIcon img = new ImageIcon(bi);
        WebDecoratedImage img2 = new WebDecoratedImage(img);
        img2.setShadeWidth(0);
        offresPanel.add(img2);
        offresPanel.setPreferredSize(new Dimension(300, 400));
        GridLayout layoutPffresPanel = new GridLayout(2, 1);
        offresPanel.setLayout(layoutPffresPanel);
        offresPanel.add(descPanel);
    } catch (IOException e) {
        //or open no image found image
        BufferedImage image = ImageIO.read(new File("resources/no-image-found.jpg"));
        ImageIcon i1 = new ImageIcon(image);
        WebDecoratedImage img2 = new WebDecoratedImage(i1);
        img2.setShadeWidth(0);
        offresPanel.add(img2);
        offresPanel.setPreferredSize(new Dimension(300, 400));
        GridLayout layoutPffresPanel = new GridLayout(2, 1);
        offresPanel.setLayout(layoutPffresPanel);
        offresPanel.add(descPanel);
    }
    return offresPanel;
}

From source file:com.seanmadden.net.fast.FastInterpretype.java

public void clearWindows() {
    boolean windowCleared = false;
    int selected = JOptionPane.showConfirmDialog(null,
            "Would you like to save the current conversation before clearing?", "Save before clearing?",
            JOptionPane.YES_NO_CANCEL_OPTION);
    if (selected == JOptionPane.YES_OPTION) {
        windowCleared = saveLogToFile();
    } else if (selected == JOptionPane.NO_OPTION) {
        windowCleared = true;/* w  ww  .  j  a  v  a  2s . c o  m*/
    }

    if (windowCleared) {
        si.sendRawDataToPort(DataPacket.generateClearConvoPayload());
        mw.clearWindow();
        String username = JOptionPane.showInputDialog("What is your name?");
        si.sendRawDataToPort(DataPacket.generateSignedOnPayload(username));
        mw.acceptText(username + " (you) has signed on.\n");
        mw.setLocalUserName(username);
    }
}

From source file:net.sf.jabref.gui.desktop.JabRefDesktop.java

public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry,
        BibDatabaseContext databaseContext, String link, UnknownExternalFileType fileType) throws IOException {

    String cancelMessage = Localization.lang("Unable to open file.");
    String[] options = new String[] { Localization.lang("Define '%0'", fileType.getName()),
            Localization.lang("Change file type"), Localization.lang("Cancel") };
    String defOption = options[0];
    int answer = JOptionPane.showOptionDialog(frame,
            Localization.lang(/*from w  w  w.ja va  2  s .c om*/
                    "This external link is of the type '%0', which is undefined. What do you want to do?",
                    fileType.getName()),
            Localization.lang("Undefined file type"), JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, defOption);
    if (answer == JOptionPane.CANCEL_OPTION) {
        frame.output(cancelMessage);
        return false;
    } else if (answer == JOptionPane.YES_OPTION) {
        // User wants to define the new file type. Show the dialog:
        ExternalFileType newType = new ExternalFileType(fileType.getName(), "", "", "", "new",
                IconTheme.JabRefIcon.FILE.getSmallIcon());
        ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor(frame, newType);
        editor.setVisible(true);
        if (editor.okPressed()) {
            // Get the old list of types, add this one, and update the list in prefs:
            List<ExternalFileType> fileTypes = new ArrayList<>(
                    ExternalFileTypes.getInstance().getExternalFileTypeSelection());
            fileTypes.add(newType);
            Collections.sort(fileTypes);
            ExternalFileTypes.getInstance().setExternalFileTypes(fileTypes);
            // Finally, open the file:
            return openExternalFileAnyFormat(databaseContext, link, Optional.of(newType));
        } else {
            // Canceled:
            frame.output(cancelMessage);
            return false;
        }
    } else {
        // User wants to change the type of this link.
        // First get a model of all file links for this entry:
        FileListTableModel tModel = new FileListTableModel();
        Optional<String> oldValue = entry.getFieldOptional(FieldName.FILE);
        oldValue.ifPresent(tModel::setContent);
        FileListEntry flEntry = null;
        // Then find which one we are looking at:
        for (int i = 0; i < tModel.getRowCount(); i++) {
            FileListEntry iEntry = tModel.getEntry(i);
            if (iEntry.link.equals(link)) {
                flEntry = iEntry;
                break;
            }
        }
        if (flEntry == null) {
            // This shouldn't happen, so I'm not sure what to put in here:
            throw new RuntimeException("Could not find the file list entry " + link + " in " + entry);
        }

        FileListEntryEditor editor = new FileListEntryEditor(frame, flEntry, false, true, databaseContext);
        editor.setVisible(true, false);
        if (editor.okPressed()) {
            // Store the changes and add an undo edit:
            String newValue = tModel.getStringRepresentation();
            UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE, oldValue.orElse(null),
                    newValue);
            entry.setField(FieldName.FILE, newValue);
            frame.getCurrentBasePanel().getUndoManager().addEdit(ce);
            frame.getCurrentBasePanel().markBaseChanged();
            // Finally, open the link:
            return openExternalFileAnyFormat(databaseContext, flEntry.link, flEntry.type);
        } else {
            // Canceled:
            frame.output(cancelMessage);
            return false;
        }
    }
}

From source file:es.emergya.ui.plugins.admin.AdminSquads.java

protected SummaryAction getSummaryAction(final Patrulla p) {
    SummaryAction action = new SummaryAction(p) {

        private static final long serialVersionUID = -8344125339845145826L;

        @Override/*from  w w  w  .j a  va  2  s.  com*/
        protected JFrame getSummaryDialog() {
            final String label_cabecera = "Nombre Patrulla:";
            final String label_pie = "Info Adicional:";
            final String centered_label = "Recursos:";
            final String left_label = "Recursos disponibles";
            final String right_label = "Recursos asignados";
            final String titulo, cabecera;
            if (isNew) {
                titulo = i18n.getString("Squads.barraTitulo.nuevo");
                cabecera = i18n.getString("Squads.cabecera.nuevo");

            } else {
                titulo = i18n.getString("Squads.barraTitulo.existente");
                cabecera = i18n.getString("Squads.cabecera.existente");
            }
            final Recurso[] left_items = RecursoConsultas.getNotAsigned(p);
            for (Recurso r : left_items)
                r.setTipoToString(Recurso.TIPO_TOSTRING.PATRULLA);
            final Recurso[] right_items = RecursoConsultas.getAsigned(p);
            for (Recurso r : right_items)
                r.setTipoToString(Recurso.TIPO_TOSTRING.PATRULLA);
            final AdminPanel.SaveOrUpdateAction<Patrulla> guardar = squads.new SaveOrUpdateAction<Patrulla>(p) {

                private static final long serialVersionUID = 7447770296943341404L;

                @Override
                public void actionPerformed(ActionEvent e) {

                    if (isNew && PatrullaConsultas.alreadyExists(textfieldCabecera.getText())) {
                        JOptionPane.showMessageDialog(super.frame, "Ya existe una patrulla con ese nombre.");
                    } else if (textfieldCabecera.getText().isEmpty()) {
                        JOptionPane.showMessageDialog(super.frame, "El nombre es obligatorio.");
                    } else if (cambios) {
                        int i = JOptionPane.showConfirmDialog(super.frame, "Desea guardar los cambios?",
                                "Guardar", JOptionPane.YES_NO_CANCEL_OPTION);

                        if (i == JOptionPane.YES_OPTION) {

                            if (original == null) {
                                original = new Patrulla();
                            }

                            original.setInfoAdicional(textfieldPie.getText());
                            original.setNombre(textfieldCabecera.getText());

                            HashSet<Recurso> recursos = new HashSet<Recurso>();
                            for (Object r : ((DefaultListModel) right.getModel()).toArray()) {
                                if (r instanceof Recurso) {
                                    recursos.add((Recurso) r);
                                    ((Recurso) r).setPatrullas(original);
                                } else {
                                    log.error("El objeto no era un recurso");
                                }
                            }
                            original.setRecursos(recursos);

                            PatrullaAdmin.saveOrUpdate(original);
                            PluginEventHandler.fireChange(AdminSquads.this);

                            cambios = false;
                            original = null;

                            squads.setTableData(getAll(new Patrulla()));

                            closeFrame();
                        } else if (i == JOptionPane.NO_OPTION) {
                            closeFrame();
                        }
                    } else {
                        closeFrame();
                    }
                }
            };

            // if (d == null)
            d = generateIconDialog(label_cabecera, label_pie, centered_label, titulo, left_items, right_items,
                    left_label, right_label, guardar, LogicConstants.getIcon("tittleficha_icon_patrulla"),
                    cabecera, null);

            if (p != null) {
                textfieldCabecera.setText(p.getNombre());
                textfieldPie.setText(p.getInfoAdicional());
                textfieldCabecera.setEditable(false);
            } else {
                textfieldCabecera.setText("");
                textfieldPie.setText("");
            }
            cambios = false;

            return d;
        }
    };

    return action;
}

From source file:es.emergya.ui.plugins.admin.AdminRoles.java

protected SummaryAction getSummaryAction(final Rol r) {
    SummaryAction action = new SummaryAction(r) {

        private static final long serialVersionUID = -601099799668196685L;

        @Override//  ww w.  j  a  v  a2s .  c om
        protected JFrame getSummaryDialog() {
            final String titulo;
            final String cabecera;
            if (isNew) {
                titulo = i18n.getString("admin.roles.tituloVentana.nuevo"); //$NON-NLS-1$
                cabecera = i18n.getString("admin.roles.cabecera.nuevo");//$NON-NLS-1$
            } else {
                titulo = i18n.getString("admin.roles.tituloVentana.existente"); //$NON-NLS-1$
                cabecera = i18n.getString("admin.roles.cabecera.existente");//$NON-NLS-1$
            }
            final String label_cabecera = i18n.getString("admin.roles7"); //$NON-NLS-1$
            final String label_pie = i18n.getString("admin.roles8"); //$NON-NLS-1$
            final String centered_label = i18n.getString("admin.roles9"); //$NON-NLS-1$
            final String left_label = i18n.getString("admin.roles10"); //$NON-NLS-1$
            final String right_label = i18n.getString("admin.roles11"); //$NON-NLS-1$

            final Flota[] left_items = RolConsultas.getDisponibles(r);
            final Flota[] right_items = RolConsultas.getAsigned(r);
            final AdminPanel.SaveOrUpdateAction<Rol> guardar = roles.new SaveOrUpdateAction<Rol>(r) {

                private static final long serialVersionUID = 7447770196943361404L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (textfieldCabecera.getText().trim().isEmpty()) {
                        JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.roles13")); //$NON-NLS-1$
                    } else if (isNew && RolConsultas.alreadyExists(textfieldCabecera.getText().trim())) {
                        JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.roles14")); //$NON-NLS-1$
                    } else if (textfieldCabecera.getText().isEmpty()) {
                        JOptionPane.showMessageDialog(super.frame, i18n.getString("admin.roles15")); //$NON-NLS-1$
                    } else if (cambios) {
                        int i = JOptionPane.showConfirmDialog(super.frame, i18n.getString("admin.roles16"), //$NON-NLS-1$
                                i18n.getString("admin.roles17"), //$NON-NLS-1$
                                JOptionPane.YES_NO_CANCEL_OPTION);

                        if (i == JOptionPane.YES_OPTION) {

                            if (original == null) {
                                original = new Rol();
                            }

                            original.setInfoAdicional(textfieldPie.getText());
                            original.setNombre(textfieldCabecera.getText());

                            HashSet<Flota> flotas = new HashSet<Flota>();
                            for (Object r : ((DefaultListModel) right.getModel()).toArray()) {
                                if (r instanceof Flota) {
                                    flotas.add((Flota) r);
                                } else {
                                    log.error(i18n.getString("admin.roles18")); //$NON-NLS-1$
                                }
                            }
                            original.setFlotas(flotas);

                            RolAdmin.saveOrUpdate(original);
                            PluginEventHandler.fireChange(AdminRoles.this);

                            cambios = false;
                            original = null;

                            roles.setTableData(getAll(new Rol()));

                            closeFrame();
                        } else if (i == JOptionPane.NO_OPTION) {
                            closeFrame();
                        }
                    } else {
                        closeFrame();
                    }
                }
            };

            d = generateIconDialog(label_cabecera, label_pie, centered_label, titulo, left_items, right_items,
                    left_label, right_label, guardar, LogicConstants.getIcon(i18n.getString("admin.roles19")),
                    cabecera, null); //$NON-NLS-1$ //$NON-NLS-2$

            if (r != null) {
                textfieldCabecera.setText(r.getNombre());
                // textfieldCabecera.setEnabled(false);
                textfieldCabecera.setEditable(false);
                textfieldPie.setText(r.getInfoAdicional());
            } else {
                textfieldCabecera.setText(""); //$NON-NLS-1$
                textfieldCabecera.setEnabled(true);
                textfieldPie.setText(""); //$NON-NLS-1$
            }
            cambios = false;

            return d;
        }
    };

    return action;
}

From source file:components.DialogDemo.java

/** Creates the panel shown by the first tab. */
private JPanel createSimpleDialogBox() {
    final int numButtons = 4;
    JRadioButton[] radioButtons = new JRadioButton[numButtons];
    final ButtonGroup group = new ButtonGroup();

    JButton showItButton = null;//from  w ww  .j a  v a 2  s  . c o  m

    final String defaultMessageCommand = "default";
    final String yesNoCommand = "yesno";
    final String yeahNahCommand = "yeahnah";
    final String yncCommand = "ync";

    radioButtons[0] = new JRadioButton("OK (in the L&F's words)");
    radioButtons[0].setActionCommand(defaultMessageCommand);

    radioButtons[1] = new JRadioButton("Yes/No (in the L&F's words)");
    radioButtons[1].setActionCommand(yesNoCommand);

    radioButtons[2] = new JRadioButton("Yes/No " + "(in the programmer's words)");
    radioButtons[2].setActionCommand(yeahNahCommand);

    radioButtons[3] = new JRadioButton("Yes/No/Cancel " + "(in the programmer's words)");
    radioButtons[3].setActionCommand(yncCommand);

    for (int i = 0; i < numButtons; i++) {
        group.add(radioButtons[i]);
    }
    radioButtons[0].setSelected(true);

    showItButton = new JButton("Show it!");
    showItButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String command = group.getSelection().getActionCommand();

            //ok dialog
            if (command == defaultMessageCommand) {
                JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.");

                //yes/no dialog
            } else if (command == yesNoCommand) {
                int n = JOptionPane.showConfirmDialog(frame, "Would you like green eggs and ham?",
                        "An Inane Question", JOptionPane.YES_NO_OPTION);
                if (n == JOptionPane.YES_OPTION) {
                    setLabel("Ewww!");
                } else if (n == JOptionPane.NO_OPTION) {
                    setLabel("Me neither!");
                } else {
                    setLabel("Come on -- tell me!");
                }

                //yes/no (not in those words)
            } else if (command == yeahNahCommand) {
                Object[] options = { "Yes, please", "No way!" };
                int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?",
                        "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                        options, options[0]);
                if (n == JOptionPane.YES_OPTION) {
                    setLabel("You're kidding!");
                } else if (n == JOptionPane.NO_OPTION) {
                    setLabel("I don't like them, either.");
                } else {
                    setLabel("Come on -- 'fess up!");
                }

                //yes/no/cancel (not in those words)
            } else if (command == yncCommand) {
                Object[] options = { "Yes, please", "No, thanks", "No eggs, no ham!" };
                int n = JOptionPane.showOptionDialog(frame,
                        "Would you like some green eggs to go " + "with that ham?", "A Silly Question",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                        options[2]);
                if (n == JOptionPane.YES_OPTION) {
                    setLabel("Here you go: green eggs and ham!");
                } else if (n == JOptionPane.NO_OPTION) {
                    setLabel("OK, just the ham, then.");
                } else if (n == JOptionPane.CANCEL_OPTION) {
                    setLabel("Well, I'm certainly not going to eat them!");
                } else {
                    setLabel("Please tell me what you want!");
                }
            }
            return;
        }
    });

    return createPane(simpleDialogDesc + ":", radioButtons, showItButton);
}