List of usage examples for javax.swing JOptionPane OK_OPTION
int OK_OPTION
To view the source code for javax.swing JOptionPane OK_OPTION.
Click Source Link
From source file:net.sf.jabref.external.DroppedFileHandler.java
private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry, BibDatabase database) {/* w w w . j a v a 2 s. co 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./*from w w w . j a v a2 s . com*/ */ 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:org.audiveris.omr.sheet.ScaleBuilder.java
/** * An abnormal situation has been found, as detailed in provided msg, * now how should we proceed, depending on batch mode or user answer. * * @param msg the problem description/*from w w w . j a va2 s .co m*/ * @throws StepException thrown when processing must stop */ private void makeDecision(String msg) throws StepException { logger.warn(msg.replaceAll(LINE_SEPARATOR, " ")); Score score = sheet.getScore(); if (Main.getGui() != null) { // Make sheet visible to the user SheetsController.getInstance().showAssembly(sheet); } if ((Main.getGui() == null) || (Main.getGui().displayModelessConfirm( msg + LINE_SEPARATOR + "OK for discarding this sheet?") == JOptionPane.OK_OPTION)) { if (score.isMultiPage()) { sheet.remove(false); throw new StepException("Sheet removed"); } else { throw new StepException("Sheet ignored"); } } }
From source file:ftpclientgui.MainWindow.java
/** * Browse button clicked. Show the file chooser and fill in the text field afterwards * @param evt //w w w . j av a 2 s . c o m */ private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed if (fileChoose.showOpenDialog(this) == JOptionPane.OK_OPTION) { txtUploadFile.setText(fileChoose.getSelectedFile().getPath()); } }
From source file:net.sf.jabref.gui.journals.ManageJournalsPanel.java
private boolean readyToClose() { Path filePath;/*from w w w . ja v a 2s . c o m*/ if (newFile.isSelected()) { if (newNameTf.getText().isEmpty()) { if (tableModel.getRowCount() > 0) { JOptionPane.showMessageDialog(this, Localization.lang("You must choose a filename to store journal abbreviations"), Localization.lang("Store journal abbreviations"), JOptionPane.ERROR_MESSAGE); return false; } else { return true; } } else { filePath = Paths.get(newNameTf.getText()); return !Files.exists(filePath) || (JOptionPane.showConfirmDialog(this, Localization.lang("'%0' exists. Overwrite file?", filePath.getFileName().toString()), Localization.lang("Store journal abbreviations"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION); } } return true; }
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. j a v a2 s . c o 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:com.t3.client.TabletopTool.java
/** * Displays a confirmation dialog that uses the message as a key to the * properties file, and the additional values as parameters to the * formatting of the key lookup./* w w w . jav a2s .c o m*/ * * @param message * key from the properties file (preferred) or hard-coded string * to display * @param params * optional arguments for the formatting of the property value * @return <code>true</code> if the user clicks the OK button, * <code>false</code> otherwise */ public static boolean confirm(String message, Object... params) { // String msg = I18N.getText(message, params); // log.debug(message); String title = I18N.getText("msg.title.messageDialogConfirm"); // return JOptionPane.showConfirmDialog(clientFrame, msg, title, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION; return confirmImpl(title, JOptionPane.OK_OPTION, message, params) == JOptionPane.OK_OPTION; }
From source file:sk.uniza.fri.pds.spotreba.energie.gui.MainGui.java
private void typeAndCatMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_typeAndCatMenuItemActionPerformed final StatistikaTypuKategorieParams params = new StatistikaTypuKategorieParams(); int option = showUniversalInputDialog(params, "tatistika poda typu a kategrie"); if (option == JOptionPane.OK_OPTION) { new SwingWorker<List, RuntimeException>() { @Override/*from www.jav a2 s.c o m*/ protected List doInBackground() throws Exception { try { return SeHistoriaService.getInstance().getTypeAndCategoryStatistics(params); } catch (RuntimeException e) { publish(e); return null; } } @Override protected void done() { try { List data = get(); showJTable(StatistikaTypuKategorie.class, data); } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex); } } @Override protected void process(List<RuntimeException> chunks) { if (chunks.size() > 0) { showException("Chyba", chunks.get(0)); } } }.execute(); } }
From source file:mekhq.gui.FinancesTab.java
private void addFundsActionPerformed() { AddFundsDialog addFundsDialog = new AddFundsDialog(getFrame(), true); addFundsDialog.setVisible(true);/*w w w. j av a 2s.c o m*/ if (addFundsDialog.getClosedType() == JOptionPane.OK_OPTION) { long funds = addFundsDialog.getFundsQuantity(); String description = addFundsDialog.getFundsDescription(); int category = addFundsDialog.getCategory(); getCampaign().addFunds(funds, description, category); } }
From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java
public void reinitializeDetailsViewFiles() { String dialogTitle = "Reinitialize details view files?"; String message = "This resets all details view related files, all manual changes will be lost!\nReinitialize details view right now?"; int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); // TODO: add "Show in Finder/Explorer" button if running on Mac/Windows if (JOptionPane.OK_OPTION != result) { return;/*from www . j av a 2 s . c om*/ } applicationPreferences.initDetailsViewRoot(true); }