View Javadoc

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;
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  }