Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Sync with ImageJ 1.43e
Browse files Browse the repository at this point in the history
  • Loading branch information
dscho committed Aug 6, 2009
2 parents 0f0ae6b + 0c9e518 commit 79c981f
Show file tree
Hide file tree
Showing 33 changed files with 712 additions and 119 deletions.
7 changes: 6 additions & 1 deletion IJ_Props.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Note that commands must be unique.

# Version 1.42
# Version 1.43

# Popup Menu
popup01=Undo
Expand Down Expand Up @@ -265,6 +265,11 @@ filters08="Variance...",ij.plugin.filter.RankFilters("variance")
filters09=-
filters10="Show Circular Masks...",ij.plugin.filter.RankFilters("masks")

# Plugins installed in the File/Batch submenu
batch01="Measure...",ij.plugin.BatchMeasure
batch02="Convert...",ij.plugin.BatchConverter
batch03="Process...",ij.plugin.BatchProcesser

# Plugins installed in the Analyze/Gels submenu
gels01="Select First Lane[1]",ij.plugin.GelAnalyzer("first")
gels02="Select Next Lane[2]",ij.plugin.GelAnalyzer("next")
Expand Down
11 changes: 9 additions & 2 deletions ij/CommandListener.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package ij;

/** Plugins that implement this interface are notified
when ImageJ is about to run a menu command. */
/** Plugins that implement this interface are notified when ImageJ
is about to run a menu command. There is an example plugin at
http://rsb.info.nih.gov/ij/plugins/download/misc/Command_Listener.java
*/
public interface CommandListener {

/* The method is called when ImageJ is about to run a menu command,
where 'command' is the name of the command. Return this string
and ImageJ will run the command, return a different command name
and ImageJ will run that command, or return null to not run a command.
*/
public String commandExecuting(String command);

}
2 changes: 1 addition & 1 deletion ij/Executer.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void run() {
IJ.setKeyUp(IJ.ALL_KEYS); // set keys up except for "<", ">", "+" and "-" shortcuts
} catch(Throwable e) {
IJ.showStatus("");
IJ.showProgress(1.0);
IJ.showProgress(1, 1);
ImagePlus imp = WindowManager.getCurrentImage();
if (imp!=null) imp.unlock();
String msg = e.getMessage();
Expand Down
64 changes: 58 additions & 6 deletions ij/IJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,19 @@ public static ImageJ getInstance() {
}

/** Runs the macro contained in the string <code>macro</code>.
Returns any string value returned by the macro, or null.
The equivalent macro function is eval(). */
Returns any string value returned by the macro, null if the macro
does not return a value, or "[aborted]" if the macro was aborted
due to an error. The equivalent macro function is eval(). */
public static String runMacro(String macro) {
return runMacro(macro, "");
}

/** Runs the macro contained in the string <code>macro</code>.
The optional string argument can be retrieved in the
called macro using the getArgument() macro function.
Returns any string value returned by the macro, or null. */
Returns any string value returned by the macro, null if the macro
does not return a value, or "[aborted]" if the macro was aborted
due to an error. */
public static String runMacro(String macro, String arg) {
Macro_Runner mr = new Macro_Runner();
return mr.runMacro(macro, arg);
Expand Down Expand Up @@ -467,7 +470,11 @@ public static void showProgress(double progress) {
The bar is updated only if more than 90 ms have passed since the last call.
Does nothing if the ImageJ window is not present. */
public static void showProgress(int currentIndex, int finalIndex) {
if (progressBar!=null) progressBar.show(currentIndex, finalIndex);
if (progressBar!=null) {
progressBar.show(currentIndex, finalIndex);
if (currentIndex==finalIndex)
progressBar.setBatchMode(false);
}
}

/** Displays a message in a dialog box titled "Message".
Expand Down Expand Up @@ -1018,6 +1025,8 @@ public static void selectWindow(int id) {

/** Activates the window with the specified title. */
public static void selectWindow(String title) {
if (title.equals("ImageJ")&&ij!=null)
{ij.toFront(); return;}
long start = System.currentTimeMillis();
while (System.currentTimeMillis()-start<3000) { // 3 sec timeout
Frame frame = WindowManager.getFrame(title);
Expand Down Expand Up @@ -1411,8 +1420,9 @@ static String updateExtension(String path, String extension) {
return path;
}

/** Saves a string as a file. Returns an error message
if there is an exception, otherwise returns null. */
/** Saves a string as a file. Displays a file save dialog if
'path' is null or blank. Returns an error message
if there is an exception, otherwise returns null. */
public static String saveString(String string, String path) {
return write(string, path, false);
}
Expand All @@ -1425,6 +1435,13 @@ public static String append(String string, String path) {
}

private static String write(String string, String path, boolean append) {
if (path==null || path.equals("")) {
String msg = append?"Append String...":"Save String...";
SaveDialog sd = new SaveDialog(msg, "Untitled", ".txt");
String name = sd.getFileName();
if (name==null) return null;
path = sd.getDirectory() + name;
}
try {
BufferedWriter out = new BufferedWriter(new FileWriter(path, append));
out.write(string);
Expand All @@ -1435,6 +1452,41 @@ private static String write(String string, String path, boolean append) {
return null;
}

/** Opens a text file as a string. Displays a file open dialog
if path is null or blank. Returns null if the user cancels
the file open dialog. If there is an error, returns a
message in the form "Error: message". */
public static String openAsString(String path) {
if (path==null || path.equals("")) {
OpenDialog od = new OpenDialog("Open As String", "");
String directory = od.getDirectory();
String name = od.getFileName();
if (name==null) return null;
path = directory + name;
}
String str = "";
File file = new File(path);
if (!file.exists())
return "Error: file not found";
try {
StringBuffer sb = new StringBuffer(5000);
BufferedReader r = new BufferedReader(new FileReader(file));
while (true) {
String s=r.readLine();
if (s==null)
break;
else
sb.append(s+"\n");
}
r.close();
str = new String(sb);
}
catch (Exception e) {
str = "Error: "+e.getMessage();
}
return str;
}

/** Creates a new imagePlus. <code>Type</code> should contain "8-bit", "16-bit", "32-bit" or "RGB".
In addition, it can contain "white", "black" or "ramp" (the default is "white"). <code>Width</code>
and <code>height</code> specify the width and height of the image in pixels.
Expand Down
3 changes: 2 additions & 1 deletion ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class ImageJ extends Frame implements ActionListener,
MouseListener, KeyListener, WindowListener, ItemListener, Runnable {

/** Plugins should call IJ.getVersion() to get the version string. */
public static final String VERSION = "1.43d";
public static final String VERSION = "1.43e";
public static Color backgroundColor = new Color(220,220,220); //224,226,235
/** SansSerif, 12-point, plain font. */
public static final Font SansSerif12 = new Font("SansSerif", Font.PLAIN, 12);
Expand Down Expand Up @@ -329,6 +329,7 @@ public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}

public void keyPressed(KeyEvent e) {
//if (e.isConsumed()) return;
int keyCode = e.getKeyCode();
IJ.setKeyDown(keyCode);
hotkey = false;
Expand Down
1 change: 1 addition & 0 deletions ij/Menus.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ String addMenuBar() {
getMenu("Process>FFT", true);
Menu filtersMenu = getMenu("Process>Filters", true);
process.addSeparator();
getMenu("Process>Batch", true);
addPlugInItem(process, "Image Calculator...", "ij.plugin.ImageCalculator", 0, false);
addPlugInItem(process, "Subtract Background...", "ij.plugin.filter.BackgroundSubtracter", 0, false);
addItem(process, "Repeat Command", KeyEvent.VK_R, true);
Expand Down
2 changes: 1 addition & 1 deletion ij/gui/GenericDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public void addTextAreas(String text1, String text2, int rows, int columns) {
c.gridx = 0; c.gridy = y;
c.gridwidth = 2;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(15, 20, 0, 0);
c.insets = getInsets(15, 20, 0, 0);
grid.setConstraints(panel, c);
add(panel);
y++;
Expand Down
27 changes: 1 addition & 26 deletions ij/gui/ImageCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,30 +465,6 @@ void setMagnification2(double magnification) {
imp.setTitle(imp.getTitle());
}

/*
public void setMagnification(double mag, int x, int y) {
if (mag>32.0) magnification = 32.0;
if (mag<0.03125) mag = 0.03125;
int newWidth = (int)(imageWidth*mag);
int newHeight = (int)(imageHeight*mag);
Dimension newSize = canEnlarge(newWidth, newHeight);
if (newSize!=null) {
setDrawingSize(newSize.width, newSize.height);
if (newSize.width!=newWidth || newSize.height!=newHeight)
adjustSourceRect(mag, x, y);
else
setMagnification(mag);
imp.getWindow().pack();
} else
adjustSourceRect(mag, x, y);
repaint();
if (srcRect.width<imageWidth || srcRect.height<imageHeight)
resetMaxBounds();
this.magnification = magnification;
imp.setTitle(imp.getTitle());
}
*/

public Rectangle getSrcRect() {
return srcRect;
}
Expand Down Expand Up @@ -634,7 +610,6 @@ protected Dimension canEnlarge(int newWidth, int newHeight) {
ImageWindow win = imp.getWindow();
if (win==null) return null;
Rectangle r1 = win.getBounds();

Insets insets = win.getInsets();
Point loc = getLocation();
if (loc.x>insets.left+5 || loc.y>insets.top+5) {
Expand All @@ -645,7 +620,7 @@ protected Dimension canEnlarge(int newWidth, int newHeight) {
r1.width = r1.width - dstWidth + newWidth+10;
r1.height = r1.height - dstHeight + newHeight+10;
}
Rectangle max = win.getMaxWindow();
Rectangle max = win.getMaxWindow(r1.x, r1.y);
boolean fitsHorizontally = r1.x+r1.width<max.x+max.width;
boolean fitsVertically = r1.y+r1.height<max.y+max.height;
if (fitsHorizontally && fitsVertically)
Expand Down
36 changes: 28 additions & 8 deletions ij/gui/ImageWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void show() {
private void setLocationAndSize(boolean updating) {
int width = imp.getWidth();
int height = imp.getHeight();
Rectangle maxWindow = getMaxWindow();
Rectangle maxWindow = getMaxWindow(0,0);
if (maxWindow.x==maxWindow.width) // work around for Linux bug
maxWindow = new Rectangle(0, maxWindow.y, maxWindow.width, maxWindow.height);
if (WindowManager.getWindowCount()<=1)
Expand Down Expand Up @@ -215,17 +215,37 @@ private void setLocationAndSize(boolean updating) {
pack();
}

Rectangle getMaxWindow() {
Rectangle getMaxWindow(int xloc, int yloc) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle maxWindow = ge.getMaximumWindowBounds();
Rectangle bounds = ge.getMaximumWindowBounds();
if (xloc>bounds.x+bounds.width || yloc>bounds.y+bounds.height) {
Rectangle bounds2 = getSecondaryMonitorBounds(ge, xloc, yloc);
if (bounds2!=null) return bounds2;
}
Dimension ijSize = ij!=null?ij.getSize():new Dimension(0,0);
if (maxWindow.height>600) {
maxWindow.y += ijSize.height;
maxWindow.height -= ijSize.height;
if (bounds.height>600) {
bounds.y += ijSize.height;
bounds.height -= ijSize.height;
}
return maxWindow;
return bounds;
}


private Rectangle getSecondaryMonitorBounds(GraphicsEnvironment ge, int xloc, int yloc) {
//IJ.log("getSecondaryMonitorBounds "+wb);
GraphicsDevice[] gs = ge.getScreenDevices();
for (int j=0; j<gs.length; j++) {
GraphicsDevice gd = gs[j];
GraphicsConfiguration[] gc = gd.getConfigurations();
for (int i=0; i<gc.length; i++) {
Rectangle bounds = gc[i].getBounds();
//IJ.log(j+" "+i+" "+bounds+" "+bounds.contains(wb.x, wb.y));
if (bounds!=null && bounds.contains(xloc, yloc))
return bounds;
}
}
return null;
}

public double getInitialMagnification() {
return initialMagnification;
}
Expand Down
7 changes: 6 additions & 1 deletion ij/gui/ProgressBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class ProgressBar extends Canvas {
private double percent;
private long lastTime = 0;
private boolean showBar;
private boolean batchMode;

private Color barColor = Color.gray;
private Color fillColor = new Color(204,204,255);
Expand Down Expand Up @@ -55,7 +56,7 @@ public void show(double percent) {
* batch mode.
*/
public void show(double percent, boolean showInBatchMode) {
if (!showInBatchMode && Interpreter.isBatchMode()) return;
if (!showInBatchMode && (batchMode||Interpreter.isBatchMode())) return;
if (percent>=1.0) { //clear the progress bar
percent = 0.0;
showBar = false;
Expand Down Expand Up @@ -109,4 +110,8 @@ public Dimension getPreferredSize() {
return new Dimension(canvasWidth, canvasHeight);
}

public void setBatchMode(boolean batchMode) {
this.batchMode = batchMode;
}

}
34 changes: 29 additions & 5 deletions ij/gui/Roi.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ protected void grow(int sx, int sy) {
}
if (constrain) {
// constrain selection to be square
if (!center)
{growConstrained(xNew, yNew); return;}
int dx, dy, d;
dx = xNew - x;
dy = yNew - y;
Expand All @@ -330,7 +332,6 @@ protected void grow(int sx, int sy) {
xNew = x + d;
yNew = y + d;
}

if (center) {
width = Math.abs(xNew - startX)*2;
height = Math.abs(yNew - startY)*2;
Expand All @@ -354,6 +355,29 @@ protected void grow(int sx, int sy) {
oldHeight = height;
}

private void growConstrained(int xNew, int yNew) {
int dx = xNew - startX;
int dy = yNew - startY;
width = height = (int)Math.round(Math.sqrt(dx*dx + dy*dy));
if (type==RECTANGLE) {
x = (xNew>=startX)?startX:startX - width;
y = (yNew>=startY)?startY:startY - height;
if (x<0) x = 0;
if (y<0) y = 0;
if ((x+width) > xMax) width = xMax-x;
if ((y+height) > yMax) height = yMax-y;
} else {
x = startX + dx/2 - width/2;
y = startY + dy/2 - height/2;
}
updateClipRect();
imp.draw(clipX, clipY, clipWidth, clipHeight);
oldX = x;
oldY = y;
oldWidth = width;
oldHeight = height;
}

protected void moveHandle(int sx, int sy) {
double asp;
if (clipboard!=null) return;
Expand Down Expand Up @@ -454,10 +478,10 @@ protected void moveHandle(int sx, int sy) {
}

if(constrain) {

if(activeHandle==1 || activeHandle==5) width=height;
else height=width;

if (activeHandle==1 || activeHandle==5)
width=height;
else
height=width;
if(center){
x=xc-width/2;
y=yc-height/2;
Expand Down
Loading

0 comments on commit 79c981f

Please sign in to comment.