001: /* Copyright (C) 2003 Finalist IT Group
002: *
003: * This file is part of JAG - the Java J2EE Application Generator
004: *
005: * JAG is free software; you can redistribute it and/or modify
006: * it under the terms of the GNU General Public License as published by
007: * the Free Software Foundation; either version 2 of the License, or
008: * (at your option) any later version.
009: * JAG is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: * You should have received a copy of the GNU General Public License
014: * along with JAG; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016: */
017: package com.finalist.jaggenerator.template;
018:
019: import org.netbeans.lib.awtextra.AbsoluteConstraints;
020:
021: import javax.swing.*;
022:
023: import com.finalist.jaggenerator.JagGenerator;
024:
025: import java.util.HashMap;
026: import java.util.Map;
027:
028: /**
029: * This class is a JPanel containing configuration settings derived from a particular
030: * JAG application generation template.
031: *
032: * @author Michael O'Connor - Finalist IT Group
033: */
034: public class TemplateConfigPanel extends JPanel {
035:
036: private HashMap configComponents = new HashMap();
037:
038: public TemplateConfigPanel(TemplateConfigParameter[] params,
039: String title) {
040: super ();
041: setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
042:
043: if (title != null) {
044: JLabel titleLabel = new JLabel();
045: titleLabel.setText(title);
046: add(titleLabel, new AbsoluteConstraints(0, 0, 350, -1));
047: titleLabel.setBorder(new javax.swing.border.TitledBorder(
048: "Selected template:"));
049: }
050:
051: for (int i = 0; i < params.length; i++) {
052: int y = (i * 25) + 45;
053: JLabel jLabel1 = new JLabel();
054: jLabel1
055: .setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
056: jLabel1.setText(params[i].getName() + ':');
057: String description = params[i].getDescription();
058: if (description != null) {
059: jLabel1.setToolTipText(description);
060: }
061: add(jLabel1, new AbsoluteConstraints(0, y, 150, -1));
062:
063: JComponent component = null;
064: if (params[i].getType() == TemplateConfigParameter.TYPE_TEXT) {
065: component = new JTextField();
066: component.setName(params[i].getId());
067: } else if (params[i].getType() == TemplateConfigParameter.TYPE_CHECKBOX) {
068: component = new JCheckBox();
069: component.setName(params[i].getId());
070:
071: } else if (params[i].getType() == TemplateConfigParameter.TYPE_LIST) {
072: component = new JComboBox(params[i].getPresetValues());
073: component.setName(params[i].getId());
074:
075: } else if (params[i].getType() == TemplateConfigParameter.TYPE_EDITABLE_LIST) {
076: component = new JComboBox(params[i].getPresetValues());
077: component.setName(params[i].getId());
078: ((JComboBox) component).setEditable(true);
079: } else {
080: JagGenerator
081: .logToConsole("ERROR: Template's config contains an unknown parameter type.");
082: continue;
083: }
084:
085: if (description != null) {
086: component.setToolTipText(description);
087: }
088:
089: add(component,
090: new org.netbeans.lib.awtextra.AbsoluteConstraints(
091: 150, y, 215, -1));
092: configComponents.put(params[i].getId(), component);
093: }
094: }
095:
096: /**
097: * Gets the mapping of (String) parameter id -> JComponent for all the configurable parameters.
098: *
099: * @return
100: */
101: public Map getConfigComponents() {
102: return configComponents;
103: }
104:
105: }
|