|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| package org.ericmignot.modeler.util.graphic; |
|
20 |
| |
|
21 |
| import java.awt.*; |
|
22 |
| import javax.swing.border.*; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| public class DashedLineBorder extends LineBorder |
|
28 |
| { |
|
29 |
| private float[] dashedPattern; |
|
30 |
| private int arcWidth; |
|
31 |
| |
|
32 |
| static private float[] defaultDashPattern = new float[]{5.0f, 5.0f}; |
|
33 |
| static private int defaultThickness = 1; |
|
34 |
| static private boolean defaultRoundedCorners = true; |
|
35 |
| static private int defaultArcWidth = 20; |
|
36 |
| |
|
37 |
0
| public DashedLineBorder(Color color)
|
|
38 |
| { |
|
39 |
0
| this(color, defaultThickness, defaultDashPattern, defaultRoundedCorners, defaultArcWidth);
|
|
40 |
| } |
|
41 |
| |
|
42 |
0
| public DashedLineBorder(Color color, boolean roundedCorners)
|
|
43 |
| { |
|
44 |
0
| this(color, defaultThickness, defaultDashPattern, roundedCorners, defaultArcWidth);
|
|
45 |
| } |
|
46 |
| |
|
47 |
0
| public DashedLineBorder(Color color, boolean roundedCorners, int arcWidth)
|
|
48 |
| { |
|
49 |
0
| this(color, defaultThickness, defaultDashPattern, roundedCorners, arcWidth);
|
|
50 |
| } |
|
51 |
| |
|
52 |
0
| public DashedLineBorder(Color color, float[] dashPattern)
|
|
53 |
| { |
|
54 |
0
| this(color, defaultThickness, dashPattern, defaultRoundedCorners, defaultArcWidth);
|
|
55 |
| } |
|
56 |
| |
|
57 |
0
| public DashedLineBorder(Color color, int thickness, float[] dashPattern)
|
|
58 |
| { |
|
59 |
0
| this(color, thickness, dashPattern, defaultRoundedCorners, defaultArcWidth);
|
|
60 |
| } |
|
61 |
| |
|
62 |
0
| public DashedLineBorder(Color color, int thickness, float[] dashPattern, boolean roundedCorners)
|
|
63 |
| { |
|
64 |
0
| this(color, thickness, dashPattern, roundedCorners, defaultArcWidth);
|
|
65 |
| } |
|
66 |
| |
|
67 |
0
| public DashedLineBorder(Color color, int thickness, float[] dashedPattern, boolean roundedCorners, int arcWidth)
|
|
68 |
| { |
|
69 |
0
| super(color, thickness, roundedCorners);
|
|
70 |
0
| this.dashedPattern = dashedPattern;
|
|
71 |
0
| this.arcWidth = arcWidth;
|
|
72 |
| } |
|
73 |
| |
|
74 |
| |
|
75 |
0
| public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
|
|
76 |
| { |
|
77 |
0
| Color oldColor = g.getColor();
|
|
78 |
| |
|
79 |
0
| g.setColor(lineColor);
|
|
80 |
0
| Graphics2D g2d = (Graphics2D) g;
|
|
81 |
0
| g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashedPattern, 0.0f));
|
|
82 |
| |
|
83 |
0
| if(roundedCorners)
|
|
84 |
| { |
|
85 |
0
| for(int i = 0; i < thickness; i++)
|
|
86 |
| { |
|
87 |
0
| g2d.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, arcWidth, arcWidth);
|
|
88 |
| } |
|
89 |
| } |
|
90 |
| else |
|
91 |
| { |
|
92 |
0
| for(int i = 0; i < thickness; i++)
|
|
93 |
| { |
|
94 |
0
| g2d.drawRect(x+i, y+i, width-i-i-1, height-i-i-1);
|
|
95 |
| } |
|
96 |
| } |
|
97 |
| |
|
98 |
0
| g.setColor(oldColor);
|
|
99 |
| } |
|
100 |
| |
|
101 |
| } |