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.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

public boolean promptSave(boolean force) {
    stopTableEditing();/*  w w w .  java2s . co  m*/
    int option;

    if (force) {
        option = JOptionPane.showConfirmDialog(parent,
                "You must save the code template changes before continuing. Would you like to save now?");
    } else {
        option = JOptionPane.showConfirmDialog(parent, "Would you like to save the code templates?");
    }

    if (option == JOptionPane.YES_OPTION) {
        CodeTemplateLibrarySaveResult updateSummary = doSaveCodeTemplates(false);

        if (updateSummary == null || updateSummary.isOverrideNeeded() || !updateSummary.isLibrariesSuccess()) {
            return false;
        } else {
            for (CodeTemplateUpdateResult result : updateSummary.getCodeTemplateResults().values()) {
                if (!result.isSuccess()) {
                    return false;
                }
            }
        }
    } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION
            || (option == JOptionPane.NO_OPTION && force)) {
        return false;
    }

    return true;
}

From source file:jatoo.app.App.java

/**
 * Displays a YES/NO question./* w w w . j a  v a2  s .co m*/
 * 
 * @param question
 *          the question to be displayed
 * 
 * @return <code>true</code> if YES was selected, <code>false</code> if NO was
 *         selected
 */
public boolean showQuestion(final String question) {
    return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(window, question, getTitle(),
            JOptionPane.YES_NO_OPTION);
}

From source file:com.xmage.launcher.XMageLauncher.java

@Override
public void run() {
    frame.setVisible(true);// w w w  .  java  2  s.c  o m
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (serverProcess != null) {
                int response = JOptionPane.showConfirmDialog(frame, messages.getString("serverRunning.message"),
                        messages.getString("serverRunning.title"), JOptionPane.YES_NO_OPTION);
                if (response == JOptionPane.YES_OPTION) {
                    Utilities.stopProcess(serverProcess);
                }
            }
            Config.saveProperties();
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (getConfig()) {
                path = Utilities.getInstallPath();
                textArea.append(messages.getString("folder") + path.getAbsolutePath() + "\n");

                DownloadLauncherTask launcher = new DownloadLauncherTask(progressBar);
                launcher.execute();
            }
        }
    });

}

From source file:com.floreantpos.main.SetUpWindow.java

