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:org.syncany.plugins.php.PhpTransferManager.java

@SuppressWarnings("deprecation")
private CloseableHttpClient getHttpClient() {
    try {//from w w  w.  ja  va  2 s .co m
        @SuppressWarnings("deprecation")
        SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                if (lastSite != null && !lastSite.equals("")) {
                    Preferences prefs = Preferences.userRoot().node(this.getClass().getName());
                    int prevr = prefs.getInt(lastSite, -1);
                    if (prevr == -1) {
                        int r = JOptionPane.showConfirmDialog(null,
                                lastSite + "'s SSL certificate is not trusted, do you want to accept it?",
                                "Accept SSL Certificate?", JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        logger.warning(lastSite + " not trusted, user answered " + r);
                        prevr = r;
                        prefs.putInt(lastSite, r);
                    }
                    logger.warning(lastSite + " not trusted, registered user answer: " + prevr);
                    if (prevr == 0) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        });
        @SuppressWarnings("deprecation")
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("https", 443, sf));
        @SuppressWarnings("deprecation")
        ClientConnectionManager ccm = new ThreadSafeClientConnManager(registry);
        return new DefaultHttpClient(ccm);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

From source file:au.org.ala.delta.intkey.directives.invocation.UseDirectiveInvocation.java

private boolean checkCharacterUsable(au.org.ala.delta.model.Character ch, IntkeyContext context,
        boolean warnAlreadySetOrMaybeInapplicable) {
    CharacterFormatter formatter = new CharacterFormatter(true, CommentStrippingMode.RETAIN,
            AngleBracketHandlingMode.REPLACE, true, false);

    // is character fixed?
    if (context.charactersFixed()) {
        if (context.getFixedCharactersList().contains(ch.getCharacterId())) {
            if (!context.isProcessingDirectivesFile()) {
                String msg = UIUtils.getResourceString("UseDirective.CharacterFixed",
                        formatter.formatCharacterDescription(ch));
                String title = UIUtils.getResourceString("Intkey.informationDlgTitle");
                JOptionPane.showMessageDialog(UIUtils.getMainFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
            }//from w ww  . jav  a 2 s .  com
            return false;
        }
    }

    // is character already used?
    if (warnAlreadySetOrMaybeInapplicable) {
        if (context.getSpecimen().hasValueFor(ch)) {
            if (context.isProcessingDirectivesFile()) {
                return true;
            } else {
                String msg = UIUtils.getResourceString("UseDirective.CharacterAlreadyUsed",
                        formatter.formatCharacterDescription(ch));
                String title = UIUtils.getResourceString("Intkey.informationDlgTitle");
                int choice = JOptionPane.showConfirmDialog(UIUtils.getMainFrame(), msg, title,
                        JOptionPane.YES_NO_OPTION);
                if (choice == JOptionPane.YES_OPTION) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    }

    // is character maybe inapplicable?
    if (warnAlreadySetOrMaybeInapplicable) {
        if (context.getSpecimen().isCharacterMaybeInapplicable(ch)) {
            if (context.isProcessingDirectivesFile()) {
                return true;
            } else {
                String msg = UIUtils.getResourceString("UseDirective.CharacterMaybeInapplicable",
                        formatter.formatCharacterDescription(ch));
                String title = UIUtils.getResourceString("Intkey.informationDlgTitle");
                int choice = JOptionPane.showConfirmDialog(UIUtils.getMainFrame(), msg, title,
                        JOptionPane.YES_NO_OPTION);
                if (choice == JOptionPane.YES_OPTION) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    }

    // is character unavailable?
    if (context.getSpecimen().isCharacterInapplicable(ch)) {
        if (!context.isProcessingDirectivesFile()) {
            String msg = UIUtils.getResourceString("UseDirective.CharacterUnavailable",
                    formatter.formatCharacterDescription(ch));
            String title = UIUtils.getResourceString("Intkey.informationDlgTitle",
                    formatter.formatCharacterDescription(ch));
            JOptionPane.showMessageDialog(UIUtils.getMainFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
        }
        return false;
    }

    // is character excluded?
    if (!context.getIncludedCharacters().contains(ch)) {
        if (!context.isProcessingDirectivesFile()) {
            String msg = UIUtils.getResourceString("UseDirective.CharacterExcluded",
                    formatter.formatCharacterDescription(ch));
            String title = UIUtils.getResourceString("Intkey.informationDlgTitle",
                    formatter.formatCharacterDescription(ch));
            JOptionPane.showMessageDialog(UIUtils.getMainFrame(), msg, title, JOptionPane.ERROR_MESSAGE);
        }
        return false;
    }

    return true;
}

From source file:com.biosis.biosislite.vistas.inventario.MantenimientoClase.java

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
    // TODO add your handling code here:
    accion = AbstractControlador.ELIMINAR;
    if (tblclase.getSelectedRow() != -1) {

        Integer id = tblclase.getSelectedRow();

        //            Clase clase = claseControlador.buscarPorId(lista.get(id).getId());

        if (tblclase.getSelectedRow() != -1) {
            if (JOptionPane.showConfirmDialog(null, "Desea Eliminar la Clase?", "Mensaje del Sistema",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                //                    int[] filas = tblclase.getSelectedRows();
                //                    for (int i = 0; i < filas.length; i++) {
                //                        Clase clase2 = lista.get(filas[0]);
                claseControlador.setSeleccionado(lista.get(id));
                lista.remove(lista.get(id));
                claseControlador.accion(accion);
                //                    }
                if (claseControlador.accion(accion) == 3) {
                    JOptionPane.showMessageDialog(null, "Clase eliminada correctamente", "Mensaje del Sistema",
                            JOptionPane.INFORMATION_MESSAGE);

                } else {
                    JOptionPane.showMessageDialog(null, "Clase no eliminada", "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }/* w w  w  .ja  v  a  2  s.com*/
            } else {
                JOptionPane.showMessageDialog(null, "Clase no eliminada", "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } else {
        JOptionPane.showMessageDialog(null, "Debe seleccionar una clase", "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:edu.umass.cs.gnsserver.installer.EC2Runner.java

private static boolean showDialog(String message, final long timeout) {
    try {//from  w w w  .j av  a  2 s  . c  o m
        int dialog = JOptionPane.YES_NO_OPTION;
        JOptionPane optionPane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE,
                JOptionPane.YES_NO_OPTION);
        final JDialog dlg = optionPane.createDialog("Error");
        new Thread(new Runnable() {
            @Override
            public void run() {
                {
                    ThreadUtils.sleep(timeout);
                    dlg.dispose();
                }
            }
        }).start();
        dlg.setVisible(true);
        int value = ((Integer) optionPane.getValue()).intValue();
        if (value == JOptionPane.YES_OPTION) {
            return true;
        } else {
            return false;
        }
    } catch (RuntimeException e) {
        return true;
    }
}

From source file:de.juwimm.cms.content.panel.PanDocuments.java

private void btnDeleteActionPerformed(ActionEvent e) {
    try {/*w w w .j  a  v a  2  s.  c o m*/
        DocumentSlimValue currDoc = null;
        String acc = bgrp.getSelection().getActionCommand();
        int rowInModel = tblDocumentsModel.getRowForDocument(Integer.valueOf(acc));
        if (rowInModel >= 0) {
            currDoc = (DocumentSlimValue) tblDocumentsModel.getValueAt(rowInModel, 4);
        }
        String tmp = acc;
        if (currDoc != null && currDoc.getDocumentName() != null
                && !"".equalsIgnoreCase(currDoc.getDocumentName())) {
            tmp += " (" + currDoc.getDocumentName() + ")";
        }
        /*
        if (currDoc != null && (currDoc.getUseCountLastVersion() + currDoc.getUseCountPublishVersion()) > 0) {
           JOptionPane.showMessageDialog(this,
          SwingMessages.getString("panel.content.documents.deleteButInUse", tmp), 
          SwingMessages.getString("panel.content.documents.deleteDocument"), 
          JOptionPane.WARNING_MESSAGE);
           return;
        }
        */
        int ret = JOptionPane.showConfirmDialog(this,
                Messages.getString("panel.content.documents.deleteThisDocument", tmp),
                Messages.getString("panel.content.documents.deleteDocument"), JOptionPane.WARNING_MESSAGE,
                JOptionPane.YES_NO_OPTION);
        if (ret == JOptionPane.YES_OPTION) {
            comm.removeDocument(Integer.valueOf(acc).intValue());
            loadThumbs(((CboModel) this.cboRegion.getSelectedItem()).getRegionId());
        }
    } catch (NullPointerException ex) {
    } catch (Exception ex) {
        if (ex.getMessage().contains("validation exception")) {
            JOptionPane.showConfirmDialog(this, rb.getString("panel.content.documents.delete.exception"),
                    rb.getString("panel.content.documents.deleteDocument"), JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE);
        } else {
            log.warn("exception on delete document");
            if (log.isDebugEnabled()) {
                log.debug(ex);
            }
        }
    }
}

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

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
    // TODO add your handling code here:
    accion = Controlador.ELIMINAR;/*from   www .j  ava 2 s  .  co  m*/
    if (tblProveedor.getSelectedRow() != -1) {

        Integer codigo = tblProveedor.getSelectedRow();

        Proveedor proveedor = lista.get(codigo);

        if (proveedor != null) {
            if (JOptionPane.showConfirmDialog(null, "Desea Eliminar el Proveedor?", "Mensaje del Sistema",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                int[] filas = tblProveedor.getSelectedRows();
                for (int i = 0; i < filas.length; i++) {
                    Proveedor empleado2 = lista.get(filas[0]);
                    lista.remove(empleado2);
                    proveedorControlador.setSeleccionado(empleado2);
                    proveedorControlador.accion(accion);
                }
                if (proveedorControlador.accion(accion) == 3) {
                    JOptionPane.showMessageDialog(null, "Proveedor eliminado correctamente",
                            "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);

                } else {
                    JOptionPane.showMessageDialog(null, "Proveedor no eliminado", "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Proveedor no eliminado", "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } else {
        JOptionPane.showMessageDialog(null, "Debe seleccionar un Empleado", "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.proyecto.vista.MantenimientoPeriodo.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 + " la Periodo?", "Mensaje del Sistema",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

            periodoControlador.setearVigenteFalse();
            periodoControlador.getSeleccionado().setPeriodo(Integer.parseInt(periodoField.getText()));
            periodoControlador.getSeleccionado().setFechaCreacion(jDateFecha.getDate());
            periodoControlador.getSeleccionado().setVigente(chckVigente.isSelected());

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

            if (accion == 1) {
                JOptionPane.showMessageDialog(null, "Periodo " + palabra2 + " correctamente",
                        "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);
                FormularioUtil.limpiarComponente(panelDatos);
            } else {
                JOptionPane.showMessageDialog(null, "Periodo no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }/*w ww.jav  a2  s.  c  om*/
        } else {
            FormularioUtil.limpiarComponente(panelDatos);
            JOptionPane.showMessageDialog(null, "Periodo no " + palabra2, "Mensaje del Sistema",
                    JOptionPane.ERROR_MESSAGE);
        }
    } else if (accion == 2) {
        palabra = "modificar";
        palabra2 = "modificado";

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

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

                lista.clear();
                periodoControlador.getSeleccionado().setPeriodo(Integer.parseInt(periodoField.getText()));
                periodoControlador.getSeleccionado().setFechaCreacion(jDateFecha.getDate());
                periodoControlador.getSeleccionado().setVigente(chckVigente.isSelected());
                periodoControlador.accion(accion);
                listar();

                FormularioUtil.limpiarComponente(panelDatos);

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

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

From source file:com.jug.MotherMachine.java

/**
 *
 * @param guiFrame//from  ww  w . j  a  va 2  s .  c om
 *            parent frame
 * @param path
 *            path to be suggested to open
 * @return
 */
private File showStartupDialog(final JFrame guiFrame, final String path) {

    final String parentFolder = path.substring(0, path.lastIndexOf(File.separatorChar));

    int decision = 0;
    if (path.equals(System.getProperty("user.home"))) {
        decision = JOptionPane.NO_OPTION;
    } else {
        final String message = "Should the MotherMachine be opened with the data found in:\n" + path
                + "\n\nIn case you want to choose a folder please select 'No'...";
        final String title = "MotherMachine Start Dialog";
        decision = JOptionPane.showConfirmDialog(guiFrame, message, title, JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
    }
    if (decision == JOptionPane.YES_OPTION) {
        return new File(path);
    } else {
        return showFolderChooser(guiFrame, parentFolder);
    }
}

From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java

/**
 * Override the default removal so we can actually stop sharing
 * and delete the file./*w  w  w. j a va 2  s. c  om*/
 * Deletes the selected rows in the table.
 * CAUTION: THIS WILL DELETE THE FILE FROM THE DISK.
 */
public void removeSelection() {
    int[] rows = TABLE.getSelectedRows();
    if (rows.length == 0)
        return;

    if (TABLE.isEditing()) {
        TableCellEditor editor = TABLE.getCellEditor();
        editor.cancelCellEditing();
    }

    List<File> files = new ArrayList<File>(rows.length);

    // sort row indices and go backwards so list indices don't change when
    // removing the files from the model list
    Arrays.sort(rows);
    for (int i = rows.length - 1; i >= 0; i--) {
        File file = DATA_MODEL.getFile(rows[i]);
        files.add(file);
    }

    CheckBoxListPanel<File> listPanel = new CheckBoxListPanel<File>(files, new FileTextProvider(), true);
    listPanel.getList().setVisibleRowCount(4);

    // display list of files that should be deleted
    Object[] message = new Object[] { new MultiLineLabel(I18n.tr(
            "Are you sure you want to delete the selected file(s), thus removing it from your computer?"), 400),
            Box.createVerticalStrut(ButtonRow.BUTTON_SEP), listPanel,
            Box.createVerticalStrut(ButtonRow.BUTTON_SEP) };

    // get platform dependent options which are displayed as buttons in the dialog
    Object[] removeOptions = createRemoveOptions();

    int option = JOptionPane.showOptionDialog(MessageService.getParentComponent(), message, I18n.tr("Message"),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, removeOptions,
            removeOptions[0] /* default option */);

    if (option == removeOptions.length - 1 /* "cancel" option index */
            || option == JOptionPane.CLOSED_OPTION) {
        return;
    }

    // remove still selected files
    List<File> selected = listPanel.getSelectedElements();
    List<String> undeletedFileNames = new ArrayList<String>();

    for (File file : selected) {
        // stop seeding if seeding
        BittorrentDownload dm = null;
        if ((dm = TorrentUtil.getDownloadManager(file)) != null) {
            dm.setDeleteDataWhenRemove(false);
            dm.setDeleteTorrentWhenRemove(false);
            BTDownloadMediator.instance().remove(dm);
        }

        // close media player if still playing
        if (MediaPlayer.instance().isThisBeingPlayed(file)) {
            MediaPlayer.instance().stop();
            MPlayerMediator.instance().showPlayerWindow(false);
        }

        // removeOptions > 2 => OS offers trash options
        boolean removed = FileUtils.delete(file,
                removeOptions.length > 2 && option == 0 /* "move to trash" option index */);
        if (removed) {

            DATA_MODEL.remove(DATA_MODEL.getRow(file));
        } else {
            undeletedFileNames.add(getCompleteFileName(file));
        }
    }

    clearSelection();

    if (undeletedFileNames.isEmpty()) {
        return;
    }

    // display list of files that could not be deleted
    message = new Object[] { new MultiLineLabel(I18n.tr(
            "The following files could not be deleted. They may be in use by another application or are currently being downloaded to."),
            400), Box.createVerticalStrut(ButtonRow.BUTTON_SEP),
            new JScrollPane(createFileList(undeletedFileNames)) };

    JOptionPane.showMessageDialog(MessageService.getParentComponent(), message, I18n.tr("Error"),
            JOptionPane.ERROR_MESSAGE);

    super.removeSelection();
}

From source file:com.biosis.biosislite.vistas.inventario.MantenimientoFactura.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.nombreField, "Nombre"));
    FormularioUtil.validar2(array);//w w  w  . j av a2 s  .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 Tipo?", "Mensaje del Sistema",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                facturaControlador.getSeleccionado().setNumeroFactura(nombreField.getText());
                facturaControlador.getSeleccionado().setFecha(jDateFecha.getDate());
                facturaControlador.getSeleccionado().setRuta(facturaField.getText());

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

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

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

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

                    lista.clear();
                    facturaControlador.getSeleccionado().setNumeroFactura(nombreField.getText());
                    facturaControlador.getSeleccionado().setFecha(jDateFecha.getDate());
                    facturaControlador.getSeleccionado().setRuta(facturaField.getText());
                    facturaControlador.accion(accion);
                    listar();

                    FormularioUtil.limpiarComponente(panelDatos);

                } else {
                    JOptionPane.showMessageDialog(null, "Tipo no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                FormularioUtil.limpiarComponente(panelDatos);
                JOptionPane.showMessageDialog(null, "Tipo no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
        FormularioUtil.limpiarComponente(panelDatos);
        FormularioUtil.limpiarComponente(panelFoto);
        FormularioUtil.activarComponente(panelOpciones, true);
        FormularioUtil.activarComponente(panelGuardar, false);
        FormularioUtil.activarComponente(panelDatos, false);
        lblFactura.setIcon(null);
    }

}