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:edu.ku.brc.specify.dbsupport.TaskSemaphoreMgr.java

/**
 * Locks the semaphore.//from  w w  w . j  a  v  a  2s. c  o m
 * @param title The human (localized) title of the task 
 * @param name the unique name
 * @param context
 * @param scope the scope of the lock
 * @param allViewMode allows it to ask the user about 'View Only'
 * @return
 */
public static USER_ACTION lock(final String title, final String name, final String context, final SCOPE scope,
        final boolean allViewMode, final TaskSemaphoreMgrCallerIFace caller, final boolean checkUsage) {
    DataProviderSessionIFace session = null;
    try {
        session = DataProviderFactory.getInstance().createSession();

        int count = 0;
        do {

            SpTaskSemaphore semaphore = null;
            try {
                semaphore = setLock(session, name, context, scope, true, false, checkUsage);

            } catch (StaleObjectException ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TaskSemaphoreMgr.class, ex);
                semaphore = null;
            }

            if (semaphore == null || previouslyLocked) {
                if (caller != null) {
                    return caller.resolveConflict(semaphore, previouslyLocked, prevLockedBy);
                }

                if (semaphore == null) {
                    String msg = UIRegistry.getLocalizedMessage("SpTaskSemaphore.IN_USE", title);//$NON-NLS-1$
                    Object[] options = { getResourceString("SpTaskSemaphore.TRYAGAIN"), //$NON-NLS-1$
                            getResourceString("CANCEL") //$NON-NLS-1$
                    };
                    int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), msg,
                            getResourceString("SpTaskSemaphore.IN_USE_TITLE"), //$NON-NLS-1$
                            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                    if (userChoice == JOptionPane.NO_OPTION) {
                        return USER_ACTION.Cancel;
                    }

                } else {
                    // Check to see if we have the same user on the same machine.
                    SpecifyUser user = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
                    String currMachineName = InetAddress.getLocalHost().toString();
                    String dbMachineName = semaphore.getMachineName();

                    //System.err.println("["+dbMachineName+"]["+currMachineName+"]["+user.getId()+"]["+semaphore.getOwner().getId()+"]");
                    if (StringUtils.isNotEmpty(dbMachineName) && StringUtils.isNotEmpty(currMachineName)
                            && currMachineName.equals(dbMachineName) && semaphore.getOwner() != null
                            && user != null && user.getId().equals(semaphore.getOwner().getId())) {
                        if (allViewMode) {
                            int options = JOptionPane.YES_NO_OPTION;
                            Object[] optionLabels = new String[] {
                                    getResourceString("SpTaskSemaphore.VIEWMODE"), //$NON-NLS-1$
                                    getResourceString("CANCEL")//$NON-NLS-1$
                            };
                            int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
                                    getLocalizedMessage("SpTaskSemaphore.IN_USE_BY_YOU", title),
                                    getResourceString("SpTaskSemaphore.IN_USE_TITLE"), //$NON-NLS-1$
                                    options, JOptionPane.QUESTION_MESSAGE, null, optionLabels, 0);

                            return userChoice == JOptionPane.NO_OPTION ? USER_ACTION.Cancel
                                    : USER_ACTION.ViewMode; // CHECKED
                        }

                        int options = JOptionPane.OK_OPTION;
                        Object[] optionLabels = new String[] { getResourceString("OK")//$NON-NLS-1$
                        };
                        JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
                                getLocalizedMessage("SpTaskSemaphore.IN_USE_BY_YOU", title),
                                getResourceString("SpTaskSemaphore.IN_USE_TITLE"), //$NON-NLS-1$
                                options, JOptionPane.QUESTION_MESSAGE, null, optionLabels, 0);

                        return USER_ACTION.Cancel;
                    }

                    String userStr = prevLockedBy != null ? prevLockedBy
                            : semaphore.getOwner().getIdentityTitle();
                    String msgKey = allViewMode ? "SpTaskSemaphore.IN_USE_OV" : "SpTaskSemaphore.IN_USE";
                    String msg = UIRegistry.getLocalizedMessage(msgKey, title, userStr,
                            semaphore.getLockedTime() != null ? semaphore.getLockedTime().toString() : "");

                    int options;
                    int defBtn;
                    Object[] optionLabels;
                    if (allViewMode) {
                        defBtn = 2;
                        options = JOptionPane.YES_NO_CANCEL_OPTION;
                        optionLabels = new String[] { getResourceString("SpTaskSemaphore.VIEWMODE"), //$NON-NLS-1$
                                getResourceString("SpTaskSemaphore.TRYAGAIN"), //$NON-NLS-1$
                                getResourceString("CANCEL")//$NON-NLS-1$
                        };
                    } else {
                        defBtn = 0;
                        options = JOptionPane.YES_NO_OPTION;
                        optionLabels = new String[] { getResourceString("SpTaskSemaphore.TRYAGAIN"), //$NON-NLS-1$
                                getResourceString("CANCEL"), //$NON-NLS-1$
                        };
                    }

                    int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), msg,
                            getResourceString("SpTaskSemaphore.IN_USE_TITLE"), //$NON-NLS-1$
                            options, JOptionPane.QUESTION_MESSAGE, null, optionLabels, defBtn);
                    if (userChoice == JOptionPane.YES_OPTION) {
                        if (options == JOptionPane.YES_NO_CANCEL_OPTION) {
                            return USER_ACTION.ViewMode; // CHECKED
                        }
                        // this means try again

                    } else if (userChoice == JOptionPane.NO_OPTION) {
                        if (options == JOptionPane.YES_NO_OPTION) {
                            return USER_ACTION.Cancel;
                        }
                        // CHECKED

                    } else if (userChoice == JOptionPane.CANCEL_OPTION) {
                        return USER_ACTION.Cancel; // CHECKED
                    }
                }
            } else {
                return USER_ACTION.OK;
            }

            count++;

        } while (true);

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TaskSemaphoreMgr.class, ex);
        ex.printStackTrace();
        //log.error(ex);

    } finally {
        if (session != null) {
            session.close();
        }
    }
    return USER_ACTION.Error;
}

