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.FormFactory; 38 import com.jgoodies.forms.layout.ColumnSpec; 39 import com.jgoodies.forms.layout.ConstantSize; 40 import com.jgoodies.forms.layout.FormLayout; 41 import com.jgoodies.forms.layout.RowSpec; 42 43 69 public final class ButtonStackBuilder extends PanelBuilder { 70 71 private static final ColumnSpec[] COL_SPECS = 72 new ColumnSpec[] { FormFactory.BUTTON_COLSPEC }; 73 74 private static final RowSpec[] ROW_SPECS = 75 new RowSpec[]{}; 76 77 private static final String NARROW_KEY = "jgoodies.isNarrow"; 78 79 80 82 88 public ButtonStackBuilder(JPanel panel) { 89 super(panel, new FormLayout(COL_SPECS, ROW_SPECS)); 90 } 91 92 96 public ButtonStackBuilder() { 97 this(new JPanel ()); 98 } 99 100 101 103 108 public void addButtons(JButton [] buttons) { 109 for (int i = 0; i < buttons.length; i++) { 110 addGridded(buttons[i]); 111 if (i < buttons.length - 1) 112 addRelatedGap(); 113 } 114 } 115 116 121 public void addFixed(JComponent component) { 122 getLayout().appendRow(FormFactory.PREF_ROWSPEC); 123 add(component); 124 nextRow(); 125 } 126 127 132 public void addGridded(JComponent component) { 133 getLayout().appendRow(FormFactory.PREF_ROWSPEC); 134 getLayout().addGroupedRow(getRow()); 135 add(component); 136 nextRow(); 137 } 138 139 144 public void addGriddedNarrow(JComponent component) { 145 component.putClientProperty(NARROW_KEY, Boolean.TRUE); 146 addGridded(component); 147 } 148 149 153 public void addGlue() { 154 appendGlueRow(); 155 nextRow(); 156 } 157 158 161 public void addRelatedGap() { 162 appendRelatedComponentsGapRow(); 163 nextRow(); 164 } 165 166 169 public void addUnrelatedGap() { 170 appendUnrelatedComponentsGapRow(); 171 nextRow(); 172 } 173 174 179 public void addStrut(ConstantSize size) { 180 getLayout().appendRow(new RowSpec(RowSpec.TOP, 181 size, 182 RowSpec.NO_GROW)); 183 nextRow(); 184 } 185 186 187 } 188 | Popular Tags |