1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.layout;
20
21 import java.awt.BasicStroke;
22 import java.awt.Color;
23 import java.awt.Graphics2D;
24 import java.awt.Stroke;
25 import java.awt.geom.Line2D;
26
27
28
29
30 public class LineObject implements GraphicsObject {
31
32 private final float x1;
33
34 private final float y1;
35
36 private final float x2;
37
38 private final float y2;
39
40 private final float width;
41
42 private final Color col;
43
44 private final boolean dash;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 public LineObject(final float offsetX, final float offsetY,
63 final float offsetX2, final float offsetY2, final float lineWidth,
64 final Color color) {
65 this.x1 = offsetX;
66 this.y1 = offsetY;
67 this.x2 = offsetX2;
68 this.y2 = offsetY2;
69 this.width = lineWidth;
70 this.col = color;
71 this.dash = false;
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 public LineObject(final float offsetX, final float offsetY,
93 final float offsetX2, final float offsetY2, final float lineWidth,
94 final Color color, final boolean dashed) {
95 this.x1 = offsetX;
96 this.y1 = offsetY;
97 this.x2 = offsetX2;
98 this.y2 = offsetY2;
99 this.width = lineWidth;
100 this.col = color;
101 this.dash = dashed;
102 }
103
104
105 public void paint(final float x, final float y, final Graphics2D g) {
106 g.setColor(this.col);
107 final Stroke oldStroke = g.getStroke();
108 if (this.dash) {
109 final float dashWidth = 3.0f * this.width;
110 g.setStroke(new BasicStroke(this.width, BasicStroke.CAP_SQUARE,
111 BasicStroke.JOIN_BEVEL, this.width, new float[] {
112 dashWidth, dashWidth, }, 0));
113 } else {
114 g.setStroke(new BasicStroke(this.width));
115 }
116 g.draw(new Line2D.Float(x + this.x1, y + this.y1, x + this.x2, y
117 + this.y2));
118 g.setStroke(oldStroke);
119
120 }
121 }