ImagePlus getImage() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) { error("There are no images open."); return null; } else return imp; }
void addParticles() { String err = IJ.runMacroFile("ij.jar:AddParticles", null); if (err!=null && err.length()>0) error(err); }
void addParticles() { String err = IJ.runMacroFile("ij.jar:AddParticles", null); if (err!=null && err.length()>0) error(err); }
ImagePlus getImage() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) { error("There are no images open."); return null; } else return imp; }
private boolean save(String name, boolean saveSelected) { if (!name.endsWith(".zip") && !name.equals("")) return error("Name must end with '.zip'"); if (getCount()==0) return error("The list is empty"); int[] indexes = null; if (saveSelected) indexes = getIndexes(); else indexes = getAllIndexes(); boolean ok = false; if (name.equals("")) ok = saveMultiple(indexes, null); else ok = saveMultiple(indexes, name); macro = false; return ok; }
private boolean save(String name, boolean saveSelected) { if (!name.endsWith(".zip") && !name.equals("")) return error("Name must end with '.zip'"); if (getCount()==0) return error("The list is empty"); int[] indexes = null; if (saveSelected) indexes = getIndexes(); else indexes = getAllIndexes(); boolean ok = false; if (name.equals("")) ok = saveMultiple(indexes, null); else ok = saveMultiple(indexes, name); macro = false; return ok; }
boolean save() { if (getCount()==0) return error("The selection list is empty."); int[] indexes = getIndexes(); if (indexes.length>1) return saveMultiple(indexes, null); else return saveOne(indexes, null); }
boolean save() { if (getCount()==0) return error("The selection list is empty."); int[] indexes = getIndexes(); if (indexes.length>1) return saveMultiple(indexes, null); else return saveOne(indexes, null); }
boolean saveOne(int[] indexes, String path) { if (indexes.length==0) return error("The list is empty"); Roi roi = (Roi)rois.get(indexes[0]); if (path==null) { Macro.setOptions(null); String name = (String) listModel.getElementAt(indexes[0]); SaveDialog sd = new SaveDialog("Save Selection...", name, ".roi"); String name2 = sd.getFileName(); if (name2 == null) return false; String dir = sd.getDirectory(); if (!name2.endsWith(".roi")) name2 = name2+".roi"; String newName = name2.substring(0, name2.length()-4); rois.set(indexes[0], roi); roi.setName(newName); listModel.setElementAt(newName, indexes[0]); path = dir+name2; } RoiEncoder re = new RoiEncoder(path); try { re.write(roi); } catch (IOException e) { IJ.error("ROI Manager", e.getMessage()); } if (Recorder.record && !IJ.isMacro()) Recorder.record("roiManager", "Save", path); return true; }
boolean update(boolean clone) { ImagePlus imp = getImage(); if (imp==null) return false; ImageCanvas ic = imp.getCanvas(); boolean showingAll = ic!=null && ic.getShowAllROIs(); Roi roi = imp.getRoi(); if (roi==null) { error("The active image does not have a selection."); return false; } int index = list.getSelectedIndex(); if (index<0 && !showingAll) return error("Exactly one item in the list must be selected."); if (index>=0) { if (clone) { String name = (String)listModel.getElementAt(index); Roi roi2 = (Roi)roi.clone(); roi2.setPosition(imp); roi.setName(name); roi2.setName(name); rois.set(index, roi2); } else rois.set(index, roi); } if (record()) Recorder.record("roiManager", "Update"); updateShowAll(); return true; }
boolean rename(String name2) { int index = list.getSelectedIndex(); if (index<0) return error("Exactly one item in the list must be selected."); String name = (String)listModel.getElementAt(index); if (name2==null) name2 = promptForName(name); if (name2==null) return false; if (name2.equals(name)) return false; Roi roi = (Roi)rois.get(index); roi.setName(name2); int position = getSliceNumber(name2); if (position>0 && !roi.hasHyperStackPosition()) roi.setPosition(position); rois.set(index, roi); listModel.setElementAt(name2, index); list.setSelectedIndex(index); if (Prefs.useNamesAsLabels && labelsCheckbox.getState()) { ImagePlus imp = WindowManager.getCurrentImage(); if (imp!=null) imp.draw(); } if (record()) Recorder.record("roiManager", "Rename", name2); return true; }
boolean rename(String name2) { int index = list.getSelectedIndex(); if (index<0) return error("Exactly one item in the list must be selected."); String name = (String)listModel.getElementAt(index); if (name2==null) name2 = promptForName(name); if (name2==null) return false; if (name2.equals(name)) return false; Roi roi = (Roi)rois.get(index); roi.setName(name2); int position = getSliceNumber(name2); if (position>0 && !roi.hasHyperStackPosition()) roi.setPosition(position); rois.set(index, roi); listModel.setElementAt(name2, index); list.setSelectedIndex(index); if (Prefs.useNamesAsLabels && labelsCheckbox.getState()) { ImagePlus imp = WindowManager.getCurrentImage(); if (imp!=null) imp.draw(); } if (record()) Recorder.record("roiManager", "Rename", name2); return true; }
void flatten() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) {IJ.noImage(); return;} ImageCanvas ic = imp.getCanvas(); if ((ic!=null && ic.getShowAllList()==null) && imp.getOverlay()==null && imp.getRoi()==null) error("Image does not have an overlay or ROI"); else IJ.doCommand("Flatten"); // run Image>Flatten in separate thread }
private void combine() { ImagePlus imp = getImage(); if (imp==null) return; Roi[] rois = getSelectedRoisAsArray(); if (rois.length==1) { error("More than one item must be selected, or none"); return; } int nPointRois = 0; for (int i=0; i<rois.length; i++) { if (rois[i].getType()==Roi.POINT) nPointRois++; else break; } if (nPointRois==rois.length) combinePoints(imp, rois); else combineRois(imp, rois); }
private void combine() { ImagePlus imp = getImage(); if (imp==null) return; Roi[] rois = getSelectedRoisAsArray(); if (rois.length==1) { error("More than one item must be selected, or none"); return; } int nPointRois = 0; for (int i=0; i<rois.length; i++) { if (rois[i].getType()==Roi.POINT) nPointRois++; else break; } if (nPointRois==rois.length) combinePoints(imp, rois); else combineRois(imp, rois); }
void flatten() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) {IJ.noImage(); return;} ImageCanvas ic = imp.getCanvas(); if ((ic!=null && ic.getShowAllList()==null) && imp.getOverlay()==null && imp.getRoi()==null) error("Image does not have an overlay or ROI"); else IJ.doCommand("Flatten"); // run Image>Flatten in separate thread }
void split() { ImagePlus imp = getImage(); if (imp==null) return; Roi roi = imp.getRoi(); if (roi==null || roi.getType()!=Roi.COMPOSITE) { error("Image with composite selection required"); return; } boolean record = Recorder.record; Recorder.record = false; Roi[] rois = ((ShapeRoi)roi).getRois(); for (int i=0; i<rois.length; i++) { imp.setRoi(rois[i]); addRoi(false); } Recorder.record = record; if (record()) Recorder.record("roiManager", "Split"); }
void split() { ImagePlus imp = getImage(); if (imp==null) return; Roi roi = imp.getRoi(); if (roi==null || roi.getType()!=Roi.COMPOSITE) { error("Image with composite selection required"); return; } boolean record = Recorder.record; Recorder.record = false; Roi[] rois = ((ShapeRoi)roi).getRois(); for (int i=0; i<rois.length; i++) { imp.setRoi(rois[i]); addRoi(false); } Recorder.record = record; if (record()) Recorder.record("roiManager", "Split"); }
int[] indexes = getSelectedIndexes(); if (indexes.length==1) { error("More than one item must be selected, or none"); return;
int[] indexes = getSelectedIndexes(); if (indexes.length==1) { error("More than one item must be selected, or none"); return;