1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.uml.reveng; |
40 | |
|
41 | |
import java.awt.BorderLayout; |
42 | |
import java.awt.Frame; |
43 | |
import java.awt.GridBagConstraints; |
44 | |
import java.awt.GridBagLayout; |
45 | |
import java.awt.Insets; |
46 | |
import java.awt.event.ActionEvent; |
47 | |
import java.awt.event.ActionListener; |
48 | |
import java.awt.event.FocusEvent; |
49 | |
import java.awt.event.FocusListener; |
50 | |
import java.io.File; |
51 | |
import java.nio.charset.Charset; |
52 | |
import java.util.List; |
53 | |
import java.util.StringTokenizer; |
54 | |
|
55 | |
import javax.swing.ButtonGroup; |
56 | |
import javax.swing.JCheckBox; |
57 | |
import javax.swing.JComboBox; |
58 | |
import javax.swing.JComponent; |
59 | |
import javax.swing.JDialog; |
60 | |
import javax.swing.JFileChooser; |
61 | |
import javax.swing.JLabel; |
62 | |
import javax.swing.JPanel; |
63 | |
import javax.swing.JRadioButton; |
64 | |
import javax.swing.JTabbedPane; |
65 | |
import javax.swing.JTextField; |
66 | |
import javax.swing.filechooser.FileSystemView; |
67 | |
|
68 | |
import org.argouml.application.api.Argo; |
69 | |
import org.argouml.configuration.Configuration; |
70 | |
import org.argouml.i18n.Translator; |
71 | |
import org.argouml.moduleloader.ModuleInterface; |
72 | |
import org.argouml.uml.reveng.SettingsTypes.BooleanSelection2; |
73 | |
import org.argouml.uml.reveng.SettingsTypes.PathListSelection; |
74 | |
import org.argouml.uml.reveng.SettingsTypes.PathSelection; |
75 | |
import org.argouml.uml.reveng.SettingsTypes.Setting; |
76 | |
import org.argouml.uml.reveng.SettingsTypes.UniqueSelection2; |
77 | |
import org.argouml.uml.reveng.SettingsTypes.UserString2; |
78 | |
import org.argouml.uml.reveng.ui.ImportClasspathDialog; |
79 | |
import org.argouml.uml.reveng.ui.ImportStatusScreen; |
80 | |
import org.argouml.util.SuffixFilter; |
81 | |
import org.argouml.util.UIUtils; |
82 | |
import org.tigris.gef.base.Globals; |
83 | |
import org.tigris.swidgets.GridLayout2; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | 0 | public class Import extends ImportCommon implements ImportSettings { |
120 | |
|
121 | |
private JComponent configPanel; |
122 | |
|
123 | |
private JCheckBox descend; |
124 | |
|
125 | |
private JCheckBox changedOnly; |
126 | |
|
127 | |
private JCheckBox createDiagrams; |
128 | |
|
129 | |
private JCheckBox minimiseFigs; |
130 | |
|
131 | |
private JCheckBox layoutDiagrams; |
132 | |
|
133 | |
|
134 | |
private JRadioButton classOnly; |
135 | |
|
136 | |
|
137 | |
private JRadioButton classAndFeatures; |
138 | |
|
139 | |
|
140 | |
private JRadioButton fullImport; |
141 | |
|
142 | |
private JComboBox sourceEncoding; |
143 | |
|
144 | |
private JDialog dialog; |
145 | |
|
146 | |
private ImportStatusScreen iss; |
147 | |
|
148 | |
private Frame myFrame; |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public Import(Frame frame) { |
156 | 0 | super(); |
157 | 0 | myFrame = frame; |
158 | |
|
159 | |
|
160 | |
|
161 | 0 | getConfigPanel(); |
162 | |
|
163 | 0 | if (frame != null) { |
164 | 0 | JComponent chooser = getChooser(); |
165 | 0 | dialog = |
166 | |
new JDialog(frame, |
167 | |
Translator.localize("action.import-sources"), true); |
168 | |
|
169 | 0 | dialog.getContentPane().add(chooser, BorderLayout.CENTER); |
170 | 0 | dialog.getContentPane().add(getConfigPanel(), BorderLayout.EAST); |
171 | 0 | dialog.pack(); |
172 | 0 | int x = (frame.getSize().width - dialog.getSize().width) / 2; |
173 | 0 | int y = (frame.getSize().height - dialog.getSize().height) / 2; |
174 | 0 | dialog.setLocation(x > 0 ? x : 0, y > 0 ? y : 0); |
175 | |
|
176 | 0 | UIUtils.loadCommonKeyMap(dialog); |
177 | |
|
178 | 0 | dialog.setVisible(true); |
179 | |
} |
180 | 0 | } |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
public String getInputSourceEncoding() { |
186 | 0 | return (String) sourceEncoding.getSelectedItem(); |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
private void disposeDialog() { |
193 | 0 | StringBuffer flags = new StringBuffer(30); |
194 | 0 | flags.append(isDescendSelected()).append(","); |
195 | 0 | flags.append(isChangedOnlySelected()).append(","); |
196 | 0 | flags.append(isCreateDiagramsSelected()).append(","); |
197 | 0 | flags.append(isMinimizeFigsSelected()).append(","); |
198 | 0 | flags.append(isDiagramLayoutSelected()); |
199 | 0 | Configuration.setString(Argo.KEY_IMPORT_GENERAL_SETTINGS_FLAGS, flags |
200 | |
.toString()); |
201 | 0 | Configuration.setString(Argo.KEY_IMPORT_GENERAL_DETAIL_LEVEL, String |
202 | |
.valueOf(getImportLevel())); |
203 | 0 | Configuration.setString(Argo.KEY_INPUT_SOURCE_ENCODING, |
204 | |
getInputSourceEncoding()); |
205 | 0 | dialog.setVisible(false); |
206 | 0 | dialog.dispose(); |
207 | 0 | } |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
private JComponent getConfigPanel() { |
217 | |
|
218 | 0 | final JTabbedPane tab = new JTabbedPane(); |
219 | |
|
220 | |
|
221 | 0 | if (configPanel == null) { |
222 | 0 | JPanel general = new JPanel(); |
223 | 0 | general.setLayout(new GridLayout2(20, 1, 0, 0, GridLayout2.NONE)); |
224 | |
|
225 | 0 | general.add(new JLabel(Translator |
226 | |
.localize("action.import-select-lang"))); |
227 | |
|
228 | 0 | JComboBox selectedLanguage = new JComboBox(getModules().keySet() |
229 | |
.toArray()); |
230 | 0 | selectedLanguage |
231 | |
.addActionListener(new SelectedLanguageListener(tab)); |
232 | 0 | general.add(selectedLanguage); |
233 | |
|
234 | 0 | addConfigCheckboxes(general); |
235 | |
|
236 | 0 | addDetailLevelButtons(general); |
237 | |
|
238 | 0 | addSourceEncoding(general); |
239 | |
|
240 | 0 | tab.add(general, Translator.localize("action.import-general")); |
241 | |
|
242 | 0 | ImportInterface current = getCurrentModule(); |
243 | 0 | if (current != null) { |
244 | 0 | tab.add(getConfigPanelExtension(), |
245 | |
current.getName()); |
246 | |
} |
247 | 0 | configPanel = tab; |
248 | |
} |
249 | 0 | return configPanel; |
250 | |
|
251 | |
} |
252 | |
|
253 | |
|
254 | |
private void addConfigCheckboxes(JPanel panel) { |
255 | 0 | boolean desc = true; |
256 | 0 | boolean chan = true; |
257 | 0 | boolean crea = true; |
258 | 0 | boolean mini = true; |
259 | 0 | boolean layo = true; |
260 | 0 | String flags = Configuration |
261 | |
.getString(Argo.KEY_IMPORT_GENERAL_SETTINGS_FLAGS); |
262 | 0 | if (flags != null && flags.length() > 0) { |
263 | 0 | StringTokenizer st = new StringTokenizer(flags, ","); |
264 | 0 | if (st.hasMoreTokens() && st.nextToken().equals("false")) { |
265 | 0 | desc = false; |
266 | |
} |
267 | 0 | if (st.hasMoreTokens() && st.nextToken().equals("false")) { |
268 | 0 | chan = false; |
269 | |
} |
270 | 0 | if (st.hasMoreTokens() && st.nextToken().equals("false")) { |
271 | 0 | crea = false; |
272 | |
} |
273 | 0 | if (st.hasMoreTokens() && st.nextToken().equals("false")) { |
274 | 0 | mini = false; |
275 | |
} |
276 | 0 | if (st.hasMoreTokens() && st.nextToken().equals("false")) { |
277 | 0 | layo = false; |
278 | |
} |
279 | |
} |
280 | |
|
281 | 0 | descend = new JCheckBox(Translator |
282 | |
.localize("action.import-option-descend-dir-recur"), desc); |
283 | 0 | panel.add(descend); |
284 | |
|
285 | 0 | changedOnly = new JCheckBox(Translator |
286 | |
.localize("action.import-option-changed_new"), chan); |
287 | 0 | panel.add(changedOnly); |
288 | |
|
289 | 0 | createDiagrams = new JCheckBox(Translator |
290 | |
.localize("action.import-option-create-diagram"), crea); |
291 | 0 | panel.add(createDiagrams); |
292 | |
|
293 | 0 | minimiseFigs = new JCheckBox(Translator |
294 | |
.localize("action.import-option-min-class-icon"), mini); |
295 | 0 | panel.add(minimiseFigs); |
296 | |
|
297 | 0 | layoutDiagrams = new JCheckBox(Translator.localize( |
298 | |
"action.import-option-perform-auto-diagram-layout"), |
299 | |
layo); |
300 | 0 | panel.add(layoutDiagrams); |
301 | |
|
302 | |
|
303 | |
|
304 | 0 | createDiagrams.addActionListener(new ActionListener() { |
305 | |
public void actionPerformed(ActionEvent actionEvent) { |
306 | 0 | if (!createDiagrams.isSelected()) { |
307 | 0 | minimiseFigs.setSelected(false); |
308 | 0 | layoutDiagrams.setSelected(false); |
309 | |
} |
310 | 0 | } |
311 | |
}); |
312 | 0 | } |
313 | |
|
314 | |
|
315 | |
private void addDetailLevelButtons(JPanel panel) { |
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | 0 | JLabel importDetailLabel = new JLabel(Translator |
322 | |
.localize("action.import-level-of-import-detail")); |
323 | 0 | ButtonGroup detailButtonGroup = new ButtonGroup(); |
324 | |
|
325 | 0 | classOnly = new JRadioButton(Translator |
326 | |
.localize("action.import-option-classifiers")); |
327 | 0 | detailButtonGroup.add(classOnly); |
328 | |
|
329 | 0 | classAndFeatures = new JRadioButton(Translator |
330 | |
.localize("action.import-option-classifiers-plus-specs")); |
331 | 0 | detailButtonGroup.add(classAndFeatures); |
332 | |
|
333 | 0 | fullImport = new JRadioButton(Translator |
334 | |
.localize("action.import-option-full-import")); |
335 | 0 | String detaillevel = Configuration |
336 | |
.getString(Argo.KEY_IMPORT_GENERAL_DETAIL_LEVEL); |
337 | 0 | if ("0".equals(detaillevel)) { |
338 | 0 | classOnly.setSelected(true); |
339 | 0 | } else if ("1".equals(detaillevel)) { |
340 | 0 | classAndFeatures.setSelected(true); |
341 | |
} else { |
342 | 0 | fullImport.setSelected(true); |
343 | |
} |
344 | 0 | detailButtonGroup.add(fullImport); |
345 | |
|
346 | 0 | panel.add(importDetailLabel); |
347 | 0 | panel.add(classOnly); |
348 | 0 | panel.add(classAndFeatures); |
349 | 0 | panel.add(fullImport); |
350 | 0 | } |
351 | |
|
352 | |
|
353 | |
private void addSourceEncoding(JPanel panel) { |
354 | 0 | panel.add(new JLabel( |
355 | |
Translator.localize("action.import-file-encoding"))); |
356 | 0 | String enc = |
357 | |
Configuration.getString(Argo.KEY_INPUT_SOURCE_ENCODING); |
358 | 0 | if (enc == null || enc.trim().equals("")) { |
359 | 0 | enc = System.getProperty("file.encoding"); |
360 | |
} |
361 | |
|
362 | |
|
363 | 0 | if (enc.startsWith("cp")) { |
364 | 0 | enc = "windows-" + enc.substring(2); |
365 | |
} |
366 | |
|
367 | 0 | sourceEncoding = new JComboBox(Charset |
368 | |
.availableCharsets().keySet().toArray()); |
369 | 0 | sourceEncoding.setSelectedItem(enc); |
370 | 0 | panel.add(sourceEncoding); |
371 | 0 | } |
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
private JComponent getConfigPanelExtension() { |
377 | 0 | List<Setting> settings = null; |
378 | 0 | ImportInterface current = getCurrentModule(); |
379 | 0 | if (current != null) { |
380 | 0 | settings = current.getImportSettings(); |
381 | |
} |
382 | 0 | return new ConfigPanelExtension(settings); |
383 | |
} |
384 | |
|
385 | |
private class SelectedLanguageListener implements ActionListener { |
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
private JTabbedPane tab; |
391 | |
|
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | 0 | SelectedLanguageListener(JTabbedPane t) { |
399 | 0 | tab = t; |
400 | 0 | } |
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
public void actionPerformed(ActionEvent e) { |
406 | 0 | JComboBox cb = (JComboBox) e.getSource(); |
407 | 0 | String selected = (String) cb.getSelectedItem(); |
408 | 0 | ImportInterface oldModule = getCurrentModule(); |
409 | 0 | setCurrentModule(getModules().get(selected)); |
410 | 0 | updateFilters((JFileChooser) dialog.getContentPane() |
411 | |
.getComponent(0), oldModule.getSuffixFilters(), |
412 | |
getCurrentModule().getSuffixFilters()); |
413 | 0 | updateTabbedPane(); |
414 | 0 | } |
415 | |
|
416 | |
private void updateTabbedPane() { |
417 | 0 | String name = ((ModuleInterface) getCurrentModule()).getName(); |
418 | 0 | if (tab.indexOfTab(name) < 0) { |
419 | 0 | tab.add(getConfigPanelExtension(), name); |
420 | |
} |
421 | 0 | } |
422 | |
} |
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
public void doFile() { |
431 | 0 | iss = new ImportStatusScreen(myFrame, "Importing", "Splash"); |
432 | 0 | Thread t = new Thread(new Runnable() { |
433 | |
public void run() { |
434 | 0 | doImport(iss); |
435 | |
|
436 | |
|
437 | 0 | } |
438 | |
}, "Import Thread"); |
439 | 0 | t.start(); |
440 | 0 | } |
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
public int getImportLevel() { |
446 | 0 | if (classOnly != null && classOnly.isSelected()) { |
447 | 0 | return ImportSettings.DETAIL_CLASSIFIER; |
448 | 0 | } else if (classAndFeatures != null && classAndFeatures.isSelected()) { |
449 | 0 | return ImportSettings.DETAIL_CLASSIFIER_FEATURE; |
450 | 0 | } else if (fullImport != null && fullImport.isSelected()) { |
451 | 0 | return ImportSettings.DETAIL_FULL; |
452 | |
} else { |
453 | 0 | return ImportSettings.DETAIL_CLASSIFIER; |
454 | |
} |
455 | |
} |
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
public boolean isCreateDiagramsSelected() { |
461 | 0 | if (createDiagrams != null) { |
462 | 0 | return createDiagrams.isSelected(); |
463 | |
} |
464 | 0 | return true; |
465 | |
} |
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
public boolean isMinimizeFigsSelected() { |
471 | 0 | if (minimiseFigs != null) { |
472 | 0 | return minimiseFigs.isSelected(); |
473 | |
} |
474 | 0 | return false; |
475 | |
} |
476 | |
|
477 | |
|
478 | |
|
479 | |
|
480 | |
public boolean isDiagramLayoutSelected() { |
481 | 0 | if (layoutDiagrams != null) { |
482 | 0 | return layoutDiagrams.isSelected(); |
483 | |
} |
484 | 0 | return false; |
485 | |
} |
486 | |
|
487 | |
|
488 | |
|
489 | |
|
490 | |
public boolean isDescendSelected() { |
491 | 0 | if (descend != null) { |
492 | 0 | return descend.isSelected(); |
493 | |
} |
494 | 0 | return true; |
495 | |
} |
496 | |
|
497 | |
|
498 | |
|
499 | |
|
500 | |
public boolean isChangedOnlySelected() { |
501 | 0 | if (changedOnly != null) { |
502 | 0 | return changedOnly.isSelected(); |
503 | |
} |
504 | 0 | return false; |
505 | |
} |
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
private JComponent getChooser() { |
514 | 0 | String directory = Globals.getLastDirectory(); |
515 | |
|
516 | 0 | final JFileChooser chooser = new ImportFileChooser(this, directory); |
517 | |
|
518 | 0 | chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); |
519 | 0 | ImportInterface current = getCurrentModule(); |
520 | |
|
521 | 0 | if (current != null) { |
522 | 0 | updateFilters(chooser, null, current.getSuffixFilters()); |
523 | |
} |
524 | 0 | return chooser; |
525 | |
} |
526 | |
|
527 | |
private static void updateFilters(JFileChooser chooser, |
528 | |
SuffixFilter[] oldFilters, SuffixFilter[] newFilters) { |
529 | 0 | if (oldFilters != null) { |
530 | 0 | for (int i = 0; i < oldFilters.length; i++) { |
531 | 0 | chooser.removeChoosableFileFilter(oldFilters[i]); |
532 | |
} |
533 | |
} |
534 | 0 | if (newFilters != null) { |
535 | 0 | for (int i = 0; i < newFilters.length; i++) { |
536 | 0 | chooser.addChoosableFileFilter(newFilters[i]); |
537 | |
} |
538 | 0 | if (newFilters.length > 0) { |
539 | 0 | chooser.setFileFilter(newFilters[0]); |
540 | |
} |
541 | |
} |
542 | 0 | } |
543 | |
|
544 | |
private static class ImportFileChooser extends JFileChooser { |
545 | |
|
546 | |
private Import theImport; |
547 | |
|
548 | |
|
549 | |
|
550 | |
|
551 | |
|
552 | |
|
553 | |
|
554 | |
|
555 | |
public ImportFileChooser(Import imp, String currentDirectoryPath) { |
556 | 0 | super(currentDirectoryPath); |
557 | 0 | theImport = imp; |
558 | 0 | initChooser(); |
559 | 0 | } |
560 | |
|
561 | |
|
562 | |
|
563 | |
|
564 | |
|
565 | |
|
566 | |
|
567 | |
|
568 | |
|
569 | |
|
570 | |
public ImportFileChooser(Import imp, String currentDirectoryPath, |
571 | |
FileSystemView fsv) { |
572 | 0 | super(currentDirectoryPath, fsv); |
573 | 0 | theImport = imp; |
574 | 0 | initChooser(); |
575 | 0 | } |
576 | |
|
577 | |
|
578 | |
|
579 | |
|
580 | |
|
581 | |
|
582 | |
|
583 | |
public ImportFileChooser(Import imp) { |
584 | 0 | super(); |
585 | 0 | theImport = imp; |
586 | 0 | initChooser(); |
587 | 0 | } |
588 | |
|
589 | |
|
590 | |
|
591 | |
|
592 | |
|
593 | |
|
594 | |
|
595 | |
|
596 | |
public ImportFileChooser(Import imp, FileSystemView fsv) { |
597 | 0 | super(fsv); |
598 | 0 | theImport = imp; |
599 | 0 | initChooser(); |
600 | 0 | } |
601 | |
|
602 | |
private void initChooser() { |
603 | 0 | setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); |
604 | 0 | setMultiSelectionEnabled(true); |
605 | 0 | setSelectedFile(getCurrentDirectory()); |
606 | 0 | } |
607 | |
|
608 | |
|
609 | |
|
610 | |
|
611 | |
@Override |
612 | |
public void approveSelection() { |
613 | 0 | File[] files = getSelectedFiles(); |
614 | 0 | File dir = getCurrentDirectory(); |
615 | 0 | if (files.length == 0) { |
616 | 0 | files = new File[] {dir}; |
617 | |
} |
618 | 0 | if (files.length == 1) { |
619 | 0 | File file = files[0]; |
620 | 0 | if (file != null && file.isDirectory()) { |
621 | 0 | dir = file; |
622 | |
} else { |
623 | 0 | dir = file.getParentFile(); |
624 | |
} |
625 | |
} |
626 | 0 | theImport.setSelectedFiles(files); |
627 | |
try { |
628 | 0 | theImport.setSelectedSuffixFilter( |
629 | |
(SuffixFilter) getFileFilter()); |
630 | 0 | } catch (Exception e) { |
631 | |
|
632 | 0 | theImport.setSelectedSuffixFilter(null); |
633 | 0 | } |
634 | 0 | Globals.setLastDirectory(dir.getPath()); |
635 | 0 | theImport.disposeDialog(); |
636 | |
|
637 | 0 | theImport.doFile(); |
638 | 0 | } |
639 | |
|
640 | |
|
641 | |
|
642 | |
|
643 | |
@Override |
644 | |
public void cancelSelection() { |
645 | 0 | theImport.disposeDialog(); |
646 | 0 | } |
647 | |
|
648 | |
} |
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
class ConfigPanelExtension extends JPanel { |
655 | |
|
656 | |
|
657 | |
|
658 | |
|
659 | |
|
660 | |
|
661 | 0 | public ConfigPanelExtension(final List<Setting> settings) { |
662 | |
|
663 | 0 | setLayout(new GridBagLayout()); |
664 | |
|
665 | 0 | if (settings == null || settings.size() == 0) { |
666 | 0 | JLabel label = new JLabel("No settings for this importer"); |
667 | 0 | add(label, createGridBagConstraints(true, false, false)); |
668 | 0 | add(new JPanel(), createGridBagConstraintsFinal()); |
669 | 0 | return; |
670 | |
} |
671 | |
|
672 | 0 | for (Setting setting : settings) { |
673 | 0 | if (setting instanceof UniqueSelection2) { |
674 | 0 | JLabel label = new JLabel(setting.getLabel()); |
675 | 0 | add(label, createGridBagConstraints(true, false, false)); |
676 | |
|
677 | 0 | final UniqueSelection2 us = (UniqueSelection2) setting; |
678 | 0 | ButtonGroup group = new ButtonGroup(); |
679 | 0 | int count = 0; |
680 | 0 | for (String option : us.getOptions()) { |
681 | 0 | JRadioButton button = new JRadioButton(option); |
682 | 0 | final int index = count++; |
683 | 0 | if (us.getDefaultSelection() == index) { |
684 | 0 | button.setSelected(true); |
685 | |
} |
686 | 0 | group.add(button); |
687 | 0 | button.addActionListener(new ActionListener() { |
688 | |
public void actionPerformed(ActionEvent e) { |
689 | 0 | us.setSelection(index); |
690 | 0 | } |
691 | |
}); |
692 | 0 | add(button, createGridBagConstraints(false, false, |
693 | |
false)); |
694 | 0 | } |
695 | 0 | } else if (setting instanceof UserString2) { |
696 | 0 | JLabel label = new JLabel(setting.getLabel()); |
697 | 0 | add(label, createGridBagConstraints(true, false, false)); |
698 | 0 | final UserString2 us = (UserString2) setting; |
699 | 0 | final JTextField text = |
700 | |
new JTextField(us.getDefaultString()); |
701 | 0 | text.addFocusListener(new FocusListener() { |
702 | 0 | public void focusGained(FocusEvent e) { } |
703 | |
public void focusLost(FocusEvent e) { |
704 | 0 | us.setUserString(text.getText()); |
705 | 0 | } |
706 | |
|
707 | |
}); |
708 | 0 | add(text, createGridBagConstraints(true, false, false)); |
709 | 0 | } else if (setting instanceof BooleanSelection2) { |
710 | 0 | final BooleanSelection2 bs = (BooleanSelection2) setting; |
711 | 0 | final JCheckBox button = new JCheckBox(setting.getLabel()); |
712 | 0 | button.setEnabled(bs.isSelected()); |
713 | 0 | button.addActionListener(new ActionListener() { |
714 | |
public void actionPerformed(ActionEvent e) { |
715 | 0 | bs.setSelected(button.isSelected()); |
716 | 0 | } |
717 | |
}); |
718 | 0 | add(button, createGridBagConstraints(true, false, false)); |
719 | 0 | } else if (setting instanceof PathSelection) { |
720 | 0 | JLabel label = new JLabel(setting.getLabel()); |
721 | 0 | add(label, createGridBagConstraints(true, false, false)); |
722 | 0 | PathSelection ps = (PathSelection) setting; |
723 | |
|
724 | 0 | JTextField text = new JTextField(ps.getDefaultPath()); |
725 | 0 | add(text, createGridBagConstraints(true, false, false)); |
726 | |
|
727 | 0 | } else if (setting instanceof PathListSelection) { |
728 | 0 | PathListSelection pls = (PathListSelection) setting; |
729 | 0 | add(new ImportClasspathDialog(pls), |
730 | |
createGridBagConstraints(true, false, false)); |
731 | 0 | } else { |
732 | 0 | throw new RuntimeException("Unknown setting type requested " |
733 | |
+ setting); |
734 | |
} |
735 | |
} |
736 | 0 | add(new JPanel(), createGridBagConstraintsFinal()); |
737 | 0 | } |
738 | |
|
739 | |
|
740 | |
|
741 | |
|
742 | |
|
743 | |
|
744 | |
|
745 | |
|
746 | |
|
747 | |
|
748 | |
private GridBagConstraints createGridBagConstraints(boolean topInset, |
749 | |
boolean bottomInset, boolean fill) { |
750 | 0 | GridBagConstraints gbc = new GridBagConstraints(); |
751 | 0 | gbc.gridx = GridBagConstraints.RELATIVE; |
752 | 0 | gbc.gridy = GridBagConstraints.RELATIVE; |
753 | 0 | gbc.gridwidth = GridBagConstraints.REMAINDER; |
754 | 0 | gbc.gridheight = 1; |
755 | 0 | gbc.weightx = 1.0; |
756 | 0 | gbc.weighty = 0.0; |
757 | 0 | gbc.anchor = GridBagConstraints.NORTHWEST; |
758 | 0 | gbc.fill = fill ? GridBagConstraints.HORIZONTAL |
759 | |
: GridBagConstraints.NONE; |
760 | 0 | gbc.insets = |
761 | |
new Insets( |
762 | |
topInset ? 5 : 0, |
763 | |
5, |
764 | |
bottomInset ? 5 : 0, |
765 | |
5); |
766 | 0 | gbc.ipadx = 0; |
767 | 0 | gbc.ipady = 0; |
768 | 0 | return gbc; |
769 | |
} |
770 | |
|
771 | |
|
772 | |
|
773 | |
|
774 | |
|
775 | |
|
776 | |
|
777 | |
private GridBagConstraints createGridBagConstraintsFinal() { |
778 | 0 | GridBagConstraints gbc = createGridBagConstraints(false, true, |
779 | |
false); |
780 | 0 | gbc.gridheight = GridBagConstraints.REMAINDER; |
781 | 0 | gbc.weighty = 1.0; |
782 | 0 | return gbc; |
783 | |
} |
784 | |
|
785 | |
} |
786 | |
|
787 | |
|
788 | |
|
789 | |
} |