don't system.ext
[jalview.git] / src / jalview / gui / ScaleCanvas.java
index 090b272..d708248 100755 (executable)
@@ -5,11 +5,6 @@ import javax.swing.*;
 \r
 public class ScaleCanvas extends JPanel {\r
 \r
-  Image    img;\r
-  Graphics gg;\r
-\r
-  int      imgWidth;\r
-  int      imgHeight;\r
   int      xoffset;\r
 \r
   public static final int HEIGHT = 30;\r
@@ -22,55 +17,42 @@ public class ScaleCanvas extends JPanel {
     this.av         = av;\r
 \r
   }\r
-  public void paintComponent(Graphics g) {\r
-\r
-   double charWidth  = av.getCharWidth();\r
-    int charHeight = av.getCharHeight();\r
-\r
-    if (img == null ||\r
-        imgWidth  != getWidth()  ||\r
-        imgHeight != getHeight() ||\r
-        paintFlag == true) {\r
-\r
-      imgWidth  = getWidth();\r
-      imgHeight = getHeight();\r
-      img       = createImage(imgWidth,imgHeight);\r
-\r
-      gg = img.getGraphics();\r
-      gg.setColor(Color.white);\r
-      gg.fillRect(0,0,imgWidth,imgHeight);\r
+  public void paintComponent(Graphics g)\r
+  {\r
+    drawScale(g, av.getStartRes(), av.getEndRes(), getWidth());\r
+  }\r
 \r
+// scalewidth will normally be screenwidth,\r
+  public void drawScale(Graphics gg, int startx, int endx, int scaleWidth)\r
+  {\r
 \r
+    int charWidth  = av.getCharWidth();\r
 \r
-      paintFlag = false;\r
-    }\r
     gg.setFont(av.getFont());\r
 \r
     //Fill in the background\r
 \r
     gg.setColor(Color.white);\r
-    gg.fillRect(0,0,imgWidth,imgHeight);\r
-\r
-    int tickSpace;\r
+    gg.fillRect(0,0,scaleWidth, HEIGHT);\r
 \r
-    int resWidth = av.getEndRes() - av.getStartRes() + 1;\r
+    int resWidth = endx - startx + 1;\r
 \r
     // We want roughly one tick every 50 pixels\r
 \r
-    double rough = getWidth()/50.0;\r
+    double rough = scaleWidth/50.0;\r
 \r
     double roughtick = resWidth/rough;\r
 \r
     int   digits  = (int)(Math.log(roughtick)/Math.log(10));\r
     int   num     = (int)(roughtick/Math.pow(10,digits));\r
 \r
-    if (Math.abs(10-num) < 3) {\r
+    if (Math.abs(10-num) < 3)\r
         num = 10;\r
-    } else if (Math.abs(5-num) <= 2) {\r
+    else if (Math.abs(5-num) >= 2)\r
         num = 5;\r
-    } else {\r
-        num = 2;\r
-    }\r
+  //   else\r
+  //  num = 2;\r
+\r
     //System.out.println("Dig " + digits + " " + rough + " " + roughtick + " " + getWidth() + " " + num);\r
 \r
     int space = (int)(num * Math.pow(10,digits));\r
@@ -79,14 +61,12 @@ public class ScaleCanvas extends JPanel {
 \r
     gg.setColor(Color.black);\r
 \r
-    int startx      = av.getStartRes();\r
-    int endx        = av.getEndRes();\r
     int scalestartx = startx - startx%space + space;\r
 \r
 \r
     //Fill the selected columns\r
     ColumnSelection cs = av.getColumnSelection();\r
-    int width = (int)charWidth;\r
+    int width = charWidth;\r
     if (width == 0)\r
       width = 1;\r
 \r
@@ -96,7 +76,7 @@ public class ScaleCanvas extends JPanel {
       //      System.out.println("Selection = " + sel);\r
       if ( sel >= startx  && sel <= endx) {\r
 \r
-        gg.fillRect((int)((sel-startx)*charWidth),0,width,getHeight());\r
+        gg.fillRect((sel-startx)*charWidth,0,width,getHeight());\r
       }\r
     }\r
 \r
@@ -108,14 +88,12 @@ public class ScaleCanvas extends JPanel {
 \r
       String string = String.valueOf(i);\r
 \r
-      gg.drawString(string,(int)((i-startx-1)*charWidth),15);\r
+      gg.drawString(string,(i-startx-1)*charWidth,15);\r
       gg.drawLine( (int)((i-startx-1)*charWidth +charWidth/2), 17, (int)((i-startx-1)*charWidth +charWidth/2), 24);\r
 \r
     }\r
 \r
 \r
-    g.drawImage(img,0,0,this);\r
-\r
   }\r
 \r
   public Dimension getMinimumSize() {\r