ij.gui.YesNoCancelDialog Java Examples
The following examples show how to use
ij.gui.YesNoCancelDialog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnippetCreator.java From Scripts with GNU General Public License v3.0 | 6 votes |
/** * This method is called when the plugin is loaded. See * {@link ij.plugin.PlugIn#run(java.lang.String)} Prompts user for a new * snippet that will be saved in {@code BAR/My_Routines/} * * @param arg * ignored (Otherwise specified in plugins.config). */ @Override public void run(final String arg) { Utils.shiftClickWarning(); if (new GuiUtils().getFileCount(Utils.getLibDir()) == 0) { final YesNoCancelDialog query = new YesNoCancelDialog(null, "Install lib Files?", "Some of the code generated by this plugin assumes the adoption\n" + "of centralized lib files, but none seem to exist in your local directory\n" + "(" + Utils.getLibDir() + ")\nWould you like to install them now?"); if (query.cancelPressed()) { return; } else if (query.yesPressed()) { final Context context = (Context) IJ.runPlugIn("org.scijava.Context", ""); final CommandService commandService = context.getService(CommandService.class); commandService.run(Installer.class, true); return; } } if (showDialog()) { if (sContents.length()>0) saveAndOpenSnippet(); else IJ.showStatus(sFilename +" was empty. No file was saved..."); } }
Example #2
Source File: DBLoader.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
private boolean upgradePatchesTable() throws Exception { Statement st = connection.createStatement(); ResultSet r = st.executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='ab_patches' AND column_name='min'"); if (!r.next()) { YesNoCancelDialog yn = new YesNoCancelDialog(IJ.getInstance(), "Upgrade", "Need to upgrade the table ab_patches.\nThe columns 'min' and 'max' will be added.\nProceed?"); if (!yn.yesPressed()) { r.close(); return false; } st.executeUpdate("ALTER TABLE ab_patches ADD min DOUBLE PRECISION"); st.executeUpdate("ALTER TABLE ab_patches ALTER COLUMN min SET DEFAULT -1"); st.executeUpdate("ALTER TABLE ab_patches ADD max DOUBLE PRECISION"); st.executeUpdate("ALTER TABLE ab_patches ALTER COLUMN max SET DEFAULT -1"); } r.close(); return true; }
Example #3
Source File: FilterEditor.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
private static boolean check(final JFrame frame, final List<FilterWrapper> wrappers) { if (!wrappers.isEmpty()) { final String s = sanityCheck(wrappers); return 0 == s.length() || new YesNoCancelDialog(frame, "WARNING", s + "\nContinue?").yesPressed(); } return true; }
Example #4
Source File: Utils.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
static public final boolean check(final String msg) { try { return new TaskOnEDT<Boolean>(new Callable<Boolean>() { @Override public Boolean call() { final YesNoCancelDialog dialog = new YesNoCancelDialog(IJ.getInstance(), "Execute?", msg); if (dialog.yesPressed()) { return true; } return false; }}).get(); } catch (final Throwable t) { IJError.print(t); return false; } }
Example #5
Source File: Utils.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** Select a file from the file system, for saving purposes. Prompts for overwritting if the file exists, unless the ControlWindow.isGUIEnabled() returns false (i.e. there is no GUI). */ static public final File chooseFile(final String default_dir, final String name, final String extension) { try { return new TaskOnEDT<File>(new Callable<File>() { @Override public File call() { // using ImageJ's JFileChooser or internal FileDialog, according to user preferences. String name2 = null; if (null != name && null != extension) name2 = name + extension; else if (null != name) name2 = name; else if (null != extension) name2 = "untitled" + extension; if (null != default_dir) { OpenDialog.setDefaultDirectory(default_dir); } final SaveDialog sd = new SaveDialog("Save", OpenDialog.getDefaultDirectory(), name2, extension); final String filename = sd.getFileName(); if (null == filename || filename.toLowerCase().startsWith("null")) return null; String dir = sd.getDirectory(); if (IJ.isWindows()) dir = dir.replace('\\', '/'); if (!dir.endsWith("/")) dir += "/"; final File f = new File(dir + filename); if (f.exists() && ControlWindow.isGUIEnabled()) { final YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), "Overwrite?", "File " + filename + " exists! Overwrite?"); if (d.cancelPressed()) { return null; } else if (!d.yesPressed()) { return chooseFile(name, extension); } // else if yes pressed, overwrite. } return f; }}).get(); } catch (final Throwable t) { IJError.print(t); return null; } }
Example #6
Source File: DBLoader.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
private boolean upgradeLayerSetTable() throws Exception { final Statement st = connection.createStatement(); ResultSet r = st.executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='ab_layer_sets' AND column_name='snapshots_enabled'"); if (!r.next()) { YesNoCancelDialog yn = new YesNoCancelDialog(IJ.getInstance(), "Upgrade", "Need to upgrade table ab_layer_sets.\nThe column 'snapshots_enabled' will be added.\nProceed?"); if (!yn.yesPressed()) { r.close(); return false; } st.execute("ALTER TABLE ab_layer_sets ADD snapshots_enabled BOOLEAN"); st.execute("ALTER TABLE ab_layer_sets ALTER COLUMN snapshots_enabled SET DEFAULT true"); } r.close(); return true; }
Example #7
Source File: DBLoader.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
private boolean upgradeDisplaysTable() throws Exception { ResultSet r = connection.prepareStatement("SELECT column_name FROM information_schema.columns WHERE table_name='ab_displays' AND column_name='scroll_step'").executeQuery(); if (!r.next()) { YesNoCancelDialog yn = new YesNoCancelDialog(IJ.getInstance(), "Upgrade", "Need to upgrade table ab_displays.\nThe column 'scroll_step' will be added.\nProceed?"); if (!yn.yesPressed()) { r.close(); return false; } connection.prepareStatement("ALTER TABLE ab_displays ADD scroll_step INT").execute(); connection.prepareStatement("ALTER TABLE ab_displays ALTER COLUMN scroll_step SET DEFAULT 1").execute(); // in two rows, so that 7.4.* is still supported. } r.close(); return true; }
Example #8
Source File: DBLoader.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
private boolean upgradeAreaListTable() throws Exception { ResultSet r = connection.createStatement().executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='ab_area_paths' AND column_name='fill_paint'"); if (!r.next()) { YesNoCancelDialog yn = new YesNoCancelDialog(IJ.getInstance(), "Upgrade", "Need to upgrade table ab_area_paths.\nThe column 'fill_paint' will be added.\nProceed?"); if (!yn.yesPressed()) { r.close(); return false; } connection.createStatement().executeUpdate("ALTER TABLE ab_area_paths ADD fill_paint BOOLEAN"); connection.createStatement().executeUpdate("ALTER TABLE ab_area_paths ALTER COLUMN fill_paint SET DEFAULT TRUE"); } r.close(); return true; }
Example #9
Source File: Render.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
static public void exportSVG(ProjectThing thing, double z_scale) { StringBuffer data = new StringBuffer(); data.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n") .append("<svg\n") .append("\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n") .append("\txmlns:cc=\"http://web.resource.org/cc/\"\n") .append("\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n") .append("\txmlns:svg=\"http://www.w3.org/2000/svg\"\n") .append("\txmlns=\"http://www.w3.org/2000/svg\"\n") //.append("\twidth=\"1500\"\n") //.append("\theight=\"1000\"\n") .append("\tid=\"").append(thing.getProject().toString()).append("\">\n") ; // traverse the tree at node 'thing' thing.exportSVG(data, z_scale, "\t"); data.append("</svg>"); // save the file final SaveDialog sd = new SaveDialog("Save .svg", OpenDialog.getDefaultDirectory(), "svg"); String dir = sd.getDirectory(); if (null == dir) return; if (IJ.isWindows()) dir = dir.replace('\\', '/'); if (!dir.endsWith("/")) dir += "/"; String file_name = sd.getFileName(); String file_path = dir + file_name; File f = new File(file_path); if (f.exists()) { YesNoCancelDialog d = new YesNoCancelDialog(IJ.getInstance(), "Overwrite?", "File " + file_name + " exists! Overwrite?"); if (!d.yesPressed()) { return; } } String contents = data.toString(); try { DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f), data.length())); dos.writeBytes(contents); dos.flush(); } catch (Exception e) { IJError.print(e); Utils.log("ERROR: Most likely did NOT save your file."); } }
Example #10
Source File: DBLoader.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** Used to upgrade old databases. */ private boolean upgradeProjectsTable() throws Exception { // Upgrade database if necessary: set a version field, create the TemplateThing entries in the database for each project from its XML template file, and delete the xml_template column // Check columns: see if trakem2_version is there ResultSet r = connection.prepareStatement("SELECT column_name FROM information_schema.columns WHERE table_name='ab_projects' AND column_name='xml_template'").executeQuery(); if (r.next()) { YesNoCancelDialog yn = new YesNoCancelDialog(IJ.getInstance(), "Upgrade", "Need to upgrade table projects.\nNo data will be lost, but reorganized.\nProceed?"); if (!yn.yesPressed()) { return false; } // retrieve and parse XML template from each project ResultSet r1 = connection.prepareStatement("SELECT * FROM ab_projects").executeQuery(); while (r1.next()) { long project_id = r1.getLong("id"); // parse the XML file stored in the db and save the TemplateThing into the ab_things table InputStream xml_stream = null; try { String query = "SELECT xml_template FROM ab_projects WHERE id=" + project_id; ResultSet result = connection.prepareStatement(query).executeQuery(); if (result.next()) { xml_stream = result.getBinaryStream("xml_template"); } result.close(); } catch (Exception e) { IJError.print(e); return false; } if (null == xml_stream) { Utils.showMessage("Failed to upgrade the database schema: XML template stream is null."); return false; } TemplateThing template_root = new TrakEM2MLParser(xml_stream).getTemplateRoot(); if (null == template_root) { Utils.showMessage("Failed to upgrade the database schema: root TemplateThing is null."); return false; } Project project = new Project(project_id, r1.getString("title")); project.setTempLoader(this); template_root.addToDatabase(project); } r1.close(); // remove the XML column connection.prepareStatement("ALTER TABLE ab_projects DROP xml_template").execute(); // org.postgresql.util.PSQLException: ERROR: adding columns with defaults is not implemented in 7.4.* (only in 8.1.4+) // connection.prepareStatement("ALTER TABLE ab_projects ADD version text default '" + Utils.version + "'").execute(); // so: workaround connection.prepareStatement("ALTER TABLE ab_projects ADD version TEXT").execute(); connection.prepareStatement("ALTER TABLE ab_projects ALTER COLUMN version SET DEFAULT '" + Utils.version + "'").execute(); } r.close(); return true; // success! }
Example #11
Source File: FSLoader.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** Return the unuid_dir or null if none valid selected. */ private String obtainUNUIdFolder() { YesNoCancelDialog yn = ControlWindow.makeYesNoCancelDialog("Old .xml version!", "The loaded XML file does not contain an UNUId. Select a shared UNUId folder?\nShould look similar to: trakem2.12345678.12345678.12345678"); if (!yn.yesPressed()) return null; DirectoryChooser dc = new DirectoryChooser("Select UNUId folder"); String unuid_dir = dc.getDirectory(); String unuid_dir_name = new File(unuid_dir).getName(); Utils.log2("Selected UNUId folder: " + unuid_dir + "\n with name: " + unuid_dir_name); if (null != unuid_dir) { if (IJ.isWindows()) unuid_dir = unuid_dir.replace('\\', '/'); if ( ! unuid_dir_name.startsWith("trakem2.")) { Utils.logAll("Invalid UNUId folder: must start with \"trakem2.\". Try again or cancel."); return obtainUNUIdFolder(); } else { String[] nums = unuid_dir_name.split("\\."); if (nums.length != 4) { Utils.logAll("Invalid UNUId folder: needs trakem + 3 number blocks. Try again or cancel."); return obtainUNUIdFolder(); } for (int i=1; i<nums.length; i++) { try { Long.parseLong(nums[i]); } catch (NumberFormatException nfe) { Utils.logAll("Invalid UNUId folder: at least one block is not a number. Try again or cancel."); return obtainUNUIdFolder(); } } // ok, aceptamos pulpo String unuid = unuid_dir_name.substring(8); // remove prefix "trakem2." if (unuid.endsWith("/")) unuid = unuid.substring(0, unuid.length() -1); this.unuid = unuid; if (!unuid_dir.endsWith("/")) unuid_dir += "/"; String dir_storage = new File(unuid_dir).getParent().replace('\\', '/'); if (!dir_storage.endsWith("/")) dir_storage += "/"; this.dir_storage = dir_storage; this.dir_mipmaps = unuid_dir + "trakem2.mipmaps/"; return unuid_dir; } } return null; }
Example #12
Source File: Loader.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** If the srcRect is null, makes a flat 8-bit or RGB image of the entire layer. Otherwise just of the srcRect. Checks first for enough memory and frees some if feasible. */ public Bureaucrat makeFlatImage(final Layer[] layer, final Rectangle srcRect, final double scale, final int c_alphas, final int type, final boolean force_to_file, final String format, final boolean quality, final Color background) { if (null == layer || 0 == layer.length) { Utils.log2("makeFlatImage: null or empty list of layers to process."); return null; } final Worker worker = new Worker("making flat images") { @Override public void run() { try { // startedWorking(); Rectangle srcRect_ = srcRect; if (null == srcRect_) srcRect_ = layer[0].getParent().get2DBounds(); ImagePlus imp = null; String target_dir = null; boolean choose_dir = force_to_file; // if not saving to a file: if (!force_to_file) { final long size = (long)Math.ceil((srcRect_.width * scale) * (srcRect_.height * scale) * ( ImagePlus.GRAY8 == type ? 1 : 4 ) * layer.length); if (size > IJ.maxMemory() * 0.9) { final YesNoCancelDialog yn = new YesNoCancelDialog(IJ.getInstance(), "WARNING", "The resulting stack of flat images is too large to fit in memory.\nChoose a directory to save the slices as an image sequence?"); if (yn.yesPressed()) { choose_dir = true; } else if (yn.cancelPressed()) { finishedWorking(); return; } else { choose_dir = false; // your own risk } } } if (choose_dir) { final DirectoryChooser dc = new DirectoryChooser("Target directory"); target_dir = dc.getDirectory(); if (null == target_dir || target_dir.toLowerCase().startsWith("null")) { finishedWorking(); return; } if (IJ.isWindows()) target_dir = target_dir.replace('\\', '/'); if (!target_dir.endsWith("/")) target_dir += "/"; } if (layer.length > 1) { // Get all slices ImageStack stack = null; Utils.showProgress(0); for (int i=0; i<layer.length; i++) { if (Thread.currentThread().isInterrupted()) return; /* free memory */ releaseAll(); Utils.showProgress(i / (float)layer.length); final ImagePlus slice = getFlatImage(layer[i], srcRect_, scale, c_alphas, type, Displayable.class, null, quality, background); if (null == slice) { Utils.log("Could not retrieve flat image for " + layer[i].toString()); continue; } if (null != target_dir) { saveToPath(slice, target_dir, layer[i].getPrintableTitle(), ".tif"); } else { if (null == stack) stack = new ImageStack(slice.getWidth(), slice.getHeight()); stack.addSlice(layer[i].getProject().findLayerThing(layer[i]).toString(), slice.getProcessor()); } } Utils.showProgress(1); if (null != stack) { imp = new ImagePlus("z=" + layer[0].getZ() + " to z=" + layer[layer.length-1].getZ(), stack); final Calibration impCalibration = layer[0].getParent().getCalibrationCopy(); impCalibration.pixelWidth /= scale; impCalibration.pixelHeight /= scale; imp.setCalibration(impCalibration); } } else { imp = getFlatImage(layer[0], srcRect_, scale, c_alphas, type, Displayable.class, null, quality, background); if (null != target_dir) { saveToPath(imp, target_dir, layer[0].getPrintableTitle(), format); imp = null; // to prevent showing it } } if (null != imp) imp.show(); } catch (final Throwable e) { IJError.print(e); } finishedWorking(); }}; // I miss my lisp macros, you have no idea return Bureaucrat.createAndStart(worker, layer[0].getProject()); }
Example #13
Source File: ControlWindow.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** For the YesNoCancelDialog dialogs to be parented properly. */ static public YesNoCancelDialog makeYesNoCancelDialog(String title, String msg) { Frame f = (null == frame ? IJ.getInstance() : (java.awt.Frame)frame); return new YesNoCancelDialog(f, title, msg); }