1
19 package com.qasystems.qstudio.java.gui.dialog;
20
21 import com.qasystems.international.MessageResource;
22 import com.qasystems.qstudio.java.QStudioGlobal;
23 import com.qasystems.qstudio.java.gui.CheckPropertiesControl;
24 import com.qasystems.qstudio.java.gui.QStudioCheckPropertiesControl;
25 import com.qasystems.qstudio.java.gui.RuleSet;
26 import com.qasystems.swing.ButtonDialog;
27 import com.qasystems.util.Utilities;
28
29 import java.awt.Dimension;
30
31 import javax.swing.*;
32
33
38 public class ConfigurationMigrationDialog extends ButtonDialog {
39
40 public final static int OK = 0;
41
42
43 public final static int CANCEL = 1;
44 private static final MessageResource RESOURCES =
45 MessageResource.getClientInstance();
46
47
55 private static final String[] DEFAULT_MESSAGE =
56 { RESOURCES.getString("MESSAGE_098") };
57 private CheckPropertiesControl checksTabControl = null;
58 private CheckPropertiesControl pmdChecksTabControl = null;
59 private RuleSet ruleSet = null;
60 private JPanel panel = null;
61 private String[] warningMessage = DEFAULT_MESSAGE;
62
63
66 public ConfigurationMigrationDialog() {
67 super(new QStudioGlobal().getFrame());
68 }
69
70
77 public synchronized void createGui(String[] message) {
78 panel = new JPanel();
79
80 if (message != null) {
81 setWarningMessage(message);
82 }
83
84 try {
85 jbInit();
86 } catch (Exception e) {
87 e.printStackTrace();
88 }
89
90 pack();
91
92 setSize(getMyPrefferedSize());
93 setCenteredDialog(false);
94 }
95
96
101 public synchronized void setRuleSet(RuleSet rules) {
102 ruleSet = rules;
103
104 if (panel == null) {
105 createGui(null);
106 }
107
108 checksTabControl.setRules(rules);
109 pmdChecksTabControl.setRules(rules);
110 pack();
111 }
112
113
116 public void pack() {
117 super.pack();
118 setSize(getMyPrefferedSize());
119 }
120
121
126 public RuleSet getRuleSet() {
127 return (ruleSet);
128 }
129
130
136 public Object clone() throws CloneNotSupportedException {
137 throw new CloneNotSupportedException();
138 }
139
140
144 public String toString() {
145 return super.toString();
146 }
147
148
154 public boolean equals(Object obj) {
155 return (super.equals(obj));
156 }
157
158
165 public JComponent getControl() {
166 if (panel == null) {
167 createGui(null);
168 }
169
170 return (panel);
171 }
172
173
176 public void cleanup() {
177 checksTabControl.cleanup();
178 pmdChecksTabControl.cleanup();
179 }
180
181
186 public int getVgap() {
187 return (0);
188 }
189
190 private synchronized void jbInit() {
191 final int VIEWPORT_WIDTH = 500;
192 final int VIEWPORT_HEIGHT = 300;
193
194 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
195 final String[] BUTTONS =
196 { RESOURCES.getString("BUTTON_005"), RESOURCES.getString("BUTTON_001") };
197
198 setModal(true);
199 setResizable(true);
200 setTitle(RESOURCES.getString("WINDOWTITLE_024"));
201 setButtons(BUTTONS);
202 setInitialButton(OK);
203
204 final JTextArea textArea = getGeneralInformation();
205 final int TEXTAREA_WIDTH = 500;
206 final int TEXTAREA_HEIGHT =
207 textArea.getLineCount() * (textArea.getFontMetrics(getFont()).getHeight());
208 textArea.setPreferredSize(new Dimension(TEXTAREA_WIDTH, TEXTAREA_HEIGHT));
209
210 final JTabbedPane tabs = new JTabbedPane();
211 checksTabControl = new QStudioCheckPropertiesControl();
212 checksTabControl.setEnabled(false);
213 checksTabControl.setViewportSize(
214 new Dimension(VIEWPORT_WIDTH, VIEWPORT_HEIGHT)
215 );
216 checksTabControl.setPreferredSize(
217 new Dimension(VIEWPORT_WIDTH, VIEWPORT_HEIGHT)
218 );
219
220 tabs.add(RESOURCES.getString("LABEL_031"), checksTabControl);
221
222 Utilities.discardResult(panel.add(textArea));
223 Utilities.discardResult(panel.add(tabs));
224
225 this.setContent(panel);
226 }
227
228
231 protected void cancelDialog() {
232 checksTabControl.cleanup();
233 super.cancelDialog();
234 }
235
236
242 protected void onActionPerformed(int action) {
243 checksTabControl.cleanup();
244 super.onActionPerformed(action);
245 }
246
247 private JTextArea getGeneralInformation() {
248 final int TEXTAREA_COLUMNS = 65;
249 final JTextArea text = new JTextArea();
250 final JLabel dummy = new JLabel("dummy");
251
252 text.setFont(dummy.getFont());
253 text.setForeground(dummy.getForeground());
254 text.setEditable(false);
255 text.setLineWrap(false);
256 text.setWrapStyleWord(false);
257 text.setOpaque(false);
258 text.setColumns(TEXTAREA_COLUMNS);
259 setMessage(text);
260
261 return (text);
262 }
263
264 private synchronized void setMessage(JTextArea text) {
265 final String[] MESSAGE = getWarningMessage();
266
267 if (MESSAGE != null) {
268 text.setText(MESSAGE[0]);
269
270 for (int i = 1; i < MESSAGE.length; i++) {
271 text.append("\n" + MESSAGE[i]);
272 }
273 }
274
275 text.setRows(MESSAGE.length);
276 }
277
278 private String[] getWarningMessage() {
279 return (warningMessage);
280 }
281
282 private synchronized void setWarningMessage(String[] message) {
283 warningMessage = message;
284 }
285
286 private Dimension getMyPrefferedSize() {
287 final int PREFERRED_WIDTH = 550;
288 final int PREFERRED_HEIGHT = 500;
289
290 return (new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
291 }
292 }
293