patched for JAL-531 - only display full symbol distribution stats on tooltip/annotati...
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index 1330cf6..0aefe9b 100755 (executable)
@@ -1,20 +1,19 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
- * 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 file is part of Jalview.
  * 
- * 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.
+ * Jalview 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 3 of the License, or (at your option) any later version.
  * 
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ * Jalview 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 Jalview.  If not, see <http://www.gnu.org/licenses/>.
  */
 package jalview.appletgui;
 
@@ -86,6 +85,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         {
           sortPairwiseMenuItem_actionPerformed();
         }
+        else if (param.equalsIgnoreCase("Length"))
+        {
+          sortLengthMenuItem_actionPerformed();
+        }
       }
 
       param = applet.getParameter("wrap");
@@ -150,7 +153,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * DOCUMENT ME!
    * 
    * @param String
-   *                DOCUMENT ME!
+   *          DOCUMENT ME!
    */
 
   public void parseFeaturesFile(String file, String type)
@@ -176,7 +179,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       }
       viewport.showSequenceFeatures = true;
       sequenceFeatures.setState(true);
-      if (viewport.featureSettings!=null)
+      if (viewport.featureSettings != null)
       {
         viewport.featureSettings.refreshTable();
       }
@@ -441,13 +444,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }
     alignPanel.paintAlignment(true);
   }
+
   /**
    * called by key handler and the hide all/show all menu items
+   * 
    * @param toggleSeqs
    * @param toggleCols
    */
-  private void toggleHiddenRegions(boolean toggleSeqs,
-          boolean toggleCols)
+  private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
   {
     boolean hide = false;
     SequenceGroup sg = viewport.getSelectionGroup();
@@ -456,8 +460,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       // Hide everything by the current selection - this is a hack - we do the
       // invert and then hide
       // first check that there will be visible columns after the invert.
-      if ((viewport.colSel != null
-              && viewport.colSel.getSelected() != null && viewport.colSel
+      if ((viewport.colSel != null && viewport.colSel.getSelected() != null && viewport.colSel
               .getSelected().size() > 0)
               || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
                       .getEndRes()))
@@ -508,6 +511,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       }
     }
   }
+
   public void keyReleased(KeyEvent evt)
   {
   }
@@ -587,7 +591,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     else if (evt.getSource() == this.centreColumnLabelFlag)
     {
       centreColumnLabelFlag_stateChanged();
-    } else if (evt.getSource() == this.followMouseOverFlag)
+    }
+    else if (evt.getSource() == this.followMouseOverFlag)
     {
       mouseOverFlag_stateChanged();
     }
@@ -598,7 +603,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   private void mouseOverFlag_stateChanged()
   {
     viewport.followHighlight = followMouseOverFlag.getState();
-    // TODO: could kick the scrollTo mechanism to reset view for current searchresults.
+    // TODO: could kick the scrollTo mechanism to reset view for current
+    // searchresults.
   }
 
   private void centreColumnLabelFlag_stateChanged()
@@ -761,18 +767,21 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       viewport.hideAllSelectedSeqs();
       alignPanel.paintAlignment(true);
     }
