\r
public void paintComponent(Graphics g)\r
{\r
- drawScale(g, av.getStartRes(), av.getEndRes(), getWidth());\r
+ drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight());\r
}\r
\r
// scalewidth will normally be screenwidth,\r
- public void drawScale(Graphics g, int startx, int endx, int scaleWidth)\r
+ public void drawScale(Graphics g, int startx, int endx, int width, int height)\r
{\r
Graphics2D gg = (Graphics2D)g;\r
- gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);\r
- int charWidth = av.getCharWidth();\r
-\r
gg.setFont(av.getFont());\r
+ gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);\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 (roughtick>5)\r
- num = 10;\r
- else\r
- num = 5;\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
-\r
- //Set the text font\r
-\r
+ gg.fillRect(0,0,width, height);\r
gg.setColor(Color.black);\r
\r
\r
- int scalestartx = 0;\r
- if(space>0)\r
- 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
+ for (int i=0; i<cs.size(); i++)\r
+ {\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
+ if ( sel >= startx && sel <= endx)\r
+ gg.fillRect((sel-startx)*av.charWidth,0,av.charWidth,getHeight());\r
}\r
\r
+\r
// Draw the scale numbers\r
gg.setColor(Color.black);\r
+ int scalestartx = (startx/10) * 10;\r
\r
+ FontMetrics fm = gg.getFontMetrics(av.getFont());\r
+ int y = av.charHeight -fm.getDescent();\r
\r
- for (int i=scalestartx;i < endx;i+= space) {\r
+ if(scalestartx%10==0)\r
+ scalestartx+=5;\r
\r
- String string = String.valueOf(i);\r
+ for (int i=scalestartx;i < endx; i+= 5)\r
+ {\r
+ if(i%10==0)\r
+ {\r
+ gg.drawString(String.valueOf(i), (i - startx - 1) * av.charWidth, y);\r
+ gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
+ y+2,\r
+ (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
+ y+fm.getDescent()*2);\r
+ }\r
+ else\r
+ gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
+ y+fm.getDescent(),\r
+ (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),\r
+ y+fm.getDescent()*2);\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