Changeset 2310


Ignore:
Timestamp:
02/21/07 17:15:35 (13 years ago)
Author:
chris
Message:

Notebook:
SaveAs functionality added with a slightly counterintuitive
conversion to tiff problem that will be solved tomorrow,
should take little time.

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

Legend:

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

    r2248 r2310  
    3131import javax.swing.*; 
    3232import javax.swing.border.*; 
     33import javax.swing.filechooser.FileFilter; 
    3334import org.openmicroscopy.xml.OMENode; 
    3435import org.w3c.dom.*; 
     36import loci.formats.*; 
    3537 
    3638/** 
     
    5254 
    5355  /**The file chooser used to save and open files.*/ 
    54   protected JFileChooser chooser; 
     56  protected JFileChooser opener,saver; 
     57   
     58  /**Format filters for saver JFileChooser.*/ 
     59  protected ExtensionFileFilter tiffFilter,omeFilter; 
    5560 
    5661  /**The MetadataPane used to display/edit OMEXML content.*/ 
     
    192197    JSeparator jSep = new JSeparator(); 
    193198    file.add(jSep); 
    194     JMenu subFile = new JMenu("Save..."); 
    195     JMenuItem fileSave = new JMenuItem("Save to original"); 
    196     subFile.add(fileSave); 
     199    JMenuItem fileSave = new JMenuItem("Save"); 
     200    file.add(fileSave); 
    197201    fileSave.setActionCommand("save"); 
    198202    fileSave.addActionListener(this); 
     
    200204    fileSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, MENU_MASK)); 
    201205    fileSave.setEnabled(addSave); 
    202     JMenuItem fileSaveComp = new JMenuItem("Save as companion"); 
    203     subFile.add(fileSaveComp); 
     206    JMenuItem fileSaveComp = new JMenuItem("Save to Companion"); 
     207    file.add(fileSaveComp); 
    204208    fileSaveComp.setActionCommand("saveComp"); 
    205209    fileSaveComp.addActionListener(this); 
     
    207211    fileSaveComp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, MENU_MASK)); 
    208212    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); 
    217213    JMenuItem fileSaveAs = new JMenuItem("Save As..."); 
    218214    file.add(fileSaveAs); 
     
    312308 
    313309    //make a filechooser to open and save our precious files 
    314     chooser = new JFileChooser(System.getProperty("user.dir")); 
     310    tiffFilter = new ExtensionFileFilter( 
     311      new String[] {"tif", "tiff"}, "Tagged Image File     Format"); 
     312    omeFilter = new ExtensionFileFilter("ome", "OME-XML"); 
     313    ExtensionFileFilter allFilter = new ExtensionFileFilter(new String[] {"tif","tiff","ome"}, 
     314      "All supported file formats"); 
     315    ExtensionFileFilter[] filters = new ExtensionFileFilter[] {tiffFilter, omeFilter}; 
     316    saver = FormatHandler.buildFileChooser(filters); 
     317    saver.setCurrentDirectory(new File(System.getProperty("user.dir")));  
     318    if(metadata.reader == null) metadata.reader = new ImageReader(); 
     319    opener = metadata.reader.getFileChooser(); 
     320    opener.setCurrentDirectory(new File(System.getProperty("user.dir"))); 
    315321 
    316322    //make WiscScan view the default 
     
    417423          options[0]); //default button title 
    418424        if (n == JOptionPane.YES_OPTION) { 
    419           chooser.setDialogTitle("Open"); 
    420           chooser.setApproveButtonText("Open"); 
    421           chooser.setApproveButtonToolTipText("Open selected file."); 
    422425          opening = true; 
    423           int rval = chooser.showOpenDialog(this); 
     426          int rval = opener.showOpenDialog(this); 
    424427          if (rval == JFileChooser.APPROVE_OPTION) { 
    425428            new Thread(this, "MetadataNotebook-Opener").start(); 
     
    428431      } 
    429432      else { 
    430         chooser.setDialogTitle("Open"); 
    431         chooser.setApproveButtonText("Open"); 
    432         chooser.setApproveButtonToolTipText("Open selected file."); 
    433433        opening = true; 
    434         int rval = chooser.showOpenDialog(this); 
     434        int rval = opener.showOpenDialog(this); 
    435435        if (rval == JFileChooser.APPROVE_OPTION) { 
    436436          new Thread(this, "MetadataNotebook-Opener").start(); 
     
    442442    { 
    443443      opening = false; 
    444       chooser.setDialogTitle("Save"); 
    445       chooser.setApproveButtonText("Save"); 
    446       chooser.setApproveButtonToolTipText("Save to selected file."); 
    447       int rval = chooser.showOpenDialog(this); 
     444      int rval = saver.showSaveDialog(this); 
    448445      if (rval == JFileChooser.APPROVE_OPTION) { 
    449446        new Thread(this, "MetadataNotebook-Saver").start(); 
     
    457454    else if ("saveComp".equals(cmd) && currentFile != null) { 
    458455      saveCompanionFile(currentFile); 
    459       metadata.stateChanged(false); 
    460     } 
    461     else if ("saveTiff".equals(cmd) && currentFile != null) { 
    462       saveTiffFile(currentFile); 
    463456      metadata.stateChanged(false); 
    464457    } 
     
    594587  public void run() { 
    595588    wait(true); 
    596     currentFile = chooser.getSelectedFile(); 
    597     if (opening) openFile(currentFile); 
    598     else saveFile(currentFile); 
     589    if (opening) { 
     590      currentFile = opener.getSelectedFile(); 
     591      openFile(currentFile); 
     592    } 
     593    else { 
     594      currentFile = saver.getSelectedFile(); 
     595      FileFilter filter = saver.getFileFilter(); 
     596      if(filter.equals((FileFilter)omeFilter)) saveFile(currentFile); 
     597      else if(filter.equals((FileFilter)tiffFilter)) saveTiffFile(currentFile); 
     598      else { 
     599        String path = currentFile.getPath(); 
     600        if(path.endsWith("ome")) saveFile(currentFile); 
     601        if(path.endsWith("tif") || path.endsWith("tiff")) saveTiffFile(currentFile); 
     602      } 
     603    } 
    599604    wait(false); 
    600605  } 
  • trunk/loci/ome/notebook/MetadataPane.java

    r2308 r2310  
    497497      doc = db.parse((java.io.InputStream)bis); 
    498498      pixList = DOMUtil.findElementList("Pixels",doc); 
    499       System.out.println(pixList);//TEMP 
    500499       
    501500    } 
     
    529528    } 
    530529     
    531     System.out.println(tiffDataStore);//TEMP 
    532530  } 
    533531   
     
    557555    if(!isOMETiff) { 
    558556      for(int i = 0;i<pixList.size();i++) { 
    559         System.out.println("Adding third-party tiffdata element");//TEMP 
    560557        Element thisEle = (Element) pixList.get(i); 
    561558        DOMUtil.createChild(thisEle, "TiffData"); 
    562         System.out.println("Not OME-Tiff format detected"); //TEMP 
    563559      } 
    564560    } 
    565561    //creating tiff from OMETiff file 
    566     else if (isOMETiff) { 
    567       System.out.println("OME-TIFF format detected"); //TEMP 
    568        
     562    else if (isOMETiff) {       
    569563      for(int i = 0;i<pixList.size();i++) { 
    570564        Element thisEle = (Element) pixList.get(i); 
    571565        String thisID = DOMUtil.getAttribute("ID", thisEle); 
    572566        Vector dataEles = (Vector) tiffDataStore.get(thisID); 
    573         System.out.println(dataEles);//TEMP 
    574567        for(int j = 0;j<dataEles.size();j++) { 
    575568          Element thisData = DOMUtil.createChild(thisEle, "TiffData"); 
     
    579572            String value = (String)(attrs.get(attrNames[k])); 
    580573            DOMUtil.setAttribute(attrNames[k],value,thisData); 
    581             System.out.println(attrNames[k] + ":" + value); //TEMP 
    582           } 
    583         } 
    584       } 
    585     } 
    586     else System.out.println("FORMAT NOT DETECTED");//TEMP 
    587      
    588     try { //TEMP 
    589       DOMUtil.writeXML(System.out,doc); //TEMP 
    590     } //TEMP 
    591     catch (Exception exc) { //TEMP 
    592       exc.printStackTrace(); //TEMP 
    593     } //TEMP 
     574          } 
     575        } 
     576      } 
     577    } 
    594578  } 
    595579   
Note: See TracChangeset for help on using the changeset viewer.