Changeset 4264


Ignore:
Timestamp:
07/31/08 12:12:54 (12 years ago)
Author:
curtis
Message:

Add hooks for "Download from OME" and "Upload to OME" menu options.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/gui/ImageViewer.java

    r4048 r4264  
    6565  protected JMenuItem fileSave; 
    6666 
     67  /** Current format reader. */ 
    6768  protected IFormatReader myReader; 
    68   protected ImageWriter myWriter; 
     69 
     70  /** Current format writer. */ 
     71  protected IFormatWriter myWriter; 
     72 
     73  /** Reader for files on disk. */ 
     74  protected IFormatReader fileReader; 
     75 
     76  /** Reader for OME servers. */ 
     77  protected IFormatReader omeReader; 
     78 
     79  /** Reader for OMERO servers. */ 
     80  protected IFormatReader omeroReader; 
     81 
     82  /** Writer for files on disk. */ 
     83  protected IFormatWriter fileWriter; 
     84 
     85  /** Writer for OME servers. */ 
     86  protected IFormatWriter omeWriter; 
     87 
     88  /** Writer for OMERO servers. */ 
     89  protected IFormatWriter omeroWriter; 
    6990 
    7091  protected String filename; 
     
    156177    JMenuBar menubar = new JMenuBar(); 
    157178    setJMenuBar(menubar); 
     179 
    158180    JMenu file = new JMenu("File"); 
    159181    file.setMnemonic('f'); 
     
    191213    fileExit.addActionListener(this); 
    192214    file.add(fileExit); 
     215 
     216    JMenu ome = new JMenu("OME"); 
     217    ome.setMnemonic('o'); 
     218    menubar.add(ome); 
     219    JMenuItem omeDownload = new JMenuItem("Download from OMERO..."); 
     220    omeDownload.setMnemonic('d'); 
     221    omeDownload.setActionCommand("download"); 
     222    omeDownload.addActionListener(this); 
     223    omeDownload.setEnabled(false); 
     224    ome.add(omeDownload); 
     225    JMenuItem omeUpload = new JMenuItem("Upload to OMERO..."); 
     226    omeUpload.setMnemonic('u'); 
     227    omeUpload.setActionCommand("upload"); 
     228    omeUpload.addActionListener(this); 
     229    omeUpload.setEnabled(false); 
     230    ome.add(omeUpload); 
     231 
    193232    JMenu options = new JMenu("Options"); 
    194     options.setMnemonic('o'); 
     233    options.setMnemonic('p'); 
    195234    menubar.add(options); 
    196235    JMenuItem optionsFPS = new JMenuItem("Frames per Second..."); 
     
    199238    optionsFPS.addActionListener(this); 
    200239    options.add(optionsFPS); 
     240 
    201241    JMenu help = new JMenu("Help"); 
    202242    help.setMnemonic('h'); 
     
    215255 
    216256    // image I/O engine 
    217     myReader = new ChannelMerger(new FileStitcher()); 
    218     myWriter = new ImageWriter(); 
    219  
    220     // animation thread 
    221   } 
    222  
    223   /** Opens the given file using the ImageReader. */ 
     257    myReader = fileReader = new ChannelMerger(new FileStitcher()); 
     258    myWriter = fileWriter = new ImageWriter(); 
     259 
     260    // NB: avoid dependencies on optional loci.ome.io package 
     261    ReflectedUniverse r = new ReflectedUniverse(); 
     262 
     263    // OME server I/O engine 
     264    try { 
     265      r.exec("import loci.ome.io.OMEReader"); 
     266      r.exec("import loci.ome.io.OMEWriter"); 
     267      omeReader = (IFormatReader) r.exec("new OMEReader()"); 
     268      omeWriter = (IFormatWriter) r.exec("new OMEWriter()"); 
     269    } 
     270    catch (ReflectException exc) { LogTools.trace(exc); } 
     271 
     272    // OMERO server I/O engine 
     273    try { 
     274      r.exec("import loci.ome.io.OMEROReader"); 
     275      r.exec("import loci.ome.io.OMEROWriter"); 
     276      omeroReader = (IFormatReader) r.exec("new OMEROReader()"); 
     277      omeroWriter = (IFormatWriter) r.exec("new OMEROWriter()"); 
     278    } 
     279    catch (ReflectException exc) { LogTools.trace(exc); } 
     280  } 
     281 
     282  /** Opens the given data source using the current format reader. */ 
    224283  public void open(String id) { 
    225284    wait(true); 
    226285    try { 
    227       Location f = new Location(id); 
    228       id = f.getAbsolutePath(); 
     286      //Location f = new Location(id); 
     287      //id = f.getAbsolutePath(); 
    229288      myReader.setId(id); 
    230289      int num = myReader.getImageCount(); 
     
    258317  } 
    259318 
    260   /** Saves the current images to the given file using the ImageWriter. */ 
     319  /** 
     320   * Saves the current images to the given destination 
     321   * using the current format writer. 
     322   */ 
    261323  public void save(String id) { 
    262324    if (images == null) return; 
     
    282344        progress.setProgress(1); 
    283345      } 
     346      myWriter.close(); 
    284347    } 
    285348    catch (FormatException exc) { LogTools.trace(exc); } 
     
    387450      if (rval == JFileChooser.APPROVE_OPTION) { 
    388451        final File file = chooser.getSelectedFile(); 
    389         if (file != null) { 
    390           new Thread("ImageViewer-Opener") { 
    391             public void run() { open(file.getAbsolutePath()); } 
    392           }.start(); 
    393         } 
     452        if (file != null) open(file.getAbsolutePath(), fileReader); 
    394453      } 
    395454    } 
     
    401460      if (rval == JFileChooser.APPROVE_OPTION) { 
    402461        final File file = chooser.getSelectedFile(); 
    403         if (file != null) { 
    404           new Thread("ImageViewer-Saver") { 
    405             public void run() { save(file.getPath()); } 
    406           }.start(); 
    407         } 
     462        if (file != null) save(file.getAbsolutePath(), fileWriter); 
    408463      } 
    409464    } 
     
    419474    } 
    420475    else if ("exit".equals(cmd)) dispose(); 
     476    else if ("download".equals(cmd)) { 
     477      // HACK - JOptionPane prevents shutdown on dispose 
     478      setDefaultCloseOperation(EXIT_ON_CLOSE); 
     479 
     480      // TODO - use loci.visbio.ome.OMELoginPane instead, 
     481      // after updating it and repackaging it to loci.ome.io.gui 
     482 
     483      String id = JOptionPane.showInputDialog(this, 
     484        "Enter OMERO connection string:", 
     485        "localhost?port=1099&user=omero&password=omero&id=1"); 
     486      open(id, omeroReader); 
     487    } 
     488    else if ("upload".equals(cmd)) { 
     489      // HACK - JOptionPane prevents shutdown on dispose 
     490      setDefaultCloseOperation(EXIT_ON_CLOSE); 
     491 
     492      // TODO - use loci.visbio.ome.OMELoginPane instead, 
     493      // after updating it and repackaging it to loci.ome.io.gui 
     494 
     495      String id = JOptionPane.showInputDialog(this, 
     496        "Enter OMERO connection string:", 
     497        "localhost?port=1099&user=omero&password=omero"); 
     498      open(id, omeroReader); 
     499    } 
    421500    else if ("fps".equals(cmd)) { 
    422501      // HACK - JOptionPane prevents shutdown on dispose 
     
    609688  } 
    610689 
     690  /** 
     691   * Opens the given data source using the specified reader 
     692   * in a separate thread. 
     693   */ 
     694  protected void open(final String id, final IFormatReader r) { 
     695    new Thread("ImageViewer-Opener") { 
     696      public void run() { 
     697        try { 
     698          myReader.close(); 
     699        } 
     700        catch (IOException exc) { LogTools.trace(exc); } 
     701        myReader = r; 
     702        open(id); 
     703      } 
     704    }.start(); 
     705  } 
     706 
     707  /** 
     708   * Opens the given data source using the specified reader 
     709   * in a separate thread. 
     710   */ 
     711  protected void save(final String id, final IFormatWriter w) { 
     712    new Thread("ImageViewer-Saver") { 
     713      public void run() { 
     714        try { 
     715          myWriter.close(); 
     716        } 
     717        catch (IOException exc) { LogTools.trace(exc); } 
     718        myWriter = w; 
     719        save(id); 
     720      } 
     721    }.start(); 
     722  } 
     723 
    611724  // -- Main method -- 
    612725 
Note: See TracChangeset for help on using the changeset viewer.