public void actionPerformed(ActionEvent e) {
    try {/*from w w  w  . jav a 2  s.  c  om*/
        String command = e.getActionCommand();

        Database selectedDb = (Database) databaseCombo.getSelectedItem();

        final String providerName = selectedDb.getProviderName();
        final String databaseURL = tfServerAddress.getText();
        final String databasePort = tfServerPort.getText();
        final String databaseName = tfDatabaseName.getText();
        final String user = tfUserName.getText();
        final String pass = new String(tfPassword.getPassword());

        final String connectionString = selectedDb.getConnectString(databaseURL, databasePort, databaseName);
        final String hibernateDialect = selectedDb.getHibernateDialect();
        final String driverClass = selectedDb.getHibernateConnectionDriverClass();

        if (CANCEL.equalsIgnoreCase(command)) {
            System.exit(1);
            return;
        }

        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        if (TEST.equalsIgnoreCase(command)) {
            try {
                DatabaseUtil.checkConnection(connectionString, hibernateDialect, driverClass, user, pass);
            } catch (DatabaseConnectionException e1) {
                JOptionPane.showMessageDialog(this, Messages.getString("DatabaseConfigurationDialog.32")); //$NON-NLS-1$
                return;
            }
            connectionSuccess = true;
            JOptionPane.showMessageDialog(this, Messages.getString("DatabaseConfigurationDialog.31")); //$NON-NLS-1$
            return;
        }
        saveConfig(selectedDb, providerName, databaseURL, databasePort, databaseName, user, pass,
                connectionString, hibernateDialect);
        if (CREATE_SAMPLE_DATA.equals(command)) {
            DataImportAction
                    .importMenuItems(DatabaseUtil.class.getResourceAsStream("/floreantpos-menu-items.xml")); //$NON-NLS-1$
        } else if (CREATE_DATABASE.equals(command)) {
            int i = JOptionPane.showConfirmDialog(this, Messages.getString("DatabaseConfigurationDialog.33"), //$NON-NLS-1$
                    Messages.getString("DatabaseConfigurationDialog.34"), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$
            if (i != JOptionPane.YES_OPTION) {
                return;
            }

            i = JOptionPane.showConfirmDialog(this, Messages.getString("DatabaseConfigurationDialog.4"), //$NON-NLS-1$
                    Messages.getString("DatabaseConfigurationDialog.5"), JOptionPane.YES_NO_OPTION); //$NON-NLS-1$
            boolean generateSampleData = false;
            if (i == JOptionPane.YES_OPTION)
                generateSampleData = true;

            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            String createDbConnectString = selectedDb.getCreateDbConnectString(databaseURL, databasePort,
                    databaseName);
            boolean databaseCreated = DatabaseUtil.createDatabase(createDbConnectString, hibernateDialect,
                    driverClass, user, pass, generateSampleData);

            if (databaseCreated) {
                JOptionPane.showMessageDialog(SetUpWindow.this,
                        Messages.getString("DatabaseConfigurationDialog.6") + //$NON-NLS-1$
                                Messages.getString("DatabaseConfigurationDialog.7")); //$NON-NLS-1$
                connectionSuccess = true;
            } else {
                JOptionPane.showMessageDialog(SetUpWindow.this,
                        Messages.getString("DatabaseConfigurationDialog.36")); //$NON-NLS-1$
            }
        } else if (SAVE.equalsIgnoreCase(command)) {
            Integer terminalId = tfTerminalNumber.getInteger();
            Integer defaultPassLen = tfSecretKeyLength.getInteger();
            Integer autoLogOffTime = tfLogoffTime.getInteger();
            Boolean isLogOff = chkAutoLogoff.isSelected();
            Double scaleFactor = tfScaleFactor.getDouble();

            TerminalConfig.setTerminalId(terminalId);
            TerminalConfig.setDefaultPassLen(defaultPassLen);
            TerminalConfig.setScreenScaleFactor(scaleFactor);
            TerminalConfig.setAutoLogoffEnable(isLogOff);
            TerminalConfig.setAutoLogoffTime(autoLogOffTime <= 0 ? 10 : autoLogOffTime);
            try {
                DatabaseUtil.initialize();
                saveConfigData();
            } catch (Exception ex) {
                int i = JOptionPane.showConfirmDialog(this, "Connection Failed. Do you want to save?", //$NON-NLS-1$
                        "Connection status!", JOptionPane.YES_NO_OPTION); //$NON-NLS-1$
                if (i == JOptionPane.YES_OPTION) {
                    System.exit(1);
                }
            }
        }
    } catch (Exception e2) {
        PosLog.error(getClass(), e2);
        POSMessageDialog.showMessage(this, e2.getMessage());
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }
}

From source file:net.rptools.maptool.client.MapTool.java

public static boolean confirmDrawDelete() {
    if (!AppPreferences.getDrawWarnWhenDeleted()) {
        return true;
    }//from   ww  w  .j a  v a2  s.  c  o m

    String msg = I18N.getText("msg.confirm.deleteDraw");
    log.debug(msg);
    Object[] options = { I18N.getText("msg.title.messageDialog.yes"),
            I18N.getText("msg.title.messageDialog.no"), I18N.getText("msg.title.messageDialog.dontAskAgain") };
    String title = I18N.getText("msg.title.messageDialogConfirm");
    int val = JOptionPane.showOptionDialog(clientFrame, msg, title, JOptionPane.NO_OPTION,
            JOptionPane.WARNING_MESSAGE, null, options, options[0]);

    // "Yes, don't show again" Button
    if (val == 2) {
        showInformation("msg.confirm.deleteDraw.removed");
        AppPreferences.setDrawWarnWhenDeleted(false);
    }
    // Any version of 'Yes'...
    if (val == JOptionPane.YES_OPTION || val == 2) {
        return true;
    }
    // Assume 'No' response
    return false;
}

From source file:com.biosis.biosislite.vistas.inventario.MantenimientoClase.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 Clase?", "Mensaje del Sistema",
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            claseControlador.getSeleccionado().setCodigo(codigoField.getText().toUpperCase());
            claseControlador.getSeleccionado().setNombre(nombreField.getText().toUpperCase());

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

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

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

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

                lista.clear();
                claseControlador.getSeleccionado().setCodigo(codigoField.getText().toUpperCase());
                claseControlador.getSeleccionado().setNombre(nombreField.getText().toUpperCase());
                claseControlador.accion(accion);
                listar();

                FormularioUtil.limpiarComponente(panelDatos);

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

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

}

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

