KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > ed > VLine


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.grid.ed;
15
16 import java.awt.*;
17 import java.awt.Component JavaDoc;
18 import java.awt.Graphics JavaDoc;
19 import javax.swing.border.*;
20
21 import org.compiere.util.*;
22 import org.compiere.plaf.*;
23
24 /**
25  * Horizontal Line with Text
26  *
27  * @author Jorg Janke
28  * @version $Id: VLine.java,v 1.5 2002/06/15 02:43:57 jjanke Exp $
29  */

30 public class VLine extends AbstractBorder
31 {
32     /**
33      * IDE Bean Constructor
34      */

35     public VLine()
36     {
37         this("");
38     } // VLine
39

40     /**
41      * Constructor
42      * @param header
43      */

44     public VLine(String JavaDoc header)
45     {
46         super();
47         setHeader(header);
48     } // VLine
49

50     /** Header */
51     private String JavaDoc m_header = "";
52
53     private Font m_font = CompierePLAF.getFont_Label();
54     private Color m_color = CompierePLAF.getTextColor_Label();
55
56     /** Gap between element */
57     public final static int GAP = 5;
58     /** space for characters below line (y) */
59     public final static int SPACE = 4; // used in VPanel
60

61     /**
62      * Paint Border
63      * @param c the component for which this border is being painted
64      * @param g the paint graphics
65      * @param x the x position of the painted border
66      * @param y the y position of the painted border
67      * @param w the width of the painted border
68      * @param h the height of the painted border
69      */

70     public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h)
71     {
72         Graphics JavaDoc copy = g.create();
73         if (copy != null)
74         {
75             try
76             {
77                 copy.translate(x, y);
78                 paintLine(c, copy, w, h);
79             }
80             finally
81             {
82                 copy.dispose();
83             }
84         }
85     } // paintBorder
86

87     /**
88      * Paint Line with Header
89      * @param c
90      * @param g
91      * @param w
92      * @param h
93      */

94     private void paintLine (Component JavaDoc c, Graphics JavaDoc g, int w, int h)
95     {
96         int y = h-SPACE;
97         // Line
98
g.setColor(Color.darkGray);
99         g.drawLine(GAP, y, w-GAP, y);
100         g.setColor(Color.white);
101         g.drawLine(GAP, y+1, w-GAP, y+1); // last part of line
102

103         if (m_header == null || m_header.length() == 0)
104             return;
105
106         // Header Text
107
g.setColor(m_color);
108         g.setFont(m_font);
109         int x = GAP;
110         if (!Language.getLanguage().isLeftToRight())
111         {
112         }
113         g.drawString(m_header, GAP, h-SPACE-1);
114     } // paintLine
115

116     /**
117      * Set Header
118      * @param newHeader String - '_' are replaced by spaces
119      */

120     public void setHeader(String JavaDoc newHeader)
121     {
122         m_header = newHeader.replace('_', ' ');
123     } // setHeader
124

125     /**
126      * Get Header
127      * @return header string
128      */

129     public String JavaDoc getHeader()
130     {
131         return m_header;
132     } // getHeader
133

134 } // VLine
135
Popular Tags