Can someone tell me if there is a java routine that will detect which version of ImageJ is
being run? I would like to incorporate this into a plugin. Thanks, Andy |
Use the IJ.getVersion() method to get the ImageJ version as a string
(e.g., "1.30f") or add a line like this if (IJ.versionLessThan("1.39f")) return; which will abort the plugin and displays an error message if the version is not 1.39f or later. In a macro, use the getVersion() and requires("1.39j") functions. -wayne On Oct 6, 2007, at 2:15 PM, Andy Puckett wrote: > Can someone tell me if there is a java routine that will detect > which version of ImageJ is being run? I would like to > incorporate this into a plugin. > > Thanks, > Andy |
In reply to this post by Andy Puckett
I would also accept a routine that tells me whether a certain class is defined or not.
Specifically, this concerns the change as of ImageJ 1.38f from FITS to FITS_Reader/FITS_Writer. Thanks, Andy ----- Original Message ----- From: Andy Puckett <[hidden email]> Date: Saturday, October 6, 2007 10:15 am Subject: Version Detection? > Can someone tell me if there is a java routine that will detect > which version of ImageJ is > being run? I would like to > incorporate this into a plugin. > > Thanks, > Andy > |
If you're interested in dynamically determining if a class or method
is available, check out the introspection features of Java. This page has a brief overview: http://www.cs.grinnell.edu/~rebelsky/Courses/ CS223/2004F/Handouts/introspection.html. Also, checkout the "Class" class in Javadocs and this tutorial: http://java.sun.com/docs/books/ tutorial/reflect/class/index.html. To my knowledge there is no way to determine that a class exists in Java without throwing an exception with the Class.forName ("ij.plugin.FITS_Reader") method (unless you'd like to write your own ClassLoader). It's not ideal, but in the exception handler you can redirect the control flow such that you can attempt to create a new instance of the FITS class. The simplest and cleanest solution would be to just require at least version 1.38f and use Rasband's suggestion to abort the plugin if that requirement is not satisfied. Best regards, John On Oct 6, 2007, at 4:16 PM, Andy Puckett wrote: > I would also accept a routine that tells me whether a certain class > is defined or not. > Specifically, this concerns > the change as of ImageJ 1.38f from FITS to FITS_Reader/FITS_Writer. > > Thanks, > Andy > > ----- Original Message ----- > From: Andy Puckett <[hidden email]> > Date: Saturday, October 6, 2007 10:15 am > Subject: Version Detection? > >> Can someone tell me if there is a java routine that will detect >> which version of ImageJ is >> being run? I would like to >> incorporate this into a plugin. >> >> Thanks, >> Andy >> -- John A. Hayes, Ph.D. Department of Applied Science The College of William & Mary |
In reply to this post by Andy Puckett
Use the Class.ForName() method to determine if a given class exits.
This method boolean exits(String className) { try { Class c = Class.forName(className); return true; } catch (ClassNotFoundException e) {} return false; } returns true if the specified class exists. For example, I get FITS: false FITS_Reader: true LSM_Reader: true in the Log window when I run this code IJ.log("FITS: "+ exits("ij.plugin.FITS")); IJ.log("FITS_Reader: "+ exits("ij.plugin.FITS_Reader")); IJ.log("LSM_Reader: "+ exits("LSM_Reader")); -wayne On Oct 6, 2007, at 4:16 PM, Andy Puckett wrote: > I would also accept a routine that tells me whether a certain class > is defined or not. > Specifically, this concerns > the change as of ImageJ 1.38f from FITS to FITS_Reader/FITS_Writer. > > Thanks, > Andy > > ----- Original Message ----- > From: Andy Puckett <[hidden email]> > Date: Saturday, October 6, 2007 10:15 am > Subject: Version Detection? > >> Can someone tell me if there is a java routine that will detect >> which version of ImageJ is >> being run? I would like to >> incorporate this into a plugin. >> >> Thanks, >> Andy >> |
In reply to this post by Andy Puckett
Ok, I find this really annoying. I'm running the following code:
String ijvers = IJ.getVersion(); if (ijvers.compareTo("1.38f") < 0) { IJ.log("ImageJ: older"); if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS)) { IJ.error( "Must select a Nova compatible FITS image." ); return; } } else { IJ.log("ImageJ: newer"); if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS_Reader)) { IJ.error( "Must select a Nova compatible FITS image." ); return; } } Now, even though I'm running ImageJ 1.38x and the code correctly responds with "ImageJ: newer" in the log file (so the ELSE clause is being used), I still get this error message: /Applications/ImageJ/plugins/Nova20071008/Nova_Plugin_.java:54: Class ij.plugin.FITS not found. if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS)) { So, Java will still examine (and reject) the code of the THEN clause, even though I've told it to use the ELSE clause for versions of ImageJ that don't have the FITS class??? That's idiotic. Ok, bitching aside... any suggestions? Thanks, Andy |
Hi Andy,
My experience is that any direct class references you make in a Java application, sometimes even in branches of code that aren't actually executed, will result in the class loader trying to load that class. Instead of: imp instanceof ij.plugin.FITS you could try: imp.getClass().getName().equals("ij.plugin.FITS") There is a difference in behavior regarding subclasses, but in your case that shouldn't be an issue. -Curtis On 10/8/07, Andy Puckett <[hidden email]> wrote: > Ok, I find this really annoying. I'm running the following code: > > String ijvers = IJ.getVersion(); > > if (ijvers.compareTo("1.38f") < 0) { > IJ.log("ImageJ: older"); > if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS)) { > IJ.error( "Must select a Nova compatible FITS image." ); > return; > } > } else { > IJ.log("ImageJ: newer"); > if (imp.getStackSize() < 2 && !(imp instanceof > ij.plugin.FITS_Reader)) { > IJ.error( "Must select a Nova compatible FITS image." ); > return; > } > } > > Now, even though I'm running ImageJ 1.38x and the code correctly > responds with "ImageJ: newer" in the log file (so the ELSE clause is > being used), I still get this error message: > > /Applications/ImageJ/plugins/Nova20071008/Nova_Plugin_.java:54: > Class ij.plugin.FITS not found. > if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS)) { > > So, Java will still examine (and reject) the code of the THEN clause, > even though I've told it to use the ELSE clause for versions of > ImageJ that don't have the FITS class??? That's idiotic. > > Ok, bitching aside... any suggestions? > > Thanks, > Andy > |
In reply to this post by Andy Puckett
You can modify Nova_Plugin so it does not reference the FITS or
FITS_Reader classes. Use imp = IJ.openImage(path); to open the image and String info = (String)imp.getProperty("Info"); boolean isFITS = info!=null && info.startsWith("SIMPLE"); to test to see if it is a FITS image. -wayne On Oct 8, 2007, at 3:12 PM, Andy Puckett wrote: > Ok, I find this really annoying. I'm running the following code: > > String ijvers = IJ.getVersion(); > > if (ijvers.compareTo("1.38f") < 0) { > IJ.log("ImageJ: older"); > if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS)) { > IJ.error( "Must select a Nova compatible FITS image." ); > return; > } > } else { > IJ.log("ImageJ: newer"); > if (imp.getStackSize() < 2 && !(imp instanceof > ij.plugin.FITS_Reader)) { > IJ.error( "Must select a Nova compatible FITS image." ); > return; > } > } > > Now, even though I'm running ImageJ 1.38x and the code correctly > responds with "ImageJ: newer" in the log file (so the ELSE clause > is being used), I still get this error message: > > /Applications/ImageJ/plugins/Nova20071008/Nova_Plugin_.java:54: > Class ij.plugin.FITS not found. > if (imp.getStackSize() < 2 && !(imp instanceof ij.plugin.FITS)) { > > So, Java will still examine (and reject) the code of the THEN > clause, even though I've told it to use the ELSE clause for > versions of ImageJ that don't have the FITS class??? That's idiotic. > > Ok, bitching aside... any suggestions? > > Thanks, > Andy |
Free forum by Nabble | Edit this page |