View Javadoc

1   /*
2    *  XNap Commons
3    *
4    *  Copyright (C) 2005  Steffen Pingel
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or (at your option) any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package org.xnap.commons.gui;
21  
22  import java.awt.Color;
23  import java.awt.Component;
24  import java.awt.Graphics;
25  import java.awt.Insets;
26  import javax.swing.border.BevelBorder;
27  
28  /***
29   * Provides a simple 1 line bevel border. If the Border is raised it will look
30   * like the component it is used with is raised a little bit. If it is lowered it
31   * will look like the component is lowered a bit.
32   * 
33   * <p>Very similiar to Swing's {@link javax.swing.border.BevelBorder} except
34   * it looks a bit prettier.
35   */
36  public class ThinBevelBorder extends BevelBorder {
37  
38  	/***
39       * Constructs a border with the given <code>etchType</code>.
40       * 
41  	 * @see BevelBorder#BevelBorder(int)
42  	 * @param bevelType either <code>BevelBoder.RAISED</code> or <code>BevelBorder.LOWERED</code> 
43  	 */
44      public ThinBevelBorder(int bevelType)
45      {
46  		super(bevelType);
47      }
48  
49  	public Insets getBorderInsets(Component c)       
50  	{
51  		return new Insets(1, 1, 1, 1);
52      }
53  
54      public Insets getBorderInsets(Component c, Insets insets) 
55  	{
56          insets.left = insets.top = insets.right = insets.bottom = 1;
57          return insets;
58      }
59  
60      protected void paintLoweredBevel(Component c, Graphics g, int x, int y,
61  									 int width, int height)  
62  	{
63          Color oldColor = g.getColor();
64          int h = height;
65          int w = width;
66  
67          g.translate(x, y);
68  
69          g.setColor(getShadowOuterColor(c));
70          g.drawLine(0, 0, 0, h - 2);
71          g.drawLine(1, 0, w - 1, 0);
72  
73          g.setColor(getHighlightOuterColor(c));
74          g.drawLine(0, h - 1, w - 1, h - 1);
75          g.drawLine(w - 1, 1, w - 1, h - 2);
76  
77          g.translate(-x, -y);
78          g.setColor(oldColor);
79  
80      }
81  
82      protected void paintRaisedBevel(Component c, Graphics g, int x, int y,
83                                      int width, int height)  
84  	{
85          Color oldColor = g.getColor();
86          int h = height;
87          int w = width;
88  
89          g.translate(x, y);
90  
91          g.setColor(getHighlightOuterColor(c));
92          g.drawLine(0, 0, 0, h - 2);
93          g.drawLine(1, 0, w - 1, 0);
94  
95          g.setColor(getShadowOuterColor(c));
96          g.drawLine(0, h - 1, w - 1, h - 1);
97          g.drawLine(w - 1, 1, w - 1, h - 2);
98  
99          g.translate(-x, -y);
100         g.setColor(oldColor);
101     }
102 
103 }