From source file:com.mirth.connect.client.ui.ChannelPanel.java

private boolean promptSave(boolean force) {
    int option;//from www .  j  av  a 2  s  .  c o m

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

    if (option == JOptionPane.YES_OPTION) {
        return doSaveGroups(false);
    } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION
            || (option == JOptionPane.NO_OPTION && force)) {
        return false;
    }

    return true;
}

From source file:biz.wolschon.finance.jgnucash.JGnucash.java

/**
 * {@inheritDoc}//from ww  w.  j  a  va 2  s  . co m
 */
@Override
protected void doExit() {
    if (hasChanged) {
        int state = JOptionPane.showConfirmDialog(this, "File has been changed. Save before exit?");
        if (state == JOptionPane.YES_OPTION) {
            saveFile();
        } else if (state == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }
    System.exit(0);
}

From source file:cl.almejo.vsim.gui.SimWindow.java

public void load() {
    if (_circuit != null && _circuit.isModified()) {
        int replace = askSaveNow();
        if (replace == JOptionPane.CANCEL_OPTION) {
            return;
        }//from www .j a va 2 s  .  c om
        if (replace == JOptionPane.YES_OPTION) {
            if (saveAs() == JOptionPane.CANCEL_OPTION) {
                LOGGER.info("save cancelled by user.");
            }
        }
    }
    try {
        if (OPEN_FILE_CHOOSER.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            File file = OPEN_FILE_CHOOSER.getSelectedFile();
            setCircuit(Circuit.fromJSon(FileUtils.readFileToString(file), file.getPath()));
            LOGGER.info("Loaded: " + file.getName() + ".");
            return;
        }
        LOGGER.info("load cancelled by user.");
    } catch (IOException exception) {
        exception.printStackTrace();
    }

}

From source file:com.openbravo.pos.sales.restaurant.JTicketsBagRestaurantRes.java

private void m_jbtnTablesActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_m_jbtnTablesActionPerformed

    try {/*from  ww  w . ja v a 2  s . c  o  m*/
        List l = dlCustomers.getReservationsList().list(new Date(), new Date());
        for (Object val : l) {
            Object[] e = (Object[]) val;
            if ((int) e[12] > 0) {
                // stay and check errors!!!
                if (JConfirmDialog.showConfirm(m_App, this, null,
                        AppLocal.getIntString("message.reservationconflicts")) == JOptionPane.CANCEL_OPTION) {
                    m_bd.refreshData();
                    return;
                } else {
                    break;
                }
            }
        }
    } catch (BasicException e) {
    }

    m_restaurantmap.viewTables();

}

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

