1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
package ij.plugin;
import ij.*;
import ij.gui.*;
import ij.process.*;
import ij.plugin.filter.Analyzer;
import ij.measure.Measurements;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
/** This plugin implements the Edit/Options/Point Tool command. */
public class PointToolOptions implements PlugIn, DialogListener {
private static GenericDialog gd = null;
private boolean multipointTool;
private boolean isMacro;
private static final String help = "<html>"
+"<h1>Point Tool</h1>"
+"<font size=+1>"
+"<ul>"
+"<li> Alt-click, or control-click, on a point to delete it.<br>"
+"<li> Press 'alt+y' (<i>Edit>Selection>Properties</i> plus<br>alt key) to display the counts in a results table.<br>"
+"<li> Press 'm' (<i>Analyze>Measure</i>) to list the counter<br>and stack position associated with each point.<br>"
+"<li> Use <i>File>Save As>Tiff</i> or <i>File>Save As>Selection</i><br>to save the points and counts.<br>"
+"<li> Press 'F' (<i>Image>Overlay</i>>Flatten</i>) to create an<br>RGB image with embedded markers for export.<br>"
+"<li> Hold the shift key down and points will be<br>constrained to a horizontal or vertical line.<br>"
+"</ul>"
+" <br>"
+"</font>";
public void run(String arg) {
if (gd!=null && gd.isShowing() && !IJ.isMacro()) {
gd.toFront();
update();
} else
showDialog();
}
void showDialog() {
String options = IJ.isMacro()?Macro.getOptions():null;
isMacro = options!=null;
boolean legacyMacro = false;
if (isMacro) {
options = options.replace("selection=", "color=");
options = options.replace("marker=", "size=");
options = options.replace("type=Crosshair", "type=Cross");
Macro.setOptions(options);
legacyMacro = options.contains("auto-") || options.contains("add");
}
multipointTool = Toolbar.getMultiPointMode() && !legacyMacro;
if (isMacro && !legacyMacro)
multipointTool = true;
Color sc =Roi.getColor();
String sname = Colors.getColorName(sc, "Yellow");
Color cc =PointRoi.getDefaultCrossColor();
String cname = Colors.getColorName(cc, "None");
String type = PointRoi.types[PointRoi.getDefaultType()];
String size = PointRoi.sizes[PointRoi.getDefaultSize()];
if (multipointTool)
gd = new NonBlockingGenericDialog("Point Tool");
else
gd = new GenericDialog("Point Tool");
gd.setInsets(5,0,2);
gd.addChoice("Type:", PointRoi.types, type);
gd.addChoice("Color:", Colors.getColors(), sname);
gd.addChoice("Size:", PointRoi.sizes, size);
if (!multipointTool) {
gd.addCheckbox("Auto-measure", Prefs.pointAutoMeasure);
gd.addCheckbox("Auto-next slice", Prefs.pointAutoNextSlice);
gd.addCheckbox("Add_to overlay", Prefs.pointAddToOverlay);
gd.addCheckbox("Add to ROI Manager", Prefs.pointAddToManager);
}
gd.setInsets(5, 20, 0);
gd.addCheckbox("Label points", !Prefs.noPointLabels);
gd.addCheckbox("Show on all slices", Prefs.showAllPoints);
if (multipointTool) {
gd.setInsets(15,0,5);
String[] choices = PointRoi.getCounterChoices();
gd.addChoice("Counter:", choices, choices[getCounter()]);
gd.setInsets(2, 75, 0);
gd.addMessage(getCount(getCounter())+" ");
}
gd.addHelp(help);
gd.addDialogListener(this);
gd.showDialog();
if (gd.wasCanceled()) {
}
}
public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
boolean redraw = false;
// type
int typeIndex = gd.getNextChoiceIndex();
if (typeIndex!=PointRoi.getDefaultType()) {
PointRoi.setDefaultType(typeIndex);
redraw = true;
}
// color
String selectionColor = gd.getNextChoice();
Color sc = Colors.getColor(selectionColor, Color.yellow);
if (sc!=Roi.getColor()) {
Roi.setColor(sc);
redraw = true;
Toolbar.getInstance().repaint();
}
// size
int sizeIndex = gd.getNextChoiceIndex();
if (sizeIndex!=PointRoi.getDefaultSize()) {
PointRoi.setDefaultSize(sizeIndex);
redraw = true;
}
if (!multipointTool) {
Prefs.pointAutoMeasure = gd.getNextBoolean();
Prefs.pointAutoNextSlice = gd.getNextBoolean();
Prefs.pointAddToOverlay = gd.getNextBoolean();
Prefs.pointAddToManager = gd.getNextBoolean();
if (Prefs.pointAddToOverlay)
Prefs.pointAddToManager = false;
if (Prefs.pointAutoNextSlice&&!Prefs.pointAddToManager)
Prefs.pointAutoMeasure = true;
}
boolean updateLabels = false;
boolean noPointLabels = !gd.getNextBoolean();
if (noPointLabels!=Prefs.noPointLabels) {
redraw = true;
updateLabels = true;
}
Prefs.noPointLabels = noPointLabels;
boolean showAllPoints = gd.getNextBoolean();
if (showAllPoints!=Prefs.showAllPoints)
redraw = true;
Prefs.showAllPoints = showAllPoints;
if (multipointTool) {
int counter = gd.getNextChoiceIndex();
if (counter!=getCounter()) {
setCounter(counter);
redraw = true;
}
}
if (isMacro) {
PointRoi roi = getPointRoi();
if (roi!=null) {
roi.setPointType(typeIndex);
roi.setStrokeColor(sc);
roi.setSize(sizeIndex);
}
}
if (redraw) {
ImagePlus imp = null;
PointRoi roi = getPointRoi();
if (roi!=null) {
roi.setShowLabels(!Prefs.noPointLabels);
imp = roi.getImage();
}
if (updateLabels) {
imp = WindowManager.getCurrentImage();
Overlay overlay = imp!=null?imp.getOverlay():null;
int pointRoiCount = 0;
if (overlay!=null) {
for (int i=0; i<overlay.size(); i++) {
Roi r = overlay.get(i);
roi = r!=null && (r instanceof PointRoi)?(PointRoi)r:null;
if (roi!=null) {
roi.setShowLabels(!Prefs.noPointLabels);
pointRoiCount++;
}
}
if (pointRoiCount==0)
imp = null;
}
}
if (imp!=null)
imp.draw();
}
return true;
}
private static int getCounter() {
PointRoi roi = getPointRoi();
return roi!=null?roi.getCounter():0;
}
private static void setCounter(int counter) {
PointRoi roi = getPointRoi();
if (roi!=null)
roi.setCounter(counter);
PointRoi.setDefaultCounter(counter);
}
private static PointRoi getPointRoi() {
ImagePlus imp = WindowManager.getCurrentImage();
if (imp==null)
return null;
Roi roi = imp.getRoi();
if (roi==null)
return null;
if (roi instanceof PointRoi)
return (PointRoi)roi;
else
return null;
}
private static int getCount(int counter) {
PointRoi roi = getPointRoi();
return roi!=null?roi.getCount(counter):0;
}
public static void update() {
if (gd!=null && gd.isShowing()) {
Vector choices = gd.getChoices();
if (choices==null || choices.size()<4)
return;
Choice counterChoice = (Choice)choices.elementAt(3);
int counter = getCounter();
int count = getCount(counter);
counterChoice.select(counter);
((Label)gd.getMessage()).setText(""+count);
}
}
}
|