001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: BorderEtched.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.swing;
009:
010: import java.awt.Color;
011: import java.awt.Component;
012: import java.awt.Graphics;
013: import java.awt.Insets;
014: import javax.swing.border.AbstractBorder;
015:
016: public class BorderEtched extends AbstractBorder {
017: private static final long serialVersionUID = -1065186910206819539L;
018:
019: private int mEdgeType = 0;
020:
021: public static final int RAISED = 0;
022: public static final int LOWERED = 1;
023:
024: public BorderEtched() {
025: this (RAISED);
026: }
027:
028: public BorderEtched(int edgeType) {
029: mEdgeType = edgeType;
030: }
031:
032: public void paintBorder(Component component, Graphics graphics,
033: int x, int y, int width, int height) {
034: Graphics new_graphics = graphics.create();
035:
036: if (null != new_graphics) {
037: try {
038: new_graphics.translate(x, y);
039:
040: Color background_color = null;
041: Color shadow_color = null;
042: Color highlight_color = null;
043:
044: if (component.isEnabled()) {
045: background_color = new Color(205, 206, 205);
046: shadow_color = Colors.BORDER_SHADOW;
047: highlight_color = Color.white;
048: } else {
049: background_color = new Color(205, 206, 205);
050: shadow_color = new Color(156, 153, 156);
051: highlight_color = background_color;
052: }
053:
054: new_graphics.setColor(background_color);
055: new_graphics.drawRect(2, 2, width - 5, height - 5);
056: new_graphics.drawRect(3, 3, width - 7, height - 7);
057:
058: if (RAISED == mEdgeType) {
059: new_graphics.setColor(shadow_color);
060: new_graphics.drawRect(0, 0, width - 2, height - 2);
061:
062: new_graphics.setColor(highlight_color);
063:
064: new_graphics.drawLine(width - 3, 1, 1, 1);
065: new_graphics.drawLine(1, 1, 1, height - 3);
066: new_graphics.drawLine(0, height - 1, width - 1,
067: height - 1);
068: new_graphics.drawLine(width - 1, height - 1,
069: width - 1, 0);
070:
071: new_graphics.drawLine(width - 7, 5, 5, 5);
072: new_graphics.drawLine(5, 5, 5, height - 6);
073: new_graphics.drawLine(width - 5, 4, width - 5,
074: height - 5);
075: new_graphics.drawLine(width - 5, height - 5, 4,
076: height - 5);
077:
078: new_graphics.setColor(shadow_color);
079: new_graphics
080: .drawRect(4, 4, width - 10, height - 10);
081: } else if (LOWERED == mEdgeType) {
082: new_graphics.setColor(shadow_color);
083: new_graphics.drawRect(1, 1, width - 2, height - 2);
084:
085: new_graphics.setColor(highlight_color);
086:
087: new_graphics.drawLine(width - 1, 0, 0, 0);
088: new_graphics.drawLine(0, 0, 0, height - 1);
089: new_graphics.drawLine(width - 2, 2, width - 2,
090: height - 2);
091: new_graphics.drawLine(width - 2, height - 2, 2,
092: height - 2);
093:
094: new_graphics.drawLine(width - 5, 4, 4, 4);
095: new_graphics.drawLine(4, 4, 4, height - 5);
096: new_graphics.drawLine(width - 6, 6, width - 6,
097: height - 6);
098: new_graphics.drawLine(width - 6, height - 6, 6,
099: height - 6);
100:
101: new_graphics.setColor(shadow_color);
102: new_graphics
103: .drawRect(5, 5, width - 10, height - 10);
104: }
105: } finally {
106: new_graphics.dispose();
107: }
108: }
109: }
110:
111: public Insets getBorderInsets(Component component) {
112: return getBorderInsets(component, new Insets(0, 0, 0, 0));
113: }
114:
115: public Insets getBorderInsets(Component component, Insets insets) {
116: insets.top = 6;
117: insets.bottom = 6;
118: insets.left = 6;
119: insets.right = 6;
120:
121: return insets;
122: }
123: }
|