01: /*
02: * WbLineBorder.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.awt.Color;
15: import java.awt.Component;
16: import java.awt.Graphics;
17: import java.awt.Insets;
18:
19: import javax.swing.border.AbstractBorder;
20:
21: public class WbLineBorder extends AbstractBorder {
22: public static final int LEFT = 1;
23: public static final int RIGHT = 2;
24: public static final int TOP = 4;
25: public static final int BOTTOM = 8;
26:
27: protected int type;
28: protected int thickness;
29: protected Color color;
30: private Insets insets = new Insets(1, 1, 1, 1);
31:
32: public WbLineBorder(int type) {
33: this (type, Color.LIGHT_GRAY);
34: }
35:
36: /**
37: * Creates a divider border with the specified type and color
38: * @param aType (LEFT, RIGHT, TOP, BOTTOM)
39: * @param aColor the thickness of the border
40: */
41: public WbLineBorder(int aType, Color aColor) {
42: this .type = aType;
43: this .color = aColor;
44: }
45:
46: public void paintBorder(Component c, Graphics g, int x, int y,
47: int width, int height) {
48: Color oldColor = g.getColor();
49: g.setColor(this .color);
50: if ((this .type & TOP) == TOP) {
51: g.drawLine(x, y, x + width, y);
52: }
53: if ((this .type & BOTTOM) == BOTTOM) {
54: g.drawLine(x, y + height - 1, x + width, y + height - 1);
55: }
56: if ((this .type & LEFT) == LEFT) {
57: g.drawLine(x, y, x, y + height);
58: }
59: if ((this .type & RIGHT) == RIGHT) {
60: g.drawLine(x + width, y, x + width, y + height);
61: }
62: g.setColor(oldColor);
63: }
64:
65: public Insets getBorderInsets(Component c) {
66: return this .insets;
67: }
68:
69: public Insets getBorderInsets(Component c, Insets i) {
70: i.left = i.top = i.right = i.bottom = 2;
71: return insets;
72: }
73:
74: }
|