1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.ui;
20
21 import java.awt.Color;
22 import java.awt.Dimension;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import javax.swing.JEditorPane;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.JScrollPane;
30 import javax.swing.JTable;
31 import javax.swing.JTextField;
32 import javax.swing.SpringLayout;
33 import javax.swing.table.DefaultTableModel;
34 import javax.swing.text.html.HTMLEditorKit;
35
36 import net.sf.jameleon.bean.Attribute;
37 import net.sf.jameleon.bean.FunctionalPoint;
38
39 public class JameleonTagsPanel extends JPanel implements FPDisplayer {
40 private static final long serialVersionUID = 1L;
41 protected JTextField tagNameF = new JTextField(15);
42 protected JTextField typeF = new JTextField(15);
43 protected JTextField authorF = new JTextField(15);
44 protected JTextField applicationsF = new JTextField(15);
45
46 protected JEditorPane descriptionF = new JEditorPane();
47 protected JEditorPane stepsF = new JEditorPane();
48 protected DefaultTableModel attributeData = new AttributeTableModel(new Object[]{"Variable Name","Description", "Type","Required","Default Value"},0);
49
50 protected JTable attributesT = new SortableJTable(new TableSorter(attributeData));
51 protected static final int FIELD_WIDTH = 350;
52 protected static final int DESC_HEIGHT = 65;
53 protected static final int TABLE_HEIGHT = 80;
54
55 public JameleonTagsPanel() {
56 super();
57 setUpFunctionalPointFields();
58 final JLabel tagNameL = new JLabel("Tag Name(s):");
59 final JLabel typeL = new JLabel("Type:");
60 final JLabel authorL = new JLabel("Author:");
61 final JLabel applicationsL = new JLabel("Applications:");
62 final JLabel descriptionL = new JLabel("Use:");
63 final JLabel stepsL = new JLabel("Steps:");
64 final JLabel attributesL = new JLabel("Atributes:");
65
66 SpringLayout fpSpringLayout = new SpringLayout();
67 JScrollPane descScrollPane = new JScrollPane(descriptionF);
68 JScrollPane stepsScrollPane = new JScrollPane(stepsF);
69 JScrollPane attsScrollPane = new JScrollPane(attributesT);
70
71 setLayout(fpSpringLayout);
72 add(tagNameL);
73 tagNameL.setLabelFor(tagNameF);
74 tagNameF.setMaximumSize(new Dimension(Integer.MAX_VALUE, 5));
75 add(tagNameF);
76 add(typeL);
77 typeF.setMaximumSize(new Dimension(Integer.MAX_VALUE, 5));
78 typeL.setLabelFor(typeF);
79 add(typeF);
80 add(authorL);
81 authorF.setMaximumSize(new Dimension(Integer.MAX_VALUE, 5));
82 authorL.setLabelFor(authorF);
83 add(authorF);
84 add(applicationsL);
85 applicationsF.setMaximumSize(new Dimension(Integer.MAX_VALUE, 5));
86 applicationsL.setLabelFor(applicationsF);
87 add(applicationsF);
88 add(descriptionL);
89 descScrollPane.setMinimumSize(new Dimension(FIELD_WIDTH, DESC_HEIGHT));
90 descScrollPane.setPreferredSize(new Dimension(FIELD_WIDTH, DESC_HEIGHT));
91 descriptionL.setLabelFor(descScrollPane);
92 add(descScrollPane);
93 add(stepsL);
94 stepsL.setLabelFor(stepsScrollPane);
95 stepsScrollPane.setMinimumSize(new Dimension(FIELD_WIDTH, DESC_HEIGHT));
96 stepsScrollPane.setPreferredSize(new Dimension(FIELD_WIDTH, DESC_HEIGHT));
97 add(stepsScrollPane);
98 add(attributesL);
99 attributesT.getColumn("Required").setMaxWidth(55);
100 attributesL.setLabelFor(attsScrollPane);
101
102
103 add(attsScrollPane);
104 }
105
106 protected void setUpFunctionalPointFields(){
107 descriptionF.setEditable(false);
108 descriptionF.setEditorKit(new HTMLEditorKit());
109 stepsF.setEditable(false);
110 stepsF.setEditorKit(new HTMLEditorKit());
111 tagNameF.setEditable(false);
112 tagNameF.setBackground(Color.white);
113 tagNameF.setBorder(descriptionF.getBorder());
114 applicationsF.setEditable(false);
115 applicationsF.setBackground(Color.white);
116 applicationsF.setBorder(descriptionF.getBorder());
117 typeF.setEditable(false);
118 typeF.setBackground(Color.white);
119 typeF.setBorder(descriptionF.getBorder());
120 authorF.setEditable(false);
121 authorF.setBackground(Color.white);
122 authorF.setBorder(descriptionF.getBorder());
123 }
124
125 public void sendFunctionalPointInfoToUI(FunctionalPoint fp){
126 StringBuffer tagNames = new StringBuffer();
127 List tagNamesList = fp.getTagNames();
128 Iterator it = tagNamesList.iterator();
129 String tag;
130 while (it.hasNext()) {
131 tag = (String)it.next();
132 tagNames.append("<").append(tag).append("/> ");
133 }
134 tagNameF.setText(tagNames.toString());
135 typeF.setText(fp.getType());
136 authorF.setText(fp.getAuthor());
137 descriptionF.setText("<font size='-1'>"+fp.getDescription()+"</font>");
138 descriptionF.setCaretPosition(0);
139 String apps = "";
140 for (it = fp.getApplications().iterator(); it.hasNext();) {
141 apps += it.next();
142 if (it.hasNext()) {
143 apps += ", ";
144 }
145 }
146 applicationsF.setText(apps);
147
148 populateEditorPane(stepsF, fp.getSteps());
149 while (attributeData.getRowCount() > 0) {
150 attributeData.removeRow(0);
151 }
152 it = fp.getAttributes().keySet().iterator();
153 Attribute att = null;
154 Object[] attRow = new Object[5];
155 String defaultValue = "";
156 while (it.hasNext()) {
157 att = (Attribute)fp.getAttributes().get(it.next());
158 attRow[0] = att.getName();
159 attRow[1] = att.getDescription();
160 attRow[2] = att.getType();
161 attRow[3] = new Boolean(att.isRequired());
162 if (att.getDefaultValue() != null) {
163 defaultValue = att.getDefaultValue();
164 }else{
165 defaultValue = "";
166 }
167 attRow[4] = defaultValue;
168 attributeData.addRow(attRow);
169 }
170 }
171
172 protected void populateEditorPane(JEditorPane field, List lines){
173 field.setText("");
174 Iterator it = lines.iterator();
175 StringBuffer linesS = new StringBuffer("<font size='-1'>");
176 String line;
177 while (it.hasNext()) {
178 line = (String)it.next();
179 linesS.append(line).append("<br>");
180 }
181 linesS.append("</font>");
182 field.setText(linesS.toString());
183 field.setCaretPosition(0);
184 }
185
186 protected class AttributeTableModel extends DefaultTableModel{
187 private static final long serialVersionUID = 1L;
188 final int REQUIRED = 3;
189 public AttributeTableModel(Object[] data, int rows){
190 super(data, rows);
191 }
192 /***
193 * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
194 *
195 * @param columnIndex the column being queried
196 * @return the Object.class
197 */
198 public Class getColumnClass(int columnIndex) {
199 Class dataType = super.getColumnClass(columnIndex);
200 if (columnIndex == REQUIRED) {
201 dataType = Boolean.class;
202 }
203 return dataType;
204 }
205 }
206
207 }