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:au.org.ala.delta.editor.ui.ImageDetailsPanel.java

private File getMediaFile(FileFilter filter) {
    String imagePath = _dataSet.getImagePath();
    JFileChooser chooser = new JFileChooser(imagePath);
    chooser.setFileFilter(filter);//from   w  w  w .  j a  v a 2  s . c  o m

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File imageFile = chooser.getSelectedFile();

        ImageSettings settings = _dataSet.getImageSettings();
        if (settings.isOnResourcePath(imageFile)) {

            String name = imageFile.getName();
            boolean exists = false;

            if (_selectedImage != null) {
                List<ImageOverlay> existingSounds = _selectedImage.getSounds();
                for (ImageOverlay sound : existingSounds) {
                    if (name.equals(sound.overlayText)) {
                        exists = true;
                        break;
                    }
                }
            }
            if (exists) {
                int result = _messageHelper.confirmDuplicateFileName();
                if (result == JOptionPane.YES_OPTION) {
                    imageFile = new File(imageFile.getAbsolutePath());
                } else if (result == JOptionPane.NO_OPTION) {
                    return getMediaFile(filter);
                } else {
                    imageFile = null;
                }
            } else {
                // Turn the file into a relative one.
                imageFile = new File(name);
            }
        } else {
            // Ask about it or copy it to the image path.
            int result = _messageHelper.confirmNotOnImagePath();
            if (result == JOptionPane.YES_OPTION) {
                imageFile = new File(imageFile.getAbsolutePath());
            } else if (result == JOptionPane.NO_OPTION) {
                return getMediaFile(filter);
            } else {
                imageFile = null;
            }
        }

        return imageFile;
    }

    return null;
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public void fileSaveBankAs(SpinCADBank b) {
    // Create a file chooser
    String savedPath = prefs.get("MRUBankFolder", "");
    final JFileChooser fc = new JFileChooser(savedPath);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Bank Files", "spbk");
    fc.setFileFilter(filter);//from   w  w  w  . ja va  2  s.c  o  m
    fc.setSelectedFile(new File(b.bankFileName));
    int returnVal = fc.showSaveDialog(new JFrame());
    // need to process user canceling box right here
    if (returnVal == JFileChooser.APPROVE_OPTION) {

        // In response to a button click:
        File fileToBeSaved = fc.getSelectedFile();

        if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spbk")) {
            fileToBeSaved = new File(fc.getSelectedFile() + ".spbk");
        }
        b.bankFileName = fileToBeSaved.getName();

        int n = JOptionPane.YES_OPTION;
        if (fileToBeSaved.exists()) {
            JFrame frame = new JFrame();
            n = JOptionPane.showConfirmDialog(frame, "Would you like to overwrite it?", "File already exists!",
                    JOptionPane.YES_NO_OPTION);
            if (n == JOptionPane.YES_OPTION) {
                try {
                    fileSaveBank(b);
                } finally {
                }
            }
        } else {
            fileSaveBank(b);
        }
        b.changed = false;
        recentBankFileList.add(fileToBeSaved);
        saveMRUBankFolder(fileToBeSaved.getPath());
        b.bankFileName = fileToBeSaved.getName();
    }
}

From source file:serial.ChartFromSerial.java

private void connect_jBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connect_jBtnActionPerformed
    defaultSeries.clear();//from w  w  w . ja  v  a  2s  . co  m
    text.setText("");
    if ("Connect".equals(connect_jBtn.getText())) {

        //Attempt to connect to to serial port
        chosenPort = SerialPort.getCommPort(portList_jCombo.getSelectedItem().toString());
        chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
        chosenPort.setBaudRate(Integer.parseInt(baudRate_jCombo.getSelectedItem().toString()));

        if (chosenPort.openPort()) {
            createSerialThread(chosenPort);
            buttonsConnected();
            //                if(createSerialThread(chosenPort)){
            //                    buttonsConnected();
            //                } else {
            //                    JOptionPane.showMessageDialog(rootPane, "Failed to create a serial connection.", "Serial connection failed.", JOptionPane.ERROR_MESSAGE);
            //                    chosenPort.closePort();
            //                }
        } else {
            if (JOptionPane.showConfirmDialog(rootPane,
                    "Error at " + portList_jCombo.getSelectedItem().toString() + "\nWould you like to refresh?",
                    "Trouble connecting to " + portList_jCombo.getSelectedItem().toString(),
                    JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.YES_OPTION) {
                hardRefresh();
            } else {
                buttonsOff();
            }
        }
    } else {
        //Attempt to disconnect from the serial port
        chosenPort.closePort();
        softRefresh();
        samples = 0;

    }
}

