01: package jimm.datavision.gui;
02:
03: import java.awt.Component;
04: import java.awt.Graphics;
05: import java.awt.Color;
06: import javax.swing.border.AbstractBorder;
07:
08: /**
09: * A border for field widgets.
10: *
11: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
12: */
13: class FWBorder extends AbstractBorder {
14:
15: protected static final int CORNER_LINE_LEN = 5;
16: protected static final int SELECTED_BORDER_THICKNESS = 1;
17:
18: protected FieldWidget fw;
19:
20: FWBorder(FieldWidget fw) {
21: this .fw = fw;
22: }
23:
24: public void paintBorder(Component c, Graphics g, int x, int y,
25: int width, int height) {
26: --width;
27: --height;
28:
29: if (fw.isSelected()) {
30: g.setColor(Color.gray);
31: for (int i = 0; i < SELECTED_BORDER_THICKNESS; ++i)
32: g.drawRect(x + i, y + i, width - 2 * i, height - 2 * i);
33: } else {
34: g.setColor(fw.getColor());
35: g.setPaintMode();
36: // top left
37: g.drawLine(x, y, x + CORNER_LINE_LEN, y);
38: g.drawLine(x, y, x, y + CORNER_LINE_LEN);
39: // top right
40: g.drawLine(x + width - CORNER_LINE_LEN, y, x + width, y);
41: g.drawLine(x + width, y, x + width, y + CORNER_LINE_LEN);
42: // bottom right
43: g.drawLine(x + width - CORNER_LINE_LEN, y + height, x
44: + width, y + height);
45: g.drawLine(x + width, y + height - CORNER_LINE_LEN, x
46: + width, y + height);
47: // bottom left
48: g.drawLine(x, y + height, x + CORNER_LINE_LEN, y + height);
49: g.drawLine(x, y + height - CORNER_LINE_LEN, x, y + height);
50: }
51: }
52:
53: }
|