1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.foRenderer.figures;
13
14 import org.eclipse.draw2d.ColorConstants;
15 import org.eclipse.draw2d.Graphics;
16 import org.eclipse.draw2d.IFigure;
17 import org.eclipse.draw2d.LineBorder;
18 import org.eclipse.draw2d.geometry.Insets;
19 import org.eclipse.swt.graphics.Color;
20
21 /***
22 * @author TV Created on 12.12.2004
23 *
24 */
25 public class LineRuleBorder extends LineBorder {
26
27 public static final double DPI = 96;
28
29 public static final double PX2CM = DPI / 2.54f;
30
31
32
33
34
35 private Color rulerColor = ColorConstants.white;
36
37 private Color innerRulerBorder = ColorConstants.lightGray;
38
39 public LineRuleBorder() {
40
41 super(ColorConstants.buttonDarker, 10);
42 }
43
44 public void paint(IFigure figure, Graphics g, Insets insets) {
45 super.paint(figure, g, insets);
46
47 tempRect.setBounds(getPaintRectangle(figure, insets));
48
49
50 g.setForegroundColor(rulerColor);
51 g.setLineWidth(1);
52 g.translate(tempRect.getLocation());
53
54 int w = getWidth();
55 float x = w;
56 int xCoord = Math.round(x);
57 while (xCoord <= tempRect.width) {
58 g.drawLine(xCoord, 0, xCoord, w - 1);
59 g.drawLine(xCoord, tempRect.height - w, xCoord,
60 tempRect.height - 1);
61 x += PX2CM;
62 xCoord = Math.round(x);
63 }
64
65
66 float y = w;
67 int yCoord = Math.round(y);
68 while (yCoord <= tempRect.height) {
69 g.drawLine(0, yCoord, w - 1, yCoord);
70 g.drawLine(tempRect.width - w, yCoord, tempRect.width - 1, yCoord);
71 y += PX2CM;
72 yCoord = Math.round(y);
73 }
74
75 g.setForegroundColor(innerRulerBorder);
76 g.setLineWidth(2);
77 g.drawRectangle(w-1, w-1, tempRect.width - 2*w,
78 tempRect.height - 2*w);
79
80 g.translate(tempRect.getLocation().getNegated());
81
82 }
83
84 }