001: /*
002: * @(#)RaisedBorder.java 2/12/2005
003: *
004: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.plaf.eclipse;
007:
008: import com.jidesoft.plaf.XPUtils;
009:
010: import javax.swing.border.Border;
011: import javax.swing.plaf.UIResource;
012: import java.awt.*;
013:
014: public class RaisedBorder implements Border, UIResource {
015: protected Color _highlight;
016: protected Color _lightHighlight;
017: protected Color _shadow;
018: protected Color _darkShadow;
019: protected Insets _insets;
020:
021: public RaisedBorder(Color highlight, Color lightHighlight,
022: Color shadow, Color darkShadow, Insets insets) {
023: _highlight = highlight;
024: _lightHighlight = lightHighlight;
025: _shadow = shadow;
026: _darkShadow = darkShadow;
027: _insets = insets;
028: }
029:
030: /**
031: * Returns the insets of the border.
032: *
033: * @param c the component for which this border insets value applies
034: */
035: public Insets getBorderInsets(Component c) {
036: return _insets;
037: }
038:
039: /**
040: * Returns whether or not the border is opaque. If the border
041: * is opaque, it is responsible for filling in it's own
042: * background when painting.
043: */
044: public boolean isBorderOpaque() {
045: return true;
046: }
047:
048: public void paintBorder(Component c, Graphics g, int x, int y,
049: int width, int height) {
050: if (XPUtils.isXPStyleOn()) {
051: if (_insets.top > 0) {
052: g.setColor(_shadow);
053: g.drawLine(x, y, x + width, y);
054: }
055: if (_insets.left > 0) {
056: g.setColor(_shadow);
057: g.drawLine(x, y, x, y + height);
058: }
059: if (_insets.bottom > 0) {
060: g.setColor(_shadow);
061: g
062: .drawLine(x, y + height - 1, x + width, y
063: + height - 1);
064: }
065: if (_insets.right > 0) {
066: g.setColor(_shadow);
067: g.drawLine(x + width - 1, y, x + width - 1, y + height);
068: }
069: } else {
070: if (_insets.top > 0) {
071: g.setColor(_highlight);
072: g.drawLine(x, y, x + width, y);
073: g.setColor(_lightHighlight);
074: g.drawLine(x + 1, y + 1, x + width - 1, y + 1);
075: }
076: if (_insets.left > 0) {
077: g.setColor(_highlight);
078: g.drawLine(x, y, x, y + height);
079: g.setColor(_lightHighlight);
080: g.drawLine(x + 1, y + 1, x + 1, y + height - 1);
081: }
082: if (_insets.bottom > 0) {
083: g.setColor(_shadow);
084: g.drawLine(x + 1, y + height - 2, x + width - 1, y
085: + height - 2);
086: g.setColor(_darkShadow);
087: g
088: .drawLine(x, y + height - 1, x + width, y
089: + height - 1);
090: }
091: if (_insets.right > 0) {
092: g.setColor(_shadow);
093: g.drawLine(x + width - 2, y + 1, x + width - 2, y
094: + height - 2);
095: g.setColor(_darkShadow);
096: g.drawLine(x + width - 1, y, x + width - 1, y + height);
097: }
098: }
099: }
100: }
|