41 import java.io.IOException; |
41 import java.io.IOException; |
42 import java.io.Reader; |
42 import java.io.Reader; |
43 import java.io.Writer; |
43 import java.io.Writer; |
44 import java.util.ArrayList; |
44 import java.util.ArrayList; |
45 import java.util.Arrays; |
45 import java.util.Arrays; |
|
46 import java.util.EnumSet; |
46 import java.util.List; |
47 import java.util.List; |
47 import java.util.Properties; |
48 import java.util.Properties; |
48 import javax.swing.JButton; |
49 import javax.swing.JButton; |
49 import javax.swing.JCheckBox; |
50 import javax.swing.JCheckBox; |
50 import javax.swing.JComboBox; |
51 import javax.swing.JComboBox; |
69 * optionally be set for future use. |
70 * optionally be set for future use. |
70 * 2) Setup mode. In this mode, no property names are provided, and the GUI |
71 * 2) Setup mode. In this mode, no property names are provided, and the GUI |
71 * is invoked to allow the user to set or reset values for use in property mode. |
72 * is invoked to allow the user to set or reset values for use in property mode. |
72 */ |
73 */ |
73 public class SelectToolTask extends Task { |
74 public class SelectToolTask extends Task { |
|
75 |
|
76 enum ToolChoices { |
|
77 NONE(""), |
|
78 JAVAC("javac"), |
|
79 JAVADOC("javadoc"), |
|
80 JAVAH("javah"), |
|
81 JAVAP("javap"); |
|
82 |
|
83 String toolName; |
|
84 boolean bootstrap; |
|
85 |
|
86 ToolChoices(String toolName) { |
|
87 this(toolName, false); |
|
88 } |
|
89 |
|
90 ToolChoices(String toolName, boolean boostrap) { |
|
91 this.toolName = toolName; |
|
92 } |
|
93 |
|
94 @Override |
|
95 public String toString() { |
|
96 return toolName; |
|
97 } |
|
98 } |
|
99 |
74 /** |
100 /** |
75 * Set the location of the private properties file used to keep the retain |
101 * Set the location of the private properties file used to keep the retain |
76 * user preferences for this repository. |
102 * user preferences for this repository. |
77 */ |
103 */ |
78 public void setPropertyFile(File propertyFile) { |
104 public void setPropertyFile(File propertyFile) { |
132 void showGUI(Properties fileProps) { |
169 void showGUI(Properties fileProps) { |
133 Properties guiProps = new Properties(fileProps); |
170 Properties guiProps = new Properties(fileProps); |
134 JOptionPane p = createPane(guiProps); |
171 JOptionPane p = createPane(guiProps); |
135 p.createDialog("Select Tool").setVisible(true); |
172 p.createDialog("Select Tool").setVisible(true); |
136 |
173 |
137 toolName = (String) toolChoice.getSelectedItem(); |
174 toolName = ((ToolChoices)toolChoice.getSelectedItem()).toolName; |
138 toolArgs = argsField.getText(); |
175 toolArgs = argsField.getText(); |
139 |
176 toolBootstrap = bootstrapCheckbox.isSelected(); |
140 if (defaultCheck.isSelected()) { |
177 if (defaultCheck.isSelected()) { |
141 if (toolName.equals("")) { |
178 if (toolName.equals("")) { |
142 fileProps.remove("tool.name"); |
179 fileProps.remove("tool.name"); |
|
180 fileProps.remove("tool.bootstrap"); |
143 } else { |
181 } else { |
144 fileProps.put("tool.name", toolName); |
182 fileProps.put("tool.name", toolName); |
|
183 if (toolBootstrap) { |
|
184 fileProps.put("tool.bootstrap", "true"); |
|
185 } else { |
|
186 fileProps.remove("tool.bootstrap"); |
|
187 } |
145 fileProps.put(toolName + ".args", toolArgs); |
188 fileProps.put(toolName + ".args", toolArgs); |
146 } |
189 } |
147 writeProperties(propertyFile, fileProps); |
190 writeProperties(propertyFile, fileProps); |
148 } |
191 } |
149 } |
192 } |
152 JPanel body = new JPanel(new GridBagLayout()); |
195 JPanel body = new JPanel(new GridBagLayout()); |
153 GridBagConstraints lc = new GridBagConstraints(); |
196 GridBagConstraints lc = new GridBagConstraints(); |
154 lc.insets.right = 10; |
197 lc.insets.right = 10; |
155 lc.insets.bottom = 3; |
198 lc.insets.bottom = 3; |
156 GridBagConstraints fc = new GridBagConstraints(); |
199 GridBagConstraints fc = new GridBagConstraints(); |
157 fc.anchor = GridBagConstraints.WEST; |
|
158 fc.gridx = 1; |
200 fc.gridx = 1; |
159 fc.gridwidth = GridBagConstraints.REMAINDER; |
201 fc.gridwidth = GridBagConstraints.NONE; |
160 fc.insets.bottom = 3; |
202 fc.insets.bottom = 3; |
|
203 |
|
204 JPanel toolPane = new JPanel(new GridBagLayout()); |
161 |
205 |
162 JLabel toolLabel = new JLabel("Tool:"); |
206 JLabel toolLabel = new JLabel("Tool:"); |
163 body.add(toolLabel, lc); |
207 body.add(toolLabel, lc); |
164 String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" }; |
208 EnumSet<ToolChoices> toolChoices = toolProperty == null ? |
165 if (true || toolProperty == null) { |
209 EnumSet.allOf(ToolChoices.class) : EnumSet.range(ToolChoices.JAVAC, ToolChoices.JAVAP); |
166 // include empty value in setup mode |
210 toolChoice = new JComboBox(toolChoices.toArray()); |
167 List<String> l = new ArrayList<String>(Arrays.asList(toolChoices)); |
|
168 l.add(0, ""); |
|
169 toolChoices = l.toArray(new String[l.size()]); |
|
170 } |
|
171 toolChoice = new JComboBox(toolChoices); |
|
172 if (toolName != null) |
211 if (toolName != null) |
173 toolChoice.setSelectedItem(toolName); |
212 toolChoice.setSelectedItem(ToolChoices.valueOf(toolName.toUpperCase())); |
174 toolChoice.addItemListener(new ItemListener() { |
213 toolChoice.addItemListener(new ItemListener() { |
175 public void itemStateChanged(ItemEvent e) { |
214 public void itemStateChanged(ItemEvent e) { |
176 String tn = (String) e.getItem(); |
215 String tn = ((ToolChoices)e.getItem()).toolName; |
177 argsField.setText(getDefaultArgsForTool(props, tn)); |
216 argsField.setText(getDefaultArgsForTool(props, tn)); |
178 if (toolProperty != null) |
217 if (toolProperty != null) |
179 okButton.setEnabled(!tn.equals("")); |
218 okButton.setEnabled(!tn.equals("")); |
180 } |
219 } |
181 }); |
220 }); |
182 body.add(toolChoice, fc); |
221 GridBagConstraints checkConstraint = new GridBagConstraints(); |
|
222 fc.anchor = GridBagConstraints.EAST; |
|
223 |
|
224 GridBagConstraints toolConstraint = new GridBagConstraints(); |
|
225 fc.anchor = GridBagConstraints.WEST; |
|
226 |
|
227 toolPane.add(toolChoice, toolConstraint); |
|
228 bootstrapCheckbox = new JCheckBox("bootstrap", toolBootstrap); |
|
229 toolPane.add(bootstrapCheckbox, checkConstraint); |
|
230 |
|
231 body.add(toolPane, fc); |
183 |
232 |
184 argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40); |
233 argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40); |
185 if (toolProperty == null || argsProperty != null) { |
234 if (toolProperty == null || argsProperty != null) { |
186 JLabel argsLabel = new JLabel("Args:"); |
235 JLabel argsLabel = new JLabel("Args:"); |
187 body.add(argsLabel, lc); |
236 body.add(argsLabel, lc); |
188 body.add(argsField, fc); |
237 body.add(argsField, fc); |
189 argsField.addFocusListener(new FocusListener() { |
238 argsField.addFocusListener(new FocusListener() { |
190 public void focusGained(FocusEvent e) { |
239 public void focusGained(FocusEvent e) { |
191 } |
240 } |
192 public void focusLost(FocusEvent e) { |
241 public void focusLost(FocusEvent e) { |
193 String toolName = (String) toolChoice.getSelectedItem(); |
242 String toolName = ((ToolChoices)toolChoice.getSelectedItem()).toolName; |
194 if (toolName.length() > 0) |
243 if (toolName.length() > 0) |
195 props.put(toolName + ".args", argsField.getText()); |
244 props.put(toolName + ".args", argsField.getText()); |
196 } |
245 } |
197 }); |
246 }); |
198 } |
247 } |
269 } |
318 } |
270 |
319 |
271 // Ant task parameters |
320 // Ant task parameters |
272 private boolean askIfUnset; |
321 private boolean askIfUnset; |
273 private String toolProperty; |
322 private String toolProperty; |
|
323 private String bootstrapProperty; |
274 private String argsProperty; |
324 private String argsProperty; |
275 private File propertyFile; |
325 private File propertyFile; |
276 |
326 |
277 // GUI components |
327 // GUI components |
278 private JComboBox toolChoice; |
328 private JComboBox toolChoice; |
|
329 private JCheckBox bootstrapCheckbox; |
279 private JTextField argsField; |
330 private JTextField argsField; |
280 private JCheckBox defaultCheck; |
331 private JCheckBox defaultCheck; |
281 private JButton okButton; |
332 private JButton okButton; |
282 |
333 |
283 // Result values for the client |
334 // Result values for the client |
284 private String toolName; |
335 private String toolName; |
|
336 private boolean toolBootstrap; |
285 private String toolArgs; |
337 private String toolArgs; |
286 } |
338 } |