Skip to content

Commit

Permalink
2023.03.15 (1.54d14; Macro #include)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Mar 15, 2023
1 parent 779b27c commit 9619147
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class ImageJ extends Frame implements ActionListener,

/** Plugins should call IJ.getVersion() or IJ.getFullVersion() to get the version string. */
public static final String VERSION = "1.54d";
public static final String BUILD = "9";
public static final String BUILD = "14";
public static Color backgroundColor = new Color(237,237,237);
/** SansSerif, 12-point, plain font. */
public static final Font SansSerif12 = new Font("SansSerif", Font.PLAIN, 12);
Expand Down
31 changes: 21 additions & 10 deletions ij/gui/Arrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,23 @@ private Shape getShape() {
}

private ShapeRoi getShapeRoi() {
Shape arrow = getPath();
BasicStroke stroke = new BasicStroke(getStrokeWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
ShapeRoi sroi = new ShapeRoi(arrow);
Shape outlineShape = stroke.createStrokedShape(arrow);
sroi.or(new ShapeRoi(outlineShape));
return sroi;
try {
Shape arrow = getPath();
BasicStroke stroke = new BasicStroke(getStrokeWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
ShapeRoi sroi = new ShapeRoi(arrow);
Shape outlineShape = stroke.createStrokedShape(arrow);
sroi.or(new ShapeRoi(outlineShape));
return sroi;
} catch(Exception e) {};
return null;
}

public ImageProcessor getMask() {
if (width==0 && height==0)
Roi roi = getShapeRoi();
if (width==0 && height==0 || roi==null)
return null;
else
return getShapeRoi().getMask();
return roi.getMask();
}

private double getOutlineWidth() {
Expand All @@ -257,6 +261,8 @@ private double getOutlineWidth() {

public void drawPixels(ImageProcessor ip) {
ShapeRoi shapeRoi = getShapeRoi();
if (shapeRoi==null)
return;
ShapeRoi shapeRoi2 = null;
if (doubleHeaded) {
flipEnds();
Expand All @@ -276,12 +282,17 @@ public void drawPixels(ImageProcessor ip) {
}

public boolean contains(int x, int y) {
return getShapeRoi().contains(x, y);
Roi roi = getShapeRoi();
return roi!=null?roi.contains(x,y):false;
}

/** Return the bounding rectangle of this arrow. */
public Rectangle getBounds() {
return getShapeRoi().getBounds();
Roi roi = getShapeRoi();
if (roi!=null)
return roi.getBounds();
else
return super.getBounds();
}

protected void handleMouseDown(int sx, int sy) {
Expand Down
20 changes: 14 additions & 6 deletions ij/macro/MacroRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ public class MacroRunner implements Runnable {
private Thread thread;
private String argument;
private Editor editor;
private int lineNumberOffset;

/** Create a MacroRunner. */
public MacroRunner() {
}

/** Create a new object that interprets macro source in a separate thread. */
public MacroRunner(String macro) {
this(macro, (Editor)null);
}

/** Create a new object that interprets macro source in debug mode if 'editor' is not null. */
public MacroRunner(String macro, Editor editor) {
this.macro = macro;
this.editor = editor;
thread = new Thread(this, "Macro$");
thread.setPriority(Math.max(thread.getPriority()-2, Thread.MIN_PRIORITY));
thread.start();
Expand Down Expand Up @@ -90,6 +85,14 @@ public MacroRunner(Program pgm, int address, String name, String argument) {
thread.start();
}

/** Runs the specified macro code. */
public void run(String macro) {
this.macro = macro;
thread = new Thread(this, "Macro$");
thread.setPriority(Math.max(thread.getPriority()-2, Thread.MIN_PRIORITY));
thread.start();
}

/** Runs a tokenized macro in debug mode if 'editor' is not null. */
public MacroRunner(Program pgm, int address, String name, Editor editor) {
this.pgm = pgm;
Expand Down Expand Up @@ -127,6 +130,11 @@ public void run(Program pgm, int address, String name) {
public Thread getThread() {
return thread;
}

/** Use 'editor' to run the macro in debug mode. */
public void setEditor(Editor editor) {
this.editor = editor;
}

/** Used to run the macro code in 'macro' on a separate thread. */
public void run() {
Expand Down
4 changes: 3 additions & 1 deletion ij/plugin/Macro_Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ else if (name.endsWith(".bsh"))
return runBeanShell(macro, arg);
else if (name.endsWith(".py"))
return runPython(macro, arg);
else
else {
macro = Editor.doInclude(macro);
return runMacro(macro, arg);
}
}
catch (Exception e) {
if (!Macro.MACRO_CANCELED.equals(e.getMessage()))
Expand Down
38 changes: 27 additions & 11 deletions ij/plugin/frame/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ public Editor(String name) {
public Editor(int rows, int columns, int fontSize, int options) {
super("Editor");
WindowManager.addWindow(this);
addMenuBar(options);
if ((options&RUN_BAR)!=0) {
addMenuBar(options);
boolean addRunBar = (options&RUN_BAR)!=0;
if (addRunBar) {
Panel panel = new Panel(new FlowLayout(FlowLayout.LEFT, 0, 0));
runButton = new Button("Run");
runButton.addActionListener(this);
Expand Down Expand Up @@ -161,6 +162,8 @@ public Editor(int rows, int columns, int fontSize, int options) {
pack();
setFont();
positionWindow();
if (addRunBar)
ta.requestFocus(); // needed for selections to show
if (!IJ.isJava18() && !IJ.isLinux())
insertSpaces = false;
}
Expand Down Expand Up @@ -503,9 +506,22 @@ else if (getTitle().endsWith(".py"))
changes = true;
checkForCurlyQuotes = false;
}
currentMacroEditor = this;
if (text.startsWith("// include ")) { // include additional functions
String path = text.substring(11, text.indexOf("\n"));
currentMacroEditor = this;
text = doInclude(text);
MacroRunner mr = new MacroRunner();
if (debug)
mr.setEditor(this);
mr.run(text);
}

/** Process any #include statment at begining of macro. */
public static String doInclude(String code) {
if (code.startsWith("#include ")||code.startsWith("// include ")) {
if (IJ.isWindows())
code = code.replaceAll("\r\n", "\n");
int offset = code.startsWith("#include ")?9:11;
int eol = code.indexOf("\n");
String path = code.substring(offset, eol);
boolean isURL = path.startsWith("http://") || path.startsWith("https://");
if (!isURL) {
boolean fullPath = path.startsWith("/") || path.startsWith("\\") || path.indexOf(":\\")==1 || path.indexOf(":/")==1;
Expand All @@ -518,14 +534,15 @@ else if (getTitle().endsWith(".py"))
if (!f.exists())
IJ.error("Include file not found:\n"+path);
}
code = code.substring(eol+1,code.length());
if (isURL)
text = text + IJ.openUrlAsString(path);
code = "//\n"+code + IJ.openUrlAsString(path);
else
text = text+IJ.openAsString(path);
code = "//\n"+code + IJ.openAsString(path);
}
new MacroRunner(text, debug?this:null);
return code;
}

void evaluateMacro() {
String title = getTitle();
if (title.endsWith(".js")||title.endsWith(".bsh")||title.endsWith(".py"))
Expand Down Expand Up @@ -1388,8 +1405,7 @@ void find(String s) {
searchString = s2;
if (index<0)
{IJ.beep(); return;}
ta.setSelectionStart(index);
ta.setSelectionEnd(index+s.length());
ta.select(index, index+s.length());
}

boolean isWholeWordMatch(String text, String word, int index) {
Expand Down
7 changes: 5 additions & 2 deletions release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</head>
<body>

<li> <u>1.54d9 13 March 2023</u>
<li> <u>1.54d14 15 March 2023</u>
<ul>
<li> Thanks to Norbert Vischer, added an 'include'
<li> Thanks to Norbert Vischer, added an '#include'
statement to the macro language. For an example,
use the <i>Help&gt;Examples&gt;Macro&gt;Turtle Graphics</i>
command.
Expand All @@ -24,6 +24,9 @@
16-bit images in the Brightness/Contrast dialog to 0 and 65,535.
<li> Thanks to 'KlMichel', fixed bug with ROI Manager "Multi Measure"
command and point selections.
<li> Fixed a 1.53g text editor regression where Search and Debug
selections were not visible on windows with "Run", "Install"
and "Macro" buttons.
</ul>

<li> <u>1.54c 6 March 2023</u>
Expand Down

0 comments on commit 9619147

Please sign in to comment.