01: package com.jidesoft.swing;
02:
03: import javax.swing.border.LineBorder;
04: import java.awt.*;
05:
06: /**
07: * This is a better version of LineBorder which allows you to show line only at one side or several sides.
08: */
09: public class PartialLineBorder extends LineBorder implements
10: PartialSide {
11:
12: private int _sides = ALL;
13:
14: public PartialLineBorder(Color color) {
15: super (color);
16: }
17:
18: public PartialLineBorder(Color color, int thickness) {
19: super (color, thickness);
20: }
21:
22: public PartialLineBorder(Color color, int thickness,
23: boolean roundedCorners) {
24: super (color, thickness, roundedCorners);
25: }
26:
27: public PartialLineBorder(Color color, int thickness, int side) {
28: super (color, thickness);
29: _sides = side;
30: }
31:
32: public int getSides() {
33: return _sides;
34: }
35:
36: public void setSides(int sides) {
37: _sides = sides;
38: }
39:
40: @Override
41: public void paintBorder(Component c, Graphics g, int x, int y,
42: int width, int height) {
43: Color oldColor = g.getColor();
44: int i;
45:
46: g.setColor(lineColor);
47: for (i = 0; i < thickness; i++) {
48: if (_sides == ALL) {
49: if (!roundedCorners)
50: g.drawRect(x + i, y + i, width - i - i - 1, height
51: - i - i - 1);
52: else
53: g.drawRoundRect(x + i, y + i, width - i - i - 1,
54: height - i - i - 1, 5, 5);
55: }
56:
57: else {
58: if ((_sides & NORTH) != 0) {
59: g.drawLine(x, y + i, x + width - 1, y + i);
60: }
61: if ((_sides & SOUTH) != 0) {
62: g.drawLine(x, y + height - i - 1, x + width - 1, y
63: + height - i - 1);
64: }
65: if ((_sides & WEST) != 0) {
66: g.drawLine(x + i, y, x + i, y + height - 1);
67: }
68: if ((_sides & EAST) != 0) {
69: g.drawLine(x + width - i - 1, y, x + width - i - 1,
70: y + height - 1);
71: }
72: }
73:
74: }
75: g.setColor(oldColor);
76: }
77: }
|