1 30 31 package com.jgoodies.forms.builder; 32 33 import javax.swing.JButton ; 34 import javax.swing.JComponent ; 35 import javax.swing.JPanel ; 36 37 import com.jgoodies.forms.factories.Borders; 38 import com.jgoodies.forms.factories.FormFactory; 39 import com.jgoodies.forms.layout.ColumnSpec; 40 import com.jgoodies.forms.layout.ConstantSize; 41 import com.jgoodies.forms.layout.FormLayout; 42 import com.jgoodies.forms.layout.RowSpec; 43 44 82 public final class ButtonBarBuilder extends PanelBuilder { 83 84 private static final ColumnSpec[] COL_SPECS = new ColumnSpec[]{}; 85 private static final RowSpec ROW_SPEC = new RowSpec("center:pref"); 86 private static final RowSpec[] ROW_SPECS = new RowSpec[]{ROW_SPEC}; 87 88 private static final String NARROW_KEY = "jgoodies.isNarrow"; 89 90 91 93 99 public ButtonBarBuilder(JPanel panel) { 100 super(panel, new FormLayout(COL_SPECS, ROW_SPECS)); 101 } 102 103 107 public ButtonBarBuilder() { 108 this(new JPanel ()); 109 } 110 111 112 114 117 public void setDefaultButtonBarGapBorder() { 118 getPanel().setBorder(Borders.BUTTON_BAR_GAP_BORDER); 119 } 120 121 122 124 129 public void addGriddedButtons(JButton [] buttons) { 130 for (int i = 0; i < buttons.length; i++) { 131 addGridded(buttons[i]); 132 if (i < buttons.length - 1) 133 addRelatedGap(); 134 } 135 } 136 137 143 public void addGriddedNarrowButtons(JButton [] buttons) { 144 for (int i = 0; i < buttons.length; i++) { 145 addGriddedNarrow(buttons[i]); 146 if (i < buttons.length - 1) 147 addRelatedGap(); 148 } 149 } 150 151 157 public void addGriddedGrowingButtons(JButton [] buttons) { 158 for (int i = 0; i < buttons.length; i++) { 159 addGriddedGrowing(buttons[i]); 160 if (i < buttons.length - 1) 161 addRelatedGap(); 162 } 163 } 164 165 170 public void addFixed(JComponent component) { 171 getLayout().appendColumn(FormFactory.PREF_COLSPEC); 172 add(component); 173 nextColumn(); 174 } 175 176 181 public void addFixedNarrow(JComponent component) { 182 component.putClientProperty(NARROW_KEY, Boolean.TRUE); 183 addFixed(component); 184 } 185 186 191 public void addGridded(JComponent component) { 192 getLayout().appendColumn(FormFactory.BUTTON_COLSPEC); 193 getLayout().addGroupedColumn(getColumn()); 194 component.putClientProperty(NARROW_KEY, Boolean.TRUE); 195 add(component); 196 nextColumn(); 197 } 198 199 205 public void addGriddedNarrow(JComponent component) { 206 addGridded(component); 207 } 208 209 214 public void addGriddedGrowing(JComponent component) { 215 getLayout().appendColumn(FormFactory.GROWING_BUTTON_COLSPEC); 216 getLayout().addGroupedColumn(getColumn()); 217 component.putClientProperty(NARROW_KEY, Boolean.TRUE); 218 add(component); 219 nextColumn(); 220 } 221 222 227 public void addGriddedGrowingNarrow(JComponent component) { 228 component.putClientProperty(NARROW_KEY, Boolean.TRUE); 229 addGriddedGrowing(component); 230 } 231 232 236 public void addGlue() { 237 appendGlueColumn(); 238 nextColumn(); 239 } 240 241 244 public void addRelatedGap() { 245 appendRelatedComponentsGapColumn(); 246 nextColumn(); 247 } 248 249 252 public void addUnrelatedGap() { 253 appendUnrelatedComponentsGapColumn(); 254 nextColumn(); 255 } 256 257 262 public void addStrut(ConstantSize size) { 263 getLayout().appendColumn(new ColumnSpec(ColumnSpec.LEFT, 264 size, 265 ColumnSpec.NO_GROW)); 266 nextColumn(); 267 } 268 269 270 } 271 | Popular Tags |