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