List of usage examples for javax.swing JOptionPane CANCEL_OPTION
int CANCEL_OPTION
To view the source code for javax.swing JOptionPane CANCEL_OPTION.
Click Source Link
From source file:cl.almejo.vsim.gui.SimWindow.java
public void quit() { if (askSureToQuit() == JOptionPane.YES_OPTION) { if (_circuit != null && _circuit.isModified()) { int saveBeforeQuit = askSaveBeforeQuit(); if (saveBeforeQuit == JOptionPane.CANCEL_OPTION) { return; }//ww w. ja v a 2s.c om if (saveBeforeQuit == JOptionPane.YES_OPTION) { if (saveAs() == JOptionPane.CANCEL_OPTION) { LOGGER.info("save cancelled by user."); return; } } } if (_circuit != null) { _circuit.remove(_canvas); } System.exit(0); } }
From source file:jboost.visualization.HistogramFrame.java
private File selectPDFFile() { File fFile = new File("default.pdf"); JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(new FileFilter() { public boolean accept(File f) { String path = f.getAbsolutePath(); if (f.isDirectory() || path.endsWith(".pdf")) return true; else/* ww w. ja v a 2s .c o m*/ return false; } public String getDescription() { return "PDF Files"; } }); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return null; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) return null; } return fFile; } else { return null; } }
From source file:jboost.visualization.HistogramFrame.java
private File selectDumpFile() { File fFile = new File("ExamplesDumpFile.txt"); JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(new FileFilter() { public boolean accept(File f) { String path = f.getAbsolutePath(); if (f.isDirectory() || path.endsWith(".txt")) return true; else//from w w w. j a v a 2s .co m return false; } public String getDescription() { return "Text Files"; } }); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return null; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) return null; } return fFile; } else { return null; } }
From source file:be.agiv.security.demo.Main.java
private void ipStsIssueToken() { GridBagLayout gridBagLayout = new GridBagLayout(); GridBagConstraints gridBagConstraints = new GridBagConstraints(); JPanel contentPanel = new JPanel(gridBagLayout); JLabel urlLabel = new JLabel("URL:"); gridBagConstraints.gridx = 0;//from ww w . j av a2 s. c o m gridBagConstraints.gridy = 0; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.ipadx = 5; gridBagLayout.setConstraints(urlLabel, gridBagConstraints); contentPanel.add(urlLabel); JTextField urlTextField = new JTextField( "https://auth.beta.agiv.be/ipsts/Services/DaliSecurityTokenServiceConfiguration.svc/IWSTrust13", 60); gridBagConstraints.gridx++; gridBagLayout.setConstraints(urlTextField, gridBagConstraints); contentPanel.add(urlTextField); 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); CredentialPanel credentialPanel = new CredentialPanel(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy++; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(credentialPanel, gridBagConstraints); contentPanel.add(credentialPanel); int result = JOptionPane.showConfirmDialog(this, contentPanel, "IP-STS Issue Token", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.CANCEL_OPTION) { return; } String location = urlTextField.getText(); String username = credentialPanel.getUsername(); String password = credentialPanel.getPassword(); File pkcs12File = credentialPanel.getPKCS12File(); String realm = realmTextField.getText(); IPSTSClient ipStsClient = new IPSTSClient(location, realm); try { if (null != username) { this.ipStsSecurityToken = ipStsClient.getSecurityToken(username, password); } else { KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(new FileInputStream(pkcs12File), password.toCharArray()); String alias = keyStore.aliases().nextElement(); X509Certificate certificate = (X509Certificate) keyStore.getCertificate(alias); PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray()); this.ipStsSecurityToken = ipStsClient.getSecuritytoken(certificate, privateKey); } this.ipStsViewMenuItem.setEnabled(true); this.rStsIssueMenuItem.setEnabled(true); ipStsViewToken(); } catch (Exception e) { showException(e); } }
From source file:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java
/** * @return true if no unsaved changes are present * else return results of prompt to save *///from www . j a va 2s . c o m protected boolean checkForChanges() { // if (termList != null) // { // int s = termList.getSelectedIndex(); // if (s != -1) // { // L10NItem entry = srcFile.getKey(s); // entry.setDstStr(textField.getText()); // } // if (srcFile.isEdited()) // { // int response = JOptionPane.showOptionDialog((Frame )getTopWindow(), // String.format(getResourceString("StrLocalizerApp.SaveChangesMsg"), destFile.getPath()), // getResourceString("StrLocalizerApp.SaveChangesTitle"), // JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.YES_OPTION); // if (response == JOptionPane.CANCEL_OPTION) // { // return false; // } // if (response == JOptionPane.YES_OPTION) // { // doSave(); // return true; //what if it fails? // } // } // return true; // } boolean hasChanges = false; for (L10NFile f : srcFiles) { if (f.isChanged()) { hasChanges = true; break; } } if (hasChanges) { int response = JOptionPane.showOptionDialog((Frame) getTopWindow(), "Changes have not been saved.\n\nDo you wish to save them?", getResourceString("StrLocalizerApp.SaveChangesTitle"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.YES_OPTION); if (response == JOptionPane.CANCEL_OPTION) { return false; } if (response == JOptionPane.YES_OPTION) { doSave(); return true; //what if it fails? } } return true; }
From source file:edu.ku.brc.ui.UIRegistry.java
/** * Asks Yes, No, Cancel question using a JOptionPane * @param yesKey the resource key for the Yes button * @param noKey the resource key for the No button * @param cancelKey the resource key for the Cancel button * @param nonL10NMsg the message or question NOT Localized * @param titleKey the resource key for the Dialog Title * @return JOptionPane.NO_OPTION or JOptionPane.YES_OPTION *//* www .j a va 2 s . c o m*/ public static int askYesNoLocalized(final String yesKey, final String noKey, final String cancelKey, final String nonL10NMsg, final String titleKey) { int userChoice = JOptionPane.CANCEL_OPTION; Object[] options = { getResourceString(yesKey), getResourceString(noKey), getResourceString(cancelKey) }; userChoice = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(), nonL10NMsg, getResourceString(titleKey), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); return userChoice; }
From source file:canreg.client.gui.analysis.ExportReportInternalFrame.java
/** * * @return//from ww w .jav a2 s . c o m */ @Action public Task writeFileAction() { if (chooser == null) { path = localSettings.getProperty("export_data_path"); if (path == null) { chooser = new JFileChooser(); } else { chooser = new JFileChooser(path); } } // Get filename int returnVal = chooser.showSaveDialog(this); fileName = ""; String separatingString = "\t"; if (returnVal == JFileChooser.APPROVE_OPTION) { try { //set the file name fileName = chooser.getSelectedFile().getCanonicalPath(); // TODO: Make this dynamic if (fileFormatComboBox.getSelectedIndex() == 0) { separatingString = ","; // append standard file extension if (!(fileName.endsWith(".csv") || fileName.endsWith(".CSV"))) { fileName += ".csv"; } } else { if (fileFormatComboBox.getSelectedIndex() == 1) { separatingString = "\t"; } else { separatingString = fileFormatComboBox.getSelectedItem().toString(); } // append standard file extension if (!(fileName.endsWith(".tsv") || fileName.endsWith(".TSV")) && !(fileName.endsWith(".csv") || fileName.endsWith(".CSV")) && !(fileName.endsWith(".txt") || fileName.endsWith(".TXT"))) { fileName += ".txt"; } } File file = new File(fileName); if (file.exists()) { int choice = JOptionPane.showInternalConfirmDialog( CanRegClientApp.getApplication().getMainFrame().getContentPane(), java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/ExportReportInternalFrame") .getString("FILE_EXISTS") + ": " + fileName + ".\n" + java.util.ResourceBundle.getBundle( "canreg/client/gui/analysis/resources/ExportReportInternalFrame") .getString("OVERWRITE?"), java.util.ResourceBundle .getBundle("canreg/client/gui/analysis/resources/ExportReportInternalFrame") .getString("FILE_EXISTS") + ".", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice == JOptionPane.CANCEL_OPTION) { return null; } else if (choice == JOptionPane.NO_OPTION) { // choose a new file writeFileAction(); return null; } } } catch (IOException ex) { Logger.getLogger(ExportReportInternalFrame.class.getName()).log(Level.SEVERE, null, ex); } } else { return null; } return new WriteFileActionTask(fileName, org.jdesktop.application.Application.getInstance(canreg.client.CanRegClientApp.class), separatingString); }
From source file:net.sf.jabref.gui.JabRefFrame.java
/** * General info dialog. The MacAdapter calls this method when "Quit" * is selected from the application menu, Cmd-Q is pressed, or "Quit" is selected from the Dock. * The function returns a boolean indicating if quitting is ok or not. * <p>/*from w w w . j a va 2 s . c om*/ * Non-OSX JabRef calls this when choosing "Quit" from the menu * <p> * SIDE EFFECT: tears down JabRef * * @return true if the user chose to quit; false otherwise */ public boolean quit() { // Ask here if the user really wants to close, if the base // has not been saved since last save. boolean close = true; List<String> filenames = new ArrayList<>(); if (tabbedPane.getTabCount() > 0) { for (int i = 0; i < tabbedPane.getTabCount(); i++) { if (getBasePanelAt(i).isModified()) { tabbedPane.setSelectedIndex(i); String filename; if (getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile() == null) { filename = GUIGlobals.UNTITLED_TITLE; } else { filename = getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile().getAbsolutePath(); } int answer = showSaveDialog(filename); if ((answer == JOptionPane.CANCEL_OPTION) || (answer == JOptionPane.CLOSED_OPTION)) { return false; } if (answer == JOptionPane.YES_OPTION) { // The user wants to save. try { //getCurrentBasePanel().runCommand("save"); SaveDatabaseAction saveAction = new SaveDatabaseAction(getCurrentBasePanel()); saveAction.runCommand(); if (saveAction.isCanceled() || !saveAction.isSuccess()) { // The action was either canceled or unsuccessful. // Break! output(Localization.lang("Unable to save database")); close = false; } } catch (Throwable ex) { // Something prevented the file // from being saved. Break!!! close = false; break; } } } if (getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile() != null) { filenames.add(getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile().getAbsolutePath()); } } } if (close) { for (int i = 0; i < tabbedPane.getTabCount(); i++) { if (getBasePanelAt(i).isSaving()) { // There is a database still being saved, so we need to wait. WaitForSaveOperation w = new WaitForSaveOperation(this); w.show(); // This method won't return until canceled or the save operation is done. if (w.canceled()) { return false; // The user clicked cancel. } } } tearDownJabRef(filenames); return true; } return false; }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * Checks to see if it is time to do a weekly or monthly backup. Weeks are rolling 7 days and months * are rolling 30 days.//from w w w . jav a 2s.c o m * @param doSendExit requests to send an application exit command * @param doSkipAsk indicates whether to skip asking the user thus forcing the backup if it is time * @return true if the backup was started, false if it wasn't started. */ private boolean checkForBackUp(final boolean doSendExit, final boolean doSkipAsk) { final long oneDayMilliSecs = 86400000; Calendar calNow = Calendar.getInstance(); Date dateNow = calNow.getTime(); Long timeDays = getLastBackupTime(WEEKLY_PREF); if (timeDays == null) { timeDays = dateNow.getTime(); saveLastBackupTime(WEEKLY_PREF, dateNow.getTime()); } Long timeMons = getLastBackupTime(MONTHLY_PREF); if (timeMons == null) { timeMons = dateNow.getTime(); saveLastBackupTime(MONTHLY_PREF, dateNow.getTime()); } Date lastBackUpDays = new Date(timeDays); Date lastBackUpMons = new Date(timeMons); int diffMons = (int) ((dateNow.getTime() - lastBackUpMons.getTime()) / oneDayMilliSecs); int diffDays = (int) ((dateNow.getTime() - lastBackUpDays.getTime()) / oneDayMilliSecs); int diff = 0; String key = null; boolean isMonthly = false; if (diffMons > 30) { key = "MySQLBackupService.MONTHLY"; diff = diffMons; isMonthly = true; } else if (diffDays > 7) { key = "MySQLBackupService.WEEKLY"; diff = diffDays; } int userChoice = JOptionPane.CANCEL_OPTION; if (key != null && (UIRegistry.isEmbedded() || !doSkipAsk)) { if (UIRegistry.isEmbedded()) { showEZDBBackupMessage(key, diff); } else { Object[] options = { getResourceString("MySQLBackupService.BACKUP_NOW"), //$NON-NLS-1$ getResourceString("MySQLBackupService.BK_SKIP") //$NON-NLS-1$ }; userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), getLocalizedMessage(key, diff), //$NON-NLS-1$ getResourceString("MySQLBackupService.BK_NOW_TITLE"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); } } if (isMonthly) { saveLastBackupTime(MONTHLY_PREF, dateNow.getTime()); if (diffDays > 7) { saveLastBackupTime(WEEKLY_PREF, dateNow.getTime()); } } else { saveLastBackupTime(WEEKLY_PREF, dateNow.getTime()); } if (!UIRegistry.isEmbedded() && (userChoice == JOptionPane.YES_OPTION || doSkipAsk)) { return doBackUp(isMonthly, doSendExit, null); } return false; }
From source file:net.rptools.maptool.client.functions.InputFunction.java
@Override public Object childEvaluate(Parser parser, String functionName, List<Object> parameters) throws EvaluationException, ParserException { // Extract the list of specifier strings from the parameters // "name | value | prompt | inputType | options" List<String> varStrings = new ArrayList<String>(); for (Object param : parameters) { String paramStr = (String) param; if (StringUtils.isEmpty(paramStr)) { continue; }/* w w w . j av a2 s.c om*/ // Multiple vars can be packed into a string, separated by "##" List<String> substrings = new ArrayList<String>(); StrListFunctions.parse(paramStr, substrings, "##"); for (String varString : substrings) { if (StringUtils.isEmpty(paramStr)) { continue; } varStrings.add(varString); } } // Create VarSpec objects from each variable's specifier string List<VarSpec> varSpecs = new ArrayList<VarSpec>(); for (String specifier : varStrings) { VarSpec vs; try { vs = new VarSpec(specifier); } catch (VarSpec.SpecifierException se) { throw new ParameterException(se.msg); } catch (InputType.OptionException oe) { throw new ParameterException(I18N.getText("macro.function.input.invalidOptionType", oe.key, oe.value, oe.type, specifier)); } varSpecs.add(vs); } // Check if any variables were defined if (varSpecs.isEmpty()) return BigDecimal.ONE; // No work to do, so treat it as a successful invocation. // UI step 1 - First, see if a token is in context. VariableResolver varRes = parser.getVariableResolver(); Token tokenInContext = null; if (varRes instanceof MapToolVariableResolver) { tokenInContext = ((MapToolVariableResolver) varRes).getTokenInContext(); } String dialogTitle = "Input Values"; if (tokenInContext != null) { String name = tokenInContext.getName(), gm_name = tokenInContext.getGMName(); boolean isGM = MapTool.getPlayer().isGM(); String extra = ""; if (isGM && gm_name != null && gm_name.compareTo("") != 0) extra = " for " + gm_name; else if (name != null && name.compareTo("") != 0) extra = " for " + name; dialogTitle = dialogTitle + extra; } // UI step 2 - build the panel with the input fields InputPanel ip = new InputPanel(varSpecs); // Calculate the height // TODO: remove this workaround int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int maxHeight = screenHeight * 3 / 4; Dimension ipPreferredDim = ip.getPreferredSize(); if (maxHeight < ipPreferredDim.height) { ip.modifyMaxHeightBy(maxHeight - ipPreferredDim.height); } // UI step 3 - show the dialog JOptionPane jop = new JOptionPane(ip, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dlg = jop.createDialog(MapTool.getFrame(), dialogTitle); // Set up callbacks needed for desired runtime behavior dlg.addComponentListener(new FixupComponentAdapter(ip)); dlg.setVisible(true); int dlgResult = JOptionPane.CLOSED_OPTION; try { dlgResult = (Integer) jop.getValue(); } catch (NullPointerException npe) { } dlg.dispose(); if (dlgResult == JOptionPane.CANCEL_OPTION || dlgResult == JOptionPane.CLOSED_OPTION) return BigDecimal.ZERO; // Finally, assign values from the dialog box to the variables for (ColumnPanel cp : ip.columnPanels) { List<VarSpec> panelVars = cp.varSpecs; List<JComponent> panelControls = cp.inputFields; int numPanelVars = panelVars.size(); StringBuilder allAssignments = new StringBuilder(); // holds all values assigned in this tab for (int varCount = 0; varCount < numPanelVars; varCount++) { VarSpec vs = panelVars.get(varCount); JComponent comp = panelControls.get(varCount); String newValue = null; switch (vs.inputType) { case TEXT: { newValue = ((JTextField) comp).getText(); break; } case LIST: { Integer index = ((JComboBox) comp).getSelectedIndex(); if (vs.optionValues.optionEquals("VALUE", "STRING")) { newValue = vs.valueList.get(index); } else { // default is "NUMBER" newValue = index.toString(); } break; } case CHECK: { Integer value = ((JCheckBox) comp).isSelected() ? 1 : 0; newValue = value.toString(); break; } case RADIO: { // This code assumes that the Box container returns components // in the same order that they were added. Component[] comps = ((Box) comp).getComponents(); int componentCount = 0; Integer index = 0; for (Component c : comps) { if (c instanceof JRadioButton) { JRadioButton radio = (JRadioButton) c; if (radio.isSelected()) index = componentCount; } componentCount++; } if (vs.optionValues.optionEquals("VALUE", "STRING")) { newValue = vs.valueList.get(index); } else { // default is "NUMBER" newValue = index.toString(); } break; } case LABEL: { newValue = null; // The variable name is ignored and not set. break; } case PROPS: { // Read out and assign all the subvariables. // The overall return value is a property string (as in StrPropFunctions.java) with all the new settings. Component[] comps = ((JPanel) comp).getComponents(); StringBuilder sb = new StringBuilder(); int setVars = 0; // "NONE", no assignments made if (vs.optionValues.optionEquals("SETVARS", "SUFFIXED")) setVars = 1; if (vs.optionValues.optionEquals("SETVARS", "UNSUFFIXED")) setVars = 2; if (vs.optionValues.optionEquals("SETVARS", "TRUE")) setVars = 2; // for backward compatibility for (int compCount = 0; compCount < comps.length; compCount += 2) { String key = ((JLabel) comps[compCount]).getText().split("\\:")[0]; // strip trailing colon String value = ((JTextField) comps[compCount + 1]).getText(); sb.append(key); sb.append("="); sb.append(value); sb.append(" ; "); switch (setVars) { case 0: // Do nothing break; case 1: parser.setVariable(key + "_", value); break; case 2: parser.setVariable(key, value); break; } } newValue = sb.toString(); break; } default: // should never happen newValue = null; break; } // Set the variable to the value we got from the dialog box. if (newValue != null) { parser.setVariable(vs.name, newValue.trim()); allAssignments.append(vs.name + "=" + newValue.trim() + " ## "); } } if (cp.tabVarSpec != null) { parser.setVariable(cp.tabVarSpec.name, allAssignments.toString()); } } return BigDecimal.ONE; // success // for debugging: //return debugOutput(varSpecs); }