update author list in license for (JAL-826)
[jalview.git] / src / jalview / gui / ScalePanel.java
index 045471a..b5a19b2 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.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.gui;
 
@@ -64,7 +63,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
    * DOCUMENT ME!
    * 
    * @param evt
-   *                DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   public void mousePressed(MouseEvent evt)
   {
@@ -73,7 +72,12 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
 
     if (av.hasHiddenColumns)
     {
-      res = av.getColumnSelection().adjustForHiddenColumns(x);
+      x = av.getColumnSelection().adjustForHiddenColumns(x);
+    }
+
+    if (x >= av.alignment.getWidth())
+    {
+      res = av.alignment.getWidth() - 1;
     }
     else
     {
@@ -170,7 +174,6 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       iVec = null;
       sg.setStartRes(res);
       sg.setEndRes(res);
-      av.setSelectionGroup(sg);
 
       if (evt.isShiftDown())
       {
@@ -183,7 +186,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
         sg.setStartRes(min);
         sg.setEndRes(max);
       }
-
+      av.setSelectionGroup(sg);
     }
 
     ap.paintAlignment(false);
@@ -194,7 +197,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
    * DOCUMENT ME!
    * 
    * @param evt
-   *                DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   public void mouseReleased(MouseEvent evt)
   {
@@ -202,14 +205,14 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
 
     int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
 
-    if (res > av.alignment.getWidth())
+    if (av.hasHiddenColumns)
     {
-      res = av.alignment.getWidth() - 1;
+      res = av.getColumnSelection().adjustForHiddenColumns(res);
     }
 
-    if (av.hasHiddenColumns)
+    if (res >= av.alignment.getWidth())
     {
-      res = av.getColumnSelection().adjustForHiddenColumns(res);
+      res = av.alignment.getWidth() - 1;
     }
 
     if (!stretchingGroup)
@@ -241,7 +244,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
    * DOCUMENT ME!
    * 
    * @param evt
-   *                DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   public void mouseDragged(MouseEvent evt)
   {
@@ -258,7 +261,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       res = av.getColumnSelection().adjustForHiddenColumns(res);
     }
 
-    if (res > av.alignment.getWidth())
+    if (res >= av.alignment.getWidth())
     {
       res = av.alignment.getWidth() - 1;
     }
@@ -296,7 +299,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       int col;
       for (int i = min; i <= max; i++)
       {
-        col = av.getColumnSelection().adjustForHiddenColumns(i);
+        col = i; // av.getColumnSelection().adjustForHiddenColumns(i);
 
         if ((col < sg.getStartRes()) || (col > sg.getEndRes()))
         {
@@ -352,8 +355,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       {
         reveal = region;
         ToolTipManager.sharedInstance().registerComponent(this);
-        this
-                .setToolTipText("Reveal Hidden Columns with Right Mouse Button");
+        this.setToolTipText("Reveal Hidden Columns with Right Mouse Button");
         break;
       }
       else
@@ -372,7 +374,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
    * DOCUMENT ME!
    * 
    * @param g
-   *                DOCUMENT ME!
+   *          DOCUMENT ME!
    */
   public void paintComponent(Graphics g)
   {
@@ -399,23 +401,33 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
 
     // Fill the selected columns
     ColumnSelection cs = av.getColumnSelection();
-    gg.setColor(new Color(220, 0, 0));
-
-    for (int i = 0; i < cs.size(); i++)
+    int s;
+    if (cs != null)
     {
-      int sel = cs.columnAt(i);
-      if (av.hasHiddenColumns)
-      {
-        sel = av.getColumnSelection().findColumnPosition(sel);
-      }
+      gg.setColor(new Color(220, 0, 0));
 
-      if ((sel >= startx) && (sel <= endx))
+      for (int i = 0; i < cs.size(); i++)
       {
-        gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
-                getHeight());
+        int sel = cs.columnAt(i);
+        if (av.hasHiddenColumns)
+        {
+          if (cs.isVisible(sel))
+          {
+            sel = cs.findColumnPosition(sel);
+          }
+          else
+          {
+            continue;
+          }
+        }
+
+        if ((sel >= startx) && (sel <= endx))
+        {
+          gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
+                  getHeight());
+        }
       }
     }
-
     // Draw the scale numbers
     gg.setColor(Color.black);
 
@@ -444,22 +456,20 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
           maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
         }
 
-        gg
-                .drawLine(
-                        (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
-                        y + 2,
-                        (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
-                        y + (fm.getDescent() * 2));
+        gg.drawLine(
+                (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+                y + 2,
+                (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+                y + (fm.getDescent() * 2));
 
       }
       else
       {
-        gg
-                .drawLine(
-                        (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
-                        y + fm.getDescent(),
-                        (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
-                        y + (fm.getDescent() * 2));
+        gg.drawLine(
+                (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+                y + fm.getDescent(),
+                (int) (((i - startx - 1) * av.charWidth) + (av.charWidth / 2)),
+                y + (fm.getDescent() * 2));
       }
     }