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.fhaes.gui.AnalysisResultsPanel.java
/** * Save a file to disk, asking the user for a filename. Add the selected FileFilter to the save dialog box. * //from w w w . jav a 2 s.co m * @param fileToSave * @param filter */ private void saveFileToDisk(File fileToSave, FileFilter filter) { File outfile = IOUtil.getOutputFile(filter); if (outfile == null) return; if (outfile.exists()) { Object[] options = { "Overwrite", "No", "Cancel" }; int response = JOptionPane.showOptionDialog(App.mainFrame, "This file already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon options, // the titles of buttons options[0]); // default button title if (response != JOptionPane.YES_OPTION) { return; } } try { FileUtils.copyFile(fileToSave, outfile); } catch (IOException e) { JOptionPane.showMessageDialog(App.mainFrame, "Error saving file:\n" + e.getMessage()); e.printStackTrace(); } }
From source file:org.fhaes.gui.ShapeFileDialog.java
/** * Prompt the user for an output filename * //from ww w . j a va 2 s .c o m * @param filter * @return */ private File getOutputFile(FileFilter filter) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null); File outputFile; // Create a file chooser final JFileChooser fc = new JFileChooser(lastVisitedFolder); fc.setAcceptAllFileFilterUsed(true); if (filter != null) { fc.addChoosableFileFilter(filter); fc.setFileFilter(filter); } fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Save as..."); // In response to a button click: int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { outputFile = fc.getSelectedFile(); if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") { log.debug("Output file extension not set by user"); if (fc.getFileFilter().getDescription().equals(new SHPFileFilter().getDescription())) { log.debug("Adding shp extension to output file name"); outputFile = new File(outputFile.getAbsolutePath() + ".shp"); } } else { log.debug("Output file extension set my user to '" + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'"); } App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath()); } else { return null; } if (outputFile.exists()) { Object[] options = { "Overwrite", "No", "Cancel" }; int response = JOptionPane.showOptionDialog(this, "The file '" + outputFile.getName() + "' already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon options, // the titles of buttons options[0]); // default button title if (response != JOptionPane.YES_OPTION) { return null; } } return outputFile; }
From source file:org.intermine.install.swing.ProjectEditor.java
/** * Prompt the user to ask whether to save the modified project before * proceeding./*w ww . j a va 2 s .c o m*/ * * @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 {/* w w w. j a v a 2s . 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;// ww w .j a v a 2s . 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 ww w .j a va2 s . 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.base.Device.java
/** * Mount the device./*w w w .j av a2 s . c o m*/ * * @param bManual set whether mount is manual or auto * * @return whether the device has been mounted. If user is asked for mounting but cancel, this method returns false. * * @throws JajukException if device cannot be mounted due to technical reason. */ public boolean mount(final boolean bManual) throws JajukException { if (bMounted) { // Device already mounted throw new JajukException(111); } // Check if we can mount the device. boolean readyToMount = checkDevice(); // Effective mounting if available. if (readyToMount) { bMounted = true; } else if (pathExists() && isVoid() && bManual) { // If the device is void and in manual mode, leave a chance to the user to // force it final int answer = Messages.getChoice( "[" + getName() + "] " + Messages.getString("Confirmation_void_refresh"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); // leave if user doesn't confirm to mount the void device if (answer != JOptionPane.YES_OPTION) { return false; } else { bMounted = true; } } else { throw new JajukException(11, "\"" + getName() + "\" at URL : " + getUrl()); } // notify views to refresh if needed ObservationManager.notify(new JajukEvent(JajukEvents.DEVICE_MOUNT)); return bMounted; }
From source file:org.jajuk.ui.views.CoverView.java
/** * Called on the delete cover button event. *///from w w w . ja v a 2 s .c om private void handleDelete() { // sanity check if (index >= alCovers.size()) { Log.warn("Cannot delete cover that is not available."); return; } if (index < 0) { Log.warn("Cannot delete cover with invalid index."); return; } // get the cover at the specified position final Cover cover = alCovers.get(index); // don't delete the splashscreen-jpg!! if (cover.getType().equals(CoverType.NO_COVER)) { Log.warn("Cannot delete default Jajuk cover."); return; } // show confirmation message if required if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_DELETE_COVER)) { final int iResu = Messages.getChoice( Messages.getString("Confirmation_delete_cover") + " : " + cover.getFile(), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (iResu != JOptionPane.YES_OPTION) { return; } } // yet there? ok, delete the cover try { final File file = cover.getFile(); if (file.isFile() && file.exists()) { UtilSystem.deleteFile(file); } else { // not a file, must have a problem throw new Exception("Encountered file which either is not a file or does not exist: " + file); } } catch (final Exception ioe) { Log.error(131, ioe); Messages.showErrorMessage(131); return; } // If this was the absolute cover, remove the reference in the // collection if (cover.getType() == CoverType.SELECTED_COVER) { dirReference.removeProperty("default_cover"); } // reorganize covers try { listLock.lock(); alCovers.remove(index); index--; if (index < 0) { index = alCovers.size() - 1; } ObservationManager.notify(new JajukEvent(JajukEvents.COVER_NEED_REFRESH)); if (fileReference != null) { update(new JajukEvent(JajukEvents.COVER_NEED_REFRESH)); } } finally { listLock.unlock(); } }
From source file:org.jajuk.ui.views.ParameterViewGUIHelper.java
@Override public void actionPerformed(final ActionEvent e) { if (e.getSource() == pv.jbClearHistory) { // show confirmation message if required if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_CLEAR_HISTORY)) { final int iResu = Messages.getChoice(Messages.getString("Confirmation_clear_history"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (iResu != JOptionPane.YES_OPTION) { return; }//from www . jav a 2s . c o m } ObservationManager.notify(new JajukEvent(JajukEvents.CLEAR_HISTORY)); } else if (e.getSource() == pv.scbLAF) { // Refresh full GUI at each LAF change as a preview UtilGUI.setupSubstanceLookAndFeel((String) pv.scbLAF.getSelectedItem()); UtilGUI.updateAllUIs(); } else if (e.getSource() == pv.jbResetRatings) { // show confirmation message if required if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_RESET_RATINGS)) { final int iResu = Messages.getChoice(Messages.getString("Confirmation_reset_ratings"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (iResu != JOptionPane.YES_OPTION) { return; } } ObservationManager.notify(new JajukEvent(JajukEvents.RATE_RESET)); } else if (e.getSource() == pv.jbResetPreferences) { // show confirmation message if required if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_RESET_RATINGS)) { final int iResu = Messages.getChoice(Messages.getString("Confirmation_reset_preferences"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (iResu != JOptionPane.YES_OPTION) { return; } } if (!DeviceManager.getInstance().isAnyDeviceRefreshing()) { ObservationManager.notify(new JajukEvent(JajukEvents.PREFERENCES_RESET)); } else { Messages.showErrorMessage(120); } } else if (e.getSource() == pv.jbOK) { updateConfFromGUI(); // Notify any client than wait for parameters updates final Properties details = new Properties(); details.put(Const.DETAIL_ORIGIN, this); ObservationManager.notify(new JajukEvent(JajukEvents.PARAMETERS_CHANGE, details)); if (someOptionsAppliedAtNextStartup) { // Inform user that some parameters will apply only at // next startup Messages.showInfoMessage(Messages.getString("ParameterView.198")); someOptionsAppliedAtNextStartup = false; } // Update Mute state according to bit-perfect mode ActionManager.getAction(JajukActions.MUTE_STATE).setEnabled(!Conf.getBoolean(Const.CONF_BIT_PERFECT)); } else if (e.getSource() == pv.jbDefault) { int resu = Messages.getChoice(Messages.getString("Confirmation_defaults"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); if (resu == JOptionPane.OK_OPTION) { Conf.setDefaultProperties(); updateGUIFromConf();// update UI InformationJPanel.getInstance().setMessage(Messages.getString("ParameterView.110"), InformationJPanel.MessageType.INFORMATIVE); updateConfFromGUI(); Messages.showInfoMessage(Messages.getString("ParameterView.198")); } } else if (e.getSource() == pv.jcbBackup) { // if backup option is unchecked, reset backup size if (pv.jcbBackup.isSelected()) { pv.backupSize.setEnabled(true); pv.backupSize.setValue(Conf.getInt(Const.CONF_BACKUP_SIZE)); } else { pv.backupSize.setEnabled(false); pv.backupSize.setValue(0); } } else if ((e.getSource() == pv.jcbProxyNone) || (e.getSource() == pv.jcbProxyHttp) || (e.getSource() == pv.jcbProxySocks)) { final boolean bUseProxy = !pv.jcbProxyNone.isSelected(); pv.jtfProxyHostname.setEnabled(bUseProxy); pv.jtfProxyPort.setEnabled(bUseProxy); pv.jtfProxyLogin.setEnabled(bUseProxy); pv.jtfProxyPwd.setEnabled(bUseProxy); pv.jlProxyHostname.setEnabled(bUseProxy); pv.jlProxyPort.setEnabled(bUseProxy); pv.jlProxyLogin.setEnabled(bUseProxy); pv.jlProxyPwd.setEnabled(bUseProxy); } else if (e.getSource() == pv.jcbAutoCover) { if (pv.jcbAutoCover.isSelected()) { pv.jcbCoverSize.setEnabled(true); pv.jlCoverSize.setEnabled(true); } else { pv.jlCoverSize.setEnabled(false); pv.jcbCoverSize.setEnabled(false); } } else if (e.getSource() == pv.jcbAudioScrobbler) { if (pv.jcbAudioScrobbler.isSelected()) { pv.jlASUser.setEnabled(true); pv.jtfASUser.setEnabled(true); pv.jlASPassword.setEnabled(true); pv.jpfASPassword.setEnabled(true); } else { pv.jlASUser.setEnabled(false); pv.jtfASUser.setEnabled(false); pv.jlASPassword.setEnabled(false); pv.jpfASPassword.setEnabled(false); } } else if (e.getSource() == pv.scbLanguage) { Locale locale = LocaleManager.getLocaleForDesc(((JLabel) pv.scbLanguage.getSelectedItem()).getText()); final String sLocal = locale.getLanguage(); final String sPreviousLocal = LocaleManager.getLocale().getLanguage(); if (!sPreviousLocal.equals(sLocal)) { // local has changed someOptionsAppliedAtNextStartup = true; } } else if (e.getSource() == pv.jcbHotkeys) { someOptionsAppliedAtNextStartup = true; } else if (e.getSource() == pv.jbCatalogRefresh) { new Thread("Parameter Catalog refresh Thread") { @Override public void run() { UtilGUI.waiting(); // Force albums to search for new covers AlbumManager.getInstance().resetCoverCache(); // Clean thumbs ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_50X50); ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_100X100); ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_150X150); ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_200X200); ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_250X250); ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_300X300); UtilGUI.stopWaiting(); // For catalog view's update ObservationManager.notify(new JajukEvent(JajukEvents.DEVICE_REFRESH)); // Display a message Messages.showInfoMessage(Messages.getString("Success")); } }.start(); } // Bit-perfect and audio normalization/cross fade options are mutually exclusive else if (e.getSource().equals(pv.jcbEnableBitPerfect)) { pv.jcbUseVolnorm.setEnabled(!pv.jcbEnableBitPerfect.isSelected()); if (pv.jcbUseVolnorm.isSelected() && pv.jcbEnableBitPerfect.isSelected()) { pv.jcbUseVolnorm.setSelected(false); } pv.crossFadeDuration.setEnabled(!pv.jcbEnableBitPerfect.isSelected()); } else if (e.getSource().equals(pv.jbReloadRadiosPreset)) { SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() { @Override protected Boolean doInBackground() throws Exception { try { java.io.File fPresets = SessionService.getConfFileByPath(Const.FILE_WEB_RADIOS_PRESET); DownloadManager.download(new URL(Const.URL_WEBRADIO_PRESETS), fPresets); WebRadioHelper.loadPresetsRadios(fPresets); return true; } catch (Exception ex) { Log.error(ex); return false; } } @Override protected void done() { try { boolean result = get(); if (result) { Messages.showInfoMessage(Messages.getString("Success")); ObservationManager.notify(new JajukEvent(JajukEvents.DEVICE_REFRESH)); } else { Messages.showErrorMessage(9); } } catch (Exception e) { Log.error(e); } } }; worker.execute(); } }
From source file:org.jajuk.util.UpgradeManager.java
/** * Require user to perform a deep scan./* w w w .j a v a2s.com*/ */ 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(); } }