List of usage examples for javax.swing JOptionPane NO_OPTION
int NO_OPTION
To view the source code for javax.swing JOptionPane NO_OPTION.
Click Source Link
From source file:pl.otros.logview.gui.Log4jPatternParserEditor.java
protected void saveParser() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(AllPluginables.USER_LOG_IMPORTERS); chooser.addChoosableFileFilter(new FileFilter() { @Override//w w w . j av a 2 s. c om public String getDescription() { return "*.pattern files"; } @Override public boolean accept(File f) { return f.getName().endsWith(".pattern") || f.isDirectory(); } }); int showSaveDialog = chooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); if (!selectedFile.getName().endsWith(".pattern")) { selectedFile = new File(selectedFile.getAbsolutePath() + ".pattern"); } if (selectedFile.exists() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(this, "Do you want to overwrite file " + selectedFile.getName() + "?", "Save parser", JOptionPane.YES_NO_OPTION)) { return; } String text = propertyEditor.getText(); FileOutputStream output = null; try { output = new FileOutputStream(selectedFile); IOUtils.write(text, output); LogImporterUsingParser log4jImporter = createLog4jImporter(text); otrosApplication.getAllPluginables().getLogImportersContainer().addElement(log4jImporter); } catch (Exception e) { LOGGER.severe("Can't save parser: " + e.getMessage()); JOptionPane.showMessageDialog(this, "Can't save parser: " + e.getMessage(), "Error saving parser", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } finally { IOUtils.closeQuietly(output); } } }
From source file:plugin.notes.gui.NotesTreeNode.java
/** reverts back to the saved file (and as a consequence, clears the cache) */ public void revert() { //If it is modified, confirm if (dirty) {/*from w w w .j a v a2 s . co m*/ int choice = JOptionPane.showConfirmDialog(GMGenSystem.inst, "Note '" + getUserObject() + "' has been altered, are you sure you wish to revert to the saved copy?", "Revert?", JOptionPane.YES_NO_OPTION); if (choice == JOptionPane.NO_OPTION) { return; } } dirty = false; pane = null; notesDoc.removeDocumentListener(this); notesDoc = null; }
From source file:plugin.notes.gui.NotesView.java
/** * Opens a .gmn file/* w ww .j a va 2 s . co m*/ * *@param notesFile .gmn file to open */ private void openGMN(File notesFile) { try { Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; if (node != root) { int choice = JOptionPane.showConfirmDialog(this, "Importing note " + notesFile.getName() + " into a node other then root, Continue?", "Importing to a node other then root", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice == JOptionPane.NO_OPTION) { return; } } InputStream in = new BufferedInputStream(new FileInputStream(notesFile)); ZipInputStream zin = new ZipInputStream(in); ZipEntry e; ProgressMonitor pm = new ProgressMonitor(GMGenSystem.inst, "Reading Notes Export", "Reading", 1, 1000); int progress = 1; while ((e = zin.getNextEntry()) != null) { unzip(zin, e.getName(), node.getDir()); progress++; if (progress > 99) { progress = 99; } pm.setProgress(progress); } zin.close(); pm.close(); } } catch (IOException e) { JOptionPane.showMessageDialog(this, "Error Reading File" + notesFile.getName()); Logging.errorPrint("Error Reading File" + notesFile.getName()); Logging.errorPrint(e.getMessage(), e); } }
From source file:plugin.notes.gui.NotesView.java
/** * Exports a node out to a gmn file./*from ww w .j a va 2 s . c o m*/ * *@param node node to export to file */ private void exportFile(NotesTreeNode node) { JFileChooser fLoad = new JFileChooser(); String sFile = SettingsHandler.getGMGenOption(OPTION_NAME_LASTFILE, ""); new File(sFile); FileFilter ff = getFileType(); fLoad.addChoosableFileFilter(ff); fLoad.setFileFilter(ff); int returnVal = fLoad.showSaveDialog(this); try { if (returnVal == JFileChooser.APPROVE_OPTION) { String fileName = fLoad.getSelectedFile().getName(); String dirName = fLoad.getSelectedFile().getParent(); String extension = EXTENSION; if (fileName.indexOf(extension) < 0) { fileName += extension; } File expFile = new File(dirName + File.separator + fileName); if (expFile.exists()) { int choice = JOptionPane.showConfirmDialog(this, "File Exists, Overwrite?", "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice == JOptionPane.NO_OPTION) { return; } } SettingsHandler.setGMGenOption(OPTION_NAME_LASTFILE, expFile.toString()); writeNotesFile(expFile, node); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error Writing File"); Logging.errorPrint("Error Writing to file: " + e.getMessage(), e); } }
From source file:processing.app.Editor.java
/** * Check if the sketch is modified and ask user to save changes. * @return false if canceling the close/quit operation *//*w ww. j av a2 s. c o m*/ protected boolean checkModified() { if (!sketch.isModified()) return true; // As of Processing 1.0.10, this always happens immediately. // http://dev.processing.org/bugs/show_bug.cgi?id=1456 toFront(); String prompt = I18n.format(_("Save changes to \"{0}\"? "), sketch.getName()); if (!OSUtils.isMacOS()) { int result = JOptionPane.showConfirmDialog(this, prompt, _("Close"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (result) { case JOptionPane.YES_OPTION: return handleSave(true); case JOptionPane.NO_OPTION: return true; // ok to continue case JOptionPane.CANCEL_OPTION: case JOptionPane.CLOSED_OPTION: // Escape key pressed return false; default: throw new IllegalStateException(); } } else { // This code is disabled unless Java 1.5 is being used on Mac OS X // because of a Java bug that prevents the initial value of the // dialog from being set properly (at least on my MacBook Pro). // The bug causes the "Don't Save" option to be the highlighted, // blinking, default. This sucks. But I'll tell you what doesn't // suck--workarounds for the Mac and Apple's snobby attitude about it! // I think it's nifty that they treat their developers like dirt. // Pane formatting adapted from the quaqua guide // http://www.randelshofer.ch/quaqua/guide/joptionpane.html JOptionPane pane = new JOptionPane(_("<html> " + "<head> <style type=\"text/css\">" + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }" + "</style> </head>" + "<b>Do you want to save changes to this sketch<BR>" + " before closing?</b>" + "<p>If you don't save, your changes will be lost."), JOptionPane.QUESTION_MESSAGE); String[] options = new String[] { _("Save"), _("Cancel"), _("Don't Save") }; pane.setOptions(options); // highlight the safest option ala apple hig pane.setInitialValue(options[0]); // on macosx, setting the destructive property places this option // away from the others at the lefthand side pane.putClientProperty("Quaqua.OptionPane.destructiveOption", new Integer(2)); JDialog dialog = pane.createDialog(this, null); dialog.setVisible(true); Object result = pane.getValue(); if (result == options[0]) { // save (and close/quit) return handleSave(true); } else if (result == options[2]) { // don't save (still close/quit) return true; } else { // cancel? return false; } } }
From source file:processing.app.Editor.java
/** * Second stage of open, occurs after having checked to see if the * modifications (if any) to the previous sketch need to be saved. *//*w w w . j av a 2s.co m*/ protected boolean handleOpenInternal(File sketchFile) { // check to make sure that this .pde file is // in a folder of the same name String fileName = sketchFile.getName(); File file = SketchData.checkSketchFile(sketchFile); if (file == null) { if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) { Base.showWarning(_("Bad file selected"), _("Arduino can only open its own sketches\n" + "and other files ending in .ino or .pde"), null); return false; } else { String properParent = fileName.substring(0, fileName.length() - 4); Object[] options = { _("OK"), _("Cancel") }; String prompt = I18n.format(_("The file \"{0}\" needs to be inside\n" + "a sketch folder named \"{1}\".\n" + "Create this folder, move the file, and continue?"), fileName, properParent); int result = JOptionPane.showOptionDialog(this, prompt, _("Moving"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result == JOptionPane.YES_OPTION) { // create properly named folder File properFolder = new File(sketchFile.getParent(), properParent); if (properFolder.exists()) { Base.showWarning(_("Error"), I18n.format(_("A folder named \"{0}\" already exists. " + "Can't open sketch."), properParent), null); return false; } if (!properFolder.mkdirs()) { //throw new IOException("Couldn't create sketch folder"); Base.showWarning(_("Error"), _("Could not create the sketch folder."), null); return false; } // copy the sketch inside File properPdeFile = new File(properFolder, sketchFile.getName()); try { Base.copyFile(sketchFile, properPdeFile); } catch (IOException e) { Base.showWarning(_("Error"), _("Could not copy to a proper location."), e); return false; } // remove the original file, so user doesn't get confused sketchFile.delete(); // update with the new path file = properPdeFile; } else if (result == JOptionPane.NO_OPTION) { return false; } } } try { sketch = new Sketch(this, file); } catch (IOException e) { Base.showWarning(_("Error"), _("Could not create the sketch."), e); return false; } header.rebuild(); setTitle(I18n.format(_("{0} | Arduino {1}"), sketch.getName(), BaseNoGui.VERSION_NAME_LONG)); // Disable untitled setting from previous document, if any untitled = false; // opening was successful return true; // } catch (Exception e) { // e.printStackTrace(); // statusError(e); // return false; // } }
From source file:processing.app.tools.FixEncoding.java
public void run() { Sketch sketch = editor.getSketch();// w ww .j a v a 2 s . co m //SketchCode code = sketch.current; if (sketch.isModified()) { int result = JOptionPane.showConfirmDialog(editor, tr("Discard all changes and reload sketch?"), tr("Fix Encoding & Reload"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.NO_OPTION) { return; } } try { for (int i = 0; i < sketch.getCodeCount(); i++) { SketchFile file = sketch.getFile(i); editor.findTab(file).setText(loadWithLocalEncoding(file.getFile())); } } catch (IOException e) { String msg = tr( "An error occurred while trying to fix the file encoding.\nDo not attempt to save this sketch as it may overwrite\nthe old version. Use Open to re-open the sketch and try again.\n") + e.getMessage(); Base.showWarning(tr("Fix Encoding & Reload"), msg, e); } }
From source file:ro.nextreports.designer.util.NextReportsUtil.java
public static boolean saveReportForInserting(String message) { QueryBuilderPanel builderPanel = Globals.getMainFrame().getQueryBuilderPanel(); if (!builderPanel.isCleaned()) { if (Globals.isReportLoaded()) { if (!reportModification()) { return true; }/*from w ww . j av a 2 s. c om*/ int option = JOptionPane.showConfirmDialog(Globals.getMainFrame(), message, I18NSupport.getString("exit"), JOptionPane.YES_NO_OPTION); if ((option == JOptionPane.NO_OPTION) || (option == JOptionPane.CLOSED_OPTION)) { return false; } else if (option == JOptionPane.YES_OPTION) { SaveReportAction action = new SaveReportAction(); action.actionPerformed(null); if (action.isCancel()) { return false; } } } } return true; }
From source file:se.cambio.cds.gdl.editor.controller.GDLEditor.java
public void runIfOKToExit(final Runnable pendingRunnable) { Runnable runnable = new Runnable() { @Override/*from ww w .j a v a2 s . c o m*/ public void run() { if (isModified()) { int response = JOptionPane.showConfirmDialog(EditorManager.getActiveEditorWindow(), GDLEditorLanguageManager.getMessage("SavingChangesMessage"), GDLEditorLanguageManager.getMessage("SavingChanges"), JOptionPane.INFORMATION_MESSAGE); if (response == JOptionPane.YES_OPTION) { SaveGuideOnFileRSW rsw = new SaveGuideOnFileRSW(EditorManager.getLastFileLoaded()) { protected void done() { super.done(); if (getFile() != null) { pendingRunnable.run(); } } }; rsw.execute(); } else if (response == JOptionPane.NO_OPTION) { pendingRunnable.run(); } } else { pendingRunnable.run(); } } }; runIfOkWithEditorState(runnable); }
From source file:skoa.helpers.ConfiguracionGraficas.java
public ConfiguracionGraficas(JFrame i) { //Inicializamos los directorios correspondientes a partir de donde se encuentra el .jar File dir_inicial = new File("./"); ruta_jar = System.getProperty("user.dir"); String os = System.getProperty("os.name"); //En Windows las barras son \ y en Linux /. String busca, reemp;//from ww w. j a v a2 s. c o m //if (os.indexOf("Win")>=0) { ruta_destino = ruta_jar + File.separator + "Consultas" + File.separator; ruta_lista2 = ruta_jar + File.separator + "lista.txt"; //busca="\\"; //reemp="\\\\"; //} //else{ //ruta_destino=ruta_jar+File.separator+"Consultas"+File.separator; //ruta_lista2=ruta_jar+File.separator+"lista.txt"; //busca="/"; //reemp="//"; //La doble barra es por MySQL, en Linux no s si hace falta. //} //String aux=ruta_jar,aux2=""; //Cuando se usa una ruta en la base de datos, debe tener doble barra, es decir \\\\ /*while(aux.length()!=0){ if (aux.indexOf(busca)>=0) { aux2=aux2+aux.substring(0,aux.indexOf(busca)); aux=aux.substring(aux.indexOf(busca)+1); } else { aux2=aux2+aux.substring(0); aux=""; } aux2=aux2+reemp; }*/ ruta_lista = ruta_lista2; //if (os.indexOf("Win")>=0) ruta_lista=aux2+"\\\\lista.txt"; //else ruta_lista=aux2+"//lista.txt"; //----------------------------------- interfaz = i; String g1 = " 1 "; //titulo del boton por defecto String g4 = " 4 "; Object[] options = { g1, g4 }; //titulo de los botones int n = JOptionPane.showOptionDialog(interfaz, "Cantas grficas desea visualizar?", "Visualizacin", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, g1); if (n == JOptionPane.YES_OPTION) g = 1; else if (n == JOptionPane.NO_OPTION) g = 4; vg = g;//N de graficas a visualizar. Variable usada en el procedimiento colocarGraficos() inicializarPaneles(); inicial(); iniciarConexiones2(); }