1 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 52 public final class VPanel extends CPanel 53 { 54 57 public VPanel() 58 { 59 super(new GridBagLayout()); 60 setName("VPanel"); 61 setBorder(null); 62 63 m_gbc.anchor = GridBagConstraints.NORTHWEST; 65 m_gbc.gridy = 0; 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 } 77 78 private GridBagConstraints m_gbc = new GridBagConstraints(); 79 80 81 private final boolean m_leftToRight = Language.getLanguage().isLeftToRight(); 82 83 private final Insets m_labelInset = 84 m_leftToRight ? new Insets(2,12,3,0) : new Insets(2,5,3,0); 86 private final Insets m_fieldInset = 87 m_leftToRight ? new Insets(2,5,3,0) : new Insets(2,12,3,0); 89 private final Insets m_zeroInset = new Insets(0,0,0,0); 90 private int m_line = 0; 92 private boolean m_hGapAdded = false; 94 private String m_oldFieldGroup = null; 95 96 97 106 public void addField (JLabel label, VEditor editor, 107 boolean isSameLine, boolean isLongField, int displayType, String groupName) 108 { 109 if (label == null && editor == null) 110 return; 111 112 boolean sameLine = isSameLine; 113 if (addGroup(groupName)) sameLine = false; 115 116 if (sameLine) m_gbc.gridy = m_line-1; 118 else 119 m_gbc.gridy = m_line++; 120 121 if (label != null) 123 { 124 m_gbc.gridwidth = 1; 125 m_gbc.insets = m_labelInset; 126 m_gbc.fill = GridBagConstraints.HORIZONTAL; if (m_leftToRight) 129 m_gbc.gridx = sameLine ? 2 : 0; 130 else 131 m_gbc.gridx = sameLine | isLongField ? 3 : 1; 132 m_gbc.weightx = 0; 134 this.add(label, m_gbc); 136 } 137 138 if (editor != null) 140 { 141 Component field = (Component)editor; 142 m_gbc.gridwidth = isLongField ? 3 : 1; 144 m_gbc.insets = m_fieldInset; 145 m_gbc.fill = GridBagConstraints.HORIZONTAL; 147 if (m_leftToRight) 149 m_gbc.gridx = sameLine ? 3 : 1; 150 else 151 m_gbc.gridx = sameLine ? 2 : 0; 152 m_gbc.weightx = 1; 154 this.add(field, m_gbc); 156 if (label != null) 158 label.setLabelFor(field); 159 } 160 161 162 } 167 172 private boolean addGroup(String fieldGroup) 173 { 174 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 m_gbc.gridwidth = 1; 194 return true; 195 } 197 200 private void addTop() 201 { 202 m_gbc.gridy = m_line++; 204 this.add(Box.createVerticalStrut(10), m_gbc); m_gbc.gridx = 4; 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 } 214 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 this.add(Box.createVerticalStrut(9), m_gbc); } 229 230 231 235 public void setBackground (int AD_Color_ID) 236 { 237 } 239 } | Popular Tags |