JAL-1517 source formatting
[jalview.git] / src / jalview / appletgui / SeqPanel.java
index 79e6ed7..5ba22b6 100644 (file)
@@ -1,19 +1,22 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 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.appletgui;
 
@@ -146,7 +149,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(
             seqCanvas.cursorY);
 
-    seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1() - 1);
+    seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
     scrollToVisible();
   }
 
@@ -154,7 +157,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
   {
     seqCanvas.cursorX += dx;
     seqCanvas.cursorY += dy;
-    if (av.hasHiddenColumns() && !av.getColumnSelection().isVisible(seqCanvas.cursorX))
+    if (av.hasHiddenColumns()
+            && !av.getColumnSelection().isVisible(seqCanvas.cursorX))
     {
       int original = seqCanvas.cursorX - dx;
       int maxWidth = av.getAlignment().getWidth();
@@ -287,7 +291,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
       else
       {
         // Now add any sequences between min and max
-        sg.getSequences(null).removeAllElements();
+        sg.clear();
         for (int i = min; i < max; i++)
         {
           sg.addSequence(av.getAlignment().getSequenceAt(i), false);
@@ -344,26 +348,36 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
   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;
   }
 
   void setStatusMessage(SequenceI sequence, int res, int seq)
@@ -458,7 +472,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt));
     if (evt.getClickCount() > 1)
     {
-      if (av.getSelectionGroup()!=null && av.getSelectionGroup().getSize() == 1
+      if (av.getSelectionGroup() != null
+              && av.getSelectionGroup().getSize() == 1
               && av.getSelectionGroup().getEndRes()
                       - av.getSelectionGroup().getStartRes() < 2)
       {
@@ -581,8 +596,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
       y -= hgap;
 
-      seq = Math.min((y % cHeight) / av.getCharHeight(),
-              av.getAlignment().getHeight() - 1);
+      seq = Math.min((y % cHeight) / av.getCharHeight(), av.getAlignment()
+              .getHeight() - 1);
       if (seq < 0)
       {
         seq = -1;
@@ -590,8 +605,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
     else
     {
-      seq = Math.min((y / av.getCharHeight()) + av.getStartSeq(),
-              av.getAlignment().getHeight() - 1);
+      seq = Math.min((y / av.getCharHeight()) + av.getStartSeq(), av
+              .getAlignment().getHeight() - 1);
       if (seq < 0)
       {
         seq = -1;
@@ -920,10 +935,9 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
     if (!groupEditing && av.hasHiddenRows())
     {
-      if (av.getHiddenRepSequences() != null
-              && av.getHiddenRepSequences().containsKey(seq))
+      if (av.isHiddenRepSequence(seq))
       {
-        sg = (SequenceGroup) av.getHiddenRepSequences().get(seq);
+        sg = (SequenceGroup) av.getRepresentedSequences(seq);
         groupEditing = true;
       }
     }
@@ -974,14 +988,13 @@ public class SeqPanel extends Panel implements MouseMotionListener,
       // but the sequence represents a group
       if (sg == null)
       {
-        if (av.getHiddenRepSequences() == null
-                || !av.getHiddenRepSequences().containsKey(seq))
+        if (!av.isHiddenRepSequence(seq))
         {
           endEditing();
           return;
         }
 
-        sg = (SequenceGroup) av.getHiddenRepSequences().get(seq);
+        sg = av.getRepresentedSequences(seq);
       }
 
       fixedLeft = sg.getStartRes();
@@ -1038,13 +1051,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
     if (groupEditing)
     {
-      Vector vseqs = sg.getSequences(av.getHiddenRepSequences());
-      int g, groupSize = vseqs.size();
-      SequenceI[] groupSeqs = new SequenceI[groupSize];
-      for (g = 0; g < groupSeqs.length; g++)
-      {
-        groupSeqs[g] = (SequenceI) vseqs.elementAt(g);
-      }
+      SequenceI[] groupSeqs = sg.getSequences(av.getHiddenRepSequences())
+              .toArray(new SequenceI[0]);
 
       // drag to right
       if (insertGap)
@@ -1066,12 +1074,12 @@ public class SeqPanel extends Panel implements MouseMotionListener,
         {
           blank = true;
 
-          for (g = 0; g < groupSize; g++)
+          for (SequenceI gs : groupSeqs)
           {
             for (int j = 0; j < startres - lastres; j++)
             {
-              if (!jalview.util.Comparison.isGap(groupSeqs[g]
-                      .getCharAt(fixedRight - j)))
+              if (!jalview.util.Comparison.isGap(gs.getCharAt(fixedRight
+                      - j)))
               {
                 blank = false;
                 break;
@@ -1088,8 +1096,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
         {
           if (sg.getSize() == av.getAlignment().getHeight())
           {
-            if ((av.hasHiddenColumns() && startres < av.getColumnSelection()
-                    .getHiddenBoundaryRight(startres)))
+            if ((av.hasHiddenColumns() && startres < av
+                    .getColumnSelection().getHiddenBoundaryRight(startres)))
             {
               endEditing();
               return;
@@ -1098,7 +1106,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
             int alWidth = av.getAlignment().getWidth();
             if (av.hasHiddenRows())
             {
-              int hwidth = av.getAlignment().getHiddenSequences().getWidth();
+              int hwidth = av.getAlignment().getHiddenSequences()
+                      .getWidth();
               if (hwidth > alWidth)
               {
                 alWidth = hwidth;
@@ -1123,16 +1132,16 @@ public class SeqPanel extends Panel implements MouseMotionListener,
         // / Are we able to delete?
         // ie are all columns blank?
 
-        for (g = 0; g < groupSize; g++)
+        for (SequenceI gs : groupSeqs)
         {
           for (int j = startres; j < lastres; j++)
           {
-            if (groupSeqs[g].getLength() <= j)
+            if (gs.getLength() <= j)
             {
               continue;
             }
 
-            if (!jalview.util.Comparison.isGap(groupSeqs[g].getCharAt(j)))
+            if (!jalview.util.Comparison.isGap(gs.getCharAt(j)))
             {
               // Not a gap, block edit not valid
               endEditing();
@@ -1266,16 +1275,16 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     editCommand.appendEdit(EditCommand.DELETE_GAP, seq, blankColumn, 1,
             av.getAlignment(), true);
 
-    editCommand.appendEdit(EditCommand.INSERT_GAP, seq, j, 1, av.getAlignment(),
-            true);
+    editCommand.appendEdit(EditCommand.INSERT_GAP, seq, j, 1,
+            av.getAlignment(), true);
 
   }
 
   void deleteChar(int j, SequenceI[] seq, int fixedColumn)
   {
 
-    editCommand.appendEdit(EditCommand.DELETE_GAP, seq, j, 1, av.getAlignment(),
-            true);
+    editCommand.appendEdit(EditCommand.DELETE_GAP, seq, j, 1,
+            av.getAlignment(), true);
 
     editCommand.appendEdit(EditCommand.INSERT_GAP, seq, fixedColumn, 1,
             av.getAlignment(), true);
@@ -1419,28 +1428,17 @@ public class SeqPanel extends Panel implements MouseMotionListener,
       return;
     }
 
+    stretchGroup.recalcConservation(); // always do this - annotation has own
+                                       // state
     if (stretchGroup.cs != null)
     {
-      if (stretchGroup.cs instanceof ClustalxColourScheme)
-      {
-        ((ClustalxColourScheme) stretchGroup.cs).resetClustalX(
-                stretchGroup.getSequences(av.getHiddenRepSequences()),
-                stretchGroup.getWidth());
-      }
-
-      if (stretchGroup.cs instanceof Blosum62ColourScheme
-              || stretchGroup.cs instanceof PIDColourScheme
-              || stretchGroup.cs.conservationApplied()
-              || stretchGroup.cs.getThreshold() > 0)
-      {
-        stretchGroup.recalcConservation();
-      }
+      stretchGroup.cs.alignmentChanged(stretchGroup,
+              av.getHiddenRepSequences());
 
       if (stretchGroup.cs.conservationApplied())
       {
         SliderPanel.setConservationSlider(ap, stretchGroup.cs,
                 stretchGroup.getName());
-        stretchGroup.recalcConservation();
       }
       else
       {
@@ -1525,7 +1523,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
       dragDirection = -1;
     }
 
-    while ((y != oldSeq) && (oldSeq > -1) && (y < av.getAlignment().getHeight()))
+    while ((y != oldSeq) && (oldSeq > -1)
+            && (y < av.getAlignment().getHeight()))
     {
       // This routine ensures we don't skip any sequences, as the
       // selection is quite slow.
@@ -1712,7 +1711,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     if (av.getSelectionGroup() == null || !av.isSelectionGroupChanged(true))
     {
       SequenceGroup sgroup = null;
-      if (seqsel != null && seqsel.getSize()>0)
+      if (seqsel != null && seqsel.getSize() > 0)
       {
         if (av.getAlignment() == null)
         {
@@ -1742,7 +1741,9 @@ public class SeqPanel extends Panel implements MouseMotionListener,
       }
       repaint = av.isSelectionGroupChanged(true);
     }
-    if (copycolsel && (av.getColumnSelection() == null || !av.isColSelChanged(true)))
+    if (copycolsel
+            && (av.getColumnSelection() == null || !av
+                    .isColSelChanged(true)))
     {
       // the current selection is unset or from a previous message
       // so import the new colsel.
@@ -1767,8 +1768,10 @@ public class SeqPanel extends Panel implements MouseMotionListener,
       }
       repaint |= av.isColSelChanged(true);
     }
-    if (copycolsel && av.hasHiddenColumns()
-            && (av.getColumnSelection() == null || av.getColumnSelection().getHiddenColumns() == null))
+    if (copycolsel
+            && av.hasHiddenColumns()
+            && (av.getColumnSelection() == null || av.getColumnSelection()
+                    .getHiddenColumns() == null))
     {
       System.err.println("Bad things");
     }
@@ -1781,35 +1784,40 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
   /**
    * scroll to the given row/column - or nearest visible location
+   * 
    * @param row
    * @param column
    */
   public void scrollTo(int row, int column)
   {
-    
-    row = row<0 ? ap.av.startSeq : row;
-    column = column<0 ? ap.av.startRes : column;
-    ap.scrollTo(row, row, column, true, true);
+
+    row = row < 0 ? ap.av.startSeq : row;
+    column = column < 0 ? ap.av.startRes : column;
+    ap.scrollTo(column, column, row, true, true);
   }
+
   /**
    * scroll to the given row - or nearest visible location
+   * 
    * @param row
    */
   public void scrollToRow(int row)
   {
-    
-    row = row<0 ? ap.av.startSeq : row;
-    ap.scrollTo(row, row, ap.av.startRes, true, true);
+
+    row = row < 0 ? ap.av.startSeq : row;
+    ap.scrollTo(ap.av.startRes, ap.av.startRes, row, true, true);
   }
+
   /**
    * scroll to the given column - or nearest visible location
+   * 
    * @param column
    */
   public void scrollToColumn(int column)
   {
-    
-    column = column<0 ? ap.av.startRes : column;
-    ap.scrollTo(ap.av.startRes, ap.av.startRes, column, true, true);
+
+    column = column < 0 ? ap.av.startRes : column;
+    ap.scrollTo(column, column, ap.av.startSeq, true, true);
   }
 
 }