JAL-1683 replace year/version strings with tokens in source
[jalview.git] / src / jalview / gui / SeqPanel.java
index 3095c47..1cc8715 100644 (file)
@@ -1,36 +1,57 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * 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.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
  *  
  * 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/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
-
 package jalview.gui;
 
-import java.util.*;
+import jalview.commands.EditCommand;
+import jalview.commands.EditCommand.Action;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.io.SequenceAnnotationReport;
+import jalview.schemes.ResidueProperties;
+import jalview.structure.SelectionListener;
+import jalview.structure.SelectionSource;
+import jalview.structure.SequenceListener;
+import jalview.structure.StructureSelectionManager;
+import jalview.util.MessageManager;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
 import java.util.List;
+import java.util.Vector;
 
-import java.awt.*;
-import java.awt.event.*;
-
-import javax.swing.*;
-
-import jalview.commands.*;
-import jalview.datamodel.*;
-import jalview.io.SequenceAnnotationReport;
-import jalview.schemes.*;
-import jalview.structure.*;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.ToolTipManager;
 
 /**
  * DOCUMENT ME!
@@ -92,7 +113,7 @@ public class SeqPanel extends JPanel implements MouseListener,
 
   private final SequenceAnnotationReport seqARep;
 
-  StringBuffer tooltipText = new StringBuffer("<html>");
+  StringBuffer tooltipText = new StringBuffer();
 
   String tmpString;
 
@@ -129,8 +150,7 @@ public class SeqPanel extends JPanel implements MouseListener,
       addMouseMotionListener(this);
       addMouseListener(this);
       addMouseWheelListener(this);
-      ssm = StructureSelectionManager
-              .getStructureSelectionManager(Desktop.instance);
+      ssm = av.getStructureSelectionManager();
       ssm.addStructureViewerListener(this);
       ssm.addSelectionListener(this);
     }
@@ -223,42 +243,6 @@ public class SeqPanel extends JPanel implements MouseListener,
     return seq;
   }
 
-  SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
-  {
-    Vector tmp = new Vector();
-    SequenceFeature[] features = sequence.getSequenceFeatures();
-    if (features != null)
-    {
-      for (int i = 0; i < features.length; i++)
-      {
-        if (av.featuresDisplayed == null
-                || !av.featuresDisplayed.containsKey(features[i].getType()))
-        {
-          continue;
-        }
-
-        if (features[i].featureGroup != null
-                && seqCanvas.fr.featureGroups != null
-                && seqCanvas.fr.featureGroups
-                        .containsKey(features[i].featureGroup)
-                && !((Boolean) seqCanvas.fr.featureGroups
-                        .get(features[i].featureGroup)).booleanValue())
-          continue;
-
-        if ((features[i].getBegin() <= res)
-                && (features[i].getEnd() >= res))
-        {
-          tmp.addElement(features[i]);
-        }
-      }
-    }
-
-    features = new SequenceFeature[tmp.size()];
-    tmp.copyInto(features);
-
-    return features;
-  }
-
   void endEditing()
   {
     if (editCommand != null && editCommand.getSize() > 0)
@@ -307,7 +291,7 @@ public class SeqPanel extends JPanel implements MouseListener,
   {
     SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
 
-    seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1() - 1);
+    seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
     scrollToVisible();
   }
 
@@ -518,26 +502,36 @@ public class SeqPanel extends JPanel implements MouseListener,
 
   int getKeyboardNo1()
   {
-    if (keyboardNo1 == null)
-      return 1;
-    else
+    try
+    {
+      if (keyboardNo1 != null)
+      {
+        int value = Integer.parseInt(keyboardNo1.toString());
+        keyboardNo1 = null;
+        return value;
+      }
+    } catch (Exception x)
     {
-      int value = Integer.parseInt(keyboardNo1.toString());
-      keyboardNo1 = null;
-      return value;
     }
+    keyboardNo1 = null;
+    return 1;
   }
 
   int getKeyboardNo2()
   {
-    if (keyboardNo2 == null)
-      return 1;
-    else
+    try
+    {
+      if (keyboardNo2 != null)
+      {
+        int value = Integer.parseInt(keyboardNo2.toString());
+        keyboardNo2 = null;
+        return value;
+      }
+    } catch (Exception x)
     {
-      int value = Integer.parseInt(keyboardNo2.toString());
-      keyboardNo2 = null;
-      return value;
     }
+    keyboardNo2 = null;
+    return 1;
   }
 
   /**
@@ -683,7 +677,9 @@ public class SeqPanel extends JPanel implements MouseListener,
 
     pos = setStatusMessage(sequence, res, seq);
     if (ssm != null && pos > -1)
+    {
       mouseOverSequence(sequence, res, pos);
+    }
 
     tooltipText.setLength(6); // Cuts the buffer back to <html>
 
@@ -694,11 +690,6 @@ public class SeqPanel extends JPanel implements MouseListener,
       {
         if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res)
         {
-          if (tooltipText.length() > 6)
-          {
-            tooltipText.append("<br>");
-          }
-
           if (!groups[g].getName().startsWith("JTreeGroup")
                   && !groups[g].getName().startsWith("JGroup"))
           {
@@ -714,14 +705,14 @@ public class SeqPanel extends JPanel implements MouseListener,
     }
 
     // use aa to see if the mouse pointer is on a
-    if (av.showSequenceFeatures)
+    if (av.isShowSequenceFeatures())
     {
       int rpos;
-      SequenceFeature[] features = findFeaturesAtRes(
+      List<SequenceFeature> features = ap.getFeatureRenderer().findFeaturesAtRes(
               sequence.getDatasetSequence(),
               rpos = sequence.findPosition(res));
       seqARep.appendFeatures(tooltipText, rpos, features,
-              this.ap.seqPanel.seqCanvas.fr.minmax);
+              this.ap.getSeqPanel().seqCanvas.fr.getMinMax());
     }
     if (tooltipText.length() == 6) // <html></html>
     {
@@ -730,11 +721,13 @@ public class SeqPanel extends JPanel implements MouseListener,
     }
     else
     {
-      tooltipText.append("</html>");
       if (lastTooltip == null
               || !lastTooltip.equals(tooltipText.toString()))
       {
-        setToolTipText(tooltipText.toString());
+        String formatedTooltipText = JvSwingUtils.wrapTooltip(true,
+                tooltipText.toString());
+        // String formatedTooltipText = tooltipText.toString();
+        setToolTipText(formatedTooltipText);
         lastTooltip = tooltipText.toString();
       }
 
@@ -937,7 +930,7 @@ public class SeqPanel extends JPanel implements MouseListener,
       message.append("Edit group:");
       if (editCommand == null)
       {
-        editCommand = new EditCommand("Edit Group");
+        editCommand = new EditCommand(MessageManager.getString("action.edit_group"));
       }
     }
     else
@@ -950,7 +943,7 @@ public class SeqPanel extends JPanel implements MouseListener,
       }
       if (editCommand == null)
       {
-        editCommand = new EditCommand("Edit " + label);
+        editCommand = new EditCommand(MessageManager.formatMessage("label.edit_params", new String[]{label}));
       }
     }
 
@@ -1156,7 +1149,7 @@ public class SeqPanel extends JPanel implements MouseListener,
         }
         else
         {
-          editCommand.appendEdit(EditCommand.INSERT_GAP, groupSeqs,
+          editCommand.appendEdit(Action.INSERT_GAP, groupSeqs,
                   startres, startres - lastres, av.getAlignment(), true);
         }
       }
@@ -1172,7 +1165,7 @@ public class SeqPanel extends JPanel implements MouseListener,
         }
         else
         {
-          editCommand.appendEdit(EditCommand.DELETE_GAP, groupSeqs,
+          editCommand.appendEdit(Action.DELETE_GAP, groupSeqs,
                   startres, lastres - startres, av.getAlignment(), true);
         }
 
@@ -1194,7 +1187,7 @@ public class SeqPanel extends JPanel implements MouseListener,
         }
         else
         {
-          editCommand.appendEdit(EditCommand.INSERT_GAP, new SequenceI[]
+          editCommand.appendEdit(Action.INSERT_GAP, new SequenceI[]
           { seq }, lastres, startres - lastres, av.getAlignment(), true);
         }
       }
@@ -1231,7 +1224,7 @@ public class SeqPanel extends JPanel implements MouseListener,
 
             if (max > 0)
             {
-              editCommand.appendEdit(EditCommand.DELETE_GAP,
+              editCommand.appendEdit(Action.DELETE_GAP,
                       new SequenceI[]
                       { seq }, startres, max, av.getAlignment(), true);
             }
@@ -1249,7 +1242,7 @@ public class SeqPanel extends JPanel implements MouseListener,
           }
           else
           {
-            editCommand.appendEdit(EditCommand.INSERT_NUC, new SequenceI[]
+            editCommand.appendEdit(Action.INSERT_NUC, new SequenceI[]
             { seq }, lastres, startres - lastres, av.getAlignment(), true);
           }
         }
@@ -1285,10 +1278,10 @@ public class SeqPanel extends JPanel implements MouseListener,
       }
     }
 
-    editCommand.appendEdit(EditCommand.DELETE_GAP, seq, blankColumn, 1,
+    editCommand.appendEdit(Action.DELETE_GAP, seq, blankColumn, 1,
             av.getAlignment(), true);
 
-    editCommand.appendEdit(EditCommand.INSERT_GAP, seq, j, 1,
+    editCommand.appendEdit(Action.INSERT_GAP, seq, j, 1,
             av.getAlignment(), true);
 
   }
@@ -1296,10 +1289,10 @@ public class SeqPanel extends JPanel implements MouseListener,
   void deleteChar(int j, SequenceI[] seq, int fixedColumn)
   {
 
-    editCommand.appendEdit(EditCommand.DELETE_GAP, seq, j, 1,
+    editCommand.appendEdit(Action.DELETE_GAP, seq, j, 1,
             av.getAlignment(), true);
 
-    editCommand.appendEdit(EditCommand.INSERT_GAP, seq, fixedColumn, 1,
+    editCommand.appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1,
             av.getAlignment(), true);
   }
 
@@ -1358,21 +1351,21 @@ public class SeqPanel extends JPanel implements MouseListener,
         av.setSelectionGroup(null);
       }
 
-      SequenceFeature[] features = findFeaturesAtRes(
+      List<SequenceFeature> features = seqCanvas.getFeatureRenderer().findFeaturesAtRes(
               sequence.getDatasetSequence(),
               sequence.findPosition(findRes(evt)));
 
-      if (features != null && features.length > 0)
+      if (features != null && features.size()> 0)
       {
         SearchResults highlight = new SearchResults();
-        highlight.addResult(sequence, features[0].getBegin(),
-                features[0].getEnd());
+        highlight.addResult(sequence, features.get(0).getBegin(),
+                features.get(0).getEnd());
         seqCanvas.highlightSearchResults(highlight);
       }
-      if (features != null && features.length > 0)
+      if (features != null && features.size()> 0)
       {
         seqCanvas.getFeatureRenderer().amendFeatures(new SequenceI[]
-        { sequence }, features, false, ap);
+        { sequence }, features.toArray(new SequenceFeature[features.size()]), false, ap);
 
         seqCanvas.highlightSearchResults(null);
       }
@@ -1425,9 +1418,10 @@ public class SeqPanel extends JPanel implements MouseListener,
 
     if (av.wrapAlignment && seq > av.getAlignment().getHeight())
     {
-      JOptionPane.showInternalMessageDialog(Desktop.desktop,
-              "Cannot edit annotations in wrapped view.",
-              "Wrapped view - no edit", JOptionPane.WARNING_MESSAGE);
+      JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
+              .getString("label.cannot_edit_annotations_in_wrapped_view"),
+              MessageManager.getString("label.wrapped_view_no_edit"),
+              JOptionPane.WARNING_MESSAGE);
       return;
     }
 
@@ -1486,16 +1480,16 @@ public class SeqPanel extends JPanel implements MouseListener,
 
     if (javax.swing.SwingUtilities.isRightMouseButton(evt))
     {
-      SequenceFeature[] allFeatures = findFeaturesAtRes(
+      List<SequenceFeature> allFeatures = ap.getFeatureRenderer().findFeaturesAtRes(
               sequence.getDatasetSequence(), sequence.findPosition(res));
       Vector links = new Vector();
-      for (int i = 0; i < allFeatures.length; i++)
+      for (SequenceFeature sf:allFeatures)
       {
-        if (allFeatures[i].links != null)
+        if (sf.links != null)
         {
-          for (int j = 0; j < allFeatures[i].links.size(); j++)
+          for (int j = 0; j < sf.links.size(); j++)
           {
-            links.addElement(allFeatures[i].links.elementAt(j));
+            links.addElement(sf.links.elementAt(j));
           }
         }
       }