List of usage examples for javax.swing JOptionPane YES_NO_CANCEL_OPTION
int YES_NO_CANCEL_OPTION
To view the source code for javax.swing JOptionPane YES_NO_CANCEL_OPTION.
Click Source Link
showConfirmDialog
. From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static DialogResult showConfirmationDialog(Component parent, String title, String message) { final Object[] options = { "Yes", "No", "Cancel" }; final int outcome = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); switch (outcome) { case 0:/*from ww w.j a v a 2 s . c o m*/ return DialogResult.YES; case 1: return DialogResult.NO; case 2: case JOptionPane.CLOSED_OPTION: return DialogResult.CANCEL; default: throw new RuntimeException("Internal error, unexpected outcome " + outcome); } }
From source file:net.pms.newgui.Wizard.java
public static void run(final PmsConfiguration configuration) { // Total number of questions int numberOfQuestions = Platform.isMac() ? 4 : 5; // The current question number int currentQuestionNumber = 1; String status = new StringBuilder().append(Messages.getString("Wizard.2")).append(" %d ") .append(Messages.getString("Wizard.4")).append(" ").append(numberOfQuestions).toString(); Object[] okOptions = { Messages.getString("Dialog.OK") }; Object[] yesNoOptions = { Messages.getString("Dialog.YES"), Messages.getString("Dialog.NO") }; Object[] networkTypeOptions = { Messages.getString("Wizard.8"), Messages.getString("Wizard.9"), Messages.getString("Wizard.10") }; if (!Platform.isMac()) { // Ask if they want UMS to start minimized int whetherToStartMinimized = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.3"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[1]); if (whetherToStartMinimized == JOptionPane.YES_OPTION) { configuration.setMinimized(true); } else if (whetherToStartMinimized == JOptionPane.NO_OPTION) { configuration.setMinimized(false); }/*from w ww. jav a2 s . com*/ } // Ask if their network is wired, etc. int networkType = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.7"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, networkTypeOptions, networkTypeOptions[1]); switch (networkType) { case JOptionPane.YES_OPTION: // Wired (Gigabit) configuration.setMaximumBitrate("0"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.NO_OPTION: // Wired (100 Megabit) configuration.setMaximumBitrate("90"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.CANCEL_OPTION: // Wireless configuration.setMaximumBitrate("30"); configuration.setMPEG2MainSettings("Automatic (Wireless)"); configuration.setx264ConstantRateFactor("Automatic (Wireless)"); break; default: break; } // Ask if they want to hide advanced options int whetherToHideAdvancedOptions = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.11"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToHideAdvancedOptions == JOptionPane.YES_OPTION) { configuration.setHideAdvancedOptions(true); } else if (whetherToHideAdvancedOptions == JOptionPane.NO_OPTION) { configuration.setHideAdvancedOptions(false); } // Ask if they want to scan shared folders int whetherToScanSharedFolders = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.IsStartupScan"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToScanSharedFolders == JOptionPane.YES_OPTION) { configuration.setScanSharedFoldersOnStartup(true); } else if (whetherToScanSharedFolders == JOptionPane.NO_OPTION) { configuration.setScanSharedFoldersOnStartup(false); } // Ask to set at least one shared folder JOptionPane.showOptionDialog(null, Messages.getString("Wizard.12"), String.format(status, currentQuestionNumber++), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, okOptions, okOptions[0]); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JFileChooser chooser; try { chooser = new JFileChooser(); } catch (Exception ee) { chooser = new JFileChooser(new RestrictedFileSystemView()); } chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle(Messages.getString("Wizard.12")); chooser.setMultiSelectionEnabled(false); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { configuration.setOnlySharedDirectory(chooser.getSelectedFile().getAbsolutePath()); } else { // If the user cancels this option, the default directories will be used. } } }); } catch (InterruptedException | InvocationTargetException e) { LOGGER.error("Error when saving folders: ", e); } // The wizard finished, do not ask them again configuration.setRunWizard(false); // Save all changes try { configuration.save(); } catch (ConfigurationException e) { LOGGER.error("Error when saving changed configuration: ", e); } }
From source file:com.pdk.DisassembleElfAction.java
@Override public void actionPerformed(ActionEvent e) { try {// ww w .j a va 2 s. c o m Lookup context = Utilities.actionsGlobalContext(); DataObject file = context.lookup(DataObject.class); if (file == null) { showList(); } else { File fileObj = new File(file.getPrimaryFile().getPath()); if (!fileObj.getName().endsWith(".o")) { showList(); } else { File dir = new File(file.getFolder().getPrimaryFile().getPath()); Object[] options = { "Disasm", "Sections", "Cancel" }; int n = JOptionPane.showOptionDialog(null, "Please select", "Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == 2) { return; } String command2 = null; if (n == 0) { command2 = "i586-peter-elf-objdump -S"; } else if (n == 1) { command2 = "i586-peter-elf-readelf -S"; } if (command2 == null) { return; } final String command = "/toolchain/bin/" + command2 + " " + fileObj.getName(); process = Runtime.getRuntime().exec(command, null, dir); InputStreamReader isr = new InputStreamReader(process.getInputStream()); final BufferedReader br = new BufferedReader(isr, 1024 * 1024 * 50); final JProgressBarDialog d = new JProgressBarDialog(new JFrame(), "i586-peter-elf-objdump -S " + fileObj.getName(), true); d.progressBar.setIndeterminate(true); d.progressBar.setStringPainted(true); d.progressBar.setString("Updating"); d.addCancelEventListener(this); Thread longRunningThread = new Thread() { public void run() { try { lines = new StringBuilder(); String line; stop = false; while (!stop && (line = br.readLine()) != null) { d.progressBar.setString(line); lines.append(line).append("\n"); } DisassembleDialog disassembleDialog = new DisassembleDialog(); disassembleDialog.setTitle(command); if (((DefaultComboBoxModel) disassembleDialog.enhancedTextArea1.fontComboBox .getModel()).getIndexOf("Monospaced") != -1) { disassembleDialog.enhancedTextArea1.fontComboBox.setSelectedItem("Monospaced"); } if (((DefaultComboBoxModel) disassembleDialog.enhancedTextArea1.fontComboBox .getModel()).getIndexOf("Monospaced.plain") != -1) { disassembleDialog.enhancedTextArea1.fontComboBox .setSelectedItem("Monospaced.plain"); } disassembleDialog.enhancedTextArea1.setText(lines.toString()); disassembleDialog.setVisible(true); } catch (Exception ex) { ModuleLib.log(CommonLib.printException(ex)); } } }; d.thread = longRunningThread; d.setVisible(true); } } } catch (Exception ex) { ModuleLib.log(CommonLib.printException(ex)); } }
From source file:net.menthor.editor.v2.util.Util.java
public static JFileChooser createChooser(String lastPath, final boolean checkOverrideFile) { return new JFileChooser(lastPath) { private static final long serialVersionUID = 1L; @Override//w w w .j a v a 2 s . c o m public void approveSelection() { File f = getSelectedFile(); if (f.exists() && checkOverrideFile) { int result = JOptionPane.showConfirmDialog(this, "\"" + f.getName() + "\" already exists. Do you want to overwrite it?", "Existing file", JOptionPane.YES_NO_CANCEL_OPTION); switch (result) { case JOptionPane.YES_OPTION: super.approveSelection(); return; case JOptionPane.NO_OPTION: return; case JOptionPane.CLOSED_OPTION: return; case JOptionPane.CANCEL_OPTION: cancelSelection(); return; } } super.approveSelection(); } }; }
From source file:hr.fer.zemris.vhdllab.platform.gui.dialog.AbstractOptionPaneDialogManager.java
private Object[] getOptionsForType(int optionType) { switch (optionType) { case JOptionPane.DEFAULT_OPTION: return getOption("ok"); case JOptionPane.YES_NO_CANCEL_OPTION: return getOption("yes", "no", "cancel"); case JOptionPane.YES_NO_OPTION: return getOption("yes", "no"); case JOptionPane.OK_CANCEL_OPTION: return getOption("ok", "cancel"); default:/*from w w w.j a v a 2 s. co m*/ throw new IllegalStateException("Unknown option: " + optionType); } }
From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
public void openPDF(boolean isInternalR, File pdf, Component comp) throws FileNotFoundException { if (isInternalR) { try {/*from www .j av a 2s . c o m*/ Desktop.getDesktop().open(pdf); } catch (Exception ex) { log.info(ex.getMessage()); String msg = "Unable to open PDF format through java. Would you like to save " + pdf.getAbsoluteFile() + " in a new location?"; JOptionPane pane = new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, null, JOptionPane.YES_OPTION); JDialog dialog = pane.createDialog(comp, "Report PDF"); dialog.setVisible(true); Object choice = pane.getValue(); if (choice.equals(JOptionPane.YES_OPTION)) { jfcFiles = new JFileChooser(); jfcFiles.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int state = jfcFiles.showSaveDialog(comp); if (state == JFileChooser.APPROVE_OPTION) { File file = checkFileExtension(".pdf"); log.info("Opening: " + file.getName() + "."); if (file != null) pdf.renameTo(file); } else { log.info("Open command cancelled by user."); } } } } }
From source file:SaveDialog.java
boolean okToQuit() { String[] choices = { "Yes, Save and Quit", "No, Quit without saving", "CANCEL" }; int result = JOptionPane.showOptionDialog(this, "You have unsaved changes. Save before quitting?", "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, choices, choices[0]);//from ww w .j a v a2 s . co m // Use of "null" as the Icon argument is contentious... the // document says you can pass null, but it does seem to // generate a lot of blather if you do, something about // a NullPointerException :-) ... if (result >= 0) System.out.println("You clicked " + choices[result]); switch (result) { case -1: System.out.println("You killed my die-alog - it died"); return false; case 0: // save and quit System.out.println("Saving..."); // mainApp.doSave(); return true; case 1: // just quit return true; case 2: // cancel return false; default: throw new IllegalArgumentException("Unexpected return " + result); } }
From source file:jpad.MainEditor.java
public boolean quitApp() { if (hasChanges) { int dialogResult = JOptionPane.showConfirmDialog(this, "You have unsaved changes, would you like to save these first?", "Question", JOptionPane.YES_NO_CANCEL_OPTION); switch (dialogResult) { case 0:/*from ww w . j a v a 2s. com*/ if (hasSavedToFile) saveFile(curFile); else saveAs(); return true; case 1: return true; case 2: return false; } } return true; }
From source file:com.igormaznitsa.zxpspritecorrector.files.AbstractFilePlugin.java
protected boolean saveDataToFile(final File file, final byte[] data) throws IOException { if (file.isFile()) { switch (JOptionPane.showConfirmDialog(this.mainFrame, "Overwrite file '" + file.getAbsolutePath() + "'?", "Overwrite file", JOptionPane.YES_NO_CANCEL_OPTION)) { case JOptionPane.NO_OPTION: return true; case JOptionPane.CANCEL_OPTION: return false; }//from w w w.jav a 2 s . c o m } FileUtils.writeByteArrayToFile(file, data); return true; }
From source file:com.openbravo.pos.customers.CustomersPayment.java
/** * * @return// ww w. ja v a 2 s. c o m */ @Override public boolean deactivate() { if (dirty.isDirty()) { int res = JOptionPane.showConfirmDialog(this, AppLocal.getIntString("message.wannasave"), AppLocal.getIntString("title.editor"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (res == JOptionPane.YES_OPTION) { save(); return true; } else { return res == JOptionPane.NO_OPTION; } } else { return true; } }