Example usage for javax.swing JOptionPane showOptionDialog

List of usage examples for javax.swing JOptionPane showOptionDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException 

Source Link

Document

Brings up a dialog with a specified icon, where the initial choice is determined by the initialValue parameter and the number of choices is determined by the optionType parameter.

Usage

From source file:com.pironet.tda.TDA.java

/**
 * save the current logfile (only used in plugin mode)
 *///ww  w .  j  a  va 2  s  .  c  om
public void saveLogFile() {
    if (fc == null) {
        fc = new JFileChooser();
        fc.setMultiSelectionEnabled(true);
        fc.setCurrentDirectory(PrefManager.get().getSelectedPath());
    }
    if (firstFile && (PrefManager.get().getPreferredSizeFileChooser().height > 0)) {
        fc.setPreferredSize(PrefManager.get().getPreferredSizeFileChooser());
    }
    int returnVal = fc.showSaveDialog(this.getRootPane());
    fc.setPreferredSize(fc.getSize());
    PrefManager.get().setPreferredSizeFileChooser(fc.getSize());

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        int selectValue = 0;
        if (file.exists()) {
            Object[] options = { "Overwrite", "Cancel" };
            selectValue = JOptionPane.showOptionDialog(null,
                    "<html><body>File exists<br><b>" + file + "</b></body></html>", "Confirm overwrite",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        }
        if (selectValue == 0) {
            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(file);
                fos.write(((LogFileContent) logFile.getUserObject()).getContent().getBytes());
                fos.flush();
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                try {
                    fos.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}

From source file:Form.Principal.java

private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
    try {//  w  ww  . j ava  2 s  .co  m
        String Comando = null;
        if (jTextField3.getText().equalsIgnoreCase("") || jTextField5.getText().equalsIgnoreCase("")
                || jTextField6.getText().equalsIgnoreCase("") || jTextField7.getText().equalsIgnoreCase("")
                || jTextField8.getText().equalsIgnoreCase("") || jTextField9.getText().equalsIgnoreCase("")
                || jTextField10.getText().equalsIgnoreCase("") || jTextField11.getText().equalsIgnoreCase("")) {
            Object[] options = { "Aceptar" };
            JOptionPane.showOptionDialog(null, "Datos incompletos", "Aviso", JOptionPane.DEFAULT_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, options, options[0]);
        } else {
            Variables.NombreCliente = jTextField6.getText();
            Variables.Direccion = jTextField10.getText();
            Variables.Estado = jTextField7.getText();
            Variables.municipio = jTextField9.getText();
            Variables.delegacion = jTextField11.getText();
            Variables.Correo = jTextField3.getText();
            Variables.codpostal = jTextField8.getText();

            Comando = "UPDATE cliente SET NombreCliente='" + jTextField6.getText() + "',Direccion='"
                    + jTextField10.getText() + "',Estado='" + jTextField7.getText() + "',Municipio='"
                    + jTextField9.getText() + "',Localidad='" + jTextField11.getText() + "',codPostal='"
                    + jTextField8.getText() + "',correo='" + jTextField3.getText() + "' WHERE idCliente="
                    + Variables.idCliente + ";";
            Funcion.Update(st, Comando);

            Variables.Comentario = jTextField20.getText();
            //*******Limpiar
            jTextField5.setText("");
            jTextField6.setText("");
            jTextField10.setText("");
            jTextField8.setText("");
            jTextField9.setText("");
            jTextField7.setText("");
            jTextField3.setText("");
            jTextField11.setText("");
            jTextField20.setText("");
            jPanel7.setVisible(false);
            jButton2.setVisible(false);
            jPanel6.setVisible(false);
            jButton1.setVisible(false);
            jButton12.setVisible(false);
            jButton13.setVisible(false);
            jPanel13.setVisible(false);

            //jButton9.setVisible(true);
            //jButton10.setVisible(true);
            jButton3.setVisible(true);
            jButton11.setVisible(true);
            EnviarSAT.setVisible(true);
            CrearPanelPDF();
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, e);
        System.out.print(e.getMessage());
        e.printStackTrace();
    }

}

From source file:com.pironet.tda.TDA.java

/**
 * close the currently selected dump.//from www .j  a  va 2 s .c o m
 */
private void closeCurrentDump() {
    TreePath selPath = tree.getSelectionPath();

    while (selPath != null && !(checkNameFromNode((DefaultMutableTreeNode) selPath.getLastPathComponent(),
            File.separator)
            || checkNameFromNode((DefaultMutableTreeNode) selPath.getLastPathComponent(), 2, File.separator))) {
        selPath = selPath.getParentPath();
    }

    Object[] options = { "Close File", "Cancel close" };

    String fileName = ((DefaultMutableTreeNode) selPath.getLastPathComponent()).getUserObject().toString();
    fileName = fileName.substring(fileName.indexOf(File.separator));

    int selectValue = JOptionPane.showOptionDialog(null,
            "<html><body>Are you sure, you want to close the currently selected dump file<br><b>" + fileName
                    + "</b></body></html>",
            "Confirm closing...", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
            options[0]);

    // if first option "close file" is selected.
    if (selectValue == 0) {
        // remove stuff from the top nodes
        topNodes.remove(selPath.getLastPathComponent());

        if (topNodes.size() == 0) {
            // simply do a reinit, as there isn't anything to display
            removeAll();
            revalidate();

            init(runningAsJConsolePlugin, runningAsVisualVMPlugin);
            getMainMenu().getLongMenuItem().setEnabled(false);
            getMainMenu().getCloseMenuItem().setEnabled(false);
            getMainMenu().getSaveSessionMenuItem().setEnabled(false);
            getMainMenu().getCloseToolBarButton().setEnabled(false);
            getMainMenu().getExpandButton().setEnabled(false);
            getMainMenu().getCollapseButton().setEnabled(false);
            getMainMenu().getFindLRThreadsToolBarButton().setEnabled(false);
            getMainMenu().getCloseAllMenuItem().setEnabled(false);
            getMainMenu().getExpandAllMenuItem().setEnabled(false);
            getMainMenu().getCollapseAllMenuItem().setEnabled(false);

        } else {
            // rebuild jtree
            getMainMenu().getCloseMenuItem().setEnabled(false);
            getMainMenu().getCloseToolBarButton().setEnabled(false);
            createTree();
        }
        revalidate();
    }

}

From source file:com.nikonhacker.gui.EmulatorUI.java

private void openAnalyseDialog(final int chip) {
    JTextField optionsField = new JTextField();
    JTextField destinationField = new JTextField();

    // compute and try default names for options file.
    // In order : <firmware>.dfr.txt , <firmware>.txt , dfr.txt (or the same for dtx)
    File optionsFile = new File(imageFile[chip].getParentFile(),
            FilenameUtils.getBaseName(imageFile[chip].getAbsolutePath())
                    + ((chip == Constants.CHIP_FR) ? ".dfr.txt" : ".dtx.txt"));
    if (!optionsFile.exists()) {
        optionsFile = new File(imageFile[chip].getParentFile(),
                FilenameUtils.getBaseName(imageFile[chip].getAbsolutePath()) + ".txt");
        if (!optionsFile.exists()) {
            optionsFile = new File(imageFile[chip].getParentFile(),
                    ((chip == Constants.CHIP_FR) ? "dfr.txt" : "dtx.txt"));
            if (!optionsFile.exists()) {
                optionsFile = null;/*  w  ww.  ja v a2  s .c o  m*/
            }
        }
    }
    if (optionsFile != null) {
        optionsField.setText(optionsFile.getAbsolutePath());
    }

    // compute default name for output
    File outputFile = new File(imageFile[chip].getParentFile(),
            FilenameUtils.getBaseName(imageFile[chip].getAbsolutePath()) + ".asm");
    destinationField.setText(outputFile.getAbsolutePath());

    final JCheckBox writeOutputCheckbox = new JCheckBox("Write disassembly to file");

    final FileSelectionPanel destinationFileSelectionPanel = new FileSelectionPanel("Destination file",
            destinationField, false);
    destinationFileSelectionPanel.setFileFilter(".asm", "Assembly language file (*.asm)");
    writeOutputCheckbox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean writeToFile = writeOutputCheckbox.isSelected();
            destinationFileSelectionPanel.setEnabled(writeToFile);
            prefs.setWriteDisassemblyToFile(chip, writeToFile);
        }
    });

    writeOutputCheckbox.setSelected(prefs.isWriteDisassemblyToFile(chip));
    destinationFileSelectionPanel.setEnabled(prefs.isWriteDisassemblyToFile(chip));

    FileSelectionPanel fileSelectionPanel = new FileSelectionPanel(
            (chip == Constants.CHIP_FR) ? "Dfr options file" : "Dtx options file", optionsField, false);
    fileSelectionPanel.setFileFilter((chip == Constants.CHIP_FR) ? ".dfr.txt" : ".dtx.txt",
            (chip == Constants.CHIP_FR) ? "Dfr options file (*.dfr.txt)" : "Dtx options file (*.dtx.txt)");
    final JComponent[] inputs = new JComponent[] {
            //new FileSelectionPanel("Source file", sourceFile, false, dependencies),
            fileSelectionPanel, writeOutputCheckbox, destinationFileSelectionPanel,
            makeOutputOptionCheckBox(chip, OutputOption.STRUCTURE, prefs.getOutputOptions(chip), true),
            makeOutputOptionCheckBox(chip, OutputOption.ORDINAL, prefs.getOutputOptions(chip), true),
            makeOutputOptionCheckBox(chip, OutputOption.PARAMETERS, prefs.getOutputOptions(chip), true),
            makeOutputOptionCheckBox(chip, OutputOption.INT40, prefs.getOutputOptions(chip), true),
            makeOutputOptionCheckBox(chip, OutputOption.MEMORY, prefs.getOutputOptions(chip), true),
            new JLabel("(hover over the options for help. See also 'Tools/Options/Disassembler output')",
                    SwingConstants.CENTER) };

    if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, inputs, "Choose analyse options",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.DEFAULT_OPTION)) {
        String outputFilename = writeOutputCheckbox.isSelected() ? destinationField.getText() : null;
        boolean cancel = false;
        if (outputFilename != null) {
            if (new File(outputFilename).exists()) {
                if (JOptionPane.showConfirmDialog(this,
                        "File '" + outputFilename + "' already exists.\nDo you really want to overwrite it ?",
                        "File exists", JOptionPane.YES_NO_OPTION,
                        JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
                    cancel = true;
                }
            }
        }
        if (!cancel) {
            AnalyseProgressDialog analyseProgressDialog = new AnalyseProgressDialog(this,
                    framework.getPlatform(chip).getMemory());
            analyseProgressDialog.startBackgroundAnalysis(chip, optionsField.getText(), outputFilename);
            analyseProgressDialog.setVisible(true);
        }
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * close all open dumps/* w  w  w  .j a  v  a2 s .  co m*/
 */
private void closeAllDumps() {
    Object[] options = { "Close all", "Cancel close" };

    int selectValue = JOptionPane.showOptionDialog(null,
            "<html><body>Are you sure, you want to close all open dump files", "Confirm closing...",
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

    // if first option "close file" is selected.
    if (selectValue == 0) {
        // remove stuff from the top nodes
        topNodes = new Vector<>();

        // simply do a re-init, as there is anything to display
        resetMainPanel();
    }
}

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

/**
 * Asks if they want to delete and then deletes it
 * @param cmdActionDB the delete command
 *///from  ww  w .j  a  v a  2s  .  co  m
private void deleteInfoRequest(final CommandActionForDB cmdActionDB) {
    NavBoxButton nb = (NavBoxButton) cmdActionDB.getSrcObj();
    int option = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(),
            String.format(getResourceString("InteractionsTask.CONFIRM_DELETE_IR"), nb.getName()),
            getResourceString("InteractionsTask.CONFIRM_DELETE_TITLE_IR"), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION); // I18N

    if (option == JOptionPane.YES_OPTION) {
        InfoRequest infoRequest = deleteInfoRequest(cmdActionDB.getId());
        deleteInfoRequestFromUI(null, infoRequest);
    }
}

From source file:Form.Principal.java

private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
    try {//from w ww  .  j av a 2 s . c  om
        String Comando = null;
        if (jTextField12.getText().equalsIgnoreCase("") || jTextField13.getText().equalsIgnoreCase("")
                || jTextField14.getText().equalsIgnoreCase("") || jTextField15.getText().equalsIgnoreCase("")
                || jTextField18.getText().equalsIgnoreCase("") || jTextField17.getText().equalsIgnoreCase("")
                || jTextField16.getText().equalsIgnoreCase("") || jTextField4.getText().equalsIgnoreCase("")) {
            Object[] options = { "Aceptar" };
            JOptionPane.showOptionDialog(null, "Datos incompletos", "Aviso", JOptionPane.DEFAULT_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, options, options[0]);
        } else {
            Variables.RFC = jTextField12.getText();
            Variables.NombreCliente = jTextField14.getText();
            Variables.Direccion = jTextField13.getText();
            Variables.Estado = jTextField15.getText();
            Variables.municipio = jTextField17.getText();
            Variables.delegacion = jTextField18.getText();
            Variables.Correo = jTextField4.getText();
            Variables.codpostal = jTextField16.getText();

            Comando = "UPDATE cliente SET NombreCliente='" + jTextField14.getText() + "',Direccion='"
                    + jTextField13.getText() + "',Estado='" + jTextField15.getText() + "',Municipio='"
                    + jTextField17.getText() + "',Localidad='" + jTextField18.getText() + "',codPostal='"
                    + jTextField16.getText() + "',correo='" + jTextField4.getText() + "',RFC='"
                    + jTextField12.getText() + "' WHERE idCliente=" + id + ";";
            Funcion.Update(st, Comando);
            Variables.Comentario = jTextField21.getText();

            if (editarcliente2 == false)
                botonfalse();
            else {
                jTextField12.setText("");
                jTextField14.setText("");
                jTextField13.setText("");
                jTextField15.setText("");
                jTextField17.setText("");
                jTextField18.setText("");
                jTextField16.setText("");
                jTextField4.setText("");
                jTextField21.setText("");
                EditarClientes.remove(scrollcuadro);
                jPanel9.setVisible(false);
                EnviarSAT1.setVisible(true);
                jButton18.setVisible(true);
                jButton15.setVisible(true);
                scrollcuadro.setVisible(true);
                jButtonSave.setVisible(false);
                jButton16.setVisible(false);
                jPanel14.setVisible(false);
                CrearPanelPDF();
            }
            editarcliente2 = false;
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, e);
        System.out.print(e.getMessage());
        e.printStackTrace();
    }

}

From source file:net.sf.jabref.gui.JabRefFrame.java

private int showSaveDialog(String filename) {
    Object[] options = { Localization.lang("Save changes"), Localization.lang("Discard changes"),
            Localization.lang("Return to JabRef") };

    return JOptionPane.showOptionDialog(JabRefFrame.this,
            Localization.lang("Database '%0' has changed.", filename), Localization.lang("Save before closing"),
            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[2]);
}

From source file:de.dal33t.powerfolder.Controller.java

/**
 * Called if controller has detected a already running instance
 *//*from w ww  . j  ava 2s .c  o  m*/
private void alreadyRunningCheck() {
    Component parent = null;
    if (isUIOpen()) {
        parent = uiController.getMainFrame().getUIComponent();
    }
    if (!isStartMinimized() && isUIEnabled() && !commandLine.hasOption('z')) {
        Object[] options = { Translation.getTranslation("dialog.already_running.show_button") };
        int exitOption = 0;
        if (verbose) {
            options = new Object[] { Translation.getTranslation("dialog.already_running.start_button"),
                    Translation.getTranslation("dialog.already_running.exit_button") };
            exitOption = 1;
        }
        if (JOptionPane.showOptionDialog(parent, Translation.getTranslation("dialog.already_running.warning"),
                Translation.getTranslation("dialog.already_running.title"), JOptionPane.DEFAULT_OPTION,
                JOptionPane.INFORMATION_MESSAGE, null, options, options[0]) == exitOption) { // exit pressed
                                                                                                                                                                                                                                                                                            // Try to bring existing instance to the foreground.
            RemoteCommandManager.sendCommand(RemoteCommandManager.SHOW_UI);
            exit(1);
        } else {
            exit(1);
        }
    } else {
        // If no gui show error but start anyways
        logWarning("PowerFolder already running");
    }
}

From source file:de.dal33t.powerfolder.Controller.java

private void fatalStartError(String message) {
    Component parent = null;/*from ww w.  j  a  va 2 s.  c om*/
    if (isUIOpen()) {
        parent = uiController.getMainFrame().getUIComponent();
    }
    if (isUIEnabled()) {
        Object[] options = { Translation.getTranslation("dialog.already_running.exit_button") };
        JOptionPane.showOptionDialog(parent, message, Translation.getTranslation("dialog.fatal_error.title"),
                JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);
    } else {
        logSevere(message);
    }
    exit(1);
}