Login  Register

Re: How to know if a file is supported by imageJ without preloading?

Posted by Rasband, Wayne (NIH/NIMH) [E] on Feb 08, 2010; 9:32pm
URL: http://imagej.273.s1.nabble.com/How-to-know-if-a-file-is-supported-by-imageJ-without-preloading-tp3689405p3689415.html

On Feb 8, 2010, at 9:37 AM, Juanjo Vega wrote:

> Hello everybody,
>
> I'm developing a new plugin and I need a way to know when
> a file is supported by imageJ.
>
> I'm implementing a browser with a preview and the idea is to know
> when a file is supported or not to show one or another icon. The main
> idea is to to use something like: "isASupportedFileType(): boolean",  
> so new file types will return "true" when a new plugin will be added.
>
> Right now I'm filtering items by their extension and that's not
> cool at all =P

You can use the getFileType() method in the Opener class to determine if a file is directly supported by ImageJ. It returns Opener.UNKNOWN if the file is not supported or if it  was not found. I am sure the Bio-Formats plugin has a similar method for determining if a particular file is supported. Here is a JavaScript example that shows how to use getFileType():

   od = new OpenDialog("Open", "");
   path = od.getDirectory()+od.getFileName();
   type = (new Opener()).getFileType(path);
   if (type==Opener.UNKNOWN)
     print(path+" is not in a supported format or it was not found");
   else
      print(path+" is a "+Opener.types[type]+" file");

It requires the 1.43p12 daily build, which makes the Opener.types String array public.

-wayne