Newer
Older
/* RunMenu.java
*
* created: Fri Jan 22 1999
*
* This file is part of Artemis
*
* Copyright(C) 1998,1999,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.
*
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/RunMenu.java,v 1.13 2009-05-13 15:53:14 tjc Exp $
**/
package uk.ac.sanger.artemis.components;
import uk.ac.sanger.artemis.*;
import uk.ac.sanger.artemis.util.ReadOnlyException;
import uk.ac.sanger.artemis.io.EntryInformationException;
import uk.ac.sanger.artemis.io.InvalidKeyException;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
/**
* A JMenu of external commands/functions.
*
* @author Kim Rutherford
* @version $Id: RunMenu.java,v 1.13 2009-05-13 15:53:14 tjc Exp $
private JMenu fastaMenu = null;
private JMenu fastaMenuOptions = null;
private Hashtable blastMenu = null;
private Hashtable blastMenuOptions = null;
/**
* Create a new RunMenu object.
* @param frame The JFrame that owns this JMenu.
* @param selection The Selection that the commands in the menu will
* operate on.
* @param menu_name The name of the new menu.
**/
public RunMenu(final JFrame frame, final Selection selection,
final String menu_name)
{
super(frame, menu_name, selection);
if(Options.isUnixHost())
{
final ExternalProgramVector external_programs = Options.getOptions()
.getExternalPrograms();
boolean sanger_options = Options.getOptions().getPropertyTruthValue(
"sanger_options");
final int external_programs_size = external_programs.size();
for(int i = 0; i < external_programs_size; ++i)
makeMenuItem(external_programs.elementAt(i), sanger_options);
for(int i = 0; i < external_programs_size; ++i)
makeOptionsMenuItem(external_programs.elementAt(i));
}
}
/**
* Create a new RunMenu object.
* @param frame The JFrame that owns this JMenu.
* @param selection The Selection that the commands in the menu will
* operate on.
**/
public RunMenu(final JFrame frame,
final Selection selection)
{
this(frame, selection, "Run");
}
private void addPfamSearches(final Selection selection)
{
final JMenuItem ncbiSearchLinks = new JMenuItem("Pfam Search");
add(ncbiSearchLinks);
ncbiSearchLinks.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
final FeatureVector features = selection.getAllFeatures();
if(features.size() != 1)
{
JOptionPane.showMessageDialog(RunMenu.this,
"Selected a single feature to send to Pfam for searching.",
"Pfam Search", JOptionPane.INFORMATION_MESSAGE);
return;
}
final String residues = features.elementAt(0).getTranslation().toString().toUpperCase();
RunPfamSearchThread pfamSearch = new RunPfamSearchThread(residues);
pfamSearch.start();
}
});
}
/**
* Add menu for NCBI web searches
* @param selection
*/
private void addNCBISearches(final Selection selection)
{
final JMenu ncbiSearchLinks = new JMenu("NCBI Searches");
add(ncbiSearchLinks);
final ExternalProgramVector ncbi_protein =
Options.getOptions().getNCBIPrograms();
for(int i = 0; i < ncbi_protein.size(); ++i)
{
final ExternalProgram program = (ExternalProgram)ncbi_protein.elementAt(i);
final String programName = program.getName();
final JMenuItem programMenu = new JMenuItem(programName);
ncbiSearchLinks.add(programMenu);
programMenu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
final FeatureVector features = selection.getAllFeatures();
if(features.size() != 1)
{
JOptionPane.showMessageDialog(RunMenu.this,
"Selected a single feature to send to NCBI for searching.",
"NCBI Search", JOptionPane.INFORMATION_MESSAGE);
return;
}
final String residues;
if(program.getType() == ExternalProgram.AA_PROGRAM)
residues = features.elementAt(0).getTranslation().toString().toUpperCase();
else
residues = features.elementAt(0).getBases();
String data = RunBlastAtNCBI.setData(programName, residues);
if(data != null)
{
RunBlastAtNCBI blastSearch = new RunBlastAtNCBI(data);
blastSearch.start();
}
//BrowserControl.displayURL(program.getProgramOptions()+residues);
/**
* Make a new menu item for running the given ExternalProgram object.
* @param program Create two menu items for this program.
**/
private void makeMenuItem(final ExternalProgram program,
final boolean sanger_options)
if(program.getType() == ExternalProgram.AA_PROGRAM ||
program.getType() == ExternalProgram.DNA_PROGRAM &&
{
final String options_string = program.getProgramOptions();
if(options_string.length() > 0)
new_menu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(!checkForSelectionFeatures())
return;
final FeatureVector selection_features =
getSelection().getAllFeatures();
try
{
final ExternalProgramMonitor monitor =
program.run(selection_features, Splash.getLogger());
monitor.addExternalProgramListener(new ExternalProgramListener()
{
public void statusChanged(final ExternalProgramEvent e)
{
if(e.getType() == ExternalProgramEvent.FINISHED)
new MessageFrame(e.getMessage()).setVisible(true);
}
});
new Thread(monitor).start();
}
catch(InvalidKeyException e)
{
new MessageDialog(getParentFrame(),
"execution failed: " + e.getMessage());
}
catch(EntryInformationException e)
{
new MessageDialog(getParentFrame(),
" failed because: " + e.getMessage());
}
catch(ReadOnlyException e)
{
new MessageDialog(getParentFrame(),
" failed because one of the features is " +
"read only");
}
catch(IOException e)
{
new MessageDialog(getParentFrame(),
" failed because of an I/O error: " +
e);
}
catch(ExternalProgramException e)
{
new MessageDialog(getParentFrame(),
{
if(fastaMenu == null)
{
fastaMenu = new JMenu("Run fasta on selected features against");
add(fastaMenu);
}
fastaMenu.add(new_menu);
}
else if(program.getName().indexOf("blast")>-1)
if(blastMenu == null)
blastMenu = new Hashtable();
if(!blastMenu.containsKey(program.getName()))
JMenu topMenu = new JMenu("Run "+program.getName()+
" on selected features against");
blastMenu.put(program.getName(), topMenu);
add(topMenu);
JMenu topMenu = (JMenu) blastMenu.get(program.getName());
topMenu.add(new_menu);
}
/**
* Make a new options menu item for the given ExternalProgram object.
* @param program Create two menu items for this program.
**/
private void makeOptionsMenuItem(final ExternalProgram program)
{
if(!(program.getType() == ExternalProgram.AA_PROGRAM ||
program.getType() == ExternalProgram.DNA_PROGRAM))
return;
final JMenuItem new_options_menu;
final String program_name = program.getName();
if(program_name.startsWith("fasta"))
add(fastaMenuOptions);
}
new_options_menu = new JMenuItem(program.getProgramOptions());
fastaMenuOptions.add(new_options_menu);
}
else if(program_name.indexOf("blast")>-1)
if(blastMenuOptions == null)
blastMenuOptions = new Hashtable();
String menuStr = "Set " + program_name + " options";
if(!blastMenuOptions.containsKey(menuStr))
JMenu topMenu = new JMenu(menuStr);
blastMenuOptions.put(menuStr, topMenu);
add(topMenu);
JMenu topMenu = (JMenu) blastMenuOptions.get(menuStr);
new_options_menu = new JMenuItem(program.getProgramOptions());