Skip to content

Commit

Permalink
2022.11.03 (1.53v15; Roi.translate)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Nov 4, 2022
1 parent c855608 commit 3930109
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 37 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.53v";
public static final String BUILD = "9";
public static final String BUILD = "15";
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
2 changes: 2 additions & 0 deletions ij/gui/GenericDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ public void addPanel(Panel panel, int constraints, Insets insets) {

/** Adds an image to the dialog. */
public void addImage(ImagePlus image) {
if (image==null)
return;
ImagePanel imagePanel = new ImagePanel(image);
addPanel(imagePanel);
if (imagePanels==null)
Expand Down
25 changes: 4 additions & 21 deletions ij/gui/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,33 +179,16 @@ public void setFillColor(Color color) {

/** Moves all the ROIs in this overlay. */
public void translate(int dx, int dy) {
for (int i=0; i<size(); i++) {
Roi roi = get(i);
if (roi.subPixelResolution()) {
Rectangle2D r = roi.getFloatBounds();
roi.setLocation(r.getX()+dx, r.getY()+dy);
} else {
Rectangle r = roi.getBounds();
roi.setLocation(r.x+dx, r.y+dy);
}
}
for (int i=0; i<size(); i++)
get(i).translate(dx,dy);
}

/** Moves all the ROIs in this overlay.
* Marcel Boeglin, October 2013
*/
public void translate(double dx, double dy) {
boolean intArgs = (int)dx==dx && (int)dy==dy;
for (int i=0; i<size(); i++) {
Roi roi = get(i);
if (roi.subPixelResolution() || !intArgs) {
Rectangle2D r = roi.getFloatBounds();
roi.setLocation(r.getX()+dx, r.getY()+dy);
} else {
Rectangle r = roi.getBounds();
roi.setLocation(r.x+(int)dx, r.y+(int)dy);
}
}
for (int i=0; i<size(); i++)
get(i).translate(dx,dy);
}

/** Measures the ROIs in this overlay on the specified image
Expand Down
13 changes: 12 additions & 1 deletion ij/gui/Roi.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ public void setLocation(double x, double y) {
subPixel = true;
}

public void translate(double dx, double dy) {
boolean intArgs = (int)dx==dx && (int)dy==dy;
if (subPixelResolution() || !intArgs) {
Rectangle2D r = getFloatBounds();
setLocation(r.getX()+dx, r.getY()+dy);
} else {
Rectangle r = getBounds();
setLocation(r.x+(int)dx, r.y+(int)dy);
}
}

/** Sets the ImagePlus associated with this ROI.
* <code>imp</code> may be null to remove the association to an image. */
public void setImage(ImagePlus imp) {
Expand Down Expand Up @@ -2264,7 +2275,7 @@ public boolean isLine() {


/** Return 'true' if this is a line or point selection. */
protected boolean isLineOrPoint() {
public boolean isLineOrPoint() {
return isLine() || type==POINT;
}

Expand Down
10 changes: 8 additions & 2 deletions ij/io/Opener.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,14 @@ public ImagePlus openWithHandleExtraFileTypes(String path, int[] fileTypes) {
fileTypes[0] = CUSTOM;
return null;
}
imp = (ImagePlus)IJ.runPlugIn("HandleExtraFileTypes", path);
if (imp==null) return null;
try {
imp = (ImagePlus)IJ.runPlugIn("HandleExtraFileTypes", path);
} catch(Exception e) {
if (IJ.debugMode) IJ.log("openWithHandleExtraFileTypes:\n"+path+"\n"+e);
imp = null;
}
if (imp==null)
return null;
FileInfo fi = imp.getOriginalFileInfo();
if (fi==null) {
fi = new FileInfo();
Expand Down
11 changes: 6 additions & 5 deletions ij/macro/FunctionFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
It was written by jerome.mutterer at ibmp.fr, and is based on Mark Longair's CommandFinder plugin.
*/
public class FunctionFinder implements TextListener, WindowListener, KeyListener, ItemListener, ActionListener {
private static String url = "http://wsr.imagej.net/developer/macro/functions.html";
private static Dialog dialog;
private TextField prompt;
private List functions;
Expand All @@ -27,11 +28,11 @@ public FunctionFinder(Editor editor) {

String exists = IJ.runMacro("return File.exists(getDirectory('macros')+'functions.html');");
if (exists=="0") {
String installLocalMacroFunctionsFile = "functions = File.openUrlAsString('"+IJ.URL+"/developer/macro/functions.html');\n"+
String installLocalMacroFunctionsFile = "functions = File.openUrlAsString(\""+url+"\");\n"+
"f = File.open(getDirectory('macros')+'functions.html');\n"+
"print (f, functions);\n"+
"File.close(f);";
try { IJ.runMacro(installLocalMacroFunctionsFile);
try {IJ.runMacro(installLocalMacroFunctionsFile);
} catch (Throwable e) { IJ.error("Problem downloading functions.html"); return;}
}
String f = IJ.runMacro("return File.openAsString(getDirectory('macros')+'functions.html');");
Expand Down Expand Up @@ -197,6 +198,7 @@ public void textValueChanged(TextEvent te) {
}

public void actionPerformed(ActionEvent e) {
String url2 = this.url;
Object b = e.getSource();
if (b==insertButton) {
int index = functions.getSelectedIndex();
Expand All @@ -205,16 +207,15 @@ public void actionPerformed(ActionEvent e) {
edPaste(selected);
}
} else if (b==infoButton) {
String url = IJ.URL+"/developer/macro/functions.html";
int index = functions.getSelectedIndex();
if (index>=0) {
String selected = functions.getItem(index);
int index2 = selected.indexOf("(");
if (index2==-1)
index2 = selected.length();
url = url + "#" + selected.substring(0, index2);
url2 = url2 + "#" + selected.substring(0, index2);
}
IJ.runPlugIn("ij.plugin.BrowserLauncher", url);
IJ.runPlugIn("ij.plugin.BrowserLauncher", url2);
} else if (b==closeButton)
closeAndRefocus();
}
Expand Down
8 changes: 7 additions & 1 deletion ij/macro/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4087,6 +4087,8 @@ String doDialog() {
gd.addChoice(prompt, choices, defaultChoice);
} else if (name.equals("setInsets")) {
gd.setInsets((int)getFirstArg(), (int)getNextArg(), (int)getLastArg());
} else if (name.equals("addImage")) {
gd.addImage(IJ.openImage(getStringArg()));
} else if (name.equals("addToSameRow")) {
interp.getParens();
gd.addToSameRow();
Expand Down Expand Up @@ -7727,7 +7729,7 @@ private Variable doRoi() {
return setSplineAnchors(imp, false);
else if (name.equals("setPolylineSplineAnchors"))
return setSplineAnchors(imp, true);
else if (name.equals("remove")) {
else if (name.equals("remove")||name.equals("selectNone")) {
getImage().deleteRoi();
return null;
}
Expand Down Expand Up @@ -7862,6 +7864,10 @@ else if (str.equals("right"))
} else if (name.equals("setUnscalableStrokeWidth")) {
roi.setUnscalableStrokeWidth(getArg());
return null;
} else if (name.equals("translate")) {
roi.translate(getFirstArg(),getLastArg());
imp.draw();
return null;
} else
interp.error("Unrecognized Roi function");
return null;
Expand Down
7 changes: 2 additions & 5 deletions ij/plugin/frame/RoiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2497,11 +2497,8 @@ private void translate() {
/** Moves the selected ROIs or all the ROIs if none are selected. */
public void translate(double dx, double dy) {
Roi[] rois = getSelectedRoisAsArray();
for (int i=0; i<rois.length; i++) {
Roi roi = rois[i];
Rectangle2D r = roi.getFloatBounds();
roi.setLocation(r.getX()+dx, r.getY()+dy);
}
for (int i=0; i<rois.length; i++)
rois[i].translate(dx,dy);
ImagePlus imp = WindowManager.getCurrentImage();
if (imp!=null)
imp.draw();
Expand Down
7 changes: 6 additions & 1 deletion release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
</head>
<body>

<li> <u>1.53v9 27 October 2022</u>
<li> <u>1.53v15 3 November 2022</u>
<ul>
<li> Thanks to Andrey Kazak, added the String.setFontSize() macro function.
<li> Thanks to Mario Faretta, added the Dialog.addImage(path) macro function.
<li> Thanks to Wilhelm Burger, added the Roi.translate() macro
function and Roi.translate() method
(<a href="http://wsr.imagej.net/macros/RoiTranslate.ijm">macro example</a>,
<a href="http://wsr.imagej.net/macros/js/RoiTranslate.js">JavaScript example</a>).
<li> Thanks to Avinoam Kalma, fixed a bug that caused ImageJ
to not correctly read TIFF images saved with the “deflate”
compression option.
Expand Down

0 comments on commit 3930109

Please sign in to comment.