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:su.fmi.photoshareclient.ui.PhotoViewDialog.java
private void SaveImageButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SaveImageButtonMouseClicked JFileChooser fileChooser = new JFileChooser() { // A warning for overweiting existing files @Override/*from w w w .j a v a 2s.com*/ public void approveSelection() { File f = getSelectedFile(); if (f.exists() && getDialogType() == SAVE_DIALOG) { int result = JOptionPane.showConfirmDialog(this, "The file exists, overwrite?", "Existing file", JOptionPane.YES_NO_CANCEL_OPTION); switch (result) { case JOptionPane.YES_OPTION: super.approveSelection(); return; case JOptionPane.NO_OPTION: return; case JOptionPane.CLOSED_OPTION: return; case JOptionPane.CANCEL_OPTION: cancelSelection(); return; } } super.approveSelection(); } }; fileChooser.setDialogTitle("Save image as..."); File rootVolume = File.listRoots()[0]; fileChooser.setSelectedFile(new File(rootVolume.getAbsolutePath(), this.imageLabel.getFileName())); int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.APPROVE_OPTION) { try { File fileToSave = fileChooser.getSelectedFile(); BufferedImage bi = (BufferedImage) this.imageLabel.getImage(); String ext = FilenameUtils.getExtension(fileToSave.getAbsolutePath()); ImageIO.write(bi, ext, fileToSave); } catch (IOException ex) { Logger.getLogger(PhotoViewDialog.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:uk.co.modularaudio.componentdesigner.mainframe.actions.ExitAction.java
@Override public void actionPerformed(final ActionEvent e) { if (fc.isRendering()) { fc.toggleRendering();//from ww w.j a v a2 s.c om } log.debug("ExitAction perform called."); int optionPaneResult = mainFrameActions.rackNotDirtyOrUserConfirmed(); if (optionPaneResult == JOptionPane.YES_OPTION) { // Need to save it - call the save saveFileAction.actionPerformed(e); // Simulate the cancel in the save action if the rack is still dirty. optionPaneResult = (fc.isRackDirty() ? JOptionPane.CANCEL_OPTION : JOptionPane.NO_OPTION); } if (optionPaneResult == JOptionPane.NO_OPTION) { for (final ExitSignalReceiver esr : exitSignalReceivers) { esr.signalPreExit(); } // Stop the engine if (fc.isAudioEngineRunning()) { fc.stopAudioEngine(); } // Give any components in the graph a chance to cleanup first try { fc.ensureRenderingStoppedBeforeExit(); } catch (final Exception e1) { final String msg = "Exception caught during destruction before exit: " + e1.toString(); log.error(msg, e1); } log.debug("Will signal exit"); for (final ExitSignalReceiver esr : exitSignalReceivers) { esr.signalPostExit(); } } }
From source file:uk.co.modularaudio.componentdesigner.mainframe.actions.NewFileAction.java
@Override public void actionPerformed(final ActionEvent e) { log.debug("NewFileAction called."); int dirtyCheckVal = mainFrameActions.rackNotDirtyOrUserConfirmed(); if (dirtyCheckVal == JOptionPane.YES_OPTION) { // Need to save it - call the save saveFileAction.actionPerformed(e); // Simulate the cancel in the save action if the rack is still dirty. dirtyCheckVal = (fc.isRackDirty() ? JOptionPane.CANCEL_OPTION : JOptionPane.NO_OPTION); }/*from w ww . j a v a 2 s . c om*/ // We don't check for cancel, as it will just fall through if (dirtyCheckVal == JOptionPane.NO_OPTION) { if (fc.isRendering()) { fc.toggleRendering(); } try { fc.newRack(); } catch (final Exception ex) { final String msg = "Exception caught performing new file action: " + ex.toString(); log.error(msg, ex); } } }
From source file:uk.co.modularaudio.componentdesigner.mainframe.actions.OpenFileAction.java
@Override public void actionPerformed(final ActionEvent e) { log.debug("OpenFileAction called."); try {/*from w ww. j a v a 2 s .c o m*/ int dirtyCheckVal = mainFrameActions.rackNotDirtyOrUserConfirmed(); if (dirtyCheckVal == JOptionPane.YES_OPTION) { // Need to save it - call the save saveFileAction.actionPerformed(e); // Simulate the cancel in the save action if the rack is still dirty. dirtyCheckVal = (fc.isRackDirty() ? JOptionPane.CANCEL_OPTION : JOptionPane.NO_OPTION); } // We don't check for cancel, as it will just fall through if (dirtyCheckVal == JOptionPane.NO_OPTION) { if (fc.isRendering()) { playStopAction.actionPerformed(e); } final JFileChooser openFileChooser = new JFileChooser(); final String patchesDir = upc.getUserPreferencesMVCController().getModel().getUserPatchesModel() .getValue(); openFileChooser.setCurrentDirectory(new File(patchesDir)); final int retVal = openFileChooser.showOpenDialog(mainFrame); if (retVal == JFileChooser.APPROVE_OPTION) { final File f = openFileChooser.getSelectedFile(); if (f != null) { if (log.isDebugEnabled()) { log.debug("Attempting to load from file " + f.getAbsolutePath()); } fc.loadRackFromFile(f.getAbsolutePath()); } } } } catch (final Exception ex) { final String msg = "Exception caught performing open file action: " + ex.toString(); log.error(msg, ex); } }
From source file:uk.co.modularaudio.componentdesigner.mainframe.MainFrameActions.java
public int rackNotDirtyOrUserConfirmed() { int retVal = JOptionPane.CANCEL_OPTION; if (fc.isRackDirty()) { // Show a dialog asking if they want to save the file retVal = JOptionPane.showConfirmDialog(mainFrame, MESSAGE_RACK_DIRT_CONFIRM_SAVE); } else {/*from www . j a va 2 s.co m*/ retVal = JOptionPane.NO_OPTION; } return retVal; }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Open or create a SQL statement file./*from ww w. j av a 2 s.c om*/ */ private void openSQLFile() { JFileChooser fileMenu; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenSQLFile; int returnVal; chosenSQLFile = null; // Save current information, including SQL Statements saveConfig(); // Allow user to choose/create new file for SQL Statements fileMenu = new JFileChooser(new File(queryFilename)); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("QUERY")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileMenu.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenQueryFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileMenu.setFileFilter(defaultFileFilter); } else if (latestChosenQueryFileFilterDescription != null && latestChosenQueryFileFilterDescription.startsWith("All")) { fileMenu.setFileFilter(fileMenu.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileMenu.setFileFilter(preferredFileFilter); } fileMenu.setSelectedFile(new File(queryFilename)); fileMenu.setDialogTitle(Resources.getString("dlgSQLFileTitle")); fileMenu.setDialogType(JFileChooser.OPEN_DIALOG); fileMenu.setFileSelectionMode(JFileChooser.FILES_ONLY); fileMenu.setMultiSelectionEnabled(false); if (fileMenu.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { chosenSQLFile = fileMenu.getSelectedFile(); // Adjust file suffix if necessary final FileFilter fileFilter = fileMenu.getFileFilter(); if (fileFilter != null && fileFilter instanceof SuffixFileFilter && !fileMenu.getFileFilter().accept(chosenSQLFile)) { chosenSQLFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(chosenSQLFile); } if (!chosenSQLFile.exists()) { returnVal = JOptionPane.showConfirmDialog(this, Resources.getString("dlgNewSQLFileText", chosenSQLFile.getName()), Resources.getString("dlgNewSQLFileTitle"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (returnVal == JOptionPane.NO_OPTION) { querySelection.removeAllItems(); queryText.setText(""); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } else if (returnVal == JOptionPane.CANCEL_OPTION) { chosenSQLFile = null; } } else { setQueryFilename(chosenSQLFile.getAbsolutePath()); querySelection.removeAllItems(); queryText.setText(""); loadCombo(querySelection, queryFilename); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } } try { latestChosenQueryFileFilterDescription = fileMenu.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable); } if (chosenSQLFile != null) { setQueryFilename(chosenSQLFile.getAbsolutePath()); saveConfig(); } }
From source file:VASSAL.build.GameModule.java
/** * Prompt user to save open game and modules/extensions being edited * @return true if shutDown should proceed, i.e. user did not cancel *///from ww w. ja va2s .c om public boolean shutDown() { boolean cancelled; getGameState().setup(false); cancelled = getGameState().isGameStarted(); if (!cancelled) { if (getDataArchive() instanceof ArchiveWriter && !buildString().equals(lastSavedConfiguration)) { switch (JOptionPane.showConfirmDialog(frame, Resources.getString("GameModule.save_module"), //$NON-NLS-1$ "", JOptionPane.YES_NO_CANCEL_OPTION)) { //$NON-NLS-1$ case JOptionPane.YES_OPTION: save(); break; case JOptionPane.CANCEL_OPTION: cancelled = true; } } for (ModuleExtension ext : getComponentsOf(ModuleExtension.class)) { cancelled = !ext.confirmExit(); } } if (!cancelled) { Prefs p = null; // write and close module prefs try { p = getPrefs(); p.write(); p.close(); } catch (IOException e) { WriteErrorDialog.error(e, p.getFile()); } finally { IOUtils.closeQuietly(p); } // write and close global prefs try { p = getGlobalPrefs(); p.write(); p.close(); } catch (IOException e) { WriteErrorDialog.error(e, p.getFile()); } finally { IOUtils.closeQuietly(p); } // close the module try { archive.close(); } catch (IOException e) { ReadErrorDialog.error(e, archive.getName()); } log.info("Exiting"); } return !cancelled; }
From source file:view.MultipleValidationDialog.java
private void writeToFile(String str) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(Bundle.getBundle().getString("title.saveAs")); boolean validPath = false; FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter( Bundle.getBundle().getString("filter.textFiles") + " (*.txt)", "txt"); fileChooser.setFileFilter(pdfFilter); File preferedFile = new File(Bundle.getBundle().getString("validationReport") + ".txt"); fileChooser.setSelectedFile(preferedFile); while (!validPath) { int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.CANCEL_OPTION) { return; }/*from w w w .j av a 2 s . co m*/ if (userSelection == JFileChooser.APPROVE_OPTION) { String dest = fileChooser.getSelectedFile().getAbsolutePath(); if (new File(dest).exists()) { String msg = Bundle.getBundle().getString("msg.reportFileNameAlreadyExists"); Object[] options = { Bundle.getBundle().getString("btn.overwrite"), Bundle.getBundle().getString("btn.chooseNewPath"), Bundle.getBundle().getString("btn.cancel") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { validPath = true; } else if (opt == JOptionPane.CANCEL_OPTION) { return; } } else { validPath = true; } if (validPath) { try (PrintStream out = new PrintStream(new FileOutputStream(dest))) { out.print(str); JOptionPane.showMessageDialog(null, Bundle.getBundle().getString("msg.reportSavedSuccessfully"), "", JOptionPane.INFORMATION_MESSAGE); } catch (FileNotFoundException ex) { controller.Logger.getLogger().addEntry(ex); JOptionPane.showMessageDialog(null, Bundle.getBundle().getString("msg.reportSaveFailed"), "", JOptionPane.ERROR_MESSAGE); } break; } } } }
From source file:view.WorkspacePanel.java
private void signDocument(Document document, boolean ocsp, boolean timestamp) { try {/*from w ww. jav a 2 s . c o m*/ if (tempCCAlias.getMainCertificate().getPublicKey().equals( CCInstance.getInstance().loadKeyStoreAndAliases().get(0).getMainCertificate().getPublicKey())) { try { String path1 = document.getDocumentLocation(); String path2 = null; if (path1.endsWith(".pdf")) { path2 = path1.substring(0, path1.length() - 4).concat("(aCCinado).pdf"); } JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(Bundle.getBundle().getString("btn.saveAs")); if (null != path2) { boolean validPath = false; FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter( Bundle.getBundle().getString("filter.pdfDocuments") + " (*.pdf)", "pdf"); fileChooser.setFileFilter(pdfFilter); File preferedFile = new File(path2); fileChooser.setCurrentDirectory(preferedFile); fileChooser.setSelectedFile(preferedFile); while (!validPath) { int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.CANCEL_OPTION) { return; } if (userSelection == JFileChooser.APPROVE_OPTION) { String dest = fileChooser.getSelectedFile().getAbsolutePath(); if (new File(dest).exists()) { String msg = Bundle.getBundle().getString("msg.fileExists"); Object[] options = { Bundle.getBundle().getString("opt.replace"), Bundle.getBundle().getString("opt.chooseNewPath"), Bundle.getBundle().getString("btn.cancel") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { validPath = true; } else if (opt == JOptionPane.CANCEL_OPTION) { return; } } else { validPath = true; } signatureSettings.setOcspClient(ocsp); signatureSettings.setTimestamp(timestamp); if (validPath) { if (!CCInstance.getInstance().signPdf(document.getDocumentLocation(), dest, signatureSettings, null)) { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("unknownErrorLog"), Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE); return; } status = Status.READY; ArrayList<File> list = new ArrayList<>(); list.add(new File(document.getDocumentLocation())); int tempPage = imagePanel.getPageNumber(); mainWindow.closeDocuments(list, false); mainWindow.loadPdf(new File(dest), false); hideRightPanel(); imagePanel.setPageNumber(tempPage); JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("label.signatureOk"), "", JOptionPane.INFORMATION_MESSAGE); break; } } } } return; } catch (IOException ex) { if (ex instanceof FileNotFoundException) { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.keystoreFileNotFound"), Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE); controller.Logger.getLogger().addEntry(ex); } else if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("outputFileError"))) { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.failedCreateOutputFile"), Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE); controller.Logger.getLogger().addEntry(ex); signDocument(document, ocsp, timestamp); } else { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("unknownErrorLog"), Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE); controller.Logger.getLogger().addEntry(ex); } } catch (DocumentException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | HeadlessException | CertificateException | KeyStoreException ex) { controller.Logger.getLogger().addEntry(ex); } catch (SignatureFailedException ex) { if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("timestampFailed"))) { String msg = Bundle.getBundle().getString("msg.timestampFailedNoInternet"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { signDocument(document, false, false); } } else { controller.Logger.getLogger().addEntry(ex); } } return; } else { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.smartcardRemovedOrChanged"), WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE); } } catch (LibraryNotLoadedException | KeyStoreNotLoadedException | CertificateException | KeyStoreException | LibraryNotFoundException | AliasException ex) { controller.Logger.getLogger().addEntry(ex); } JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.smartcardRemovedOrChanged"), WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE); }
From source file:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java
@SuppressWarnings("unchecked") @Override/*from w w w . j av a 2s. com*/ protected void createGeneralMenuEntries(final Point point, final N graph, final LayerViewer<V, E> vv) { JMenuItem mi; // creating a node mi = new JMenuItem("Create node"); final int layer = vv.getLayer().getLayer(); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // adding an resource/demand boolean addConstraint = true; V node = vertexFactory.create(); Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(point); node.setCoordinateX(p2.getX()); node.setCoordinateY(p2.getY()); while (addConstraint) { new AddConstraintDialog(node, layer, GUI.getInstance(), new Dimension(300, 150)); // if a resource/demand has been added if (node.get().size() > 0) { addConstraint = false; @SuppressWarnings("rawtypes") Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer); if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net).addVertex((SubstrateNode) node)) || (net instanceof VirtualNetwork && ((VirtualNetwork) net).addVertex((VirtualNode) node))) { vv.updateUI(); } else { throw new AssertionError("Adding Node failed."); } } else { String cons = (layer == 0 ? "Resource" : "Demand"); int option = JOptionPane.showConfirmDialog(GUI.getInstance(), "A " + cons + " must be added for the node to be created!", "Create Node", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { addConstraint = false; } } } } }); popup.add(mi); popup.addSeparator(); @SuppressWarnings("rawtypes") final MyGraphPanel pnl = GUI.getInstance().getGraphPanel(); if (pnl.getMaximized() == null) { mi = new JMenuItem("Maximize"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pnl.setMaximized(vv); } }); } else { mi = new JMenuItem("Restore"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pnl.setMaximized(null); } }); } popup.add(mi); if (pnl.getMaximized() != null) { mi = new JMenuItem("Hide"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { vv.getParent().setVisible(false); } }); popup.add(mi); } popup.addSeparator(); // Copied from MuLaNEO mi = new JMenuItem("Export layer to SVG"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int layer = vv.getLayer().getLayer(); MyFileChooser fc = new MyFileChooser("Export layer " + layer + " to SVG", MyFileChooserType.MISC, false); fc.addChoosableFileFilter(FileFilters.svgFilter); fc.setSelectedFile(new File("export-layer-" + layer + ".svg")); if (fc.showSaveDialog(GUI.getInstance()) == JFileChooser.APPROVE_OPTION) new SVGExporter().export(vv, fc.getSelectedFile()); } }); popup.add(mi); }