private void copyVillageAsBBCode() {
    List villageSelection = jVillageList.getSelectedValuesList();
    if (villageSelection == null || villageSelection.isEmpty()) {
        showInfo("Keine Drfer ausgewhlt");
        return;/* ww w . j a  v  a  2 s  .  co  m*/
    }
    try {
        List<Village> villages = new LinkedList<>();
        for (Object o : villageSelection) {
            villages.add((Village) o);
        }
        boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
                "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
                "Nein", "Ja") == JOptionPane.YES_OPTION);

        StringBuilder buffer = new StringBuilder();
        if (extended) {
            buffer.append("[u][size=12]Dorfliste[/size][/u]\n\n");
        } else {
            buffer.append("[u]Dorfliste[/u]\n\n");
        }
        buffer.append(new VillageListFormatter().formatElements(villages, extended));

        if (extended) {
            buffer.append("\n[size=8]Erstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n");
        } else {
            buffer.append("\nErstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n");
        }

        String b = buffer.toString();
        StringTokenizer t = new StringTokenizer(b, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Die ausgewhlten Drfer bentigen mehr als 1000 BB-Codes\n"
                            + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?",
                    "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null);
        String result = "Drfer in Zwischenablage kopiert.";
        showSuccess(result);
    } catch (Exception e) {
        logger.error("Failed to copy data to clipboard", e);
        String result = "Fehler beim Kopieren in die Zwischenablage.";
        showError(result);
    }
}

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

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
    // TODO add your handling code here:
    accion = AbstractControlador.ELIMINAR;
    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);
                }//from  w w w . j  a v a  2  s.co  m
                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.holycityaudio.SpinCAD.SpinCADFile.java

public void fileSaveAsm(SpinCADPatch patch) {
    // Create a file chooser
    String savedPath = prefs.get("MRUSpnFolder", "");

    final JFileChooser fc = new JFileChooser(savedPath);
    // In response to a button click:
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin ASM Files", "spn");
    fc.setFileFilter(filter);//from  w  w w.  ja  v  a 2 s .com
    // XXX DEBUG
    fc.showSaveDialog(new JFrame());
    File fileToBeSaved = fc.getSelectedFile();

    if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spn")) {
        fileToBeSaved = new File(fc.getSelectedFile() + ".spn");
    }
    int n = JOptionPane.YES_OPTION;
    if (fileToBeSaved.exists()) {
        JFrame frame1 = new JFrame();
        n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!",
                JOptionPane.YES_NO_OPTION);
    }
    if (n == JOptionPane.YES_OPTION) {
        String filePath = fileToBeSaved.getPath();
        fileToBeSaved.delete();

        try {
            fileSaveAsm(patch, filePath);
        } catch (IOException e) {
            JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, null, null);
            e.printStackTrace();
        }
        saveMRUSpnFolder(filePath);
    }
}

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

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
    // TODO add your handling code here:
    accion = Controlador.ELIMINAR;// w w  w.  ja  va2  s.c o m
    if (tblarea.getSelectedRow() != -1) {

        Integer codigo = tblarea.getSelectedRow();

        Area area = areaControlador.buscarPorId(lista.get(codigo).getId());

        if (area != null) {
            if (JOptionPane.showConfirmDialog(null, "Desea Eliminar la Area?", "Mensaje del Sistema",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                int[] filas = tblarea.getSelectedRows();
                for (int i = 0; i < filas.length; i++) {
                    Area area2 = lista.get(filas[0]);
                    lista.remove(area2);
                    areaControlador.setSeleccionado(area2);
                    areaControlador.accion(accion);
                }
                if (areaControlador.accion(accion) == 3) {
                    JOptionPane.showMessageDialog(null, "Area eliminada correctamente", "Mensaje del Sistema",
                            JOptionPane.INFORMATION_MESSAGE);

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