applied 2009 GPL license
[jalview.git] / src / jalview / appletgui / ScalePanel.java
index b938cb8..106d668 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.0.b2)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, 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
@@ -23,20 +23,26 @@ import java.awt.event.*;
 
 import jalview.datamodel.*;
 
-public class ScalePanel
-    extends Panel implements MouseMotionListener, MouseListener
+public class ScalePanel extends Panel implements MouseMotionListener,
+        MouseListener
 {
 
   protected int offy = 4;
+
   public int width;
 
   protected AlignViewport av;
+
   AlignmentPanel ap;
 
   boolean stretchingGroup = false;
-  int min; //used by mouseDragged to see if user
-  int max; //used by mouseDragged to see if user
+
+  int min; // used by mouseDragged to see if user
+
+  int max; // used by mouseDragged to see if user
+
   boolean mouseDragging = false;
+
   int[] reveal;
 
   public ScalePanel(AlignViewport av, AlignmentPanel ap)
@@ -66,8 +72,7 @@ public class ScalePanel
 
     min = res;
     max = res;
-    if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK)
-        == InputEvent.BUTTON3_MASK)
+    if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
     {
       PopupMenu pop = new PopupMenu();
       if (reveal != null)
@@ -118,8 +123,8 @@ public class ScalePanel
           {
             av.hideColumns(res, res);
             if (av.getSelectionGroup() != null
-                &&
-                av.getSelectionGroup().getSize() == av.alignment.getHeight())
+                    && av.getSelectionGroup().getSize() == av.alignment
+                            .getHeight())
             {
               av.setSelectionGroup(null);
             }
@@ -136,7 +141,8 @@ public class ScalePanel
         pop.show(this, evt.getX(), evt.getY());
       }
     }
-    else // LEFT MOUSE TO SELECT
+    else
+    // LEFT MOUSE TO SELECT
     {
       if (!evt.isControlDown() && !evt.isShiftDown())
       {
@@ -263,7 +269,7 @@ public class ScalePanel
       {
         col = av.getColumnSelection().adjustForHiddenColumns(i);
 
-        if ( (col < sg.getStartRes()) || (col > sg.getEndRes()))
+        if ((col < sg.getStartRes()) || (col > sg.getEndRes()))
         {
           av.getColumnSelection().removeElement(col);
         }
@@ -312,8 +318,8 @@ public class ScalePanel
     reveal = null;
     for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
     {
-      int[] region = (int[]) av.getColumnSelection().getHiddenColumns().
-          elementAt(i);
+      int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
+              .elementAt(i);
       if (res + 1 == region[0] || res - 1 == region[1])
       {
         reveal = region;
@@ -332,21 +338,21 @@ public class ScalePanel
   public void paint(Graphics g)
   {
     drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,
-              getSize().height);
+            getSize().height);
   }
 
-// scalewidth will normally be screenwidth,
+  // scalewidth will normally be screenwidth,
   public void drawScale(Graphics gg, int startx, int endx, int width,
-                        int height)
+          int height)
   {
     gg.setFont(av.getFont());
 
-    //Fill in the background
+    // Fill in the background
     gg.setColor(Color.white);
     gg.fillRect(0, 0, width, height);
     gg.setColor(Color.black);
 
-    //Fill the selected columns
+    // Fill the selected columns
     ColumnSelection cs = av.getColumnSelection();
     gg.setColor(new Color(220, 0, 0));
 
@@ -358,10 +364,10 @@ public class ScalePanel
         sel = av.getColumnSelection().findColumnPosition(sel);
       }
 
-      if ( (sel >= startx) && (sel <= endx))
+      if ((sel >= startx) && (sel <= endx))
       {
-        gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth,
-                    getSize().height);
+        gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
+                getSize().height);
       }
     }
 
@@ -373,7 +379,7 @@ public class ScalePanel
     FontMetrics fm = gg.getFontMetrics(av.getFont());
     int y = av.charHeight - fm.getDescent();
 
-    if ( (scalestartx % 10) == 0)
+    if ((scalestartx % 10) == 0)
     {
       scalestartx += 5;
     }
@@ -383,30 +389,32 @@ public class ScalePanel
 
     for (int i = scalestartx; i < endx; i += 5)
     {
-      if ( (i % 10) == 0)
+      if ((i % 10) == 0)
       {
-        string = String.valueOf(av.getColumnSelection().adjustForHiddenColumns(
-            i));
-        if ( (i - startx - 1) * av.charWidth > maxX)
+        string = String.valueOf(av.getColumnSelection()
+                .adjustForHiddenColumns(i));
+        if ((i - startx - 1) * av.charWidth > maxX)
         {
-          gg.drawString(string,
-                        (i - startx - 1) * av.charWidth, y);
+          gg.drawString(string, (i - startx - 1) * av.charWidth, y);
           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));
       }
     }
 
@@ -416,12 +424,12 @@ public class ScalePanel
       int res;
       if (av.getShowHiddenMarkers())
       {
-        for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size();
-             i++)
+        for (int i = 0; i < av.getColumnSelection().getHiddenColumns()
+                .size(); i++)
         {
 
-          res = av.getColumnSelection().findHiddenRegionPosition(i) -
-              startx;
+          res = av.getColumnSelection().findHiddenRegionPosition(i)
+                  - startx;
 
           if (res < 0 || res > endx - scalestartx)
           {
@@ -429,14 +437,11 @@ public class ScalePanel
           }
 
           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);
+          { 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);
 
         }
       }