-    else if (source == hideAllButSelection) {
-      toggleHiddenRegions(false,false);
+    else if (source == hideAllButSelection)
+    {
+      toggleHiddenRegions(false, false);
       alignPanel.paintAlignment(true);
     }
-    else if (source == hideAllSelection) {
+    else if (source == hideAllSelection)
+    {
       SequenceGroup sg = viewport.getSelectionGroup();
       viewport.expandColSelection(sg, false);
       viewport.hideAllSelectedSeqs();
       viewport.hideSelectedColumns();
       alignPanel.paintAlignment(true);
     }
-    else if (source == showAllHidden) {
+    else if (source == showAllHidden)
+    {
       viewport.showAllHiddenColumns();
       viewport.showAllHiddenSeqs();
       alignPanel.paintAlignment(true);
@@ -900,6 +909,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       sortIDMenuItem_actionPerformed();
     }
+    else if (source == sortLengthMenuItem)
+    {
+      sortLengthMenuItem_actionPerformed();
+    }
     else if (source == sortGroupMenuItem)
     {
       sortGroupMenuItem_actionPerformed();
@@ -996,14 +1009,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   private Hashtable getDisplayedFeatureCols()
   {
-    if (alignPanel.getFeatureRenderer()!=null) {
+    if (alignPanel.getFeatureRenderer() != null)
+    {
       FeatureRenderer fr = alignPanel.getFeatureRenderer();
       Hashtable fcols = new Hashtable();
       Enumeration en = viewport.featuresDisplayed.keys();
       while (en.hasMoreElements())
       {
         Object col = en.nextElement();
-        fcols.put(col,fr.featureColours.get(col));
+        fcols.put(col, fr.featureColours.get(col));
       }
       return fcols;
     }
@@ -1191,7 +1205,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * DOCUMENT ME!
    * 
    * @param e
-   *                DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   protected void undoMenuItem_actionPerformed()
   {
@@ -1216,7 +1230,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * DOCUMENT ME!
    * 
    * @param e
-   *                DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   protected void redoMenuItem_actionPerformed()
   {
@@ -1653,6 +1667,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       this.setVisible(false);
     }
   }
+
   protected void makeGrpsFromSelection_actionPerformed()
   {
     if (viewport.getSelectionGroup() != null)
@@ -1668,7 +1683,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       for (int g = 0; g < gps.length; g++)
       {
         // gps[g].setShowunconserved(viewport.getShowUnconserved());
-        gps[g].setIncludeAllConsSymbols(viewport.isIncludeAllConsensusSymbols());
+        gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
         viewport.alignment.addGroup(gps[g]);
         Color col = new Color((int) (Math.random() * 255), (int) (Math
                 .random() * 255), (int) (Math.random() * 255));
@@ -1683,6 +1698,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       alignPanel.paintAlignment(true);
     }
   }
+
   protected void deleteGroups_actionPerformed()
   {
     viewport.alignment.deleteAllGroups();
@@ -1731,6 +1747,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
   }
+
   public void invertColSel_actionPerformed()
   {
     viewport.invertColumnSelection();
@@ -1976,7 +1993,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * get sequence feature groups that are hidden or shown
    * 
    * @param visible
-   *                true is visible
+   *          true is visible
    * @return list
    */
   public String[] getFeatureGroupsOfState(boolean visible)
@@ -1994,9 +2011,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * Change the display state for the given feature groups
    * 
    * @param groups
-   *                list of group strings
+   *          list of group strings
    * @param state
-   *                visible or invisible
+   *          visible or invisible
    */
   public void setFeatureGroupState(String[] groups, boolean state)
   {
@@ -2238,6 +2255,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     modifyPID_actionPerformed();
   }
+
   public void sortPairwiseMenuItem_actionPerformed()
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
@@ -2253,8 +2271,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
     AlignmentSorter.sortByID(viewport.getAlignment());
-    addHistoryItem(new OrderCommand("ID Sort", oldOrder,
-            viewport.alignment));
+    addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
+    alignPanel.paintAlignment(true);
+  }
+
+  public void sortLengthMenuItem_actionPerformed()
+  {
+    SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
+    AlignmentSorter.sortByLength(viewport.getAlignment());
+    addHistoryItem(new OrderCommand("Length Sort", oldOrder, viewport.alignment));
     alignPanel.paintAlignment(true);
   }
 
@@ -2288,7 +2313,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   public void PCAMenuItem_actionPerformed()
   {
     // are the sequences aligned?
-    if (!viewport.alignment.isAligned())
+    if (!viewport.alignment.isAligned(false))
     {
       SequenceI current;
       int Width = viewport.getAlignment().getWidth();
@@ -2345,7 +2370,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   void NewTreePanel(String type, String pwType, String title)
   {
     // are the sequences aligned?
-    if (!viewport.alignment.isAligned())
+    if (!viewport.alignment.isAligned(false))
     {
       SequenceI current;
       int Width = viewport.getAlignment().getWidth();
@@ -2392,28 +2417,36 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
     addTreeMenuItem(tp, treeFile);
   }
+
   /**
    * sort the alignment using the given treePanel
-   * @param treePanel tree used to sort view
-   * @param title string used for undo event name
+   * 
+   * @param treePanel
+   *          tree used to sort view
+   * @param title
+   *          string used for undo event name
    */
   public void sortByTree(TreePanel treePanel, String title)
   {
     SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
-    AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel
-            .getTree());
+    AlignmentSorter
+            .sortByTree(viewport.getAlignment(), treePanel.getTree());
     // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
     // HistoryItem.SORT));
-    addHistoryItem(new OrderCommand("Order by "+title, oldOrder,
+    addHistoryItem(new OrderCommand("Order by " + title, oldOrder,
             viewport.alignment));
     alignPanel.paintAlignment(true);
   }
+
   /**
-   * Do any automatic reordering of the alignment and add the necessary bits to the menu structure for the new tree
+   * Do any automatic reordering of the alignment and add the necessary bits to
+   * the menu structure for the new tree
+   * 
    * @param treePanel
    * @param title
    */
-  protected void addTreeMenuItem(final TreePanel treePanel, final String title)
+  protected void addTreeMenuItem(final TreePanel treePanel,
+          final String title)
   {
     final MenuItem item = new MenuItem(title);
     sortByTreeMenu.add(item);
@@ -2454,7 +2487,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     class AboutPanel extends Canvas
     {
       String version;
+
       String builddate;
+
       public AboutPanel(String version, String builddate)
       {
         this.version = version;
@@ -2475,7 +2510,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         g.setFont(new Font("Helvetica", Font.BOLD, 14));
         g.drawString("JalviewLite - Release " + version, x, y += fh);
         g.setFont(new Font("Helvetica", Font.BOLD, 12));
-        g.drawString("Build date: "+builddate, x, y += fh);
+        g.drawString("Build date: " + builddate, x, y += fh);
         g.setFont(new Font("Helvetica", Font.PLAIN, 12));
         g
                 .drawString(
@@ -2491,15 +2526,22 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
                         "For help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list",
                         x, y += fh);
         g.drawString("If  you use Jalview, please cite:", x, y += fh + 8);
-        g.drawString(
-                        "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)",x,y+=fh);
-        g.drawString("Jalview Version 2 - a multiple sequence alignment editor and analysis workbench",x,y+=fh);
-        g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033",x,y+=fh);
+        g
+                .drawString(
+                        "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)",
+                        x, y += fh);
+        g
+                .drawString(
+                        "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench",
+                        x, y += fh);
+        g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033",
+                x, y += fh);
       }
     }
 
     Frame frame = new Frame();
-    frame.add(new AboutPanel(JalviewLite.getVersion(), JalviewLite.getBuildDate()));
+    frame.add(new AboutPanel(JalviewLite.getVersion(), JalviewLite
+            .getBuildDate()));
     jalview.bin.JalviewLite.addFrame(frame, "Jalview", 580, 220);
 
   }
@@ -2514,18 +2556,25 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       try
       {
-        if (url.indexOf(":")==-1)
+        if (url.indexOf(":") == -1)
         {
-          // TODO: verify (Bas Vroling bug) prepend codebase or server URL to form valid URL
-          if (url.indexOf("/")==0)
+          // TODO: verify (Bas Vroling bug) prepend codebase or server URL to
+          // form valid URL
+          if (url.indexOf("/") == 0)
           {
             String codebase = viewport.applet.getCodeBase().toString();
-            url = codebase.substring(0,codebase.length()-viewport.applet.getCodeBase().getFile().length())+url;
-          } else {
-            url = viewport.applet.getCodeBase()+url;
+            url = codebase.substring(0, codebase.length()
+                    - viewport.applet.getCodeBase().getFile().length())
+                    + url;
+          }
+          else
+          {
+            url = viewport.applet.getCodeBase() + url;
           }
           System.out.println("Show url (prepended codebase): " + url);
-        } else {
+        }
+        else
+        {
           System.out.println("Show url: " + url);
         }
         viewport.applet.getAppletContext().showDocument(
@@ -2586,6 +2635,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   MenuItem sortIDMenuItem = new MenuItem();
 
+  MenuItem sortLengthMenuItem = new MenuItem();
+
   MenuItem sortGroupMenuItem = new MenuItem();
 
   MenuItem removeRedundancyMenuItem = new MenuItem();
@@ -2660,7 +2711,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   MenuItem deleteGroups = new MenuItem();
 
-  MenuItem grpsFromSelection= new MenuItem();
+  MenuItem grpsFromSelection = new MenuItem();
 
   MenuItem delete = new MenuItem();
 
@@ -2763,6 +2814,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     sortPairwiseMenuItem.addActionListener(this);
     sortIDMenuItem.setLabel("by ID");
     sortIDMenuItem.addActionListener(this);
+    sortLengthMenuItem.setLabel("by Length");
+    sortLengthMenuItem.addActionListener(this);
     sortGroupMenuItem.setLabel("by Group");
     sortGroupMenuItem.addActionListener(this);
     removeRedundancyMenuItem.setLabel("Remove Redundancy...");
@@ -2812,7 +2865,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     annotationPanelMenuItem.addItemListener(this);
     colourTextMenuItem.setLabel("Colour Text");
     colourTextMenuItem.addItemListener(this);
-    displayNonconservedMenuItem.setLabel("Show non-conserved");
+    displayNonconservedMenuItem.setLabel("Show nonconserved");
     displayNonconservedMenuItem.addItemListener(this);
     alProperties.addActionListener(this);
     overviewMenuItem.setLabel("Overview Window");
@@ -3006,6 +3059,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     pasteMenu.add(pasteNew);
     pasteMenu.add(pasteThis);
     sort.add(sortIDMenuItem);
+    sort.add(sortLengthMenuItem);
     sort.add(sortByTreeMenu);
     sort.add(sortGroupMenuItem);
     sort.add(sortPairwiseMenuItem);
@@ -3042,7 +3096,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     selectMenu.add(invertColSel);
     selectMenu.add(grpsFromSelection);
     selectMenu.add(deleteGroups);
-    
+
   }
 
   MenuItem featureSettings = new MenuItem();
@@ -3066,7 +3120,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   MenuItem hideSequences = new MenuItem();
 
   MenuItem hideAllButSelection = new MenuItem();
+
   MenuItem hideAllSelection = new MenuItem();
+
   MenuItem showAllHidden = new MenuItem();
 
   Menu formatMenu = new Menu();
@@ -3081,8 +3137,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * platform independent manner to avoid OSX/Mac menu appendage daftness.
    * 
    * @param reallyEmbedded
-   *                true to attach the view to the applet area on the page
-   *                rather than in a new window
+   *          true to attach the view to the applet area on the page rather than
+   *          in a new window
    */
   public void createAlignFrameWindow(boolean reallyEmbedded, String title)
   {