Changeset 2722


Ignore:
Timestamp:
05/02/07 11:05:21 (13 years ago)
Author:
curtis
Message:

Generalize the way the library checking methods work.

Location:
trunk/loci/plugins
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/plugins/Exporter.java

    r2692 r2722  
    5959 
    6060  /** Executes the plugin. */ 
    61   public synchronized void run(ImageProcessor ip) { 
     61  public void run(ImageProcessor ip) { 
    6262    String outfile = null; 
    6363 
  • trunk/loci/plugins/LociExporter.java

    r2244 r2722  
    2929import ij.plugin.filter.PlugInFilter; 
    3030import ij.process.ImageProcessor; 
     31import java.util.HashSet; 
    3132 
    3233/** 
     
    4142  // -- Fields -- 
    4243 
    43   /** Flag indicating whether last operation was successful. */ 
    44   public boolean success = false; 
    45  
    46   /** Argument passed to setup(). */ 
     44  /** Argument passed to setup method. */ 
    4745  public String arg; 
    4846 
     
    5957 
    6058  /** Executes the plugin. */ 
    61   public synchronized void run(ImageProcessor ip) { 
    62     success = false; 
     59  public void run(ImageProcessor ip) { 
    6360    if (!Util.checkVersion()) return; 
    64     if (!Util.checkLibraries(true, true, false, false)) return; 
     61    HashSet missing = new HashSet(); 
     62    Util.checkLibrary(Util.BIO_FORMATS, missing); 
     63    Util.checkLibrary(Util.OME_JAVA_XML, missing); 
     64    if (!Util.checkMissing(missing)) return; 
    6565    if (exporter != null) exporter.run(ip); 
    6666  } 
  • trunk/loci/plugins/LociImporter.java

    r2178 r2722  
    2727 
    2828import ij.plugin.PlugIn; 
     29import java.util.HashSet; 
    2930 
    3031/** 
     
    4950 
    5051  /** Executes the plugin. */ 
    51   public synchronized void run(String arg) { 
     52  public void run(String arg) { 
    5253    canceled = false; 
    5354    success = false; 
    5455    if ("about".equals(arg)) About.about(); 
    55     else if (Util.checkVersion() && 
    56       Util.checkLibraries(true, true, false, false)) 
    57     { 
     56    else { 
     57      if (!Util.checkVersion()) return; 
     58      HashSet missing = new HashSet(); 
     59      Util.checkLibrary(Util.BIO_FORMATS, missing); 
     60      Util.checkLibrary(Util.OME_JAVA_XML, missing); 
     61      if (!Util.checkMissing(missing)) return; 
    5862      new Importer(this).run(arg); 
    5963    } 
  • trunk/loci/plugins/LociUploader.java

    r2688 r2722  
    3030import ij.gui.GenericDialog; 
    3131import ij.plugin.PlugIn; 
    32 import ij.process.*; 
     32import ij.process.ColorProcessor; 
    3333import ij.io.FileInfo; 
    34 import loci.formats.*; 
    35 import loci.formats.ome.*; 
     34import java.util.HashSet; 
     35import loci.formats.FormatTools; 
     36import loci.formats.ome.OMEXMLMetadataStore; 
     37import loci.formats.ome.OMEWriter; 
    3638 
    3739/** 
     
    5052  // -- PlugIn API methods -- 
    5153 
    52   public synchronized void run(String arg) { 
     54  public void run(String arg) { 
    5355    // check that we can safely execute the plugin 
    54  
    55     if (Util.checkVersion() && Util.checkLibraries(true, true, true, false)) { 
    56       promptForLogin(); 
    57       uploadStack(); 
    58     } 
    59     else { 
    60     } 
     56    if (!Util.checkVersion()) return; 
     57    HashSet missing = new HashSet(); 
     58    Util.checkLibrary(Util.BIO_FORMATS, missing); 
     59    Util.checkLibrary(Util.OME_JAVA_XML, missing); 
     60    Util.checkLibrary(Util.OME_JAVA_DS, missing); 
     61    if (!Util.checkMissing(missing)) return; 
     62 
     63    promptForLogin(); 
     64    uploadStack(); 
    6165  } 
    6266 
  • trunk/loci/plugins/OMEPlugin.java

    r2419 r2722  
    2727import ij.gui.GenericDialog; 
    2828import ij.plugin.PlugIn; 
    29 import ij.process.*; 
     29import ij.process.ImageProcessor; 
    3030import java.awt.TextField; 
    3131import java.util.*; 
     
    3333import loci.plugins.Util; 
    3434import org.openmicroscopy.ds.*; 
    35 import org.openmicroscopy.ds.dto.*; 
    36 import org.openmicroscopy.ds.st.*; 
    37 import org.openmicroscopy.is.*; 
     35import org.openmicroscopy.ds.dto.Image; 
     36import org.openmicroscopy.ds.dto.Project; 
     37import org.openmicroscopy.ds.st.Experimenter; 
     38import org.openmicroscopy.is.PixelsFactory; 
    3839 
    3940/** 
     
    8485  public void run(String arg) { 
    8586    if (!Util.checkVersion()) return; 
    86     if (!Util.checkLibraries(true, true, true, true)) return; 
     87    HashSet missing = new HashSet(); 
     88    Util.checkLibrary(Util.BIO_FORMATS, missing); 
     89    Util.checkLibrary(Util.OME_JAVA_XML, missing); 
     90    Util.checkLibrary(Util.OME_JAVA_DS, missing); 
     91    Util.checkLibrary(Util.FORMS, missing); 
     92    if (!Util.checkMissing(missing)) return; 
    8793    runPlugin(); 
    8894  } 
  • trunk/loci/plugins/Util.java

    r2178 r2722  
    3333public final class Util { 
    3434 
     35  // -- Constants -- 
     36 
     37  /** Identifier for checking the Bio-Formats library is present. */ 
     38  public static final int BIO_FORMATS = 1; 
     39 
     40  /** Identifier for checking the OME Java OME-XML library is present. */ 
     41  public static final int OME_JAVA_XML = 2; 
     42 
     43  /** Identifier for checking the OME Java OMEDS library is present. */ 
     44  public static final int OME_JAVA_DS = 3; 
     45 
     46  /** Identifier for checking the JGoodies Forms library is present. */ 
     47  public static final int FORMS = 4; 
     48 
     49  // -- Constructor -- 
     50 
    3551  private Util() { } 
     52 
     53  // -- Utility methods -- 
     54 
     55  /** Checks whether the given class is available. */ 
     56  public static boolean checkClass(String className) { 
     57    try { Class.forName(className); } 
     58    catch (Throwable t) { return false; } 
     59    return true; 
     60  } 
     61 
     62  /** 
     63   * Checks for a required library. 
     64   * @param library One of:<ul> 
     65   *   <li>BIO_FORMATS</li> 
     66   *   <li>OME_JAVA_XML</li> 
     67   *   <li>OME_JAVA_DS</li> 
     68   *   <li>FORMS</li> 
     69   *   </ul> 
     70   */ 
     71  public static void checkLibrary(int library, HashSet missing) { 
     72    switch (library) { 
     73      case BIO_FORMATS: 
     74        checkLibrary("loci.formats.FormatHandler", "bio-formats.jar", missing); 
     75        checkLibrary("org.apache.poi.poifs.filesystem.POIFSFileSystem", 
     76          "poi-loci.jar", missing); 
     77        break; 
     78      case OME_JAVA_XML: 
     79        checkLibrary("org.openmicroscopy.xml.OMENode", "ome-java.jar", missing); 
     80        break; 
     81      case OME_JAVA_DS: 
     82        checkLibrary("org.openmicroscopy.ds.DataServer", 
     83          "ome-java.jar", missing); 
     84        checkLibrary("org.apache.xmlrpc.XmlRpcClient", 
     85          "xmlrpc-1.2-b1.jar", missing); 
     86        checkLibrary("org.apache.commons.httpclient.HttpClient", 
     87          "commons-httpclient-2.0-rc2.jar", missing); 
     88        checkLibrary("org.apache.commons.logging.Log", 
     89          "commons-logging.jar", missing); 
     90        break; 
     91      case FORMS: 
     92        checkLibrary("com.jgoodies.forms.layout.FormLayout", 
     93          "forms-1.0.4.jar", missing); 
     94        break; 
     95    } 
     96  } 
     97 
     98  /** 
     99   * Checks whether the given class is available; if not, 
     100   * adds the specified JAR file name to the hash set 
     101   * (presumably to report it missing to the user). 
     102   */ 
     103  public static void checkLibrary(String className, 
     104    String jarFile, HashSet missing) 
     105  { 
     106    if (!checkClass(className)) missing.add(jarFile); 
     107  } 
    36108 
    37109  /** Checks for a new enough version of the Java Runtime Environment. */ 
     
    49121 
    50122  /** 
    51    * Checks for libraries required by the LOCI plugins. 
    52    * @return true if libraries are present, false if some are missing. 
     123   * Reports missing libraries in the given hash set to the user. 
     124   * @return true iff no libraries are missing (the hash set is empty). 
    53125   */ 
    54   public static boolean checkLibraries(boolean bioFormats, 
    55     boolean omeJavaXML, boolean omeJavaDS, boolean forms) 
    56   { 
    57     HashSet hs = new HashSet(); 
    58     if (bioFormats) { 
    59       checkLibrary("loci.formats.FormatHandler", "bio-formats.jar", hs); 
    60       checkLibrary("org.apache.poi.poifs.filesystem.POIFSFileSystem", 
    61         "poi-loci.jar", hs); 
    62     } 
    63     if (omeJavaXML) { 
    64       checkLibrary("org.openmicroscopy.xml.OMENode", "ome-java.jar", hs); 
    65     } 
    66     if (omeJavaDS) { 
    67       checkLibrary("org.openmicroscopy.ds.DataServer", "ome-java.jar", hs); 
    68       checkLibrary("org.apache.xmlrpc.XmlRpcClient", "xmlrpc-1.2-b1.jar", hs); 
    69       checkLibrary("org.apache.commons.httpclient.HttpClient", 
    70         "commons-httpclient-2.0-rc2.jar", hs); 
    71       checkLibrary("org.apache.commons.logging.Log", "commons-logging.jar", hs); 
    72     } 
    73     if (forms) { 
    74       checkLibrary("com.jgoodies.forms.layout.FormLayout", 
    75         "forms-1.0.4.jar", hs); 
    76     } 
    77     int missing = hs.size(); 
    78     if (missing > 0) { 
    79       StringBuffer sb = new StringBuffer(); 
    80       sb.append("The following librar"); 
    81       sb.append(missing == 1 ? "y was" : "ies were"); 
    82       sb.append(" not found:"); 
    83       Iterator iter = hs.iterator(); 
    84       for (int i=0; i<missing; i++) { 
    85         sb.append("\n    " + iter.next()); 
    86       } 
    87       String them = missing == 1 ? "it" : "them"; 
    88       sb.append("\nPlease download "); 
    89       sb.append(them); 
    90       sb.append(" from the LOCI website at"); 
    91       sb.append("\n    http://www.loci.wisc.edu/software/"); 
    92       sb.append("\nand place "); 
    93       sb.append(them); 
    94       sb.append(" in the ImageJ plugins folder."); 
    95       IJ.error("LOCI Plugins", sb.toString()); 
    96       return false; 
    97     } 
    98     return true; 
    99   } 
    100  
    101   /** Checks whether the given class is available. */ 
    102   public static boolean checkClass(String className) { 
    103     try { Class.forName(className); } 
    104     catch (Throwable t) { return false; } 
    105     return true; 
    106   } 
    107  
    108   private static void checkLibrary(String className, 
    109     String jarFile, HashSet hs) 
    110   { 
    111     if (!checkClass(className)) hs.add(jarFile); 
     126  public static boolean checkMissing(HashSet missing) { 
     127    int num = missing.size(); 
     128    if (num == 0) return true; 
     129    StringBuffer sb = new StringBuffer(); 
     130    sb.append("The following librar"); 
     131    sb.append(num == 1 ? "y was" : "ies were"); 
     132    sb.append(" not found:"); 
     133    Iterator iter = missing.iterator(); 
     134    for (int i=0; i<num; i++) sb.append("\n    " + iter.next()); 
     135    String them = num == 1 ? "it" : "them"; 
     136    sb.append("\nPlease download "); 
     137    sb.append(them); 
     138    sb.append(" from the LOCI website at"); 
     139    sb.append("\n    http://www.loci.wisc.edu/software/"); 
     140    sb.append("\nand place "); 
     141    sb.append(them); 
     142    sb.append(" in the ImageJ plugins folder."); 
     143    IJ.error("LOCI Plugins", sb.toString()); 
     144    return false; 
    112145  } 
    113146 
Note: See TracChangeset for help on using the changeset viewer.