From source file:gda.gui.mca.McaGUI.java

private void makeTcaControlDialog() {
    if (tcaControlPanel == null) {
        tcaControlPanel = new TcaPanel();
        tcaDialog = new JDialog();
        Object[] options = { "OK" };
        Object[] array = { tcaControlPanel };

        // Create the JOptionPane.
        final JOptionPane optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION,
                null, options, options[0]);
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {

            @Override/*from   w w w .j  a va2  s .  c  o  m*/
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();

                if (isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop)
                        || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if ("OK".equals(value)) {

                        tcaDialog.setVisible(false);
                    }
                }

            }

        });
        tcaDialog.setContentPane(optionPane);
        tcaDialog.pack();
        tcaDialog.setTitle("TCA Controls");
        tcaDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    }

}

From source file:net.sf.jabref.exporter.SaveDatabaseAction.java

/**
 * Check whether or not the external database has been modified. If so need to alert the user to accept external updates prior to
 * saving the database. This is necessary to avoid overwriting other users work when using a multiuser database file.
 *
 * @return true if the external database file has been modified and the user must choose to accept the changes and false if no modifications
 * were found or there is no requested protection for the database file.
 *///from  w  w  w  .j  av  a2s. com
private boolean checkExternalModification() {
    // Check for external modifications:
    if (panel.isUpdatedExternally()
            || Globals.fileUpdateMonitor.hasBeenModified(panel.getFileMonitorHandle())) {
        String[] opts = new String[] { Localization.lang("Review changes"), Localization.lang("Save"),
                Localization.lang("Cancel") };
        int answer = JOptionPane.showOptionDialog(panel.frame(),
                Localization.lang("File has been updated externally. " + "What do you want to do?"),
                Localization.lang("File updated externally"), JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, opts, opts[0]);

        if (answer == JOptionPane.CANCEL_OPTION) {
            canceled = true;
            return true;
        } else if (answer == JOptionPane.YES_OPTION) {
            canceled = true;

            JabRefExecutorService.INSTANCE.execute((Runnable) () -> {

                if (!FileBasedLock.waitForFileLock(panel.getBibDatabaseContext().getDatabaseFile(), 10)) {
                    // TODO: GUI handling of the situation when the externally modified file keeps being locked.
                    LOGGER.error("File locked, this will be trouble.");
                }

                ChangeScanner scanner = new ChangeScanner(panel.frame(), panel,
                        panel.getBibDatabaseContext().getDatabaseFile());
                JabRefExecutorService.INSTANCE.executeWithLowPriorityInOwnThreadAndWait(scanner);
                if (scanner.changesFound()) {
                    scanner.displayResult((ChangeScanner.DisplayResultCallback) resolved -> {
                        if (resolved) {
                            panel.setUpdatedExternally(false);
                            SwingUtilities.invokeLater(
                                    (Runnable) () -> panel.getSidePaneManager().hide("fileUpdate"));
                        } else {
                            canceled = true;
                        }
                    });
                }
            });

            return true;
        } else { // User indicated to store anyway.
            if (panel.getBibDatabaseContext().getMetaData().isProtected()) {
                JOptionPane.showMessageDialog(frame, Localization
                        .lang("Database is protected. Cannot save until external changes have been reviewed."),
                        Localization.lang("Protected database"), JOptionPane.ERROR_MESSAGE);
                canceled = true;
            } else {
                panel.setUpdatedExternally(false);
                panel.getSidePaneManager().hide("fileUpdate");
            }
        }
    }

    // Return false as either no external database file modifications have been found or overwrite is requested any way
    return false;
}

