1 2 24 package org.enhydra.tool.codegen.wizard; 25 26 import org.enhydra.tool.ToolBoxInfo; 28 import org.enhydra.tool.codegen.CodeGen; 29 import org.enhydra.tool.codegen.GeneratorOption; 30 import org.enhydra.tool.codegen.GeneratorException; 31 import org.enhydra.tool.codegen.Generator; 32 import org.enhydra.tool.codegen.ValidationException; 33 import org.enhydra.tool.common.PathHandle; 34 import org.enhydra.tool.common.SwingUtil; 35 36 import javax.swing.*; 38 import javax.swing.border.*; 39 import java.awt.event.ActionEvent ; 40 import java.awt.event.ActionListener ; 41 import java.awt.event.ItemEvent ; 42 import java.awt.event.ItemListener ; 43 import java.awt.*; 44 import java.beans.*; 45 import java.io.File ; 46 import java.util.ResourceBundle ; 47 48 52 public class GenSelectionPanel extends CodeGenPanel { 53 54 transient private GridBagLayout layoutMain; 56 transient private BorderLayout layoutDescription; 57 transient private JComboBox comboGenerator; 58 transient private JLabel labelGenerator; 59 transient private JPanel panelDescription; 60 transient private JTextArea textDescription; 61 transient private Generator[] generators = new Generator[0]; 62 transient private LocalItemListener itemListener = null; 63 transient private Generator selection = null; 64 transient private JPanel panelFiller; 65 66 70 public GenSelectionPanel() { 71 try { 72 jbInit(); 73 pmInit(); 74 } catch (Exception ex) { 75 ex.printStackTrace(); 76 } 77 } 78 79 85 public String getPageTitle() { 86 return "Select a component type"; 87 } 88 89 95 public String getInstructions() { 96 return "Select the type of component you would like " 97 + "to generate. The description applies the the current " 98 + "selection."; 99 } 100 101 104 public void readOptionSet() {} 105 106 109 public void writeOptionSet() {} 110 111 114 public void validateOptionSet() throws ValidationException {} 115 116 122 public Generator[] getGenerators() { 123 return generators; 124 } 125 126 132 public void setGenerators(Generator[] g) { 133 generators = g; 134 comboGenerator.removeAllItems(); 135 for (int i = 0; i < generators.length; i++) { 136 comboGenerator.addItem(generators[i]); 137 } 138 comboGenerator.repaint(); 139 } 140 141 147 public Generator getSelection() { 148 return selection; 149 } 150 151 protected void setSelection(Generator sel) { 152 ComboBoxModel model = comboGenerator.getModel(); 153 int count = model.getSize(); 154 155 for (int i = 0; i < count; i++) { 156 if (model.getElementAt(i) instanceof Generator) { 157 Generator cursor = (Generator) model.getElementAt(i); 158 159 if (cursor.getDescription().equalsIgnoreCase(sel.getDescription())) { 160 comboGenerator.setSelectedIndex(i); 161 break; 162 } 163 } 164 } 165 } 166 167 private void jbInit() throws Exception { 171 panelDescription = 172 (JPanel) Beans.instantiate(getClass().getClassLoader(), 173 JPanel.class.getName()); 174 labelGenerator = 175 (JLabel) Beans.instantiate(getClass().getClassLoader(), 176 JLabel.class.getName()); 177 textDescription = 178 (JTextArea) Beans.instantiate(getClass().getClassLoader(), 179 JTextArea.class.getName()); 180 comboGenerator = 181 (JComboBox) Beans.instantiate(getClass().getClassLoader(), 182 JComboBox.class.getName()); 183 layoutMain = 184 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 185 GridBagLayout.class.getName()); 186 layoutDescription = 187 (BorderLayout) Beans.instantiate(getClass().getClassLoader(), 188 BorderLayout.class.getName()); 189 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 190 JPanel.class.getName()); 191 labelGenerator.setMaximumSize(new Dimension(80, 20)); 192 labelGenerator.setMinimumSize(new Dimension(80, 20)); 193 labelGenerator.setPreferredSize(new Dimension(80, 20)); 194 labelGenerator.setLabelFor(comboGenerator); 195 labelGenerator.setText("Component type:"); 196 textDescription.setDisabledTextColor(SystemColor.controlText); 197 textDescription.setBackground(SystemColor.text); 198 textDescription.setBounds(2, 2, 2, 2); 199 textDescription.setMargin(new Insets(5, 5, 5, 5)); 200 textDescription.setEnabled(false); 201 textDescription.setEditable(false); 202 textDescription.setWrapStyleWord(true); 203 textDescription.setFont(labelGenerator.getFont()); 204 textDescription.setLineWrap(true); 205 panelDescription.setLayout(layoutDescription); 206 panelDescription.setBorder(BorderFactory.createEtchedBorder()); 207 panelDescription.setMaximumSize(new Dimension(220, 70)); 208 panelDescription.setMinimumSize(new Dimension(220, 70)); 209 panelDescription.setPreferredSize(new Dimension(220, 70)); 210 panelDescription.add(textDescription, BorderLayout.CENTER); 211 comboGenerator.setMaximumSize(new Dimension(100, 21)); 212 comboGenerator.setMinimumSize(new Dimension(100, 21)); 213 comboGenerator.setPreferredSize(new Dimension(100, 21)); 214 this.setLayout(layoutMain); 215 this.add(panelFiller, 216 new GridBagConstraints(3, 0, 1, 1, 0.1, 0.1, 217 GridBagConstraints.CENTER, 218 GridBagConstraints.BOTH, 219 new Insets(0, 0, 0, 0), 0, 0)); 220 this.add(comboGenerator, 221 new GridBagConstraints(1, 0, 2, 1, 0.5, 0.5, 222 GridBagConstraints.WEST, 223 GridBagConstraints.NONE, 224 new Insets(5, 5, 5, 5), 100, 0)); 225 this.add(labelGenerator, 226 new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5, 227 GridBagConstraints.WEST, 228 GridBagConstraints.NONE, 229 new Insets(5, 10, 5, 0), 60, 15)); 230 this.add(panelDescription, 231 new GridBagConstraints(0, 1, 4, 1, 0.5, 0.5, 232 GridBagConstraints.NORTHWEST, 233 GridBagConstraints.VERTICAL, 234 new Insets(5, 5, 5, 5), 150, 80)); 235 } 236 237 private void pmInit() { 238 itemListener = new LocalItemListener(); 239 comboGenerator.addItemListener(itemListener); 240 } 241 242 private class LocalItemListener implements ItemListener { 243 public void itemStateChanged(ItemEvent event) { 244 Object item = comboGenerator.getSelectedItem(); 245 246 if (item instanceof Generator) { 247 selection = (Generator) item; 248 textDescription.setText(selection.getDescription()); 249 } else { 250 selection = null; 251 textDescription.setText(new String ()); 252 } 253 } 254 255 } 256 } 257 | Popular Tags |