private void invokeClaimsAwareService() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    JPanel contentPanel = new JPanel(gridBagLayout);

    final JLabel ipStsLabel = new JLabel("IP-STS:");
    gridBagConstraints.gridx = 0;/*from   w w w  .java  2  s. c  om*/
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.ipadx = 5;
    gridBagLayout.setConstraints(ipStsLabel, gridBagConstraints);
    contentPanel.add(ipStsLabel);

    final JTextField ipStsTextField = new JTextField(
            "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13",
            60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(ipStsTextField, gridBagConstraints);
    contentPanel.add(ipStsTextField);

    JLabel realmLabel = new JLabel("Realm:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(realmLabel, gridBagConstraints);
    contentPanel.add(realmLabel);

    JTextField realmTextField = new JTextField(AGIVSecurity.BETA_REALM, 30);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(realmTextField, gridBagConstraints);
    contentPanel.add(realmTextField);

    final CredentialPanel credentialPanel = new CredentialPanel();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(credentialPanel, gridBagConstraints);
    contentPanel.add(credentialPanel);

    final JLabel rStsLabel = new JLabel("R-STS:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = 1;
    gridBagLayout.setConstraints(rStsLabel, gridBagConstraints);
    contentPanel.add(rStsLabel);

    final JTextField rStsTextField = new JTextField(
            "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13",
            60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(rStsTextField, gridBagConstraints);
    contentPanel.add(rStsTextField);

    JLabel serviceRealmLabel = new JLabel("Service realm:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(serviceRealmLabel, gridBagConstraints);
    contentPanel.add(serviceRealmLabel);

    JTextField serviceRealmTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_REALM, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(serviceRealmTextField, gridBagConstraints);
    contentPanel.add(serviceRealmTextField);

    JLabel urlLabel = new JLabel("Service URL:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(urlLabel, gridBagConstraints);
    contentPanel.add(urlLabel);

    JTextField urlTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_LOCATION, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(urlTextField, gridBagConstraints);
    contentPanel.add(urlTextField);

    final JCheckBox noWsPolicyCheckBox = new JCheckBox("WSDL without WS-Policy");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(noWsPolicyCheckBox, gridBagConstraints);
    contentPanel.add(noWsPolicyCheckBox);

    final JCheckBox useWsSecureConversationCheckBox = new JCheckBox("Use WS-SecureConversation");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(useWsSecureConversationCheckBox, gridBagConstraints);
    contentPanel.add(useWsSecureConversationCheckBox);

    final JCheckBox usePreviousSecurityCheckBox = new JCheckBox("Use previous AGIV Security");
    final JCheckBox cancelPreviousSecureConversationToken = new JCheckBox("Cancel previous conversation token");
    usePreviousSecurityCheckBox.setEnabled(null != this.agivSecurity);
    cancelPreviousSecureConversationToken.setEnabled(false);
    usePreviousSecurityCheckBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            LOG.debug("use previous security: " + usePreviousSecurityCheckBox.isSelected());
            boolean newSecurity = !usePreviousSecurityCheckBox.isSelected();
            ipStsLabel.setEnabled(newSecurity);
            ipStsTextField.setEditable(newSecurity);
            credentialPanel.setEnabled(newSecurity);
            rStsLabel.setEnabled(newSecurity);
            rStsTextField.setEnabled(newSecurity);
            cancelPreviousSecureConversationToken.setEnabled(!newSecurity);
        }
    });
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(usePreviousSecurityCheckBox, gridBagConstraints);
    contentPanel.add(usePreviousSecurityCheckBox);

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(cancelPreviousSecureConversationToken, gridBagConstraints);
    contentPanel.add(cancelPreviousSecureConversationToken);

    JPanel expiresPanel = new JPanel();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = 2;
    gridBagLayout.setConstraints(expiresPanel, gridBagConstraints);
    contentPanel.add(expiresPanel);

    JLabel expiresLabelLabel = new JLabel("Secure conversation token expires:");
    expiresLabelLabel.setEnabled(null != this.agivSecurity);
    expiresPanel.add(expiresLabelLabel);

    JLabel expiresLabel = new JLabel();
    expiresLabel.setEnabled(null != this.agivSecurity);
    expiresPanel.add(expiresLabel);
    if (null != this.agivSecurity) {
        if (false == this.agivSecurity.getSecureConversationTokens().isEmpty()) {
            SecurityToken secureConversationToken = this.agivSecurity.getSecureConversationTokens().values()
                    .iterator().next();
            expiresLabel.setText(secureConversationToken.getExpires().toString());
        }
    }

    int dialogResult = JOptionPane.showConfirmDialog(this, contentPanel, "Claims Aware Service",
            JOptionPane.OK_CANCEL_OPTION);
    if (dialogResult == JOptionPane.CANCEL_OPTION) {
        return;
    }

    final String location = urlTextField.getText();
    final String serviceRealm = serviceRealmTextField.getText();
    final String ipStsLocation = ipStsTextField.getText();
    final String rStsLocation = rStsTextField.getText();
    final String username = credentialPanel.getUsername();
    final String password = credentialPanel.getPassword();
    final File pkcs12File = credentialPanel.getPKCS12File();
    final String realm = realmTextField.getText();

    ExecutorService executor = Executors.newFixedThreadPool(1);
    FutureTask<ArrayOfClaimInfo> futureTask = new FutureTask<ArrayOfClaimInfo>(
            new Callable<ArrayOfClaimInfo>() {

                public ArrayOfClaimInfo call() throws Exception {
                    Service service;
                    if (noWsPolicyCheckBox.isSelected()) {
                        service = ClaimsAwareServiceFactory.getInstanceNoWSPolicy();
                    } else {
                        service = ClaimsAwareServiceFactory.getInstance();
                    }
                    IService iservice = service.getWS2007FederationHttpBindingIService(new AddressingFeature());
                    BindingProvider bindingProvider = (BindingProvider) iservice;

                    if (false == usePreviousSecurityCheckBox.isSelected()) {
                        if (null != username) {
                            Main.this.agivSecurity = new AGIVSecurity(ipStsLocation, rStsLocation, realm,
                                    username, password);
                        } else {
                            Main.this.agivSecurity = new AGIVSecurity(ipStsLocation, rStsLocation, realm,
                                    pkcs12File, password);
                        }
                        Main.this.agivSecurity.addSTSListener(Main.this);
                        if (Main.this.proxyEnable) {
                            agivSecurity.setProxy(Main.this.proxyHost, Main.this.proxyPort,
                                    Main.this.proxyType);
                        }
                    }
                    if (cancelPreviousSecureConversationToken.isSelected()) {
                        Main.this.agivSecurity.cancelSecureConversationTokens();
                    }
                    Main.this.agivSecurity.enable(bindingProvider, location,
                            useWsSecureConversationCheckBox.isSelected(), serviceRealm);

                    ArrayOfClaimInfo result = iservice.getData(0);
                    return result;
                }
            }) {

        @Override
        protected void done() {
            try {
                ArrayOfClaimInfo result = get();
                List<ClaimInfo> claims = result.getClaimInfo();
                StringBuffer message = new StringBuffer();
                for (ClaimInfo claim : claims) {
                    message.append(claim.getName());
                    message.append(" = ");
                    message.append(claim.getValue());
                    message.append("\n");
                }

                JOptionPane.showMessageDialog(Main.this, message.toString(), "Claims Aware Service Result",
                        JOptionPane.INFORMATION_MESSAGE);
            } catch (final Exception e) {
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {

                        public void run() {
                            Main.this.statusBar.setErrorStatus(e.getMessage());
                        }
                    });
                } catch (Exception e1) {
                }
                showException(e);
            }
        }
    };
    executor.execute(futureTask);
}