From source file:MstrPetugas.FormPetugas.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    String kode = tabel_petugas.getValueAt(tabel_petugas.getSelectedRow(), 0).toString();
    int jawab = JOptionPane.showConfirmDialog(this, "Hapus ? Data Petugas : " + kode, "Konfirmasi",
            JOptionPane.YES_NO_OPTION);
    if (jawab == JOptionPane.YES_OPTION) {
        MstrPetugas x = new MstrPetugas();
        x.Delete(kode);/*  w  w  w  .  j ava 2 s  . c  o  m*/
        LoadData();
    }
}

From source file:com.nwn.NwnUpdaterHomeView.java

/**
 * Delete server from gui and config/* w  w w . j  av a 2s  .  c om*/
 * Currently this cannot be undone
 * @param evt 
 */
private void btnRemoveServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveServerActionPerformed
    ServerInfo selectedServer = (ServerInfo) cmbServerList.getSelectedItem();
    int confirm = JOptionPane.showConfirmDialog(null,
            "Are you sure you want to delete " + selectedServer.getServerName() + "?", "Warning",
            JOptionPane.YES_NO_OPTION);
    if (confirm == JOptionPane.YES_OPTION) {
        config.getServerList().remove(cmbServerList.getSelectedItem());
        cmbServerList.removeItemAt(cmbServerList.getSelectedIndex());
        config.save();
    }
}

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

private void untagSelectedVillages() {
    List villageSelection = jVillageList.getSelectedValuesList();
    if (villageSelection == null || villageSelection.isEmpty()) {
        showInfo("Keine Drfer ausgewhlt");
        return;/*w w w .  j  ava 2  s  . c  o  m*/
    }

    if (JOptionPaneHelper.showQuestionConfirmBox(this,
            "Willst du" + ((villageSelection.size() == 1) ? " das gewhlte Dorf " : " die gewhlten Drfer ")
                    + "wirklich aus den gewhlten Gruppen entfernen?",
            "Lschen", "Nein", "Ja") == JOptionPane.YES_OPTION) {
        List<Tag> selection = getSelectedTags();
        TagManager.getSingleton().invalidate();
        for (Tag t : selection) {
            for (Object o : villageSelection) {
                Village v = (Village) o;
                t.untagVillage(v.getId());
            }
        }
        TagManager.getSingleton().revalidate(true);
        showSuccess("Drfer erfolgreich entfernt");
    }
}

From source file:net.sf.profiler4j.console.Console.java

/**
 * /*from www .j  a  va  2  s  .  c  o m*/
 * @return <code>true</code> if the user has cancelled
 */
private boolean checkUnsavedChanges() {
    if (project.isChanged()) {
        int ret = JOptionPane.showConfirmDialog(mainFrame, "Project has unsaved changes? Save before exit?",
                "Unsaved Changes", JOptionPane.YES_NO_CANCEL_OPTION);
        if (ret == JOptionPane.CANCEL_OPTION) {
            return true;
        } else if (ret == JOptionPane.YES_OPTION) {
            return saveProject(false);
        }
    }
    return false;
}

From source file:dylemator.UserResultList.java

private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
    int row = this.codeTable.getSelectedRow();
    if (row == -1)
        return;/*from  w ww .  j  a  v a  2 s . c  o  m*/
    String[] values = exportData.get(row + 1);
    int dialogResult = JOptionPane.showConfirmDialog(null, "Usun wyniki uytkownika " + values[0] + "?",
            "Warning", JOptionPane.YES_NO_OPTION);
    if (dialogResult == JOptionPane.YES_OPTION) {
        exportData.remove(row + 1);
        DefaultTableModel m = (DefaultTableModel) codeTable.getModel();
        m.setRowCount(0);
        for (int i = 1; i < exportData.size(); i++) {
            m.addRow(new String[] { exportData.get(i)[0] });
        }
        DefaultTableModel n = (DefaultTableModel) infoTable.getModel();
        DefaultTableModel o = (DefaultTableModel) resultsTable.getModel();
        n.setRowCount(0);
        o.setRowCount(0);
        try {
            OutputStreamWriter output = new FileWriter(this.selectedFilename);
            BufferedWriter bufferWriter = new BufferedWriter(output);
            for (String[] v : exportData) {
                String s = StringUtils.join(v, ";");
                bufferWriter.write(s + "\n");
            }
            bufferWriter.flush();
            bufferWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(UserResultList.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}