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.43f
Browse files Browse the repository at this point in the history
  • Loading branch information
dscho committed Aug 24, 2009
2 parents 79c981f + 44685d0 commit 84103f3
Show file tree
Hide file tree
Showing 31 changed files with 1,215 additions and 703 deletions.
10 changes: 6 additions & 4 deletions IJ_Props.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ popup12=Duplicate...

# Plugins installed in the File/New submenu
new01="Image...[n]",ij.plugin.Commands("new")
new02="Text Window[N]",ij.plugin.NewPlugin("text")
new03="Internal Clipboard",ij.plugin.Clipboard("show")
new04="System Clipboard[V]",ij.plugin.Clipboard("showsys")
new02="Hyperstack...",ij.plugin.HyperStackConverter("new")
new03="Text Window[N]",ij.plugin.NewPlugin("text")
new04="Internal Clipboard",ij.plugin.Clipboard("show")
new05="System Clipboard[V]",ij.plugin.Clipboard("showsys")

# Plugins installed in the File/Import submenu
import01="Image Sequence...",ij.plugin.FolderOpener
import02="Raw...",ij.plugin.Raw
Expand Down Expand Up @@ -101,7 +103,7 @@ adjust01="Brightness/Contrast...[C]",ij.plugin.frame.ContrastAdjuster
adjust02="Window/Level...",ij.plugin.frame.ContrastAdjuster("wl")
adjust03="Color Balance...",ij.plugin.frame.ContrastAdjuster("balance")
adjust04="Threshold...[T]",ij.plugin.frame.ThresholdAdjuster
adjust05="Size...",ij.plugin.filter.Resizer
adjust05="Size...",ij.plugin.Resizer
adjust06="Canvas Size...",ij.plugin.CanvasResizer
adjust07="Line Width... ",ij.plugin.frame.LineWidthAdjuster

Expand Down
3 changes: 1 addition & 2 deletions ij/IJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ public static void showStatus(String s) {
ic.setShowCursorStatus(s.length()==0?true:false);
}

