Example usage for javax.swing JOptionPane CANCEL_OPTION

List of usage examples for javax.swing JOptionPane CANCEL_OPTION

Introduction

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

Prototype

int CANCEL_OPTION

To view the source code for javax.swing JOptionPane CANCEL_OPTION.

Click Source Link

Document

Return value from class method if CANCEL is chosen.

Usage

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/*  w ww .  j  a v a2s. c om*/
        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:de.juwimm.cms.gui.admin.PanUnitGroupPerUser.java

public boolean exitPerformed(ExitEvent e) {
    try {//from  w w w. j  a  v a2  s .  com
        if (unitPickData.isModified() || groupPickData.isModified()) {
            int i = JOptionPane.showConfirmDialog(this, rb.getString("dialog.wantToSave"),
                    rb.getString("dialog.title"), JOptionPane.YES_NO_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
            if (i == JOptionPane.YES_OPTION) {
                saveChanges(currentSelected);
            } else if (i == JOptionPane.CANCEL_OPTION) {
                return false;
            }
        }
    } catch (Exception ex) {
    }
    return true;
}

From source file:strobe.spectroscopy.StrobeSpectroscopy.java

private void menuFileSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFileSaveActionPerformed
    int result = fileChooser.showSaveDialog(this);

    if (result == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        if (selectedFile.exists()) {
            int resultOverride = JOptionPane.showConfirmDialog(this, "File is already exists.", "Rewrite file?",
                    JOptionPane.YES_NO_CANCEL_OPTION);

            switch (resultOverride) {
            case JOptionPane.NO_OPTION:
                menuFileSaveActionPerformed(evt);
                return;
            case JOptionPane.CANCEL_OPTION:
                fileChooser.cancelSelection();
                return;
            }/*  w w w .  j  a  v  a 2 s .  co m*/

            fileChooser.approveSelection();
        }
        String name = selectedFile.getName();

        String fileNameForSave = (name.contains(".txt") ? selectedFile.getPath()
                : selectedFile.getPath() + ".txt");

        if (!dataGraphList.isEmpty()) {
            DataUtils.writeData(dataGraphList, fileNameForSave);
        } else {
            JOptionPane.showMessageDialog(this, "No data to write!");
            fileChooser.cancelSelection();
        }
    }
    dataGraphList.clear();
}

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

/**
 *
 *
 * @param sftp//  w w  w. j a v a2 s . com
 * @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:com.jvms.i18neditor.editor.Editor.java

public boolean closeCurrentProject() {
    boolean result = true;
    if (dirty) {//from www . j ava  2 s  . co  m
        int confirm = JOptionPane.showConfirmDialog(this, MessageBundle.get("dialogs.save.text"),
                MessageBundle.get("dialogs.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
        if (confirm == JOptionPane.YES_OPTION) {
            result = saveProject();
        } else {
            result = confirm != JOptionPane.CANCEL_OPTION;
        }
    }
    if (result && project != null) {
        storeProjectState();
    }
    if (result && dirty) {
        setDirty(false);
    }
    return result;
}

From source file:de.ailis.xadrian.frames.MainFrame.java

/**
 * Closes the current tab. Prompts for saving unsaved changes before
 * closing. Returns true if the tab was closed or false if it was not
 * closed.//from   www  .  j  a va 2  s. com
 *
 * @return True if tab was closed, false if not
 */
public boolean closeCurrentTab() {
    final Component current = getCurrentTab();
    if (current != null) {
        final ComplexEditor editor = (ComplexEditor) current;
        if (editor.isChanged()) {
            final int answer = JOptionPane.showConfirmDialog(null,
                    I18N.getString("confirm.saveChanges", editor.getComplex().getName()),
                    I18N.getTitle("confirm.saveChanges"), JOptionPane.YES_NO_CANCEL_OPTION);
            if (answer == JOptionPane.CLOSED_OPTION)
                return false;
            if (answer == JOptionPane.CANCEL_OPTION)
                return false;
            if (answer == JOptionPane.YES_OPTION) {
                editor.save();
                if (editor.isChanged())
                    return false;
            }
        }

        this.tabs.remove(current);

        // Replace the tab control with the welcome panel if no tabs present
        if (this.tabs.getTabCount() == 0) {
            remove(this.tabs);
            add(this.welcomePanel, BorderLayout.CENTER);
            repaint();
        }

        fireChange();
        return true;
    }
    return false;
}

From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java

private JFrame createJDialog(final String titulo) {
    final JFrame d = new JFrame(titulo);
    d.setResizable(false);/*from   ww w .jav  a2s .  com*/
    d.setAlwaysOnTop(true);
    d.setIconImage(window.getIconImage());
    d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    d.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            if (cambios) {
                int res = JOptionPane.showConfirmDialog(d,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION);
                if (res != JOptionPane.CANCEL_OPTION) {
                    e.getWindow().dispose();
                }
            } else {
                e.getWindow().dispose();
            }
        }
    });
    d.setLayout(new BorderLayout(5, 5));
    d.setBackground(Color.WHITE);
    d.getContentPane().setBackground(Color.WHITE);
    return d;
}

From source file:com.dragoniade.deviantart.favorites.FavoritesDownloader.java

