Formatted source
[jalview.git] / src / jalview / appletgui / ScalePanel.java
index 24460ba..71d360d 100755 (executable)
@@ -1,33 +1,35 @@
 /*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
-*/\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 \r
 package jalview.appletgui;\r
 \r
-import jalview.datamodel.*;\r
 import java.awt.*;\r
 import java.awt.event.*;\r
 \r
-public class ScalePanel extends Panel\r
+import jalview.datamodel.*;\r
+\r
+public class ScalePanel\r
+    extends Panel\r
 {\r
 \r
   protected int offy = 4;\r
-  public    int width;\r
+  public int width;\r
 \r
   protected AlignViewport av;\r
   AlignmentPanel ap;\r
@@ -37,7 +39,7 @@ public class ScalePanel extends Panel
   public ScalePanel(AlignViewport av, AlignmentPanel ap)\r
   {\r
     setLayout(null);\r
-    this.av         = av;\r
+    this.av = av;\r
     this.ap = ap;\r
 \r
     addMouseListener(new MouseAdapter()\r
@@ -46,6 +48,7 @@ public class ScalePanel extends Panel
       {\r
         doMousePressed(evt);\r
       }\r
+\r
       public void mouseReleased(MouseEvent evt)\r
       {\r
         doMouseReleased(evt);\r
@@ -62,21 +65,25 @@ public class ScalePanel extends Panel
 \r
   }\r
 \r
-\r
-  public void doMousePressed(MouseEvent evt) {\r
+  public void doMousePressed(MouseEvent evt)\r
+  {\r
     int x = evt.getX();\r
-    int res = x/av.getCharWidth() + av.getStartRes();\r
+    int res = x / av.getCharWidth() + av.getStartRes();\r
     SequenceGroup sg = null;\r
 \r
     if (av.getColumnSelection().contains(res))\r
+    {\r
       av.getColumnSelection().removeElement(res);\r
+    }\r
     else\r
     {\r
       av.getColumnSelection().addElement(res);\r
 \r
       sg = new SequenceGroup();\r
       for (int i = 0; i < av.alignment.getSequences().size(); i++)\r
+      {\r
         sg.addSequence(av.alignment.getSequenceAt(i));\r
+      }\r
 \r
       sg.setStartRes(res);\r
       sg.setEndRes(res);\r
@@ -89,41 +96,53 @@ public class ScalePanel extends Panel
 \r
   public void doMouseReleased(MouseEvent evt)\r
   {\r
-    if(!stretchingGroup)\r
+    if (!stretchingGroup)\r
+    {\r
       return;\r
+    }\r
 \r
     int x = evt.getX();\r
-    int res = x/av.getCharWidth() + av.getStartRes();\r
+    int res = x / av.getCharWidth() + av.getStartRes();\r
 \r
-   if (! av.getColumnSelection().contains(res))\r
-     av.getColumnSelection().addElement(res);\r
+    if (!av.getColumnSelection().contains(res))\r
+    {\r
+      av.getColumnSelection().addElement(res);\r
+    }\r
 \r
-   SequenceGroup sg = av.getSelectionGroup();\r
+    SequenceGroup sg = av.getSelectionGroup();\r
 \r
-   if(res>sg.getStartRes())\r
-     sg.setEndRes(res);\r
-   else if(res<sg.getStartRes())\r
-     sg.setStartRes(res);\r
+    if (res > sg.getStartRes())\r
+    {\r
+      sg.setEndRes(res);\r
+    }\r
+    else if (res < sg.getStartRes())\r
+    {\r
+      sg.setStartRes(res);\r
+    }\r
 \r
-   stretchingGroup = false;\r
-   ap.repaint();\r
+    stretchingGroup = false;\r
+    ap.repaint();\r
   }\r
 \r
   public void doMouseDragged(MouseEvent evt)\r
   {\r
     int x = evt.getX();\r
-    int res = x/av.getCharWidth() + av.getStartRes();\r
+    int res = x / av.getCharWidth() + av.getStartRes();\r
 \r
     SequenceGroup sg = av.getSelectionGroup();\r
-    if(sg!=null)\r
+    if (sg != null)\r
     {\r
       stretchingGroup = true;\r
       if (res > sg.getStartRes())\r
+      {\r
         sg.setEndRes(res);\r
+      }\r
       else if (res < sg.getStartRes())\r
+      {\r
         sg.setStartRes(res);\r
+      }\r
 \r
-       ap.annotationPanel.addEditableColumn(res);\r
+      ap.annotationPanel.addEditableColumn(res);\r
       ap.repaint();\r
     }\r
   }\r
@@ -135,60 +154,65 @@ public class ScalePanel extends Panel
 \r
   public void paint(Graphics g)\r
   {\r
-    drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width, getSize().height);\r
+    drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,\r
+              getSize().height);\r
   }\r
 \r
 // scalewidth will normally be screenwidth,\r
-  public void drawScale(Graphics gg, int startx, int endx, int width, int height)\r
+  public void drawScale(Graphics gg, int startx, int endx, int width,\r
+                        int height)\r
   {\r
     gg.setFont(av.getFont());\r
 \r
     //Fill in the background\r
     gg.setColor(Color.white);\r
-    gg.fillRect(0,0,width, height);\r
+    gg.fillRect(0, 0, width, height);\r
     gg.setColor(Color.black);\r
 \r
-\r
     //Fill the selected columns\r
     ColumnSelection cs = av.getColumnSelection();\r
-    gg.setColor(new Color(220,0,0));\r
-    for (int i=0; i<cs.size(); i++)\r
+    gg.setColor(new Color(220, 0, 0));\r
+    for (int i = 0; i < cs.size(); i++)\r
     {\r
-      int sel  = cs.columnAt(i);\r
-      if ( sel >= startx  && sel <= endx)\r
-        gg.fillRect((sel-startx)*av.charWidth,0,av.charWidth, getSize().height);\r
+      int sel = cs.columnAt(i);\r
+      if (sel >= startx && sel <= endx)\r
+      {\r
+        gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth,\r
+                    getSize().height);\r
+      }\r
     }\r
 \r
-\r
     // Draw the scale numbers\r
     gg.setColor(Color.black);\r
-    int scalestartx = (startx/10) * 10;\r
+    int scalestartx = (startx / 10) * 10;\r
 \r
     FontMetrics fm = gg.getFontMetrics(av.getFont());\r
-    int y = av.charHeight -fm.getDescent();\r
+    int y = av.charHeight - fm.getDescent();\r
 \r
-    if(scalestartx%10==0)\r
-      scalestartx+=5;\r
+    if (scalestartx % 10 == 0)\r
+    {\r
+      scalestartx += 5;\r
+    }\r
 \r
-    for (int i=scalestartx;i < endx; i+= 5)\r
+    for (int i = scalestartx; i < endx; i += 5)\r
     {\r
-      if(i%10==0)\r
+      if (i % 10 == 0)\r
       {\r
         gg.drawString(String.valueOf(i), (i - startx - 1) * av.charWidth, y);\r
         gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
-                    y+2,\r
+                    y + 2,\r
                     (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
-                    y+fm.getDescent()*2);\r
+                    y + fm.getDescent() * 2);\r
       }\r
       else\r
+      {\r
         gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
-                    y+fm.getDescent(),\r
+                    y + fm.getDescent(),\r
                     (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
-                   y+fm.getDescent()*2);\r
-\r
+                    y + fm.getDescent() * 2);\r
+      }\r
 \r
     }\r
   }\r
 \r
-\r
 }\r