/** Displays a line of text in the "Results" window. Writes to
System.out.println if the "ImageJ" frame is not present. */
/** Obsolete; replaced by IJ.log().*/
public static void write(String s) {
if (textPanel==null && ij!=null)
showResults();
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.43e";
public static final String VERSION = "1.43f";
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 @@ -573,6 +573,7 @@ else if (delta>0 && DEFAULT_PORT+delta<65536)
if (arg.startsWith("-")) {
if ((arg.startsWith("-macro") || arg.startsWith("-batch")) && i+1<nArgs) {
String arg2 = i+2<nArgs?args[i+2]:null;
Prefs.commandLineMacro = true;
IJ.runMacroFile(args[i+1], arg2);
break;
} else if (arg.startsWith("-eval") && i+1<nArgs) {
Expand Down
2 changes: 1 addition & 1 deletion ij/Menus.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ String addMenuBar() {
getMenu("Image>Stacks", true);
Menu hyperstacksMenu = getMenu("Image>Hyperstacks", true);
image.addSeparator();
addPlugInItem(image, "Crop", "ij.plugin.filter.Resizer(\"crop\")", KeyEvent.VK_X, true);
addPlugInItem(image, "Crop", "ij.plugin.Resizer(\"crop\")", KeyEvent.VK_X, true);
addPlugInItem(image, "Duplicate...", "ij.plugin.filter.Duplicater", KeyEvent.VK_D, true);
addPlugInItem(image, "Rename...", "ij.plugin.SimpleCommands(\"rename\")", 0, false);
addPlugInItem(image, "Scale...", "ij.plugin.Scaler", KeyEvent.VK_E, false);
Expand Down
9 changes: 9 additions & 0 deletions ij/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class Prefs {
static String homeDir; // ImageJ folder
static int threads;
static int transparentIndex = -1;
static boolean commandLineMacro;

/** Finds and loads the ImageJ configuration file, "IJ_Props.txt".
@return an error message if "IJ_Props.txt" not found.
Expand Down Expand Up @@ -190,6 +191,14 @@ static void setHomeDir(String path) {
homeDir = path;
}

/** Returns the default directory, if any, or null. */
public static String getDefaultDirectory() {
if (commandLineMacro)
return null;
else
return getString(DIR_IMAGE);
}

/** Finds an string in IJ_Props or IJ_Prefs.txt. */
public static String getString(String key) {
return props.getProperty(key);
Expand Down
49 changes: 37 additions & 12 deletions ij/gui/GenericDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ij.plugin.filter.PlugInFilter;
import ij.plugin.filter.PlugInFilterRunner;
import ij.util.Tools;
import ij.macro.MacroRunner;
import ij.macro.*;


/**
Expand Down Expand Up @@ -670,14 +670,20 @@ public double getNextNumber() {
if (d!=null)
value = d.doubleValue();
else {
invalidNumber = true;
errorMessage = "\""+theText+"\" is an invalid number";
value = 0.0;
if (macro) {
IJ.error("Macro Error", "Numeric value expected in run() function\n \n"
+" Dialog: \""+getTitle()+"\"\n"
+" Label: \""+label+"\"\n"
+" Value: \""+theText+"\"");
// Is the value a macro variable?
if (theText.startsWith("&")) theText = theText.substring(1);
Interpreter interp = Interpreter.getInstance();
value = interp!=null?interp.getVariable(theText):Double.NaN;
if (Double.isNaN(value)) {
invalidNumber = true;
errorMessage = "\""+theText+"\" is an invalid number";
value = 0.0;
if (macro) {
IJ.error("Macro Error", "Numeric value expected in run() function\n \n"
+" Dialog box title: \""+getTitle()+"\"\n"
+" Key: \""+label.toLowerCase(Locale.US)+"\"\n"
+" Value or variable name: \""+theText+"\"");
}
}
}
}
Expand Down Expand Up @@ -744,7 +750,13 @@ public String getNextString() {
if (macro) {
String label = (String)labels.get((Object)tf);
theText = Macro.getValue(macroOptions, label, theText);
//IJ.write("getNextString: "+label+" "+theText);
if (theText!=null && (theText.startsWith("&")||label.toLowerCase(Locale.US).startsWith(theText))) {
// Is the value a macro variable?
if (theText.startsWith("&")) theText = theText.substring(1);
Interpreter interp = Interpreter.getInstance();
String s = interp!=null?interp.getStringVariable(theText):null;
if (s!=null) theText = s;
}
}
if (recorderOn)
recordOption(tf, theText);
Expand Down Expand Up @@ -824,10 +836,23 @@ public int getNextChoiceIndex() {
String oldItem = thisChoice.getSelectedItem();
int oldIndex = thisChoice.getSelectedIndex();
String item = Macro.getValue(macroOptions, label, oldItem);
if (item!=null && item.startsWith("&")) { // value is macro variable
item = item.substring(1);
Interpreter interp = Interpreter.getInstance();
String s = interp!=null?interp.getStringVariable(item):null;
if (s!=null) item = s;
}
thisChoice.select(item);
index = thisChoice.getSelectedIndex();
if (index==oldIndex && !item.equals(oldItem))
IJ.error(getTitle(), "\""+item+"\" is not a valid choice for \""+label+"\"");
if (index==oldIndex && !item.equals(oldItem)) {
// is value a macro variable?
Interpreter interp = Interpreter.getInstance();
String s = interp!=null?interp.getStringVariable(item):null;
if (s==null)
IJ.error(getTitle(), "\""+item+"\" is not a valid choice for \""+label+"\"");
else
item = s;
}
}
if (recorderOn)
recordOption(thisChoice, thisChoice.getSelectedItem());
Expand Down
26 changes: 26 additions & 0 deletions ij/gui/NonBlockingGenericDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ij.gui;
import ij.IJ;
import java.awt.event.ActionEvent;

/** This is an xtension of GenericDialog that is non-model.
* @author Johannes Schindelin
*/
public class NonBlockingGenericDialog extends GenericDialog {
public NonBlockingGenericDialog(String title) {
super(title, null);
setModal(false);
}

public synchronized void showDialog() {
super.showDialog();
try {
wait();
} catch (InterruptedException e) { }
}

public synchronized void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (wasOKed() || wasCanceled())
notify();
}
}
22 changes: 22 additions & 0 deletions ij/gui/TextRoi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,30 @@ public class TextRoi extends Roi {
private static int style = Font.PLAIN;
private static int size = 18;
private static Font font;
private Font instanceFont;
private static boolean antialiasedText = true;
private static boolean recordSetFont = true;
private double previousMag;
private boolean firstChar = true;
private boolean firstMouseUp = true;
private int cline = 0;

/** Creates a new TextRoi.*/
public TextRoi(int x, int y, String text) {
this(x, y, text, null, null);
font = null;
firstChar = false;
}

/** Creates a new TextRoi.*/
public TextRoi(int x, int y, String text, Font font, Color color) {
super(x, y, 1, 1);
theText[0] = text;
instanceFont = font;
instanceColor = color;
if (IJ.debugMode) IJ.log("TextRoi: "+theText[0]+" "+width+","+height);
}

public TextRoi(int x, int y, ImagePlus imp) {
super(x, y, imp);
ImageCanvas ic = imp.getCanvas();
Expand Down Expand Up @@ -76,6 +93,8 @@ else if (cline>0) {
}

Font getCurrentFont() {
if (instanceFont!=null)
return instanceFont;
double mag = ic.getMagnification();
if (font==null || mag!=previousMag) {
font = new Font(name, style, (int)(size*mag));
Expand Down Expand Up @@ -103,6 +122,7 @@ public void drawPixels(ImageProcessor ip) {

/** Draws the text on the screen, clipped to the ROI. */
public void draw(Graphics g) {
if (IJ.debugMode) IJ.log("draw: "+theText[0]+" "+width+","+height);
super.draw(g); // draw the rectangle
g.setColor(instanceColor!=null?instanceColor:ROIColor);
double mag = ic.getMagnification();
Expand Down Expand Up @@ -192,6 +212,7 @@ protected void handleMouseUp(int screenX, int screenY) {
/** Increases the size of the rectangle so it's large
enough to hold the text. */
void adjustSize() {
if (IJ.debugMode) IJ.log("adjustSize1: "+theText[0]+" "+width+","+height);
if (ic==null)
return;
double mag = ic.getMagnification();
Expand Down Expand Up @@ -225,6 +246,7 @@ void adjustSize() {
y = yMax-height;
updateClipRect();
imp.draw(clipX, clipY, clipWidth, clipHeight);
if (IJ.debugMode) IJ.log("adjustSize2: "+theText[0]+" "+width+","+height);
}

int stringWidth(String s, FontMetrics metrics, Graphics g) {
Expand Down
6 changes: 2 additions & 4 deletions ij/io/FileSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ public boolean saveAsPgm(String path) {
}

/** Save the image in PNG format using a save file dialog.
Returns false if the user selects cancel. Requires
java 1.4 or later. */
Returns false if the user selects cancel. */
public boolean saveAsPng() {
String path = getPath("PNG", ".png");
if (path==null)
Expand All @@ -308,8 +307,7 @@ public boolean saveAsPng() {
return saveAsPng(path);
}

/** Save the image in PNG format using the specified path.
Requires Java 1,4 or later. */
/** Save the image in PNG format using the specified path. */
public boolean saveAsPng(String path) {
IJ.runPlugIn(imp, "ij.plugin.PNG_Writer", path);
return true;
Expand Down
12 changes: 10 additions & 2 deletions ij/io/OpenDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ij.gui.*;
import ij.plugin.frame.Recorder;
import ij.util.Java2;
import ij.macro.Interpreter;
import java.awt.*;
import java.io.*;
import javax.swing.*;
Expand All @@ -18,7 +19,7 @@ public class OpenDialog {
private static String defaultDirectory;
private static Frame sharedFrame;
private String title;
static String lastDir, lastName;
private static String lastDir, lastName;


/** Displays a file open dialog with 'title' as
Expand All @@ -33,6 +34,13 @@ public OpenDialog(String title, String path) {
path = Macro.getValue(macroOptions, "path", path);
if ((path==null || path.equals("")) && title!=null && title.equals("Open As String"))
path = Macro.getValue(macroOptions, "OpenAsString", path);
if (path!=null && path.indexOf(".")==-1 && !((new File(path)).exists())) {
// Is 'path' a macro variable?
if (path.startsWith("&")) path=path.substring(1);
Interpreter interp = Interpreter.getInstance();
String path2 = interp!=null?interp.getStringVariable(path):null;
if (path2!=null) path = path2;
}
}
if (path==null || path.equals("")) {
if (Prefs.useJFileChooser)
Expand Down Expand Up @@ -180,7 +188,7 @@ public String getFileName() {
returned string always ends with the separator character ("/" or "\").*/
public static String getDefaultDirectory() {
if (defaultDirectory==null)
defaultDirectory = Prefs.getString(Prefs.DIR_IMAGE);
defaultDirectory = Prefs.getDefaultDirectory();
return defaultDirectory;
}

Expand Down
Loading

0 comments on commit 84103f3

Please sign in to comment.