1 package org.telscenter.pas.ui.beans.issueReporter;
2
3 import info.clearthought.layout.TableLayout;
4
5 import java.awt.BorderLayout;
6 import java.awt.Component;
7 import java.awt.Dimension;
8 import java.awt.Font;
9
10 import javax.swing.BorderFactory;
11 import javax.swing.JButton;
12 import javax.swing.JComboBox;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.JScrollPane;
16 import javax.swing.JTabbedPane;
17 import javax.swing.JTextArea;
18 import javax.swing.JTextField;
19 import javax.swing.SwingConstants;
20 import javax.swing.border.Border;
21
22 import org.telscenter.pas.common.ui.CommonUI;
23 import org.telscenter.pas.common.ui.layouts.EqualsLayout;
24 import org.telscenter.pas.common.ui.tab.PasTabbedPaneUI;
25 import org.telscenter.pas.common.ui.text.CurrentLineHighlighter;
26 import org.telscenter.pas.steps.actions.DialogSaveAction;
27 import org.telscenter.pas.ui.beans.issueReporter.actions.ReportIssueAction;
28 import org.telscenter.pas.ui.util.PasColors;
29
30 public class IssueUI extends JPanel {
31
32 private static final int TEXT_BOX_LEN = 15;
33
34 protected String[] reportTypes = {
35 Messages.getString("IssueUI.send_comment"), Messages.getString("IssueUI.report_problem"),
36 Messages.getString("IssueUI.suggest_new_feature") };
37
38 protected Border emptyBorder = BorderFactory.createCompoundBorder(
39 BorderFactory.createEmptyBorder(1, 1, 1, 1), BorderFactory
40 .createEtchedBorder());
41
42 private JTextField nameText;
43
44 private JButton sendButton;
45
46 private JButton cancelButton;
47
48 private JComboBox reportCombo;
49
50 private JTextField subjectText;
51
52 private JTextArea descriptionArea;
53
54 private JTextField emailText;
55
56 public IssueUI() {
57 setBackground(PasColors.issueReporterBackgroundColor);
58 setPreferredSize(new Dimension(480, 520));
59
60 JTabbedPane tabbedPane = new JTabbedPane();
61
62 tabbedPane.setBackground(PasColors.issueReporterBorderColor);
63 tabbedPane.setUI(new PasTabbedPaneUI());
64
65 tabbedPane.addTab("Issue Reporter", createReportPanel());
66
67 add(tabbedPane, BorderLayout.CENTER);
68 }
69
70 /***
71 * @return
72 */
73 protected Component createAboutPanel() {
74 JPanel reportPanel = new JPanel();
75 reportPanel.setBorder(BorderFactory.createLineBorder(PasColors.issueReporterBorderColor, 2));
76
77 JPanel innerPanel = new JPanel(new BorderLayout(0, 0));
78
79 JTextArea aboutText = new JTextArea();
80 aboutText.setText("TELS SAIL & Pas Based Frameworks System Architects\n\n" +
81 "University California Berkeley Team:\n\n" +
82 " Turadg Aleahmad\n" +
83 " Anthony Perritano\n\n" +
84 "Concord Consortium Team:\n\n" +
85 " Edward Burke\n" +
86 " Scott Cytacki\n\n" +
87 "TELS is a NSF Funded Project");
88 aboutText.setEditable(false);
89 aboutText.setBackground(PasColors.issueReporterReportBackgroundColor);
90 aboutText.setOpaque(false);
91 innerPanel.add(aboutText, BorderLayout.WEST);
92 innerPanel.setOpaque(false);
93 reportPanel.add(innerPanel, BorderLayout.CENTER);
94 reportPanel.setBackground(PasColors.issueReporterReportBackgroundColor);
95 return reportPanel;
96 }
97
98 protected JPanel createReportPanel() {
99 JPanel reportPanel = new JPanel();
100 reportPanel.setBorder(BorderFactory.createLineBorder(PasColors.issueReporterBorderColor, 2));
101
102 JPanel innerPanel = new JPanel(new BorderLayout(0, 0));
103
104 JTextArea instructionText = new JTextArea();
105 instructionText.setText(Messages
106 .getString("IssueUI.choose_report_type"));
107 CommonUI.makeMultilineLabel(instructionText);
108
109 innerPanel.add(instructionText, BorderLayout.NORTH);
110 innerPanel.add(createForm(), BorderLayout.CENTER);
111 innerPanel.setOpaque(false);
112 reportPanel.add(innerPanel, BorderLayout.CENTER);
113 reportPanel.setBackground(PasColors.issueReporterReportBackgroundColor);
114 return reportPanel;
115 }
116
117 private JPanel createForm() {
118 JPanel formPanel = new JPanel();
119
120 double pref = TableLayout.PREFERRED;
121 double fill = TableLayout.FILL;
122 double vSpace = 5;
123 double hSpace = 6;
124 double size[][] = {
125 { pref, hSpace, pref,
126 },
127
128 { pref, vSpace, pref, vSpace, pref, vSpace, pref, vSpace, fill,
129 vSpace, pref }
130
131 };
132 formPanel.setLayout(new TableLayout(size));
133 formPanel.setOpaque(false);
134 createReportType(formPanel);
135 createNamePanel(formPanel);
136 createEmailPanel(formPanel);
137 createSubjectPanel(formPanel);
138 createDescription(formPanel);
139 createButtonPanel(formPanel);
140 nameText.requestFocusInWindow();
141 return formPanel;
142 }
143
144 protected void createReportType(JPanel reportPanel) {
145 JLabel reportLabel = new JLabel(Messages
146 .getString("IssueUI.report_type"));
147 reportLabel.setFont(reportLabel.getFont().deriveFont(Font.BOLD));
148 reportLabel.setOpaque(false);
149 reportLabel.setHorizontalAlignment(SwingConstants.LEFT);
150 reportPanel.add(reportLabel, "0,0");
151
152 reportCombo = new JComboBox(reportTypes);
153 reportCombo.setOpaque(false);
154 reportPanel.add(reportCombo, "2,0");
155 }
156
157 protected void createNamePanel(JPanel namePanel) {
158 JLabel nameLabel = new JLabel(Messages.getString("IssueUI.prompt_name"));
159 nameLabel.setFont(nameLabel.getFont().deriveFont(Font.BOLD));
160 nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
161 namePanel.add(nameLabel, "0,2");
162 nameText = new JTextField("", TEXT_BOX_LEN);
163 namePanel.add(nameText, "2,2");
164 namePanel.setMaximumSize(namePanel.getPreferredSize());
165 }
166
167 protected void createEmailPanel(JPanel emailPanel) {
168 JLabel emailLabel = new JLabel(Messages
169 .getString("IssueUI.prompt_email"));
170 emailLabel.setFont(emailLabel.getFont().deriveFont(Font.BOLD));
171 emailLabel.setHorizontalAlignment(SwingConstants.LEFT);
172 emailPanel.add(emailLabel, "0,4");
173 emailText = new JTextField("", TEXT_BOX_LEN);
174 emailPanel.add(emailText, "2,4");
175 emailPanel.setMaximumSize(emailPanel.getPreferredSize());
176 }
177
178 protected void createSubjectPanel(JPanel subjectPanel) {
179 JLabel subjectLabel = new JLabel(Messages
180 .getString("IssueUI.prompt_subject"));
181 subjectLabel.setFont(subjectLabel.getFont().deriveFont(Font.BOLD));
182 subjectLabel.setHorizontalAlignment(SwingConstants.LEFT);
183 subjectPanel.add(subjectLabel, "0,6");
184
185 subjectText = new JTextField("", TEXT_BOX_LEN);
186 subjectPanel.add(subjectText, "2,6");
187 }
188
189 protected void createDescription(JPanel descriptionPanel) {
190 JLabel descriptionLabel = new JLabel(Messages
191 .getString("IssueUI.prompt_description"));
192 descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(
193 Font.BOLD));
194 descriptionLabel.setHorizontalAlignment(SwingConstants.LEFT);
195 descriptionLabel.setVerticalTextPosition(SwingConstants.NORTH);
196 descriptionPanel.add(descriptionLabel, "0,8,l,t");
197 descriptionArea = new JTextArea();
198 CommonUI.makeMultilineEditable(descriptionArea);
199 descriptionArea.setEditable(true);
200
201 CurrentLineHighlighter.install(descriptionArea);
202 descriptionArea.setOpaque(true);
203 descriptionArea.setBackground(PasColors.issueReporterDescriptionTextAreaColor);
204
205 JScrollPane sp = new JScrollPane(descriptionArea);
206 sp
207 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
208 sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
209 sp.setPreferredSize(new Dimension(300, 200));
210 sp.setBorder(CommonUI.createEtchedBorder());
211 descriptionPanel.add(sp, "2,8");
212 descriptionPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
213 }
214
215 protected void createButtonPanel(JPanel formPanel) {
216 sendButton = new JButton(new ReportIssueAction(Messages
217 .getString("IssueUI.button_send_report"), this));
218 cancelButton = new JButton();
219
220 cancelButton.setAction(new DialogSaveAction(Messages
221 .getString("IssueUI.button_cancel")));
222
223 sendButton = CommonUI.makeEnhancedButton(sendButton);
224 cancelButton = CommonUI.makeEnhancedButton(cancelButton);
225 JPanel buttonPanel = new JPanel();
226 buttonPanel.setLayout(new EqualsLayout(EqualsLayout.HORIZONTAL, 1, 2));
227 buttonPanel.add(cancelButton);
228 buttonPanel.add(sendButton);
229
230 buttonPanel.setOpaque(false);
231 formPanel.add(buttonPanel, "0,10, 2,10, r,t");
232 }
233
234 public Issue getCurrentIssue() {
235 Issue issue = new Issue();
236 issue.setReporterName(nameText.getText());
237 issue.setType((String) reportCombo.getSelectedItem());
238 issue.setReporterEmail(emailText.getText());
239 issue.setSubject(subjectText.getText());
240 issue.setIssueDescription(descriptionArea.getText());
241 return issue;
242 }
243 }