+++ /dev/null
-package jalview.gui;\r
-\r
-import java.awt.*;\r
-import javax.swing.*;\r
-\r
-public class ScaleCanvas extends JPanel {\r
-\r
- int xoffset;\r
-\r
- public static final int HEIGHT = 30;\r
-\r
- boolean paintFlag = false;\r
-\r
- protected AlignViewport av;\r
-\r
- public ScaleCanvas(AlignViewport av) {\r
- this.av = av;\r
-\r
- }\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
- gg.setFont(av.getFont());\r
-\r
- //Fill in the background\r
-\r
- gg.setColor(Color.white);\r
- gg.fillRect(0,0,scaleWidth, HEIGHT);\r
-\r
- int resWidth = endx - startx + 1;\r
-\r
- // We want roughly one tick every 50 pixels\r
-\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
- num = 10;\r
- else if (Math.abs(5-num) >= 2)\r
- num = 5;\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
-\r
- //Set the text font\r
-\r
- gg.setColor(Color.black);\r
-\r
- int scalestartx = startx - startx%space + space;\r
-\r
-\r
- //Fill the selected columns\r
- ColumnSelection cs = av.getColumnSelection();\r
- int width = charWidth;\r
- if (width == 0)\r
- width = 1;\r
-\r
- gg.setColor(new Color(220,0,0));\r
- for (int i=0; i<cs.size(); i++) {\r
- int sel = cs.columnAt(i);\r
- // System.out.println("Selection = " + sel);\r
- if ( sel >= startx && sel <= endx) {\r
-\r
- gg.fillRect((sel-startx)*charWidth,0,width,getHeight());\r
- }\r
- }\r
-\r
- // Draw the scale numbers\r
- gg.setColor(Color.black);\r
-\r
-\r
- for (int i=scalestartx;i < endx;i+= space) {\r
-\r
- String string = String.valueOf(i);\r
-\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
- }\r
-\r
- public Dimension getMinimumSize() {\r
- return new Dimension(500,HEIGHT);\r
- }\r
-\r
- public Dimension getPreferredSize() {\r
- return getMinimumSize();\r
- }\r
-\r
-}\r
-\r
public class ScalePanel extends JPanel\r
{\r
\r
- protected ScaleCanvas scaleCanvas;\r
-\r
- protected int offy;\r
+ protected int offy = 4;\r
public int width;\r
\r
protected AlignViewport av;\r
this.av = av;\r
this.ap = ap;\r
\r
- scaleCanvas = new ScaleCanvas(av);\r
- setLayout(new BorderLayout());\r
- add(scaleCanvas, BorderLayout.CENTER);\r
addMouseListener(new MouseAdapter()\r
{\r
public void mousePressed(MouseEvent evt)\r
\r
}\r
\r
- public Dimension getMinimumSize() {\r
- return scaleCanvas.getMinimumSize();\r
- }\r
-\r
- public Dimension getPreferredSize() {\r
- return scaleCanvas.getPreferredSize();\r
- }\r
\r
public void doMousePressed(MouseEvent evt) {\r
int x = evt.getX();\r
\r
ap.RefreshPanels();\r
}\r
+ }\r
+\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
+ int charWidth = av.getCharWidth();\r
+\r
+ gg.setFont(av.getFont());\r
+\r
+ //Fill in the background\r
+\r
+ gg.setColor(Color.white);\r
+ gg.fillRect(0,0,scaleWidth, getHeight());\r
+\r
+ int resWidth = endx - startx + 1;\r
+\r
+ // We want roughly one tick every 50 pixels\r
+\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
+ num = 10;\r
+ else if (Math.abs(5-num) >= 2)\r
+ num = 5;\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
+\r
+ //Set the text font\r
+\r
+ gg.setColor(Color.black);\r
+\r
+ int scalestartx = startx - startx%space + space;\r
+\r
+\r
+ //Fill the selected columns\r
+ ColumnSelection cs = av.getColumnSelection();\r
+ int width = charWidth;\r
+ if (width == 0)\r
+ width = 1;\r
+\r
+ gg.setColor(new Color(220,0,0));\r
+ for (int i=0; i<cs.size(); i++) {\r
+ int sel = cs.columnAt(i);\r
+ // System.out.println("Selection = " + sel);\r
+ if ( sel >= startx && sel <= endx) {\r
+\r
+ gg.fillRect((sel-startx)*charWidth,0,width,getHeight());\r
+ }\r
+ }\r
+\r
+ // Draw the scale numbers\r
+ gg.setColor(Color.black);\r
+\r
+\r
+ for (int i=scalestartx;i < endx;i+= space) {\r
+\r
+ String string = String.valueOf(i);\r
\r
+ gg.drawString(string,(i-startx-1)*charWidth, av.charHeight / 2 +offy);\r
+ gg.drawLine( (int)((i-startx-1)*charWidth +charWidth/2), av.charHeight/2 +offy +2, (int)((i-startx-1)*charWidth +charWidth/2),av.charHeight/2 +offy+7);\r
+\r
+ }\r
}\r
+\r
+\r
}\r