1 30 31 package com.jgoodies.forms.builder; 32 33 import java.awt.Component ; 34 35 import javax.swing.JComponent ; 36 import javax.swing.JLabel ; 37 import javax.swing.JPanel ; 38 import javax.swing.SwingConstants ; 39 import javax.swing.border.Border ; 40 41 import com.jgoodies.forms.factories.Borders; 42 import com.jgoodies.forms.factories.ComponentFactory; 43 import com.jgoodies.forms.factories.DefaultComponentFactory; 44 import com.jgoodies.forms.layout.CellConstraints; 45 import com.jgoodies.forms.layout.FormLayout; 46 47 86 public class PanelBuilder extends AbstractFormBuilder { 87 88 92 private ComponentFactory componentFactory; 93 94 95 97 104 public PanelBuilder(JPanel panel, FormLayout layout){ 105 super(panel, layout); 106 } 107 108 114 public PanelBuilder(FormLayout layout){ 115 this(new JPanel (), layout); 116 } 117 118 119 121 124 public final JPanel getPanel() { 125 return (JPanel ) getContainer(); 126 } 127 128 129 131 136 public final void setBorder(Border border) { 137 getPanel().setBorder(border); 138 } 139 140 143 public final void setDefaultDialogBorder() { 144 setBorder(Borders.DIALOG_BORDER); 145 } 146 147 148 150 157 public final JLabel addLabel(String textWithMnemonic, CellConstraints constraints) { 158 JLabel label = getComponentFactory().createLabel(textWithMnemonic); 159 add(label, constraints); 160 return label; 161 } 162 163 170 public final JLabel addLabel(String textWithMnemonic, String encodedConstraints) { 171 return addLabel(textWithMnemonic, new CellConstraints(encodedConstraints)); 172 } 173 174 180 public final JLabel addLabel(String textWithMnemonic) { 181 return addLabel(textWithMnemonic, cellConstraints()); 182 } 183 184 185 187 198 public final JLabel add(JLabel label, CellConstraints labelConstraints, 199 Component component, CellConstraints componentConstraints) { 200 add(label, labelConstraints); 201 add(component, componentConstraints); 202 label.setLabelFor(component); 203 return label; 204 } 205 206 217 public final JLabel addLabel( 218 String textWithMnemonic, CellConstraints labelConstraints, 219 Component component, CellConstraints componentConstraints) { 220 JLabel label = addLabel(textWithMnemonic, labelConstraints); 221 add(component, componentConstraints); 222 label.setLabelFor(component); 223 return label; 224 } 225 226 227 229 236 public final JLabel addTitle(String text, CellConstraints constraints) { 237 JLabel titleLabel = getComponentFactory().createTitle(text); 238 add(titleLabel, constraints); 239 return titleLabel; 240 } 241 242 249 public final JLabel addTitle(String text, String encodedConstraints) { 250 return addTitle(text, new CellConstraints(encodedConstraints)); 251 } 252 253 259 public final JLabel addTitle(String text) { 260 return addTitle(text, cellConstraints()); 261 } 262 263 264 266 273 public final JComponent addSeparator(String text, CellConstraints constraints) { 274 int titleAlignment = 275 getPanel().getComponentOrientation().isLeftToRight() 276 ? SwingConstants.LEFT 277 : SwingConstants.RIGHT; 278 JComponent titledSeparator = 279 getComponentFactory().createSeparator(text, titleAlignment); 280 add(titledSeparator, constraints); 281 return titledSeparator; 282 } 283 284 291 public final JComponent addSeparator(String text, String encodedConstraints) { 292 return addSeparator(text, new CellConstraints(encodedConstraints)); 293 } 294 295 302 public final JComponent addSeparator(String text, int columnSpan) { 303 return addSeparator(text, new CellConstraints(getColumn(), 304 getRow(), 305 columnSpan, 306 1)); 307 } 308 309 315 public final JComponent addSeparator(String text) { 316 return addSeparator(text, getLayout().getColumnCount()); 317 } 318 319 320 322 329 protected final ComponentFactory getComponentFactory() { 330 if (componentFactory == null) { 331 componentFactory = DefaultComponentFactory.getInstance(); 332 } 333 return componentFactory; 334 } 335 336 341 protected final void setComponentFactory(ComponentFactory newFactory) { 342 componentFactory = newFactory; 343 } 344 345 346 } 347 | Popular Tags |