From source file:Interfaz.rubiktimer.java

public void cerrar() {
    try {//from   w w  w . j  av  a2s .  c om
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent w) {

                int valor = JOptionPane.showConfirmDialog(null,
                        "Esta Seguro de cerrar la aplicacion?\nNota:  Asegurese de haber guardado los tiempos obtenidos ",
                        "Cerrar Rubik Cube Timer", JOptionPane.OK_CANCEL_OPTION);
                if (valor == JOptionPane.OK_OPTION) {
                    JOptionPane.showMessageDialog(null, "Gracias por usar Rubik Cube Timer", "Gracias",
                            JOptionPane.INFORMATION_MESSAGE);
                    System.exit(0);
                } else if (valor == JOptionPane.CANCEL_OPTION) {
                    System.out.println("Cnacelar Operacion de cerrar");
                }
            }
        });
        this.setVisible(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:cl.almejo.vsim.gui.SimWindow.java

public int saveAs() {
    SAVE_AS_FILE_CHOOSER.setSelectedFile(new File(_circuit.getName()));
    if (SAVE_AS_FILE_CHOOSER.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
        LOGGER.info("save cancelled by user.");
        return 0;
    }/*w ww  . j  a  va  2 s.co  m*/

    File file = SAVE_AS_FILE_CHOOSER.getSelectedFile();
    if (file.exists()) {
        if (askOverwrite() != JOptionPane.YES_OPTION) {
            return JOptionPane.CANCEL_OPTION;
        }
    }

    _circuit.setName(file.getPath());
    updateTitle();
    save(file.getPath());
    LOGGER.info("saved: " + file.getPath());
    return JOptionPane.OK_OPTION;
}

From source file:ca.uhn.hl7v2.testpanel.controller.Controller.java

public boolean saveAllMessagesAndReturnFalseIfCancelIsPressed() {

    for (Hl7V2MessageCollection next : myMessagesList.getMessages()) {
        if (next.isSaved() == false) {
            int save = showPromptToSaveMessageBeforeClosingIt(next, true);
            switch (save) {
            case JOptionPane.YES_OPTION:
                if (!saveMessages(next)) {
                    return false;
                }/*from ww w. j a  va  2 s  .c  om*/
                break;
            case JOptionPane.NO_OPTION:
                break;
            case JOptionPane.CANCEL_OPTION:
                return false;
            default:
                // shouldn't happen
                throw new Error("invalid option:" + save);
            }
        }
    }

    return true;
}

From source file:jeplus.gui.EPlusEditorPanel.java

@Override
public void closeTextPanel() {
    // Confirm save before open another file
    if (this.isContentChanged()) {
        int ans = JOptionPane.showConfirmDialog(this,
                "The contents of " + CurrentFileName + " has been modified. \nDo you want to save the changes?",
                "Save to file?", JOptionPane.YES_NO_CANCEL_OPTION);
        if (ans == JOptionPane.CANCEL_OPTION) {
            return;
        } else if (ans == JOptionPane.YES_OPTION) {
            this.cmdSaveActionPerformed(null);
        }/*  w  ww.  j  a v  a  2  s.  co m*/
    }
    if (ContainerComponent instanceof Frame) {
        ((Frame) ContainerComponent).dispose();
    } else if (ContainerComponent instanceof Dialog) {
        ((Dialog) ContainerComponent).dispose();
    } else if (ContainerComponent instanceof JTabbedPane && TabId > 0) {
        //((JTabbedPane)ContainerComponent).remove(this.TabId);
        ((JTabbedPane) ContainerComponent).remove(this);
        TabId = 0;
    }
}