1
14 package gate.gui;
15
16 import java.awt.*;
17 import java.awt.event.*;
18 import java.util.*;
19
20 import javax.swing.*;
21
22 import gate.*;
23 import gate.annotation.AnnotationDiff;
24 import gate.creole.*;
25
26
30 class AnnotDiffDialog extends JFrame {
31
33
36 Map documentsMap = null;
37
40 Map keyAnnotationSetMap = null;
41
44 Map responseAnnotationSetMap = null;
45
48 Map typesMap = null;
49
50 Set falsePozTypes = null;
51
52 MainFrame mainFrame = null;
53
54 AnnotDiffDialog thisAnnotDiffDialog = null;
55
56
58 JComboBox keyDocComboBox = null;
59
60 JComboBox responseDocComboBox = null;
61
64 JComboBox typesComboBox = null;
65
66 JComboBox falsePozTypeComboBox = null;
67
70 JComboBox responseDocAnnotSetFalsePozComboBox = null;
71
72 JComboBox keyDocAnnotSetComboBox = null;
73
74 JComboBox responseDocAnnotSetComboBox = null;
75
76 JLabel keyLabel = null;
77
78 JLabel responseLabel = null;
79
80 JLabel typesLabel = null;
81
82 JLabel falsePozLabel = null;
83
84 JLabel keyDocAnnotSetLabel = null;
85
86 JLabel responseDocAnnotSetLabel = null;
87
88 JLabel responseDocAnnotSetFalsePozLabel = null;
89
90 JLabel weightLabel = null;
91
92 JTextField weightTextField = null;
93
94 JButton evalButton = null;
95
96 AnnotationDiff annotDiff = null;
97
98 JSplitPane jSplit = null;
99
100 JRadioButton someFeaturesRadio = null;
101
102 JRadioButton noFeaturesRadio = null;
103
104 JRadioButton allFeaturesRadio = null;
105
106 ButtonGroup groupRadios = null;
107
108 JLabel selectFeaturesLabel = null;
109
110 CollectionSelectionDialog featureSelectionDialog = null;
111
115 public AnnotDiffDialog(MainFrame aMainFrame){
116 mainFrame = aMainFrame;
117 thisAnnotDiffDialog = this;
118 initLocalData();
119 initGuiComponents();
120 initListeners();
121 }
123
124 public void updateData(){
125 documentsMap = null;
126 typesMap = null;
127 falsePozTypes = null;
128 this.removeAll();
129
130 SwingUtilities.invokeLater(new Runnable(){
131 public void run(){
132 initLocalData();
133 initGuiComponents();
134 initListeners();
135 }
136 });
137 }
139
142 public void initLocalData(){
143 annotDiff = new AnnotationDiff();
144 documentsMap = new HashMap();
147
148 CreoleRegister registry = Gate.getCreoleRegister();
149 ResourceData resourceData =
150 (ResourceData)registry.get("gate.corpora.DocumentImpl");
151 if(resourceData != null && !resourceData.getInstantiations().isEmpty()){
152 java.util.List instantiations = resourceData.getInstantiations();
153 Iterator iter = instantiations.iterator();
154 while (iter.hasNext()){
155 Resource resource = (Resource) iter.next();
156 String docName = resource.getName ();
157 gate.Document doc = (Document) resource;
158 documentsMap.put(docName,doc);
160 } }else documentsMap.put("No docs found",null);
162
163 keyAnnotationSetMap = new TreeMap();
164 responseAnnotationSetMap = new TreeMap();
165
166 typesMap = new TreeMap();
167 typesMap.put("No annot.",null);
169
170 falsePozTypes = new TreeSet();
172 falsePozTypes.add("No annot.");
173 }
175
179 public void initGuiComponents(){
180
181 this.getContentPane().setLayout(new BorderLayout());
184 Set comboCont = new TreeSet(documentsMap.keySet());
186 keyDocComboBox = new JComboBox(comboCont.toArray());
187 keyDocComboBox.setSelectedIndex(0);
188 keyDocComboBox.setEditable(false);
189 keyDocComboBox.setAlignmentX(Component.LEFT_ALIGNMENT);
190 Dimension dim = new Dimension(150,keyDocComboBox.getPreferredSize().height);
191 keyDocComboBox.setPreferredSize(dim);
192 keyDocComboBox.setMaximumSize(dim);
193 keyDocComboBox.setMinimumSize(dim);
194 keyDocComboBox.setRenderer(new MyCellRenderer(Color.green, Color.black));
195 keyLabel = new JLabel("Select the KEY doc");
197 keyLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
198 keyLabel.setOpaque(true);
199 keyLabel.setFont(keyLabel.getFont().deriveFont(Font.BOLD));
200 keyLabel.setForeground(Color.black);
201 keyLabel.setBackground(Color.green);
202
203 Set comboAsCont = new TreeSet(keyAnnotationSetMap.keySet());
205 keyDocAnnotSetComboBox = new JComboBox(comboAsCont.toArray());
206 keyDocAnnotSetComboBox.setEditable(false);
207 keyDocAnnotSetComboBox.setAlignmentX(Component.LEFT_ALIGNMENT);
208 keyDocAnnotSetLabel = new JLabel("Select the KEY annotation set");
210 keyDocAnnotSetLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
211 keyDocAnnotSetLabel.setOpaque(true);
212 keyDocAnnotSetLabel.setFont(
213 keyDocAnnotSetLabel.getFont().deriveFont(Font.BOLD));
214 keyDocAnnotSetLabel.setForeground(Color.black);
215 keyDocAnnotSetLabel.setBackground(Color.green);
216
217 responseDocComboBox = new JComboBox(comboCont.toArray());
219 responseDocComboBox.setSelectedIndex(0);
220 responseDocComboBox.setEditable(false);
221 responseDocComboBox.setAlignmentX(Component.LEFT_ALIGNMENT);
222 responseDocComboBox.setPreferredSize(dim);
223 responseDocComboBox.setMaximumSize(dim);
224 responseDocComboBox.setMinimumSize(dim);
225 responseDocComboBox.setRenderer(new MyCellRenderer(Color.red, Color.black));
226 responseLabel = new JLabel("Select the RESPONSE doc");
228 responseLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
229 responseLabel.setOpaque(true);
230 responseLabel.setFont(responseLabel.getFont().deriveFont(Font.BOLD));
231 responseLabel.setBackground(Color.red);
232 responseLabel.setForeground(Color.black);
233
234 comboAsCont = new TreeSet(responseAnnotationSetMap.keySet());
236 responseDocAnnotSetComboBox = new JComboBox(comboAsCont.toArray());
237 responseDocAnnotSetComboBox.setEditable(false);
238 responseDocAnnotSetComboBox.setAlignmentX(Component.LEFT_ALIGNMENT);
239 responseDocAnnotSetLabel = new JLabel("Select the RESPONSE annot set");
241 responseDocAnnotSetLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
242 responseDocAnnotSetLabel.setOpaque(true);
243 responseDocAnnotSetLabel.setFont(
244 responseDocAnnotSetLabel.getFont().deriveFont(Font.BOLD));
245 responseDocAnnotSetLabel.setForeground(Color.black);
246 responseDocAnnotSetLabel.setBackground(Color.red);
247
248 comboAsCont = new TreeSet(responseAnnotationSetMap.keySet());
251 responseDocAnnotSetFalsePozComboBox = new JComboBox(comboAsCont.toArray());
252 responseDocAnnotSetFalsePozComboBox.setEditable(false);
253 responseDocAnnotSetFalsePozComboBox.setAlignmentX(Component.LEFT_ALIGNMENT);
254 responseDocAnnotSetFalsePozLabel = new JLabel("Select the RESPONSE annot set");
256 responseDocAnnotSetFalsePozLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
257 responseDocAnnotSetFalsePozLabel.setOpaque(true);
258 responseDocAnnotSetFalsePozLabel.setFont(
259 responseDocAnnotSetFalsePozLabel.getFont().deriveFont(Font.BOLD));
260 responseDocAnnotSetFalsePozLabel.setForeground(Color.black);
261 responseDocAnnotSetFalsePozLabel.setBackground(Color.red);
262
263
264 Vector typesCont = new Vector(typesMap.keySet());
266 Collections.sort(typesCont);
267 typesComboBox = new JComboBox(typesCont);
268 dim = new Dimension(Integer.MAX_VALUE, typesComboBox.getPreferredSize().height);
269 typesComboBox.setMaximumSize(dim);
270
271
272 typesComboBox.setEditable(false);
273 typesComboBox.setAlignmentX(Component.LEFT_ALIGNMENT);
274 typesLabel = new JLabel("Select annot. type");
276 typesLabel.setFont(typesLabel.getFont().deriveFont(Font.BOLD));
277 typesLabel.setOpaque(true);
278 typesLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
279
280 falsePozTypeComboBox = new JComboBox(falsePozTypes.toArray());
282 falsePozTypeComboBox.setEditable(false);
283 falsePozTypeComboBox.setAlignmentX(Component.LEFT_ALIGNMENT);
284 falsePozLabel = new JLabel("Select annot. type for FalsePoz");
286 falsePozLabel.setFont(falsePozLabel.getFont().deriveFont(Font.BOLD));
287 falsePozLabel.setOpaque(true);
288 falsePozLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
289
290 weightTextField = new JTextField(
292 (new Double(AnnotationDiff.weight)).toString());
293 weightTextField.setAlignmentX(Component.LEFT_ALIGNMENT);
294 weightLabel = new JLabel("Weight for F-Measure");
296 weightLabel.setFont(falsePozLabel.getFont().deriveFont(Font.BOLD));
297 weightLabel.setOpaque(true);
298 weightLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
299
300 Dimension d = new Dimension(weightLabel.getPreferredSize().width,
302 weightTextField.getPreferredSize().height);
303 weightTextField.setMinimumSize(d);
304 weightTextField.setMaximumSize(d);
305 weightTextField.setPreferredSize(d);
306
307 evalButton = new JButton("Evaluate");
309 evalButton.setFont(evalButton.getFont().deriveFont(Font.BOLD));
310
311 someFeaturesRadio = new JRadioButton("Some");
313 someFeaturesRadio.setToolTipText("Select some features from the key"+
314 " annotation set, that will be taken into consideration"+
315 " in the diff process.");
316 noFeaturesRadio = new JRadioButton("None");
318 noFeaturesRadio.setToolTipText("No features from the key"+
319 " annotation set will be taken into consideration"+
320 " in the diff process.");
321 allFeaturesRadio = new JRadioButton("All");
323 allFeaturesRadio.setSelected(true);
324 allFeaturesRadio.setToolTipText("All features from the key"+
325 " annotation set will be taken into consideration"+
326 " in the diff process.");
327 groupRadios = new ButtonGroup();
329 groupRadios.add(allFeaturesRadio);
330 groupRadios.add(someFeaturesRadio);
331 groupRadios.add(noFeaturesRadio);
332 selectFeaturesLabel = new JLabel("Features");
334 selectFeaturesLabel.setFont(falsePozLabel.getFont().deriveFont(Font.BOLD));
335 selectFeaturesLabel.setOpaque(true);
336 selectFeaturesLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
337 Box northBox = new Box(BoxLayout.X_AXIS);
341 Box currentBox = new Box(BoxLayout.Y_AXIS);
343 currentBox.add(keyLabel);
344 currentBox.add(keyDocComboBox);
345 currentBox.add(Box.createVerticalStrut(10));
346 currentBox.add(responseLabel);
347 currentBox.add(responseDocComboBox);
348 northBox.add(currentBox);
349
350 northBox.add(Box.createRigidArea(new Dimension(10,0)));
351
352 currentBox = new Box(BoxLayout.Y_AXIS);
354 currentBox.add(keyDocAnnotSetLabel);
355 currentBox.add(keyDocAnnotSetComboBox);
356 currentBox.add(Box.createVerticalStrut(10));
357 currentBox.add(responseDocAnnotSetLabel);
358 currentBox.add(responseDocAnnotSetComboBox);
359 northBox.add(currentBox);
360
361 northBox.add(Box.createRigidArea(new Dimension(10,0)));
362
363 currentBox = new Box(BoxLayout.Y_AXIS);
365 currentBox.add(typesLabel);
366 currentBox.add(typesComboBox);
367 currentBox.add(Box.createVerticalGlue());
368 northBox.add(currentBox);
369
370 northBox.add(Box.createRigidArea(new Dimension(10,0)));
371
372 currentBox = new Box(BoxLayout.Y_AXIS);
374 currentBox.add(selectFeaturesLabel);
375 currentBox.add(allFeaturesRadio);
376 currentBox.add(someFeaturesRadio);
377 currentBox.add(noFeaturesRadio);
378 northBox.add(currentBox);
379
380 northBox.add(Box.createRigidArea(new Dimension(10,0)));
381
382 currentBox = new Box(BoxLayout.Y_AXIS);
384 currentBox.add(weightLabel);
385 currentBox.add(weightTextField);
386 northBox.add(currentBox);
387
388 northBox.add(Box.createRigidArea(new Dimension(10,0)));
389
390 currentBox = new Box(BoxLayout.Y_AXIS);
392 currentBox.add(falsePozLabel);
393 currentBox.add(falsePozTypeComboBox);
394 currentBox.add(Box.createVerticalStrut(10));
395 currentBox.add(responseDocAnnotSetFalsePozLabel);
396 currentBox.add(responseDocAnnotSetFalsePozComboBox);
397 northBox.add(currentBox);
398
399 northBox.add(Box.createRigidArea(new Dimension(10,0)));
400 northBox.add(evalButton);
401
402 initKeyAnnotSetNames();
403 initResponseAnnotSetNames();
404 initAnnotTypes();
405 initAnnotTypesFalsePoz();
406
407 this.getContentPane().setLayout(new BoxLayout(this.getContentPane(),
408 BoxLayout.Y_AXIS));
409 Dimension maxDimm = Toolkit.getDefaultToolkit().getScreenSize();
410 Dimension newDim = new Dimension(maxDimm.width/3, maxDimm.height/3);
411 JScrollPane upperScrolPane = new JScrollPane(northBox);
412 upperScrolPane.getViewport().
413 putClientProperty("EnableWindowBlit", new Boolean(true));
414 JScrollPane lowerScrolPane = new JScrollPane(annotDiff);
415 lowerScrolPane.getViewport().
416 putClientProperty("EnableWindowBlit", new Boolean(true));
417 lowerScrolPane.setMaximumSize(newDim);
418 lowerScrolPane.setMinimumSize(newDim);
419 lowerScrolPane.setPreferredSize(newDim);
420
421 jSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
422 upperScrolPane,
423 lowerScrolPane);
424 jSplit.setOneTouchExpandable(true);
425 jSplit.setOpaque(true);
426 jSplit.setAlignmentY(Component.TOP_ALIGNMENT);
427 this.getContentPane().add(jSplit);
428 this.pack();
429 Dimension ownerSize;
433 Point ownerLocation;
434 if(getOwner() == null){
435 ownerSize = Toolkit.getDefaultToolkit().getScreenSize();
436 ownerLocation = new Point(0, 0);
437 }else{
438 ownerSize = getOwner().getSize();
439 ownerLocation = getOwner().getLocation();
440 if(ownerSize.height == 0 ||
441 ownerSize.width == 0 ||
442 !getOwner().isVisible()){
443 ownerSize = Toolkit.getDefaultToolkit().getScreenSize();
444 ownerLocation = new Point(0, 0);
445 }
446 }
447 Dimension frameSize = getSize();
449 if (frameSize.height > ownerSize.height)
450 frameSize.height = ownerSize.height;
451 if (frameSize.width > ownerSize.width)
452 frameSize.width = ownerSize.width;
453 setLocation(ownerLocation.x + (ownerSize.width - frameSize.width) / 2,
454 ownerLocation.y + (ownerSize.height - frameSize.height) / 2);
455
456 }
458
461 void this_windowClosing(WindowEvent e){
462 this.setVisible(false);
463 }
465
466 private void doDiff(){
467 try{
468 Double d = new Double(thisAnnotDiffDialog.getCurrentWeight());
469 AnnotationDiff.weight = d.doubleValue();
470 }catch (NumberFormatException e){
471 JOptionPane.showMessageDialog(thisAnnotDiffDialog,
472 "The weight for F-Measure should be a double !",
473 "Annotation Diff initialization error !",
474 JOptionPane.ERROR_MESSAGE);
475 return;
476 } Thread thread = new Thread(Thread.currentThread().getThreadGroup(),
478 new DiffRunner(),
479 "AnnotDiffDialog1");
480 thread.setPriority(Thread.MIN_PRIORITY);
481 thread.start();
482 }
484
485 public void initListeners(){
486
487 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
488 this.addWindowListener(new java.awt.event.WindowAdapter() {
489 public void windowClosing(WindowEvent e) {
490 this_windowClosing(e);
491 } });
494 evalButton.addActionListener(new java.awt.event.ActionListener() {
495 public void actionPerformed(ActionEvent e) {
496 thisAnnotDiffDialog.doDiff();
497 } });
500 keyDocComboBox.addActionListener(new ActionListener() {
501 public void actionPerformed(ActionEvent e) {
502 initKeyAnnotSetNames();
503 initAnnotTypes();
504 } });
507 responseDocComboBox.addActionListener(new ActionListener() {
508 public void actionPerformed(ActionEvent e) {
509 initResponseAnnotSetNames();
510 initAnnotTypes();
511 } });
514 keyDocAnnotSetComboBox.addActionListener(new ActionListener() {
515 public void actionPerformed(ActionEvent e) {
516 initAnnotTypes();
517 } });
520 responseDocAnnotSetComboBox.addActionListener(new ActionListener() {
521 public void actionPerformed(ActionEvent e) {
522 initAnnotTypes();
523 } });
526 responseDocAnnotSetFalsePozComboBox.addActionListener(new ActionListener() {
527 public void actionPerformed(ActionEvent e) {
528 initAnnotTypesFalsePoz();
529 } });
532 typesComboBox.addActionListener(new ActionListener() {
533 public void actionPerformed(ActionEvent e){
534 if (featureSelectionDialog != null) featureSelectionDialog = null;
535 } });
538 someFeaturesRadio.addActionListener(new ActionListener() {
539 public void actionPerformed(ActionEvent e){
540 collectSomeFeatures();
541 } });
544 }
546
549 private void collectSomeFeatures(){
550 if (featureSelectionDialog == null){
551 featureSelectionDialog = new CollectionSelectionDialog(
552 thisAnnotDiffDialog,true);
553 }else{
554 featureSelectionDialog.setVisible(true);
555 return;
556 } gate.Document keyDocument = null;
560 keyDocument = (gate.Document) documentsMap.get(
561 (String)keyDocComboBox.getSelectedItem());
562 if (keyDocument == null){
563 JOptionPane.showMessageDialog(this,
564 "Select a key document first !",
565 "GATE", JOptionPane.ERROR_MESSAGE);
566 featureSelectionDialog = null;
567 return;
568 }
570 AnnotationSet keySet = null;
571 if (keyDocAnnotSetComboBox.getSelectedItem()== null ||
572 keyAnnotationSetMap.get(keyDocAnnotSetComboBox.getSelectedItem())==null)
573 keySet = keyDocument.getAnnotations();
575 else{
576 AnnotationSet as = (AnnotationSet) keyAnnotationSetMap.get(
578 keyDocAnnotSetComboBox.getSelectedItem());
579 keySet = as;
580 } if (keySet == null){
582 JOptionPane.showMessageDialog(this,
583 "Select some annotation sets first !",
584 "GATE", JOptionPane.ERROR_MESSAGE);
585 featureSelectionDialog = null;
586 return;
587 } AnnotationSchema annotSchema = (AnnotationSchema)
589 typesMap.get(typesComboBox.getSelectedItem());
590 if (annotSchema == null){
591 JOptionPane.showMessageDialog(this,
592 "Select some annotation types first !",
593 "GATE", JOptionPane.ERROR_MESSAGE);
594 featureSelectionDialog = null;
595 return;
596 } AnnotationSet selectedTypeSet = keySet.get(annotSchema.getAnnotationName());
598 Set featureNamesSet = new TreeSet();
599 Iterator selectedTypeIterator = selectedTypeSet.iterator();
601 while(selectedTypeIterator.hasNext()){
602 Annotation a = (Annotation) selectedTypeIterator.next();
603 if (a.getFeatures() != null)
604 featureNamesSet.addAll(a.getFeatures().keySet());
605 } featureSelectionDialog.show("Select features for annotation type \"" +
607 annotSchema.getAnnotationName()+ "\" that would be used in diff proces",
608 featureNamesSet);
609 }
611
612 private void initAnnotTypesFalsePoz(){
613 gate.Document responseDocument = null;
614 responseDocument = (gate.Document) documentsMap.get(
615 (String)responseDocComboBox.getSelectedItem());
616 falsePozTypes.clear();
617 if (responseDocument == null){
618 falsePozTypes.add("No annot.");
620 DefaultComboBoxModel cbm = new DefaultComboBoxModel(falsePozTypes.toArray());
621 falsePozTypeComboBox.setModel(cbm);
622 return;
623 }
625 Set responseSet = null;
627 if (responseDocAnnotSetFalsePozComboBox.getSelectedItem() == null ||
628 responseAnnotationSetMap.get(
629 responseDocAnnotSetFalsePozComboBox.getSelectedItem())==null)
630 responseSet = new HashSet(
631 responseDocument.getAnnotations().getAllTypes());
632 else{
633 AnnotationSet as = (AnnotationSet) responseAnnotationSetMap.get(
635 responseDocAnnotSetFalsePozComboBox.getSelectedItem());
636 responseSet = new HashSet(as.getAllTypes());
637 }
639 falsePozTypes.addAll(responseSet);
641 if (falsePozTypes.isEmpty())
642 falsePozTypes.add("No annot.");
643 DefaultComboBoxModel cbm = new DefaultComboBoxModel(falsePozTypes.toArray());
644 falsePozTypeComboBox.setModel(cbm);
645 }
647
652 private void initAnnotTypes(){
653 gate.Document keyDocument = null;
654 gate.Document responseDocument = null;
655
656 keyDocument = (gate.Document) documentsMap.get(
657 (String)keyDocComboBox.getSelectedItem());
658 responseDocument = (gate.Document) documentsMap.get(
659 (String)responseDocComboBox.getSelectedItem());
660
661 typesMap.clear();
662
663 if (keyDocument == null || responseDocument == null){
664 typesMap.put("No annot.",null);
666 ComboBoxModel cbm = new DefaultComboBoxModel(typesMap.keySet().toArray());
667 typesComboBox.setModel(cbm);
668 return;
669 }
671 Set keySet = null;
674 if (keyDocAnnotSetComboBox.getSelectedItem()== null ||
675 keyAnnotationSetMap.get(keyDocAnnotSetComboBox.getSelectedItem())==null)
676 keySet = new HashSet(keyDocument.getAnnotations().getAllTypes());
678 else{
679 AnnotationSet as = (AnnotationSet) keyAnnotationSetMap.get(
681 keyDocAnnotSetComboBox.getSelectedItem());
682 keySet = new HashSet(as.getAllTypes());
683 }
685 Set responseSet = null;
688 if (responseDocAnnotSetComboBox.getSelectedItem() == null ||
689 responseAnnotationSetMap.get(
690 responseDocAnnotSetComboBox.getSelectedItem())==null)
691 responseSet = new HashSet(
692 responseDocument.getAnnotations().getAllTypes());
693 else{
694 AnnotationSet as = (AnnotationSet) responseAnnotationSetMap.get(
696 responseDocAnnotSetComboBox.getSelectedItem());
697 responseSet = new HashSet(as.getAllTypes());
698 }
700 keySet.retainAll(responseSet);
702 Set intersectSet = keySet;
703
704 Iterator iter = intersectSet.iterator();
705 while (iter.hasNext()){
706 String annotName = (String) iter.next();
707
708 AnnotationSchema schema = new AnnotationSchema();
709 schema.setAnnotationName(annotName);
710
711 typesMap.put(annotName,schema);
712 }
714 if (typesMap.isEmpty())
715 typesMap.put("No annot.",null);
716
717 DefaultComboBoxModel cbm = new DefaultComboBoxModel(
718 typesMap.keySet().toArray());
719 typesComboBox.setModel(cbm);
720 }
722
726 private void initKeyAnnotSetNames(){
727 gate.Document keyDocument = null;
728 keyDocument = (gate.Document) documentsMap.get(
729 (String)keyDocComboBox.getSelectedItem());
730 keyAnnotationSetMap.clear();
731
732 if (keyDocument != null){
733 Map namedAnnotSets = keyDocument.getNamedAnnotationSets();
734 if (namedAnnotSets != null)
735 keyAnnotationSetMap.putAll(namedAnnotSets);
736 keyAnnotationSetMap.put("Default set",null);
737 DefaultComboBoxModel cbm = new DefaultComboBoxModel(
738 keyAnnotationSetMap.keySet().toArray());
739 keyDocAnnotSetComboBox.setModel(cbm);
740 } }
743
747 private void initResponseAnnotSetNames(){
748 gate.Document responseDocument = null;
749 responseDocument = (gate.Document) documentsMap.get(
750 (String)responseDocComboBox.getSelectedItem());
751 responseAnnotationSetMap.clear();
752
753 if (responseDocument != null){
754 Map namedAnnotSets = responseDocument.getNamedAnnotationSets();
755 if (namedAnnotSets != null)
756 responseAnnotationSetMap.putAll(namedAnnotSets);
757 responseAnnotationSetMap.put("Default set",null);
758 DefaultComboBoxModel cbm = new DefaultComboBoxModel(
759 responseAnnotationSetMap.keySet().toArray());
760 responseDocAnnotSetComboBox.setModel(cbm);
761 cbm = new DefaultComboBoxModel(
762 responseAnnotationSetMap.keySet().toArray());
763 responseDocAnnotSetFalsePozComboBox.setModel(cbm);
764 } }
767
768 public gate.Document getSelectedKeyDocument(){
769 return (gate.Document) documentsMap.get(
770 (String)keyDocComboBox.getSelectedItem());
771 }
773
774 public gate.Document getSelectedResponseDocument(){
775 return (gate.Document) documentsMap.get(
776 (String)responseDocComboBox.getSelectedItem());
777 }
779
780 public AnnotationSchema getSelectedSchema(){
781 return (AnnotationSchema) typesMap.get(
782 (String)typesComboBox.getSelectedItem());
783 }
785
786 public String getCurrentWeight(){
787 return weightTextField.getText();
788 }
790
791 public String getSelectedFalsePozAnnot(){
792 return (String) falsePozTypeComboBox.getSelectedItem();
793 }
795
798 public String getSelectedKeyAnnotationSetName(){
799 String asName = (String) keyDocAnnotSetComboBox.getSelectedItem();
800 if ("Default set".equals(asName)) return null;
801 else return asName;
802 }
804
807 public String getSelectedResponseAnnotationSetName(){
808 String asName = (String) responseDocAnnotSetComboBox.getSelectedItem();
809 if ("Default set".equals(asName)) return null;
810 else return asName;
811 }
813
816 public String getSelectedResponseAnnotationSetNameFalsePoz(){
817 String asName = (String) responseDocAnnotSetFalsePozComboBox.getSelectedItem();
818 if ("Default set".equals(asName)) return null;
819 else return asName;
820 }
822
825 class MyCellRenderer extends JLabel implements ListCellRenderer {
826
827 Color background = null;
828 Color foreground = null;
829
830 public MyCellRenderer(Color aBackground, Color aForeground){
831 setOpaque(true);
832 background = aBackground;
833 foreground = aForeground;
834 }
836
837 public Component getListCellRendererComponent(
838 JList list,
839 Object value,
840 int index,
841 boolean isSelected,
842 boolean cellHasFocus){
843 ToolTipManager.sharedInstance().registerComponent(list);
845 setText(value.toString());
846 setBackground(isSelected ? background : Color.white);
847 setForeground(isSelected ? foreground : Color.black);
848 if (isSelected)
849 list.setToolTipText(value.toString());
850 return this;
851 } }
854
855 class DiffRunner implements Runnable{
856
857 public DiffRunner(){}
859 public void run(){
860 annotDiff.setKeyDocument(thisAnnotDiffDialog.getSelectedKeyDocument());
861 annotDiff.setResponseDocument(
862 thisAnnotDiffDialog.getSelectedResponseDocument());
863 annotDiff.setAnnotationSchema(thisAnnotDiffDialog.getSelectedSchema());
864 annotDiff.setKeyAnnotationSetName(
865 thisAnnotDiffDialog.getSelectedKeyAnnotationSetName());
866 annotDiff.setResponseAnnotationSetName(
867 thisAnnotDiffDialog.getSelectedResponseAnnotationSetName());
868 annotDiff.setResponseAnnotationSetNameFalsePoz(
869 thisAnnotDiffDialog.getSelectedResponseAnnotationSetNameFalsePoz());
870
871 if (allFeaturesRadio.isSelected())
873 annotDiff.setKeyFeatureNamesSet(null);
874 if (noFeaturesRadio.isSelected())
875 annotDiff.setKeyFeatureNamesSet(new HashSet());
876 if (someFeaturesRadio.isSelected())
879 annotDiff.setKeyFeatureNamesSet(
880 new HashSet(featureSelectionDialog.getSelectedCollection()));
881 String falsePozAnnot = thisAnnotDiffDialog.getSelectedFalsePozAnnot();
882 if ("No annot.".equals(falsePozAnnot))
883 falsePozAnnot = null;
884 annotDiff.setAnnotationTypeForFalsePositive(falsePozAnnot);
885 try{
886 annotDiff.init();
887 } catch (ResourceInstantiationException e){
888 JOptionPane.showMessageDialog(thisAnnotDiffDialog,
889 e.getMessage() + "\n Annotation diff stopped !",
890 "Annotation Diff initialization error !",
891 JOptionPane.ERROR_MESSAGE);
892 }finally {
893 SwingUtilities.invokeLater(new Runnable(){
894 public void run(){
895 doLayout();
896 pack();
897 } }); } } }}