1 30 31 package com.jgoodies.forms.factories; 32 33 import com.jgoodies.forms.layout.ColumnSpec; 34 import com.jgoodies.forms.layout.ConstantSize; 35 import com.jgoodies.forms.layout.FormLayout; 36 import com.jgoodies.forms.layout.RowSpec; 37 import com.jgoodies.forms.layout.Sizes; 38 import com.jgoodies.forms.util.LayoutStyle; 39 40 69 public final class FormFactory { 70 71 72 74 public static final ColumnSpec MIN_COLSPEC = 75 new ColumnSpec(Sizes.MINIMUM).asUnmodifyable(); 76 77 public static final ColumnSpec PREF_COLSPEC = 78 new ColumnSpec(Sizes.PREFERRED).asUnmodifyable(); 79 80 public static final ColumnSpec DEFAULT_COLSPEC = 81 new ColumnSpec(Sizes.DEFAULT).asUnmodifyable(); 82 83 public static final ColumnSpec GLUE_COLSPEC = 84 new ColumnSpec(ColumnSpec.DEFAULT, Sizes.ZERO, ColumnSpec.DEFAULT_GROW).asUnmodifyable(); 85 86 91 public static final ColumnSpec RELATED_GAP_COLSPEC = 92 createGapColumnSpec(LayoutStyle.getCurrent().getRelatedComponentsPadX()); 93 94 public static final ColumnSpec UNRELATED_GAP_COLSPEC = 95 createGapColumnSpec(LayoutStyle.getCurrent().getUnrelatedComponentsPadX()); 96 97 public static final ColumnSpec BUTTON_COLSPEC = 98 new ColumnSpec(Sizes.bounded(Sizes.PREFERRED, 99 LayoutStyle.getCurrent().getDefaultButtonWidth(), 100 null)).asUnmodifyable(); 101 102 public static final ColumnSpec GROWING_BUTTON_COLSPEC = 103 new ColumnSpec(ColumnSpec.DEFAULT, 104 BUTTON_COLSPEC.getSize(), 105 ColumnSpec.DEFAULT_GROW).asUnmodifyable(); 106 107 108 110 public static final RowSpec MIN_ROWSPEC = 111 new RowSpec(Sizes.MINIMUM).asUnmodifyable(); 112 113 public static final RowSpec PREF_ROWSPEC = 114 new RowSpec(Sizes.PREFERRED).asUnmodifyable(); 115 116 public static final RowSpec DEFAULT_ROWSPEC = 117 new RowSpec(Sizes.DEFAULT).asUnmodifyable(); 118 119 public static final RowSpec GLUE_ROWSPEC = 120 new RowSpec(RowSpec.DEFAULT, Sizes.ZERO, RowSpec.DEFAULT_GROW).asUnmodifyable(); 121 122 127 public static final RowSpec RELATED_GAP_ROWSPEC = 128 createGapRowSpec(LayoutStyle.getCurrent().getRelatedComponentsPadY()); 129 130 public static final RowSpec UNRELATED_GAP_ROWSPEC = 131 createGapRowSpec(LayoutStyle.getCurrent().getUnrelatedComponentsPadY()); 132 133 public static final RowSpec LINE_GAP_ROWSPEC = 134 createGapRowSpec(LayoutStyle.getCurrent().getLinePad()); 135 136 public static final RowSpec NARROW_LINE_GAP_ROWSPEC = 137 createGapRowSpec(LayoutStyle.getCurrent().getNarrowLinePad()); 138 139 public static final RowSpec PARAGRAPH_GAP_ROWSPEC = 140 createGapRowSpec(LayoutStyle.getCurrent().getParagraphPad()); 141 142 143 144 146 160 public static FormLayout createColumnLayout( 161 int majorColumns, 162 int minorColumns, 163 ColumnSpec labelColumnSpec) { 164 return createColumnLayout( 165 majorColumns, 166 minorColumns, 167 labelColumnSpec, 168 Sizes.DLUX14, 169 Sizes.DLUX2); 170 } 171 172 193 public static FormLayout createColumnLayout( 194 int majorColumns, 195 int minorColumns, 196 ColumnSpec labelColumnSpec, 197 ConstantSize indent, 198 ConstantSize minorColumnGap) { 199 return createColumnLayout( 200 majorColumns, 201 minorColumns, 202 labelColumnSpec, 203 PREF_COLSPEC, 204 indent, 205 Sizes.DLUX14, 206 minorColumnGap); 207 } 208 209 233 public static FormLayout createColumnLayout( 234 int majorColumns, 235 int minorColumns, 236 ColumnSpec labelColumnSpec, 237 ColumnSpec componentColumnSpec, 238 ConstantSize indent, 239 ConstantSize majorColumnGap, 240 ConstantSize minorColumnGap) { 241 242 ColumnSpec majorGapColSpec = createGapColumnSpec(majorColumnGap); 243 ColumnSpec minorGapColSpec = createGapColumnSpec(minorColumnGap); 244 FormLayout layout = new FormLayout(new ColumnSpec[]{}, new RowSpec[]{}); 245 246 if (indent != null) { 248 layout.appendColumn(createGapColumnSpec(indent)); 249 } 250 for (int i = 0; i < majorColumns; i++) { 251 if (labelColumnSpec != null) { 253 layout.appendColumn(labelColumnSpec); 254 layout.appendColumn(RELATED_GAP_COLSPEC); 255 } 256 for (int j = 0; j < minorColumns; j++) { 258 layout.appendColumn(componentColumnSpec); 259 layout.addGroupedColumn(layout.getColumnCount()); 260 if (j < minorColumns - 1) { 261 layout.appendColumn(minorGapColSpec); 262 } 263 } 264 if (i < majorColumns - 1) { 266 layout.appendColumn(majorGapColSpec); 267 } 268 } 269 return layout; 270 } 271 272 273 275 282 public static ColumnSpec createGapColumnSpec(ConstantSize gapSize) { 283 ColumnSpec spec = new ColumnSpec(ColumnSpec.LEFT, gapSize, ColumnSpec.NO_GROW); 284 return spec.asUnmodifyable(); 285 } 286 287 294 public static RowSpec createGapRowSpec(ConstantSize gapSize) { 295 RowSpec spec = new RowSpec(RowSpec.TOP, gapSize, RowSpec.NO_GROW); 296 return spec.asUnmodifyable(); 297 } 298 299 300 } 301 | Popular Tags |