KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > finalist > jaggenerator > template > TemplateConfigPanel


1 /* Copyright (C) 2003 Finalist IT Group
2  *
3  * This file is part of JAG - the Java J2EE Application Generator
4  *
5  * JAG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * JAG is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with JAG; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 JavaDoc;
26 import java.util.Map JavaDoc;
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 JavaDoc configComponents = new HashMap JavaDoc();
37
38
39    public TemplateConfigPanel(TemplateConfigParameter[] params, String JavaDoc 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 JavaDoc("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 JavaDoc 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    /**
96     * Gets the mapping of (String) parameter id -> JComponent for all the configurable parameters.
97     *
98     * @return
99     */

100    public Map JavaDoc getConfigComponents() {
101       return configComponents;
102    }
103
104 }
105
Popular Tags