Changeset 2247


Ignore:
Timestamp:
02/08/07 17:07:55 (13 years ago)
Author:
chris
Message:

Notebook:
Capable now of saving wierd formats (if they're openable
by ImageReader) to TIFF format with associated metadata.

Location:
trunk/loci/ome/notebook
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/ome/notebook/Merger.java

    r2243 r2247  
    4141     
    4242  /** Different mode constants.*/ 
    43   public static final int ALL_ORIGINAL = 0x01; // 0001 
    44   public static final int ALL_COMPANION = 0x02; // 0010 
    45   public static final int ORIGINAL_OVER = 0x04; // 0100 
    46   public static final int COMPANION_OVER = 0x08; // 1000 
     43  public static final int ALL_ORIGINAL = 0x01; 
     44  public static final int ALL_COMPANION = 0x02; 
     45  public static final int ORIGINAL_OVER = 0x04; 
     46  public static final int COMPANION_OVER = 0x08; 
    4747 
    4848  // --Members-- 
  • trunk/loci/ome/notebook/MetadataNotebook.java

    r2213 r2247  
    190190    fileOpen.setMnemonic('o'); 
    191191    fileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, MENU_MASK)); 
    192     JMenuItem fileSave = new JMenuItem("Save to orignal"); 
    193     file.add(fileSave); 
     192    JSeparator jSep = new JSeparator(); 
     193    file.add(jSep); 
     194    JMenu subFile = new JMenu("Save..."); 
     195    JMenuItem fileSave = new JMenuItem("Save to original"); 
     196    subFile.add(fileSave); 
    194197    fileSave.setActionCommand("save"); 
    195198    fileSave.addActionListener(this); 
     
    198201    fileSave.setEnabled(addSave); 
    199202    JMenuItem fileSaveComp = new JMenuItem("Save as companion"); 
    200     file.add(fileSaveComp); 
     203    subFile.add(fileSaveComp); 
    201204    fileSaveComp.setActionCommand("saveComp"); 
    202205    fileSaveComp.addActionListener(this); 
     
    204207    fileSaveComp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, MENU_MASK)); 
    205208    fileSaveComp.setEnabled(addSave); 
     209    JMenuItem fileSaveTiff = new JMenuItem("Save as TIFF Format"); 
     210    subFile.add(fileSaveTiff); 
     211    fileSaveTiff.setActionCommand("saveTiff"); 
     212    fileSaveTiff.addActionListener(this); 
     213    fileSaveTiff.setMnemonic('t'); 
     214    fileSaveTiff.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, MENU_MASK)); 
     215    fileSaveTiff.setEnabled(addSave); 
     216    file.add(subFile); 
    206217    JMenuItem fileSaveAs = new JMenuItem("Save As..."); 
    207218    file.add(fileSaveAs); 
     
    212223      KeyEvent.CTRL_MASK|KeyEvent.SHIFT_MASK)); 
    213224    fileSaveAs.setEnabled(addSave); 
    214     JSeparator jSep = new JSeparator(); 
     225    jSep = new JSeparator(); 
    215226    file.add(jSep); 
    216227    JMenuItem fileExit = new JMenuItem("Exit"); 
     
    271282    exportItem.setMnemonic('x'); 
    272283    exportItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, MENU_MASK)); 
     284    JMenuItem mergeItem = new JMenuItem("Merge Companion File"); 
     285    mergeItem.setSelected(false); 
     286    toolsMenu.add(mergeItem); 
     287    mergeItem.addActionListener(this); 
     288    mergeItem.setActionCommand("merge"); 
     289    mergeItem.setMnemonic('m'); 
     290    mergeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, MENU_MASK)); 
     291     
    273292 
    274293    JMenu options = new JMenu("Options"); 
     
    328347  public void saveCompanionFile(File file) { 
    329348    metadata.saveCompanionFile(file); 
     349  } 
     350   
     351  public void saveTiffFile(File file) { 
     352    metadata.saveTiffFile(file); 
    330353  } 
    331354 
     
    436459      metadata.stateChanged(false); 
    437460    } 
     461    else if ("saveTiff".equals(cmd) && currentFile != null) { 
     462      saveTiffFile(currentFile); 
     463      metadata.stateChanged(false); 
     464    } 
    438465    else if ("exit".equals(cmd)) { 
    439466          if (metadata.getState()) { 
  • trunk/loci/ome/notebook/MetadataPane.java

    r2213 r2247  
    3737import javax.swing.table.*; 
    3838import loci.formats.*; 
     39import loci.formats.out.TiffWriter; 
    3940import org.openmicroscopy.xml.*; 
    4041import org.w3c.dom.*; 
     
    133134  /** Holds the first image of a tiff file.*/ 
    134135  public BufferedImage img, thumb; 
     136   
     137  /** Holds the ImageReader used to open image or null if none used.*/ 
     138  protected ImageReader reader; 
    135139 
    136140  // -- Fields - raw panel -- 
     
    189193    thumb = null; 
    190194    showIDs = false; 
     195    reader = null; 
    191196 
    192197    // -- Tabbed Pane Initialization -- 
     
    320325    try { 
    321326      thisOmeNode.writeOME(compFile, false); 
     327      stateChanged(false); 
    322328    } 
    323329    catch (Exception exc) { 
    324330      if(exc instanceof RuntimeException) throw (RuntimeException)exc; 
    325331      else exc.printStackTrace(); 
     332    } 
     333  } 
     334   
     335  public void saveTiffFile(File file) throws RuntimeException{ 
     336    if(originalTIFF != null) saveFile(file); 
     337    else { 
     338      String id = currentFile.getPath(); 
     339      String outId = id + ".tif"; 
     340      if(reader == null) reader = new ImageReader(); 
     341      TiffWriter writer = new TiffWriter(); 
     342 
     343      int imageCount = 0; 
     344      String xml = null; 
     345 
     346      try {       
     347        xml = thisOmeNode.writeOME(false); 
     348        imageCount = reader.getImageCount(id); 
     349      } 
     350      catch(Exception exc) { 
     351        if(exc instanceof RuntimeException) throw (RuntimeException)exc; 
     352        else exc.printStackTrace(); 
     353      } 
     354 
     355      for(int i = 0;i < imageCount;i++) { 
     356        BufferedImage plane = null; 
     357         
     358        try {       
     359          plane = reader.openImage(id, i); 
     360        } 
     361        catch(Exception exc) { 
     362          if(exc instanceof RuntimeException) throw (RuntimeException)exc; 
     363          else exc.printStackTrace(); 
     364        } 
     365 
     366        Hashtable ifd = null;   
     367        if (i == 0) { 
     368          // save OME-XML metadata to TIFF file's first IFD   
     369          ifd = new Hashtable(); 
     370          TiffTools.putIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION, xml); 
     371        }   
     372        // write plane to output file 
     373         
     374        try {       
     375          writer.saveImage(outId, plane, ifd, i == imageCount - 1); 
     376        } 
     377        catch(Exception exc) { 
     378          if(exc instanceof RuntimeException) throw (RuntimeException)exc; 
     379          else exc.printStackTrace(); 
     380        } 
     381      } 
     382      currentFile = new File(outId); 
     383      if (getTopLevelAncestor() instanceof MetadataNotebook) { 
     384        MetadataNotebook mn = (MetadataNotebook) getTopLevelAncestor(); 
     385        mn.setCurrentFile(file); 
     386      } 
     387      stateChanged(false); 
    326388    } 
    327389  } 
     
    362424 
    363425      try { 
    364         ImageReader reader = new ImageReader(); 
     426        reader = new ImageReader(); 
    365427        OMEXMLMetadataStore ms = new OMEXMLMetadataStore(); 
     428         
    366429        // tell reader to write metadata as it's being 
    367430        // parsed to an OMENode (DOM in memory) 
Note: See TracChangeset for help on using the changeset viewer.