KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > base > SingleSideEtchedBorder


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
22 import java.awt.Graphics JavaDoc;
23 import java.awt.Insets JavaDoc;
24
25 import javax.swing.SwingConstants JavaDoc;
26 import javax.swing.border.EtchedBorder JavaDoc;
27
28 public class SingleSideEtchedBorder extends EtchedBorder JavaDoc {
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 JavaDoc c, Graphics JavaDoc g, int x, int y, int width, int height) {
41         g.translate(x, y);
42         int x1, y1, x2, y2;
43         switch(side) {
44             case SwingConstants.TOP:
45                 x2 = width-2;
46                 x1 = y1 = y2 = 0;
47                 break;
48             case SwingConstants.LEFT:
49                 y2 = height-2;
50                 x1 = y1 = x2 = 0;
51                 break;
52             case SwingConstants.RIGHT:
53                 x1 = x2 = width-2;
54                 y1 = 0;
55                 y2 = height-2;
56                 break;
57             default:
58                 x1 = 0;
59                 x2 = width-2;
60                 y1 = y2 = height-2;
61         }
62         g.setColor(etchType == LOWERED? getShadowColor(c) : getHighlightColor(c));
63         g.drawLine(x1, y1, x2, y2);
64         g.setColor(etchType == LOWERED? getHighlightColor(c) : getShadowColor(c));
65         g.drawLine(x1+1, y1+1, x2+1, y2+1);
66         g.translate(-x, -y);
67     }
68     
69     public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
70         return getBorderInsets(c, new Insets JavaDoc(0, 0, 0, 0));
71     }
72     
73     public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc i) {
74         switch(side) {
75             case SwingConstants.TOP:
76                 i.top = 2;
77                 i.left = i.right = i.bottom = 0;
78                 break;
79             case SwingConstants.LEFT:
80                 i.left = 2;
81                 i.top = i.right = i.bottom = 0;
82                 break;
83             case SwingConstants.RIGHT:
84                 i.right = 2;
85                 i.top = i.left = i.bottom = 0;
86                 break;
87             default:
88                 i.bottom = 2;
89                 i.top = i.left = i.right = 0;
90         }
91         return i;
92     }
93 }
94
Popular Tags