|
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 |
| |
|
23 |
| import javax.swing.border.*; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| public class RoundedLineBorder extends LineBorder |
|
29 |
| { |
|
30 |
| private float[] dashedPattern; |
|
31 |
| private int arcWidth; |
|
32 |
| |
|
33 |
| |
|
34 |
| static private int defaultThickness = 1; |
|
35 |
| static private int defaultArcWidth = 20; |
|
36 |
| |
|
37 |
0
| public RoundedLineBorder(Color color)
|
|
38 |
| { |
|
39 |
0
| this(color, defaultThickness, defaultArcWidth);
|
|
40 |
| } |
|
41 |
| |
|
42 |
0
| public RoundedLineBorder(Color color, int thickness)
|
|
43 |
| { |
|
44 |
0
| this(color, thickness, defaultArcWidth);
|
|
45 |
| } |
|
46 |
| |
|
47 |
0
| public RoundedLineBorder(Color color, int thickness, int arcWidth)
|
|
48 |
| { |
|
49 |
0
| super(color, thickness);
|
|
50 |
0
| this.arcWidth = arcWidth;
|
|
51 |
| } |
|
52 |
| |
|
53 |
0
| public Insets getBorderInsets(Component c) {
|
|
54 |
0
| return new Insets(4, 4, 4, 4);
|
|
55 |
| } |
|
56 |
| |
|
57 |
| |
|
58 |
0
| public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
|
|
59 |
| { |
|
60 |
0
| Graphics2D g2d = (Graphics2D) g;
|
|
61 |
0
| g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
62 |
| |
|
63 |
| |
|
64 |
0
| Color oldColor = g.getColor();
|
|
65 |
| |
|
66 |
0
| g.setColor(lineColor);
|
|
67 |
| |
|
68 |
0
| g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashedPattern, 0.0f));
|
|
69 |
| |
|
70 |
0
| for(int i = 0; i < thickness; i++)
|
|
71 |
| { |
|
72 |
0
| g2d.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, arcWidth, arcWidth);
|
|
73 |
| } |
|
74 |
0
| g.setColor(oldColor);
|
|
75 |
| |
|
76 |
0
| g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
|
|
77 |
| |
|
78 |
| } |
|
79 |
| |
|
80 |
| } |