001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: EtchedLineBorder.java,v 1.10 2005/12/04 13:46:03 jesper Exp $
023: package net.infonode.gui.border;
024:
025: import net.infonode.gui.ComponentUtil;
026: import net.infonode.gui.GraphicsUtil;
027: import net.infonode.util.ColorUtil;
028:
029: import javax.swing.border.Border;
030: import java.awt.*;
031: import java.io.Serializable;
032:
033: /**
034: * @author $Author: jesper $
035: * @version $Revision: 1.10 $
036: */
037: public class EtchedLineBorder implements Border, Serializable {
038: private static final long serialVersionUID = 1;
039:
040: private boolean drawTop;
041: private boolean drawBottom;
042: private boolean drawLeft;
043: private boolean drawRight;
044: private Insets insets;
045: private Color highlightColor;
046: private Color shadowColor;
047:
048: public EtchedLineBorder() {
049: this (true, true, true, true);
050: }
051:
052: public EtchedLineBorder(boolean drawTop, boolean drawLeft,
053: boolean drawBottom, boolean drawRight) {
054: this (drawTop, drawLeft, drawBottom, drawRight, null, null);
055: }
056:
057: public EtchedLineBorder(boolean drawTop, boolean drawLeft,
058: boolean drawBottom, boolean drawRight,
059: Color highlightColor, Color shadowColor) {
060: this .drawBottom = drawBottom;
061: this .drawLeft = drawLeft;
062: this .drawRight = drawRight;
063: this .drawTop = drawTop;
064: insets = new Insets(drawTop ? 2 : 0, drawLeft ? 2 : 0,
065: drawBottom ? 2 : 0, drawRight ? 2 : 0);
066: this .highlightColor = highlightColor;
067: this .shadowColor = shadowColor;
068: }
069:
070: public Insets getBorderInsets(Component c) {
071: return insets;
072: }
073:
074: public boolean isBorderOpaque() {
075: return false;
076: }
077:
078: public void paintBorder(Component c, Graphics g, int x, int y,
079: int width, int height) {
080: Color c1 = highlightColor == null ? ColorUtil.mult(
081: ComponentUtil.getBackgroundColor(c), 1.70)
082: : highlightColor;
083: Color c2 = shadowColor == null ? ColorUtil.mult(ComponentUtil
084: .getBackgroundColor(c), 0.5) : shadowColor;
085: g.setColor(c1);
086:
087: if (drawTop)
088: GraphicsUtil.drawOptimizedLine(g, x, y + 1, x + width - 1,
089: y + 1);
090:
091: if (drawLeft)
092: GraphicsUtil.drawOptimizedLine(g, x + 1, y, x + 1, y
093: + height - 1);
094:
095: g.setColor(c2);
096:
097: if (drawBottom)
098: GraphicsUtil.drawOptimizedLine(g, x, y + height - 2, x
099: + width - 1, y + height - 2);
100:
101: if (drawRight)
102: GraphicsUtil.drawOptimizedLine(g, x + width - 2, y, x
103: + width - 2, y + height - 1);
104:
105: g.setColor(c1);
106:
107: if (drawBottom)
108: GraphicsUtil.drawOptimizedLine(g, x, y + height - 1, x
109: + width - 1, y + height - 1);
110:
111: if (drawRight)
112: GraphicsUtil.drawOptimizedLine(g, x + width - 1, y, x
113: + width - 1, y + height - 1);
114:
115: g.setColor(c2);
116:
117: if (drawTop)
118: GraphicsUtil.drawOptimizedLine(g, x, y, x + width - 1, y);
119:
120: if (drawLeft)
121: GraphicsUtil.drawOptimizedLine(g, x, y, x, y + height - 1);
122:
123: g.setColor(ComponentUtil.getBackgroundColor(c));
124:
125: if (drawTop && drawRight)
126: GraphicsUtil.drawOptimizedLine(g, x + width - 2, y + 1, x
127: + width - 1, y);
128:
129: if (drawBottom && drawLeft)
130: GraphicsUtil.drawOptimizedLine(g, x, y + height - 1, x + 1,
131: y + height - 2);
132: }
133: }
|