private ImagePlus openImage(String directory, String name, String path) {
    Object o = tryOpen(directory, name, path);
    // if an image was returned, assume success
    if (o instanceof ImagePlus) return (ImagePlus) o;

    // try opening the file with LOCI Bio-Formats plugin - always check this last!
    // Do not call Bio-Formats if File>Import>Image Sequence is opening this file.
    if (o == null
        && (IJ.getVersion().compareTo("1.38j") < 0 || !IJ.redirectingErrorMessages())
        && (new File(path).exists())) {
      Object loci = IJ.runPlugIn("loci.plugins.LociImporter", path);
      if (loci != null) {
        // plugin exists and was launched
        try {
          // check whether plugin was successful
          Class c = loci.getClass();
          boolean success = c.getField("success").getBoolean(loci);
          boolean canceled = c.getField("canceled").getBoolean(loci);
          if (success || canceled) {
            width = IMAGE_OPENED;
            return null;
          }
        } catch (Exception exc) {
        }
      }
    }

    return null;
  } // openImage
Exemple #2
0
 /**
  * Opens and displays the specified tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text
  * file. Displays an error message if the file is not in a supported format.
  *
  * @see ij.IJ#open(String)
  * @see ij.IJ#openImage(String)
  */
 public void open(String path) {
   boolean isURL = path.indexOf("://") > 0;
   if (isURL && isText(path)) {
     openTextURL(path);
     return;
   }
   if (path.endsWith(".jar") || path.endsWith(".class")) {
     (new PluginInstaller()).install(path);
     return;
   }
   boolean fullPath =
       path.startsWith("/") || path.startsWith("\\") || path.indexOf(":\\") == 1 || isURL;
   if (!fullPath) {
     String defaultDir = OpenDialog.getDefaultDirectory();
     if (defaultDir != null) path = defaultDir + path;
     else path = (new File(path)).getAbsolutePath();
   }
   if (!silentMode) IJ.showStatus("Opening: " + path);
   long start = System.currentTimeMillis();
   ImagePlus imp = openImage(path);
   if (imp == null && isURL) return;
   if (imp != null) {
     WindowManager.checkForDuplicateName = true;
     if (isRGB48) openRGB48(imp);
     else imp.show(getLoadRate(start, imp));
   } else {
     switch (fileType) {
       case LUT:
         imp = (ImagePlus) IJ.runPlugIn("ij.plugin.LutLoader", path);
         if (imp.getWidth() != 0) imp.show();
         break;
       case ROI:
         IJ.runPlugIn("ij.plugin.RoiReader", path);
         break;
       case JAVA_OR_TEXT:
       case TEXT:
         if (IJ.altKeyDown()) { // open in TextWindow if alt key down
           new TextWindow(path, 400, 450);
           IJ.setKeyUp(KeyEvent.VK_ALT);
           break;
         }
         File file = new File(path);
         int maxSize = 250000;
         long size = file.length();
         if (size >= 28000) {
           String osName = System.getProperty("os.name");
           if (osName.equals("Windows 95")
               || osName.equals("Windows 98")
               || osName.equals("Windows Me")) maxSize = 60000;
         }
         if (size < maxSize) {
           Editor ed = (Editor) IJ.runPlugIn("ij.plugin.frame.Editor", "");
           if (ed != null) ed.open(getDir(path), getName(path));
         } else new TextWindow(path, 400, 450);
         break;
       case OJJ: // ObjectJ project
         IJ.runPlugIn("ObjectJ_", path);
         break;
       case TABLE: // ImageJ Results table
         openResultsTable(path);
         break;
       case RAW:
         IJ.runPlugIn("ij.plugin.Raw", path);
         break;
       case UNKNOWN:
         String msg =
             "File is not in a supported format, a reader\n"
                 + "plugin is not available, or it was not found.";
         if (path != null) {
           if (path.length() > 64) path = (new File(path)).getName();
           if (path.length() <= 64) {
             if (IJ.redirectingErrorMessages()) msg += " \n   " + path;
             else msg += " \n	 \n" + path;
           }
         }
         if (openUsingPlugins) msg += "\n \nNOTE: The \"OpenUsingPlugins\" option is set.";
         IJ.wait(IJ.isMacro() ? 500 : 100); // work around for OS X thread deadlock problem
         IJ.error("Opener", msg);
         error = true;
         break;
     }
   }
 }