KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > awt > BevelPanel


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sshtools.ui.awt;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.LayoutManager JavaDoc;
27 import java.awt.Panel JavaDoc;
28
29 /**
30  * <p>
31  * <code>Panel</code> that draws a 3d border around the edge. The edge, or bevel, can be one of :-
32  * </p>
33  *
34  * <ul>
35  * <li><code>BevelPanel.NONE</code></li>
36  * <li><code>BevelPanel.LOWERED</code></li>
37  * <li><code>BevelPanel.RAISED</code></li>
38  *
39  * <p>
40  * </p>
41  *
42  * @author $Author: james $
43  */

44 public class BevelPanel
45     extends java.awt.Panel JavaDoc {
46   // Public static
47

48   /**
49    * No border
50    */

51   public static final int NONE = 0;
52
53   /**
54    * Lowered bevel
55    */

56   public static final int LOWERED = 1;
57
58   /**
59    * Raised bevel
60    */

61   public static final int RAISED = 2;
62
63   // Private instance variables
64

65   private int type;
66
67   /**
68    * Create a panel with the specified type of bevel.
69    *
70    * @param layout layout manager
71    */

72   public BevelPanel(int bevel) {
73     this(bevel, null);
74   }
75
76   /**
77    * Create a panel with the specified type of bevel.
78    *
79    * @param type bevel type
80    * @param layout layout manager
81    */

82   public BevelPanel(int type, LayoutManager JavaDoc layout) {
83     super();
84     if (layout != null) {
85       setLayout(layout);
86     }
87     setType(type);
88   }
89
90   /**
91    * Set the bevel type. Can be one of :-
92    * </p>
93    *
94    * <ul>
95    * <li><code>BevelPanel.NONE</code></li>
96    * <li><code>BevelPanel.LOWERED</code></li>
97    * <li><code>BevelPanel.RAISED</code></li>
98    *
99    * @param type bevel type
100    */

101   public void setType(int type) {
102     this.type = type;
103     repaint();
104   }
105
106   /**
107    * Return insets sufficient for bevel and label drawing space.
108    */

109   public Insets JavaDoc getInsets() {
110     return new Insets JavaDoc(2, 2, 2, 2);
111   }
112
113   /*
114    * (non-Javadoc)
115    *
116    * @see java.awt.Component#paint(java.awt.Graphics)
117    */

118   public void paint(Graphics JavaDoc g) {
119     super.paint(g);
120     Dimension JavaDoc d = getSize();
121     Color JavaDoc si = getBackground().darker();
122     Color JavaDoc so = si.darker();
123     Color JavaDoc hi = getBackground().brighter();
124     Color JavaDoc ho = hi.brighter();
125     if (type == LOWERED) {
126       g.setColor(si);
127       g.drawLine(0, 0, 0, d.height - 1);
128       g.drawLine(1, 0, d.width - 1, 0);
129       g.setColor(so);
130       g.drawLine(1, 1, 1, d.height - 2);
131       g.drawLine(2, 1, d.width - 2, 1);
132       g.setColor(ho);
133       g.drawLine(1, d.height - 1, d.width - 1, d.height - 1);
134       g.drawLine(d.width - 1, 1, d.width - 1, d.height - 2);
135       g.setColor(hi);
136       g.drawLine(2, d.height - 2, d.width - 2, d.height - 2);
137       g.drawLine(d.width - 2, 2, d.width - 2, d.height - 3);
138     }
139     else {
140       if (type == RAISED) {
141         g.setColor(ho);
142         g.drawLine(0, 0, 0, d.height - 2);
143         g.drawLine(1, 0, d.width - 2, 0);
144         g.setColor(hi);
145         g.drawLine(1, 1, 1, d.height - 3);
146         g.drawLine(2, 1, d.width - 3, 1);
147         g.setColor(so);
148         g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
149         g.drawLine(d.width - 1, 0, d.width - 1, d.height - 2);
150         g.setColor(si);
151         g.drawLine(1, d.height - 2, d.width - 2, d.height - 2);
152         g.drawLine(d.width - 2, 1, d.width - 2, d.height - 3);
153       }
154     }
155   }
156 }
157
Popular Tags