-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRun_MyMacro.java
53 lines (49 loc) · 1.44 KB
/
Run_MyMacro.java
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
package QuickPALM;
import ij.*;
import ij.measure.*;
import ij.plugin.*;
import ij.plugin.filter.*;
import ij.plugin.frame.*;
import ij.process.*;
import ij.gui.*;
import ij.measure.CurveFitter.*;
import java.awt.*;
import java.lang.*;
import java.io.*;
import java.net.*;
public class Run_MyMacro implements PlugIn
{
public void run(String arg)
{
IJ.runMacro(getText(arg));
}
private String getText(String path) {
String text = "";
try {
// get the text resource as a stream
InputStream is = getClass().getResourceAsStream(path);
if (is==null)
is = getClass().getResourceAsStream("/" + path);
if (is==null) {
//IJ.showMessage("JAR Demo", "File not found in JAR at "+path);
return "";
}
InputStreamReader isr = new InputStreamReader(is);
StringBuffer sb = new StringBuffer();
char [] b = new char [8192];
int n;
//read a block and append any characters
while ((n = isr.read(b)) > 0)
sb.append(b,0, n);
// display the text in a TextWindow
text = sb.toString();
}
catch (IOException e) {
String msg = e.getMessage();
if (msg==null || msg.equals(""))
msg = "" + e;
//IJ.showMessage("JAR Demo", msg);
}
return text;
}
}