1 package ij.plugin.frame;
3 import java.awt.event.*;
8 import ij.plugin.frame.*;
25 private Button makeMacro, help;
26 private TextField macroName;
27 private String fitTypeStr = CurveFitter.fitList[0];
28 private static TextArea textArea;
29 private static Frame instance;
30 private static String commandName;
31 private static String commandOptions;
32 private static String defaultName =
"Macro";
42 Panel panel =
new Panel(
new FlowLayout(FlowLayout.CENTER, 2, 0));
43 panel.add(
new Label(
"Name:"));
44 macroName =
new TextField(defaultName,15);
46 panel.add(
new Label(
" "));
47 makeMacro =
new Button(
"Create");
48 makeMacro.addActionListener(
this);
50 panel.add(
new Label(
" "));
51 help =
new Button(
"?");
52 help.addActionListener(
this);
55 textArea =
new TextArea(
"",15,60,TextArea.SCROLLBARS_VERTICAL_ONLY);
56 textArea.setFont(
new Font(
"Monospaced", Font.PLAIN, 12));
58 add(
"Center", textArea);
65 public static void record(String method) {
68 textArea.append(method+
"();\n");
75 if (textArea==null || (Thread.currentThread().getName().startsWith(
"Run$_")&&!
recordInMacros))
77 commandName = command;
78 commandOptions = null;
82 static String fixPath (String path) {
83 StringBuffer sb =
new StringBuffer();
85 for (
int i=0; i<path.length(); i++) {
86 sb.append(c=path.charAt(i));
90 return new String(sb);
93 public static void record(String method, String arg) {
94 if (textArea==null)
return;
95 textArea.append(method+
"(\""+arg+
"\");\n");
98 public static void record(String method,
int a1) {
99 if (textArea==null)
return;
100 textArea.append(method+
"("+a1+
");\n");
103 public static void record(String method,
int a1,
int a2) {
104 if (textArea==null)
return;
105 textArea.append(method+
"("+a1+
", "+a2+
");\n");
108 public static void record(String method,
double a1,
double a2) {
109 if (textArea==null)
return;
110 textArea.append(method+
"("+a1+
", "+a2+
");\n");
113 public static void record(String method,
int a1,
int a2,
int a3) {
114 if (textArea==null)
return;
115 textArea.append(method+
"("+a1+
", "+a2+
", "+a3+
");\n");
118 public static void record(String method, String args,
int a1,
int a2) {
119 if (textArea==null)
return;
120 method =
"//"+method;
121 textArea.append(method+
"(\""+args+
"\", "+a1+
", "+a2+
");\n");
124 public static void record(String method,
int a1,
int a2,
int a3,
int a4) {
125 if (textArea==null)
return;
126 textArea.append(method+
"("+a1+
", "+a2+
", "+a3+
", "+a4+
");\n");
129 public static void record(String method, String path, String args,
int a1,
int a2,
int a3,
int a4,
int a5) {
130 if (textArea==null)
return;
131 path = fixPath(path);
132 method =
"//"+method;
133 textArea.append(method+
"(\""+path+
"\", "+
"\""+args+
"\", "+a1+
", "+a2+
", "+a3+
", "+a4+
", "+a5+
");\n");
136 public static void recordOption(String key, String value) {
138 value = addQuotes(value);
139 if (commandOptions==null)
140 commandOptions = key+
"="+value;
142 commandOptions +=
" "+key+
"="+value;
146 public static void recordPath(String key, String path) {
147 if (key==null)
return;
149 path = fixPath(path);
150 path = addQuotes(path);
151 if (commandOptions==null)
152 commandOptions = key+
"="+path;
154 commandOptions +=
" "+key+
"="+path;
158 public static void recordOption(String key) {
159 if (commandOptions==null && key.equals(
" "))
160 commandOptions =
" ";
163 if (commandOptions==null)
164 commandOptions = key;
166 commandOptions +=
" "+key;
170 static String trimKey(String key) {
171 int index = key.indexOf(
" ");
173 key = key.substring(0,index);
174 index = key.indexOf(
":");
176 key = key.substring(0,index);
177 key = key.toLowerCase(Locale.US);
183 if (commandName!=null) {
184 if (commandOptions!=null)
185 textArea.append(
"run(\""+commandName+
"\", \""+commandOptions+
"\");\n");
187 textArea.append(
"run(\""+commandName+
"\");\n");
190 commandOptions = null;
193 static String addQuotes(String value) {
194 int index = value.indexOf(
' ');
196 value =
"'"+value+
"'";
204 public void actionPerformed(ActionEvent e) {
205 if (e.getSource()==makeMacro)
207 else if (e.getSource()==help)
212 IJ.showMessage(
"Recorder",
213 "Click \"Create\" to open recorded commands\n"
214 +
"as a macro in an editor window.\n"
218 +
" Type ctrl+R (File>Run Macro) to\n"
221 +
" Use File>Save As to save it and\n"
222 +
" ImageJ's Open command to open it.\n"
224 +
" To create a command, use File>Save As,\n"
225 +
" add a '_' to the name, save in the \n"
226 +
" plugins folder, and restart ImageJ.\n"
228 +
" Use Edit>Convert to Plugin to convert\n"
229 +
" the macro to a plugin."
233 public void windowClosing(WindowEvent e) {
237 public void close() {