Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WizStepManyTextFields |
|
| 2.0;2 |
1 | /* $Id: WizStepManyTextFields.java 17818 2010-01-12 18:39:46Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * tfmorris | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2007 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.cognitive.ui; | |
40 | ||
41 | import java.awt.Dimension; | |
42 | import java.awt.GridBagConstraints; | |
43 | import java.awt.GridBagLayout; | |
44 | import java.util.ArrayList; | |
45 | import java.util.List; | |
46 | ||
47 | import javax.swing.JLabel; | |
48 | import javax.swing.JTextArea; | |
49 | import javax.swing.JTextField; | |
50 | import javax.swing.border.EtchedBorder; | |
51 | ||
52 | import org.argouml.cognitive.critics.Wizard; | |
53 | import org.argouml.swingext.SpacerPanel; | |
54 | ||
55 | ||
56 | /** | |
57 | * A non-modal wizard step that shows instructions and prompts | |
58 | * the user to enter a series of strings in textfields. | |
59 | * | |
60 | * @see org.argouml.cognitive.Critic | |
61 | * @see org.argouml.cognitive.critics.Wizard | |
62 | */ | |
63 | ||
64 | public class WizStepManyTextFields extends WizStep { | |
65 | 0 | private JTextArea instructions = new JTextArea(); |
66 | 0 | private List<JTextField> fields = new ArrayList<JTextField>(); |
67 | ||
68 | /** | |
69 | * The constructor. | |
70 | * | |
71 | * @param w the wizard | |
72 | * @param instr the instructions | |
73 | * @param strings the strings | |
74 | */ | |
75 | 0 | public WizStepManyTextFields(Wizard w, String instr, List strings) { |
76 | // store wizard? | |
77 | 0 | instructions.setText(instr); |
78 | 0 | instructions.setWrapStyleWord(true); |
79 | 0 | instructions.setLineWrap(true); |
80 | 0 | instructions.setEditable(false); |
81 | 0 | instructions.setBorder(null); |
82 | 0 | instructions.setBackground(getMainPanel().getBackground()); |
83 | ||
84 | ||
85 | 0 | getMainPanel().setBorder(new EtchedBorder()); |
86 | ||
87 | 0 | GridBagLayout gb = new GridBagLayout(); |
88 | 0 | getMainPanel().setLayout(gb); |
89 | ||
90 | 0 | GridBagConstraints c = new GridBagConstraints(); |
91 | 0 | c.ipadx = 3; c.ipady = 3; |
92 | 0 | c.weightx = 0.0; c.weighty = 0.0; |
93 | 0 | c.anchor = GridBagConstraints.EAST; |
94 | ||
95 | 0 | JLabel image = new JLabel(""); |
96 | //image.setMargin(new Insets(0, 0, 0, 0)); | |
97 | 0 | image.setIcon(getWizardIcon()); |
98 | 0 | image.setBorder(null); |
99 | 0 | c.gridx = 0; |
100 | 0 | c.gridheight = GridBagConstraints.REMAINDER; |
101 | 0 | c.gridy = 0; |
102 | 0 | c.anchor = GridBagConstraints.NORTH; |
103 | 0 | gb.setConstraints(image, c); |
104 | 0 | getMainPanel().add(image); |
105 | ||
106 | 0 | c.weightx = 0.0; |
107 | 0 | c.gridx = 2; |
108 | 0 | c.gridheight = 1; |
109 | 0 | c.gridwidth = 3; |
110 | 0 | c.gridy = 0; |
111 | 0 | c.fill = GridBagConstraints.NONE; |
112 | 0 | gb.setConstraints(instructions, c); |
113 | 0 | getMainPanel().add(instructions); |
114 | ||
115 | 0 | c.gridx = 1; |
116 | 0 | c.gridy = 1; |
117 | 0 | c.weightx = 0.0; |
118 | 0 | c.gridwidth = 1; |
119 | 0 | c.fill = GridBagConstraints.NONE; |
120 | 0 | SpacerPanel spacer = new SpacerPanel(); |
121 | 0 | gb.setConstraints(spacer, c); |
122 | 0 | getMainPanel().add(spacer); |
123 | ||
124 | 0 | c.gridx = 2; |
125 | 0 | c.weightx = 1.0; |
126 | 0 | c.anchor = GridBagConstraints.WEST; |
127 | 0 | c.gridwidth = 1; |
128 | 0 | int size = strings.size(); |
129 | 0 | for (int i = 0; i < size; i++) { |
130 | 0 | c.gridy = 2 + i; |
131 | 0 | String s = (String) strings.get(i); |
132 | 0 | JTextField tf = new JTextField(s, 50); |
133 | 0 | tf.setMinimumSize(new Dimension(200, 20)); |
134 | 0 | tf.getDocument().addDocumentListener(this); |
135 | 0 | fields.add(tf); |
136 | 0 | gb.setConstraints(tf, c); |
137 | 0 | getMainPanel().add(tf); |
138 | } | |
139 | ||
140 | 0 | c.gridx = 1; |
141 | 0 | c.gridy = 3 + strings.size(); |
142 | 0 | c.weightx = 0.0; |
143 | 0 | c.gridwidth = 1; |
144 | 0 | c.fill = GridBagConstraints.NONE; |
145 | 0 | SpacerPanel spacer2 = new SpacerPanel(); |
146 | 0 | gb.setConstraints(spacer2, c); |
147 | 0 | getMainPanel().add(spacer2); |
148 | ||
149 | 0 | } |
150 | ||
151 | ||
152 | /** | |
153 | * @return the strings | |
154 | */ | |
155 | public List<String> getStringList() { | |
156 | 0 | List<String> result = new ArrayList<String>(fields.size()); |
157 | 0 | for (JTextField tf : fields) { |
158 | 0 | result.add(tf.getText()); |
159 | } | |
160 | 0 | return result; |
161 | } | |
162 | ||
163 | /** | |
164 | * The UID. | |
165 | */ | |
166 | private static final long serialVersionUID = -5154002407806917092L; | |
167 | } | |
168 | ||
169 | ||
170 |