File: RectToolOptions.java

package info (click to toggle)
imagej 1.52j-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,604 kB
  • sloc: java: 120,017; sh: 279; xml: 161; makefile: 6
file content (85 lines) | stat: -rw-r--r-- 2,797 bytes parent folder | download | duplicates (3)
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
package ij.plugin;
import ij.*;
import ij.gui.*;
import java.awt.*;

/** This plugin implements the rounded rectangle tool dialog box. */
public class RectToolOptions implements PlugIn, DialogListener {
	private String strokeColorName, fillColorName;
	private static GenericDialog gd;
	private static double defaultStrokeWidth = 0.0;
	private static Color defaultStrokeColor;

 	public void run(String arg) {
 		if (gd!=null && gd.isVisible())
 			gd.toFront();
 		else
			rectToolOptions();
	}
				
	void rectToolOptions() {
		if (defaultStrokeColor==null)
			defaultStrokeColor = Roi.getColor();
		Color strokeColor = defaultStrokeColor;
		Color fillColor = null;
		if (defaultStrokeWidth==0.0)
			defaultStrokeWidth = 1.0;
		double strokeWidth = defaultStrokeWidth;
		int cornerDiameter = (int)Prefs.get(Toolbar.CORNER_DIAMETER, 20);
		ImagePlus imp = WindowManager.getCurrentImage();
		Roi roi = imp!=null?imp.getRoi():null;
		if (roi!=null && (roi.getType()==Roi.RECTANGLE)) {
			strokeColor = roi.getStrokeColor();
			if (strokeColor==null)
				strokeColor = Roi.getColor();
			fillColor = roi.getFillColor();
			strokeWidth = roi.getStrokeWidth();
			cornerDiameter = roi.getCornerDiameter();
		}
		String strokec = Colors.colorToString(strokeColor);
		String fillc = Colors.colorToString(fillColor);

		gd = new NonBlockingGenericDialog("Rounded Rectangle Tool");
		gd.addSlider("Stroke width:", 1, 25, (int)strokeWidth);
		gd.addSlider("Corner diameter:", 0, 200, cornerDiameter);
		gd.addStringField("Color: ", strokec);
		gd.addStringField("Fill color: ", fillc);
		gd.addDialogListener(this);
		gd.showDialog();
	}

	public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
		double strokeWidth2 = gd.getNextNumber();
		int cornerDiameter2 = (int)gd.getNextNumber();
		String strokec2 = gd.getNextString();
		String fillc2 = gd.getNextString();
		ImagePlus imp = WindowManager.getCurrentImage();
		Roi roi = imp!=null?imp.getRoi():null;
		Color strokeColor2 = Colors.decode(strokec2, defaultStrokeColor);
		if (roi!=null && (roi.getType()==Roi.RECTANGLE)) {
			roi.setStrokeWidth((int)strokeWidth2);
			roi.setCornerDiameter((int)(cornerDiameter2));
			strokeColor2 = Colors.decode(strokec2, roi.getStrokeColor());
			Color fillColor = Colors.decode(fillc2, roi.getFillColor());
			roi.setStrokeColor(strokeColor2);
			roi.setFillColor(fillColor);
		}
		defaultStrokeWidth = strokeWidth2;
		defaultStrokeColor = strokeColor2;
		Toolbar.setRoundRectArcSize(cornerDiameter2);
		if (cornerDiameter2>0) {
			if (!Toolbar.getToolName().equals("roundrect"))
				IJ.setTool("roundrect");
		}
		return true;
	}
	
	public static Color getDefaultStrokeColor() {
		return defaultStrokeColor;
	}
	
	public static float getDefaultStrokeWidth() {
		return (float)defaultStrokeWidth;
	}
	
}