01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18:
19: package org.columba.core.gui.base;
20:
21: import java.awt.Component;
22: import java.awt.Graphics;
23: import java.awt.Insets;
24:
25: import javax.swing.SwingConstants;
26: import javax.swing.border.EtchedBorder;
27:
28: public class SingleSideEtchedBorder extends EtchedBorder {
29: protected int side;
30:
31: public SingleSideEtchedBorder(int side) {
32: this (side, LOWERED);
33: }
34:
35: public SingleSideEtchedBorder(int side, int etchType) {
36: super (etchType);
37: this .side = side;
38: }
39:
40: public void paintBorder(Component c, Graphics g, int x, int y,
41: int width, int height) {
42: g.translate(x, y);
43: int x1, y1, x2, y2;
44: switch (side) {
45: case SwingConstants.TOP:
46: x2 = width - 2;
47: x1 = y1 = y2 = 0;
48: break;
49: case SwingConstants.LEFT:
50: y2 = height - 2;
51: x1 = y1 = x2 = 0;
52: break;
53: case SwingConstants.RIGHT:
54: x1 = x2 = width - 2;
55: y1 = 0;
56: y2 = height - 2;
57: break;
58: default:
59: x1 = 0;
60: x2 = width - 2;
61: y1 = y2 = height - 2;
62: }
63: g.setColor(etchType == LOWERED ? getShadowColor(c)
64: : getHighlightColor(c));
65: g.drawLine(x1, y1, x2, y2);
66: g.setColor(etchType == LOWERED ? getHighlightColor(c)
67: : getShadowColor(c));
68: g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
69: g.translate(-x, -y);
70: }
71:
72: public Insets getBorderInsets(Component c) {
73: return getBorderInsets(c, new Insets(0, 0, 0, 0));
74: }
75:
76: public Insets getBorderInsets(Component c, Insets i) {
77: switch (side) {
78: case SwingConstants.TOP:
79: i.top = 2;
80: i.left = i.right = i.bottom = 0;
81: break;
82: case SwingConstants.LEFT:
83: i.left = 2;
84: i.top = i.right = i.bottom = 0;
85: break;
86: case SwingConstants.RIGHT:
87: i.right = 2;
88: i.top = i.left = i.bottom = 0;
89: break;
90: default:
91: i.bottom = 2;
92: i.top = i.left = i.right = 0;
93: }
94: return i;
95: }
96: }
|