Changeset 1786


Ignore:
Timestamp:
11/13/06 14:30:47 (13 years ago)
Author:
curtis
Message:

Add setIdMap and getIdMap methods to allow multiple format handlers to share
the same ID map hashtable -- useful for ImageReader, ImageWriter and
FileStitcher, that manage a number of handlers at once.

Location:
trunk/loci/formats
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/FileStitcher.java

    r1783 r1786  
    428428  /* @see IFormatHandler#mapId(String, String) */ 
    429429  public void mapId(String id, String filename) { 
    430     System.err.println("FileStitcher.mapId: unimplemented"); // CTR TODO 
     430    // NB: all readers share the same ID map 
     431    reader.mapId(id, filename); 
    431432  } 
    432433 
    433434  /* @see IFormatHandler#getMappedId(String) */ 
    434435  public String getMappedId(String id) { 
    435     System.err.println("FileStitcher.getMappedId: unimplemented"); // CTR TODO 
    436     return null; 
    437   } 
     436    return reader.getMappedId(id); 
     437  } 
     438 
     439  /* @see IFormatHandler#getIdMap() */ 
     440  public Hashtable getIdMap() { 
     441    return reader.getIdMap(); 
     442  } 
     443 
     444  /* @see IFormatHandler#setIdMap(Hashtable) */ 
     445  public void setIdMap(Hashtable map) { 
     446    for (int i=0; i<readers.length; i++) readers[i].setIdMap(map); 
     447  } 
     448 
    438449 
    439450  // -- Helper methods -- 
     
    480491    readers = new IFormatReader[files.length]; 
    481492    readers[0] = reader; 
     493    Hashtable map = reader.getIdMap(); 
    482494    for (int i=1; i<readers.length; i++) { 
    483495      // use crazy reflection to instantiate a reader of the proper type 
     
    493505        } 
    494506        readers[i] = (IFormatReader) r; 
     507        // NB: ensure all readers share the same ID map 
     508        readers[i].setIdMap(map); 
    495509      } 
    496510      catch (InstantiationException exc) { exc.printStackTrace(); } 
  • trunk/loci/formats/FormatHandler.java

    r1743 r1786  
    126126  } 
    127127 
     128  /* @see IFormatHandler#getIdMap() */ 
     129  public Hashtable getIdMap() { 
     130    return idMap; 
     131  } 
     132 
     133  /* @see IFormatHandler#setIdMap(Hashtable) */ 
     134  public void setIdMap(Hashtable map) { 
     135    idMap = map; 
     136  } 
     137 
    128138  // -- Utility methods -- 
    129139 
  • trunk/loci/formats/IFormatHandler.java

    r1674 r1786  
    2525package loci.formats; 
    2626 
     27import java.util.Hashtable; 
    2728import javax.swing.JFileChooser; 
    2829import javax.swing.filechooser.FileFilter; 
     
    7677  String getMappedId(String id); 
    7778 
     79  /** 
     80   * Gets a hashtable containing mappings from ids to actual filenames on disk. 
     81   * @see #mapId(String, String) 
     82   * @see #getMappedId(String) 
     83   */ 
     84  Hashtable getIdMap(); 
     85 
     86  /** 
     87   * Sets the mappings from ids to actual filenames on disk to match those 
     88   * given in the. 
     89   * @see #mapId(String, String) 
     90   * @see #getMappedId(String) 
     91   */ 
     92  void setIdMap(Hashtable map); 
     93 
    7894} 
  • trunk/loci/formats/ImageReader.java

    r1747 r1786  
    3030import java.io.IOException; 
    3131import java.io.InputStreamReader; 
    32 import java.util.Arrays; 
    33 import java.util.HashSet; 
    34 import java.util.Hashtable; 
    35 import java.util.Vector; 
     32import java.util.*; 
    3633import javax.swing.JFileChooser; 
    3734import javax.swing.filechooser.FileFilter; 
     
    126123    // add built-in readers to the list 
    127124    Vector v = new Vector(); 
     125    Hashtable map = null; 
    128126    for (int i=0; i<readerClasses.length; i++) { 
    129127      IFormatReader reader = null; 
    130       try { reader = (IFormatReader) readerClasses[i].newInstance(); } 
     128      try { 
     129        reader = (IFormatReader) readerClasses[i].newInstance(); 
     130        // NB: ensure all readers share the same ID map 
     131        if (i == 0) map = reader.getIdMap(); 
     132        else reader.setIdMap(map); 
     133      } 
    131134      catch (IllegalAccessException exc) { } 
    132135      catch (InstantiationException exc) { } 
     
    504507  /* @see IFormatHandler#mapId(String, String) */ 
    505508  public void mapId(String id, String filename) { 
    506     for (int i=0; i<readers.length; i++) { 
    507       readers[i].mapId(id, filename); 
    508     } 
     509    // NB: all readers share the same ID map 
     510    readers[0].mapId(id, filename); 
    509511  } 
    510512 
     
    512514  public String getMappedId(String id) { 
    513515    return readers[0].getMappedId(id); 
     516  } 
     517 
     518  /* @see IFormatHandler.getIdMap() */ 
     519  public Hashtable getIdMap() { 
     520    return readers[0].getIdMap(); 
     521  } 
     522 
     523  /* @see IFormatHandler.setIdMap(Hashtable) */ 
     524  public void setIdMap(Hashtable map) { 
     525    for (int i=0; i<readers.length; i++) readers[i].setIdMap(map); 
    514526  } 
    515527 
  • trunk/loci/formats/ImageWriter.java

    r1672 r1786  
    3030import java.io.IOException; 
    3131import java.io.InputStreamReader; 
    32 import java.util.Arrays; 
    33 import java.util.HashSet; 
    34 import java.util.Vector; 
     32import java.util.*; 
    3533import javax.swing.JFileChooser; 
    3634import javax.swing.filechooser.FileFilter; 
     
    125123    // add built-in writers to the list 
    126124    Vector v = new Vector(); 
     125    Hashtable map = null; 
    127126    for (int i=0; i<writerClasses.length; i++) { 
    128127      FormatWriter writer = null; 
    129       try { writer = (FormatWriter) writerClasses[i].newInstance(); } 
     128      try { 
     129        writer = (FormatWriter) writerClasses[i].newInstance(); 
     130        // NB: ensure all writers share the same ID map 
     131        if (i == 0) map = writer.getIdMap(); 
     132        else writer.setIdMap(map); 
     133      } 
    130134      catch (IllegalAccessException exc) { } 
    131135      catch (InstantiationException exc) { } 
     
    319323  /* @see IFormatHandler#mapId(String, String) */ 
    320324  public void mapId(String id, String filename) { 
    321     for (int i=0; i<writers.length; i++) { 
    322       writers[i].mapId(id, filename); 
    323     } 
     325    // NB: all writers share the same ID map 
     326    writers[0].mapId(id, filename); 
    324327  } 
    325328 
     
    329332  } 
    330333 
     334  /* @see IFormatHandler.getIdMap() */ 
     335  public Hashtable getIdMap() { 
     336    return writers[0].getIdMap(); 
     337  } 
     338 
     339  /* @see IFormatHandler.setIdMap(Hashtable) */ 
     340  public void setIdMap(Hashtable map) { 
     341    for (int i=0; i<writers.length; i++) writers[i].setIdMap(map); 
     342  } 
     343 
    331344  // -- Main method -- 
    332345 
  • trunk/loci/formats/ReaderWrapper.java

    r1747 r1786  
    276276  } 
    277277 
     278  public Hashtable getIdMap() { 
     279    return reader.getIdMap(); 
     280  } 
     281 
     282  public void setIdMap(Hashtable map) { 
     283    reader.setIdMap(map); 
     284  } 
     285 
    278286} 
Note: See TracChangeset for help on using the changeset viewer.