Skip to content
Snippets Groups Projects
SearchResultViewer.java 3.94 KiB
Newer Older
  • Learn to ignore specific revisions
  • tjc's avatar
    tjc committed
    /* SearchResultViewer.java
     *
     * created: Thu Feb 24 2000
     *
     * This file is part of Artemis
     *
     * Copyright (C) 2000  Genome Research Limited
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * as published by the Free Software Foundation; either version 2
     * of the License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     *
    
    tjc's avatar
    tjc committed
     * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/SearchResultViewer.java,v 1.5 2008-01-23 14:22:49 tjc Exp $
    
    tjc's avatar
    tjc committed
     */
    
    package uk.ac.sanger.artemis.components;
    
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.ExternalProgram;
    import uk.ac.sanger.artemis.ExternalProgramException;
    import uk.ac.sanger.artemis.Options;
    import uk.ac.sanger.artemis.util.Document;
    
    import uk.ac.sanger.artemis.util.ZipFileDocument;
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
    
    import javax.swing.JButton;
    
    tjc's avatar
    tjc committed
    
    
    
    /**
     *  A component that displays the results of external searches, with the
     *  ability to send the results to a netscape process.
     *
     *  @author Kim Rutherford <kmr@sanger.ac.uk>
    
    tjc's avatar
    tjc committed
     *  @version $Id: SearchResultViewer.java,v 1.5 2008-01-23 14:22:49 tjc Exp $
    
    tjc's avatar
    tjc committed
     **/
    
    
    tjc's avatar
    tjc committed
    public class SearchResultViewer extends FileViewer 
    {
    
    tjc's avatar
    tjc committed
      /** */
      private static final long serialVersionUID = 1L;
    
    
    tjc's avatar
    tjc committed
      /**
       *  Create a new SearchResultViewer component.
       *  @param title The name to attach to the new JFrame.
       *  @param file_name The file to read into the new viewer.
       **/
    
    tjc's avatar
    tjc committed
      public SearchResultViewer(final String label,
                                final Document document)
          throws IOException 
      {
    
    tjc's avatar
    tjc committed
        super (label, false, false, false);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        try 
        {
          readFile(document.getReader());
        } 
        catch (IOException e) 
        {
          System.out.println("error while reading results: " + e);
          dispose();
    
    tjc's avatar
    tjc committed
          throw e;
        }
    
    tjc's avatar
    tjc committed
        setVisible(true);
    
    tjc's avatar
    tjc committed
        if(!Options.getOptions().getPropertyTruthValue("sanger_options")) 
    
    tjc's avatar
    tjc committed
          return;
    
    
    tjc's avatar
    tjc committed
        final JButton to_browser = new JButton("Send to browser");
        getButtonPanel().add(to_browser);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        to_browser.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
    
            String fileName = document.toString();
    
    tjc's avatar
    tjc committed
            try 
            {
    
              if(document instanceof ZipFileDocument)
                fileName = ((ZipFileDocument)document).writeTmpFile(
                    SearchResultViewer.this.getText());
              
              sendToBrowser(fileName);
    
    tjc's avatar
    tjc committed
            }
            catch (IOException e) 
            {
    
    tjc's avatar
    tjc committed
              System.out.println ("error while reading results: " + e);
    
    tjc's avatar
    tjc committed
              new MessageDialog(SearchResultViewer.this,
                                "Message",
                                "Send to browser failed: " + e);
            } 
            catch(ExternalProgramException e) 
            {
              System.out.println("error while reading results: " + e);
              new MessageDialog(SearchResultViewer.this,
                                "Message",
                                "Send to browser failed: " + e);
    
    tjc's avatar
    tjc committed
            }
          }
        });
      }
    
      /**
       *  Mark up the contents of the given file (which should contain blast or
       *  fasta output) and send it to a web browser (with netscape -remote).
       **/
    
    tjc's avatar
    tjc committed
      protected static void sendToBrowser(final String file_name)
          throws IOException, ExternalProgramException
      {
        final String[] arguments =
        {
    
    tjc's avatar
    tjc committed
          file_name
        };
    
        final Process process =
    
          ExternalProgram.startProgram("results_to_netscape", arguments);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        new ProcessWatcher(process, "results_to_netscape", false);
    
    tjc's avatar
    tjc committed
      }
    }