List of usage examples for javax.swing JOptionPane showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) throws HeadlessException
optionType
parameter, where the messageType
parameter determines the icon to display. From source file:edu.ku.brc.helpers.EMailHelper.java
/** * Asks for a password.//from w w w .j a va 2 s . co m * @param topframe the parent frame * @return the password */ public static String askForPassword(final Frame topframe) { PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p", "p,2px,p")); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); JLabel label = createI18NFormLabel("EMailHelper.PASSWORD"); //$NON-NLS-1$ //$NON-NLS-2$ JPasswordField passField = createPasswordField(25); JCheckBox savePassword = createCheckBox(getResourceString("EMailHelper.SAVE_PASSWORD")); //$NON-NLS-1$ builder.add(label, cc.xy(1, 1)); builder.add(passField, cc.xy(3, 1)); builder.add(savePassword, cc.xy(3, 3)); JOptionPane.showConfirmDialog(topframe, builder.getPanel(), getResourceString("EMailHelper.PASSWORD_TITLE"), //$NON-NLS-1$ JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); String passwordText = new String(passField.getPassword()); if (savePassword.isSelected()) { AppPreferences appPrefs = AppPreferences.getRemote(); if (StringUtils.isNotEmpty(passwordText)) { appPrefs.put("settings.email.password", Encryption.encrypt(passwordText)); //$NON-NLS-1$ } } return passwordText; }
From source file:latexstudio.editor.EditorTopComponent.java
public UnsavedWorkState canOpen() { if (isModified() && !isPreviewDisplayed()) { int userChoice = JOptionPane.showConfirmDialog(this, "This document has been modified. Do you want to save it first?", "Save document", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (userChoice == JOptionPane.YES_OPTION) { return UnsavedWorkState.SAVE_AND_OPEN; } else if (userChoice == JOptionPane.NO_OPTION) { return UnsavedWorkState.OPEN; } else {/*from w ww .j a v a2 s .c om*/ return UnsavedWorkState.CANCEL; } } else { return UnsavedWorkState.OPEN; } }
From source file:net.sf.jabref.external.DroppedFileHandler.java
private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry, BibDatabase database) {// w ww. j av a2 s . c o m String dialogTitle = Localization.lang("Link to file %0", linkFileName); List<String> dirs = panel.getBibDatabaseContext().getFileDirectory(); int found = -1; for (int i = 0; i < dirs.size(); i++) { if (new File(dirs.get(i)).exists()) { found = i; break; } } if (found < 0) { destDirLabel.setText(Localization.lang("File directory is not set or does not exist!")); copyRadioButton.setEnabled(false); moveRadioButton.setEnabled(false); renameToTextBox.setEnabled(false); renameCheckBox.setEnabled(false); linkInPlace.setSelected(true); } else { destDirLabel.setText(Localization.lang("File directory is '%0':", dirs.get(found))); copyRadioButton.setEnabled(true); moveRadioButton.setEnabled(true); renameToTextBox.setEnabled(true); renameCheckBox.setEnabled(true); } ChangeListener cl = arg0 -> { renameCheckBox.setEnabled(!linkInPlace.isSelected()); renameToTextBox.setEnabled(!linkInPlace.isSelected()); }; linkInPlace.setText(Localization.lang("Leave file in its current directory")); copyRadioButton.setText(Localization.lang("Copy file to file directory")); moveRadioButton.setText(Localization.lang("Move file to file directory")); renameCheckBox.setText(Localization.lang("Rename file to").concat(": ")); // Determine which name to suggest: String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.journalAbbreviationLoader, Globals.prefs); renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension())); linkInPlace.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_LEAVE)); copyRadioButton.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_COPY)); moveRadioButton.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_MOVE)); renameCheckBox.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_RENAME)); linkInPlace.addChangeListener(cl); cl.stateChanged(new ChangeEvent(linkInPlace)); try { Object[] messages = { Localization.lang("How would you like to link to '%0'?", linkFileName), optionsPanel }; int reply = JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (reply == JOptionPane.OK_OPTION) { // store user's choice frame.prefs().putBoolean(DroppedFileHandler.DFH_LEAVE, linkInPlace.isSelected()); frame.prefs().putBoolean(DroppedFileHandler.DFH_COPY, copyRadioButton.isSelected()); frame.prefs().putBoolean(DroppedFileHandler.DFH_MOVE, moveRadioButton.isSelected()); frame.prefs().putBoolean(DroppedFileHandler.DFH_RENAME, renameCheckBox.isSelected()); return true; } else { return false; } } finally { linkInPlace.removeChangeListener(cl); } }
From source file:org.fhaes.jsea.JSEAFrame.java
/** * Initialize the menu/toolbar actions./* ww w.j av a 2 s . co m*/ */ private void initActions() { final JFrame glue = this; actionFileExit = new FHAESAction("Close", "close.png") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { dispose(); } }; actionChartProperties = new FHAESAction("Chart properties", "properties.png") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { ChartEditor editor = ChartEditorManager .getChartEditor(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart()); int result = JOptionPane.showConfirmDialog(glue, editor, "Properties", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { editor.updateChart(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart()); } } }; actionReset = new FHAESAction("Reset", "filenew.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { Object[] options = { "Yes", "No", "Cancel" }; int n = JOptionPane.showOptionDialog(glue, "Are you sure you want to start a new analysis?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setToDefault(); } } }; actionRun = new FHAESAction("Run analysis", "run.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { runAnalysis(); } }; actionSaveAll = new FHAESAction("Save all results", "save_all.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } File f; try { f = new File(file.getAbsolutePath() + File.separator + "report.txt"); saveReportTXT(f); f = new File(file.getAbsolutePath() + File.separator + "report.pdf"); saveReportPDF(f); f = new File(file.getAbsolutePath() + File.separator + "chart.png"); saveChartPNG(f); f = new File(file.getAbsolutePath() + File.separator + "chart.pdf"); saveChartPDF(f); f = new File(file.getAbsolutePath() + File.separator + "data.xls"); saveDataXLS(f); f = new File(file.getAbsolutePath()); saveDataCSV(f); } catch (IOException e) { e.printStackTrace(); } } }; actionSaveData = new FHAESAction("Save data tables", "table.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } try { saveDataCSV(file); } catch (IOException e) { e.printStackTrace(); } } }; actionSaveReport = new FHAESAction("Save report", "report.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } // Set file filters fc.setAcceptAllFileFilterUsed(false); TXTFileFilter txtfilter = new TXTFileFilter(); PDFFilter pdffilter = new PDFFilter(); fc.addChoosableFileFilter(txtfilter); fc.addChoosableFileFilter(pdffilter); fc.setFileFilter(txtfilter); FileFilter chosenFilter; // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); chosenFilter = fc.getFileFilter(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } // Handle file type and extensions nicely if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) { if (chosenFilter.equals(txtfilter)) { file = new File(file.getAbsoluteFile() + ".txt"); } else if (chosenFilter.equals(pdffilter)) { file = new File(file.getAbsoluteFile() + ".pdf"); } } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("txt") && chosenFilter.equals("pdf")) { chosenFilter = txtfilter; } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf") && chosenFilter.equals("txt")) { chosenFilter = pdffilter; } // If file already exists confirm overwrite if (file.exists()) { // Check we have write access to this file if (!file.canWrite()) { JOptionPane.showMessageDialog(glue, "You do not have write permission to this file", "Error", JOptionPane.ERROR_MESSAGE); return; } int n = JOptionPane.showConfirmDialog(glue, "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?", "Overwrite file?", JOptionPane.YES_NO_OPTION); if (n != JOptionPane.YES_OPTION) { return; } } // Do save try { if (chosenFilter.equals(txtfilter)) { saveReportTXT(file); } else if (chosenFilter.equals(pdffilter)) { saveReportPDF(file); } else { log.error("No export file format chosen. Shouldn't be able to get here!"); } } catch (IOException e) { JOptionPane.showMessageDialog(glue, "Unable to save report. Check log file.", "Warning", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }; actionSaveChart = new FHAESAction("Save chart", "barchart.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } // Set file filters fc.setAcceptAllFileFilterUsed(false); PNGFilter pngfilter = new PNGFilter(); PDFFilter pdffilter = new PDFFilter(); fc.addChoosableFileFilter(pngfilter); fc.addChoosableFileFilter(pdffilter); fc.setFileFilter(pngfilter); FileFilter chosenFilter; // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); chosenFilter = fc.getFileFilter(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } // Handle file type and extensions nicely if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) { if (chosenFilter.equals(pngfilter)) { file = new File(file.getAbsoluteFile() + ".png"); } else if (chosenFilter.equals(pdffilter)) { file = new File(file.getAbsoluteFile() + ".pdf"); } } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("png") && chosenFilter.equals("pdf")) { chosenFilter = pngfilter; } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf") && chosenFilter.equals("png")) { chosenFilter = pdffilter; } // If file already exists confirm overwrite if (file.exists()) { // Check we have write access to this file if (!file.canWrite()) { JOptionPane.showMessageDialog(glue, "You do not have write permission to this file", "Error", JOptionPane.ERROR_MESSAGE); return; } int n = JOptionPane.showConfirmDialog(glue, "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?", "Overwrite file?", JOptionPane.YES_NO_OPTION); if (n != JOptionPane.YES_OPTION) { return; } } // Do save try { if (chosenFilter.equals(pngfilter)) { saveChartPNG(file); } else if (chosenFilter.equals(pdffilter)) { saveChartPDF(file); } else { log.error("No export file format chosen. Shouldn't be able to get here!"); } } catch (IOException e) { JOptionPane.showMessageDialog(glue, "Unable to save chart. Check log file.", "Warning", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }; actionCopy = new FHAESAction("Copy", "edit_copy.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { copyCurrentSelectionToClipboard(); } }; actionLagMap = new FHAESAction("LagMap", "lagmap22.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { launchLagMap(); } }; }
From source file:jmemorize.gui.swing.frames.MainFrame.java
/** * If lesson was modified this shows a dialog that asks if the user wants to * save the lesson before closing it./* w w w . jav a2s. co m*/ * * @return <code>true</code> if user chose not to cancel the lesson close * operation. If this method return <code>false</code> the closing * of jMemorize was canceled. */ public boolean allowTheUserToSaveIfClosing() { // first check the editCardFrame for unsaved changes final EditCardFrame editFrame = EditCardFrame.getInstance(); if (editFrame.isVisible() && !editFrame.close()) { return false; // user canceled closing of edit card frame } if (!m_newCardManager.closeAllFrames()) // close all addCard frames { return false; } // then see if lesson should to be saved final Lesson lesson = m_main.getLesson(); if (lesson.canSave()) { final int n = JOptionPane.showConfirmDialog(MainFrame.this, Localization.get("MainFrame.SAVE_MODIFIED"), //$NON-NLS-1$ "Warning", //$NON-NLS-1$ JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (n == JOptionPane.OK_OPTION) { try { jMemorizeIO.saveLesson(lesson); jMemorizeIO.reset(); } catch (final Exception exception) { final File file = jMemorizeIO.getFile(); final Object[] args = { file != null ? file.getName() : "?" }; final MessageFormat form = new MessageFormat(Localization.get(LC.ERROR_SAVE)); final String msg = form.format(args); Main.logThrowable(msg, exception); new ErrorDialog(this, msg, exception).setVisible(true); } // if lesson was saved return true, false otherwise return !lesson.canSave(); } // if NO chosen continue, otherwise CANCEL was chosen return n == JOptionPane.NO_OPTION; } return true; }
From source file:gdt.jgui.entity.JEntityFacetPanel.java
private void removeFacets() { try {//from w w w. j av a 2 s . c o m // System.out.println("EntityFacetPanel:removeFacets:BEGIN"); JItemPanel[] ipa = getItems(); if (ipa == null) return; ArrayList<JFacetOpenItem> foil = new ArrayList<JFacetOpenItem>(); for (JItemPanel aIpa : ipa) { if (aIpa.isChecked()) { if (((JFacetOpenItem) aIpa).isRemovable()) foil.add((JFacetOpenItem) aIpa); else aIpa.setChecked(false); } } JFacetOpenItem[] foia = foil.toArray(new JFacetOpenItem[0]); if (foia.length < 1) return; int response = JOptionPane.showConfirmDialog(this, "Delete selected facets ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) return; for (JFacetOpenItem foi : foia) foi.removeFacet(); console.putContext(instantiate(console, this.locator$), this.locator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } }
From source file:gdt.jgui.base.JPropertyPanel.java
public void deleteProperty(JMainConsole console, String locator$) { try {// w ww . j a va2 s. c o m Properties locator = Locator.toProperties(locator$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); Entigrator entigrator = console.getEntigrator(entihome$); String propertyName$ = locator.getProperty(JDesignPanel.PROPERTY_NAME); int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete property ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { entigrator.prp_deletePropertyName(propertyName$); JDesignPanel dp = new JDesignPanel(); String dpLocator$ = dp.getLocator(); dpLocator$ = Locator.append(dpLocator$, Entigrator.ENTIHOME, entihome$); JConsoleHandler.execute(console, dpLocator$); } } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:com.edduarte.protbox.Protbox.java
private static void changeProtPath(PReg reg, File serializedDirectory) throws ProtboxException { if (JOptionPane.showConfirmDialog(null, "The prot folder from one of your registries\n" + "was deleted while Protbox wasn't running!\n" + "Do you wish to set a new folder to place the decoded files from the shared folder?\n" + "CHOOSING \"NO\" WILL DELETE THE REGISTRY AND YOU WILL LOSE ACCESS TO THE FILES " + "IN THE SHARED FOLDER!", "Prot Folder was deleted!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { final DirectoryChooser chooser = new DirectoryChooser("Choose Output folder..."); String newOutputPath = chooser.getDirectory(); if (newOutputPath != null) { reg.changeProtPath(newOutputPath); } else {/*w w w . j a v a 2 s . c o m*/ changeProtPath(reg, serializedDirectory); } } else { reg.stop(); serializedDirectory.deleteOnExit(); } }
From source file:de.juwimm.cms.util.Communication.java
public boolean exitPerformed(ExitEvent e) { log.info("Exit-event started"); int result = JOptionPane.showConfirmDialog(UIConstants.getMainFrame(), rb.getString("dialog.exit.text"), rb.getString("dialog.exit"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { if (!checkOutPages.isEmpty()) { ArrayList<ContentValue> pageList = new ArrayList<ContentValue>(); Iterator it = checkOutPages.iterator(); while (it.hasNext()) { try { ContentValue current = getClientService().getContent(((Integer) it.next())); pageList.add(current); } catch (Exception ex) { String msg = Messages.getString("exception.checkingInAllRemainingPages", Integer.toString(checkOutPages.size())); log.info(msg);//from w ww. j a va 2 s. co m JOptionPane.showMessageDialog(UIConstants.getMainFrame(), msg, rb.getString("dialog.title"), JOptionPane.INFORMATION_MESSAGE); UIConstants.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); while (it.hasNext()) { Integer contentId = (Integer) it.next(); try { msg = Messages.getString("exception.checkingInAllRemainingPagesStatusbar", contentId.toString()); UIConstants.setActionStatus(msg); getClientService().checkIn4ContentId(contentId); } catch (Exception exe) { log.error("Exit event error", exe); } } checkOutPages = new ArrayList<Integer>(); UIConstants.getMainFrame().setCursor(Cursor.getDefaultCursor()); try { if (log.isDebugEnabled()) { log.debug("Calling logout on server"); } getClientService().logout(); } catch (Exception exe) { } log.info("Goodbye!"); loggedIn = false; return true; } } PanCheckInPages pan = new PanCheckInPages(pageList); if (rb == null) rb = Constants.rb; DlgModal dlg = new DlgModal(pan, 300, 500, rb.getString("DlgModal.checkin")); dlg.addOkListener(new OkListener(pan, dlg)); dlg.setVisible(true); } try { if (log.isDebugEnabled()) { log.debug("Calling logout on server"); } getClientService().logout(); } catch (Exception exe) { } log.info("Goodbye!"); loggedIn = false; return true; } return false; }
From source file:uk.co.markfrimston.tasktree.Main.java
@Override public boolean confirmMerge() { return JOptionPane.showConfirmDialog(this, "Was the merge completed successfully?", "Merge", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION; }