1
22package ee.ut.mrz.volumest;
23
24import java.awt.Canvas;
25import java.awt.Color;
26import java.awt.Graphics;
27
28
33public class Ruler extends Canvas {
34
35 private String orientation;
36 private Volumest vol;
37
38
39 public Ruler(String s, Volumest vol) {
40 super();
41 this.orientation = s;
42 this.vol = vol;
43 this.setBackground(Color.BLACK);
44 }
45
46 @Override
47 public void paint(Graphics g) {
48 Double height = getSize().getHeight();
49 Double width = getSize().getWidth();
50
51 g.setColor(Color.WHITE);
52
53 double horizontalWidthInUnits = vol.getImp().getWidth() * vol.getImp().getCalibration().pixelWidth;
54 double verticalHeightInUnits = vol.getImp().getHeight() * vol.getImp().getCalibration().pixelHeight;
55
56 double horizontalScale = Math.pow(10, Math.floor(Math.log10(horizontalWidthInUnits)) - 1);
57 double verticalScale = Math.pow(10, Math.floor(Math.log10(verticalHeightInUnits)) - 1);
58
59
60 int counttofive = 0;
61 if (orientation.equals("upper")) {
62 for (double c = 0; c < horizontalWidthInUnits * horizontalScale; c = c + 1 * horizontalScale) {
63 int x = (int) Math.round(c / vol.getImp().getCalibration().pixelWidth * vol.getImageZoomFactor());
64 int h = (int) Math.floor(height);
65 if (counttofive % 10 == 0) {
66 g.drawLine(x, 0, x, h);
67 } else if (counttofive % 10 == 5) {
68 g.drawLine(x, h / 6, x, h);
69 } else {
70 g.drawLine(x, h / 3, x, h);
71 }
72 counttofive++;
73 }
74 } else if (orientation.equals("lower")) {
75 for (double c = 0; c < horizontalWidthInUnits * horizontalScale; c = c + 1 * horizontalScale) {
76 int x = (int) Math.round(c / vol.getImp().getCalibration().pixelWidth * vol.getImageZoomFactor());
77 int h = (int) Math.floor(height);
78 if (counttofive % 10 == 0) {
79 g.drawLine(x, 0, x, h);
80 } else if (counttofive % 10 == 5) {
81 g.drawLine(x, 0, x, 2 * h / 3);
82 } else {
83 g.drawLine(x, 0, x, h / 3);
84 }
85 counttofive++;
86 }
87 } else if (orientation.equals("right")) {
88 for (double c = 0; c < verticalHeightInUnits * verticalScale; c = c + 1 * verticalScale) {
89 int y = (int) Math.round(c / vol.getImp().getCalibration().pixelHeight * vol.getImageZoomFactor());
90 int h = (int) Math.floor(width);
91 if (counttofive % 10 == 0) {
92 g.drawLine(0, y, h, y);
93 } else if (counttofive % 10 == 5) {
94 g.drawLine(0, y, 2 * h / 3, y);
95 } else {
96 g.drawLine(0, y, h / 3, y);
97 }
98 counttofive++;
99 }
00 } else if (orientation.equals("left")) {
01 for (double c = 0; c < verticalHeightInUnits * verticalScale; c = c + 1 * verticalScale) {
02 int y = (int) Math.round(c / vol.getImp().getCalibration().pixelHeight * vol.getImageZoomFactor());
03 int h = (int) Math.floor(width);
04 if (counttofive % 10 == 0) {
05 g.drawLine(0, y, h, y);
06 } else if (counttofive % 10 == 5) {
07 g.drawLine(h / 6, y, h, y);
08 } else {
09 g.drawLine(h / 3, y, h, y);
10 }
11 counttofive++;
12 }
13 }
14
15
16 }
17}
18