1 17 package com.finalist.jaggenerator.template; 18 19 import org.netbeans.lib.awtextra.AbsoluteConstraints; 20 21 import javax.swing.*; 22 23 import com.finalist.jaggenerator.JagGenerator; 24 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 34 public class TemplateConfigPanel extends JPanel { 35 36 private HashMap configComponents = new HashMap (); 37 38 39 public TemplateConfigPanel(TemplateConfigParameter[] params, String title) { 40 super(); 41 setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); 42 43 if (title != null) { 44 JLabel titleLabel = new JLabel(); 45 titleLabel.setText(title); 46 add(titleLabel, new AbsoluteConstraints(0, 0, 350, -1)); 47 titleLabel.setBorder(new javax.swing.border.TitledBorder ("Selected template:")); 48 } 49 50 for (int i = 0; i < params.length; i++) { 51 int y = (i * 25) + 45; 52 JLabel jLabel1 = new JLabel(); 53 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 54 jLabel1.setText(params[i].getName() + ':'); 55 String description = params[i].getDescription(); 56 if (description != null) { 57 jLabel1.setToolTipText(description); 58 } 59 add(jLabel1, new AbsoluteConstraints(0, y, 150, -1)); 60 61 JComponent component = null; 62 if (params[i].getType() == TemplateConfigParameter.TYPE_TEXT) { 63 component = new JTextField(); 64 component.setName(params[i].getId()); 65 } 66 else if (params[i].getType() == TemplateConfigParameter.TYPE_CHECKBOX) { 67 component = new JCheckBox(); 68 component.setName(params[i].getId()); 69 70 } 71 else if (params[i].getType() == TemplateConfigParameter.TYPE_LIST) { 72 component = new JComboBox(params[i].getPresetValues()); 73 component.setName(params[i].getId()); 74 75 } 76 else if (params[i].getType() == TemplateConfigParameter.TYPE_EDITABLE_LIST) { 77 component = new JComboBox(params[i].getPresetValues()); 78 component.setName(params[i].getId()); 79 ((JComboBox) component).setEditable(true); 80 } 81 else { 82 JagGenerator.logToConsole("ERROR: Template's config contains an unknown parameter type."); 83 continue; 84 } 85 86 if (description != null) { 87 component.setToolTipText(description); 88 } 89 90 add(component, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, y, 215, -1)); 91 configComponents.put(params[i].getId(), component); 92 } 93 } 94 95 100 public Map getConfigComponents() { 101 return configComponents; 102 } 103 104 } 105 | Popular Tags |