001: /*
002: * DividerBorder.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.components;
013:
014: import java.awt.Color;
015: import java.awt.Component;
016: import java.awt.Dimension;
017: import java.awt.Graphics;
018: import java.awt.Insets;
019:
020: import javax.swing.JPanel;
021: import javax.swing.border.AbstractBorder;
022:
023: public class DividerBorder extends AbstractBorder {
024: public static final int LEFT = 1;
025: public static final int RIGHT = 2;
026: public static final int TOP = 4;
027: public static final int BOTTOM = 8;
028: public static final int LEFT_RIGHT = 3;
029:
030: public static final int VERTICAL_MIDDLE = 16;
031: public static final int HORIZONTAL_MIDDLE = 32;
032:
033: protected int type;
034: protected int thickness;
035:
036: public static final DividerBorder BOTTOM_DIVIDER = new DividerBorder(
037: BOTTOM);
038:
039: public DividerBorder(int type) {
040: this (type, 1);
041: }
042:
043: /**
044: * Creates a divider border with the specified type and thickness
045: * @param aType (LEFT, RIGHT, TOP, BOTTOM)
046: * @param aThickness the thickness of the border
047: */
048: public DividerBorder(int aType, int aThickness) {
049: this .thickness = aThickness;
050: this .type = aType;
051: }
052:
053: public void paintBorder(Component c, Graphics g, int x, int y,
054: int width, int height) {
055: Color oldColor = g.getColor();
056:
057: Color bg = c.getBackground();
058: Color light = bg.brighter();
059: Color shade = bg.darker();
060:
061: if ((this .type & TOP) == TOP) {
062: g.setColor(shade);
063: g.drawLine(x, y, x + width, y);
064: g.setColor(light);
065: g.drawLine(x, y + 1, x + width, y + 1);
066: }
067:
068: if ((this .type & BOTTOM) == BOTTOM) {
069: g.setColor(shade);
070: g.drawLine(x, y + height - 2, x + width, y + height - 2);
071: g.setColor(light);
072: g.drawLine(x, y + height - 1, x + width, y + height - 1);
073: }
074:
075: if ((this .type & LEFT) == LEFT) {
076: g.setColor(shade);
077: g.drawLine(x, y, x, y + height);
078: g.setColor(light);
079: g.drawLine(x + 1, y, x + 1, y + height);
080:
081: }
082: if ((this .type & RIGHT) == RIGHT) {
083: g.setColor(shade);
084: g.drawLine(x + width - 2, y, x + width - 2, y + height);
085: g.setColor(light);
086: g.drawLine(x + width - 1, y, x + width - 1, y + height);
087: }
088:
089: if ((this .type & VERTICAL_MIDDLE) == VERTICAL_MIDDLE) {
090: g.setColor(shade);
091: int w2 = (int) width / 2;
092: g.drawLine(x + w2, y, x + w2, y + height);
093: g.setColor(light);
094: g.drawLine(x + w2 + 1, y, x + w2 + 1, y + height);
095: }
096: if ((this .type & HORIZONTAL_MIDDLE) == HORIZONTAL_MIDDLE) {
097: g.setColor(shade);
098: int h2 = (int) height / 2;
099: g.drawLine(0, y + h2, width, y + h2);
100: g.setColor(light);
101: g.drawLine(0, y + h2 + 1, width, y + h2 + 1);
102: }
103:
104: g.setColor(oldColor);
105: }
106:
107: public Insets getBorderInsets(Component c) {
108: return new Insets(2, 2, 2, 2);
109: }
110:
111: public Insets getBorderInsets(Component c, Insets insets) {
112: insets.left = insets.top = insets.right = insets.bottom = 2;
113: return insets;
114: }
115:
116: }
|