1 package rero.dck; 2 3 import javax.swing.*; 4 import javax.swing.table.*; 5 import javax.swing.event.*; 6 7 import java.awt.*; 8 import java.awt.event.*; 9 10 import rero.dck.items.*; 11 12 import java.util.*; 13 14 public abstract class DContainer 15 { 16 protected LinkedList itemList; 17 protected JComponent dialog; 19 protected GridBagConstraints constraints = new GridBagConstraints(); 20 protected DCapabilities capabilities; 21 22 public DContainer() 23 { 24 itemList = new LinkedList(); 25 26 constraints.gridwidth = GridBagConstraints.REMAINDER; 27 constraints.fill = GridBagConstraints.BOTH; 28 constraints.weightx = 1.0; 29 constraints.insets = new Insets(0, 0, 2, 0); 30 } 31 32 public void installCapabilities(DCapabilities c) 33 { 34 capabilities = c; 35 } 36 37 public DCapabilities getCapabilities() 38 { 39 return capabilities; 40 } 41 42 43 public JComponent getDialog() 44 { 45 if (dialog != null) 46 { 47 return dialog; 48 } 49 50 dialog = new JPanel(); 51 52 54 JComponent child = setupLayout(dialog); 55 56 58 setupDialog(); 59 60 62 int maxWidth = 0; 63 64 Iterator i = itemList.iterator(); 65 while (i.hasNext()) 66 { 67 DItem temp = (DItem)i.next(); 68 69 if (temp.getEstimatedWidth() > maxWidth) 70 { 71 maxWidth = temp.getEstimatedWidth(); 72 } 73 } 74 75 GridBagLayout layout = new GridBagLayout(); 76 child.setLayout(layout); 77 78 i = itemList.iterator(); 79 while (i.hasNext()) 80 { 81 DItem temp = (DItem)i.next(); 82 temp.setAlignWidth(maxWidth); 83 84 JComponent blah = temp.getComponent(); 85 86 layout.setConstraints(blah, constraints); 87 child.add(blah); 88 } 89 90 return dialog; 91 } 92 93 public void setEnabled(boolean b) 94 { 95 Iterator i = itemList.iterator(); 96 while (i.hasNext()) 97 { 98 DItem temp = (DItem)i.next(); 99 temp.setEnabled(b); 100 } 101 102 dialog.setEnabled(b); 103 } 104 105 public void setParent(DParent parent) 106 { 107 Iterator i = itemList.iterator(); 108 while (i.hasNext()) 109 { 110 DItem temp = (DItem)i.next(); 111 temp.setParent(parent); 112 } 113 } 114 115 public void save() 116 { 117 Iterator i = itemList.iterator(); 118 while (i.hasNext()) 119 { 120 DItem temp = (DItem)i.next(); 121 temp.save(); 122 } 123 } 124 125 public void refresh() 126 { 127 Iterator i = itemList.iterator(); 128 while (i.hasNext()) 129 { 130 DItem temp = (DItem)i.next(); 131 temp.refresh(); 132 } 133 } 134 135 public abstract JComponent setupLayout(JComponent component); 136 public abstract void setupDialog(); 137 public abstract String getTitle(); 138 139 public StringInput addStringInput(String var, String defValue, String label, char Mn) 140 { 141 StringInput temp = new StringInput(var, defValue, label, 0, Mn); 142 itemList.add(temp); 143 return temp; 144 } 145 146 public StringInput addStringInput(String var, String defValue, String label, char Mn, int gap) 147 { 148 StringInput temp = new StringInput(var, defValue, label, gap, Mn); 149 itemList.add(temp); 150 return temp; 151 } 152 153 public CheckboxInput addCheckboxInput(String variable, boolean defValue, String label, char Mn) 154 { 155 CheckboxInput temp = new CheckboxInput(variable, defValue, label, Mn); 156 itemList.add(temp); 157 return temp; 158 } 159 160 public CheckboxInput addCheckboxInput(String variable, boolean defValue, String label, char Mn, int alignment) 161 { 162 CheckboxInput temp = new CheckboxInput(variable, defValue, label, Mn, alignment); 163 itemList.add(temp); 164 return temp; 165 } 166 167 public FileInput addFileInput(String variable, String defValue, String label, char Mn, int inset) 168 { 169 FileInput temp = new FileInput(variable, defValue, label, Mn, false, inset); 170 itemList.add(temp); 171 return temp; 172 } 173 174 public DirectoryInput addDirectoryInput(String variable, String defValue, String label, char Mn, int inset) 175 { 176 DirectoryInput temp = new DirectoryInput(variable, defValue, label, Mn, inset); 177 itemList.add(temp); 178 return temp; 179 } 180 181 public ListInput addListInput(String variable, String title, String desc, int width, int height) 182 { 183 ListInput temp = new ListInput(variable, title, desc, width, height); 184 itemList.add(temp); 185 return temp; 186 } 187 188 public FontInput addFontInput(String variable, Font defaultf) 189 { 190 FontInput temp = new FontInput(variable, defaultf); 191 itemList.add(temp); 192 return temp; 193 } 194 195 public CharsetInput addCharsetInput(String variable, String label, char Mnemonic, int gap) 196 { 197 CharsetInput temp = new CharsetInput(variable, label, Mnemonic, gap); 198 itemList.add(temp); 199 return temp; 200 } 201 202 public SelectInput addSelectInput(String variable, int defaultV, String [] values, String label, char Mnemonic, int gap) 203 { 204 SelectInput temp = new SelectInput(variable, defaultV, values, label, Mnemonic, gap); 205 itemList.add(temp); 206 return temp; 207 } 208 209 public OptionInput addOptionInput(String variable, String defaultV, String [] values, String label, char Mnemonic, int gap) 210 { 211 OptionInput temp = new OptionInput(variable, defaultV, values, label, Mnemonic, gap); 212 itemList.add(temp); 213 return temp; 214 } 215 216 public NetworkSelect addNetworkSelector(String variable, String variable2) 217 { 218 NetworkSelect temp = new NetworkSelect(variable, variable2); 219 itemList.add(temp); 220 return temp; 221 } 222 223 public TextInput addTextInput(String variable, int gap) 224 { 225 TextInput temp = new TextInput(variable, gap); 226 itemList.add(temp); 227 return temp; 228 } 229 230 public ColorInput addColorInput(String variable, Color defaultColor, String text, char mnemonic) 231 { 232 ColorInput temp = new ColorInput(variable, defaultColor, text, mnemonic); 233 itemList.add(temp); 234 return temp; 235 } 236 237 public FloatInput addFloatInput(String variable, float defaultf, String text) 238 { 239 FloatInput temp = new FloatInput(variable, defaultf, text); 240 itemList.add(temp); 241 return temp; 242 } 243 244 public DGroup addDialogGroup(DGroup g) 245 { 246 itemList.add(g); 247 return g; 248 } 249 250 public BlankInput addBlankSpace() 251 { 252 BlankInput temp = new BlankInput(); 253 itemList.add(temp); 254 return temp; 255 } 256 257 public LabelInput addLabel(String text, int gap) 258 { 259 LabelInput temp = new LabelInput(text, gap); 260 itemList.add(temp); 261 return temp; 262 } 263 264 public NormalInput addLabelNormal(String text, int align) 265 { 266 NormalInput temp = new NormalInput(text, align); 267 itemList.add(temp); 268 return temp; 269 } 270 271 public DItem addComponent(JComponent component) 272 { 273 OtherInput temp = new OtherInput(component); 274 itemList.add(temp); 275 return temp; 276 } 277 278 public TabbedInput addTabbedInput() 279 { 280 TabbedInput temp = new TabbedInput(); 281 itemList.add(temp); 282 return temp; 283 } 284 285 public DItem addOther(DItem item) 286 { 287 itemList.add(item); 288 return item; 289 } 290 } 291 | Popular Tags |