/* GraphMenu.java * * created: Tue Sep 18 2001 * * This file is part of Artemis * * Copyright (C) 2001 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/GraphMenu.java,v 1.11 2009-08-03 10:29:32 tjc Exp $ */ package uk.ac.sanger.artemis.components; import uk.ac.sanger.artemis.EntryGroup; import uk.ac.sanger.artemis.Options; import uk.ac.sanger.artemis.chado.Graph; import uk.ac.sanger.artemis.io.DatabaseDocumentEntry; import uk.ac.sanger.artemis.io.DocumentEntry; import uk.ac.sanger.artemis.plot.Algorithm; import uk.ac.sanger.artemis.plot.BaseAlgorithm; import uk.ac.sanger.artemis.plot.CodonUsageAlgorithm; import uk.ac.sanger.artemis.plot.CodonUsageWeight; import uk.ac.sanger.artemis.plot.UserDataAlgorithm; import uk.ac.sanger.artemis.sequence.Strand; import uk.ac.sanger.artemis.util.DatabaseDocument; import uk.ac.sanger.artemis.util.Document; import java.awt.Cursor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.IOException; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import java.util.Vector; import javax.swing.*; /** * This menu controls one particular BasePlotGroup. * * @author Kim Rutherford * @version $Id: GraphMenu.java,v 1.11 2009-08-03 10:29:32 tjc Exp $ **/ public class GraphMenu extends JMenu { private static final long serialVersionUID = 1L; /** * The JFrame reference that was passed to the constructor. **/ private JFrame frame; /** * The BasePlotGroup that was passed to the constructor. **/ private BasePlotGroup base_plot_group; /** * The EntryGroup object that was passed to the constructor. **/ private EntryGroup entry_group = null; /** * The FeatureDisplay that was passed to the constructor. **/ private FeatureDisplay feature_display; private JMenu menuSubMenu = new JMenu("Other Graphs"); /** * This list of the CheckboxMenuItems for the graphs is stored so that we * can turn them all off with "Hide All Graphs". **/ private Vector algorithm_menu_items = new Vector (); private JSplitPane splitPane; /** * Create a new GraphMenu object and all it's menu items. * @param frame The JFrame that owns this JMenu. * @param entry_group The EntryGroup containing the sequence to plot. * @param base_plot_group The BasePlotGroup that this menu controls. * @param view_menu This ViewMenu is updated when a usage plot is added. * @param add_menu This AddMenu is updated when a usage plot is added. * @param menu_name The name of the new menu. **/ public GraphMenu (final JFrame frame, final EntryGroup entry_group, final BasePlotGroup base_plot_group, final FeatureDisplay feature_display, final String menu_name, final JSplitPane splitPane, final int index) { super (menu_name); this.frame = frame; this.entry_group = entry_group; this.base_plot_group = base_plot_group; this.feature_display = feature_display; this.splitPane = splitPane; final BaseAlgorithm [] orig_algorithms = base_plot_group.getPlotAlgorithms (); final JMenuItem hide_all_graphs_item = new JMenuItem ("Hide All Graphs"); hide_all_graphs_item.addActionListener (new ActionListener () { public void actionPerformed (ActionEvent event) { final BaseAlgorithm [] current_algorithms = base_plot_group.getPlotAlgorithms (); for (int i = 0 ; i < current_algorithms.length ; ++i) { final BaseAlgorithm this_algorithm = current_algorithms[i]; base_plot_group.setVisibleByAlgorithm (this_algorithm, false); final JCheckBoxMenuItem this_menu_item = algorithm_menu_items.elementAt (i); this_menu_item.setState (false); } if (getParent () != null) { // XXX change to revalidate(). frame.validate (); } } }); add (hide_all_graphs_item); addSeparator (); if (Options.readWritePossible ()) { final JMenuItem usage_plot_item = new JMenuItem ("Add Usage Plots ..."); usage_plot_item.addActionListener (new ActionListener () { public void actionPerformed (ActionEvent event) { addUsagePlot (); adjustSplitPane(true); } }); add (usage_plot_item); final JMenuItem user_plot_item = new JMenuItem ("Add User Plot ..."); user_plot_item.addActionListener (new ActionListener () { public void actionPerformed (ActionEvent event) { try { addUserPlot ((uk.ac.sanger.artemis.util.Document)null, false); adjustSplitPane(true); } catch(java.lang.OutOfMemoryError emem) { JOptionPane.showMessageDialog(frame, "Out of memory. Increase the maximum memory"+ "\navailable for this application and try again.", "Out Of Memory", JOptionPane.WARNING_MESSAGE); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } }); add (user_plot_item); if(getEntryGroup().getSequenceEntry().getEMBLEntry() instanceof DatabaseDocumentEntry) { final JMenu database_user_plot = new JMenu("Add Database Plot ..."); final DatabaseDocument dbDoc = (DatabaseDocument) ((DocumentEntry) entry_group .getSequenceEntry().getEMBLEntry()).getDocument(); try { boolean hasGraphs = addDatabaseUserPlot(dbDoc, database_user_plot); database_user_plot.setEnabled(hasGraphs); add(database_user_plot); } catch(Exception e) { e.printStackTrace(); } } addSeparator (); } boolean useSubMenu = false; for (int i = 0 ; i < orig_algorithms.length ; ++i) { final BaseAlgorithm this_algorithm = orig_algorithms[i]; if(this_algorithm.getAlgorithmName().startsWith("Cumulative AT")) useSubMenu = true; addAlgorithm (this_algorithm, false, useSubMenu); } if(useSubMenu) add(menuSubMenu); if (Options.getOptions ().getProperty ("codon_usage_file") != null) { final String codon_usage_file_name = Options.getOptions ().getProperty ("codon_usage_file"); try { addUsagePlot (new File (codon_usage_file_name), true, false); addUsagePlot (new File (codon_usage_file_name), false, false); if (getParent () != null) { // XXX change to revalidate(). frame.validate (); } } catch (IOException e) { new MessageDialog (frame, "error while reading usage data: " + e); } } // add user plots from the command line JVM option if(System.getProperty("userplot"+ (index > 0 ? index : "")) != null || System.getProperty("loguserplot"+ (index > 0 ? index : "")) != null) { String plots[] = new String[]{}; if(System.getProperty("userplot"+ (index > 0 ? index : "")) != null) plots = System.getProperty("userplot"+ (index > 0 ? index : "")).split("[\\s,]"); String logplots[] = new String[]{}; if(System.getProperty("loguserplot"+ (index > 0 ? index : "")) != null) logplots = System.getProperty("loguserplot"+ (index > 0 ? index : "")).split("[\\s,]"); try { for(int i=0;i