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:org.jreversepro.gui.ClassEditPanel.java
/** * @param aParent//from ww w . j av a 2s . c om * Parent Frame * @param aOutputFile * File which already exists. * @return true, if user prompts to overwrite file. false, otherwise. **/ private boolean confirmOverwrite(JFrame aParent, File aOutputFile) { int a = JOptionPane.showConfirmDialog(aParent, "OverWrite File " + aOutputFile.toString(), "Confirm Overwrite", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); return (a == JOptionPane.YES_OPTION); }
From source file:org.kepler.gui.KeplerGraphFrame.java
/** * Open a dialog to prompt the user to save a KAR. Return false if the user * clicks "cancel", and otherwise return true. * /*from w ww . ja v a2 s. co m*/ * Overrides Top._queryForSave() * * @return _SAVED if the file is saved, _DISCARDED if the modifications are * discarded, _CANCELED if the operation is canceled by the user, * and _FAILED if the user selects save and the save fails. */ @Override protected int _queryForSave() { Object[] options = { "Save", "Discard changes", "Cancel" }; // making more generic since other items to go in the KAR // may be the reason for querying to save // String query = "Save changes to " + StringUtilities.split(_getName()) // + "?"; String query = "Save changes to KAR?"; // Show the MODAL dialog int selected = JOptionPane.showOptionDialog(this, query, "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (selected == JOptionPane.YES_OPTION) { JButton saveButton = new JButton("Save Kar"); ExportArchiveAction eaa = new ExportArchiveAction(this); eaa.setRefreshFrameAfterSave(false); // if the file already exists, call ExportArchiveAction.setSave() // so that the save as file dialog does is not used. KARFile karFile = KARManager.getInstance().get(this); if (karFile != null) { File file = karFile.getFileLocation(); if (file.canWrite()) { eaa.setSaveFile(file); } } saveButton.addActionListener(eaa); saveButton.doClick(); if (eaa.saveSucceeded()) { setModified(false); return _SAVED; } else { return _FAILED; } } if (selected == JOptionPane.NO_OPTION) { return _DISCARDED; } return _CANCELED; }
From source file:org.nuclos.client.ui.collect.CollectController.java
/** * asks the user to save the current record if necessary, so that it can be abandoned afterwards. * @return can the action be performed?//ww w .j a v a 2 s .co m */ @Override public void askAndSaveIfNecessary(final boolean returnNullIfCancel, final ResultListener<Boolean> rl) { if (this.changesArePending()) { try { MainFrame.setSelectedTab(this.getTab()); } catch (Exception e) { // TODO TABS: Ein Overlay Tab kann der MainFrame noch nicht finden... Quickfix try-catch LOG.error(e.getMessage(), e); } final String sMsg = getSpringLocaleDelegate().getMessage("CollectController.14", "Der Datensatz wurde ge\u00e4ndert.") + "\n" + getSpringLocaleDelegate().getMessage("CollectController.32", "Wenn Sie jetzt nicht speichern, werden diese \u00c4nderungen verloren gehen.") + "\n" + getSpringLocaleDelegate().getMessage("CollectController.20", "Jetzt speichern?"); OverlayOptionPane.showConfirmDialog(this.getTab(), sMsg, getSpringLocaleDelegate().getMessage("CollectController.10", "Datensatz ge\u00e4ndert"), JOptionPane.YES_NO_CANCEL_OPTION, new OvOpAdapter() { @Override public void done(int result) { boolean bResult = true; if (returnNullIfCancel && result == OverlayOptionPane.CANCEL_OPTION) { rl.done(null); return; } bResult = (result != OverlayOptionPane.CANCEL_OPTION && result != OverlayOptionPane.CLOSED_OPTION); if (result == OverlayOptionPane.YES_OPTION) { try { // cmdSave cannot be used here, because it does not throw any non-fatal exceptions, which can be used to prevent closing of the window. // To solve the problem otherwise, handleSaveExeption is called here, which could provide additional behaviour like focus faulty fields... switch (CollectController.this.statemodel.getDetailsMode()) { case CollectState.DETAILSMODE_EDIT: case CollectState.DETAILSMODE_NEW_CHANGED: case CollectState.DETAILSMODE_MULTIEDIT: save(); break; } } catch (CommonPermissionException ex) { bResult = false; final String sMessage = getSpringLocaleDelegate().getMessage( "CollectController.24", "Sie verf\u00fcgen nicht \u00fcber die ausreichenden Rechte, um dieses Objekt zu speichern."); Errors.getInstance().showExceptionDialog(getTab(), sMessage, ex); } catch (CommonBusinessException ex) { bResult = false; final String sMessage1 = getSpringLocaleDelegate().getMessage( "CollectController.13", "Der Datensatz konnte nicht gespeichert werden"); try { handleSaveException(ex, sMessage1); } catch (CommonFinderException ex2) { final String sErrorMsg = getSpringLocaleDelegate().getMessage( "CollectController.1", ", da er zwischenzeitlich von einem anderen Benutzer gel\u00f6scht wurde."); Errors.getInstance().showExceptionDialog(getTab(), sErrorMsg, ex2); } catch (CommonBusinessException ex2) { Errors.getInstance().showExceptionDialog(getTab(), sMessage1 + ".", ex2); } //final String sMessage = "Der Datensatz konnte nicht gespeichert werden."; //Errors.getInstance().showExceptionDialog(this.getFrame(), sMessage, ex); } catch (CommonFatalException ex) { bResult = false; final String sMessage = getSpringLocaleDelegate().getMessage( "CollectController.11", "Der Datensatz konnte nicht gespeichert werden."); Errors.getInstance().showExceptionDialog(getTab(), sMessage, ex); } } rl.done(bResult); } }); } else { rl.done(true); } }
From source file:org.orbisgis.groovy.GroovyConsolePanel.java
/** * Open a dialog that let the user select a file and add or replace the * content of the sql editor.//from w w w.ja va 2 s.co m */ public void onOpenFile() { final OpenFilePanel inFilePanel = new OpenFilePanel("groovyConsoleInFile", I18N.tr("Open script")); inFilePanel.addFilter("groovy", I18N.tr("Groovy Script (*.groovy)")); inFilePanel.loadState(); if (UIFactory.showDialog(inFilePanel)) { int answer = JOptionPane.NO_OPTION; if (scriptPanel.getDocument().getLength() > 0) { answer = JOptionPane.showConfirmDialog(this, I18N.tr("Do you want to clear all before loading the file ?"), I18N.tr("Open file"), JOptionPane.YES_NO_CANCEL_OPTION); } String text; try { text = FileUtils.readFileToString(inFilePanel.getSelectedFile()); } catch (IOException e1) { LOGGER.error(I18N.tr("Cannot write the script."), e1); return; } if (answer == JOptionPane.YES_OPTION) { scriptPanel.setText(text); } else if (answer == JOptionPane.NO_OPTION) { scriptPanel.append(text); } } }
From source file:org.orbisgis.r.RConsolePanel.java
/** * Open a dialog that let the user select a file and add or replace the * content of the R editor.//from w w w . j a v a 2s.c o m */ public void onOpenFile() { final OpenFilePanel inFilePanel = new OpenFilePanel("rConsoleInFile", I18N.tr("Open script")); inFilePanel.addFilter("R", I18N.tr("R Script (*.R)")); inFilePanel.loadState(); if (UIFactory.showDialog(inFilePanel)) { int answer = JOptionPane.NO_OPTION; if (scriptPanel.getDocument().getLength() > 0) { answer = JOptionPane.showConfirmDialog(this, I18N.tr("Do you want to clear all before loading the file ?"), I18N.tr("Open file"), JOptionPane.YES_NO_CANCEL_OPTION); } String text; try { text = FileUtils.readFileToString(inFilePanel.getSelectedFile()); } catch (IOException e1) { LOGGER.error(I18N.tr("Cannot write the script."), e1); return; } if (answer == JOptionPane.YES_OPTION) { scriptPanel.setText(text); } else if (answer == JOptionPane.NO_OPTION) { scriptPanel.append(text); } } }
From source file:org.orbisgis.sqlconsole.ui.SQLConsolePanel.java
/** * Open a dialog that let the user to select a file * and add or replace the content of the sql editor. *///from www. j a v a2s . co m public void onOpenFile() { final OpenFilePanel inFilePanel = new OpenFilePanel("sqlConsoleInFile", I18N.tr("Open script")); inFilePanel.addFilter("sql", I18N.tr("SQL script (*.sql)")); if (sqlElement.getDocumentPathString().isEmpty()) { inFilePanel.loadState(); } else { inFilePanel.setCurrentDirectory(sqlElement.getDocumentPath()); } if (UIFactory.showDialog(inFilePanel)) { int answer = JOptionPane.YES_OPTION; if (scriptPanel.getDocument().getLength() > 0) { answer = JOptionPane.showConfirmDialog(this, I18N.tr("Do you want to clear all before loading the file ?"), I18N.tr("Open file"), JOptionPane.YES_NO_CANCEL_OPTION); } String text; try { text = FileUtils.readFileToString(inFilePanel.getSelectedFile()); } catch (IOException e1) { LOGGER.error(I18N.tr("IO error."), e1); return; } if (answer == JOptionPane.YES_OPTION) { scriptPanel.setText(text); sqlElement.setDocumentPath(inFilePanel.getSelectedFile()); sqlElement.setModified(false); } else if (answer == JOptionPane.NO_OPTION) { scriptPanel.append(text); } } }
From source file:org.orbisgis.view.beanshell.BshConsolePanel.java
/** * Open a dialog that let the user select a file * and add or replace the content of the sql editor. *//* w w w.ja v a 2 s .c om*/ public void onOpenFile() { final OpenFilePanel inFilePanel = new OpenFilePanel("bshConsoleInFile", I18N.tr("Open script")); inFilePanel.addFilter("bsh", I18N.tr("BeanShell Script (*.bsh)")); inFilePanel.loadState(); if (UIFactory.showDialog(inFilePanel)) { int answer = JOptionPane.NO_OPTION; if (scriptPanel.getDocument().getLength() > 0) { answer = JOptionPane.showConfirmDialog(this, I18N.tr("Do you want to clear all before loading the file ?"), I18N.tr("Open file"), JOptionPane.YES_NO_CANCEL_OPTION); } String text; try { text = FileUtils.readFileToString(inFilePanel.getSelectedFile()); } catch (IOException e1) { LOGGER.error(I18N.tr("IO error."), e1); return; } if (answer == JOptionPane.YES_OPTION) { scriptPanel.setText(text); } else if (answer == JOptionPane.NO_OPTION) { scriptPanel.append(text); } } }
From source file:org.orbisgis.view.map.MapElement.java
@Override public void save() throws UnsupportedOperationException { // If a layer hold a not well known source then alert the user boolean doSave = true; if (hasNotWellKnownDataSources()) { int response = JOptionPane.showConfirmDialog(UIFactory.getMainFrame(), I18N.tr( "Some layers use temporary data source, are you sure to save this map and loose layers with temporary data sources ?"), I18N.tr("Temporary layers data source"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response == JOptionPane.NO_OPTION) { doSave = false;//w ww . j a va 2 s . c o m } } if (hasModifiedDataSources()) { int response = JOptionPane.showConfirmDialog(UIFactory.getMainFrame(), I18N.tr("Some layers use modified data source, do you want to save also these modifications ?"), I18N.tr("Save geometry edits"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) { doSave = false; } else if (response == JOptionPane.YES_OPTION) { // Save DataSources if (!saveModifiedDataSources()) { response = JOptionPane.showConfirmDialog(UIFactory.getMainFrame(), I18N.tr( "Some layers data source modifications can not be saved, are you sure you want to continue ?"), I18N.tr("Errors on data source save process"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response == JOptionPane.NO_OPTION) { doSave = false; } } } } if (doSave) { // Save MapContext try { //Create folders if needed File parentFolder = mapContextFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } mapContext.write(new FileOutputStream(mapContextFile)); } catch (FileNotFoundException ex) { throw new UnsupportedOperationException(ex); } if (doSave) { setModified(false); } } }
From source file:org.orbisgis.view.sqlconsole.ui.SQLConsolePanel.java
/** * Open a dialog that let the user to select a file * and add or replace the content of the sql editor. *//*w w w . j a v a 2 s . c o m*/ public void onOpenFile() { final OpenFilePanel inFilePanel = new OpenFilePanel("sqlConsoleInFile", I18N.tr("Open script")); inFilePanel.addFilter("sql", I18N.tr("SQL script (*.sql)")); inFilePanel.loadState(); if (UIFactory.showDialog(inFilePanel)) { int answer = JOptionPane.NO_OPTION; if (scriptPanel.getDocument().getLength() > 0) { answer = JOptionPane.showConfirmDialog(this, I18N.tr("Do you want to clear all before loading the file ?"), I18N.tr("Open file"), JOptionPane.YES_NO_CANCEL_OPTION); } String text; try { text = FileUtils.readFileToString(inFilePanel.getSelectedFile()); } catch (IOException e1) { LOGGER.error(I18N.tr("IO error."), e1); return; } if (answer == JOptionPane.YES_OPTION) { scriptPanel.setText(text); } else if (answer == JOptionPane.NO_OPTION) { scriptPanel.append(text); } } }
From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java
public PanboxClientGUI(final PanboxClient client) { this.client = client; this.shareModel = client.getShareList(); this.contactModel = client.getContactList(); this.deviceModel = client.getDeviceList(); initComponents();// w w w. ja v a 2s.c o m ActionListener changesDetectedActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setSettingsChangesDetected(); } }; DocumentListener changesDetectedDocumentListener = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { setSettingsChangesDetected(); } @Override public void removeUpdate(DocumentEvent e) { setSettingsChangesDetected(); } @Override public void changedUpdate(DocumentEvent e) { } }; dropboxSettingsPanel = new DropboxSettingsPanel(changesDetectedActionListener, changesDetectedDocumentListener); initSettingsConfig(); // set the icon Toolkit kit = Toolkit.getDefaultToolkit(); Image img = kit.createImage(getClass().getResource("panbox-icon-big.png")); setIconImage(img); // set the default locale for popup messages JOptionPane.setDefaultLocale(Settings.getInstance().getLocale()); // Hide these for now. Do we still need this? syncStatusLabel.setVisible(false); syncStatusTextField.setVisible(false); cspInfoTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // NOI18N shareList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { refreshShare(); } }); shareList.setSelectedIndex(0); // always try to select first share enableDisableAddDeviceContactForShare(); addressbookList.addListSelectionListener(new ListSelectionListener() { private DocumentListener firstNameFieldDocListener = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { changed(); } @Override public void removeUpdate(DocumentEvent e) { changed(); } @Override public void changedUpdate(DocumentEvent e) { } public void changed() { if (!firstNameTextField.getText().equals(contact.getFirstName()) && !unsavedContactChanges) { setContactChangesDetected(); } } }; private DocumentListener lastNameFieldDocListener = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { changed(); } @Override public void removeUpdate(DocumentEvent e) { changed(); } @Override public void changedUpdate(DocumentEvent e) { } public void changed() { if (!lastNameTextField.getText().equals(contact.getName()) && !unsavedContactChanges) { setContactChangesDetected(); } } }; private ListSelectionListener cspListSelectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int selectedIndex = cspInfoTable.getSelectedRow(); int max = ((CSPTableModel) cspInfoTable.getModel()).getMax(); if (selectedIndex != -1 && selectedIndex < max) { removeCSPInfoButton.setEnabled(true); } else { removeCSPInfoButton.setEnabled(false); } } }; boolean manuallySetSelection = false; @Override public void valueChanged(ListSelectionEvent e) { final List<PanboxGUIContact> selected = addressbookList.getSelectedValuesList(); firstNameTextField.getDocument().removeDocumentListener(firstNameFieldDocListener); lastNameTextField.getDocument().removeDocumentListener(lastNameFieldDocListener); cspInfoTable.getSelectionModel().removeListSelectionListener(cspListSelectionListener); if (!manuallySetSelection) { if (!uneditedCSPsExist()) { if (unsavedContactChanges) { int saveUnchanged = JOptionPane.showConfirmDialog(null, bundle.getString("PanboxClientGUI.unsavedChangesToContact"), // NOI18N bundle.getString("PanboxClientGUI.panboxMessage"), // NOI18N JOptionPane.YES_NO_CANCEL_OPTION); if (saveUnchanged == JOptionPane.YES_OPTION) { saveContactChanges(); refreshContact(); resetContactApplyDiscardButtons(); } else if (saveUnchanged == JOptionPane.CANCEL_OPTION) { manuallySetSelection = true; int previousIndex = e.getFirstIndex() == addressbookList.getSelectedIndex() ? e.getLastIndex() : e.getFirstIndex(); addressbookList.setSelectedIndex(previousIndex); } else { refreshContact(); resetContactApplyDiscardButtons(); } unsavedContactChanges = false; } int selectedIndex = addressbookList.getSelectedIndex(); if (selectedIndex != -1) { // enable Buttons removeContactButton.setEnabled(true); exportContactButton.setEnabled(true); // refresh contact infos contact = contactModel.getElementAt(selectedIndex); contacts = selected; firstNameTextField.setText(contact.getFirstName()); lastNameTextField.setText(contact.getName()); emailTextField.setText(contact.getEmail()); cspInfoTable.setModel(contact.generateCspInfoTableModel()); cspInfoTable.getSelectionModel().addListSelectionListener(cspListSelectionListener); // show certificate info encKeyFprintTextField.setText(contact.getCertEncFingerprint()); signKeyFprintTextField.setText(contact.getCertSignFingerprint()); validFromUntilLabel.setText(bundle.getString("valid.from") + " " + contact.getFromDate() + " " + bundle.getString("valid.to") + " " + contact.getUntilDate()); // disable apply and discard buttons when contact // selection // changes contactApplyButton.setEnabled(false); contactDiscardButton.setEnabled(false); // disable csp add button when no further csps are // available to add if (contact.getAvailableCSPs() > 0) { addCSPInfoButton.setEnabled(true); } else { addCSPInfoButton.setEnabled(false); } removeCSPInfoButton.setEnabled(false); if (contact instanceof PanboxMyContact) { firstNameTextField.setEnabled(false); lastNameTextField.setEnabled(false); removeContactButton.setEnabled(false); contactVerificationStatusCheckBox.setEnabled(false); } else { firstNameTextField.setEnabled(true); lastNameTextField.setEnabled(true); removeContactButton.setEnabled(true); firstNameTextField.getDocument().addDocumentListener(firstNameFieldDocListener); lastNameTextField.getDocument().addDocumentListener(lastNameFieldDocListener); contactVerificationStatusCheckBox.setEnabled(true); } } else { // disable export and remove button when no item is // selected removeContactButton.setEnabled(false); exportContactButton.setEnabled(false); } } else { manuallySetSelection = true; int previousIndex = e.getFirstIndex() == addressbookList.getSelectedIndex() ? e.getLastIndex() : e.getFirstIndex(); addressbookList.setSelectedIndex(previousIndex); } } else { manuallySetSelection = false; } if (contact.isVerified()) { contactVerificationStatusCheckBox.setSelected(true); contactVerificationStatusCheckBox.setText(bundle.getString("PanboxClientGUI.contact.verified")); } else { contactVerificationStatusCheckBox.setSelected(false); contactVerificationStatusCheckBox.setText(bundle.getString("PanboxClientGUI.contact.verified")); } } }); addressbookList.setSelectedIndex(0); // always try to select first // contact // contact firstNameTextField.setDisabledTextColor(Color.BLACK); lastNameTextField.setDisabledTextColor(Color.BLACK); emailTextField.setDisabledTextColor(Color.BLACK); encKeyFprintTextField.setDisabledTextColor(Color.BLACK); signKeyFprintTextField.setDisabledTextColor(Color.BLACK); deviceList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int selected = deviceList.getSelectedIndex(); if (!e.getValueIsAdjusting() && selected != -1) { device = deviceModel.getElementAt(selected); deviceKeyFprintTextField.setText(device.getDevicePubKeyFingerprint()); deviceShareList.setModel(client.getDeviceShares(device)); checkIfRemoveDeviceShouldBeEnabled(); } } }); deviceList.setSelectedIndex(0); // always try to select first device checkIfRemoveDeviceShouldBeEnabled(); // expert mode visible/invisible expertModeCheckBoxActionPerformed(null); languageComboBox.addActionListener(changesDetectedActionListener); expertModeCheckBox.addActionListener(changesDetectedActionListener); networkAddressComboBox.addActionListener(changesDetectedActionListener); networkInterfaceComboBox.addActionListener(changesDetectedActionListener); panboxFolderTextField.getDocument().addDocumentListener(changesDetectedDocumentListener); settingsFolderTextField.getDocument().addDocumentListener(changesDetectedDocumentListener); // disable settings apply and discard buttons settingsApplyButton.setEnabled(false); settingsRevertButton.setEnabled(false); // TODO: add action and document listeners to the csp settings after it // has been fixed (see trac ticket #139) // Disable device pairing for SLAVE devices and enable the click for MASTER devices! if (Settings.getInstance().isSlave()) { addDeviceButton.setEnabled(false); addDeviceButton.setToolTipText(bundle.getString("client.disabledPairingSlave")); } else { addDeviceButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { addDeviceButtonMousePressed(evt); } }); } if (OS.getOperatingSystem().isWindows()) { panboxFolderLabel.setText(bundle.getString("client.settings.panboxDrive")); // NOI18N panboxFolderChooseButton.setVisible(false); } }