View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
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 License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui.component;
21  
22  import java.awt.Component;
23  import java.awt.Graphics;
24  import java.awt.Insets;
25  
26  import javax.swing.border.AbstractBorder;
27  
28  public class XNapEtchedBorder extends AbstractBorder
29  {
30  
31  
32      //--- Constant(s) ---
33  
34      public static final int RAISED  = 0;
35  
36      public static final int LOWERED = 1;
37  
38      //--- Data field(s) ---
39  
40      protected int etchType;
41  
42      //--- Constructor(s) ---
43  
44      public XNapEtchedBorder(int etchType)
45      {
46          this.etchType = etchType;
47      }
48  
49      public XNapEtchedBorder()
50      {
51          this(LOWERED);
52      }
53  
54      //--- Method(s) ---
55  
56      public void paintBorder(Component c, Graphics g, int x, int y, int w,
57  							int h) 
58  	{
59  		g.translate(x, y);
60  	
61  		g.setColor((etchType == LOWERED) 
62  				   ? c.getBackground().darker() 
63  				   : c.getBackground().brighter());
64  		g.drawLine(0, h - 2, w - 1, h - 2);
65  
66  		g.setColor((etchType == LOWERED)
67  				   ? c.getBackground().brighter() 
68  				   : c.getBackground().darker());
69  		g.drawLine(0, h - 1, w - 1, h - 1);
70  	
71  		g.translate(-x, -y);
72      }
73  
74      public Insets getBorderInsets(Component c)       
75  	{
76          return new Insets(2, 2, 2, 2);
77      }
78  
79      public Insets getBorderInsets(Component c, Insets insets) 
80  	{
81          insets.left = insets.top = insets.right = insets.bottom = 2;
82          return insets;
83      }
84  
85      /***
86       * Returns true.
87       */
88      public boolean isBorderOpaque() 
89  	{ 
90  		return true; 
91  	}
92  
93      /***
94       * Returns the etch type.
95       */
96      public int getEtchType() 
97  	{
98          return etchType;
99      }
100 
101 }