MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / RectToolOptions

Class RectToolOptions

ij/src/main/java/ij/plugin/RectToolOptions.java:7–85  ·  view source on GitHub ↗

This plugin implements the rounded rectangle tool dialog box.

Source from the content-addressed store, hash-verified

5
6/** This plugin implements the rounded rectangle tool dialog box. */
7public class RectToolOptions implements PlugIn, DialogListener {
8 private String strokeColorName, fillColorName;
9 private static GenericDialog gd;
10 private static double defaultStrokeWidth = 0.0;
11 private static Color defaultStrokeColor;
12
13 public void run(String arg) {
14 if (gd!=null && gd.isVisible())
15 gd.toFront();
16 else
17 rectToolOptions();
18 }
19
20 void rectToolOptions() {
21 if (defaultStrokeColor==null)
22 defaultStrokeColor = Roi.getColor();
23 Color strokeColor = defaultStrokeColor;
24 Color fillColor = null;
25 if (defaultStrokeWidth==0.0)
26 defaultStrokeWidth = 1.0;
27 double strokeWidth = defaultStrokeWidth;
28 int cornerDiameter = (int)Prefs.get(Toolbar.CORNER_DIAMETER, 20);
29 ImagePlus imp = WindowManager.getCurrentImage();
30 Roi roi = imp!=null?imp.getRoi():null;
31 if (roi!=null && (roi.getType()==Roi.RECTANGLE)) {
32 strokeColor = roi.getStrokeColor();
33 if (strokeColor==null)
34 strokeColor = Roi.getColor();
35 fillColor = roi.getFillColor();
36 strokeWidth = roi.getStrokeWidth();
37 cornerDiameter = roi.getCornerDiameter();
38 }
39 String strokec = Colors.colorToString(strokeColor);
40 String fillc = Colors.colorToString(fillColor);
41
42 gd = GUI.newNonBlockingDialog("Rounded Rectangle Tool");
43 gd.addSlider("Stroke width:", 1, 25, (int)strokeWidth);
44 gd.addSlider("Corner diameter:", 0, 200, cornerDiameter);
45 gd.addStringField("Color: ", strokec);
46 gd.addStringField("Fill color: ", fillc);
47 gd.addDialogListener(this);
48 gd.showDialog();
49 }
50
51 public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
52 double strokeWidth2 = gd.getNextNumber();
53 int cornerDiameter2 = (int)gd.getNextNumber();
54 String strokec2 = gd.getNextString();
55 String fillc2 = gd.getNextString();
56 ImagePlus imp = WindowManager.getCurrentImage();
57 Roi roi = imp!=null?imp.getRoi():null;
58 Color strokeColor2 = Colors.decode(strokec2, defaultStrokeColor);
59 if (roi!=null && (roi.getType()==Roi.RECTANGLE)) {
60 roi.setStrokeWidth((int)strokeWidth2);
61 roi.setCornerDiameter((int)(cornerDiameter2));
62 strokeColor2 = Colors.decode(strokec2, roi.getStrokeColor());
63 Color fillColor = Colors.decode(fillc2, roi.getFillColor());
64 roi.setStrokeColor(strokeColor2);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected