Changeset 3866


Ignore:
Timestamp:
04/02/08 12:36:25 (12 years ago)
Author:
curtis
Message:
  • Hook up format-specific checkboxes to reader logic.
  • Encapsulate reader-specific settings into Util.makeImageReader method.
  • Show "Loading..." message until list begins to populate.
Location:
trunk/loci/plugins
Files:
8 edited

Legend:

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

    r3859 r3866  
    5050public class Importer { 
    5151 
    52   // -- Constants -- 
    53  
    54   public static final String READER_ENABLED_PROPERTY = "bioformats.enabled"; 
    55  
    5652  // -- Fields -- 
    5753 
     
    10096    if (options.isLocal() || options.isHTTP()) { 
    10197      IJ.showStatus("Identifying " + idName); 
    102       ImageReader reader = makeImageReader(); 
     98      ImageReader reader = Util.makeImageReader(); 
    10399      try { r = reader.getReader(id); } 
    104100      catch (FormatException exc) { 
     
    594590  // -- Helper methods -- 
    595591 
    596   /** Creates an image reader from only the enabled reader types. */ 
    597   private ImageReader makeImageReader() { 
    598     Class[] c = null; 
    599     try { 
    600       ClassList defaultClasses = 
    601         new ClassList("readers.txt", IFormatReader.class); 
    602       c = defaultClasses.getClasses(); 
    603     } 
    604     catch (IOException exc) { 
    605       return new ImageReader(); 
    606     } 
    607     ClassList enabledClasses = new ClassList(IFormatReader.class); 
    608     for (int i=0; i<c.length; i++) { 
    609       String n = c[i].getName(); 
    610       String readerName = n.substring(n.lastIndexOf(".") + 1, n.length() - 6); 
    611       String key = READER_ENABLED_PROPERTY + "." + readerName; 
    612       boolean on = Prefs.get(key, true); 
    613       if (on) { 
    614         try { 
    615           enabledClasses.addClass(c[i]); 
    616         } 
    617         catch (FormatException exc) { 
    618           exc.printStackTrace(); 
    619         } 
    620       } 
    621     } 
    622     return new ImageReader(enabledClasses); 
    623   } 
    624  
    625592  /** 
    626593   * Displays the given image stack according to 
  • trunk/loci/plugins/ImporterOptions.java

    r3815 r3866  
    3838import javax.swing.ImageIcon; 
    3939import loci.formats.*; 
    40 import loci.formats.in.SDTReader; 
    4140 
    4241/** 
     
    284283    firstTime = Prefs.get(PREF_FIRST, true); 
    285284    forceThumbnails = Prefs.get(PREF_THUMBNAIL, false); 
    286  
    287     // set SDT intensity property, if available 
    288     String sdtIntensity = Prefs.get(SDTReader.INTENSITY_PROPERTY, null); 
    289     if (sdtIntensity != null) { 
    290       System.setProperty(SDTReader.INTENSITY_PROPERTY, sdtIntensity); 
    291     } 
    292285  } 
    293286 
  • trunk/loci/plugins/Util.java

    r3815 r3866  
    3535import loci.formats.*; 
    3636import loci.formats.codec.LuraWaveCodec; 
     37import loci.formats.in.*; 
    3738import loci.formats.meta.MetadataRetrieve; 
    3839 
     
    5253    "ImageJ 1.39l or later is required to merge >8 bit or >3 channel data"; 
    5354 
     55  public static final String PREF_READER_ENABLED = "bioformats.enabled"; 
     56  public static final String PREF_ND2_NIKON = "bioformats.nd2.nikon"; 
     57  public static final String PREF_PICT_QTJAVA = "bioformats.pict.qtjava"; 
     58  public static final String PREF_QT_QTJAVA = "bioformats.qt.qtjava"; 
     59  public static final String PREF_SDT_INTENSITY = "bioformats.sdt.intensity"; 
    5460 
    5561  // -- Constructor -- 
     
    467473  } 
    468474 
     475  /** 
     476   * Creates an image reader according to the current configuration settings, 
     477   * including which format readers are currently enabled, as well as 
     478   * format-specific configuration settings. 
     479   */ 
     480  public static ImageReader makeImageReader() { 
     481    // include only enabled classes 
     482    Class[] c = null; 
     483    try { 
     484      ClassList defaultClasses = 
     485        new ClassList("readers.txt", IFormatReader.class); 
     486      c = defaultClasses.getClasses(); 
     487    } 
     488    catch (IOException exc) { 
     489      return new ImageReader(); 
     490    } 
     491    ClassList enabledClasses = new ClassList(IFormatReader.class); 
     492    for (int i=0; i<c.length; i++) { 
     493      String n = c[i].getName(); 
     494      String readerName = n.substring(n.lastIndexOf(".") + 1, n.length() - 6); 
     495      String key = PREF_READER_ENABLED + "." + readerName; 
     496      boolean on = Prefs.get(key, true); 
     497      if (on) { 
     498        try { 
     499          enabledClasses.addClass(c[i]); 
     500        } 
     501        catch (FormatException exc) { 
     502          exc.printStackTrace(); 
     503        } 
     504      } 
     505    } 
     506    ImageReader reader = new ImageReader(enabledClasses); 
     507 
     508    // toggle reader-specific options 
     509    boolean nd2Nikon = Prefs.get(PREF_ND2_NIKON, false); 
     510    boolean pictQTJava = Prefs.get(PREF_PICT_QTJAVA, false); 
     511    boolean qtQTJava = Prefs.get(PREF_QT_QTJAVA, false); 
     512    boolean sdtIntensity = Prefs.get(PREF_SDT_INTENSITY, false); 
     513    IFormatReader[] r = reader.getReaders(); 
     514    for (int i=0; i<r.length; i++) { 
     515      if (r[i] instanceof ND2Reader) { 
     516        ND2Reader nd2 = (ND2Reader) r[i]; 
     517        //nd2.setLegacy(nd2); 
     518      } 
     519      else if (r[i] instanceof PictReader) { 
     520        PictReader pict = (PictReader) r[i]; 
     521        //pict.setLegacy(pictQTJava); 
     522      } 
     523      else if (r[i] instanceof QTReader) { 
     524        QTReader qt = (QTReader) r[i]; 
     525        qt.setLegacy(qtQTJava); 
     526      } 
     527      else if (r[i] instanceof SDTReader) { 
     528        SDTReader sdt = (SDTReader) r[i]; 
     529        sdt.setIntensity(sdtIntensity); 
     530      } 
     531    } 
     532 
     533    return reader; 
     534  } 
     535 
    469536} 
  • trunk/loci/plugins/config/ConfigWindow.java

    r3864 r3866  
    7474    // build UI 
    7575 
     76    final String loading = "Loading..."; 
     77 
    7678    JTabbedPane tabs = new JTabbedPane(); 
    7779    tabs.setBorder(new EmptyBorder(3, 3, 3, 3)); 
     
    8284 
    8385    formatsListModel = new DefaultListModel(); 
     86    formatsListModel.addElement(loading); 
    8487    formatsList = makeList(formatsListModel); 
    8588 
     
    9497 
    9598    libsListModel = new DefaultListModel(); 
     99    libsListModel.addElement(loading); 
    96100    libsList = makeList(libsListModel); 
    97101    JPanel libInfo = new JPanel(); 
     
    165169 
    166170  public void itemStateChanged(ItemEvent e) { 
    167     FormatEntry entry = (FormatEntry) formatsList.getSelectedValue(); 
     171    Object value = formatsList.getSelectedValue(); 
     172    if (!(value instanceof FormatEntry)) return; 
     173    FormatEntry entry = (FormatEntry) value; 
    168174    setReaderEnabled(entry, enabled.isSelected()); 
    169175  } 
     
    174180    Object src = e.getSource(); 
    175181    if (src == formatsList) { 
     182      Object value = formatsList.getSelectedValue(); 
     183      if (!(value instanceof FormatEntry)) return; 
    176184      FormatEntry entry = (FormatEntry) formatsList.getSelectedValue(); 
    177185      doFormatLayout(entry); 
    178186    } 
    179187    else if (src == libsList) { 
     188      Object value = libsList.getSelectedValue(); 
     189      if (!(value instanceof LibraryEntry)) return; 
    180190      LibraryEntry entry = (LibraryEntry) libsList.getSelectedValue(); 
    181191      type.setText(entry.type); 
     
    344354    SwingUtilities.invokeLater(new Runnable() { 
    345355      public void run() { 
     356        // remove "Loading..." message 
     357        if (listModel.size() == 1 && listModel.get(0) instanceof String) { 
     358          listModel.remove(0); 
     359        } 
    346360        // binary search for proper location 
    347361        int min = 0, max = listModel.size(); 
     
    435449    if (entry == null) return false; 
    436450    try { 
    437       Class importerClass = Class.forName("loci.plugins.Importer"); 
    438       Field field = importerClass.getField("READER_ENABLED_PROPERTY"); 
     451      Class importerClass = Class.forName("loci.plugins.Util"); 
     452      Field field = importerClass.getField("PREF_READER_ENABLED"); 
    439453      String key = field.get(null) + "." + entry.readerName; 
    440454      Class prefsClass = Class.forName("ij.Prefs"); 
     
    456470    if (entry == null) return; 
    457471    try { 
    458       Class importerClass = Class.forName("loci.plugins.Importer"); 
    459       Field field = importerClass.getField("READER_ENABLED_PROPERTY"); 
     472      Class importerClass = Class.forName("loci.plugins.Util"); 
     473      Field field = importerClass.getField("PREF_READER_ENABLED"); 
    460474      String key = field.get(null) + "." + entry.readerName; 
    461475      Class prefsClass = Class.forName("ij.Prefs"); 
  • trunk/loci/plugins/config/ND2Widgets.java

    r3856 r3866  
    2626package loci.plugins.config; 
    2727 
     28import ij.Prefs; 
    2829import java.awt.Component; 
    2930import java.awt.event.ItemEvent; 
    3031import java.awt.event.ItemListener; 
    3132import javax.swing.JCheckBox; 
     33import loci.plugins.Util; 
    3234 
    3335/** 
     
    5052 
    5153  public ND2Widgets() { 
    52     String legacyLabel = "Legacy"; 
     54    boolean nikon = Prefs.get(Util.PREF_ND2_NIKON, false); 
     55 
     56    String legacyLabel = "Nikon"; 
    5357    JCheckBox legacyBox = new JCheckBox( 
    5458      "Use Nikon's ND2 library instead of native ND2 support"); 
    5559    legacyBox.addItemListener(this); 
     60    legacyBox.setEnabled(false);//TEMP 
    5661 
    5762    labels = new String[] {legacyLabel}; 
     
    7277 
    7378  public void itemStateChanged(ItemEvent e) { 
    74     // TOOD - respond to checkbox toggle 
     79    JCheckBox box = (JCheckBox) e.getSource(); 
     80    Prefs.set(Util.PREF_ND2_NIKON, box.isSelected()); 
    7581  } 
    7682 
  • trunk/loci/plugins/config/PictWidgets.java

    r3856 r3866  
    2626package loci.plugins.config; 
    2727 
     28import ij.Prefs; 
    2829import java.awt.Component; 
    2930import java.awt.event.ItemEvent; 
    3031import java.awt.event.ItemListener; 
    3132import javax.swing.JCheckBox; 
     33import loci.plugins.Util; 
    3234 
    3335/** 
     
    5052 
    5153  public PictWidgets() { 
     54    boolean qtJava = Prefs.get(Util.PREF_PICT_QTJAVA, false); 
     55 
    5256    String legacyLabel = "Legacy"; 
    5357    JCheckBox legacyBox = new JCheckBox( 
    54       "Use QTJava instead of native PICT support"); 
     58      "Use QTJava instead of native PICT support", qtJava); 
    5559    legacyBox.addItemListener(this); 
     60    legacyBox.setEnabled(false);//TEMP 
    5661 
    5762    labels = new String[] {legacyLabel}; 
     
    7277 
    7378  public void itemStateChanged(ItemEvent e) { 
    74     // TOOD - respond to checkbox toggle 
     79    JCheckBox box = (JCheckBox) e.getSource(); 
     80    Prefs.set(Util.PREF_PICT_QTJAVA, box.isSelected()); 
    7581  } 
    7682 
  • trunk/loci/plugins/config/QTWidgets.java

    r3856 r3866  
    2626package loci.plugins.config; 
    2727 
     28import ij.Prefs; 
    2829import java.awt.Component; 
    2930import java.awt.event.ItemEvent; 
    3031import java.awt.event.ItemListener; 
    3132import javax.swing.JCheckBox; 
     33import loci.plugins.Util; 
    3234 
    3335/** 
     
    5052 
    5153  public QTWidgets() { 
     54    boolean qtJava = Prefs.get(Util.PREF_QT_QTJAVA, false); 
     55 
    5256    String legacyLabel = "Legacy"; 
    5357    JCheckBox legacyBox = new JCheckBox( 
    54       "Use QTJava instead of native QT support"); 
     58      "Use QTJava instead of native QT support", qtJava); 
    5559    legacyBox.addItemListener(this); 
    5660 
     
    7276 
    7377  public void itemStateChanged(ItemEvent e) { 
    74     // TOOD - respond to checkbox toggle 
     78    JCheckBox box = (JCheckBox) e.getSource(); 
     79    Prefs.set(Util.PREF_QT_QTJAVA, box.isSelected()); 
    7580  } 
    7681 
  • trunk/loci/plugins/config/SDTWidgets.java

    r3856 r3866  
    2626package loci.plugins.config; 
    2727 
     28import ij.Prefs; 
    2829import java.awt.Component; 
    2930import java.awt.event.ItemEvent; 
    3031import java.awt.event.ItemListener; 
    3132import javax.swing.JCheckBox; 
     33import loci.plugins.Util; 
    3234 
    3335/** 
     
    5052 
    5153  public SDTWidgets() { 
     54    boolean intensity = Prefs.get(Util.PREF_SDT_INTENSITY, false); 
     55 
    5256    String mergeLabel = "Merge"; 
    53     JCheckBox mergeBox = new JCheckBox("Merge lifetime bins to intensity"); 
     57    JCheckBox mergeBox = new JCheckBox( 
     58      "Combine lifetime bins to intensity", intensity); 
    5459    mergeBox.addItemListener(this); 
    5560 
     
    7176 
    7277  public void itemStateChanged(ItemEvent e) { 
    73     // TOOD - respond to checkbox toggle 
     78    JCheckBox box = (JCheckBox) e.getSource(); 
     79    Prefs.set(Util.PREF_SDT_INTENSITY, box.isSelected()); 
    7480  } 
    7581 
Note: See TracChangeset for help on using the changeset viewer.