1   /* Gaze.java
2    * borislav popov
3    */
4   package com.ontotext.gate.vr;
5   
6   import javax.swing.*;
7   import javax.swing.event.*;
8   
9   import gate.creole.*;
10  import gate.creole.gazetteer.*;
11  import gate.creole.ontology.*;
12  import gate.util.*;
13  import gate.event.ObjectModificationListener;
14  import gate.event.GateEvent;
15  import gate.event.ObjectModificationEvent;
16  import gate.gui.MainFrame;
17  import gate.*;
18  
19  import com.ontotext.gate.ontology.*;
20  
21  import java.awt.*;
22  import java.awt.event.*;
23  import java.util.*;
24  import java.net.*;
25  import java.io.*;
26  
27  /** Gaze is a Gazetteer VR capable of viewing and editing
28   *  gazetteer lists, linear definitions (lists.def files),
29   *  and mapping definitions (mappings between ontology classes and gazetteer lists).
30   *  I.e. capable of visualizing and editing both linear and ontology-aware gazetteers. */
31  public class Gaze extends AbstractVisualResource
32    implements GazetteerListener, ObjectModificationListener {
33  
34    /** size x when running from the tools menu */
35    public final static int SIZE_X = 700;
36    /** size y when running from the tools menu */
37    public final static int SIZE_Y = 500;
38    /** positin x when running from the tools menu */
39    public final static int POSITION_X = 300;
40    /** positin y when running from the tools menu */
41    public final static int POSITION_Y = 200;
42  
43    /* Linear Definition Actions */
44    /** Edit Linear Node */
45    private final static int LDA_EDIT = 1;
46    /** Insert Linear Node */
47    private final static int LDA_INSERT = 2;
48    /** Remove Linear Node */
49    private final static int LDA_REMOVE = 3;
50  
51    /** the target to be displayed */
52    private Gazetteer target = null;
53  
54    /** is the target resource ontology-aware gazetteer */
55    private boolean isOntoGaz = false;
56  
57    /** the linear definition being displayed */
58    private LinearDefinition linear = null;
59  
60    /** the linear node currently selected */
61    private LinearNode linearNode = null;
62  
63    /** the gazetteer list currently selected */
64    private GazetteerList gazList = null;
65  
66    /** Set of all lists, both in the linear definition and
67     *  explicitly loaded ones.*/
68    private Set listSet = null;
69  
70    /** the mapping definition being displayed */
71    private MappingDefinition mapping = null;
72  
73    /** the mapping node currently selected */
74    private MappingNode mappingNode = null;
75  
76    /** the ontology that is currently displayed */
77    private Taxonomy ontology = null;
78  
79    /** map of ontologies vs trees */
80    private Map ontologyTrees = new HashMap();
81  
82    /*manually added gui components */
83  
84    /**Linear Definition Popup menu */
85    protected JPopupMenu linearPopup = new JPopupMenu();
86    /**Linear Definition Edit Popup Item*/
87    protected JMenuItem linearPopupEdit;
88    /**Linear Definition Insert Popup Item*/
89    protected JMenuItem linearPopupInsert;
90    /**Linear Definition Remove Popup Item*/
91    protected JMenuItem linearPopupRemove;
92  
93    /*automatically added gui components */
94    protected JMenuBar mainMenu = new JMenuBar();
95    protected JMenu fileMenu = new JMenu();
96    protected JMenu viewMenu = new JMenu();
97    protected JSplitPane baseSplit = new JSplitPane();
98    protected JSplitPane mappingSplit = new JSplitPane();
99    protected JSplitPane linearSplit = new JSplitPane();
100   protected JPanel linearPanel = new JPanel();
101   protected JPanel listPanel = new JPanel();
102   protected JPanel mappingPanel = new JPanel();
103   protected JPanel ontologyPanel = new JPanel();
104   protected JLabel linearLabel = new JLabel();
105   protected GridBagLayout gridBagLayout1 = new GridBagLayout();
106   protected JScrollPane linearScroll = new JScrollPane();
107   protected JToolBar linearBar = new JToolBar();
108   protected JButton btnLinearLoad = new JButton();
109   protected JList linearList = new JList();
110   protected JButton btnLinearSave = new JButton();
111   protected JButton btnLinearSaveAs = new JButton();
112   protected JLabel listLabel = new JLabel();
113   protected GridBagLayout gridBagLayout2 = new GridBagLayout();
114   protected JToolBar listBar = new JToolBar();
115   protected JButton btnListLoad = new JButton();
116   protected JScrollPane listScroll = new JScrollPane();
117   protected JButton btnListSave = new JButton();
118   protected JButton btnListSaveAs = new JButton();
119   protected GridBagLayout gridBagLayout3 = new GridBagLayout();
120   protected JLabel mappingLabel = new JLabel();
121   protected JToolBar mappingBar = new JToolBar();
122   protected JButton btnMappingLoad = new JButton();
123   protected JScrollPane mappingScroll = new JScrollPane();
124   protected JList mappingList = new JList();
125   protected JButton btnMappingSave = new JButton();
126   protected JButton btnMappingSaveAs = new JButton();
127   protected JLabel ontologyLabel = new JLabel();
128   protected JToolBar ontologyBar = new JToolBar();
129   protected JButton btnOntologyLoad = new JButton();
130   protected JScrollPane ontologyScroll = new JScrollPane();
131   protected GridBagLayout gridBagLayout4 = new GridBagLayout();
132   protected JMenu menuHelp = new JMenu();
133   protected JMenuItem menuAbout = new JMenuItem();
134   protected GridBagLayout thisLayout = new GridBagLayout();
135   protected JMenu menuLinear = new JMenu();
136   protected JMenuItem menuLinearLoad = new JMenuItem();
137   protected JMenuItem menuLinearSave = new JMenuItem();
138   protected JMenuItem menuLinearSaveAs = new JMenuItem();
139   protected JMenu menuList = new JMenu();
140   protected JMenuItem menuListLoad = new JMenuItem();
141   protected JMenuItem menuListSave = new JMenuItem();
142   protected JMenuItem menuListSaveAs = new JMenuItem();
143   protected JMenu menuMapping = new JMenu();
144   protected JMenuItem menuMappingLoad = new JMenuItem();
145   protected JMenuItem menuMappingSave = new JMenuItem();
146   protected JMenuItem menuMappingSaveAs = new JMenuItem();
147   protected JMenu menuOntology = new JMenu();
148   protected JMenuItem menuOntologyLoad = new JMenuItem();
149   protected JMenuItem menuRefresh = new JMenuItem();
150   protected JTree oTree = new JTree();
151   protected JTextArea listArea = new JTextArea();
152   protected JButton btnMappingNew = new JButton();
153   protected JButton btnLinearNew = new JButton();
154   protected JButton btnListNew = new JButton();
155   protected JMenuItem menuLinearNew = new JMenuItem();
156   protected JMenuItem menuListNew = new JMenuItem();
157   protected JMenuItem menuMappingNew = new JMenuItem();
158   protected JButton btnListSaveAll = new JButton();
159   protected JMenuItem menuListSaveAll = new JMenuItem();
160 
161 
162   public Gaze() {
163     try {
164 
165       jbInit();
166       /* add menu bar*/
167       mainMenu.setMinimumSize(new Dimension(0,20));
168       mainMenu.setMaximumSize(new Dimension(0,20));
169       mainMenu.setPreferredSize(new Dimension(0,20));
170       this.add(mainMenu,   new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
171             ,GridBagConstraints.CENTER,
172             GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0 ));
173 
174       /* make the ontology tree invisible because not initialized yet*/
175       oTree.setVisible(false);
176 
177       /* create and associate linear listeners... */
178       createLinearListeneres();
179 
180       /*...and non linear (mapping, ontology) listeners */
181       createNonLinearListeners();
182 
183       /* associate the load,save,saveas buttons with action */
184       createLinearDefBtnListeners();
185       createGazListBtnListeners();
186       createMappingDefBtnListeners();
187 
188       /* create a new cell renderer for the linear definition list */
189       linearList.setCellRenderer(new LinearCR());
190 
191       /* add modifications listener over the gazetteer list text area */
192       listArea.getDocument().addDocumentListener(new GazListDL());
193 
194       /* create Linear Definition Popup menu */
195       linearPopupEdit = new JMenuItem("edit");
196       linearPopupInsert = new JMenuItem("insert");
197       linearPopupRemove = new JMenuItem("remove");
198 
199       linearPopup.add(linearPopupEdit);
200       linearPopup.add(linearPopupInsert);
201       linearPopup.add(linearPopupRemove);
202 
203       /* add popup listener */
204       linearList.addMouseListener(new LinearPopupListener());
205 
206 
207       /* add popup menu items' listeners*/
208       linearPopupEdit.addActionListener(new LinearPopupEditListener());
209       linearPopupRemove.addActionListener(new LinearPopupRemoveListener());
210       linearPopupInsert.addActionListener(new LinearPopupInsertListener());
211     } catch(Exception e) {
212       e.printStackTrace(gate.util.Err.getPrintWriter());
213     }
214   }
215 
216   /**
217    * Called by the GUI when this viewer/editor has to initialise itself for a
218    * specific object. this is an {@link gate.creole.AbstractVisualResource} overriden method.
219    * @param targeta the object (be it a {@link gate.Resource},
220    * {@link gate.DataStore} or whatever) this viewer has to display
221    */
222   public void setTarget(Object targeta) {
223 
224     /*check the parameter*/
225     if (null == targeta) {
226       throw new GateRuntimeException("should not set null target.");
227     }
228     if (! (targeta instanceof Gazetteer) ) {
229       throw new GateRuntimeException(
230         "the target should impelement \n"+
231         "gate.creole.gazetteer.Gazetteer. \n"+
232         "target => "+targeta.getClass());
233     }
234 
235     target = (Gazetteer)targeta;
236 
237     target.addGazetteerListener(this);
238 
239     /** determine the type of the target */
240     isOntoGaz = (target instanceof OntoGazetteer);
241 
242     /**disable the ontology and mapping areas */
243     if (!isOntoGaz) {
244       mappingSplit.setVisible(false);
245       mappingList.disable();
246     }
247 
248     /* display linear definition */
249     displayLinear(target);
250 
251     /* display mapping */
252     if (isOntoGaz)
253       displayMapping(target);
254 
255   } // setTarget(Object)
256 
257 
258   public gate.Resource init() throws ResourceInstantiationException {
259     return this;
260   }
261 
262   /** updates the mapping list's ui */
263   void updateMappingUI(){
264     if ( null!=mappingList ) {
265       mappingList.setListData(mapping.toArray());
266       mappingList.updateUI();
267     }
268   } // updateMappingUI()
269 
270   /** Displays the specified list in the most right pane of Gaze
271    * @param listName the name of the list
272    */
273   void displayList(String listName) {
274     // find the gazetteer list by list name
275     Object node = linear.getNodesByListNames().get(listName);
276     GazetteerList newList = null;
277     if ( node != null )  {
278       newList = (GazetteerList)linear.getListsByNode().get(node);
279       if ( null != newList ){
280 
281         //retrieve the possible editions of the gazetteer
282         if (null!=listArea && null!=gazList) {
283           gazList.setMode(gazList.STRING_MODE);
284           boolean mdfd = gazList.isModified();
285           gazList.updateContent(listArea.getText());
286           gazList.setModified(mdfd);
287         }
288 
289         //show the newly selected list
290         gazList = newList;
291         if ( null!= gazList) {
292           gazList.setMode(gazList.STRING_MODE);
293           boolean mdfd = gazList.isModified();
294           listArea.setText(gazList.toString());
295           gazList.setModified(mdfd);
296         } else {
297           listArea.setText("");
298         }
299       }  // != null
300     } // != null
301 
302   } // displayList(String)
303 
304   /**Gets the lists
305    * @return a list of all the gaz lists known to this VR*/
306   java.util.List getLists() {
307     return linear.getLists();
308   }
309 
310   /**Gets all classes.
311    * @return a list of all the classes from all the ontologies known to this VR*/
312   java.util.List getClasses() {
313     java.util.List result = null;
314     if ( null == ontology)
315       result = new ArrayList();
316     else {
317       result = new ArrayList (ontology.getClasses());
318     }
319     return result;
320   }
321 
322 
323 
324   /** Displays linear definition
325    *  @param g the gazetteer to take the definition from */
326   private void displayLinear(Gazetteer g) {
327     // get the linear definition
328     linear = g.getLinearDefinition();
329     // check the linear definition
330     if (null == linear)
331       throw new GateRuntimeException(
332         "linear definition of a gazetteer should not be null.");
333 
334     listSet = new HashSet(linear.getLists());
335 
336     if (null == listSet)
337       throw new GateRuntimeException(
338         "The set of Gazetteer Lists should not be null.");
339 
340     // set the list data with the nodes of the gaz
341     linearList.setListData(new Vector(linear.getNodes()));
342   } // displayLinear()
343 
344   /** Displays mapping
345    *  @param g the gazetteer to take the mapping from */
346   private void displayMapping(Gazetteer g) {
347     mapping = g.getMappingDefinition();
348     if (null == mapping)
349       throw new GateRuntimeException(
350         "the mapping definition of an onto gazetteer should not be null");
351     mappingList.setListData(mapping.toArray());
352 
353     /*Add all lists present in the mapping to the set of loaded lists*/
354     listSet.addAll(mapping.getLists());
355 
356   }// displayMapping()
357 
358   /**Creates and associates listeners for the linear gui components*/
359   private void createLinearListeneres() {
360 
361     /* add list selection listener to the linear definition list component*/
362     linearList.addListSelectionListener(
363       new ListSelectionListener () {
364         public void valueChanged(ListSelectionEvent e) {
365           if (linearList.getAnchorSelectionIndex() < linearList.getModel().getSize()) {
366             Object obj = linearList.getModel().getElementAt(
367               linearList.getAnchorSelectionIndex());
368             if ( obj instanceof LinearNode ) {
369               linearNode = (LinearNode) obj;
370 
371               //retrieve the possible editions of the gazetteer
372               if (null!=listArea && null!=gazList) {
373                 gazList.setMode(gazList.STRING_MODE);
374                 boolean mdfd = gazList.isModified();
375                 gazList.updateContent(listArea.getText());
376                 gazList.setModified(mdfd);
377               }
378 
379               //show the newly selected list
380               gazList = (GazetteerList)linear.getListsByNode().get(linearNode);
381               if ( null!= gazList) {
382                 gazList.setMode(gazList.STRING_MODE);
383                 boolean mdfd = gazList.isModified();
384                 listArea.setText(gazList.toString());
385                 gazList.setModified(mdfd);
386               } else {
387                 listArea.setText("");
388               }
389 
390 
391             } // only if linear node
392           } // size > 0
393         } // valueChanged();
394       } );
395 
396   } // createLinearListeneres()
397 
398   /**Creates and asssociates listeners for the
399    * non linear (mapping,ontology) gui components   */
400   private void createNonLinearListeners() {
401 
402     /* add list selection listener to the mapping definition list component*/
403     mappingList.addListSelectionListener(
404       new ListSelectionListener () {
405         public void valueChanged(ListSelectionEvent e) {
406           if (0 < mappingList.getModel().getSize()) {
407             Object obj = mappingList.getModel().getElementAt(
408               mappingList.getAnchorSelectionIndex());
409             if ( obj instanceof MappingNode ) {
410               mappingNode = (MappingNode) obj;
411               URL ourl;
412               try {
413                 ourl = new URL(mappingNode.getOntologyID());
414               } catch  (MalformedURLException x) {
415                 throw new GateRuntimeException("Malformed URL:"
416                   +mappingNode.getOntologyID());
417               }
418               // get te ontology
419               try {
420                 ontology = new OntologyImpl().getOntology(ourl);
421                 if(ontology instanceof TaxonomyImpl)
422                   ((TaxonomyImpl)ontology).
423                   addObjectModificationListener(Gaze.this);
424               } catch (ResourceInstantiationException x) {
425                 x.printStackTrace(Err.getPrintWriter());
426               }
427               if (null == ontology)
428                 throw new GateRuntimeException("can not retrieve ontology by url.\n"
429                   +"ontology is null.\n"
430                   +"url = "+ourl);
431 
432               // remove the old tree from the scroll pane
433               if (null != oTree)
434                 ontologyScroll.getViewport().remove(oTree);
435 
436               // check if there is already a tree for this ontology
437               oTree = (JTree) ontologyTrees.get(ontology);
438 
439               if (null == oTree) {
440                 Map namesVsNodes = new HashMap();
441                 ClassNode root = ClassNode.createRootNode(ontology,mapping,namesVsNodes);
442                 OntoTreeModel model = new OntoTreeModel(root);
443                 MappingTreeView view = new MappingTreeView(model,mapping,Gaze.this);
444                 oTree = view;
445                 ontologyTrees.put(ontology,oTree);
446               } // ontology tree has not been previously creted
447 
448               ontologyScroll.getViewport().add(oTree,null);
449               oTree.setVisible(true);
450 
451               displayList(mappingNode.getList());
452             } // only if mapping node
453           } // size > 0
454         } // valueChanged();
455       } );
456 
457   } // createNonLinearListeners()
458 
459 
460   /**Sets the listeners for the load,save and save as
461    * buttons in the linear definition pane */
462   private void createLinearDefBtnListeners() {
463     /* add a create/new action listener */
464     btnLinearNew.addActionListener(new LinearNewListener());
465     menuLinearNew.addActionListener(new LinearNewListener());
466 
467     /* add load action listener for the linear definition */
468     btnLinearLoad.addActionListener(new LinearLoadListener());
469     menuLinearLoad.addActionListener(new LinearLoadListener());
470 
471     /* add save as action listener for the linear definition */
472     btnLinearSaveAs.addActionListener(new LinearSaveAsListener());
473     menuLinearSaveAs.addActionListener(new LinearSaveAsListener());
474 
475 
476     /* add save action listener for the linear definition */
477     btnLinearSave.addActionListener(new LinearSaveListener());
478     menuLinearSave.addActionListener(new LinearSaveListener());
479 
480   } // createLinearDefBtnListeners()
481 
482   /**Sets the listeners for the load,save and save as
483    * buttons in the gazetteer list pane */
484   private void createGazListBtnListeners() {
485 
486     /* add new action listener */
487     btnListNew.addActionListener(new ListNewListener());
488     menuListNew.addActionListener(new ListNewListener());
489 
490     /* add load action listener */
491     btnListLoad.addActionListener(new ListLoadListener());
492     menuListLoad.addActionListener(new ListLoadListener());
493 
494     /* add save as action listener */
495     btnListSaveAs.addActionListener(new ListSaveAsListener());
496     menuListSaveAs.addActionListener(new ListSaveAsListener());
497 
498     /* add save action listener */
499     btnListSave.addActionListener(new ListSaveListener());
500     menuListSave.addActionListener(new ListSaveListener());
501 
502     /* add save all action listener */
503     btnListSaveAll.addActionListener(new ListSaveAllListener());
504     menuListSaveAll.addActionListener(new ListSaveAllListener());
505   } // createGazListBtnListeners()
506 
507   /**Sets the listeners for the load,save and save as
508    * buttons in the mapping pane */
509   private void createMappingDefBtnListeners() {
510 
511     /* add create new action listener */
512     btnMappingNew.addActionListener(new MappingNewListener());
513     menuMappingNew.addActionListener(new MappingNewListener());
514 
515     /* add load action listener */
516     btnMappingLoad.addActionListener(new MappingLoadListener());
517     menuMappingLoad.addActionListener(new MappingLoadListener());
518 
519     /* add save as action listen*/
520     btnMappingSaveAs.addActionListener(new MappingSaveAsListener());
521     menuMappingSaveAs.addActionListener(new MappingSaveAsListener());
522 
523 
524     /* add save action listener */
525     btnMappingSave.addActionListener(new MappingSaveListener());
526     menuMappingSave.addActionListener(new MappingSaveListener());
527 
528     /* add load ontology action listener*/
529     btnOntologyLoad.addActionListener(new OntologyLoadListener());
530     menuOntologyLoad.addActionListener(new OntologyLoadListener());
531 
532   } // createLinearDefBtnListeners()
533 
534   /**
535    * Performs an action over the Linear Definition.
536    * e.g. edit,insert,remove Linear Node.
537    * @param action the action to be performed
538    * @param index index of the place where this action took place(e.g. where to insert)
539    * @param node the Linear Node to be used in the action
540    */
541   private void performLinearAction(int action, int index, LinearNode node ) {
542     switch (action) {
543       case LDA_EDIT : {
544         Object bkp = linear.get(index);
545         linear.remove(index);
546         int size = linear.size();
547         linear.add(index,node);
548         if (size == linear.size()) {
549           JOptionPane.showMessageDialog(
550             this,
551             "The Linear Node can not be added to the Linear Definition \n"
552             +"because a node with such a list already exists,\n"+
553             "cannot be opened, or cannot be created if non-existant.\n"
554             +"node : "+node,
555             "Edit Linear Node Failure",
556             JOptionPane.ERROR_MESSAGE);
557           //rollback
558           linear.add(index,bkp);
559         }// if
560 
561         break;
562       }
563       case LDA_INSERT : {
564         int size = linear.size();
565         if (index < 0 ) index = 0;
566         linear.add(index,node);
567         if (size == linear.size()) {
568           JOptionPane.showMessageDialog(
569             this,
570             "The Linear Node can not be added to the Linear Definition \n"
571             +"because a node with such a list already exists,\n"+
572             "cannot be opened, or cannot be created if non-existant.\n"
573             +"node : "+node,
574             "Insert Linear Node Failure",
575             JOptionPane.ERROR_MESSAGE);
576         }// if
577         break;
578       }
579       case LDA_REMOVE : {
580         linear.remove(index);
581         break;
582       }
583     } // switch action
584     linearList.setListData(linear.toArray());
585   } // performLinearAction(int,LinearNode)
586 
587   /** Reinitializes the edited gazetteer */
588   private void reinitializeGazetteer() {
589     try {
590       target.setListsURL(linear.getURL());
591       if (isOntoGaz) {
592         ((OntoGazetteer)target).setMappingURL(mapping.getURL());
593         gate.Factory.deleteResource(((OntoGazetteer)target).getGazetteer());
594       } // if onto gaz
595       target = (Gazetteer)target.init();
596       JOptionPane.showMessageDialog(this,
597           "Gazetteer Reinitialized.",
598           "Reinitialize Gazetteer",
599           JOptionPane.INFORMATION_MESSAGE);
600     } catch(ResourceInstantiationException x) {
601       JOptionPane.showMessageDialog(this,
602         "Gazetteer can not be reinitialized.\n"+
603         "due to:"+x.getClass()+" "+x.getMessage(),
604         "Gazsetteer Reinitialize Failure.",JOptionPane.ERROR_MESSAGE);
605     }
606   } // reinitializeGazetteer()
607 
608   /** Init of the gui components */
609   private void jbInit() throws Exception {
610     fileMenu.setToolTipText("");
611     fileMenu.setText("File");
612     viewMenu.setText("View");
613     this.setPreferredSize(new Dimension(600, 300));
614     this.setLayout(thisLayout);
615     baseSplit.setPreferredSize(new Dimension(700, 450));
616     mappingSplit.setOrientation(JSplitPane.VERTICAL_SPLIT);
617     mappingSplit.setToolTipText("");
618     linearSplit.setContinuousLayout(true);
619     linearLabel.setAlignmentY((float) 0.0);
620     linearLabel.setToolTipText("");
621     linearLabel.setHorizontalAlignment(SwingConstants.CENTER);
622     linearLabel.setText("Linear Definition");
623     linearPanel.setLayout(gridBagLayout1);
624     linearScroll.setPreferredSize(new Dimension(100, 50));
625     btnLinearLoad.setBorder(BorderFactory.createEtchedBorder());
626     btnLinearLoad.setToolTipText("Load a linear definition");
627     btnLinearLoad.setFocusPainted(false);
628     btnLinearLoad.setMargin(new Insets(2, 2, 2, 2));
629     btnLinearLoad.setText("Load");
630     btnLinearSave.setBorder(BorderFactory.createEtchedBorder());
631     btnLinearSave.setToolTipText("Save the linear definition");
632     btnLinearSave.setFocusPainted(false);
633     btnLinearSave.setMargin(new Insets(2, 2, 2, 2));
634     btnLinearSave.setText("Save");
635     btnLinearSaveAs.setBorder(BorderFactory.createEtchedBorder());
636     btnLinearSaveAs.setToolTipText("Save the linear definition changing the location");
637     btnLinearSaveAs.setFocusPainted(false);
638     btnLinearSaveAs.setMargin(new Insets(2, 0, 2, 0));
639     btnLinearSaveAs.setText("Save as...");
640     listLabel.setAlignmentY((float) 0.0);
641     listLabel.setHorizontalAlignment(SwingConstants.CENTER);
642     listLabel.setText("Gazetteer List");
643     listPanel.setLayout(gridBagLayout2);
644     btnListLoad.setBorder(BorderFactory.createEtchedBorder());
645     btnListLoad.setToolTipText("Load a gazetteer list");
646     btnListLoad.setFocusPainted(false);
647     btnListLoad.setMargin(new Insets(2, 0, 2, 0));
648     btnListLoad.setText("Load");
649     listScroll.setAlignmentX((float) 0.0);
650     listScroll.setAlignmentY((float) 0.0);
651     btnListSave.setBorder(BorderFactory.createEtchedBorder());
652     btnListSave.setToolTipText("Save the gazetteer list");
653     btnListSave.setFocusPainted(false);
654     btnListSave.setMargin(new Insets(2, 0, 2, 0));
655     btnListSave.setText("Save");
656     btnListSaveAs.setBorder(BorderFactory.createEtchedBorder());
657     btnListSaveAs.setToolTipText("Save the gazetteer list to different location");
658     btnListSaveAs.setFocusPainted(false);
659     btnListSaveAs.setMargin(new Insets(2, 0, 2, 0));
660     btnListSaveAs.setText("Save as...");
661     listBar.setFloatable(false);
662     mappingPanel.setLayout(gridBagLayout3);
663     mappingLabel.setHorizontalAlignment(SwingConstants.CENTER);
664     mappingLabel.setText("Mapping Definition");
665     btnMappingLoad.setBorder(BorderFactory.createEtchedBorder());
666     btnMappingLoad.setToolTipText("Load a mapping definition");
667     btnMappingLoad.setFocusPainted(false);
668     btnMappingLoad.setMargin(new Insets(2, 0, 2, 0));
669     btnMappingLoad.setText("Load");
670     btnMappingSave.setBorder(BorderFactory.createEtchedBorder());
671     btnMappingSave.setToolTipText("Save mapping definition");
672     btnMappingSave.setFocusPainted(false);
673     btnMappingSave.setMargin(new Insets(2, 0, 2, 0));
674     btnMappingSave.setText("Save");
675     btnMappingSaveAs.setBorder(BorderFactory.createEtchedBorder());
676     btnMappingSaveAs.setToolTipText("Save mapping definition to another location");
677     btnMappingSaveAs.setFocusPainted(false);
678     btnMappingSaveAs.setMargin(new Insets(2, 0, 2, 0));
679     btnMappingSaveAs.setText("Save As...");
680     ontologyLabel.setHorizontalAlignment(SwingConstants.CENTER);
681     ontologyLabel.setText("Ontology");
682     btnOntologyLoad.setBorder(BorderFactory.createEtchedBorder());
683     btnOntologyLoad.setToolTipText("Load an ontology");
684     btnOntologyLoad.setFocusPainted(false);
685     btnOntologyLoad.setMargin(new Insets(2, 2, 2, 2));
686     btnOntologyLoad.setText("Load");
687     ontologyPanel.setLayout(gridBagLayout4);
688     mappingBar.setFloatable(false);
689     ontologyBar.setFloatable(false);
690     linearBar.setFloatable(false);
691     menuHelp.setText("Help");
692     menuAbout.setText("About");
693     menuLinear.setText("Linear Definition");
694     menuLinearLoad.setText("Load");
695     menuLinearSave.setText("Save");
696     menuLinearSaveAs.setText("Save as");
697     menuList.setText("Gazetteer List");
698     menuListLoad.setText("Load");
699     menuListSave.setText("Save");
700     menuListSaveAs.setText("Save as");
701     menuMapping.setText("Mapping Definition");
702     menuMappingLoad.setText("Load");
703     menuMappingSave.setText("Save");
704     menuMappingSaveAs.setText("Save as");
705     menuOntology.setText("Ontology");
706     menuOntologyLoad.setText("Load");
707     menuRefresh.setText("Refresh");
708     mainMenu.setBorder(BorderFactory.createEtchedBorder());
709     oTree.setToolTipText("");
710     btnMappingNew.setText("New");
711     btnMappingNew.setMargin(new Insets(2, 0, 2, 0));
712     btnMappingNew.setFocusPainted(false);
713     btnMappingNew.setToolTipText("Create a New Mapping Definition");
714     btnMappingNew.setBorder(BorderFactory.createEtchedBorder());
715     btnLinearNew.setText("New");
716     btnLinearNew.setMargin(new Insets(2, 2, 2, 2));
717     btnLinearNew.setFocusPainted(false);
718     btnLinearNew.setToolTipText("Create a New Linear Definition");
719     btnLinearNew.setBorder(BorderFactory.createEtchedBorder());
720     btnListNew.setText("New");
721     btnListNew.setMargin(new Insets(2, 0, 2, 0));
722     btnListNew.setFocusPainted(false);
723     btnListNew.setToolTipText("Create a New Gazetteer List");
724     btnListNew.setBorder(BorderFactory.createEtchedBorder());
725     menuLinearNew.setText("New");
726     menuListNew.setText("New");
727     menuMappingNew.setText("New");
728     btnListSaveAll.setText("Save All");
729     btnListSaveAll.setMargin(new Insets(2, 0, 2, 0));
730     btnListSaveAll.setFocusPainted(false);
731     btnListSaveAll.setToolTipText("Save all modified gazetteer lists ");
732     btnListSaveAll.setBorder(BorderFactory.createEtchedBorder());
733     menuListSaveAll.setToolTipText("Save All Modified Gazetteer Lists");
734     menuListSaveAll.setText("Save All");
735     listBar.add(btnListNew, null);
736     linearBar.add(btnLinearNew, null);
737     mainMenu.add(fileMenu);
738     mainMenu.add(viewMenu);
739     mainMenu.add(menuHelp);
740     this.add(baseSplit,   new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
741             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 48, 64));
742     baseSplit.add(mappingSplit, JSplitPane.LEFT);
743     baseSplit.add(linearSplit, JSplitPane.RIGHT);
744     linearSplit.add(linearPanel, JSplitPane.TOP);
745     linearSplit.add(listPanel, JSplitPane.BOTTOM);
746     listPanel.add(listLabel,                           new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
747             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
748     mappingSplit.add(mappingPanel, JSplitPane.BOTTOM);
749     mappingSplit.add(ontologyPanel, JSplitPane.TOP);
750     ontologyPanel.add(ontologyLabel,    new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
751             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
752     ontologyPanel.add(ontologyBar,   new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
753             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
754     ontologyPanel.add(ontologyScroll,   new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0
755             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
756     ontologyScroll.getViewport().add(oTree, null);
757     ontologyBar.add(btnOntologyLoad, null);
758     linearPanel.add(linearBar,      new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
759             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
760     linearBar.add(btnLinearLoad, null);
761     linearBar.add(btnLinearSave, null);
762     linearBar.add(btnLinearSaveAs, null);
763     linearPanel.add(linearScroll,       new GridBagConstraints(0, 2, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0
764             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
765     linearScroll.getViewport().add(linearList, null);
766     linearPanel.add(linearLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
767             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
768     listPanel.add(listBar,         new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
769             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
770     listPanel.add(listScroll,       new GridBagConstraints(0, 2, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0
771             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
772     listScroll.getViewport().add(listArea, null);
773     listBar.add(btnListLoad, null);
774     listBar.add(btnListSave, null);
775     listBar.add(btnListSaveAs, null);
776     listBar.add(btnListSaveAll, null);
777     mappingPanel.add(mappingLabel,  new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
778             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
779     mappingPanel.add(mappingBar,   new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
780             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
781     mappingPanel.add(mappingScroll,  new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0
782             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
783     mappingScroll.getViewport().add(mappingList, null);
784     mappingBar.add(btnMappingNew, null);
785     mappingBar.add(btnMappingLoad, null);
786     mappingBar.add(btnMappingSave, null);
787     mappingBar.add(btnMappingSaveAs, null);
788     menuHelp.add(menuAbout);
789     fileMenu.add(menuLinear);
790     fileMenu.add(menuList);
791     fileMenu.addSeparator();
792     fileMenu.add(menuMapping);
793     fileMenu.add(menuOntology);
794     menuLinear.add(menuLinearNew);
795     menuLinear.add(menuLinearLoad);
796     menuLinear.add(menuLinearSave);
797     menuLinear.add(menuLinearSaveAs);
798     menuList.add(menuListNew);
799     menuList.add(menuListLoad);
800     menuList.add(menuListSave);
801     menuList.add(menuListSaveAs);
802     menuList.add(menuListSaveAll);
803     menuMapping.add(menuMappingNew);
804     menuMapping.add(menuMappingLoad);
805     menuMapping.add(menuMappingSave);
806     menuMapping.add(menuMappingSaveAs);
807     menuOntology.add(menuOntologyLoad);
808     viewMenu.add(menuRefresh);
809     mappingSplit.setDividerLocation(200);
810     linearSplit.setDividerLocation(230);
811     baseSplit.setDividerLocation(300);
812   } // jbInit()
813 
814 /*---------implementation of GazetteerListener interface--------------*/
815   public void processGazetteerEvent(GazetteerEvent e) {
816     if ( e.REINIT == e.getType() ) {
817       displayLinear((Gazetteer)e.getSource());
818       if (isOntoGaz) {
819         displayMapping((Gazetteer)e.getSource());
820         ontologyTrees = new HashMap();
821         oTree.setVisible(false);
822       }
823     } // reinit
824   } // processGazetteerEvent(GazetteerEvent)
825 /*---------implementation of GazetteerListener interface--------------*/
826 
827 /*->->->---implementation of ObjectModificationListener interface--------------*/
828   public void processGateEvent(GateEvent e) {
829   }
830 
831   public void objectCreated(ObjectModificationEvent e) {
832   }
833 
834   public void objectDeleted(ObjectModificationEvent e) {
835   }
836 
837   public void objectModified(ObjectModificationEvent e) {
838     Object source = e.getSource();
839     if ( source instanceof Taxonomy ) {
840 
841       JTree tree = (JTree)ontologyTrees.get((Taxonomy)source);
842       if (tree!=null) {
843         ontologyTrees.remove((Taxonomy)source);
844         Map namesVsNodes = new HashMap();
845         ClassNode root = ClassNode.createRootNode((Taxonomy)source,mapping,namesVsNodes);
846         OntoTreeModel model = new OntoTreeModel(root);
847         MappingTreeView view = new MappingTreeView(model,mapping,Gaze.this);
848 
849         /* synchronize the expansion of the old and new trees */
850         EditableTreeView.synchronizeTreeExpansion(tree,view);
851 
852         if ( ontology.equals((Taxonomy)ontology)) {
853           oTree = view;
854           ontologyScroll.getViewport().add(oTree,null);
855           oTree.setVisible(true);
856         }
857         ontologyTrees.put(ontology,oTree);
858       }
859     }
860   }
861 
862 /*-<-<-<---implementation of ObjectModificationListener interface--------------*/
863 
864 
865   /* --- inner classes ----*/
866 
867   /** Creates a list cell renderer for the
868    *  Linear Definition list. It should make
869    *  distinct the modifed gazetteer lists and still
870    *  look like the default one.*/
871   class LinearCR extends DefaultListCellRenderer {
872 
873     public LinearCR() {
874       super();
875     }
876 
877     public Component getListCellRendererComponent(
878       JList list,
879       Object value,
880       int index,
881       boolean isSelected,
882       boolean cellHasFocus)
883     {
884       super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
885       GazetteerList gl = (GazetteerList)linear.getListsByNode().get(value);
886       if ( null!= gl && gl.isModified()) {
887         setBackground(list.getBackground());
888         setForeground(Color.red);
889       } // is modified
890       return this;
891     }// getListCellRendererComponent()
892   } // class linearCR
893 
894   /** Gazetteer List Document Listener is used to monitor the
895    * gaz list changes and alter the isModified flag of the current list.*/
896   class GazListDL implements DocumentListener {
897 
898     public void changedUpdate(DocumentEvent ev) {
899         gazList.setModified(true);
900       }
901 
902       public void insertUpdate(DocumentEvent ev) {
903         gazList.setModified(true);
904       }
905 
906       public void removeUpdate(DocumentEvent ev) {
907         gazList.setModified(true);
908       }
909   } // class GazListDL
910 
911   /** Reacts on all New Linear Definition actions performed either
912    *  through the menu, wither through the new buton. */
913   class LinearNewListener implements ActionListener {
914         public void actionPerformed(ActionEvent e) {
915           JFileChooser chooser = MainFrame.getFileChooser();
916           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
917 
918           int result = chooser.showDialog(Gaze.this, "New");
919           if ( result == JFileChooser.APPROVE_OPTION ) {
920             File selected = chooser.getSelectedFile();
921             try {
922               if (!selected.createNewFile()){
923                 JOptionPane.showMessageDialog(
924                   Gaze.this,
925                   "Cannot Create Linear Definition\n"+
926                   selected.getAbsolutePath(),
927                   "Linear Definition Create Failure",
928                   JOptionPane.ERROR_MESSAGE
929                 );
930               } // if
931               URL lurl = new URL("file:///"+selected.getAbsolutePath());
932               linear = new LinearDefinition();
933               linear.setURL(lurl);
934               linear.setEncoding(target.getEncoding());
935               linear.load();
936 
937               // get the new list set
938               listSet = new HashSet(linear.getLists());
939 
940               if (null == listSet)
941                 throw new GateRuntimeException(
942                   "The set of Gazetteer Lists should not be null.");
943 
944               // set the list data with the nodes of the gaz
945               linearList.setListData(new Vector(linear.getNodes()));
946 
947 
948               JOptionPane.showMessageDialog(
949                 Gaze.this,
950                 "New Linear Definition created successfully \n"+
951                 selected.getAbsolutePath(),
952                 "Create New Linear Definition Successful",
953                 JOptionPane.INFORMATION_MESSAGE
954               );
955 
956             } catch (ResourceInstantiationException x) {
957               JOptionPane.showMessageDialog(Gaze.this,
958                 "Unable to load linear definition (corrupted format).\n"
959                 +"file:///"+selected.getAbsolutePath()+"\n"
960                 +"Due to:\nResourceInstantiationException:"+x.getMessage()
961                 ,"Linear Definition Load Failure",
962                 JOptionPane.ERROR_MESSAGE);
963             } catch (Exception x) {
964               JOptionPane.showMessageDialog(Gaze.this,
965                 "Unable to load linear definition (corrupted format).\n"
966                 +"file:///"+selected.getAbsolutePath()+"\n"
967                 +"Due to:\n"+x.getClass()+":"+x.getMessage()
968                 ,"Linear Definition Load Failure",
969                 JOptionPane.ERROR_MESSAGE);
970             }
971           } // approve
972         } // actionPerformed(ActionEvent)
973     } // class LinearLoadListener
974 
975   /** Reacts on all Load Linear Definition actions performed either
976    *  through the menu, wither through the load buton. */
977   class LinearLoadListener implements ActionListener {
978         public void actionPerformed(ActionEvent e) {
979           JFileChooser chooser = MainFrame.getFileChooser();
980           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
981 
982           int result = chooser.showOpenDialog(Gaze.this);
983           if ( result == JFileChooser.APPROVE_OPTION ) {
984             File selected = chooser.getSelectedFile();
985             try {
986               URL lurl = new URL("file:///"+selected.getAbsolutePath());
987               linear = new LinearDefinition();
988               linear.setURL(lurl);
989               linear.setEncoding(target.getEncoding());
990               linear.load();
991 
992               // get the new list set
993               listSet = new HashSet(linear.getLists());
994 
995               if (null == listSet)
996                 throw new GateRuntimeException(
997                   "The set of Gazetteer Lists should not be null.");
998 
999               // set the list data with the nodes of the gaz
1000              linearList.setListData(new Vector(linear.getNodes()));
1001
1002
1003              reinitializeGazetteer();
1004            } catch (ResourceInstantiationException x) {
1005              JOptionPane.showMessageDialog(Gaze.this,
1006                "Unable to load linear definition (corrupted format).\n"
1007                +"file:///"+selected.getAbsolutePath()+"\n"
1008                +"Due to:\nResourceInstantiationException:"+x.getMessage()
1009                ,"Linear Definition Load Failure",
1010                JOptionPane.ERROR_MESSAGE);
1011            } catch (Exception x) {
1012              JOptionPane.showMessageDialog(Gaze.this,
1013                "Unable to load linear definition (corrupted format).\n"
1014                +"file:///"+selected.getAbsolutePath()+"\n"
1015                +"Due to:\n"+x.getClass()+":"+x.getMessage()
1016                ,"Linear Definition Load Failure",
1017                JOptionPane.ERROR_MESSAGE);
1018            }
1019          } // approve
1020        } // actionPerformed(ActionEvent)
1021    } // class LinearLoadListener
1022
1023    /** Reacts on all Save As Linear Definition actions. */
1024    class LinearSaveAsListener implements ActionListener {
1025        public void actionPerformed(ActionEvent e) {
1026          if ( null == linear ) {
1027            JOptionPane.showMessageDialog(
1028              Gaze.this,"The linear definition is null and cannot be saved.",
1029              "Linear Definition Save As Failure.",JOptionPane.ERROR_MESSAGE);
1030          } else {
1031            JFileChooser chooser = MainFrame.getFileChooser();
1032            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1033
1034            int result = chooser.showSaveDialog(Gaze.this);
1035            if ( result == JFileChooser.APPROVE_OPTION ) {
1036              File selected = chooser.getSelectedFile();
1037              URL lurl;
1038              try {
1039                lurl = new URL("file:///"+selected.getAbsolutePath());
1040                linear.setURL(lurl);
1041                linear.store();
1042                JOptionPane.showMessageDialog(
1043                  Gaze.this,
1044                  "Linear Definition saved sucessfuly.\n"
1045                  +lurl,
1046                  "Linear Definition Save As",
1047                  JOptionPane.PLAIN_MESSAGE);
1048                reinitializeGazetteer();
1049              } catch (MalformedURLException x) {
1050                JOptionPane.showMessageDialog(Gaze.this,"Cannot save linear definition.\n"
1051                  +"Due to "+x.getClass()+":"+x.getMessage(),
1052                  "Linear Definition Save As failure",JOptionPane.ERROR_MESSAGE);
1053              } catch (ResourceInstantiationException x) {
1054                JOptionPane.showMessageDialog(
1055                  Gaze.this,
1056                  "Unable to save the linear defintion.\n"
1057                  +"Due to : "+x.getClass()+":"+x.getMessage(),
1058                  "Linear Definition Save failure.",
1059                  JOptionPane.ERROR_MESSAGE);
1060              } // catch
1061            } // approved
1062          } // else
1063        }
1064    }// class LinearSaveListener
1065
1066  /** Reacts on all Linear Definition  Save As events */
1067  class LinearSaveListener implements ActionListener {
1068    public void actionPerformed(ActionEvent e) {
1069      if ( null == linear ) {
1070        JOptionPane.showMessageDialog(
1071          Gaze.this,"The Linear Definition is null and cannot be saved.",
1072          "Linear Definition Save failure.",JOptionPane.ERROR_MESSAGE);
1073      } else {
1074
1075        try {
1076          linear.store();
1077          JOptionPane.showMessageDialog(
1078            Gaze.this,
1079            "Linear Definition saved sucessfuly.\n"+
1080            linear.getURL(),
1081            "Linear Definition Save",
1082            JOptionPane.PLAIN_MESSAGE);
1083
1084          reinitializeGazetteer();
1085
1086        } catch (ResourceInstantiationException x) {
1087          JOptionPane.showMessageDialog(
1088            Gaze.this,
1089            "Unable to save the Linear Definition.\n"
1090            +"Due to : "+x.getClass()+":"+x.getMessage(),
1091            "Linear Definition Save failure.",
1092            JOptionPane.ERROR_MESSAGE);
1093        } // catch
1094      } // else
1095    } // actionPerformed(ActionEvent)
1096  } // class LinearSaveListener
1097
1098  /**Reacts on all Create New Gaz List Events */
1099  class ListNewListener implements ActionListener {
1100        public void actionPerformed(ActionEvent e) {
1101          JFileChooser chooser = MainFrame.getFileChooser();
1102          chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1103
1104          int result = chooser.showDialog(Gaze.this, "New");
1105          if ( result == JFileChooser.APPROVE_OPTION ) {
1106            File selected = chooser.getSelectedFile();
1107            try {
1108              if (!selected.createNewFile()){
1109                JOptionPane.showMessageDialog(
1110                  Gaze.this,
1111                  "Cannot Create Gazetteer List.\n"+
1112                  selected.getAbsolutePath(),
1113                  "Gazetteer List Create Failure",
1114                  JOptionPane.ERROR_MESSAGE
1115                );
1116              } // if
1117              URL lurl = new URL("file:///"+selected.getAbsolutePath());
1118              gazList = new GazetteerList();
1119              gazList.setURL(lurl);
1120              gazList.load();
1121              gazList.setMode(gazList.STRING_MODE);
1122              // set the list data with the nodes of the gaz
1123              listArea.setText(gazList.toString());
1124              gazList.setModified(false);
1125
1126              String lName = gazList.getURL().getFile();
1127              int slash = lName.lastIndexOf('/');
1128              lName = lName.substring(slash+1);
1129              listSet.add(lName);
1130
1131            } catch (ResourceInstantiationException x) {
1132              JOptionPane.showMessageDialog(Gaze.this,
1133                "Unable to load Gazetteer List (corrupted format).\n"
1134                +"file:///"+selected.getAbsolutePath()+"\n"
1135                +"Due to:\nResourceInstantiationException:"+x.getMessage()
1136                ,"Gazetteer List Load Failure",
1137                JOptionPane.ERROR_MESSAGE);
1138            } catch (Exception x) {
1139              JOptionPane.showMessageDialog(Gaze.this,
1140                "Unable to load Gazetteer List (corrupted format).\n"
1141                +"file:///"+selected.getAbsolutePath()+"\n"
1142                +"Due to:\n"+x.getClass()+":"+x.getMessage()
1143                ,"Gazetteer List Load Failure",
1144                JOptionPane.ERROR_MESSAGE);
1145            }
1146          } // approve
1147        } // actionPerformed(ActionEvent)
1148    } // class ListNewListener
1149
1150
1151  /**Reacts on all Gaz List Load Events */
1152  class ListLoadListener implements ActionListener {
1153        public void actionPerformed(ActionEvent e) {
1154          JFileChooser chooser = MainFrame.getFileChooser();
1155          chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1156
1157          int result = chooser.showOpenDialog(Gaze.this);
1158          if ( result == JFileChooser.APPROVE_OPTION ) {
1159            File selected = chooser.getSelectedFile();
1160            try {
1161              URL lurl = new URL("file:///"+selected.getAbsolutePath());
1162              gazList = new GazetteerList();
1163              gazList.setURL(lurl);
1164              gazList.load();
1165              gazList.setMode(gazList.STRING_MODE);
1166
1167              listArea.setText(gazList.toString());
1168
1169              gazList.setModified(false);
1170
1171              String lName = gazList.getURL().getFile();
1172              int slash = lName.lastIndexOf('/');
1173              lName = lName.substring(slash+1);
1174              listSet.add(lName);
1175
1176            } catch (ResourceInstantiationException x) {
1177              JOptionPane.showMessageDialog(Gaze.this,
1178                "Unable to load Gazetteer List (corrupted format).\n"
1179                +"file:///"+selected.getAbsolutePath()+"\n"
1180                +"Due to:\nResourceInstantiationException:"+x.getMessage()
1181                ,"Gazetteer List Load Failure",
1182                JOptionPane.ERROR_MESSAGE);
1183            } catch (Exception x) {
1184              JOptionPane.showMessageDialog(Gaze.this,
1185                "Unable to load Gazetteer List (corrupted format).\n"
1186                +"file:///"+selected.getAbsolutePath()+"\n"
1187                +"Due to:\n"+x.getClass()+":"+x.getMessage()
1188                ,"Gazetteer List Load Failure",
1189                JOptionPane.ERROR_MESSAGE);
1190            }
1191          } // approve
1192        } // actionPerformed(ActionEvent)
1193    } // class ListLoadListener
1194
1195    /** Gazetteer list Save As action listener */
1196    class ListSaveAsListener implements ActionListener {
1197        public void actionPerformed(ActionEvent e) {
1198          if ( null == gazList ) {
1199            JOptionPane.showMessageDialog(
1200              Gaze.this,"The Gazetteer List is null and cannot be saved.",
1201              "Gazetteer List Save failure.",JOptionPane.ERROR_MESSAGE);
1202          } else {
1203            JFileChooser chooser = MainFrame.getFileChooser();
1204            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1205
1206            int result = chooser.showSaveDialog(Gaze.this);
1207            if ( result == JFileChooser.APPROVE_OPTION ) {
1208              File selected = chooser.getSelectedFile();
1209              URL lurl;
1210              try {
1211                lurl = new URL("file:///"+selected.getAbsolutePath());
1212                gazList.setURL(lurl);
1213                gazList.updateContent(listArea.getText());
1214                gazList.setMode(gazList.LIST_MODE);
1215                gazList.store();
1216                JOptionPane.showMessageDialog(
1217                  Gaze.this,
1218                  "Gazetteer List saved sucessfuly.\n"
1219                  +lurl,
1220                  "Gazetteer List Save As",
1221                  JOptionPane.PLAIN_MESSAGE);
1222
1223                reinitializeGazetteer();
1224
1225              } catch (MalformedURLException x) {
1226                JOptionPane.showMessageDialog(Gaze.this,"Cannot save Gazetteer List.\n"
1227                  +"Due to "+x.getClass()+":"+x.getMessage(),
1228                  "Gazetteer List Save As failure",JOptionPane.ERROR_MESSAGE);
1229              } catch (ResourceInstantiationException x) {
1230                JOptionPane.showMessageDialog(
1231                  Gaze.this,
1232                  "Unable to save the Gazetteer List.\n"
1233                  +"Due to : "+x.getClass()+":"+x.getMessage(),
1234                  "Gazetteer List save failure.",
1235                  JOptionPane.ERROR_MESSAGE);
1236              } // catch
1237            } // approved
1238          } // else
1239        }
1240    }//class ListSaveAsListener
1241
1242    /** Gaz List Save Action Listener */
1243    class ListSaveListener implements ActionListener {
1244        public void actionPerformed(ActionEvent e) {
1245          if ( null == gazList ) {
1246            JOptionPane.showMessageDialog(
1247              Gaze.this,"The Gazetteer List is null and cannot be saved.",
1248              "Gazetteer List Save failure.",JOptionPane.ERROR_MESSAGE);
1249          } else {
1250
1251            try {
1252              gazList.updateContent(listArea.getText());
1253              gazList.setMode(gazList.LIST_MODE);
1254              gazList.store();
1255              JOptionPane.showMessageDialog(
1256                Gaze.this,
1257                "Gazetteer List saved sucessfully.\n"
1258                +gazList.getURL(),
1259                "Gazetteer List Save",
1260                JOptionPane.PLAIN_MESSAGE);
1261
1262              reinitializeGazetteer();
1263
1264            } catch (ResourceInstantiationException x) {
1265              JOptionPane.showMessageDialog(
1266                Gaze.this,
1267                "Unable to save the Gazetteer List.\n"
1268                +"Due to : "+x.getClass()+":"+x.getMessage(),
1269                "Gazetteer List Save failure.",
1270                JOptionPane.ERROR_MESSAGE);
1271            } // catch
1272          } // else
1273        }
1274    }//gaz list save action listener
1275
1276    /** Gaz List Save All Action Listener */
1277    class ListSaveAllListener implements ActionListener {
1278        public void actionPerformed(ActionEvent e) {
1279              if (null!=gazList && null!=listArea) {
1280                boolean mdf = gazList.isModified();
1281                gazList.updateContent(listArea.getText());
1282                gazList.setMode(gazList.LIST_MODE);
1283                gazList.setModified(mdf);
1284              }
1285
1286              GazetteerList gl = null ;
1287              StringBuffer allListsStr = new StringBuffer();
1288              boolean totalSuccess = true;
1289              boolean totalFailure = true;
1290              boolean anythingHappened = false;
1291
1292              LinearNode node = null;
1293
1294              for ( int i = 0 ; i < linear.size() ; i++ ) {
1295                node = (LinearNode)linear.get(i);
1296                gl = (GazetteerList)linear.getListsByNode().get(node);
1297                try {
1298                  if (gl.isModified()) {
1299                    anythingHappened = true;
1300                    gl.setMode(gl.LIST_MODE);
1301                    gl.store();
1302                    allListsStr.append("\nSAVED : "+
1303                      node.getList());
1304                    totalFailure = false;
1305                  }
1306                } catch (ResourceInstantiationException x ) {
1307                  allListsStr.append("\nFAILED : ");
1308                  allListsStr.append(node.getList());
1309                  totalSuccess = false;
1310                }
1311              }//for
1312
1313              String msg = null;
1314              if (!anythingHappened) {
1315                msg = "There were no modified Gazetteer Lists to be saved.\n";
1316              } else {
1317                if (totalFailure) {
1318                  msg = "Not even one modified Gazetteer List was saved.\n";
1319                } else {
1320                  if (totalSuccess) {
1321                    msg = "All Modified Gazetteer Lists saved sucessfuly.\n";
1322                  } else {
1323                    msg = "Some of the Modified Gazetteer Lists were saved sucessfuly.\n";
1324                  } // else
1325                } // else
1326              } //else
1327              JOptionPane.showMessageDialog(
1328                Gaze.this,
1329                msg+allListsStr,
1330                "Gazetteer List Save All",
1331                JOptionPane.PLAIN_MESSAGE);
1332
1333              reinitializeGazetteer();
1334        }
1335    }//gaz list save all action listener
1336
1337  /** Listener for right click on the Linear Definition list */
1338  class LinearPopupListener extends MouseAdapter {
1339    public void mouseClicked(MouseEvent e) {
1340      if(SwingUtilities.isRightMouseButton(e)){
1341        /* invoke popup*/
1342        linearPopup.show(linearList,e.getX(),e.getY());
1343      } // if right button
1344    } // mouse clicked
1345  } // class LinearPopupListener
1346
1347  /**Listener for the Edit action of the LinearDefinition popup*/
1348  class LinearPopupEditListener implements ActionListener{
1349    public void actionPerformed(ActionEvent e) {
1350      LinearNode lnode =
1351        (LinearNode) linearList.getSelectedValue();
1352
1353      Vector lists = new Vector(listSet);
1354      Vector majors = new Vector(linear.getMajors());
1355      Vector minors = new Vector(linear.getMinors());
1356      Vector languages = new Vector(linear.getLanguages());
1357
1358      Collections.sort(lists);
1359      Collections.sort(majors);
1360      Collections.sort(minors);
1361      Collections.sort(languages);
1362
1363      LinearNodeInput dialog =
1364        new LinearNodeInput(
1365          LDA_EDIT,
1366          linearList.getSelectedIndex(),
1367          lists,
1368          majors,
1369          minors,
1370          languages,
1371          lnode.getList(),
1372          lnode.getMajorType(),
1373          lnode.getMinorType(),
1374          lnode.getLanguage());
1375      dialog.setTitle("Edit Linear Node");
1376      dialog.setLocationRelativeTo(linearLabel);
1377      dialog.setResizable(false);
1378      dialog.setVisible(true);
1379    } // actionPerformed
1380  } // class LinearPopupEditListener
1381
1382  /**Listener for the Insert action of the LinearDefinition popup*/
1383  class LinearPopupInsertListener implements ActionListener{
1384    public void actionPerformed(ActionEvent e) {
1385
1386      Vector lists = new Vector(listSet);
1387      Vector majors = new Vector(linear.getMajors());
1388      Vector minors = new Vector(linear.getMinors());
1389      Vector languages = new Vector(linear.getLanguages());
1390
1391      Collections.sort(lists);
1392      Collections.sort(majors);
1393      Collections.sort(minors);
1394      Collections.sort(languages);
1395
1396      LinearNodeInput dialog =
1397        new LinearNodeInput(
1398          LDA_INSERT,
1399          linearList.getSelectedIndex(),
1400          lists,
1401          majors,
1402          minors,
1403          languages);
1404
1405      dialog.setTitle("Insert Linear Node");
1406      dialog.setLocationRelativeTo(linearLabel);
1407      dialog.setResizable(false);
1408      dialog.setVisible(true);
1409    } // actionPerformed
1410  } // class LinearPopupInsertListener
1411
1412  /**Listener for the Remove action of the LinearDefinition popup*/
1413  class LinearPopupRemoveListener implements ActionListener{
1414    public void actionPerformed(ActionEvent e) {
1415      int [] indices = linearList.getSelectedIndices();
1416      for ( int i = (indices.length-1) ; i > -1 ; i-- ){
1417        linear.remove(indices[i]);
1418      } // for
1419      linearList.setListData(linear.toArray());
1420    }
1421  } // class LinearPopupRemoveListener
1422
1423  /**A dialog for input of a LinearNode. */
1424  class LinearNodeInput extends JDialog {
1425    /** the action that has been performed */
1426    private int action = -1;
1427    /** the position at which the action has been performed */
1428    private int position = -1;
1429
1430    protected JPanel jPanel1 = new JPanel();
1431    protected JLabel jLabel1 = new JLabel();
1432    protected JComboBox listCombo = new JComboBox();
1433    protected JLabel jLabel2 = new JLabel();
1434    protected JComboBox majorCombo = new JComboBox();
1435    protected JLabel jLabel3 = new JLabel();
1436    protected JComboBox minorCombo = new JComboBox();
1437    protected JLabel jLabel4 = new JLabel();
1438    protected JComboBox languagesCombo = new JComboBox();
1439    protected JLabel jLabel5 = new JLabel();
1440    protected JLabel jLabel6 = new JLabel();
1441    protected GridBagLayout gridBagLayout1 = new GridBagLayout();
1442    protected JButton btnOk = new JButton();
1443    protected JButton btnCancel = new JButton();
1444
1445    /** default constructor
1446     * @param anAction one of a set of predefined actions
1447     * @param pos the position/index where the action occured
1448     *   */
1449    public LinearNodeInput(int anAction, int pos) {
1450      try {
1451        action = anAction;
1452        position = pos;
1453        jbInit();
1454      }
1455      catch(Exception e) {
1456        e.printStackTrace();
1457      }
1458    } // default constructor
1459
1460    /** Construct with providing the combobox lists
1461     * @param anAction one of a set of predefined actions
1462     * @param pos the position/index where the action occured
1463     * @param lists the lists to be loaded in the lists combo box
1464     * @param majors the major types to be loaded in the major type combo box
1465     * @param minors the minor types to be loaded in the minor type combo box
1466     * @param languages the languages to be loaded in the languages combo box*/
1467    public LinearNodeInput(int anAction,int pos,Vector lists, Vector majors,
1468                            Vector minors, Vector languages)
1469    {
1470      try {
1471        action = anAction;
1472        position = pos;
1473        if (null!=lists)
1474          listCombo = new JComboBox(lists);
1475
1476        if (null!=majors)
1477          majorCombo = new JComboBox(majors);
1478
1479        if (null!=minors)
1480          minorCombo = new JComboBox(minors);
1481
1482        if (null!=languages)
1483          languagesCombo = new JComboBox(languages);
1484
1485        jbInit();
1486      }
1487      catch(Exception e) {
1488        e.printStackTrace();
1489      }
1490    } // constructor with combo lists
1491
1492    /** Construct with providing the combobox lists and the current values of the members
1493     * @param anAction one of a set of predefined actions
1494     * @param pos the position/index where the action occured
1495     * @param lists the lists to be loaded in the lists combo box
1496     * @param majors the major types to be loaded in the major type combo box
1497     * @param minors the minor types to be loaded in the minor type combo box
1498     * @param languagesList the languages to be loaded in the languages combo box
1499     */
1500    public LinearNodeInput(int anAction,int pos,
1501                    Vector lists, Vector majors, Vector minors,
1502                    Vector languagesList,
1503                    String list,String major, String minor, String languages)
1504    {
1505      try {
1506        action = anAction;
1507        position = pos;
1508        if (null!=lists)
1509          listCombo = new JComboBox(lists);
1510
1511        if (null!=majors)
1512          majorCombo = new JComboBox(majors);
1513
1514        if (null!=minors)
1515          minorCombo = new JComboBox(minors);
1516
1517        if (null!=languagesList)
1518          languagesCombo = new JComboBox(languagesList);
1519
1520        if (null!=list)
1521          listCombo.setSelectedItem(list);
1522
1523
1524        if (null!=major)
1525          majorCombo.setSelectedItem(major);
1526
1527        if (null!=minor)
1528          minorCombo.setSelectedItem(minor);
1529        else
1530          minorCombo.setSelectedItem("");
1531
1532        if (null!=languages)
1533          languagesCombo.setSelectedItem(languages);
1534        else
1535          languagesCombo.setSelectedItem("");
1536
1537        jbInit();
1538      }
1539      catch(Exception e) {
1540        e.printStackTrace();
1541      }
1542    } // constructor with combo lists
1543
1544    private void jbInit() throws Exception {
1545      jLabel1.setAlignmentX((float) 0.5);
1546      jLabel1.setAlignmentY((float) 0.0);
1547      jLabel1.setText("Gazetteer List*");
1548      jPanel1.setLayout(gridBagLayout1);
1549      jLabel2.setText("Major Type*");
1550      jLabel3.setText("Minor Type");
1551      jLabel4.setText("Languages (comma-separated)");
1552      jLabel5.setText("Select, enter or alter the members of the Linear Node");
1553      jLabel6.setToolTipText("");
1554      jLabel6.setText("The members marked with \"*\" are mandatory.");
1555      btnOk.setText("OK");
1556      btnCancel.setText("Cancel");
1557      listCombo.setEditable(true);
1558      majorCombo.setEditable(true);
1559      minorCombo.setEditable(true);
1560      languagesCombo.setEditable(true);
1561      this.getContentPane().add(jPanel1,  BorderLayout.CENTER);
1562      jPanel1.add(jLabel5,           new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
1563              ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 10, 10, 0), 22, 0));
1564      jPanel1.add(jLabel1,       new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
1565              ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 20, 0, 0), 0, 0));
1566      jPanel1.add(listCombo,         new GridBagConstraints(0, 2, 2, 1, 1.0, 0.0
1567              ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 60), 0, 0));
1568      jPanel1.add(jLabel2,      new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0
1569              ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 20, 0, 0), 0, 0));
1570      jPanel1.add(majorCombo,      new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0
1571              ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 60), 0, 0));
1572      jPanel1.add(jLabel3,      new GridBagConstraints(0, 5, 2, 1, 0.0, 0.0
1573              ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 20, 0, 60), 0, 0));
1574      jPanel1.add(minorCombo,      new GridBagConstraints(0, 6, 2, 1, 1.0, 0.0
1575              ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 60), 0, 0));
1576      jPanel1.add(jLabel4,       new GridBagConstraints(0, 7, 2, 1, 0.0, 0.0
1577              ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 20, 0, 0), 0, 0));
1578      jPanel1.add(languagesCombo,      new GridBagConstraints(0, 8, 2, 1, 1.0, 0.0
1579              ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 0, 60), 0, 0));
1580      jPanel1.add(jLabel6,        new GridBagConstraints(0, 9, 2, 1, 0.0, 0.0
1581              ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 10, 15, 0), 0, 0));
1582      jPanel1.add(btnOk,          new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0
1583              ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 150, 0, 0), 0, 0));
1584      jPanel1.add(btnCancel,         new GridBagConstraints(1, 10, 1, 1, 0.0, 0.0
1585              ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 50), 0, 0));
1586
1587      this.setSize(new Dimension(338, 318));
1588
1589      createListeners();
1590    }
1591
1592    /** Create the Action Listeners for the dialog*/
1593    private void createListeners() {
1594        btnOk.addActionListener( new ActionListener() {
1595          public void actionPerformed(ActionEvent e) {
1596            LinearNode ln = new LinearNode(
1597                (String)listCombo.getSelectedItem(),
1598                (String)majorCombo.getSelectedItem(),
1599                (String)minorCombo.getSelectedItem(),
1600                (String)languagesCombo.getSelectedItem()
1601              );
1602            if ((0 == ln.getList().trim().length())
1603              ||
1604              (0 == ln.getMajorType().trim().length())) {
1605              JOptionPane.showMessageDialog(Gaze.this,
1606              "This is not a valid Linear Node.\n"+
1607              "List and Major Type are mandatory\n"+
1608              "List : "+ln.getList()+
1609              "\nMajor Type : "+ln.getMajorType(),
1610              "Invalid Linear Node",JOptionPane.ERROR_MESSAGE );
1611            } else {
1612              performLinearAction(action,position,ln);
1613            }
1614            dispose();
1615          }
1616        });
1617
1618        btnCancel.addActionListener( new ActionListener() {
1619          public void actionPerformed(ActionEvent e) {
1620            dispose();   }  });
1621
1622          addKeyListener(new KeyListener(){
1623
1624          public void keyTyped(KeyEvent kev){}
1625
1626          public void keyReleased(KeyEvent kev) {
1627            if (kev.VK_ENTER == kev.getKeyCode()) {
1628              LinearNode ln = new LinearNode(
1629                  (String)listCombo.getSelectedItem(),
1630                  (String)majorCombo.getSelectedItem(),
1631                  (String)minorCombo.getSelectedItem(),
1632                  (String)languagesCombo.getSelectedItem()
1633                );
1634              performLinearAction(action,position,ln);
1635              dispose();
1636            } // if enter
1637            else {
1638              if (kev.VK_ESCAPE == kev.getKeyCode()) {
1639                dispose();
1640              } // if escape
1641            } // else
1642          } // keyReleased()
1643
1644          public void keyPressed(KeyEvent kev) {}
1645
1646        }); // add esc enter key listener
1647
1648    } // createListeners()
1649
1650  }// class LinearNodeInput
1651
1652
1653  /** Reacts on all Create New Mapping actions performed either
1654   *  through the menu, either through the new buton. */
1655  class MappingNewListener implements ActionListener {
1656        public void actionPerformed(ActionEvent e) {
1657          JFileChooser chooser = MainFrame.getFileChooser();
1658          chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1659
1660          int result = chooser.showDialog(Gaze.this, "New");
1661          if ( result == JFileChooser.APPROVE_OPTION ) {
1662            File selected = chooser.getSelectedFile();
1663            try {
1664              if (!selected.createNewFile()){
1665                JOptionPane.showMessageDialog(
1666                  Gaze.this,
1667                  "Cannot Create Mapping Definition.\n"+
1668                  selected.getAbsolutePath(),
1669                  "Mapping Definition Create Failure",
1670                  JOptionPane.ERROR_MESSAGE
1671                );
1672              } // if
1673              URL lurl = new URL("file:///"+selected.getAbsolutePath());
1674              mapping = new MappingDefinition();
1675              mapping.setURL(lurl);
1676              mapping.load();
1677
1678              // remove the old tree from the scroll pane
1679              if (null != oTree)
1680                ontologyScroll.getViewport().remove(oTree);
1681
1682              oTree = new JTree();
1683              ontologyScroll.getViewport().add(oTree);
1684              oTree.setVisible(false);
1685              oTree.updateUI();
1686
1687              // set the list data with the nodes of the gaz
1688              mappingList.setListData(mapping.toArray());
1689
1690
1691            } catch (ResourceInstantiationException x) {
1692              JOptionPane.showMessageDialog(Gaze.this,
1693                "Unable to load Mapping Definition (corrupted format).\n"
1694                +"file:///"+selected.getAbsolutePath()+"\n"
1695                +"Due to:\nResourceInstantiationException:"+x.getMessage()
1696                ,"Mapping Definition Load Failure",
1697                JOptionPane.ERROR_MESSAGE);
1698            } catch (Exception x) {
1699              JOptionPane.showMessageDialog(Gaze.this,
1700                "Unable to load linear definition (corrupted format).\n"
1701                +"file:///"+selected.getAbsolutePath()+"\n"
1702                +"Due to:\n"+x.getClass()+":"+x.getMessage()
1703                ,"Linear Definition Load Failure",
1704                JOptionPane.ERROR_MESSAGE);
1705            }
1706          } // approve
1707        } // actionPerformed(ActionEvent)
1708    } // class MappingNewListener
1709
1710
1711  /** Reacts on all Load Mapping actions performed either
1712   *  through the menu, wither through the load buton. */
1713  class MappingLoadListener implements ActionListener {
1714        public void actionPerformed(ActionEvent e) {
1715          JFileChooser chooser = MainFrame.getFileChooser();
1716          chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1717
1718          int result = chooser.showOpenDialog(Gaze.this);
1719          if ( result == JFileChooser.APPROVE_OPTION ) {
1720            File selected = chooser.getSelectedFile();
1721            try {
1722              URL lurl = new URL("file:///"+selected.getAbsolutePath());
1723              mapping = new MappingDefinition();
1724              mapping.setURL(lurl);
1725              mapping.load();
1726
1727              // set the list data with the nodes of the gaz
1728              mappingList.setListData(mapping.toArray());
1729
1730              reinitializeGazetteer();
1731            } catch (ResourceInstantiationException x) {
1732              JOptionPane.showMessageDialog(Gaze.this,
1733                "Unable to load Mapping Definition (corrupted format).\n"
1734                +"file:///"+selected.getAbsolutePath()+"\n"
1735                +"Due to:\nResourceInstantiationException:"+x.getMessage()
1736                ,"Mapping Definition Load Failure",
1737                JOptionPane.ERROR_MESSAGE);
1738            } catch (Exception x) {
1739              JOptionPane.showMessageDialog(Gaze.this,
1740                "Unable to load linear definition (corrupted format).\n"
1741                +"file:///"+selected.getAbsolutePath()+"\n"
1742                +"Due to:\n"+x.getClass()+":"+x.getMessage()
1743                ,"Linear Definition Load Failure",
1744                JOptionPane.ERROR_MESSAGE);
1745            }
1746          } // approve
1747        } // actionPerformed(ActionEvent)
1748    } // class MappingLoadListener
1749
1750    /** Reacts on all Save As Mapping Definition actions. */
1751    class MappingSaveAsListener implements ActionListener {
1752        public void actionPerformed(ActionEvent e) {
1753          if ( null == mapping ) {
1754            JOptionPane.showMessageDialog(
1755              Gaze.this,"The Mapping Definition is null and cannot be saved.",
1756              "Mapping Definition Save As Failure.",JOptionPane.ERROR_MESSAGE);
1757          } else {
1758            JFileChooser chooser = MainFrame.getFileChooser();
1759            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1760
1761            int result = chooser.showSaveDialog(Gaze.this);
1762            if ( result == JFileChooser.APPROVE_OPTION ) {
1763              File selected = chooser.getSelectedFile();
1764              URL lurl;
1765              try {
1766                lurl = new URL("file:///"+selected.getAbsolutePath());
1767                mapping.setURL(lurl);
1768                mapping.store();
1769                JOptionPane.showMessageDialog(
1770                  Gaze.this,
1771                  "Mapping Definition saved sucessfuly.\n"
1772                  +lurl,
1773                  "Mapping Definition Save As",
1774                  JOptionPane.PLAIN_MESSAGE);
1775
1776                  reinitializeGazetteer();
1777
1778              } catch (MalformedURLException x) {
1779                JOptionPane.showMessageDialog(Gaze.this,"Cannot save Mapping Definition.\n"
1780                  +"Due to "+x.getClass()+":"+x.getMessage(),
1781                  "Mapping Definition Save As Failure",JOptionPane.ERROR_MESSAGE);
1782              } catch (ResourceInstantiationException x) {
1783                JOptionPane.showMessageDialog(
1784                  Gaze.this,
1785                  "Unable to save the Mapping Defintion.\n"
1786                  +"Due to : "+x.getClass()+":"+x.getMessage(),
1787                  "Mapping Definition Save Failure.",
1788                  JOptionPane.ERROR_MESSAGE);
1789              } // catch
1790            } // approved
1791          } // else
1792        }
1793    }// class MappingSaveListener
1794
1795  /** Reacts on all Mapping Definition Save As events */
1796  class MappingSaveListener implements ActionListener {
1797    public void actionPerformed(ActionEvent e) {
1798      if ( null == mapping ) {
1799        JOptionPane.showMessageDialog(
1800          Gaze.this,"The Mapping Definition is null and cannot be saved.",
1801          "Mapping Definition Save failure.",JOptionPane.ERROR_MESSAGE);
1802      } else {
1803
1804        try {
1805          mapping.store();
1806          JOptionPane.showMessageDialog(
1807            Gaze.this,
1808            "Mapping Definition saved sucessfuly.",
1809            "Mapping Definition Save",
1810            JOptionPane.PLAIN_MESSAGE);
1811          reinitializeGazetteer();
1812        } catch (ResourceInstantiationException x) {
1813          JOptionPane.showMessageDialog(
1814            Gaze.this,
1815            "Unable to save the Mapping Definition.\n"
1816            +"Due to : "+x.getClass()+":"+x.getMessage(),
1817            "Mapping Definition Save failure.",
1818            JOptionPane.ERROR_MESSAGE);
1819        } // catch
1820      } // else
1821    } // actionPerformed(ActionEvent)
1822  } // class MappingSaveListener
1823
1824  /** Reacts on all Load Ontology actions performed either
1825   *  through the menu, wither through the load buton. */
1826  class OntologyLoadListener implements ActionListener {
1827        public void actionPerformed(ActionEvent e) {
1828          JFileChooser chooser = MainFrame.getFileChooser();
1829          chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1830
1831          int result = chooser.showOpenDialog(Gaze.this);
1832          if ( result == JFileChooser.APPROVE_OPTION ) {
1833            File selected = chooser.getSelectedFile();
1834            try {
1835              URL ourl = new URL("file:///"+selected.getAbsolutePath());
1836              try {
1837                ontology = new OntologyImpl().getOntology(ourl);
1838                if(ontology instanceof TaxonomyImpl)
1839                  ((TaxonomyImpl)ontology).
1840                  addObjectModificationListener(Gaze.this);
1841              } catch (ResourceInstantiationException x) {
1842                x.printStackTrace(Err.getPrintWriter());
1843              }
1844              if (null == ontology)
1845                throw new GateRuntimeException("can not Load ontology by url.\n"
1846                  +"ontology is null.\n"
1847                  +"url = "+ourl);
1848
1849              // remove the old tree from the scroll pane
1850              if (null != oTree)
1851                ontologyScroll.getViewport().remove(oTree);
1852
1853              // check if there is already a tree for this ontology
1854              oTree = (JTree) ontologyTrees.get(ontology);
1855
1856              if (null == oTree) {
1857                Map namesVsNodes = new HashMap();
1858                ClassNode root = ClassNode.createRootNode(ontology,mapping,namesVsNodes);
1859                OntoTreeModel model = new OntoTreeModel(root);
1860                MappingTreeView view = new MappingTreeView(model,mapping,Gaze.this);
1861                oTree = view;
1862                ontologyTrees.put(ontology,oTree);
1863              } // ontology tree has not been previously creted
1864
1865              ontologyScroll.getViewport().add(oTree,null);
1866              oTree.setVisible(true);
1867
1868
1869            } catch (Exception x) {
1870              JOptionPane.showMessageDialog(Gaze.this,
1871                "Unable to load Ontology.\n"
1872                +"file:///"+selected.getAbsolutePath()+"\n"
1873                +"Due to:\n"+x.getClass()+":"+x.getMessage()
1874                ,"Ontology Load Failure",
1875                JOptionPane.ERROR_MESSAGE);
1876            }
1877          } // approve
1878        } // actionPerformed(ActionEvent)
1879    } // class OntologyLoadListener
1880
1881} // class Gaze