JAL-1989 more unit tests and encapsulation for ColumnSelection
[jalview.git] / src / jalview / gui / ScalePanel.java
index bc5ec3d..10963b6 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -84,6 +84,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mousePressed(MouseEvent evt)
   {
     int x = (evt.getX() / av.getCharWidth()) + av.getStartRes();
@@ -115,6 +116,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
                 MessageManager.getString("label.reveal"));
         item.addActionListener(new ActionListener()
         {
+          @Override
           public void actionPerformed(ActionEvent e)
           {
             av.showColumn(reveal[0]);
@@ -134,6 +136,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
                   MessageManager.getString("action.reveal_all"));
           item.addActionListener(new ActionListener()
           {
+            @Override
             public void actionPerformed(ActionEvent e)
             {
               av.showAllHiddenColumns();
@@ -155,6 +158,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
                 MessageManager.getString("label.hide_columns"));
         item.addActionListener(new ActionListener()
         {
+          @Override
           public void actionPerformed(ActionEvent e)
           {
             av.hideColumns(res, res);
@@ -170,6 +174,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
             {
               ap.overviewPanel.updateOverviewImage();
             }
+            av.sendSelection();
           }
         });
         pop.add(item);
@@ -221,6 +226,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mouseReleased(MouseEvent evt)
   {
     mouseDragging = false;
@@ -268,6 +274,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mouseDragged(MouseEvent evt)
   {
     mouseDragging = true;
@@ -337,6 +344,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
     }
   }
 
+  @Override
   public void mouseEntered(MouseEvent evt)
   {
     if (mouseDragging)
@@ -345,6 +353,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
     }
   }
 
+  @Override
   public void mouseExited(MouseEvent evt)
   {
     if (mouseDragging)
@@ -353,10 +362,12 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
     }
   }
 
+  @Override
   public void mouseClicked(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseMoved(MouseEvent evt)
   {
     if (!av.hasHiddenColumns())
@@ -398,6 +409,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
    * @param g
    *          DOCUMENT ME!
    */
+  @Override
   public void paintComponent(Graphics g)
   {
     drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight());
@@ -423,14 +435,15 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
 
     // Fill the selected columns
     ColumnSelection cs = av.getColumnSelection();
+    int avCharWidth = av.getCharWidth(), avCharHeight = av.getCharHeight();
+
     int s;
     if (cs != null)
     {
       gg.setColor(new Color(220, 0, 0));
 
-      for (int i = 0; i < cs.size(); i++)
+      for (int sel : cs.getSelected())
       {
-        int sel = cs.columnAt(i);
         if (av.hasHiddenColumns())
         {
           if (cs.isVisible(sel))
@@ -445,7 +458,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
 
         if ((sel >= startx) && (sel <= endx))
         {
-          gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
+          gg.fillRect((sel - startx) * avCharWidth, 0, avCharWidth,
                   getHeight());
         }
       }
@@ -456,7 +469,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
     int scalestartx = (startx / 10) * 10;
 
     FontMetrics fm = gg.getFontMetrics(av.getFont());
-    int y = av.charHeight - fm.getDescent();
+    int y = avCharHeight - fm.getDescent();
 
     if ((scalestartx % 10) == 0)
     {
@@ -472,26 +485,22 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       {
         string = String.valueOf(av.getColumnSelection()
                 .adjustForHiddenColumns(i));
-        if ((i - startx - 1) * av.charWidth > maxX)
+        if ((i - startx - 1) * avCharWidth > maxX)
         {
-          gg.drawString(string, (i - startx - 1) * av.charWidth, y);
-          maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
+          gg.drawString(string, (i - startx - 1) * avCharWidth, y);
+          maxX = (i - startx + 1) * avCharWidth + fm.stringWidth(string);
         }
 
-        gg.drawLine(
-                ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
+        gg.drawLine(((i - startx - 1) * avCharWidth) + (avCharWidth / 2),
                 y + 2,
-                ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
-                y + (fm.getDescent() * 2));
-
+                ((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y
+                        + (fm.getDescent() * 2));
       }
       else
       {
-        gg.drawLine(
-                ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
-                y + fm.getDescent(),
-                ((i - startx - 1) * av.charWidth) + (av.charWidth / 2),
-                y + (fm.getDescent() * 2));
+        gg.drawLine(((i - startx - 1) * avCharWidth) + (avCharWidth / 2), y
+                + fm.getDescent(), ((i - startx - 1) * avCharWidth)
+                + (avCharWidth / 2), y + (fm.getDescent() * 2));
       }
     }
 
@@ -514,12 +523,10 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
             continue;
           }
 
-          gg.fillPolygon(new int[]
-          { res * av.charWidth - av.charHeight / 4,
-              res * av.charWidth + av.charHeight / 4, res * av.charWidth },
-                  new int[]
-                  { y - av.charHeight / 2, y - av.charHeight / 2, y + 8 },
-                  3);
+          gg.fillPolygon(new int[] { res * avCharWidth - avCharHeight / 4,
+              res * avCharWidth + avCharHeight / 4, res * avCharWidth },
+                  new int[] { y - avCharHeight / 2, y - avCharHeight / 2,
+                      y + 8 }, 3);
 
         }
       }
@@ -527,7 +534,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       if (reveal != null && reveal[0] > startx && reveal[0] < endx)
       {
         gg.drawString(MessageManager.getString("label.reveal_columns"),
-                reveal[0] * av.charWidth, 0);
+                reveal[0] * avCharWidth, 0);
       }
     }