Changeset 2365


Ignore:
Timestamp:
03/01/07 12:09:08 (13 years ago)
Author:
curtis
Message:

Load metadata from just the first file, rather than all constituent files.

Location:
trunk/loci/visbio/data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/data/Dataset.java

    r2327 r2365  
    9393  protected String format; 
    9494 
    95   /** Metadata associated with each source file. */ 
    96   protected Hashtable[] metadata; 
    97  
    98   /** OME node associated with each source file. */ 
    99   protected OMENode[] ome; 
     95  /** Metadata associated with the first source file. */ 
     96  protected Hashtable metadata; 
     97 
     98  /** OME node associated with the first source file. */ 
     99  protected OMENode ome; 
    100100 
    101101  /** Range component count for each image. */ 
     
    200200  public String getFileFormat() { return format; } 
    201201 
    202   /** Gets metadata associated with each source file. */ 
    203   public Hashtable[] getMetadata() { return metadata; } 
    204  
    205   /** Gets the OME node associated with each source file. */ 
    206   public OMENode[] getOMENodes() { return ome; } 
     202  /** Gets metadata associated with the first source file. */ 
     203  public Hashtable getMetadata() { return metadata; } 
     204 
     205  /** Gets the OME node associated with the first source file. */ 
     206  public OMENode getOMENode() { return ome; } 
    207207 
    208208  // -- ImageTransform API methods -- 
     
    463463    } 
    464464 
    465     metadata = new Hashtable[ids.length]; 
    466     ome = new OMENode[ids.length]; 
    467     int numTasks = ids.length + 4; 
     465    int numTasks = 5; 
    468466 
    469467    // make sure each file exists 
     
    566564    spatial = domain.getRealComponents(); 
    567565 
    568     // load metadata for each source file 
    569     for (int i=0; i<ids.length; i++) { 
    570       String fname = new File(ids[i]).getName(); 
    571       status(i + 3, numTasks, "Reading " + fname + " metadata"); 
    572       try { metadata[i] = readers[i].getMetadata(ids[i]); } 
    573       catch (IOException exc) { metadata[i] = null; } 
    574       catch (FormatException exc) { metadata[i] = null; } 
    575       if (metadata[i] == null) { 
    576         System.err.println("Could not read metadata from " + 
    577           fname + ". The file may be corrupt or invalid."); 
    578         return; 
    579       } 
    580       try { 
    581         MetadataStore ms = readers[i].getMetadataStore(ids[i]); 
    582         if (ms instanceof OMEXMLMetadataStore) { 
    583           ome[i] = (OMENode) ((OMEXMLMetadataStore) ms).getRoot(); 
    584         } 
    585       } 
    586       catch (IOException exc) { ome[i] = null; } 
    587       catch (FormatException exc) { ome[i] = null; } 
    588     } 
     566    // load metadata for the first source file 
     567    String fname = new File(ids[0]).getName(); 
     568    status(3, numTasks, "Reading " + fname + " metadata"); 
     569    try { metadata = readers[0].getMetadata(ids[0]); } 
     570    catch (IOException exc) { metadata = null; } 
     571    catch (FormatException exc) { metadata = null; } 
     572    if (metadata == null) { 
     573      System.err.println("Could not read metadata from " + 
     574        fname + ". The file may be corrupt or invalid."); 
     575      return; 
     576    } 
     577    try { 
     578      MetadataStore ms = readers[0].getMetadataStore(ids[0]); 
     579      if (ms instanceof OMEXMLMetadataStore) { 
     580        ome = (OMENode) ((OMEXMLMetadataStore) ms).getRoot(); 
     581      } 
     582    } 
     583    catch (IOException exc) { ome = null; } 
     584    catch (FormatException exc) { ome = null; } 
    589585 
    590586    // construct metadata controls 
    591     status(ids.length + 3, numTasks, "Finishing"); 
     587    status(4, numTasks, "Finishing"); 
    592588    controls = new DatasetWidget(this); 
    593589 
     
    597593    thumbs = new ThumbnailHandler(this, 
    598594      path + File.separator + name + ".visbio"); 
    599     status(ids.length + 4, numTasks, "Done"); 
     595    status(5, numTasks, "Done"); 
    600596  } 
    601597 
  • trunk/loci/visbio/data/DatasetWidget.java

    r1989 r2365  
    2525 
    2626import java.awt.BorderLayout; 
    27 import java.io.File; 
    2827import java.util.*; 
    2928import javax.swing.*; 
     
    3736 
    3837/** DatasetWidget is a set of GUI controls for a Dataset transform. */ 
    39 public class DatasetWidget extends JPanel 
    40   implements ListSelectionListener, TreeSelectionListener 
    41 { 
     38public class DatasetWidget extends JPanel implements TreeSelectionListener { 
    4239 
    4340  // -- Constants -- 
     
    5552 
    5653  /** Dataset's associated metadata in OME-XML format. */ 
    57   protected OMENode[] ome; 
     54  protected OMENode ome; 
    5855 
    5956  /** Dataset's associated metadata. */ 
    60   protected Hashtable[] metadata; 
    61  
    62   /** Metadata hashtables' sorted key lists. */ 
    63   protected String[][] keys; 
     57  protected Hashtable metadata; 
     58 
     59  /** Metadata hashtable's sorted key lists. */ 
     60  protected String[] keys; 
    6461 
    6562  /** List of dataset source files. */ 
     
    9289 
    9390    // get dataset's metadata 
    94     ome = dataset.getOMENodes(); 
     91    ome = dataset.getOMENode(); 
    9592    metadata = dataset.getMetadata(); 
    96     keys = new String[metadata.length][]; 
    9793 
    9894    // sort metadata keys 
    99     for (int i=0; i<metadata.length; i++) { 
    100       if (metadata[i] == null) { 
    101         keys[i] = new String[0]; 
    102         continue; 
    103       } 
    104       Enumeration e = metadata[i].keys(); 
     95    if (metadata == null) keys = new String[0]; 
     96    else { 
     97      Enumeration e = metadata.keys(); 
    10598      Vector v = new Vector(); 
    10699      while (e.hasMoreElements()) v.add(e.nextElement()); 
    107       keys[i] = new String[v.size()]; 
    108       v.copyInto(keys[i]); 
    109       Arrays.sort(keys[i]); 
    110     } 
    111  
    112     // list of filenames 
    113     String[] ids = dataset.getFilenames(); 
    114     String[] names = new String[ids.length]; 
    115     for (int i=0; i<names.length; i++) names[i] = new File(ids[i]).getName(); 
    116     list = new JList(names); 
    117     JScrollPane scrollList = new JScrollPane(list); 
    118     SwingUtil.configureScrollPane(scrollList); 
    119     list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
    120     list.addListSelectionListener(this); 
     100      keys = new String[v.size()]; 
     101      v.copyInto(keys); 
     102      Arrays.sort(keys); 
     103    } 
    121104 
    122105    // -- First tab -- 
     
    159142    tabbed.addTab("OME-XML", treeSplit); 
    160143 
    161     // split pane 
    162     JSplitPane mainSplit = 
    163       new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollList, tabbed); 
    164  
    165144    // lay out components 
    166145    setLayout(new BorderLayout()); 
    167     add(mainSplit); 
    168     list.setSelectedIndex(0); 
    169   } 
    170  
    171   // -- ListSelectionListener API methods -- 
    172  
    173   /** Called when the filename list selection changes. */ 
    174   public void valueChanged(ListSelectionEvent e) { 
    175     treeRoot.removeAllChildren(); 
    176  
    177     int ndx = list.getSelectedIndex(); 
    178     if (ndx < 0 || ndx >= keys.length) { 
    179       metaTableModel.setRowCount(0); 
    180       return; 
    181     } 
    182  
    183     // update metadata table 
    184     int len = keys[ndx].length; 
     146    add(tabbed); 
     147 
     148    // populate metadata table 
     149    int len = keys.length; 
    185150    metaTableModel.setRowCount(len); 
    186151    for (int i=0; i<len; i++) { 
    187       metaTableModel.setValueAt(keys[ndx][i], i, 0); 
    188       metaTableModel.setValueAt(metadata[ndx].get(keys[ndx][i]), i, 1); 
    189     } 
    190  
    191     // update OME-XML tree 
     152      metaTableModel.setValueAt(keys[i], i, 0); 
     153      metaTableModel.setValueAt(metadata.get(keys[i]), i, 1); 
     154    } 
     155 
     156    // populate OME-XML tree 
    192157    Document doc = null; 
    193     try { doc = ome[ndx] == null ? null : ome[ndx].getOMEDocument(false); } 
     158    try { doc = ome == null ? null : ome.getOMEDocument(false); } 
    194159    catch (Exception exc) { } 
    195160    if (doc != null) { 
Note: See TracChangeset for help on using the changeset viewer.