Changeset 6525


Ignore:
Timestamp:
06/11/10 10:49:14 (9 years ago)
Author:
melissa
Message:

Merged r6520 to 4.2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2/components/bio-formats/src/loci/formats/gui/ImageViewer.java

    r6516 r6525  
    5757import javax.swing.event.ChangeEvent; 
    5858import javax.swing.event.ChangeListener; 
     59import javax.xml.parsers.ParserConfigurationException; 
    5960 
    6061import loci.common.services.DependencyException; 
    61 import loci.common.services.OMENotesService; 
     62import loci.common.services.ServiceException; 
    6263import loci.common.services.ServiceFactory; 
    6364import loci.formats.ChannelMerger; 
     
    6970import loci.formats.IFormatWriter; 
    7071import loci.formats.ImageWriter; 
     72import loci.formats.meta.MetadataRetrieve; 
     73import loci.formats.meta.MetadataStore; 
    7174import loci.formats.services.OMEReaderWriterService; 
     75import loci.formats.services.OMEXMLService; 
    7276 
    7377import org.slf4j.Logger; 
    7478import org.slf4j.LoggerFactory; 
     79import org.xml.sax.SAXException; 
    7580 
    7681/** 
     
    104109  protected JSlider nSlider, zSlider, tSlider, cSlider; 
    105110  protected JLabel probeLabel; 
    106   protected JMenuItem fileSave; 
     111  protected JMenuItem fileView, fileSave; 
     112 
     113  /** Attached OME metadata store, if available. */ 
     114  protected MetadataStore omeMeta; 
    107115 
    108116  /** Current format reader. */ 
     
    115123  protected IFormatReader fileReader; 
    116124 
    117   /** Reader for OME servers. */ 
    118   protected IFormatReader omeReader; 
    119  
    120   /** Reader for OMERO servers. */ 
    121   protected IFormatReader omeroReader; 
    122  
    123125  /** Writer for files on disk. */ 
    124126  protected IFormatWriter fileWriter; 
    125  
    126   /** Writer for OME servers. */ 
    127   protected IFormatWriter omeWriter; 
    128  
    129   /** Writer for OMERO servers. */ 
    130   protected IFormatWriter omeroWriter; 
    131127 
    132128  protected String filename; 
     
    137133  protected boolean anim = false; 
    138134  protected int fps = 10; 
     135 
     136  // -- Fields - OME-XML -- 
     137 
     138  /** Service for working with OME-XML metadata. */ 
     139  protected OMEXMLService omexmlService; 
     140 
     141  // -- Fields - OME I/O -- 
     142 
     143  /** Reader for OME servers. */ 
     144  protected IFormatReader omeReader; 
     145 
     146  /** Reader for OMERO servers. */ 
     147  protected IFormatReader omeroReader; 
     148 
     149  /** Writer for OME servers. */ 
     150  protected IFormatWriter omeWriter; 
     151 
     152  /** Writer for OMERO servers. */ 
     153  protected IFormatWriter omeroWriter; 
    139154 
    140155  // -- Constructor -- 
     
    151166    myWriter = new BufferedImageWriter(fileWriter); 
    152167 
    153     // NB: avoid dependencies on optional loci.ome.io package 
    154168    try { 
     169      // NB: avoid dependencies on optional ome.xml package 
    155170      ServiceFactory factory = new ServiceFactory(); 
    156       OMEReaderWriterService service = 
     171      omexmlService = factory.getInstance(OMEXMLService.class); 
     172    } 
     173    catch (DependencyException exc) { 
     174      LOGGER.debug("OME-XML service unavailable", exc); 
     175    } 
     176    try { 
     177      // NB: avoid dependencies on optional loci.ome.io package 
     178      ServiceFactory factory = new ServiceFactory(); 
     179      OMEReaderWriterService omeIOService = 
    157180        factory.getInstance(OMEReaderWriterService.class); 
    158181      // OME server I/O engine 
    159182      try { 
    160         omeReader = service.newOMEReader(); 
     183        omeReader = omeIOService.newOMEReader(); 
    161184      } 
    162185      catch (Exception exc) { 
     
    164187      } 
    165188      try { 
    166         omeWriter = service.newOMEWriter(); 
     189        omeWriter = omeIOService.newOMEWriter(); 
    167190      } 
    168191      catch (Exception exc) { 
     
    172195      // OMERO server I/O engine 
    173196      try { 
    174         omeroReader = service.newOMEROReader(); 
     197        omeroReader = omeIOService.newOMEROReader(); 
    175198      } 
    176199      catch (Exception exc) { 
     
    178201      } 
    179202      try { 
    180         omeroWriter = service.newOMEROWriter(); 
     203        omeroWriter = omeIOService.newOMEROWriter(); 
    181204      } 
    182205      catch (Exception exc) { 
     
    185208    } 
    186209    catch (DependencyException e) { 
    187       LOGGER.debug("OME and OMERO reader/writer service unavailble", e); 
     210      LOGGER.debug("OME and OMERO reader/writer service unavailable", e); 
    188211    } 
    189212 
     
    278301    fileSave.addActionListener(this); 
    279302    file.add(fileSave); 
    280     boolean canDoNotes = false; 
    281     try { 
    282       Class c = Class.forName("loci.ome.notes.Notes"); 
    283       if (c != null) canDoNotes = true; 
    284     } 
    285     catch (Throwable t) { 
    286       LOGGER.debug("Could not find OME Notes", t); 
    287     } 
    288     if (canDoNotes) { 
    289       JMenuItem fileView = new JMenuItem("View Metadata..."); 
     303    if (omexmlService != null) { 
     304      fileView = new JMenuItem("View Metadata..."); 
    290305      fileView.setMnemonic('m'); 
    291306      fileView.setEnabled(true); 
     
    347362      //Location f = new Location(id); 
    348363      //id = f.getAbsolutePath(); 
     364      try { 
     365        myReader.setMetadataStore(omexmlService.createOMEXMLMetadata()); 
     366      } 
     367      catch (ServiceException exc) { 
     368        LOGGER.info("OME metadata unavailable", exc); 
     369      } 
    349370      myReader.setId(id); 
    350371      int num = myReader.getImageCount(); 
     
    429450      sizeT = reader.getSizeT(); 
    430451      sizeC = reader.getEffectiveSizeC(); 
    431     } 
     452      omeMeta = reader.getMetadataStore(); 
     453      if (omexmlService == null || !omexmlService.isOMEXMLMetadata(omeMeta)) { 
     454        omeMeta = null; 
     455      } 
     456    } 
     457    fileView.setEnabled(omeMeta != null); 
    432458 
    433459    fileSave.setEnabled(true); 
     
    525551    } 
    526552    else if ("view".equals(cmd)) { 
    527       // NB: avoid dependency on optional loci.ome.notes package 
    528       OMENotesService service = null; 
    529       try { 
    530         ServiceFactory factory = new ServiceFactory(); 
    531         service = factory.getInstance(OMENotesService.class); 
    532         service.newNotes(filename); 
    533       } 
    534       catch (DependencyException de) { 
    535         LOGGER.info("", de); 
     553      if (omeMeta != null) { 
     554        XMLWindow metaWindow = new XMLWindow("OME Metadata - " + getTitle()); 
     555        metaWindow.setDefaultCloseOperation(XMLWindow.DISPOSE_ON_CLOSE); 
     556        Exception exception = null; 
     557        try { 
     558          MetadataRetrieve retrieve = omexmlService.asRetrieve(omeMeta); 
     559          metaWindow.setXML(omexmlService.getOMEXML(retrieve)); 
     560          metaWindow.setVisible(true); 
     561        } 
     562        catch (ServiceException exc) { exception = exc; } 
     563        catch (ParserConfigurationException exc) { exception = exc; } 
     564        catch (SAXException exc) { exception = exc; } 
     565        catch (IOException exc) { exception = exc; } 
     566        if (exception != null) { 
     567          LOGGER.info("Cannot display OME metadata", exception); 
     568        } 
    536569      } 
    537570    } 
Note: See TracChangeset for help on using the changeset viewer.