Example usage for javax.swing JOptionPane showConfirmDialog

List of usage examples for javax.swing JOptionPane showConfirmDialog

Introduction

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

Prototype

public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
        throws HeadlessException 

Source Link

Document

Brings up a dialog where the number of choices is determined by the optionType parameter.

Usage

From source file:de.ailis.xadrian.components.ComplexEditor.java

/**
 * Prompts for a file name and saves the complex there.
 *//*from   ww w  .  j  a  v  a  2  s.c  o m*/
public void saveAs() {
    final SaveComplexDialog dialog = SaveComplexDialog.getInstance();
    dialog.setSelectedFile(getSuggestedFile());
    File file = dialog.open();
    if (file != null) {
        // Add file extension if none present
        if (FileUtils.getExtension(file) == null)
            file = new File(file.getPath() + ".x3c");

        // Save the file if it does not yet exists are user confirms
        // overwrite
        if (!file.exists() || JOptionPane.showConfirmDialog(null, I18N.getString("confirm.overwrite"),
                I18N.getString("confirm.title"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            save(file);
        }
    }
}

From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java

private boolean promptForUnsavedChanges() {
    if (currentGroupOrUserEditPanel != null && (currentGroupOrUserEditPanel.hasUnsavedChanges())) {

        int option = JOptionPane.showConfirmDialog(getPanel(),
                "You have not saved all of your changes,\n" + "do you want to save them now?", "",
                JOptionPane.INFORMATION_MESSAGE);

        if (option == JOptionPane.YES_OPTION) {
            currentGroupOrUserEditPanel.applyChanges();
            return true;
        }//from w w w.  ja va2 s .  c  o m

        if (option == JOptionPane.NO_OPTION) {
            return true;
        }

        if (option == JOptionPane.CANCEL_OPTION) {
            return false;
        }
    }

    return true;
}

From source file:be.fedict.eid.tsl.tool.TslInternalFrame.java

@Override
public void actionPerformed(ActionEvent event) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Save Signer Certificate");
    int result = fileChooser.showSaveDialog(this);
    if (JFileChooser.APPROVE_OPTION == result) {
        File file = fileChooser.getSelectedFile();
        if (file.exists()) {
            int confirmResult = JOptionPane.showConfirmDialog(this,
                    "File already exists.\n" + file.getAbsolutePath() + "\n" + "Overwrite file?", "Overwrite",
                    JOptionPane.OK_CANCEL_OPTION);
            if (JOptionPane.CANCEL_OPTION == confirmResult) {
                return;
            }/*from   ww w. ja  v  a  2s.  c  o m*/
        }
        try {
            FileUtils.writeByteArrayToFile(file, this.signerCertificate.getEncoded());
        } catch (Exception e) {
            throw new RuntimeException("error writing file: " + e.getMessage(), e);
        }
    }
}

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  .j  a  v a2s .co  m*/
    // 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.mirth.connect.manager.ManagerController.java

/**
 * Alerts the user with a yes/no option with the passed in 'message'
 *///from   w w w. ja v a  2 s. c om
public boolean alertOptionDialog(Component parent, String message) {
    int option = JOptionPane.showConfirmDialog(parent, message, "Select an Option", JOptionPane.YES_NO_OPTION);
    if (option == JOptionPane.YES_OPTION) {
        return true;
    } else {
        return false;
    }
}

From source file:com.sshtools.shift.FileTransferDialog.java

/**
 *
 *
 * @param sftp/*from ww  w.j av a 2  s  . c  om*/
 * @param files
 * @param totalBytes
 */

public void getRemoteFiles(SftpClient sftp, java.util.List files, long totalBytes) {

    this.files = files;
    this.totalBytes = totalBytes;
    this.sftp = sftp;

    lblTargetAction.setText("Downloading to:");
    progressbar.setMaximum(100);

    if ((totalBytes / 1073741824) > 0) {
        // Were in the gigabytes
        formattedTotal = formatMb.format((double) totalBytes / 1073741824) + " GB";
    } else if ((totalBytes / 1048576) > 0) {
        // Were in the megabytes
        formattedTotal = formatMb.format((double) totalBytes / 1048576) + " MB";
    } else {
        // Were still in Kilobytes
        formattedTotal = formatKb.format((double) totalBytes / 1024) + " KB";
    }

    Thread thread = new Thread(new Runnable() {
        int i;

        public void run() {
            String pwd = FileTransferDialog.this.sftp.pwd();
            String lpwd = FileTransferDialog.this.sftp.lpwd();
            try {
                for (i = 0; i < FileTransferDialog.this.files.size(); i++) {
                    // Test whether the file exists before the download commences
                    File file = new File(lpwd + File.separator + FileTransferDialog.this.files.get(i));
                    if (file.exists()) {
                        int result = JOptionPane.showConfirmDialog(FileTransferDialog.this,
                                "This file already exists are you sure you wish to overwrite?\n\n"
                                        + file.getName(),
                                "Confirm File Overwrite", JOptionPane.YES_NO_CANCEL_OPTION);
                        if (result == JOptionPane.NO_OPTION) {
                            if (i == FileTransferDialog.this.files.size() - 1) {
                                // This was the last file for transfer
                                cancelOperation();
                                return;
                            } else {
                                String ff = pwd + "/" + FileTransferDialog.this.files.get(i);
                                FileAttributes attrs = FileTransferDialog.this.sftp.stat(ff);
                                started(attrs.getSize().longValue(), ff);
                                progressed(attrs.getSize().longValue());
                                completed();
                                // Was not the last file so goto next
                                continue;
                            }
                        }

                        if (result == JOptionPane.CANCEL_OPTION) {
                            // Cancel the upload operation
                            cancelOperation();
                            return;
                        }
                    }
                    setSource(pwd + "/" + FileTransferDialog.this.files.get(i));
                    setTarget(lpwd + File.separator + FileTransferDialog.this.files.get(i));

                    if (!cancelled) {
                        FileTransferDialog.this.sftp.get((String) FileTransferDialog.this.files.get(i),
                                FileTransferDialog.this);
                    }
                }
                // Notify any waiting threads that we've completed our operation
                completed = true;
                notifyWaiting();
            } catch (IOException ex) {
                if (!cancelled) {
                    SshToolsApplicationPanel.showErrorMessage(FileTransferDialog.this,
                            "The file operation failed!\n" + ex.getMessage(), "File Transfer", ex);
                    // Delete the partially completed file

                    File file = new File(lpwd + File.separator + FileTransferDialog.this.files.get(i));
                    if (file.exists()) {
                        file.delete();
                    }
                    setVisible(false);
                }
            }
        }
    });
    thread.start();
    try {
        setVisible(true);
    } catch (NullPointerException e) {
        setVisible(true);
    }
}

From source file:condorclient.MainFXMLController.java

@FXML
void reScheduleFired(ActionEvent event) {
    //cluster?//from   ww w  . j  a  v a2  s .c  o  m
    int oldId = 0;//??
    int delNo = 0;
    int reScheduleId = 0;

    URL url = null;

    // String scheddURLStr="http://localhost:9628";
    XMLHandler handler = new XMLHandler();
    String scheddStr = handler.getURL("schedd");
    try {
        url = new URL(scheddStr);
    } catch (MalformedURLException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    }
    Schedd schedd = null;

    int n = JOptionPane.showConfirmDialog(null, "?????", "",
            JOptionPane.YES_NO_OPTION);
    if (n == JOptionPane.YES_OPTION) {

        //checkboxclusterId
        System.out.print(Thread.currentThread().getName() + "\n");

        try {
            schedd = new Schedd(url);
        } catch (ServiceException ex) {
            Logger.getLogger(CondorClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        //ClassAdStructAttr[]

        ClassAd ad = null;//birdbath.ClassAd;
        ClassAdStructAttr[][] classAdArray = null;
        ClassAdStructAttr[][] classAdArray2 = null;
        String taskStatus = "";

        final List<?> selectedNodeList = new ArrayList<>(table.getSelectionModel().getSelectedItems());
        for (Object o : selectedNodeList) {
            if (o instanceof ObservableDisplayedClassAd) {
                oldId = Integer.parseInt(((ObservableDisplayedClassAd) o).getClusterId());
                taskStatus = ((ObservableDisplayedClassAd) o).getJobStatus();
                if (taskStatus.equals("") || taskStatus.equals("?") || taskStatus.equals("")) {
                    JOptionPane.showMessageDialog(null, "??????");
                    return;
                }

            }
        }
        //e
        int job = 0;
        Transaction xact = schedd.createTransaction();
        try {
            xact.begin(30);

        } catch (RemoteException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        System.out.println("oldId:" + oldId);

        String findreq = "owner==\"" + condoruser + "\"&&ClusterId==" + oldId;
        try {
            classAdArray = schedd.getJobAds(findreq);
            classAdArray2 = schedd.getJobAds(findreq);
        } catch (RemoteException ex) {
            Logger.getLogger(MainFXMLController.class.getName()).log(Level.SEVERE, null, ex);
        }
        //?jobclassAd?
        int newClusterId = 0;
        try {
            newClusterId = xact.createCluster();

        } catch (RemoteException e) {
        }
        int newJobId = 0;
        //            XMLHandler handler = new XMLHandler();
        String oldname = handler.getJobName("" + oldId);
        String transferInput = "";
        String jobdir = null;
        //?job??job
        int jobcount = 0;
        String timestamp = (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date());
        System.out.println("oldname" + oldname);
        jobdir = handler.getTaskDir("" + oldId);
        String expfilename = handler.getExpFile("" + oldId);
        String infofilename = handler.getInfoFile("" + oldId);
        for (ClassAdStructAttr[] x : classAdArray) {

            ad = new ClassAd(x);
            job = Integer.parseInt(ad.get("ProcId"));
            ClassAdStructAttr[] attributes = null;// {new ClassAdStructAttr()};

            System.out.println("jobdir:===" + jobdir);

            //??
            // 
            File[] files = { new File(expfilename), new File(infofilename) };// new File[2];

            System.out.println(expfilename + "===" + infofilename);

            //
            String oldiwd = jobdir.substring(0, jobdir.length() - 14);//D:\tmp\test\dirtest\20140902200811;
            String resultdirstr = oldiwd + timestamp + "\\" + job;//job
            // new String(handler.getTaskDir(oldname).getBytes(),"UTF-8");
            //
            //attributes[0] = new ClassAdStructAttr("Iwd", ClassAdAttrType.value3, resultdirstr);
            File newjobdir = new File(resultdirstr);
            try {
                System.out.println("resultdirstr:" + resultdirstr);
                FileUtils.forceMkdir(newjobdir);
            } catch (IOException ex) {
                Logger.getLogger(CreateJobDialogController.class.getName()).log(Level.SEVERE, null, ex);
            }
            //?
            /* for (int j = 0; j < inputfilecount; j++) {
              System.out.println("j:" + j);
              try {
              FileUtils.copyFileToDirectory(files[j], newjobdir);
              } catch (IOException ex) {
              Logger.getLogger(MainFXMLController.class.getName()).log(Level.SEVERE, null, ex);
              }
              }*/

            try {
                newJobId = xact.createJob(newClusterId);
            } catch (RemoteException ex) {
                Logger.getLogger(MainFXMLController.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {

                xact.submit(newClusterId, newJobId, condoruser, UniverseType.VANILLA, ad.get("Cmd"),
                        ad.get("Arguments"), ad.get("Requirements"), attributes, files);
                xact.closeSpool(oldId, job);
            } catch (RemoteException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
        //s
        try {
            xact.removeCluster(oldId, "");
        } catch (RemoteException ex) {
            Logger.getLogger(MainFXMLController.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            xact.commit();
        } catch (RemoteException e) {

            e.printStackTrace();
        }
        try {
            schedd.requestReschedule();
        } catch (RemoteException ex) {
            Logger.getLogger(MainFXMLController.class.getName()).log(Level.SEVERE, null, ex);
        }

        System.out.println("comit:" + oldname);

        String olddir = handler.getTaskDir("" + oldId);

        System.out.println("olddir:" + olddir);
        // olddir.substring(0, olddir.length() - 14);//??14?
        String newdir = olddir.substring(0, olddir.length() - 14) + timestamp;
        System.out.println("newdir:" + newdir);
        //  System.out.println(olddir+"\nmm"+newdir);
        handler.removeJob("" + oldId);
        handler.addJob(oldname, "" + newClusterId, newdir, expfilename, infofilename);

        // reConfigureButtons();
    } else if (n == JOptionPane.NO_OPTION) {
        System.out.println("qu xiao");

    }

    System.out.print("recreateTransaction succeed\n");

}

From source file:be.agiv.security.demo.Main.java

private void showPreferences() {
    JTabbedPane tabbedPane = new JTabbedPane();

    GridBagLayout proxyGridBagLayout = new GridBagLayout();
    GridBagConstraints proxyGridBagConstraints = new GridBagConstraints();
    JPanel proxyPanel = new JPanel(proxyGridBagLayout) {

        private static final long serialVersionUID = 1L;

        @Override//from  ww  w. jav  a 2  s.com
        public Insets getInsets() {
            return new Insets(10, 10, 10, 10);
        }
    };
    tabbedPane.addTab("Proxy", proxyPanel);

    JCheckBox proxyEnableCheckBox = new JCheckBox("Enable proxy", this.proxyEnable);
    proxyGridBagConstraints.gridx = 0;
    proxyGridBagConstraints.gridy = 0;
    proxyGridBagConstraints.anchor = GridBagConstraints.WEST;
    proxyGridBagConstraints.ipadx = 5;
    proxyGridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    proxyGridBagLayout.setConstraints(proxyEnableCheckBox, proxyGridBagConstraints);
    proxyPanel.add(proxyEnableCheckBox);
    proxyGridBagConstraints.gridwidth = 1;

    JLabel proxyHostLabel = new JLabel("Host:");
    proxyGridBagConstraints.gridx = 0;
    proxyGridBagConstraints.gridy++;
    proxyGridBagLayout.setConstraints(proxyHostLabel, proxyGridBagConstraints);
    proxyPanel.add(proxyHostLabel);

    JTextField proxyHostTextField = new JTextField(this.proxyHost, 20);
    proxyGridBagConstraints.gridx++;
    proxyGridBagLayout.setConstraints(proxyHostTextField, proxyGridBagConstraints);
    proxyPanel.add(proxyHostTextField);

    JLabel proxyPortLabel = new JLabel("Port:");
    proxyGridBagConstraints.gridx = 0;
    proxyGridBagConstraints.gridy++;
    proxyGridBagLayout.setConstraints(proxyPortLabel, proxyGridBagConstraints);
    proxyPanel.add(proxyPortLabel);

    JTextField proxyPortTextField = new JTextField(Integer.toString(this.proxyPort), 8);
    proxyGridBagConstraints.gridx++;
    proxyGridBagLayout.setConstraints(proxyPortTextField, proxyGridBagConstraints);
    proxyPanel.add(proxyPortTextField);

    JLabel proxyTypeLabel = new JLabel("Type:");
    proxyGridBagConstraints.gridx = 0;
    proxyGridBagConstraints.gridy++;
    proxyGridBagLayout.setConstraints(proxyTypeLabel, proxyGridBagConstraints);
    proxyPanel.add(proxyTypeLabel);

    JComboBox proxyTypeComboBox = new JComboBox(new Object[] { Proxy.Type.HTTP, Proxy.Type.SOCKS });
    proxyTypeComboBox.setSelectedItem(this.proxyType);
    proxyGridBagConstraints.gridx++;
    proxyGridBagLayout.setConstraints(proxyTypeComboBox, proxyGridBagConstraints);
    proxyPanel.add(proxyTypeComboBox);

    int dialogResult = JOptionPane.showConfirmDialog(this, tabbedPane, "Preferences",
            JOptionPane.OK_CANCEL_OPTION);
    if (dialogResult == JOptionPane.CANCEL_OPTION) {
        return;
    }

    this.statusBar.setStatus("Applying new preferences...");
    this.proxyHost = proxyHostTextField.getText();
    this.proxyPort = Integer.parseInt(proxyPortTextField.getText());
    this.proxyType = (Proxy.Type) proxyTypeComboBox.getSelectedItem();
    this.proxyEnable = proxyEnableCheckBox.isSelected();
}

From source file:strobe.spectroscopy.StrobeSpectroscopy.java

private void btnSetZeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSetZeroActionPerformed
    int result = JOptionPane.showConfirmDialog(this, OPTION_PANE_TEXT, btnSetZero.getText(),
            JOptionPane.OK_CANCEL_OPTION);

    if (result == JOptionPane.OK_OPTION) {
        //Get a noise current level and assign it to darkCurrent variable
        return;//from   w ww .ja v  a  2  s  .com
    }
}

From source file:net.sf.nmedit.nomad.core.Nomad.java

public void fileSave(boolean saveAs) {
    Document d = pageContainer.getSelection();
    if (d == null)
        return;/*from  w w  w .j  a va  2  s.co  m*/

    if (!saveAs) {
        Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class);
        FileService useService = null;
        while (iter.hasNext()) {
            FileService fs = iter.next();
            if (fs.isDirectSaveOperationSupported(d)) {
                useService = fs;
                break;
            }
        }

        if (useService != null) {
            useService.save(d, useService.getAssociatedFile(d));
            return;
        }
    }

    JFileChooser chooser = new JFileChooser();
    chooser.setSelectedFile(lastSaveInFolderLocation);
    chooser.setMultiSelectionEnabled(false);

    Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class);
    while (iter.hasNext()) {
        FileService fs = iter.next();

        boolean add = (saveAs && fs.isSaveOperationSupported(d))
                || ((!saveAs) && fs.isDirectSaveOperationSupported(d));

        if (add)
            chooser.addChoosableFileFilter(fs.getFileFilter());
    }

    File sfile = d.getFile();
    if (sfile == null && d.getTitle() != null)
        sfile = new File(d.getTitle());
    if (sfile != null)
        chooser.setSelectedFile(sfile);

    if (!(chooser.showSaveDialog(mainWindow) == JFileChooser.APPROVE_OPTION))
        return;

    FileService service = FileServiceTool.lookupFileService(chooser);

    if (service != null) {
        File newFile = chooser.getSelectedFile();
        if (newFile == null)
            return;

        if (newFile.exists() && JOptionPane.showConfirmDialog(mainWindow,
                "Overwrite existing file '" + newFile.getAbsolutePath() + "' ?", "File already exists.",
                JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION)
            return;

        service.save(d, newFile);

        lastSaveInFolderLocation = newFile.getParentFile();
    } else {
        JOptionPane.showMessageDialog(mainWindow, "Could not find service to save file.");
    }
}