Skip to content

Commit

Permalink
2022.12.02 (1.54a3; GenericDialog.addEnumChoice)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Dec 2, 2022
1 parent 72c46b1 commit e6c6c80
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public class ImageJ extends Frame implements ActionListener,
MouseListener, KeyListener, WindowListener, ItemListener, Runnable {

/** 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 = ""; //19
public static final String VERSION = "1.54a";
public static final String BUILD = "3";
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
65 changes: 63 additions & 2 deletions ij/gui/GenericDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,30 @@ public ImagePlus getNextImage() {
/**
* Adds a group of choices to the dialog with menu items taken from the
* <code>enum</code> class of the specified default item (enum constant).
* The default item is automatically set. Calls the original (string-based)
* Calls the original (string-based)
* {@link GenericDialog#addChoice(String, String[], String)} method.
* Usage example:
* <pre>
* import ij.process.AutoThresholder.Method;
* ...
* Method method = Method.Otsu;
*
* GenericDialog gd = new GenericDialog("Select AutoThresholder Method");
* gd.addEnumChoice("All threshold methods", method);
* ...
* gd.showDialog();
* ...
* method = gd.getNextEnumChoice(Method.class);
* </pre>
*
* @param <E> the generic enum type containing the items to chose from
* @param label the label displayed for this choice group
* @param defaultItem the menu item initially selected
*
* @see #addEnumChoice(String, Enum[], Enum)
* @see #getNextEnumChoice(Class)
*/
public <E extends Enum<E>> void addEnumChoice(String label, Enum<E> defaultItem) {
public <E extends Enum<E>> void addEnumChoice(String label, E defaultItem) {
Class<E> enumClass = defaultItem.getDeclaringClass();
E[] enums = enumClass.getEnumConstants();
String[] items = new String[enums.length];
Expand All @@ -447,6 +463,51 @@ public <E extends Enum<E>> void addEnumChoice(String label, Enum<E> defaultItem)
this.addChoice(label, items, defaultItem.name());
}

/**
* Adds a group of choices to the dialog with menu items taken from the supplied
* array of <code>enum</code> elements. This allows to present only a subset of
* enum choices in a specified order. A default item (enum constant) must be
* specified which, if {@code null} of not contained in the enum array, is
* replaced by the first element of the enum array. Calls the original
* (string-based) {@link GenericDialog#addChoice(String, String[], String)}
* method. Usage example:
* <pre>
* import ij.process.AutoThresholder.Method;
* ...
* Method[] selectMethods = {Method.Triangle, Method.Otsu, Method.Huang};
* Method method = Method.Otsu;
*
* GenericDialog gd = new GenericDialog("Select AutoThresholder Method");
* gd.addEnumChoice("Select threshold methods", selectMethods, method);
* ...
* gd.showDialog();
* ...
* method = gd.getNextEnumChoice(Method.class);
* </pre>
*
* @param <E> the generic enum type containing the items to choose from
* @param label the label displayed for this choice group
* @param enumArray an array of enum items (of type E)
* @param defaultItem the menu item initially selected (of type E, may be {@code null})
*
* @see #addEnumChoice(String, Enum)
* @see #getNextEnumChoice(Class)
*/
public <E extends Enum<E>> void addEnumChoice(String label, E[] enumArray, E defaultItem) {
String[] items = new String[enumArray.length];
boolean contained = false; // to check if defaultItem is contained in enumArray
for (int i = 0; i < enumArray.length; i++) {
if (enumArray[i] == defaultItem) {
contained = true;
}
items[i] = enumArray[i].name();
}
if (!contained) {
defaultItem = enumArray[0];
}
this.addChoice(label, items, defaultItem.name());
}

/**
* Returns the selected item in the next enum choice menu.
* Note that 'enumClass' is required to infer the proper enum type.
Expand Down
18 changes: 18 additions & 0 deletions ij/plugin/AVI_Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ public static ImagePlus openVirtual(String path) {
return open(path, true);
}

/** Opens an AVI file, where 'options' can contain
* 'virtual' (open as virtual stack),
* 'convert' (convert color images to grayscale) or
* 'flip' (flip vertically).
* The ImagePlus is not displayed.
*/
public static ImagePlus open(String path, String options) {
AVI_Reader reader = new AVI_Reader();
boolean virtual = options.contains("virtual");
boolean convertToGray = options.contains("convert");
boolean flipVertical = options.contains("flip");
ImageStack stack = reader.makeStack (path, 1, 0, virtual, convertToGray, flipVertical);
if (stack!=null)
return new ImagePlus((new File(path)).getName(), stack);
else
return null;
}

/** Opens an AVI file as a stack in memory or a virtual stack. The ImagePlus is not displayed. */
public static ImagePlus open(String path, boolean virtual) {
AVI_Reader reader = new AVI_Reader();
Expand Down
1 change: 1 addition & 0 deletions ij/plugin/Zoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ void setZoom(ImagePlus imp, double mag, int x, int y) {
}

private void scaleToFit(ImagePlus imp) {
waitUntilActivated(imp);
ImageCanvas ic = imp.getCanvas();
if (ic==null)
return;
Expand Down
2 changes: 1 addition & 1 deletion ij/plugin/filter/Rotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/** This plugin implements the Image/Rotate/Arbitrarily command. */
public class Rotator implements ExtendedPlugInFilter, DialogListener {
public static final String GRID = "|GRID|";
private int flags = DOES_ALL|SUPPORTS_MASKING|PARALLELIZE_STACKS;
private int flags = DOES_ALL|SUPPORTS_MASKING;
private static double angle = 15.0;
private static boolean fillWithBackground;
private static boolean enlarge;
Expand Down
12 changes: 12 additions & 0 deletions release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
</head>
<body>

<li> <u>1.54a3 02 December 2022</u>
<ul>
<li> Thanks to Christian Tischer, added the
AVI_Reader.open(path,options) method.
<li> Thanks to Wilhelm Burger, added a GenericDialog.addEnumChoice()
for reducing choices.
<li> Thanks to Andrew McCall, fixed a bug that caused the
<i>Image&gt;Transform&gt;Rotate</i> command to fail when rotating
very large stacks. Processing is now slower because
multi-threading is no longer used.
</ul>

<li> <u>1.53v 21 November 2022</u>
<ul>
<li> Thanks to Andrey Kazak, added the String.setFontSize() macro function.
Expand Down

0 comments on commit e6c6c80

Please sign in to comment.