From 05d637d6b2e5aa0555f28f351b2d65001c9bcf09 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 18 Nov 2004 18:41:08 +0000 Subject: [PATCH] allow for printing --- src/jalview/gui/ScaleCanvas.java | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/jalview/gui/ScaleCanvas.java b/src/jalview/gui/ScaleCanvas.java index 090b272..4a0bd2a 100755 --- a/src/jalview/gui/ScaleCanvas.java +++ b/src/jalview/gui/ScaleCanvas.java @@ -22,17 +22,23 @@ public class ScaleCanvas extends JPanel { this.av = av; } - public void paintComponent(Graphics g) { + public void paintComponent(Graphics g) + { + drawScale(g, av.getStartRes(), av.getEndRes(), getWidth()); + } + +// scalewidth will normally be screenwidth, + public void drawScale(Graphics g, int startx, int endx, int scaleWidth) + { - double charWidth = av.getCharWidth(); - int charHeight = av.getCharHeight(); + double charWidth = av.getCharWidth(); if (img == null || - imgWidth != getWidth() || + imgWidth != scaleWidth || imgHeight != getHeight() || paintFlag == true) { - imgWidth = getWidth(); + imgWidth = scaleWidth; imgHeight = getHeight(); img = createImage(imgWidth,imgHeight); @@ -51,26 +57,24 @@ public class ScaleCanvas extends JPanel { gg.setColor(Color.white); gg.fillRect(0,0,imgWidth,imgHeight); - int tickSpace; - - 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,8 +83,6 @@ public class ScaleCanvas extends JPanel { gg.setColor(Color.black); - int startx = av.getStartRes(); - int endx = av.getEndRes(); int scalestartx = startx - startx%space + space; -- 1.7.10.2