private String getDocumentUrl(Deviation da, AtomicBoolean download) {
    String downloadUrl = da.getDocumentDownloadUrl();
    GetMethod method = new GetMethod(downloadUrl);

    try {//from w ww.  ja v a 2  s.c om
        int sc = -1;
        do {
            method.setFollowRedirects(false);
            sc = client.executeMethod(method);
            requestCount++;

            if (sc >= 300 && sc <= 399) {
                String location = method.getResponseHeader("Location").getValue();
                method.releaseConnection();
                return location;
            } else {
                LoggableException ex = new LoggableException(method.getResponseBodyAsString());
                Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex);

                int res = showConfirmDialog(owner,
                        "An error has occured when contacting deviantART : error " + sc + ". Try again?",
                        "Continue?", JOptionPane.YES_NO_CANCEL_OPTION);
                if (res == JOptionPane.NO_OPTION) {
                    String text = "<br/><a style=\"color:red;\" href=\"" + da.getUrl() + "\">" + downloadUrl
                            + " has an error" + "</a>";
                    setPaneText(text);
                    method.releaseConnection();
                    progress.incremTotal();
                    download.set(false);
                    return null;
                }
                if (res == JOptionPane.CANCEL_OPTION) {
                    return null;
                }
            }
        } while (true);
    } catch (HttpException e) {
        showMessageDialog(owner, "Error contacting deviantART: " + e.getMessage(), "Error",
                JOptionPane.ERROR_MESSAGE);
        return null;
    } catch (IOException e) {
        showMessageDialog(owner, "Error contacting deviantART: " + e.getMessage(), "Error",
                JOptionPane.ERROR_MESSAGE);
        return null;
    }
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public boolean closeCurrentSession() {
    if (isDirty()) {
        int result = JOptionPane.showConfirmDialog(this, MessageBundle.get("dialogs.save.text"),
                MessageBundle.get("dialogs.save.title"), JOptionPane.YES_NO_CANCEL_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            saveResources();/*from w  w w .j  av  a2 s .c  om*/
        }
        return result != JOptionPane.CANCEL_OPTION;
    }
    return true;
}

From source file:com.projity.pm.task.ProjectFactory.java

/**
 * @param project//ww  w  .  j  av  a  2  s. c  o m
 * @param allowCancel
 * @param prompt
 * @return null if cancelled
 */
public Job getRemoveProjectJob(final Project project, boolean allowCancel, boolean prompt,
        boolean calledFromSwing) {
    Job job = null;
    if (prompt && project.needsSaving()) {
        //         final boolean[] lock=new boolean[]{false};
        //            SwingUtilities.invokeLater(new Runnable(){
        //               public void run(){
        //                  Alert.okCancel("test");
        //                  synchronized (lock) {
        //                     lock[0]=true;
        //                     lock.notifyAll();
        //                  }
        //                }
        //            });
        //         synchronized(lock){
        //            while (!lock[0]){
        //               try{
        //                     lock.wait();
        //                  }catch (InterruptedException e) {}
        //            }
        //         }

        int promptResult = promptForSave(project, allowCancel);
        if (promptResult == JOptionPane.YES_OPTION) {
            SaveOptions opt = new SaveOptions();
            opt.setLocal(project.isLocal());
            if (project.isLocal()) {
                String fileName = project.getFileName();
                if (fileName == null) {
                    fileName = SessionFactory.getInstance().getLocalSession().chooseFileName(true,
                            project.getGuessedFileName());
                }
                if (fileName == null)
                    return null;
                project.setFileName(fileName);
                opt.setFileName(fileName);
                opt.setImporter(LocalSession.getImporter(project.getFileType()));
            }
            job = getSaveProjectJob(project, opt);
        } else if (promptResult == JOptionPane.CANCEL_OPTION)
            return null;
    }

    final ArrayList toRemove = new ArrayList();
    final ArrayList projects = new ArrayList();
    DeepChildWalker.recursivelyTreatBranch(portfolio.getNodeModel(), project, new Closure() {
        public void execute(Object arg0) {
            Node node = (Node) arg0;
            Object impl = node.getImpl();
            if (!(impl instanceof Project))
                return;
            final Project p = (Project) impl;
            toRemove.add(node);
            if (Environment.getStandAlone() || project.isLockable()) {
                projects.add(p);
            }
        }
    });

    Job closeProjectJob = getCloseProjectsOnServerJob(projects);
    if (closeProjectJob == null) {
        closeProjectJob = new Job(SessionFactory.getInstance().getJobQueue(), "closeProjects", "Closing...",
                false);

    }
    if (job == null)
        job = closeProjectJob;
    else
        job.addJob(closeProjectJob);

    job.addRunnable(new JobRunnable("Local: closeProjects") {
        public Object run() throws Exception {
            Iterator i = toRemove.iterator();
            while (i.hasNext()) {
                Node node = (Node) i.next();
                Project p = (Project) node.getImpl();
                portfolio.handleExternalTasks(p, false, false); // external link handling
                p.getResourcePool().removeProject(p);
                p.disconnect();
                portfolio.getObjectEventManager().fireDeleteEvent(this, p);
                portfolio.getNodeModel().remove(node, NodeModel.EVENT);

                removeClosingProject(project.getUniqueId());
            }
            System.gc(); // clean up memory used by projects
            return null; //return not used anyway
        }
    }, /*!calledFromSwing*/false, false, calledFromSwing, false);
    return job;
}