package jalview.gui; import java.awt.*; import javax.swing.*; public class ScaleCanvas extends JPanel { int xoffset; public static final int HEIGHT = 30; boolean paintFlag = false; protected AlignViewport av; public ScaleCanvas(AlignViewport av) { this.av = av; } 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(); gg.setFont(av.getFont()); //Fill in the background gg.setColor(Color.white); gg.fillRect(0,0,scaleWidth, HEIGHT); int resWidth = endx - startx + 1; // We want roughly one tick every 50 pixels 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) num = 10; else if (Math.abs(5-num) >= 2) num = 5; // else // num = 2; //System.out.println("Dig " + digits + " " + rough + " " + roughtick + " " + getWidth() + " " + num); int space = (int)(num * Math.pow(10,digits)); //Set the text font gg.setColor(Color.black); int scalestartx = startx - startx%space + space; //Fill the selected columns ColumnSelection cs = av.getColumnSelection(); int width = charWidth; if (width == 0) width = 1; gg.setColor(new Color(220,0,0)); for (int i=0; i