001: package com.jidesoft.swing;
002:
003: import javax.swing.border.EtchedBorder;
004: import java.awt.*;
005:
006: /**
007: */
008: public class PartialEtchedBorder extends EtchedBorder implements
009: PartialSide {
010:
011: private int _sides;
012:
013: public PartialEtchedBorder() {
014: this (ALL);
015: }
016:
017: public PartialEtchedBorder(int sides) {
018: _sides = sides;
019: }
020:
021: public PartialEtchedBorder(int etchType, int sides) {
022: super (etchType);
023: _sides = sides;
024: }
025:
026: public PartialEtchedBorder(Color highlight, Color shadow, int sides) {
027: super (highlight, shadow);
028: _sides = sides;
029: }
030:
031: public PartialEtchedBorder(int etchType, Color highlight,
032: Color shadow, int sides) {
033: super (etchType, highlight, shadow);
034: _sides = sides;
035: }
036:
037: public int getSides() {
038: return _sides;
039: }
040:
041: public void setSides(int sides) {
042: _sides = sides;
043: }
044:
045: @Override
046: public void paintBorder(Component c, Graphics g, int x, int y,
047: int width, int height) {
048: int w = width;
049: int h = height;
050:
051: g.translate(x, y);
052:
053: if (c.getBackground() == null) {
054: c.setBackground(Color.GRAY); // just a workaround to resolve the background is null issue.
055: }
056:
057: Color shadowColor = getShadowColor(c);
058: Color highlightColor = getHighlightColor(c);
059:
060: if (_sides == ALL) {
061: g.setColor(etchType == LOWERED ? shadowColor
062: : highlightColor);
063: g.drawRect(0, 0, w - 2, h - 2);
064:
065: g.setColor(etchType == LOWERED ? highlightColor
066: : shadowColor);
067: g.drawLine(1, h - 3, 1, 1);
068: g.drawLine(1, 1, w - 3, 1);
069:
070: g.drawLine(0, h - 1, w - 1, h - 1);
071: g.drawLine(w - 1, h - 1, w - 1, 0);
072: } else {
073: if ((_sides & NORTH) != 0) {
074: g.setColor(etchType == LOWERED ? shadowColor
075: : highlightColor);
076: g.drawLine(0, 0, w - 2, 0);
077: g.setColor(etchType == LOWERED ? highlightColor
078: : shadowColor);
079: g.drawLine(1, 1, w - 2, 1);
080: }
081: if ((_sides & SOUTH) != 0) {
082: g.setColor(etchType == LOWERED ? shadowColor
083: : highlightColor);
084: g.drawLine(0, h - 2, w - 1, h - 2);
085: g.setColor(etchType == LOWERED ? highlightColor
086: : shadowColor);
087: g.drawLine(0, h - 1, w - 1, h - 1);
088: }
089: if ((_sides & WEST) != 0) {
090: g.setColor(etchType == LOWERED ? shadowColor
091: : highlightColor);
092: g.drawLine(0, h - 2, 0, 0);
093: g.setColor(etchType == LOWERED ? highlightColor
094: : shadowColor);
095: g.drawLine(1, h - 3, 1, 1);
096: }
097: if ((_sides & EAST) != 0) {
098: g.setColor(etchType == LOWERED ? shadowColor
099: : highlightColor);
100: g.drawLine(w - 2, h - 2, w - 2, 0);
101: g.setColor(etchType == LOWERED ? highlightColor
102: : shadowColor);
103: g.drawLine(w - 1, h - 1, w - 1, 0);
104: }
105: }
106: g.translate(-x, -y);
107: }
108: }
|