001 /*
002 * The contents of this file are subject to the Mozilla Public
003 * License Version 1.1 (the "License"); you may not use this file
004 * except in compliance with the License. You may obtain a copy of
005 * the License at http://www.mozilla.org/MPL/
006 *
007 * Software distributed under the License is distributed on an "AS
008 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
009 * implied. See the License for the specific language governing
010 * rights and limitations under the License.
011 *
012 * The Original Code is Knowtator.
013 *
014 * The Initial Developer of the Original Code is University of Colorado.
015 * Copyright (C) 2005 - 2008. All Rights Reserved.
016 *
017 * Knowtator was developed by the Center for Computational Pharmacology
018 * (http://compbio.uchcs.edu) at the University of Colorado Health
019 * Sciences Center School of Medicine with support from the National
020 * Library of Medicine.
021 *
022 * Current information about Knowtator can be obtained at
023 * http://knowtator.sourceforge.net/
024 *
025 * Contributor(s):
026 * Philip V. Ogren <philip@ogren.info> (Original Author)
027 */
028 package edu.uchsc.ccp.knowtator.wizards;
029
030 import java.awt.BorderLayout;
031 import java.awt.Color;
032 import java.awt.Dimension;
033 import java.awt.Font;
034 import java.awt.GridBagConstraints;
035 import java.awt.GridBagLayout;
036 import java.awt.Insets;
037 import java.awt.Point;
038 import java.awt.event.ActionEvent;
039 import java.awt.event.ActionListener;
040 import java.io.File;
041 import java.util.Collection;
042 import java.util.HashSet;
043 import java.util.Set;
044 import java.util.TreeSet;
045
046 import javax.swing.JButton;
047 import javax.swing.JCheckBox;
048 import javax.swing.JFileChooser;
049 import javax.swing.JFrame;
050 import javax.swing.JLabel;
051 import javax.swing.JList;
052 import javax.swing.JOptionPane;
053 import javax.swing.JPanel;
054 import javax.swing.JScrollPane;
055 import javax.swing.JTextArea;
056 import javax.swing.JTextField;
057 import javax.swing.event.CaretEvent;
058 import javax.swing.event.CaretListener;
059
060 import edu.stanford.smi.protege.model.KnowledgeBase;
061 import edu.stanford.smi.protege.model.Project;
062 import edu.stanford.smi.protege.model.SimpleInstance;
063 import edu.stanford.smi.protege.ui.DisplayUtilities;
064 import edu.stanford.smi.protege.ui.FrameRenderer;
065 import edu.stanford.smi.protege.ui.InstanceDisplay;
066 import edu.stanford.smi.protege.util.CollectionUtilities;
067 import edu.stanford.smi.protege.util.ComponentUtilities;
068 import edu.uchsc.ccp.knowtator.FilterUtil;
069 import edu.uchsc.ccp.knowtator.KnowtatorProjectUtil;
070
071 public class IAAWizard implements ActionListener, CaretListener {
072
073 public static final String IAA_DIRECTORY = "IAA_DIRECTORY";
074
075 public static final String IAA_FILTER = "IAA_FILTER";
076
077 public static final String IAA_TEXTSOURCES = "IAA_TEXTSOURCES";
078
079 public static final String IAA_CONFIG = "IAA_CONFIG";
080
081 public static final String IAA_CONFIG_DISPLAY = "IAA_CONFIG_DISPLAY";
082
083 public static final String IAA_WELCOME_MESSAGE = "This wizard allows you to configure how inter-annotator agreement (IAA) metrics will be calculated. "
084 + "All IAA results are written to local html files that are veiwable using a web browser. Please "
085 + "consult available documentation for details on how IAA is calculated and what the results mean. "
086 + "Calculating the IAA may take some time depending on how many matchers are used and how many "
087 + "annotations are in your project. Please be patient!";
088
089 public static final String TO_WELCOME_FRAME = "TO_WELCOME_FRAME";
090
091 public static final String TO_OUTPUT_FRAME = "TO_OUTPUT_FRAME";
092
093 public static final String TO_FILTER_FRAME = "TO_FILTER_FRAME";
094
095 public static final String TO_TEXTSOURCES_FRAME = "TO_TEXTSOURCES_FRAME";
096
097 public static final String TO_CONFIG_FRAME = "TO_CONFIG_FRAME";
098
099 public static final String GO_CLICKED = "GO_CLICKED";
100
101 public static final String ADD_SLOT_MATCHER_CLICKED = "ADD_SLOT_MATCHER_CLICKED";
102
103 public static final String REMOVE_SLOT_MATCHER_CLICKED = "REMOVE_SLOT_MATCHER_CLICKED";
104
105 File outputDirectory;
106
107 SimpleInstance filter;
108
109 Set<SimpleInstance> textSources;
110
111 boolean goClicked = false;
112
113 SimpleInstance slotMatcherConfig;
114
115 Project project;
116
117 KnowledgeBase kb;
118
119 KnowtatorProjectUtil kpu;
120
121 JFrame parent;
122
123 WizardFrame welcomeFrame;
124
125 WizardFrame outputFrame;
126
127 WizardFrame filterFrame;
128
129 WizardFrame textSourcesFrame;
130
131 WizardFrame configFrame;
132
133 WizardFrame visibleFrame; // one of the above frames
134
135 JLabel outputDirectoryLabel;
136
137 JTextField outputDirectoryField;
138
139 JButton outputDirectoryButton;
140
141 JLabel outputDirectoryWarningLabel;
142
143 JLabel filterLabel;
144
145 JButton filterButton;
146
147 JLabel textSourcesLabel;
148
149 JList textSourcesList;
150
151 JButton textSourcesRemoveButton;
152
153 JButton textSourcesAddButton;
154
155 JPanel configPanel;
156
157 JCheckBox classMatcherCheckBox;
158
159 JCheckBox spanMatcherCheckBox;
160
161 JCheckBox classAndSpanMatcherCheckBox;
162
163 JCheckBox subclassMatcherCheckBox;
164
165 JPanel slotMatcherPanel;
166
167 JButton addSlotMatcherButton;
168
169 InstanceDisplay instanceDisplay;
170
171 Dimension wizardSize;
172
173 Point wizardLocation;
174
175 public IAAWizard(Project project, KnowledgeBase kb, KnowtatorProjectUtil kpu, JFrame parent)
176
177 {
178 this.project = project;
179 this.kb = kb;
180 this.kpu = kpu;
181 this.parent = parent;
182
183 textSources = new TreeSet<SimpleInstance>();
184
185 createWelcomeFrame();
186 createOutputFrame();
187 createFilterFrame();
188 createTextSourcesFrame();
189 createConfigFrame();
190
191 setOutputDirectory(getRecentIAADirectory(), true);
192 setIAAFilter(getRecentIAAFilter());
193 addTextSources(getRecentTextSources());
194 }
195
196 private void createWelcomeFrame() {
197 welcomeFrame = new WizardFrame(parent, "Inter-annotator agreement metrics");
198 welcomeFrame.setAlwaysOnTop(false);
199 welcomeFrame.previousButton.setEnabled(false);
200 welcomeFrame.nextButton.setActionCommand(TO_OUTPUT_FRAME);
201 welcomeFrame.nextButton.addActionListener(this);
202 welcomeFrame.cancelButton.addActionListener(this);
203 welcomeFrame.contentPane.setLayout(new BorderLayout());
204 welcomeFrame.setLocation(WizardUtil.getCentralDialogLocation(parent, welcomeFrame));
205
206 JTextArea welcomeMessage = new JTextArea();
207 welcomeMessage.setEditable(false);
208 welcomeMessage.setText(IAA_WELCOME_MESSAGE);
209 welcomeMessage.setLineWrap(true);
210 welcomeMessage.setWrapStyleWord(true);
211 Font font = welcomeMessage.getFont();
212 Font newFont = font.deriveFont((float) (font.getSize() + 4));
213 welcomeMessage.setFont(newFont);
214 welcomeFrame.contentPane.add(welcomeMessage, BorderLayout.CENTER);
215 }
216
217 private void createOutputFrame() {
218 outputFrame = new WizardFrame(parent, "Select IAA output directory");
219 outputFrame.setAlwaysOnTop(false);
220 outputFrame.previousButton.setActionCommand(TO_WELCOME_FRAME);
221 outputFrame.previousButton.addActionListener(this);
222 outputFrame.nextButton.setActionCommand(TO_FILTER_FRAME);
223 outputFrame.nextButton.addActionListener(this);
224 outputFrame.cancelButton.addActionListener(this);
225
226 outputDirectoryLabel = new JLabel("Output directory");
227
228 outputDirectoryField = new JTextField();
229 outputDirectoryField.addCaretListener(this);
230
231 outputDirectoryButton = new JButton(ComponentUtilities.loadImageIcon(IAAWizard.class,
232 "/edu/uchsc/ccp/knowtator/images/Open24.gif"));
233 outputDirectoryButton.setToolTipText("Browse for output directory using file chooser.");
234 outputDirectoryButton.addActionListener(this);
235
236 outputDirectoryWarningLabel = new JLabel();
237 outputDirectoryWarningLabel.setForeground(Color.BLUE);
238
239 outputFrame.contentPane.setLayout(new GridBagLayout());
240 outputFrame.contentPane.add(outputDirectoryLabel, new GridBagConstraints(0, 0, 1, 1, 0d, 0d,
241 GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
242 outputFrame.contentPane.add(outputDirectoryField, new GridBagConstraints(1, 0, 1, 1, 1.0d, 0d,
243 GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 2, 2));
244 outputFrame.contentPane.add(outputDirectoryButton, new GridBagConstraints(2, 0, 1, 1, 0d, 0d,
245 GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
246 outputFrame.contentPane.add(outputDirectoryWarningLabel, new GridBagConstraints(1, 1, 1, 1, 0d, 0d,
247 GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
248 }
249
250 private void createFilterFrame() {
251 filterFrame = new WizardFrame(parent, "Select annotation filter that specifies which annotations to compare.");
252 filterFrame.setAlwaysOnTop(false);
253 filterFrame.previousButton.setActionCommand(TO_OUTPUT_FRAME);
254 filterFrame.previousButton.addActionListener(this);
255 filterFrame.nextButton.setActionCommand(TO_TEXTSOURCES_FRAME);
256 filterFrame.nextButton.addActionListener(this);
257 filterFrame.cancelButton.addActionListener(this);
258
259 filterLabel = new JLabel();
260 filterButton = new JButton("Choose filter");
261 filterButton.addActionListener(this);
262
263 filterFrame.contentPane.setLayout(new GridBagLayout());
264 filterFrame.contentPane.add(filterLabel, new GridBagConstraints(0, 0, 1, 1, 0d, 0d, GridBagConstraints.CENTER,
265 GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
266 filterFrame.contentPane.add(filterButton, new GridBagConstraints(1, 0, 1, 1, 0d, 0d, GridBagConstraints.CENTER,
267 GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
268 }
269
270 private void createTextSourcesFrame() {
271 textSourcesFrame = new WizardFrame(parent, "Select text sources to perform IAA on.");
272 textSourcesFrame.setAlwaysOnTop(false);
273 textSourcesFrame.previousButton.setActionCommand(TO_FILTER_FRAME);
274 textSourcesFrame.previousButton.addActionListener(this);
275 textSourcesFrame.nextButton.setActionCommand(TO_CONFIG_FRAME);
276 textSourcesFrame.nextButton.addActionListener(this);
277 textSourcesFrame.cancelButton.addActionListener(this);
278
279 textSourcesLabel = new JLabel("Selected text sources");
280 textSourcesList = new JList();
281 textSourcesList.setCellRenderer(new FrameRenderer());
282 JScrollPane scrollPane = new JScrollPane(textSourcesList);
283
284 textSourcesAddButton = new JButton("Add");
285 textSourcesAddButton.addActionListener(this);
286 textSourcesRemoveButton = new JButton("Remove");
287 textSourcesRemoveButton.addActionListener(this);
288
289 textSourcesFrame.contentPane.setLayout(new GridBagLayout());
290 textSourcesFrame.contentPane.add(textSourcesLabel, new GridBagConstraints(0, 0, 2, 1, 0d, 0d,
291 GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
292 textSourcesFrame.contentPane.add(scrollPane, new GridBagConstraints(0, 1, 2, 1, 1.0d, 1.0d,
293 GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 2, 2));
294 textSourcesFrame.contentPane.add(textSourcesAddButton, new GridBagConstraints(0, 2, 1, 1, 0d, 0d,
295 GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
296 textSourcesFrame.contentPane.add(textSourcesRemoveButton, new GridBagConstraints(1, 2, 1, 1, 0d, 0d,
297 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
298 }
299
300 private void createConfigFrame() {
301 configFrame = new WizardFrame(parent, "IAA configuration");
302 configFrame.setAlwaysOnTop(false);
303 configFrame.previousButton.setActionCommand(TO_TEXTSOURCES_FRAME);
304 configFrame.previousButton.addActionListener(this);
305 configFrame.nextButton.setText("Go!");
306 configFrame.nextButton.setActionCommand(GO_CLICKED);
307 configFrame.nextButton.addActionListener(this);
308
309 configFrame.cancelButton.addActionListener(this);
310
311 configPanel = new JPanel(new GridBagLayout());
312
313 classMatcherCheckBox = new JCheckBox("class matcher");
314 classMatcherCheckBox.setSelected(true);
315
316 spanMatcherCheckBox = new JCheckBox("span matcher");
317 spanMatcherCheckBox.setSelected(true);
318
319 classAndSpanMatcherCheckBox = new JCheckBox("class and span matcher");
320 classAndSpanMatcherCheckBox.setSelected(true);
321
322 subclassMatcherCheckBox = new JCheckBox("subclass matcher");
323 subclassMatcherCheckBox.setSelected(true);
324
325 slotMatcherPanel = new JPanel(new GridBagLayout());
326
327 addSlotMatcherButton = new JButton("add slot matcher");
328 addSlotMatcherButton.setActionCommand(ADD_SLOT_MATCHER_CLICKED);
329 addSlotMatcherButton.addActionListener(this);
330 slotMatcherPanel.add(addSlotMatcherButton, new GridBagConstraints(0, 0, 1, 1, 0d, 0d,
331 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
332
333 instanceDisplay = new InstanceDisplay(project);
334 if (getRecentDisplayConfig())
335 showSlotMatcherConfig();
336
337 configPanel.add(classMatcherCheckBox, new GridBagConstraints(0, 0, 1, 1, 0d, 0d, GridBagConstraints.WEST,
338 GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
339 configPanel.add(spanMatcherCheckBox, new GridBagConstraints(0, 1, 1, 1, 0d, 0d, GridBagConstraints.WEST,
340 GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
341 configPanel.add(classAndSpanMatcherCheckBox, new GridBagConstraints(0, 2, 1, 1, 0d, 0d,
342 GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
343 configPanel.add(subclassMatcherCheckBox, new GridBagConstraints(0, 3, 1, 1, 0d, 0d, GridBagConstraints.WEST,
344 GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
345 configPanel.add(subclassMatcherCheckBox, new GridBagConstraints(0, 4, 1, 1, 0d, 0d, GridBagConstraints.WEST,
346 GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 2, 2));
347 configPanel.add(slotMatcherPanel, new GridBagConstraints(0, 5, 1, 1, 1.0d, 1.0d, GridBagConstraints.NORTHWEST,
348 GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 2, 2));
349
350 JScrollPane configScrollPane = new JScrollPane(configPanel);
351 configFrame.contentPane.setLayout(new BorderLayout());
352 configFrame.contentPane.add(configScrollPane, BorderLayout.CENTER);
353
354 }
355
356 private void showSlotMatcherConfig() {
357 if (slotMatcherConfig == null) {
358 slotMatcherConfig = getRecentSlotMatcherConfig();
359 if (slotMatcherConfig == null) {
360 slotMatcherConfig = kb.createSimpleInstance(null, null, CollectionUtilities.createCollection(kb
361 .getCls("knowtator slot matcher config")), true);
362 setRecentSlotMatcherConfig(slotMatcherConfig);
363 }
364 }
365
366 instanceDisplay.setInstance(slotMatcherConfig);
367
368 slotMatcherPanel.add(instanceDisplay, new GridBagConstraints(0, 2, 1, 1, 1.0d, 1.0d,
369 GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 2, 2));
370
371 addSlotMatcherButton.setActionCommand(REMOVE_SLOT_MATCHER_CLICKED);
372 addSlotMatcherButton.setText("remove slot matcher");
373
374 slotMatcherPanel.repaint();
375
376 setRecentDisplayConfig(true);
377 }
378
379 private void hideSlotMatcherConfig() {
380 slotMatcherPanel.remove(instanceDisplay);
381
382 addSlotMatcherButton.setActionCommand(ADD_SLOT_MATCHER_CLICKED);
383 addSlotMatcherButton.setText("add slot matcher");
384
385 slotMatcherPanel.repaint();
386 setRecentDisplayConfig(false);
387
388 }
389
390 private SimpleInstance getRecentSlotMatcherConfig() {
391 SimpleInstance recentSlotMatcherConfig = (SimpleInstance) project.getClientInformation(IAA_CONFIG);
392 return recentSlotMatcherConfig;
393 }
394
395 private void setRecentSlotMatcherConfig(SimpleInstance slotMatcherConfig) {
396 project.setClientInformation(IAA_CONFIG, slotMatcherConfig);
397 }
398
399 private boolean getRecentDisplayConfig() {
400 Boolean recentDisplayConfig = (Boolean) project.getClientInformation(IAA_CONFIG_DISPLAY);
401 if (recentDisplayConfig != null)
402 return recentDisplayConfig.booleanValue();
403 else
404 return false;
405 }
406
407 private void setRecentDisplayConfig(boolean displayed) {
408 project.setClientInformation(IAA_CONFIG_DISPLAY, new Boolean(displayed));
409 }
410
411 private void setOutputDirectory(File directory, boolean updateOutputDirectoryField) {
412 if (directory != null && directory.exists() && directory.isDirectory()) {
413 outputDirectory = directory;
414 setRecentIAADirectory(outputDirectory);
415 outputDirectoryWarningLabel.setText("");
416 if (updateOutputDirectoryField) {
417 outputDirectoryField.setText(outputDirectory.getPath());
418 }
419 } else {
420 outputDirectoryWarningLabel.setText("Output directory is not valid.");
421 }
422 }
423
424 private void chooseOutputDirectory() {
425 JFileChooser chooser = new JFileChooser();
426 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
427
428 File chooserDirectory = null;
429 File userEnteredDirectory = new File(outputDirectoryField.getText());
430 if (userEnteredDirectory.exists()) {
431 if (userEnteredDirectory.isDirectory())
432 chooserDirectory = userEnteredDirectory;
433 else
434 chooserDirectory = userEnteredDirectory.getParentFile();
435 } else {
436 File recentDirectory = getRecentIAADirectory();
437 if (recentDirectory != null && recentDirectory.exists() && recentDirectory.isDirectory()) {
438 chooserDirectory = recentDirectory;
439 }
440 }
441 if (chooserDirectory != null) {
442 chooser.setCurrentDirectory(chooserDirectory);
443 }
444
445 int returnVal = chooser.showOpenDialog(outputFrame);
446 if (returnVal == JFileChooser.APPROVE_OPTION) {
447 setOutputDirectory(chooser.getSelectedFile(), true);
448 }
449 }
450
451 private File getRecentIAADirectory() {
452 String path = (String) project.getClientInformation(IAA_DIRECTORY);
453 if (path == null)
454 return null;
455 File projectDirectory = new File(path);
456 if (projectDirectory.exists()) {
457 if (projectDirectory.isDirectory()) {
458 return projectDirectory;
459 } else {
460 return projectDirectory.getParentFile();
461 }
462 }
463 return null;
464 }
465
466 private void setRecentIAADirectory(File iaaDirectory) {
467 project.setClientInformation(IAA_DIRECTORY, iaaDirectory.getPath());
468 }
469
470 private void setIAAFilter(SimpleInstance setFilter) {
471 if (setFilter != null) {
472 Set<SimpleInstance> annotators = new HashSet<SimpleInstance>(FilterUtil.getAnnotators(setFilter));
473 Set<SimpleInstance> sets = FilterUtil.getSets(setFilter);
474 if (annotators.size() >= 2 || sets.size() >= 2) {
475 filter = setFilter;
476 filterLabel.setText("Selected filter is '" + filter.getBrowserText() + "'");
477 setRecentIAAFilter(filter);
478 return;
479 }
480 }
481 filterLabel.setText("No filter selected.");
482 }
483
484 private void chooseIAAFilter() {
485 SimpleInstance chosenFilter = (SimpleInstance) DisplayUtilities.pickInstance(filterFrame, CollectionUtilities
486 .createCollection(kpu.getFilterCls()), "Select annotation filter");
487
488 if (chosenFilter == null)
489 return;
490 Set<SimpleInstance> annotators = new HashSet<SimpleInstance>(FilterUtil.getAnnotators(chosenFilter));
491 Set<SimpleInstance> sets = FilterUtil.getSets(chosenFilter);
492 if (annotators.size() < 2 && sets.size() < 2) {
493 JOptionPane.showMessageDialog(filterFrame,
494 "The selected filter must have either two annotators or two annotation sets specified.",
495 "Incomplete annotation filter", JOptionPane.ERROR_MESSAGE);
496 return;
497 }
498 setIAAFilter(chosenFilter);
499 }
500
501 private SimpleInstance getRecentIAAFilter() {
502 SimpleInstance filter = (SimpleInstance) project.getClientInformation(IAA_FILTER);
503 return filter;
504 }
505
506 private void setRecentIAAFilter(SimpleInstance filter) {
507 project.setClientInformation(IAA_FILTER, filter);
508 }
509
510 private Collection<SimpleInstance> getRecentTextSources() {
511 Collection<SimpleInstance> recentTextSources = (Collection<SimpleInstance>) project
512 .getClientInformation(IAA_TEXTSOURCES);
513 return recentTextSources;
514 }
515
516 private void setRecentTextSources(Set<SimpleInstance> textSources) {
517 project.setClientInformation(IAA_TEXTSOURCES, textSources);
518 }
519
520 private void addTextSources(Collection<SimpleInstance> addedTextSources) {
521 if (addedTextSources != null && addedTextSources.size() > 0) {
522 textSources.addAll(addedTextSources);
523 textSourcesList.setListData(textSources.toArray());
524 setRecentTextSources(textSources);
525 }
526 }
527
528 private void chooseTextSources() {
529 Collection<SimpleInstance> textSources = (Collection<SimpleInstance>) DisplayUtilities.pickInstances(
530 textSourcesFrame, project.getKnowledgeBase(), CollectionUtilities.createCollection(kpu
531 .getTextSourceCls()), "Select text sources");
532 addTextSources(textSources);
533 }
534
535 private void removeTextSources() {
536 Object[] selectedValues = textSourcesList.getSelectedValues();
537 for (Object selectedValue : selectedValues) {
538 textSources.remove(selectedValue);
539 }
540 textSourcesList.setListData(textSources.toArray());
541 }
542
543 public void actionPerformed(ActionEvent actionEvent) {
544 String command = actionEvent.getActionCommand();
545 Object source = actionEvent.getSource();
546 if (command.equals(TO_WELCOME_FRAME)) {
547 showFrame(welcomeFrame);
548 } else if (command.equals(TO_OUTPUT_FRAME)) {
549 showFrame(outputFrame);
550 } else if (command.equals(TO_FILTER_FRAME)) {
551 showFrame(filterFrame);
552 } else if (command.equals(TO_TEXTSOURCES_FRAME)) {
553 showFrame(textSourcesFrame);
554 } else if (command.equals(TO_CONFIG_FRAME)) {
555 showFrame(configFrame);
556 }
557
558 else if (command.equals("CANCEL")) {
559 setVisible(false);
560 } else if (source == outputDirectoryButton) {
561 chooseOutputDirectory();
562 } else if (source == filterButton) {
563 chooseIAAFilter();
564 } else if (source == textSourcesAddButton) {
565 chooseTextSources();
566 } else if (source == textSourcesRemoveButton) {
567 removeTextSources();
568 } else if (command.equals(GO_CLICKED)) {
569 goClicked = true;
570 setVisible(false);
571 } else if (command.equals(ADD_SLOT_MATCHER_CLICKED)) {
572 showSlotMatcherConfig();
573 } else if (command.equals(REMOVE_SLOT_MATCHER_CLICKED)) {
574 hideSlotMatcherConfig();
575 }
576 }
577
578 public void setVisible(boolean visible) {
579 if (visible) {
580 goClicked = false;
581 showFrame(welcomeFrame);
582 } else {
583 welcomeFrame.setVisible(false);
584 outputFrame.setVisible(false);
585 filterFrame.setVisible(false);
586 textSourcesFrame.setVisible(false);
587 configFrame.setVisible(false);
588 }
589 }
590
591 public void showFrame(WizardFrame wizardFrame) {
592 if (visibleFrame != null) {
593 wizardSize = visibleFrame.getSize();
594 wizardLocation = visibleFrame.getLocation();
595 wizardFrame.setSize(wizardSize);
596 wizardFrame.setLocation(wizardLocation);
597 }
598 visibleFrame = wizardFrame;
599 setVisible(false);
600 visibleFrame.setVisible(true);
601 }
602
603 public void caretUpdate(CaretEvent caretEvent) {
604 Object source = caretEvent.getSource();
605 if (source == outputDirectoryField) {
606 String directoryString = outputDirectoryField.getText();
607 File outputFile = new File(directoryString);
608 setOutputDirectory(outputFile, false);
609 }
610 }
611
612 public boolean isGoClicked() {
613 return goClicked;
614 }
615
616 public File getOutputDirectory() {
617 return outputDirectory;
618 }
619
620 public SimpleInstance getFilter() {
621 return filter;
622 }
623
624 public Set<SimpleInstance> getTextSources() {
625 return textSources;
626 }
627
628 public boolean isClassMatcherSelected() {
629 return classMatcherCheckBox.isSelected();
630 }
631
632 public boolean isSpanMatcherSelected() {
633 return spanMatcherCheckBox.isSelected();
634 }
635
636 public boolean isClassAndSpanMatcherSelected() {
637 return classAndSpanMatcherCheckBox.isSelected();
638 }
639
640 public boolean isSubclassMatcherSelected() {
641 return subclassMatcherCheckBox.isSelected();
642 }
643
644 public SimpleInstance getSlotMatcherConfig() {
645 return slotMatcherConfig;
646 }
647 }
648
649 // private static List<Slot> askForSlots(SimpleInstance filter, Project project,
650 // Component parent)
651 // {
652 // List<Slot> slots = new ArrayList<Slot>();
653 // Set<Cls> clses = new HashSet<Cls>();
654 // Set<Cls> filterTypes = FilterUtil.getTypes(filter);
655 // if(filterTypes.size() > 0)
656 // {
657 // clses.addAll(filterTypes);
658 // for(Cls filterType : filterTypes)
659 // {
660 // clses.addAll(filterType.getSubclasses());
661 // }
662 // }
663 // else
664 // {
665 // Cls rootCls = ProjectSettings.getRootCls(project);
666 // if(rootCls != null)
667 // {
668 // clses.add(rootCls);
669 // clses.addAll(rootCls.getSubclasses());
670 // }
671 // }
672 // for(Cls cls : clses)
673 // {
674 // Collection<Slot> clsSlots = (Collection<Slot>) cls.getTemplateSlots();
675 // for(Slot clsSlot : clsSlots)
676 // {
677 // ValueType slotType = clsSlot.getValueType();
678 // if(slotType == ValueType.BOOLEAN ||
679 // slotType == ValueType.FLOAT ||
680 // slotType == ValueType.INTEGER ||
681 // slotType == ValueType.STRING ||
682 // slotType == ValueType.SYMBOL)
683 // {
684 // slots.add(clsSlot);
685 // }
686 // }
687 // }
688 // if(slots.size() > 0)
689 // {
690 // Collection<Slot> selectedSlots = (Collection<Slot>)
691 // DisplayUtilities.pickSlots(parent, slots,
692 // "Select slots that you want matched.");
693 // slots.clear();
694 // slots.addAll(selectedSlots);
695 // }
696 // return slots;
697 // }
698