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:org.intermine.install.swing.ProjectEditor.java
/** * Prompt the user to ask whether to save the modified project before * proceeding./*ww w .ja v a 2 s . com*/ * * @return <code>false</code> if the user chose to save the project, * <code>true</code> if the project has not been saved. */ protected boolean promptedSave() { boolean cancel = false; if (projectModified) { int choice = JOptionPane.showConfirmDialog(this, Messages.getMessage("project.modified.save.message"), Messages.getMessage("project.modified.save.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); switch (choice) { case JOptionPane.CANCEL_OPTION: cancel = true; break; case JOptionPane.YES_OPTION: saveProject(); break; } } return cancel; }
From source file:org.interreg.docexplore.authoring.AuthoringMenu.java
boolean requestSave() { if (curFile != null && lastModified(tool.defaultFile) <= lastLoad) return true; try {//from w ww .j a v a2 s .c o m if (tool.editor.link.getBook(tool.editor.link.getLink().getAllBookIds().get(0)).pagesByNumber.isEmpty()) return true; } catch (Exception e) { e.printStackTrace(); return true; } int res = JOptionPane.showConfirmDialog(tool, XMLResourceBundle.getBundledString("generalSaveMessage"), XMLResourceBundle.getBundledString("generalMenuSave"), JOptionPane.YES_NO_CANCEL_OPTION); if (res == JOptionPane.CANCEL_OPTION) return false; if (res == JOptionPane.YES_OPTION) return save(); return true; }
From source file:org.interreg.docexplore.management.manage.ManageComponent.java
public void importBook(final File file, final Book selected) { GuiUtils.blockUntilComplete(new ProgressRunnable() { float[] progress = { 0 }; BookExporter exporter = new BookExporter(); public void run() { File tmpDir = null;//from ww w . j a va2 s.c o m try { tmpDir = new File(DocExploreTool.getHomeDir(), ".export-tmp"); if (tmpDir.exists()) FileUtils.deleteDirectory(tmpDir); tmpDir.mkdirs(); ZipUtils.unzip(file, tmpDir); DataLinkFS2Source source = new DataLinkFS2Source(tmpDir.getAbsolutePath()); DataLink fs2link = source.getDataLink(); final ManuscriptLink link = new ManuscriptLink(fs2link); Book remote = link.getBook(link.getLink().getAllBookIds().get(0)); Book merge = null; boolean cancel = false; if (selected != null && selected.getLastPageNumber() == remote.getLastPageNumber()) { int res = JOptionPane.showConfirmDialog(win, XMLResourceBundle.getBundledString("manageMergeMessage").replace("%name", selected.getName()), XMLResourceBundle.getBundledString("manageMergeLabel"), JOptionPane.YES_NO_CANCEL_OPTION); if (res == JOptionPane.CANCEL_OPTION) cancel = true; else if (res == JOptionPane.YES_OPTION) merge = selected; } if (!cancel && merge == null) { Book found = findTitle(remote.getName()); if (found != null && found != selected && found.getLastPageNumber() == remote.getLastPageNumber()) { int res = JOptionPane.showConfirmDialog(win, XMLResourceBundle.getBundledString("manageMergeMessage").replace("%name", found.getName()), XMLResourceBundle.getBundledString("manageMergeLabel"), JOptionPane.YES_NO_CANCEL_OPTION); if (res == JOptionPane.CANCEL_OPTION) cancel = true; else if (res == JOptionPane.YES_OPTION) merge = found; } } String newTitle = null; if (!cancel && merge == null) { String title = remote.getName(); while (findTitle(title) != null) if ((title = JOptionPane.showInputDialog(XMLResourceBundle .getBundledString("manageExistsMessage").replace("%name", title), title)) == null) { cancel = true; break; } newTitle = title; } if (!cancel) { if (merge == null) { Book imported = exporter.add(remote, win.getDocExploreLink(), null); if (newTitle != null) imported.setName(newTitle); } else exporter.merge(remote, merge, null); } link.getLink().release(); } catch (Exception e) { ErrorHandler.defaultHandler.submit(e); } if (tmpDir != null) try { FileUtils.deleteDirectory(tmpDir); } catch (Exception e) { ErrorHandler.defaultHandler.submit(e, true); } } public float getProgress() { return .5f * exporter.progress + .5f * progress[0]; } }, win); reload(); }
From source file:org.interreg.docexplore.PresentationImporter.java
void doImport(Component comp, String title, String desc, File bookFile) throws Exception { progress = 0;/*from w w w. j av a 2s.c o m*/ File indexFile = new File(exportDir, "index.xml"); if (!indexFile.exists()) { ErrorHandler.defaultHandler.submit(new Exception("Invalid server resource directory")); } try { int bookNum = 0; for (String filename : exportDir.list()) if (filename.startsWith("book") && filename.endsWith(".xml")) { String numString = filename.substring(4, filename.length() - 4); try { int num = Integer.parseInt(numString); if (num >= bookNum) bookNum = num + 1; } catch (Exception e) { } } String bookFileName = "book" + bookNum + ".xml"; String xml = StringUtils.readFile(indexFile, "UTF-8"); //look for duplicate int curIndex = 0; while (curIndex >= 0) { int startIndex = xml.indexOf("<Book", curIndex); if (startIndex < 0) break; int index = xml.indexOf("title=\"", startIndex); if (index < 0) break; index += "title=\"".length(); int endIndex = xml.indexOf("\"", index); String testTitle = xml.substring(index, endIndex); if (testTitle.equals(title)) { int res = JOptionPane.showConfirmDialog(comp, XMLResourceBundle.getString("authoring-lrb", "exportDuplicateMessage"), "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION); if (res == JOptionPane.CANCEL_OPTION) return; if (res == JOptionPane.YES_OPTION) { endIndex = xml.indexOf("</Book>", startIndex); xml = xml.substring(0, startIndex) + xml.substring(endIndex + "</Book>".length(), xml.length()); } else { title = JOptionPane.showInputDialog(comp, XMLResourceBundle.getString("authoring-lrb", "collectionAddBookMessage"), title); if (title != null) doImport(comp, title, desc, bookFile); return; } break; } curIndex = endIndex; } int insertIndex = xml.indexOf("</Index>"); if (insertIndex < 0) throw new Exception("Invalid index file"); xml = xml.substring(0, insertIndex) + "\t<Book title=\"" + title + "\" src=\"" + bookFileName + "\">\n\t\t" + desc + "\n\t</Book>\n" + xml.substring(insertIndex); FileOutputStream indexOutput = new FileOutputStream(indexFile); indexOutput.write(xml.getBytes(Charset.forName("UTF-8"))); indexOutput.close(); File bookDir = new File(exportDir, "book" + bookNum); String bookSpec = StringUtils.readFile(bookFile, "UTF-8"); int start = bookSpec.indexOf("path=\"") + 6; int end = bookSpec.indexOf("\"", start); bookSpec = bookSpec.substring(0, start) + bookDir.getName() + "/" + bookSpec.substring(end); FileOutputStream bookOutput = new FileOutputStream(new File(exportDir, bookFileName)); bookOutput.write(bookSpec.toString().getBytes(Charset.forName("UTF-8"))); bookOutput.close(); File contentDir = new File(bookFile.getParentFile(), bookFile.getName().substring(0, bookFile.getName().length() - 4)); FileUtils.moveDirectory(contentDir, bookDir); } catch (Exception e) { ErrorHandler.defaultHandler.submit(e); } }
From source file:org.jajuk.services.startup.StartupCollectionService.java
private static void tryToParseABackupFile() { final File[] fBackups = SessionService.getConfFileByPath("").listFiles(new FilenameFilter() { @Override/*from w w w . j a v a2 s.c o m*/ public boolean accept(File dir, String name) { if (name.indexOf("backup") != -1) { return true; } return false; } }); final List<File> alBackupFiles = new ArrayList<File>(Arrays.asList(fBackups)); Collections.sort(alBackupFiles); // sort alphabetically (newest // last) Collections.reverse(alBackupFiles); // newest first now final Iterator<File> it = alBackupFiles.iterator(); // parse all backup files, newest first boolean parsingOK = false; while (!parsingOK && it.hasNext()) { final File file = it.next(); try { // Clear all previous collection Collection.clearCollection(); // Load the backup file Collection.load(file); parsingOK = true; // Show a message telling user that we use a backup file final int i = Messages.getChoice(Messages.getString("Error.133") + ":\n" + file.getAbsolutePath(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (i == JOptionPane.CANCEL_OPTION) { System.exit(-1); //NOSONAR } break; } catch (final Exception e2) { Log.error(5, file.getAbsolutePath(), e2); } } }
From source file:org.jajuk.util.UpgradeManager.java
/** * Require user to perform a deep scan.//w w w . j a v a 2 s.c o m */ private static void deepScanRequest() { int reply = Messages.getChoice(Messages.getString("Warning.7"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (reply == JOptionPane.CANCEL_OPTION || reply == JOptionPane.NO_OPTION) { return; } if (reply == JOptionPane.YES_OPTION) { final Thread t = new Thread("Device Refresh Thread after upgrade") { @Override public void run() { List<Device> devices = DeviceManager.getInstance().getDevices(); for (Device device : devices) { if (device.isReady()) { device.manualRefresh(false, false, true, null); } } } }; t.setPriority(Thread.MIN_PRIORITY); t.start(); } }
From source file:org.nuclos.client.main.MainController.java
public static void cmdOpenSettings() { NuclosSettingsContainer panel = new NuclosSettingsContainer(frm); JOptionPane p = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null); JDialog dlg = p.createDialog(Main.getInstance().getMainFrame(), SpringLocaleDelegate.getInstance().getMessage("R00022927", "Einstellungen")); dlg.pack();// w w w .j a va2 s . c o m dlg.setResizable(true); dlg.setVisible(true); Object o = p.getValue(); int res = ((o instanceof Integer) ? ((Integer) o).intValue() : JOptionPane.CANCEL_OPTION); if (res == JOptionPane.OK_OPTION) { try { panel.save(); } catch (PreferencesException e) { Errors.getInstance().showExceptionDialog(frm, e); } } }
From source file:org.openuat.apps.IPSecConnectorAdmin.java
/** * dialog to set up the dongle configuration. *//*w ww. j a v a2s . c o m*/ private static Configuration configureDialog(String[] ports, String[] sides, String[] types) { JTextField username = new JTextField(); JComboBox cport = new JComboBox(ports); JComboBox csides = new JComboBox(sides); JComboBox ctypes = new JComboBox(types); int option = JOptionPane.showOptionDialog(null, new Object[] { "User Name:", username, "Choose your port", cport, "On which side of your Device is the Dongle plugged into:", csides, " What type of Device:", ctypes, }, " Relate Dongle Configuration", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if ((option == JOptionPane.CLOSED_OPTION) || (option == JOptionPane.CANCEL_OPTION)) { System.exit(0); } Configuration config = new Configuration(cport.getSelectedItem() + ""); config.setType(ctypes.getSelectedIndex()); config.setSide(csides.getSelectedIndex()); config.setUserName(username.getText()); config.setDeviceType(Configuration.DEVICE_TYPE_DONGLE); // logger.finer(config); return config; }
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;/*from w w w .j ava2s . com*/ } } 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.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();//from w w w . j a v a 2 s . 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); } }