KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > VPanel


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;
15
16 import java.awt.*;
17 import java.net.*;
18 import javax.swing.*;
19 import javax.swing.border.*;
20
21 import org.compiere.grid.ed.*;
22 import org.compiere.util.*;
23 import org.compiere.plaf.*;
24 import org.compiere.swing.*;
25
26 /**
27  * Single Row Panel.
28  * Called from GridController
29  * <pre>
30  * Structure
31  * this (CPanel - Group Bag Layout)
32  * group
33  * label - field
34  *
35  * Spacing:
36  * -------------------
37  * Total Top = 10+2
38  * Total Right = 0+12
39  * Total Left = 0+12
40  * Total Bottom = 3+9
41  * -------------------
42  * 2
43  * 12 Label 0+5 Field 0
44  * 3+2=5
45  * 12 Label 0+5 Field 0
46  * 3
47  *
48  * </pre>
49  * @author Jorg Janke
50  * @version $Id: VPanel.java,v 1.10 2002/07/13 04:24:47 jjanke Exp $
51  */

52 public final class VPanel extends CPanel
53 {
54     /**
55      * Constructor
56      */

57     public VPanel()
58     {
59         super(new GridBagLayout());
60         setName("VPanel");
61         setBorder(null);
62
63         // Set initial values of constraint
64
m_gbc.anchor = GridBagConstraints.NORTHWEST;
65         m_gbc.gridy = 0; // line
66
m_gbc.gridx = 0;
67         m_gbc.gridheight = 1;
68         m_gbc.gridwidth = 1;
69         m_gbc.insets = m_zeroInset;
70         m_gbc.fill = GridBagConstraints.HORIZONTAL;
71         m_gbc.weightx = 0;
72         m_gbc.weighty = 0;
73         m_gbc.ipadx = 0;
74         m_gbc.ipady = 0;
75     } // VPanel
76

77     /** GridBag Constraint */
78     private GridBagConstraints m_gbc = new GridBagConstraints();
79
80     /** Orientation */
81     private final boolean m_leftToRight = Language.getLanguage().isLeftToRight();
82     /** Label Inset */
83     private final Insets m_labelInset =
84         m_leftToRight ? new Insets(2,12,3,0) : new Insets(2,5,3,0); // top,left,bottom,right
85
/** Field Inset */
86     private final Insets m_fieldInset =
87         m_leftToRight ? new Insets(2,5,3,0) : new Insets(2,12,3,0); // top,left,bottom,right
88
/** Zero Inset */
89     private final Insets m_zeroInset = new Insets(0,0,0,0);
90     //
91
private int m_line = 0;
92     private boolean m_hGapAdded = false; // only once
93
/** Previous Field Group Header */
94     private String JavaDoc m_oldFieldGroup = null;
95
96
97     /**
98      * Add Field and Label to Panel
99      * @param label label
100      * @param editor editor
101      * @param isSameLine same line
102      * @param isLongField long field
103      * @param displayType display type
104      * @param groupName group name
105      */

106     public void addField (JLabel label, VEditor editor,
107         boolean isSameLine, boolean isLongField, int displayType, String JavaDoc groupName)
108     {
109         if (label == null && editor == null)
110             return;
111
112         boolean sameLine = isSameLine;
113         if (addGroup(groupName)) // sets top
114
sameLine = false;
115
116         if (sameLine) // Set line #
117
m_gbc.gridy = m_line-1;
118         else
119             m_gbc.gridy = m_line++;
120
121         // *** The Label ***
122
if (label != null)
123         {
124             m_gbc.gridwidth = 1;
125             m_gbc.insets = m_labelInset;
126             m_gbc.fill = GridBagConstraints.HORIZONTAL; // required for right justified
127
// Set column #
128
if (m_leftToRight)
129                 m_gbc.gridx = sameLine ? 2 : 0;
130             else
131                 m_gbc.gridx = sameLine | isLongField ? 3 : 1;
132             // Weight factor for Label
133
m_gbc.weightx = 0;
134             // Add Label
135
this.add(label, m_gbc);
136         }
137
138         // *** The Field ***
139
if (editor != null)
140         {
141             Component field = (Component)editor;
142             // Default Width
143
m_gbc.gridwidth = isLongField ? 3 : 1;
144             m_gbc.insets = m_fieldInset;
145         // m_gbc.fill = GridBagConstraints.NONE;
146
m_gbc.fill = GridBagConstraints.HORIZONTAL;
147             // Set column #
148
if (m_leftToRight)
149                 m_gbc.gridx = sameLine ? 3 : 1;
150             else
151                 m_gbc.gridx = sameLine ? 2 : 0;
152             // Weight factor for Fields
153
m_gbc.weightx = 1;
154             // Add Field
155
this.add(field, m_gbc);
156             // Link Label to Field
157
if (label != null)
158                 label.setLabelFor(field);
159         }
160
161
162         // ADebug.trace(ADebug.l5_DData, m_cField[i].m_mField.ColumnName
163
// + " \t line="+ gbc.gridy + " column="+gbc.gridx
164
// + " width="+gbc.gridwidth);
165
} // addField
166

167     /**
168      * Add Group
169      * @param fieldGroup field group
170      * @return true if group added
171      */

172     private boolean addGroup(String JavaDoc fieldGroup)
173     {
174         // First time - add top
175
if (m_oldFieldGroup == null)
176         {
177             addTop();
178             m_oldFieldGroup = "";
179         }
180
181         if (fieldGroup == null || fieldGroup.length() == 0 || fieldGroup.equals(m_oldFieldGroup))
182             return false;
183         m_oldFieldGroup = fieldGroup;
184
185         CPanel group = new CPanel();
186         group.setBorder(new VLine(fieldGroup));
187         group.add(Box.createVerticalStrut(VLine.SPACE));
188         m_gbc.gridx = 0;
189         m_gbc.gridy = m_line++;
190         m_gbc.gridwidth = 4;
191         this.add(group, m_gbc);
192         // reset
193
m_gbc.gridwidth = 1;
194         return true;
195     } // addGroup
196

197     /**
198      * Add Top (10) and right (12) gap
199      */

200     private void addTop()
201     {
202         // Top Gap
203
m_gbc.gridy = m_line++;
204         this.add(Box.createVerticalStrut(10), m_gbc); // top gap
205
// Right gap
206
m_gbc.gridx = 4; // 5th column
207
m_gbc.gridwidth = 1;
208         m_gbc.weightx = 0;
209         m_gbc.insets = m_zeroInset;
210         m_gbc.fill = GridBagConstraints.NONE;
211         this.add(Box.createHorizontalStrut(12), m_gbc);
212     } // addTop
213

214     /**
215      * Add End (9) of Form
216      */

217     public void addEnd()
218     {
219         m_gbc.gridx = 0;
220         m_gbc.gridy = m_line;
221         m_gbc.gridwidth = 1;
222         m_gbc.insets = m_zeroInset;
223         m_gbc.fill = GridBagConstraints.HORIZONTAL;
224         m_gbc.weightx = 0;
225         //
226
this.add(Box.createVerticalStrut(9), m_gbc); // botton gap
227
} // addEnd
228

229     /*************************************************************************/
230
231     /**
232      * Set Background to AD_Color_ID (nop)
233      * @param AD_Color_ID Color
234      */

235     public void setBackground (int AD_Color_ID)
236     {
237     } // setBackground
238

239 } // VPanel
240
Popular Tags