1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 /***
29 * This class is a JPanel containing configuration settings derived from a particular
30 * JAG application generation template.
31 *
32 * @author Michael O'Connor - Finalist IT Group
33 */
34 public class TemplateConfigPanel extends JPanel {
35
36 private HashMap configComponents = new HashMap();
37
38
39 public TemplateConfigPanel(TemplateConfigParameter[] params) {
40 super();
41 setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
42 for (int i = 0; i < params.length; i++) {
43 int y = (i * 25) + 20;
44 JLabel jLabel1 = new JLabel();
45 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
46 jLabel1.setText(params[i].getName() + ':');
47 String description = params[i].getDescription();
48 if (description != null) {
49 jLabel1.setToolTipText(description);
50 }
51 add(jLabel1, new AbsoluteConstraints(0, y, 150, -1));
52
53 JComponent component = null;
54 if (params[i].getType() == TemplateConfigParameter.TYPE_TEXT) {
55 component = new JTextField();
56 component.setName(params[i].getId());
57 }
58 else if (params[i].getType() == TemplateConfigParameter.TYPE_CHECKBOX) {
59 component = new JCheckBox();
60 component.setName(params[i].getId());
61
62 }
63 else if (params[i].getType() == TemplateConfigParameter.TYPE_LIST) {
64 component = new JComboBox(params[i].getPresetValues());
65 component.setName(params[i].getId());
66
67 }
68 else if (params[i].getType() == TemplateConfigParameter.TYPE_EDITABLE_LIST) {
69 component = new JComboBox(params[i].getPresetValues());
70 component.setName(params[i].getId());
71 ((JComboBox) component).setEditable(true);
72 }
73 else {
74 JagGenerator.logToConsole("ERROR: Template's config contains an unknown parameter type.");
75 continue;
76 }
77
78 if (description != null) {
79 component.setToolTipText(description);
80 }
81
82 add(component, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, y, 215, -1));
83 configComponents.put(params[i].getId(), component);
84 }
85 }
86
87 /***
88 * Gets the mapping of (String) parameter id -> JComponent for all the configurable parameters.
89 *
90 * @return
91 */
92 public Map getConfigComponents() {
93 return configComponents;
94 }
95
96 }