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:net.sf.profiler4j.console.Console.java
public void disconnect() { if (!client.isConnected()) { return;//from w w w. ja v a 2s .co m } int ret = JOptionPane.showConfirmDialog(mainFrame, "Do you want to undo any changes made to classes before\n" + "you disconnect?\n\n" + "(This requires some time to complete but leaves\n" + "the remote JVM running at 100% of the original speed)", "Disconnection", JOptionPane.YES_NO_CANCEL_OPTION); if (ret == JOptionPane.CANCEL_OPTION) { return; } final boolean undoChanges = ret == JOptionPane.YES_OPTION; LongTask t = new LongTask() { public void executeInBackground() throws Exception { if (undoChanges) { setTaskMessage("Undoing changes to classes..."); client.restoreClasses(new ProgressCallback() { private int max; public void operationStarted(int amount) { max = amount; update(0); } public void update(int value) { setTaskProgress((value * 100) / max); setTaskMessage("Undoing changes to classes... (class " + value + " of " + max + ")"); } }); } }; }; runInBackground(t); memoryPanelTimer.stop(); sendEvent(AppEventType.TO_DISCONNECT); try { client.disconnect(); } catch (ClientException e) { error("Connection was close with error: (" + e.getMessage() + ")", e); } sendEvent(AppEventType.DISCONNECTED); }
From source file:com.mirth.connect.client.ui.SettingsPanelMap.java
public void doExportMap() { if (isSaveEnabled()) { int option = JOptionPane.showConfirmDialog(this, "Would you like to save the settings first?"); if (option == JOptionPane.YES_OPTION) { if (!doSave()) { return; }// w ww . j av a 2s . c o m } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { return; } } final String workingId = getFrame().startWorking("Exporting " + getTabName() + " settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { private Map<String, ConfigurationProperty> configurationMap; public Void doInBackground() { try { File file = getFrame().createFileForExport(null, "PROPERTIES"); if (file != null) { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.setDelimiterParsingDisabled(true); properties.setListDelimiter((char) 0); properties.clear(); PropertiesConfigurationLayout layout = properties.getLayout(); configurationMap = getFrame().mirthClient.getConfigurationMap(); Map<String, ConfigurationProperty> sortedMap = new TreeMap<String, ConfigurationProperty>( String.CASE_INSENSITIVE_ORDER); sortedMap.putAll(configurationMap); for (Entry<String, ConfigurationProperty> entry : sortedMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue().getValue(); String comment = entry.getValue().getComment(); if (StringUtils.isNotBlank(key)) { properties.setProperty(key, value); layout.setComment(key, StringUtils.isBlank(comment) ? null : comment); } } properties.save(file); } } catch (Exception e) { getFrame().alertThrowable(getFrame(), e); } return null; } @Override public void done() { getFrame().stopWorking(workingId); } }; worker.execute(); }
From source file:org.fhaes.FHRecorder.FireHistoryRecorder.java
/** * Closes the dialog but only after running necessary checks * to ensure user doesn't inadvertently loose data * /*from w ww . ja v a 2 s . com*/ */ private void closeAfterRunningChecks() { if (Controller.isModified()) { Object[] options = { "Save", "Close without saving", "Cancel" }; int n = JOptionPane.showOptionDialog(Controller.thePrimaryWindow, "Save changes to file before closing?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { Controller.save(); setVisible(false); } else if (n == JOptionPane.NO_OPTION) { Controller.setIsModified(false); Controller.setIsChangedSinceOpened(false); setVisible(false); } else if (n == JOptionPane.CANCEL_OPTION) { return; } } setVisible(false); }
From source file:de.ipk_gatersleben.ag_nw.graffiti.plugins.gui.webstart.KgmlEdMain.java
/** * Constructs a new instance of the editor. */// w w w . ja va 2 s. com public KgmlEdMain(final boolean showMainFrame, String applicationName, String[] args) { // URL config, final ThreadSafeOptions tso = new ThreadSafeOptions(); SplashScreenInterface splashScreen = new DBEsplashScreen(applicationName, "", new Runnable() { public void run() { if (showMainFrame) { ClassLoader cl = this.getClass().getClassLoader(); String path = this.getClass().getPackage().getName().replace('.', '/'); ImageIcon icon = new ImageIcon(cl.getResource(path + "/ipklogo16x16_5.png")); final MainFrame mainFrame = MainFrame.getInstance(); mainFrame.setIconImage(icon.getImage()); Thread t = new Thread(new Runnable() { public void run() { long waitTime = 0; long start = System.currentTimeMillis(); do { if (ErrorMsg.getAppLoadingStatus() == ApplicationStatus.ADDONS_LOADED) break; try { Thread.sleep(50); } catch (InterruptedException e) { } waitTime = System.currentTimeMillis() - start; } while (waitTime < 2000); SplashScreenInterface ss = (SplashScreenInterface) tso.getParam(0, null); ss.setVisible(false); mainFrame.setVisible(true); } }, "wait for add-on initialization"); t.start(); } } }); tso.setParam(0, splashScreen); ClassLoader cl = this.getClass().getClassLoader(); String path = this.getClass().getPackage().getName().replace('.', '/'); ImageIcon icon = new ImageIcon(cl.getResource(path + "/ipklogo16x16_5.png")); ((DBEsplashScreen) splashScreen).setIconImage(icon.getImage()); splashScreen.setVisible(true); GravistoMainHelper.createApplicationSettingsFolder(splashScreen); if (!(new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_accepted")).exists() && !(new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_rejected")).exists()) { ReleaseInfo.setIsFirstRun(true); splashScreen.setVisible(false); splashScreen.setText("Request KEGG License Status"); JOptionPane.showMessageDialog(null, "<html><h3>KEGG License Status Evaluation</h3>" + "While " + DBEgravistoHelper.DBE_GRAVISTO_VERSION + " is available as a academic research tool at no cost to commercial and non-commercial users, for using<br>" + "KEGG related functions, it is necessary for all users to adhere to the KEGG license.<br>" + "For using " + DBEgravistoHelper.DBE_GRAVISTO_VERSION + " you need also be aware of information about licenses and conditions for<br>" + "usage, listed at the program info dialog and the " + DBEgravistoHelper.DBE_GRAVISTO_VERSION + " website (" + ReleaseInfo.getAppWebURL() + ").<br><br>" + DBEgravistoHelper.DBE_GRAVISTO_VERSION + " does not distribute information from KEGG but contains functionality for the online-access to information from KEGG wesite.<br><br>" + "<b>Before these functions are available to you, you should carefully read the following license information<br>" + "and decide if it is legit for you to use the KEGG related program functions. If you choose not to use the KEGG functions<br>" + "all other features of this application are still available and fully working.", DBEgravistoHelper.DBE_GRAVISTO_VERSION + " Program Features Initialization", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "<html><h3>KEGG License Status Evaluation</h3>" + MenuItemInfoDialog.getKEGGlibText(), DBEgravistoHelper.DBE_GRAVISTO_VERSION + " Program Features Initialization", JOptionPane.INFORMATION_MESSAGE); int result = JOptionPane.showConfirmDialog(null, "<html><h3>Enable KEGG functions?", DBEgravistoHelper.DBE_GRAVISTO_VERSION + " Program Features Initialization", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { try { new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_accepted").createNewFile(); } catch (IOException e) { ErrorMsg.addErrorMessage(e); } } if (result == JOptionPane.NO_OPTION) { try { new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_rejected").createNewFile(); } catch (IOException e) { ErrorMsg.addErrorMessage(e); } } if (result == JOptionPane.CANCEL_OPTION) { JOptionPane.showMessageDialog(null, "Startup aborted.", DBEgravistoHelper.DBE_GRAVISTO_VERSION + " Program Features Initialization", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } splashScreen.setVisible(true); } GravistoMainHelper.initApplicationExt(args, splashScreen, cl, null, null); }
From source file:net.sf.housekeeper.swing.MainFrame.java
/** * Asks if data should be saved before it terminates the application. *///ww w . jav a 2 s. co m private void exitApplication() { boolean exit = true; //Only show dialog for saving before exiting if any data has been // changed if (FoodItemManager.instance().hasChanged()) { final String question = LocalisationManager.INSTANCE.getText("gui.mainFrame.saveModificationsQuestion"); final int option = JOptionPane.showConfirmDialog(view, question); //If user choses yes try to save. If that fails do not exit. if (option == JOptionPane.YES_OPTION) { try { PersistenceController.instance().saveDomainData(); } catch (IOException e) { exit = false; showSavingErrorDialog(); e.printStackTrace(); } } else if (option == JOptionPane.CANCEL_OPTION) { exit = false; } } if (exit) { System.exit(0); } }
From source file:com.projity.dialog.AbstractDialog.java
/** * */ protected void onCancel() { setVisible(false); setDialogResult(JOptionPane.CANCEL_OPTION); // desactivateListeners(); }
From source file:fi.smaa.jsmaa.gui.JSMAAMainFrame.java
private boolean checkSaveCurrentModel() { if (!modelManager.getSaved()) { int conf = JOptionPane.showConfirmDialog(this, "Current model not saved. Do you want do save changes?", "Save changed", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_STOP)); if (conf == JOptionPane.CANCEL_OPTION) { return false; } else if (conf == JOptionPane.YES_OPTION) { if (!save()) { return false; }//from w w w. j av a 2 s . c om } } return true; }
From source file:VoteDialog.java
private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton voteButton = null;//from www . j a v a 2s.c o m final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("<html>Candidate 1: <font color=red>Sparky the Dog</font></html>"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("<html>Candidate 2: <font color=green>Shady Sadie</font></html>"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("<html>Candidate 3: <font color=blue>R.I.P. McDaniels</font></html>"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton( "<html>Candidate 4: <font color=maroon>Duke the Java<font size=-2><sup>TM</sup></font size> Platform Mascot</font></html>"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } // Select the first button by default. radioButtons[0].setSelected(true); voteButton = new JButton("Vote"); voteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "This candidate is a dog. Invalid vote."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "This candidate is a convicted felon. \nDo you still want to vote for her?", "A Follow-up Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("OK. Keep an eye on your wallet."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no (with customized wording) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No, thanks" }; int n = JOptionPane.showOptionDialog(frame, "This candidate is deceased. \nDo you still want to vote for him?", "A Follow-up Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("I hope you don't expect much from your candidate."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no/cancel (with customized wording) } else if (command == yncCommand) { Object[] options = { "Yes!", "No, I'll pass", "Well, if I must" }; int n = JOptionPane.showOptionDialog(frame, "Duke is a cartoon mascot. \nDo you " + "still want to cast your vote?", "A Follow-up Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Excellent choice."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whatever you say. It's your vote."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to make you vote."); } else { setLabel("It is your civic duty to cast your vote."); } } return; } }); System.out.println("calling createPane"); return createPane(simpleDialogDesc + ":", radioButtons, voteButton); }
From source file:com.sshtools.tunnel.PortForwardingPane.java
protected void addPortForward() { PortForwardEditorPane editor = new PortForwardEditorPane(); int option = JOptionPane.showConfirmDialog(this, editor, "Add New Tunnel", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (option != JOptionPane.CANCEL_OPTION && option != JOptionPane.CLOSED_OPTION) { try {/*from www . j a v a2s . c o m*/ ForwardingClient forwardingClient = client; //.getForwardingClient(); String id = editor.getForwardName(); if (id.equals("x11")) { throw new Exception("The id of x11 is reserved."); } int i = model.getRowCount(); if (editor.isLocal()) { ForwardingConfiguration f = forwardingClient.addLocalForwarding(id, editor.getBindAddress(), editor.getLocalPort(), editor.getHost(), editor.getRemotePort()); forwardingClient.startLocalForwarding(id); active.addConfiguration(f); } else { ForwardingConfiguration f = forwardingClient.addRemoteForwarding(id, editor.getBindAddress(), editor.getLocalPort(), editor.getHost(), editor.getRemotePort()); forwardingClient.startRemoteForwarding(id); active.addConfiguration(f); } if (i < model.getRowCount()) { table.getSelectionModel().addSelectionInterval(i, i); } } catch (Exception e) { sessionPanel.setAvailableActions(); JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } finally { model.refresh(); sessionPanel.setAvailableActions(); } } }
From source file:com.t3.macro.api.functions.input.InputFunctions.java
/** * <pre>/*ww w .j a va2 s . c o m*/ * <span style="font-family:sans-serif;">The input() function prompts the user to input several variable values at once. * * Each of the string parameters has the following format: * "varname|value|prompt|inputType|options" * * Only the first section is required. * varname - the variable name to be assigned * value - sets the initial contents of the input field * prompt - UI text shown for the variable * inputType - specifies the type of input field * options - a string of the form "opt1=val1; opt2=val2; ..." * * The inputType field can be any of the following (defaults to TEXT): * TEXT - A text field. * "value" sets the initial contents. * The return value is the string in the text field. * Option: WIDTH=nnn sets the width of the text field (default 16). * LIST - An uneditable combo box. * "value" populates the list, and has the form "item1,item2,item3..." (trailing empty strings are dropped) * The return value is the numeric index of the selected item. * Option: SELECT=nnn sets the initial selection (default 0). * Option: VALUE=STRING returns the string contents of the selected item (default NUMBER). * Option: TEXT=FALSE suppresses the text of the list item (default TRUE). * Option: ICON=TRUE causes icon asset URLs to be extracted from the "value" and displayed (default FALSE). * Option: ICONSIZE=nnn sets the size of the icons (default 50). * CHECK - A checkbox. * "value" sets the initial state of the box (anything but "" or "0" checks the box) * The return value is 0 or 1. * No options. * RADIO - A group of radio buttons. * "value" is a list "name1, name2, name3, ..." which sets the labels of the buttons. * The return value is the index of the selected item. * Option: SELECT=nnn sets the initial selection (default 0). * Option: ORIENT=H causes the radio buttons to be laid out on one line (default V). * Option: VALUE=STRING causes the return value to be the string of the selected item (default NUMBER). * LABEL - A label. * The "varname" is ignored and no value is assigned to it. * Option: TEXT=FALSE, ICON=TRUE, ICONSIZE=nnn, as in the LIST type. * PROPS - A sub-panel with multiple text boxes. * "value" contains a StrProp of the form "key1=val1; key2=val2; ..." * One text box is created for each key, populated with the matching value. * Option: SETVARS=SUFFIXED causes variable assignment to each key name, with appended "_" (default NONE). * Option: SETVARS=UNSUFFIXED causes variable assignment to each key name. * TAB - A tabbed dialog tab is created. Subsequent variables are contained in the tab. * Option: SELECT=TRUE causes this tab to be shown at start (default SELECT=FALSE). * * All inputTypes except TAB accept the option SPAN=TRUE, which causes the prompt to be hidden and the input * control to span both columns of the dialog layout (default FALSE). * </span> * </pre> * @param parameters a list of strings containing information as described above * @return a HashMap with the returned values or null if the user clicked on cancel * @author knizia.fan * @throws MacroException */ public static Map<String, String> input(TokenView token, String... parameters) throws MacroException { // 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; } // Multiple vars can be packed into a string, separated by "##" for (String varString : StringUtils.splitByWholeSeparator(paramStr, "##")) { 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 MacroException(se); } catch (InputType.OptionException oe) { throw new MacroException(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 Collections.emptyMap(); // No work to do, so treat it as a successful invocation. // UI step 1 - First, see if a token is given String dialogTitle = "Input Values"; if (token != null) { String name = token.getName(), gm_name = token.getGMName(); boolean isGM = TabletopTool.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(TabletopTool.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 null; HashMap<String, String> results = new HashMap<String, String>(); // 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: results.put(key + "_", value); break; case 2: results.put(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) { results.put(vs.name, newValue.trim()); allAssignments.append(vs.name + "=" + newValue.trim() + " ## "); } } if (cp.tabVarSpec != null) { results.put(cp.tabVarSpec.name, allAssignments.toString()); } } return results; // success // for debugging: //return debugOutput(varSpecs); }