001: /*
002: * @(#)FrameBorder.java
003: *
004: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.plaf.xerto;
007:
008: import javax.swing.border.Border;
009: import javax.swing.plaf.UIResource;
010: import java.awt.*;
011:
012: /**
013: * This class is an implementation of the DockableFrame border.
014: */
015: public class SlidingFrameBorder implements Border, UIResource {
016: public final static int SHADOW_SIZE = 10;
017: protected Color _highlight;
018: protected Color _lightHighlight;
019: protected Color _shadow;
020: protected Color _darkShadow;
021: protected Insets _insets;
022: private static double LOG10 = Math.log(10);
023:
024: public SlidingFrameBorder(Color highlight, Color lightHighlight,
025: Color shadow, Color darkShadow, Insets insets) {
026: _highlight = highlight;
027: _lightHighlight = lightHighlight;
028: _shadow = shadow;
029: _darkShadow = darkShadow;
030: _insets = insets;
031: }
032:
033: /**
034: * Returns the insets of the border.
035: *
036: * @param c the component for which this border insets value applies
037: */
038: public Insets getBorderInsets(Component c) {
039: return _insets;
040: }
041:
042: /**
043: * Returns whether or not the border is opaque. If the border
044: * is opaque, it is responsible for filling in it's own
045: * background when painting.
046: */
047: public boolean isBorderOpaque() {
048: return true;
049: }
050:
051: public void paintBorder(Component c, Graphics g, int x, int y,
052: int width, int height) {
053: if (_insets.top >= SHADOW_SIZE) { //
054: g.setColor(XertoUtils.getFrameBorderColor());
055: g.drawRect(x, y + _insets.top - 1, width, height
056: - _insets.top + 1);
057:
058: g.setColor(_highlight);
059: g.drawLine(x, y + _insets.top - 5, x + width, y
060: + _insets.top - 5);
061: g.setColor(_lightHighlight);
062: g.drawLine(x, y + _insets.top - 4, x + width, y
063: + _insets.top - 4);
064: g.setColor(_highlight);
065: g.drawLine(x, y + _insets.top - 3, x + width, y
066: + _insets.top - 3);
067: g.drawLine(x, y + _insets.top - 2, x + width, y
068: + _insets.top - 2);
069:
070: paintGradient((Graphics2D) g, new Rectangle(x, y, width,
071: _insets.top - 5), true, 40, false);
072: }
073:
074: if (_insets.left >= SHADOW_SIZE) { //
075: g.setColor(XertoUtils.getFrameBorderColor());
076: g.drawRect(x + _insets.left - 1, y, width - _insets.left,
077: height);
078:
079: g.setColor(_highlight);
080: g.drawLine(x + _insets.left - 5, y, x + _insets.left - 5, y
081: + height);
082: g.setColor(_lightHighlight);
083: g.drawLine(x + _insets.left - 4, y, x + _insets.left - 4, y
084: + height);
085: g.setColor(_highlight);
086: g.drawLine(x + _insets.left - 3, y, x + _insets.left - 3, y
087: + height);
088: g.drawLine(x + _insets.left - 2, y, x + _insets.left - 2, y
089: + height);
090:
091: paintGradient((Graphics2D) g, new Rectangle(x, y,
092: _insets.left - 5, height), false, 40, false);
093: }
094:
095: if (_insets.bottom >= SHADOW_SIZE) {
096: g.setColor(XertoUtils.getFrameBorderColor());
097: g.drawRect(x, y, width, height - _insets.bottom);
098:
099: g.setColor(_highlight);
100: g.drawLine(x, y + height - _insets.bottom + 1, x + width, y
101: + height - _insets.bottom + 1);
102: g.drawLine(x, y + height - _insets.bottom + 2, x + width, y
103: + height - _insets.bottom + 2);
104: g.setColor(_shadow);
105: g.drawLine(x, y + height - _insets.bottom + 3, x + width, y
106: + height - _insets.bottom + 3);
107: g.setColor(_darkShadow);
108: g.drawLine(x, y + height - _insets.bottom + 4, x + width, y
109: + height - _insets.bottom + 4);
110:
111: paintGradient((Graphics2D) g, new Rectangle(x, y + height
112: - _insets.bottom + 4, width, _insets.bottom - 5),
113: true, 100, true);
114: }
115:
116: if (_insets.right >= SHADOW_SIZE) {
117: g.setColor(XertoUtils.getFrameBorderColor());
118: g.drawRect(x, y, width - _insets.right, height);
119:
120: g.setColor(_highlight);
121: g.drawLine(x + width - _insets.right + 1, y, x + width
122: - _insets.right + 1, y + height);
123: g.drawLine(x + width - _insets.right + 2, y, x + width
124: - _insets.right + 2, y + height);
125: g.setColor(_shadow);
126: g.drawLine(x + width - _insets.right + 3, y, x + width
127: - _insets.right + 3, y + height);
128: g.setColor(_darkShadow);
129: g.drawLine(x + width - _insets.right + 4, y, x + width
130: - _insets.right + 4, y + height);
131:
132: paintGradient((Graphics2D) g, new Rectangle(x + width
133: - _insets.right + 4, y, _insets.right - 5, height),
134: false, 100, true);
135: }
136: }
137:
138: public static void paintGradient(Graphics g, Rectangle rect,
139: boolean isVertical, int darkness, boolean lighter) {
140: if (isVertical) {
141: for (int i = 1; i < rect.height; i++) {
142: int iAlpha = (int) ((1 - Math.log(i) / LOG10) * darkness);
143: g.setColor(new Color(0, 0, 0, iAlpha));
144: if (lighter) {
145: g.drawLine(rect.x, rect.y + i, rect.x + rect.width,
146: rect.y + i);
147: } else {
148: g.drawLine(rect.x, rect.y + rect.height - i, rect.x
149: + rect.width, rect.y + rect.height - i);
150: }
151: }
152: } else {
153: for (int i = 1; i < rect.width; i++) {
154: int iAlpha = (int) ((1 - Math.log(i) / LOG10) * darkness);
155: g.setColor(new Color(0, 0, 0, iAlpha));
156: if (lighter) {
157: g.drawLine(rect.x + i, rect.y, rect.x + i, rect.y
158: + rect.height);
159: } else {
160: g.drawLine(rect.x + rect.width - i, rect.y, rect.x
161: + rect.width - i, rect.y + rect.height);
162: }
163: }
164: }
165: }
166: }
|