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;
public static final String help = ""
+"
Point Tool
"
+""
+""
+"- Click on a point and drag to move it.
"
+" - Alt-click, or control-click, on a point to delete it.
"
+" - To delete multiple points, create an area
selection while holding down the alt key.
"
+" - Press 'alt+y' (Edit>Selection>Properties plus
alt key) to display the counts in a results table.
"
+" - Press 'm' (Analyze>Measure) to list the counter
and stack position associated with each point.
"
+" - To measure a subset of the points, move them
to an overlay, create a selection and then use
Image>Overlay>Measure Overlay.
"
+" - Use File>Save As>Tiff or File>Save As>Selection
to save the points and counts.
"
+" - Press 'F' (Image>Overlay>Flatten) to create an
RGB image with embedded markers for export.
"
+" - Hold the shift key down and points will be
constrained to a horizontal or vertical line.
"
+" - Use Edit>Selection>Select None to delete a
multi-point selection.
"
+" - Switch to the multi-point tool and use
Edit>Selection>Restore Selection to restore
a deleted multi-point selection.
"
+"
"
+"
"
+"";
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()];
gd = GUI.newNonBlockingDialog("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();
}
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 tb = Toolbar.getInstance();
if (tb!=null) tb.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==0 || counter!=getCounter()) {
setCounter(counter);
redraw = true;
}
}
if (isMacro) {
PointRoi roi = getPointRoi();
if (roi!=null) {
roi.setPointType(typeIndex);
roi.setStrokeColor(sc);
roi.setSize(sizeIndex);
redraw = true;
}
}
if (redraw) {
ImagePlus imp = null;
boolean impHasPointRoi = false;
PointRoi roi = getPointRoi();
if (roi!=null) {
roi.setShowLabels(!Prefs.noPointLabels);
imp = roi.getImage();
impHasPointRoi = true;
}
if (updateLabels) {
imp = WindowManager.getCurrentImage();
Overlay overlay = imp!=null?imp.getOverlay():null;
if (overlay!=null) {
for (int i=0; i