1 /***
2 *
3 */
4 package org.telscenter.pas.common.ui.border;
5
6 import java.awt.Color;
7 import java.awt.Component;
8 import java.awt.Graphics;
9 import java.awt.Insets;
10
11 import javax.swing.border.AbstractBorder;
12
13 /***
14 * @author aperritano
15 *
16 */
17 public class CustomLineBorder extends AbstractBorder {
18
19
20 protected Color topColor;
21 protected int topThickness;
22 protected Color rightColor;
23 protected int rightThickness;
24 protected Color bottomColor;
25 protected int bottomThickness;
26 protected Color leftColor;
27 protected int leftThickness;
28
29
30
31 /***
32 * @param color
33 */
34 public CustomLineBorder(Color topColor,int topThickness,Color rightColor,int rightThickness,Color bottomColor,int bottomThickness,Color leftColor,int leftThickness) {
35
36 this.topColor = topColor;
37 this.topThickness = topThickness;
38
39 this.rightColor = rightColor;
40 this.rightThickness = rightThickness;
41
42 this.bottomColor = bottomColor;
43 this.bottomThickness = bottomThickness;
44
45 this.leftColor = leftColor;
46 this.leftThickness = leftThickness;
47 }
48 /***
49 * Paints the border for the specified component with the
50 * specified position and size.
51 * @param c the component for which this border is being painted
52 * @param g the paint graphics
53 * @param x the x position of the painted border
54 * @param y the y position of the painted border
55 * @param width the width of the painted border
56 * @param height the height of the painted border
57 */
58 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
59
60
61
62
63
64
65
66
67
68 for(int i = 0; i < topThickness; i++) {
69
70 int newX = x+i;
71 int newY = y+i;
72 int newWidth = width;
73 int newHeight = height-i-i;
74
75 g.setColor(topColor);
76 g.drawLine(0, newY, (newX + newWidth), newY);
77
78 }
79
80 for(int k = 0; k < rightThickness; k++) {
81 int newX = x-k;
82
83 int newWidth = width-1;
84 int newHeight = height;
85
86 g.setColor(rightColor);
87 g.drawLine(newX+newWidth, 0, newX+newWidth, newHeight);
88 }
89
90 for(int i = 0; i < leftThickness; i++) {
91 int newX = x+i;
92 int newY = y;
93 int newWidth = width-i-i;
94
95 int newHeight = height;
96
97
98 g.setColor(leftColor);
99 g.drawLine(newX,0, newX, newY+newHeight );
100 }
101
102 for(int i = 0; i < bottomThickness; i++) {
103 int newX = x;
104 int newY = y-i;
105 int newWidth = width;
106 int newHeight = height-1;
107
108
109 g.setColor(bottomColor);
110 g.drawLine(0, newY+newHeight, (newX + newWidth), newY+newHeight);
111
112 }
113 }
114
115 /***
116 * Returns the insets of the border.
117 * @param c the component for which this border insets value applies
118 */
119 public Insets getBorderInsets(Component c) {
120 return new Insets(topThickness, leftThickness, bottomThickness, rightThickness);
121 }
122
123 /***
124 * Reinitialize the insets parameter with this Border's current Insets.
125 * @param c the component for which this border insets value applies
126 * @param insets the object to be reinitialized
127 */
128 public Insets getBorderInsets(Component c, Insets insets) {
129 insets.left = this.leftThickness;
130 insets.top = this.topThickness;
131 insets.right = this.rightThickness;
132 insets.bottom = this.bottomThickness;
133 return insets;
134 }
135 }