Gaze.java
0001 /* Gaze.java
0002  * borislav popov
0003  */
0004 package com.ontotext.gate.vr;
0005 
0006 import javax.swing.*;
0007 import javax.swing.event.*;
0008 import javax.swing.tree.TreeModel;
0009 import javax.swing.tree.TreePath;
0010 
0011 import gate.creole.*;
0012 import gate.creole.gazetteer.*;
0013 import gate.creole.ontology.*;
0014 import gate.util.*;
0015 import gate.event.GateEvent;
0016 import gate.gui.MainFrame;
0017 import java.awt.*;
0018 import java.awt.event.*;
0019 import java.util.*;
0020 import java.net.*;
0021 import java.io.*;
0022 
0023 /** Gaze is a Gazetteer VR capable of viewing and editing
0024  *  gazetteer lists, linear definitions (lists.def files),
0025  *  and mapping definitions (mappings between ontology classes and gazetteer lists).
0026  *  I.e. capable of visualizing and editing both linear and ontology-aware gazetteers. */
0027 public class Gaze extends AbstractVisualResource
0028   implements GazetteerListener, OntologyModificationListener {
0029 
0030   /** size x when running from the tools menu */
0031   public final static int SIZE_X = 700;
0032   /** size y when running from the tools menu */
0033   public final static int SIZE_Y = 500;
0034   /** positin x when running from the tools menu */
0035   public final static int POSITION_X = 300;
0036   /** positin y when running from the tools menu */
0037   public final static int POSITION_Y = 200;
0038 
0039   /* Linear Definition Actions */
0040   /** Edit Linear Node */
0041   private final static int LDA_EDIT = 1;
0042   /** Insert Linear Node */
0043   private final static int LDA_INSERT = 2;
0044   /** Remove Linear Node */
0045   private final static int LDA_REMOVE = 3;
0046 
0047   /** the target to be displayed */
0048   private Gazetteer target = null;
0049 
0050   /** is the target resource ontology-aware gazetteer */
0051   private boolean isOntoGaz = false;
0052 
0053   /** the linear definition being displayed */
0054   private LinearDefinition linear = null;
0055 
0056   /** the linear node currently selected */
0057   private LinearNode linearNode = null;
0058 
0059   /** the gazetteer list currently selected */
0060   private GazetteerList gazList = null;
0061 
0062   /** Set of all lists, both in the linear definition and
0063    *  explicitly loaded ones.*/
0064   private Set listSet = null;
0065 
0066   /** the mapping definition being displayed */
0067   private MappingDefinition mapping = null;
0068 
0069   /** the mapping node currently selected */
0070   private MappingNode mappingNode = null;
0071 
0072   /** the ontology that is currently displayed */
0073   private Ontology ontology = null;
0074 
0075   /** map of ontologies vs trees */
0076   private Map<Ontology, JTree> ontologyTrees = new HashMap<Ontology, JTree>();
0077 
0078   /*manually added gui components */
0079 
0080   /**Linear Definition Popup menu */
0081   protected JPopupMenu linearPopup = new JPopupMenu();
0082   /**Linear Definition Edit Popup Item*/
0083   protected JMenuItem linearPopupEdit;
0084   /**Linear Definition Insert Popup Item*/
0085   protected JMenuItem linearPopupInsert;
0086   /**Linear Definition Remove Popup Item*/
0087   protected JMenuItem linearPopupRemove;
0088 
0089   /*automatically added gui components */
0090   protected JMenuBar mainMenu = new JMenuBar();
0091   protected JMenu fileMenu = new JMenu();
0092   protected JMenu viewMenu = new JMenu();
0093   protected JSplitPane baseSplit = new JSplitPane();
0094   protected JSplitPane mappingSplit = new JSplitPane();
0095   protected JSplitPane linearSplit = new JSplitPane();
0096   protected JPanel linearPanel = new JPanel();
0097   protected JPanel listPanel = new JPanel();
0098   protected JPanel mappingPanel = new JPanel();
0099   protected JPanel ontologyPanel = new JPanel();
0100   protected JLabel linearLabel = new JLabel();
0101   protected GridBagLayout gridBagLayout1 = new GridBagLayout();
0102   protected JScrollPane linearScroll = new JScrollPane();
0103   protected JToolBar linearBar = new JToolBar();
0104   protected JButton btnLinearLoad = new JButton();
0105   protected JList linearList = new JList();
0106   protected JButton btnLinearSave = new JButton();
0107   protected JButton btnLinearSaveAs = new JButton();
0108   protected JLabel listLabel = new JLabel();
0109   protected GridBagLayout gridBagLayout2 = new GridBagLayout();
0110   protected JToolBar listBar = new JToolBar();
0111   protected JButton btnListLoad = new JButton();
0112   protected JScrollPane listScroll = new JScrollPane();
0113   protected JButton btnListSave = new JButton();
0114   protected JButton btnListSaveAs = new JButton();
0115   protected GridBagLayout gridBagLayout3 = new GridBagLayout();
0116   protected JLabel mappingLabel = new JLabel();
0117   protected JToolBar mappingBar = new JToolBar();
0118   protected JButton btnMappingLoad = new JButton();
0119   protected JScrollPane mappingScroll = new JScrollPane();
0120   protected JList mappingList = new JList();
0121   protected JButton btnMappingSave = new JButton();
0122   protected JButton btnMappingSaveAs = new JButton();
0123   protected JLabel ontologyLabel = new JLabel();
0124   protected JToolBar ontologyBar = new JToolBar();
0125   protected JButton btnOntologyLoad = new JButton();
0126   protected JScrollPane ontologyScroll = new JScrollPane();
0127   protected GridBagLayout gridBagLayout4 = new GridBagLayout();
0128   protected JMenu menuHelp = new JMenu();
0129   protected JMenuItem menuAbout = new JMenuItem();
0130   protected GridBagLayout thisLayout = new GridBagLayout();
0131   protected JMenu menuLinear = new JMenu();
0132   protected JMenuItem menuLinearLoad = new JMenuItem();
0133   protected JMenuItem menuLinearSave = new JMenuItem();
0134   protected JMenuItem menuLinearSaveAs = new JMenuItem();
0135   protected JMenu menuList = new JMenu();
0136   protected JMenuItem menuListLoad = new JMenuItem();
0137   protected JMenuItem menuListSave = new JMenuItem();
0138   protected JMenuItem menuListSaveAs = new JMenuItem();
0139   protected JMenu menuMapping = new JMenu();
0140   protected JMenuItem menuMappingLoad = new JMenuItem();
0141   protected JMenuItem menuMappingSave = new JMenuItem();
0142   protected JMenuItem menuMappingSaveAs = new JMenuItem();
0143   protected JMenu menuOntology = new JMenu();
0144   protected JMenuItem menuOntologyLoad = new JMenuItem();
0145   protected JMenuItem menuRefresh = new JMenuItem();
0146   protected JTree oTree = new JTree();
0147   protected JTextArea listArea = new JTextArea();
0148   protected JButton btnMappingNew = new JButton();
0149   protected JButton btnLinearNew = new JButton();
0150   protected JButton btnListNew = new JButton();
0151   protected JMenuItem menuLinearNew = new JMenuItem();
0152   protected JMenuItem menuListNew = new JMenuItem();
0153   protected JMenuItem menuMappingNew = new JMenuItem();
0154   protected JButton btnListSaveAll = new JButton();
0155   protected JMenuItem menuListSaveAll = new JMenuItem();
0156 
0157 
0158   public Gaze() {
0159     try {
0160 
0161       jbInit();
0162       /* add menu bar*/
0163       mainMenu.setMinimumSize(new Dimension(0,20));
0164       mainMenu.setMaximumSize(new Dimension(0,20));
0165       mainMenu.setPreferredSize(new Dimension(0,20));
0166       this.add(mainMenu,   new GridBagConstraints(00111.00.0
0167             ,GridBagConstraints.CENTER,
0168             GridBagConstraints.HORIZONTAL, new Insets(0000)0));
0169 
0170       /* make the ontology tree invisible because not initialized yet*/
0171       oTree.setVisible(false);
0172 
0173       /* create and associate linear listeners... */
0174       createLinearListeneres();
0175 
0176       /*...and non linear (mapping, ontology) listeners */
0177       createNonLinearListeners();
0178 
0179       /* associate the load,save,saveas buttons with action */
0180       createLinearDefBtnListeners();
0181       createGazListBtnListeners();
0182       createMappingDefBtnListeners();
0183 
0184       /* create a new cell renderer for the linear definition list */
0185       linearList.setCellRenderer(new LinearCR());
0186 
0187       /* add modifications listener over the gazetteer list text area */
0188       listArea.getDocument().addDocumentListener(new GazListDL());
0189 
0190       /* create Linear Definition Popup menu */
0191       linearPopupEdit = new JMenuItem("edit");
0192       linearPopupInsert = new JMenuItem("insert");
0193       linearPopupRemove = new JMenuItem("remove");
0194 
0195       linearPopup.add(linearPopupEdit);
0196       linearPopup.add(linearPopupInsert);
0197       linearPopup.add(linearPopupRemove);
0198 
0199       /* add popup listener */
0200       linearList.addMouseListener(new LinearPopupListener());
0201 
0202 
0203       /* add popup menu items' listeners*/
0204       linearPopupEdit.addActionListener(new LinearPopupEditListener());
0205       linearPopupRemove.addActionListener(new LinearPopupRemoveListener());
0206       linearPopupInsert.addActionListener(new LinearPopupInsertListener());
0207     catch(Exception e) {
0208       e.printStackTrace(gate.util.Err.getPrintWriter());
0209     }
0210   }
0211 
0212   /**
0213    * Called by the GUI when this viewer/editor has to initialise itself for a
0214    * specific object. this is an {@link gate.creole.AbstractVisualResource} overriden method.
0215    @param targeta the object (be it a {@link gate.Resource},
0216    {@link gate.DataStore} or whatever) this viewer has to display
0217    */
0218   public void setTarget(Object targeta) {
0219 
0220     /*check the parameter*/
0221     if (null == targeta) {
0222       throw new GateRuntimeException("should not set null target.");
0223     }
0224     if ((targeta instanceof Gazetteer) ) {
0225       throw new GateRuntimeException(
0226         "the target should impelement \n"+
0227         "gate.creole.gazetteer.Gazetteer. \n"+
0228         "target => "+targeta.getClass());
0229     }
0230 
0231     target = (Gazetteer)targeta;
0232 
0233     target.addGazetteerListener(this);
0234 
0235     /** determine the type of the target */
0236     isOntoGaz = (target instanceof OntoGazetteer);
0237 
0238     /**disable the ontology and mapping areas */
0239     if (!isOntoGaz) {
0240       mappingSplit.setVisible(false);
0241       mappingList.setEnabled(false);
0242     }
0243 
0244     /* display linear definition */
0245     displayLinear(target);
0246 
0247     /* display mapping */
0248     if (isOntoGaz)
0249       displayMapping(target);
0250 
0251   // setTarget(Object)
0252 
0253 
0254   public gate.Resource init() throws ResourceInstantiationException {
0255     return this;
0256   }
0257 
0258   /** updates the mapping list's ui */
0259   void updateMappingUI(){
0260     if null!=mappingList ) {
0261       mappingList.setListData(mapping.toArray());
0262       mappingList.updateUI();
0263     }
0264   // updateMappingUI()
0265 
0266   /** Displays the specified list in the most right pane of Gaze
0267    @param listName the name of the list
0268    */
0269   void displayList(String listName) {
0270     // find the gazetteer list by list name
0271     Object node = linear.getNodesByListNames().get(listName);
0272     GazetteerList newList = null;
0273     if node != null )  {
0274       newList = (GazetteerList)linear.getListsByNode().get(node);
0275       if null != newList ){
0276 
0277         //retrieve the possible editions of the gazetteer
0278         if (null!=listArea && null!=gazList) {
0279           gazList.setMode(gazList.STRING_MODE);
0280           boolean mdfd = gazList.isModified();
0281           gazList.updateContent(listArea.getText());
0282           gazList.setModified(mdfd);
0283         }
0284 
0285         //show the newly selected list
0286         gazList = newList;
0287         if null!= gazList) {
0288           gazList.setMode(gazList.STRING_MODE);
0289           boolean mdfd = gazList.isModified();
0290           listArea.setText(gazList.toString());
0291           gazList.setModified(mdfd);
0292         else {
0293           listArea.setText("");
0294         }
0295       }  // != null
0296     // != null
0297 
0298   // displayList(String)
0299 
0300   /**Gets the lists
0301    @return a list of all the gaz lists known to this VR*/
0302   java.util.List getLists() {
0303     return linear.getLists();
0304   }
0305 
0306   /**Gets all classes.
0307    @return a list of all the classes from all the ontologies known to this VR*/
0308   java.util.List getClasses() {
0309     java.util.List<OClass> result = null;
0310     if null == ontology)
0311       result = new ArrayList<OClass>();
0312     else {
0313       result = new ArrayList<OClass>(ontology.getOClasses(false));
0314     }
0315     return result;
0316   }
0317 
0318 
0319 
0320   /** Displays linear definition
0321    *  @param g the gazetteer to take the definition from */
0322   private void displayLinear(Gazetteer g) {
0323     // get the linear definition
0324     linear = g.getLinearDefinition();
0325     // check the linear definition
0326     if (null == linear)
0327       throw new GateRuntimeException(
0328         "linear definition of a gazetteer should not be null.");
0329 
0330     listSet = new HashSet(linear.getLists());
0331 
0332     if (null == listSet)
0333       throw new GateRuntimeException(
0334         "The set of Gazetteer Lists should not be null.");
0335 
0336     // set the list data with the nodes of the gaz
0337     linearList.setListData(new Vector(linear.getNodes()));
0338   // displayLinear()
0339 
0340   /** Displays mapping
0341    *  @param g the gazetteer to take the mapping from */
0342   private void displayMapping(Gazetteer g) {
0343     mapping = g.getMappingDefinition();
0344     if (null == mapping)
0345       throw new GateRuntimeException(
0346         "the mapping definition of an onto gazetteer should not be null");
0347     mappingList.setListData(mapping.toArray());
0348 
0349     /*Add all lists present in the mapping to the set of loaded lists*/
0350     listSet.addAll(mapping.getLists());
0351 
0352   }// displayMapping()
0353 
0354   /**Creates and associates listeners for the linear gui components*/
0355   private void createLinearListeneres() {
0356 
0357     /* add list selection listener to the linear definition list component*/
0358     linearList.addListSelectionListener(
0359       new ListSelectionListener () {
0360         public void valueChanged(ListSelectionEvent e) {
0361           if (linearList.getAnchorSelectionIndex() < linearList.getModel().getSize()) {
0362             Object obj = linearList.getModel().getElementAt(
0363               linearList.getAnchorSelectionIndex());
0364             if obj instanceof LinearNode ) {
0365               linearNode = (LinearNodeobj;
0366 
0367               //retrieve the possible editions of the gazetteer
0368               if (null!=listArea && null!=gazList) {
0369                 gazList.setMode(gazList.STRING_MODE);
0370                 boolean mdfd = gazList.isModified();
0371                 gazList.updateContent(listArea.getText());
0372                 gazList.setModified(mdfd);
0373               }
0374 
0375               //show the newly selected list
0376               gazList = (GazetteerList)linear.getListsByNode().get(linearNode);
0377               if null!= gazList) {
0378                 gazList.setMode(gazList.STRING_MODE);
0379                 boolean mdfd = gazList.isModified();
0380                 listArea.setText(gazList.toString());
0381                 gazList.setModified(mdfd);
0382               else {
0383                 listArea.setText("");
0384               }
0385 
0386 
0387             // only if linear node
0388           // size > 0
0389         // valueChanged();
0390       } );
0391 
0392   // createLinearListeneres()
0393 
0394   /**Creates and asssociates listeners for the
0395    * non linear (mapping,ontology) gui components   */
0396   private void createNonLinearListeners() {
0397 
0398     /* add list selection listener to the mapping definition list component*/
0399     mappingList.addListSelectionListener(
0400       new ListSelectionListener () {
0401         public void valueChanged(ListSelectionEvent e) {
0402           if (< mappingList.getModel().getSize()) {
0403             Object obj = mappingList.getModel().getElementAt(
0404               mappingList.getAnchorSelectionIndex());
0405             if obj instanceof MappingNode ) {
0406               mappingNode = (MappingNodeobj;
0407               URL ourl;
0408               try {
0409                 ourl = new URL(mappingNode.getOntologyID());
0410               catch  (MalformedURLException x) {
0411                 throw new GateRuntimeException("Malformed URL:"
0412                   +mappingNode.getOntologyID());
0413               }
0414               // get te ontology
0415               try {
0416                 ontology = OntologyUtilities.getOntology(ourl);
0417                 ontology.addOntologyModificationListener(Gaze.this);
0418               catch (ResourceInstantiationException x) {
0419                 x.printStackTrace(Err.getPrintWriter());
0420               }
0421               if (null == ontology)
0422                 throw new GateRuntimeException("can not retrieve ontology by url.\n"
0423                   +"ontology is null.\n"
0424                   +"url = "+ourl);
0425 
0426               // remove the old tree from the scroll pane
0427               if (null != oTree)
0428                 ontologyScroll.getViewport().remove(oTree);
0429 
0430               // check if there is already a tree for this ontology
0431               oTree = (JTreeontologyTrees.get(ontology);
0432 
0433               if (null == oTree) {
0434                 Map namesVsNodes = new HashMap();
0435                 ClassNode root = ClassNode.createRootNode(ontology,mapping,namesVsNodes);
0436                 OntoTreeModel model = new OntoTreeModel(root);
0437                 MappingTreeView view = new MappingTreeView(model,mapping,Gaze.this);
0438                 oTree = view;
0439                 ontologyTrees.put(ontology,oTree);
0440               // ontology tree has not been previously creted
0441 
0442               ontologyScroll.getViewport().add(oTree,null);
0443               oTree.setVisible(true);
0444 
0445               displayList(mappingNode.getList());
0446             // only if mapping node
0447           // size > 0
0448         // valueChanged();
0449       } );
0450 
0451   // createNonLinearListeners()
0452 
0453 
0454   /**Sets the listeners for the load,save and save as
0455    * buttons in the linear definition pane */
0456   private void createLinearDefBtnListeners() {
0457     /* add a create/new action listener */
0458     btnLinearNew.addActionListener(new LinearNewListener());
0459     menuLinearNew.addActionListener(new LinearNewListener());
0460 
0461     /* add load action listener for the linear definition */
0462     btnLinearLoad.addActionListener(new LinearLoadListener());
0463     menuLinearLoad.addActionListener(new LinearLoadListener());
0464 
0465     /* add save as action listener for the linear definition */
0466     btnLinearSaveAs.addActionListener(new LinearSaveAsListener());
0467     menuLinearSaveAs.addActionListener(new LinearSaveAsListener());
0468 
0469 
0470     /* add save action listener for the linear definition */
0471     btnLinearSave.addActionListener(new LinearSaveListener());
0472     menuLinearSave.addActionListener(new LinearSaveListener());
0473 
0474   // createLinearDefBtnListeners()
0475 
0476   /**Sets the listeners for the load,save and save as
0477    * buttons in the gazetteer list pane */
0478   private void createGazListBtnListeners() {
0479 
0480     /* add new action listener */
0481     btnListNew.addActionListener(new ListNewListener());
0482     menuListNew.addActionListener(new ListNewListener());
0483 
0484     /* add load action listener */
0485     btnListLoad.addActionListener(new ListLoadListener());
0486     menuListLoad.addActionListener(new ListLoadListener());
0487 
0488     /* add save as action listener */
0489     btnListSaveAs.addActionListener(new ListSaveAsListener());
0490     menuListSaveAs.addActionListener(new ListSaveAsListener());
0491 
0492     /* add save action listener */
0493     btnListSave.addActionListener(new ListSaveListener());
0494     menuListSave.addActionListener(new ListSaveListener());
0495 
0496     /* add save all action listener */
0497     btnListSaveAll.addActionListener(new ListSaveAllListener());
0498     menuListSaveAll.addActionListener(new ListSaveAllListener());
0499   // createGazListBtnListeners()
0500 
0501   /**Sets the listeners for the load,save and save as
0502    * buttons in the mapping pane */
0503   private void createMappingDefBtnListeners() {
0504 
0505     /* add create new action listener */
0506     btnMappingNew.addActionListener(new MappingNewListener());
0507     menuMappingNew.addActionListener(new MappingNewListener());
0508 
0509     /* add load action listener */
0510     btnMappingLoad.addActionListener(new MappingLoadListener());
0511     menuMappingLoad.addActionListener(new MappingLoadListener());
0512 
0513     /* add save as action listen*/
0514     btnMappingSaveAs.addActionListener(new MappingSaveAsListener());
0515     menuMappingSaveAs.addActionListener(new MappingSaveAsListener());
0516 
0517 
0518     /* add save action listener */
0519     btnMappingSave.addActionListener(new MappingSaveListener());
0520     menuMappingSave.addActionListener(new MappingSaveListener());
0521 
0522     /* add load ontology action listener*/
0523     btnOntologyLoad.addActionListener(new OntologyLoadListener());
0524     menuOntologyLoad.addActionListener(new OntologyLoadListener());
0525 
0526   // createLinearDefBtnListeners()
0527 
0528   /**
0529    * Performs an action over the Linear Definition.
0530    * e.g. edit,insert,remove Linear Node.
0531    @param action the action to be performed
0532    @param index index of the place where this action took place(e.g. where to insert)
0533    @param node the Linear Node to be used in the action
0534    */
0535   private void performLinearAction(int action, int index, LinearNode node ) {
0536     switch (action) {
0537       case LDA_EDIT : {
0538         Object bkp = linear.get(index);
0539         linear.remove(index);
0540         int size = linear.size();
0541         linear.add(index,node);
0542         if (size == linear.size()) {
0543           JOptionPane.showMessageDialog(
0544             this,
0545             "The Linear Node can not be added to the Linear Definition \n"
0546             +"because a node with such a list already exists,\n"+
0547             "cannot be opened, or cannot be created if non-existant.\n"
0548             +"node : "+node,
0549             "Edit Linear Node Failure",
0550             JOptionPane.ERROR_MESSAGE);
0551           //rollback
0552           linear.add(index,bkp);
0553         }// if
0554 
0555         break;
0556       }
0557       case LDA_INSERT : {
0558         int size = linear.size();
0559         if (index < index = 0;
0560         linear.add(index,node);
0561         if (size == linear.size()) {
0562           JOptionPane.showMessageDialog(
0563             this,
0564             "The Linear Node can not be added to the Linear Definition \n"
0565             +"because a node with such a list already exists,\n"+
0566             "cannot be opened, or cannot be created if non-existant.\n"
0567             +"node : "+node,
0568             "Insert Linear Node Failure",
0569             JOptionPane.ERROR_MESSAGE);
0570         }// if
0571         break;
0572       }
0573       case LDA_REMOVE : {
0574         linear.remove(index);
0575         break;
0576       }
0577     // switch action
0578     linearList.setListData(linear.toArray());
0579   // performLinearAction(int,LinearNode)
0580 
0581   /** Reinitializes the edited gazetteer */
0582   private void reinitializeGazetteer() {
0583     try {
0584       target.setListsURL(linear.getURL());
0585       if (isOntoGaz) {
0586         ((OntoGazetteer)target).setMappingURL(mapping.getURL());
0587         gate.Factory.deleteResource(((OntoGazetteer)target).getGazetteer());
0588       // if onto gaz
0589       target = (Gazetteer)target.init();
0590       JOptionPane.showMessageDialog(this,
0591           "Gazetteer Reinitialized.",
0592           "Reinitialize Gazetteer",
0593           JOptionPane.INFORMATION_MESSAGE);
0594     catch(ResourceInstantiationException x) {
0595       JOptionPane.showMessageDialog(this,
0596         "Gazetteer can not be reinitialized.\n"+
0597         "due to:"+x.getClass()+" "+x.getMessage(),
0598         "Gazsetteer Reinitialize Failure.",JOptionPane.ERROR_MESSAGE);
0599     }
0600   // reinitializeGazetteer()
0601 
0602   /** Init of the gui components */
0603   private void jbInit() throws Exception {
0604     fileMenu.setToolTipText("");
0605     fileMenu.setText("File");
0606     viewMenu.setText("View");
0607     this.setPreferredSize(new Dimension(600300));
0608     this.setLayout(thisLayout);
0609     baseSplit.setPreferredSize(new Dimension(700450));
0610     mappingSplit.setOrientation(JSplitPane.VERTICAL_SPLIT);
0611     mappingSplit.setToolTipText("");
0612     linearSplit.setContinuousLayout(true);
0613     linearLabel.setAlignmentY((float0.0);
0614     linearLabel.setToolTipText("");
0615     linearLabel.setHorizontalAlignment(SwingConstants.CENTER);
0616     linearLabel.setText("Linear Definition");
0617     linearPanel.setLayout(gridBagLayout1);
0618     linearScroll.setPreferredSize(new Dimension(10050));
0619     btnLinearLoad.setBorder(BorderFactory.createEtchedBorder());
0620     btnLinearLoad.setToolTipText("Load a linear definition");
0621     btnLinearLoad.setFocusPainted(false);
0622     btnLinearLoad.setMargin(new Insets(2222));
0623     btnLinearLoad.setText("Load");
0624     btnLinearSave.setBorder(BorderFactory.createEtchedBorder());
0625     btnLinearSave.setToolTipText("Save the linear definition");
0626     btnLinearSave.setFocusPainted(false);
0627     btnLinearSave.setMargin(new Insets(2222));
0628     btnLinearSave.setText("Save");
0629     btnLinearSaveAs.setBorder(BorderFactory.createEtchedBorder());
0630     btnLinearSaveAs.setToolTipText("Save the linear definition changing the location");
0631     btnLinearSaveAs.setFocusPainted(false);
0632     btnLinearSaveAs.setMargin(new Insets(2020));
0633     btnLinearSaveAs.setText("Save as...");
0634     listLabel.setAlignmentY((float0.0);
0635     listLabel.setHorizontalAlignment(SwingConstants.CENTER);
0636     listLabel.setText("Gazetteer List");
0637     listPanel.setLayout(gridBagLayout2);
0638     btnListLoad.setBorder(BorderFactory.createEtchedBorder());
0639     btnListLoad.setToolTipText("Load a gazetteer list");
0640     btnListLoad.setFocusPainted(false);
0641     btnListLoad.setMargin(new Insets(2020));
0642     btnListLoad.setText("Load");
0643     listScroll.setAlignmentX((float0.0);
0644     listScroll.setAlignmentY((float0.0);
0645     btnListSave.setBorder(BorderFactory.createEtchedBorder());
0646     btnListSave.setToolTipText("Save the gazetteer list");
0647     btnListSave.setFocusPainted(false);
0648     btnListSave.setMargin(new Insets(2020));
0649     btnListSave.setText("Save");
0650     btnListSaveAs.setBorder(BorderFactory.createEtchedBorder());
0651     btnListSaveAs.setToolTipText("Save the gazetteer list to different location");
0652     btnListSaveAs.setFocusPainted(false);
0653     btnListSaveAs.setMargin(new Insets(2020));
0654     btnListSaveAs.setText("Save as...");
0655     listBar.setFloatable(false);
0656     mappingPanel.setLayout(gridBagLayout3);
0657     mappingLabel.setHorizontalAlignment(SwingConstants.CENTER);
0658     mappingLabel.setText("Mapping Definition");
0659     btnMappingLoad.setBorder(BorderFactory.createEtchedBorder());
0660     btnMappingLoad.setToolTipText("Load a mapping definition");
0661     btnMappingLoad.setFocusPainted(false);
0662     btnMappingLoad.setMargin(new Insets(2020));
0663     btnMappingLoad.setText("Load");
0664     btnMappingSave.setBorder(BorderFactory.createEtchedBorder());
0665     btnMappingSave.setToolTipText("Save mapping definition");
0666     btnMappingSave.setFocusPainted(false);
0667     btnMappingSave.setMargin(new Insets(2020));
0668     btnMappingSave.setText("Save");
0669     btnMappingSaveAs.setBorder(BorderFactory.createEtchedBorder());
0670     btnMappingSaveAs.setToolTipText("Save mapping definition to another location");
0671     btnMappingSaveAs.setFocusPainted(false);
0672     btnMappingSaveAs.setMargin(new Insets(2020));
0673     btnMappingSaveAs.setText("Save As...");
0674     ontologyLabel.setHorizontalAlignment(SwingConstants.CENTER);
0675     ontologyLabel.setText("Ontology");
0676     btnOntologyLoad.setBorder(BorderFactory.createEtchedBorder());
0677     btnOntologyLoad.setToolTipText("Load an ontology");
0678     btnOntologyLoad.setFocusPainted(false);
0679     btnOntologyLoad.setMargin(new Insets(2222));
0680     btnOntologyLoad.setText("Load");
0681     ontologyPanel.setLayout(gridBagLayout4);
0682     mappingBar.setFloatable(false);
0683     ontologyBar.setFloatable(false);
0684     linearBar.setFloatable(false);
0685     menuHelp.setText("Help");
0686     menuAbout.setText("About");
0687     menuLinear.setText("Linear Definition");
0688     menuLinearLoad.setText("Load");
0689     menuLinearSave.setText("Save");
0690     menuLinearSaveAs.setText("Save as");
0691     menuList.setText("Gazetteer List");
0692     menuListLoad.setText("Load");
0693     menuListSave.setText("Save");
0694     menuListSaveAs.setText("Save as");
0695     menuMapping.setText("Mapping Definition");
0696     menuMappingLoad.setText("Load");
0697     menuMappingSave.setText("Save");
0698     menuMappingSaveAs.setText("Save as");
0699     menuOntology.setText("Ontology");
0700     menuOntologyLoad.setText("Load");
0701     menuRefresh.setText("Refresh");
0702     mainMenu.setBorder(BorderFactory.createEtchedBorder());
0703     oTree.setToolTipText("");
0704     btnMappingNew.setText("New");
0705     btnMappingNew.setMargin(new Insets(2020));
0706     btnMappingNew.setFocusPainted(false);
0707     btnMappingNew.setToolTipText("Create a New Mapping Definition");
0708     btnMappingNew.setBorder(BorderFactory.createEtchedBorder());
0709     btnLinearNew.setText("New");
0710     btnLinearNew.setMargin(new Insets(2222));
0711     btnLinearNew.setFocusPainted(false);
0712     btnLinearNew.setToolTipText("Create a New Linear Definition");
0713     btnLinearNew.setBorder(BorderFactory.createEtchedBorder());
0714     btnListNew.setText("New");
0715     btnListNew.setMargin(new Insets(2020));
0716     btnListNew.setFocusPainted(false);
0717     btnListNew.setToolTipText("Create a New Gazetteer List");
0718     btnListNew.setBorder(BorderFactory.createEtchedBorder());
0719     menuLinearNew.setText("New");
0720     menuListNew.setText("New");
0721     menuMappingNew.setText("New");
0722     btnListSaveAll.setText("Save All");
0723     btnListSaveAll.setMargin(new Insets(2020));
0724     btnListSaveAll.setFocusPainted(false);
0725     btnListSaveAll.setToolTipText("Save all modified gazetteer lists ");
0726     btnListSaveAll.setBorder(BorderFactory.createEtchedBorder());
0727     menuListSaveAll.setToolTipText("Save All Modified Gazetteer Lists");
0728     menuListSaveAll.setText("Save All");
0729     listBar.add(btnListNew, null);
0730     linearBar.add(btnLinearNew, null);
0731     mainMenu.add(fileMenu);
0732     mainMenu.add(viewMenu);
0733     mainMenu.add(menuHelp);
0734     this.add(baseSplit,   new GridBagConstraints(01111.01.0
0735             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)4864));
0736     baseSplit.add(mappingSplit, JSplitPane.LEFT);
0737     baseSplit.add(linearSplit, JSplitPane.RIGHT);
0738     linearSplit.add(linearPanel, JSplitPane.TOP);
0739     linearSplit.add(listPanel, JSplitPane.BOTTOM);
0740     listPanel.add(listLabel,                           new GridBagConstraints(00111.00.0
0741             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0742     mappingSplit.add(mappingPanel, JSplitPane.BOTTOM);
0743     mappingSplit.add(ontologyPanel, JSplitPane.TOP);
0744     ontologyPanel.add(ontologyLabel,    new GridBagConstraints(00111.00.0
0745             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0746     ontologyPanel.add(ontologyBar,   new GridBagConstraints(01111.00.0
0747             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0748     ontologyPanel.add(ontologyScroll,   new GridBagConstraints(02111.01.0
0749             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0750     ontologyScroll.getViewport().add(oTree, null);
0751     ontologyBar.add(btnOntologyLoad, null);
0752     linearPanel.add(linearBar,      new GridBagConstraints(01111.00.0
0753             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0754     linearBar.add(btnLinearLoad, null);
0755     linearBar.add(btnLinearSave, null);
0756     linearBar.add(btnLinearSaveAs, null);
0757     linearPanel.add(linearScroll,       new GridBagConstraints(02, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.01.0
0758             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0759     linearScroll.getViewport().add(linearList, null);
0760     linearPanel.add(linearLabel, new GridBagConstraints(00111.00.0
0761             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0762     listPanel.add(listBar,         new GridBagConstraints(01111.00.0
0763             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0764     listPanel.add(listScroll,       new GridBagConstraints(02, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.01.0
0765             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0766     listScroll.getViewport().add(listArea, null);
0767     listBar.add(btnListLoad, null);
0768     listBar.add(btnListSave, null);
0769     listBar.add(btnListSaveAs, null);
0770     listBar.add(btnListSaveAll, null);
0771     mappingPanel.add(mappingLabel,  new GridBagConstraints(00111.00.0
0772             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0773     mappingPanel.add(mappingBar,   new GridBagConstraints(01111.00.0
0774             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0775     mappingPanel.add(mappingScroll,  new GridBagConstraints(02111.01.0
0776             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0000)00));
0777     mappingScroll.getViewport().add(mappingList, null);
0778     mappingBar.add(btnMappingNew, null);
0779     mappingBar.add(btnMappingLoad, null);
0780     mappingBar.add(btnMappingSave, null);
0781     mappingBar.add(btnMappingSaveAs, null);
0782     menuHelp.add(menuAbout);
0783     fileMenu.add(menuLinear);
0784     fileMenu.add(menuList);
0785     fileMenu.addSeparator();
0786     fileMenu.add(menuMapping);
0787     fileMenu.add(menuOntology);
0788     menuLinear.add(menuLinearNew);
0789     menuLinear.add(menuLinearLoad);
0790     menuLinear.add(menuLinearSave);
0791     menuLinear.add(menuLinearSaveAs);
0792     menuList.add(menuListNew);
0793     menuList.add(menuListLoad);
0794     menuList.add(menuListSave);
0795     menuList.add(menuListSaveAs);
0796     menuList.add(menuListSaveAll);
0797     menuMapping.add(menuMappingNew);
0798     menuMapping.add(menuMappingLoad);
0799     menuMapping.add(menuMappingSave);
0800     menuMapping.add(menuMappingSaveAs);
0801     menuOntology.add(menuOntologyLoad);
0802     viewMenu.add(menuRefresh);
0803     mappingSplit.setDividerLocation(200);
0804     linearSplit.setDividerLocation(230);
0805     baseSplit.setDividerLocation(300);
0806   // jbInit()
0807 
0808 /*---------implementation of GazetteerListener interface--------------*/
0809   public void processGazetteerEvent(GazetteerEvent e) {
0810     if e.REINIT == e.getType() ) {
0811       displayLinear((Gazetteer)e.getSource());
0812       if (isOntoGaz) {
0813         displayMapping((Gazetteer)e.getSource());
0814         ontologyTrees = new HashMap();
0815         oTree.setVisible(false);
0816       }
0817     // reinit
0818   // processGazetteerEvent(GazetteerEvent)
0819 /*---------implementation of GazetteerListener interface--------------*/
0820 
0821 /*->->->---implementation of OntologyModificationListener interface--------------*/
0822   public void processGateEvent(GateEvent e) {
0823   }
0824 
0825   public void resourceAdded(Ontology ontology, OResource resource) {
0826     ontologyModified(ontology, null, -1);
0827   }
0828   
0829   public void resourcesRemoved(Ontology ontology, String[] resourcesURIs) {
0830     ontologyModified(ontology, null, -1);
0831   }
0832   
0833   public void ontologyReset(Ontology ontology) {
0834       ontologyModified(ontology, null, -1);
0835   }
0836   
0837   public void resourceRelationChanged(Ontology ontology, OResource resource1, OResource resouce2, int eventType) {
0838     this.ontologyModified(ontology, resource1, eventType);
0839   }
0840   
0841   public void resourcePropertyValueChanged(Ontology ontology, OResource resource, RDFProperty property, Object value, int eventType) {
0842     this.ontologyModified(ontology, resource, eventType);
0843   }
0844   
0845   public void ontologyModified(Ontology ontology, OResource resource, int eventType) {
0846       JTree tree = ontologyTrees.get(ontology);
0847       if (tree!=null) {
0848         ontologyTrees.remove(ontology);
0849         Map<String, ClassNode> namesVsNodes = new HashMap<String, ClassNode>();
0850         ClassNode root = ClassNode.createRootNode(ontology,mapping,namesVsNodes);
0851         OntoTreeModel model = new OntoTreeModel(root);
0852         MappingTreeView view = new MappingTreeView(model,mapping,Gaze.this);
0853 
0854         /* synchronize the expansion of the old and new trees */
0855         synchronizeTreeExpansion(tree,view);
0856 
0857         if (ontology.equals(ontology)) {
0858           oTree = view;
0859           ontologyScroll.getViewport().add(oTree,null);
0860           oTree.setVisible(true);
0861         }
0862         ontologyTrees.put(ontology,oTree);
0863       }
0864   }
0865 
0866   /**
0867    * Synchronizes the expansion of the given trees.
0868    @param orig the original tree
0869    @param mirror the tree to mimic the expansion of the original
0870    */
0871   public static void synchronizeTreeExpansion(JTree orig, JTree mirror) {
0872     /*create a Set of expanded node names*/
0873     /*below will :
0874       iterate all nodes of the tree
0875       accumulate the path for each node as an arraylist
0876       check for each passed node whether the treepath is expanded
0877       and if expanded add it to the expanded list as a string.
0878     */
0879     Set expanded = new HashSet();
0880     TreeModel model =  orig.getModel();
0881 
0882     ArrayList remains = new ArrayList();
0883     ArrayList remainPaths = new ArrayList();
0884 
0885     remains.add(model.getRoot());
0886     ArrayList rootPath = new ArrayList();
0887     rootPath.add(model.getRoot());
0888     remainPaths.add(rootPath);
0889 
0890     while (remains.size() ) {
0891       Object node = remains.get(0);
0892       int cc = model.getChildCount(node);
0893       ArrayList parentPath = (ArrayList)remainPaths.get(0);
0894       for int c = ; c < cc ; c++) {
0895         Object child = model.getChild(node,c);
0896         remains.add(child);
0897         ArrayList pp = new ArrayList(parentPath);
0898         pp.add(child);
0899         remainPaths.add(pp);
0900       }
0901       TreePath tp = new TreePath(parentPath.toArray());
0902       if (orig.isExpanded(tp)) {
0903         expanded.add(node.toString());
0904       }
0905       remains.remove(0);
0906       remainPaths.remove(0);
0907     }
0908 
0909     /*expand the mirror tree according to the expanded nodes set*/
0910     /*
0911       iterate all the nodes and keep their paths
0912       if a node is found as a string then expand it
0913     */
0914 
0915     remains = new ArrayList();
0916     remainPaths = new ArrayList();
0917 
0918     model = mirror.getModel();
0919     remains.add(model.getRoot());
0920     rootPath = new ArrayList();
0921     rootPath.add(model.getRoot());
0922     remainPaths.add(rootPath);
0923 
0924     while (remains.size() ) {
0925       Object node = remains.get(0);
0926       int cc = model.getChildCount(node);
0927       ArrayList parentPath = (ArrayList)remainPaths.get(0);
0928       for int c = ; c < cc ; c++) {
0929         Object child = model.getChild(node,c);
0930         remains.add(child);
0931         ArrayList pp = new ArrayList(parentPath);
0932         pp.add(child);
0933         remainPaths.add(pp);
0934       }
0935 
0936       if (expanded.contains(node.toString()) ) {
0937         TreePath tp = new TreePath(parentPath.toArray());
0938         mirror.expandPath(tp);
0939       }
0940       remains.remove(0);
0941       remainPaths.remove(0);
0942     // while nodes remain
0943 
0944   // synchronizeTreeExpansion(JTree,JTree)
0945   
0946   
0947 /*-<-<-<---implementation of OntologyModificationListener interface--------------*/
0948 
0949 
0950   /* --- inner classes ----*/
0951 
0952   /** Creates a list cell renderer for the
0953    *  Linear Definition list. It should make
0954    *  distinct the modifed gazetteer lists and still
0955    *  look like the default one.*/
0956   class LinearCR extends DefaultListCellRenderer {
0957 
0958     private static final long serialVersionUID = 3690752878255943737L;
0959 
0960     public LinearCR() {
0961       super();
0962     }
0963 
0964     public Component getListCellRendererComponent(
0965       JList list,
0966       Object value,
0967       int index,
0968       boolean isSelected,
0969       boolean cellHasFocus)
0970     {
0971       super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
0972       GazetteerList gl = (GazetteerList)linear.getListsByNode().get(value);
0973       if null!= gl && gl.isModified()) {
0974         setBackground(list.getBackground());
0975         setForeground(Color.red);
0976       // is modified
0977       return this;
0978     }// getListCellRendererComponent()
0979   // class linearCR
0980 
0981   /** Gazetteer List Document Listener is used to monitor the
0982    * gaz list changes and alter the isModified flag of the current list.*/
0983   class GazListDL implements DocumentListener {
0984 
0985     public void changedUpdate(DocumentEvent ev) {
0986         gazList.setModified(true);
0987       }
0988 
0989       public void insertUpdate(DocumentEvent ev) {
0990         gazList.setModified(true);
0991       }
0992 
0993       public void removeUpdate(DocumentEvent ev) {
0994         gazList.setModified(true);
0995       }
0996   // class GazListDL
0997 
0998   /** Reacts on all New Linear Definition actions performed either
0999    *  through the menu, wither through the new buton. */
1000   class LinearNewListener implements ActionListener {
1001         public void actionPerformed(ActionEvent e) {
1002           JFileChooser chooser = MainFrame.getFileChooser();
1003           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1004 
1005           int result = chooser.showDialog(Gaze.this, "New");
1006           if result == JFileChooser.APPROVE_OPTION ) {
1007             File selected = chooser.getSelectedFile();
1008             try {
1009               if (!selected.createNewFile()){
1010                 JOptionPane.showMessageDialog(
1011                   Gaze.this,
1012                   "Cannot Create Linear Definition\n"+
1013                   selected.getAbsolutePath(),
1014                   "Linear Definition Create Failure",
1015                   JOptionPane.ERROR_MESSAGE
1016                 );
1017               // if
1018               URL lurl = new URL("file:///"+selected.getAbsolutePath());
1019               linear = new LinearDefinition();
1020               linear.setURL(lurl);
1021               linear.setEncoding(target.getEncoding());
1022               linear.load();
1023 
1024               // get the new list set
1025               listSet = new HashSet(linear.getLists());
1026 
1027               if (null == listSet)
1028                 throw new GateRuntimeException(
1029                   "The set of Gazetteer Lists should not be null.");
1030 
1031               // set the list data with the nodes of the gaz
1032               linearList.setListData(new Vector(linear.getNodes()));
1033 
1034 
1035               JOptionPane.showMessageDialog(
1036                 Gaze.this,
1037                 "New Linear Definition created successfully \n"+
1038                 selected.getAbsolutePath(),
1039                 "Create New Linear Definition Successful",
1040                 JOptionPane.INFORMATION_MESSAGE
1041               );
1042 
1043             catch (ResourceInstantiationException x) {
1044               JOptionPane.showMessageDialog(Gaze.this,
1045                 "Unable to load linear definition (corrupted format).\n"
1046                 +"file:///"+selected.getAbsolutePath()+"\n"
1047                 +"Due to:\nResourceInstantiationException:"+x.getMessage()
1048                 ,"Linear Definition Load Failure",
1049                 JOptionPane.ERROR_MESSAGE);
1050             catch (Exception x) {
1051               JOptionPane.showMessageDialog(Gaze.this,
1052                 "Unable to load linear definition (corrupted format).\n"
1053                 +"file:///"+selected.getAbsolutePath()+"\n"
1054                 +"Due to:\n"+x.getClass()+":"+x.getMessage()
1055                 ,"Linear Definition Load Failure",
1056                 JOptionPane.ERROR_MESSAGE);
1057             }
1058           // approve
1059         // actionPerformed(ActionEvent)
1060     // class LinearLoadListener
1061 
1062   /** Reacts on all Load Linear Definition actions performed either
1063    *  through the menu, wither through the load buton. */
1064   class LinearLoadListener implements ActionListener {
1065         public void actionPerformed(ActionEvent e) {
1066           JFileChooser chooser = MainFrame.getFileChooser();
1067           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1068 
1069           int result = chooser.showOpenDialog(Gaze.this);
1070           if result == JFileChooser.APPROVE_OPTION ) {
1071             File selected = chooser.getSelectedFile();
1072             try {
1073               URL lurl = new URL("file:///"+selected.getAbsolutePath());
1074               linear = new LinearDefinition();
1075               linear.setURL(lurl);
1076               linear.setEncoding(target.getEncoding());
1077               linear.load();
1078 
1079               // get the new list set
1080               listSet = new HashSet(linear.getLists());
1081 
1082               if (null == listSet)
1083                 throw new GateRuntimeException(
1084                   "The set of Gazetteer Lists should not be null.");
1085 
1086               // set the list data with the nodes of the gaz
1087               linearList.setListData(new Vector(linear.getNodes()));
1088 
1089 
1090               reinitializeGazetteer();
1091             catch (ResourceInstantiationException x) {
1092               JOptionPane.showMessageDialog(Gaze.this,
1093                 "Unable to load linear definition (corrupted format).\n"
1094                 +"file:///"+selected.getAbsolutePath()+"\n"
1095                 +"Due to:\nResourceInstantiationException:"+x.getMessage()
1096                 ,"Linear Definition Load Failure",
1097                 JOptionPane.ERROR_MESSAGE);
1098             catch (Exception x) {
1099               JOptionPane.showMessageDialog(Gaze.this,
1100                 "Unable to load linear definition (corrupted format).\n"
1101                 +"file:///"+selected.getAbsolutePath()+"\n"
1102                 +"Due to:\n"+x.getClass()+":"+x.getMessage()
1103                 ,"Linear Definition Load Failure",
1104                 JOptionPane.ERROR_MESSAGE);
1105             }
1106           // approve
1107         // actionPerformed(ActionEvent)
1108     // class LinearLoadListener
1109 
1110     /** Reacts on all Save As Linear Definition actions. */
1111     class LinearSaveAsListener implements ActionListener {
1112         public void actionPerformed(ActionEvent e) {
1113           if null == linear ) {
1114             JOptionPane.showMessageDialog(
1115               Gaze.this,"The linear definition is null and cannot be saved.",
1116               "Linear Definition Save As Failure.",JOptionPane.ERROR_MESSAGE);
1117           else {
1118             JFileChooser chooser = MainFrame.getFileChooser();
1119             chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1120 
1121             int result = chooser.showSaveDialog(Gaze.this);
1122             if result == JFileChooser.APPROVE_OPTION ) {
1123               File selected = chooser.getSelectedFile();
1124               URL lurl;
1125               try {
1126                 lurl = new URL("file:///"+selected.getAbsolutePath());
1127                 linear.setURL(lurl);
1128                 linear.store();
1129                 JOptionPane.showMessageDialog(
1130                   Gaze.this,
1131                   "Linear Definition saved sucessfuly.\n"
1132                   +lurl,
1133                   "Linear Definition Save As",
1134                   JOptionPane.PLAIN_MESSAGE);
1135                 reinitializeGazetteer();
1136               catch (MalformedURLException x) {
1137                 JOptionPane.showMessageDialog(Gaze.this,"Cannot save linear definition.\n"
1138                   +"Due to "+x.getClass()+":"+x.getMessage(),
1139                   "Linear Definition Save As failure",JOptionPane.ERROR_MESSAGE);
1140               catch (ResourceInstantiationException x) {
1141                 JOptionPane.showMessageDialog(
1142                   Gaze.this,
1143                   "Unable to save the linear defintion.\n"
1144                   +"Due to : "+x.getClass()+":"+x.getMessage(),
1145                   "Linear Definition Save failure.",
1146                   JOptionPane.ERROR_MESSAGE);
1147               // catch
1148             // approved
1149           // else
1150         }
1151     }// class LinearSaveListener
1152 
1153   /** Reacts on all Linear Definition  Save As events */
1154   class LinearSaveListener implements ActionListener {
1155     public void actionPerformed(ActionEvent e) {
1156       if null == linear ) {
1157         JOptionPane.showMessageDialog(
1158           Gaze.this,"The Linear Definition is null and cannot be saved.",
1159           "Linear Definition Save failure.",JOptionPane.ERROR_MESSAGE);
1160       else {
1161 
1162         try {
1163           linear.store();
1164           JOptionPane.showMessageDialog(
1165             Gaze.this,
1166             "Linear Definition saved sucessfuly.\n"+
1167             linear.getURL(),
1168             "Linear Definition Save",
1169             JOptionPane.PLAIN_MESSAGE);
1170 
1171           reinitializeGazetteer();
1172 
1173         catch (ResourceInstantiationException x) {
1174           JOptionPane.showMessageDialog(
1175             Gaze.this,
1176             "Unable to save the Linear Definition.\n"
1177             +"Due to : "+x.getClass()+":"+x.getMessage(),
1178             "Linear Definition Save failure.",
1179             JOptionPane.ERROR_MESSAGE);
1180         // catch
1181       // else
1182     // actionPerformed(ActionEvent)
1183   // class LinearSaveListener
1184 
1185   /**Reacts on all Create New Gaz List Events */
1186   class ListNewListener implements ActionListener {
1187         public void actionPerformed(ActionEvent e) {
1188           JFileChooser chooser = MainFrame.getFileChooser();
1189           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1190 
1191           int result = chooser.showDialog(Gaze.this, "New");
1192           if result == JFileChooser.APPROVE_OPTION ) {
1193             File selected = chooser.getSelectedFile();
1194             try {
1195               if (!selected.createNewFile()){
1196                 JOptionPane.showMessageDialog(
1197                   Gaze.this,
1198                   "Cannot Create Gazetteer List.\n"+
1199                   selected.getAbsolutePath(),
1200                   "Gazetteer List Create Failure",
1201                   JOptionPane.ERROR_MESSAGE
1202                 );
1203               // if
1204               URL lurl = new URL("file:///"+selected.getAbsolutePath());
1205               gazList = new GazetteerList();
1206               gazList.setURL(lurl);
1207               gazList.load();
1208               gazList.setMode(gazList.STRING_MODE);
1209               // set the list data with the nodes of the gaz
1210               listArea.setText(gazList.toString());
1211               gazList.setModified(false);
1212 
1213               String lName = gazList.getURL().getFile();
1214               int slash = lName.lastIndexOf('/');
1215               lName = lName.substring(slash+1);
1216               listSet.add(lName);
1217 
1218             catch (ResourceInstantiationException x) {
1219               JOptionPane.showMessageDialog(Gaze.this,
1220                 "Unable to load Gazetteer List (corrupted format).\n"
1221                 +"file:///"+selected.getAbsolutePath()+"\n"
1222                 +"Due to:\nResourceInstantiationException:"+x.getMessage()
1223                 ,"Gazetteer List Load Failure",
1224                 JOptionPane.ERROR_MESSAGE);
1225             catch (Exception x) {
1226               JOptionPane.showMessageDialog(Gaze.this,
1227                 "Unable to load Gazetteer List (corrupted format).\n"
1228                 +"file:///"+selected.getAbsolutePath()+"\n"
1229                 +"Due to:\n"+x.getClass()+":"+x.getMessage()
1230                 ,"Gazetteer List Load Failure",
1231                 JOptionPane.ERROR_MESSAGE);
1232             }
1233           // approve
1234         // actionPerformed(ActionEvent)
1235     // class ListNewListener
1236 
1237 
1238   /**Reacts on all Gaz List Load Events */
1239   class ListLoadListener implements ActionListener {
1240         public void actionPerformed(ActionEvent e) {
1241           JFileChooser chooser = MainFrame.getFileChooser();
1242           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1243 
1244           int result = chooser.showOpenDialog(Gaze.this);
1245           if result == JFileChooser.APPROVE_OPTION ) {
1246             File selected = chooser.getSelectedFile();
1247             try {
1248               URL lurl = new URL("file:///"+selected.getAbsolutePath());
1249               gazList = new GazetteerList();
1250               gazList.setURL(lurl);
1251               gazList.load();
1252               gazList.setMode(gazList.STRING_MODE);
1253 
1254               listArea.setText(gazList.toString());
1255 
1256               gazList.setModified(false);
1257 
1258               String lName = gazList.getURL().getFile();
1259               int slash = lName.lastIndexOf('/');
1260               lName = lName.substring(slash+1);
1261               listSet.add(lName);
1262 
1263             catch (ResourceInstantiationException x) {
1264               JOptionPane.showMessageDialog(Gaze.this,
1265                 "Unable to load Gazetteer List (corrupted format).\n"
1266                 +"file:///"+selected.getAbsolutePath()+"\n"
1267                 +"Due to:\nResourceInstantiationException:"+x.getMessage()
1268                 ,"Gazetteer List Load Failure",
1269                 JOptionPane.ERROR_MESSAGE);
1270             catch (Exception x) {
1271               JOptionPane.showMessageDialog(Gaze.this,
1272                 "Unable to load Gazetteer List (corrupted format).\n"
1273                 +"file:///"+selected.getAbsolutePath()+"\n"
1274                 +"Due to:\n"+x.getClass()+":"+x.getMessage()
1275                 ,"Gazetteer List Load Failure",
1276                 JOptionPane.ERROR_MESSAGE);
1277             }
1278           // approve
1279         // actionPerformed(ActionEvent)
1280     // class ListLoadListener
1281 
1282     /** Gazetteer list Save As action listener */
1283     class ListSaveAsListener implements ActionListener {
1284         public void actionPerformed(ActionEvent e) {
1285           if null == gazList ) {
1286             JOptionPane.showMessageDialog(
1287               Gaze.this,"The Gazetteer List is null and cannot be saved.",
1288               "Gazetteer List Save failure.",JOptionPane.ERROR_MESSAGE);
1289           else {
1290             JFileChooser chooser = MainFrame.getFileChooser();
1291             chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1292 
1293             int result = chooser.showSaveDialog(Gaze.this);
1294             if result == JFileChooser.APPROVE_OPTION ) {
1295               File selected = chooser.getSelectedFile();
1296               URL lurl;
1297               try {
1298                 lurl = new URL("file:///"+selected.getAbsolutePath());
1299                 gazList.setURL(lurl);
1300                 gazList.updateContent(listArea.getText());
1301                 gazList.setMode(gazList.LIST_MODE);
1302                 gazList.store();
1303                 JOptionPane.showMessageDialog(
1304                   Gaze.this,
1305                   "Gazetteer List saved sucessfuly.\n"
1306                   +lurl,
1307                   "Gazetteer List Save As",
1308                   JOptionPane.PLAIN_MESSAGE);
1309 
1310                 reinitializeGazetteer();
1311 
1312               catch (MalformedURLException x) {
1313                 JOptionPane.showMessageDialog(Gaze.this,"Cannot save Gazetteer List.\n"
1314                   +"Due to "+x.getClass()+":"+x.getMessage(),
1315                   "Gazetteer List Save As failure",JOptionPane.ERROR_MESSAGE);
1316               catch (ResourceInstantiationException x) {
1317                 JOptionPane.showMessageDialog(
1318                   Gaze.this,
1319                   "Unable to save the Gazetteer List.\n"
1320                   +"Due to : "+x.getClass()+":"+x.getMessage(),
1321                   "Gazetteer List save failure.",
1322                   JOptionPane.ERROR_MESSAGE);
1323               // catch
1324             // approved
1325           // else
1326         }
1327     }//class ListSaveAsListener
1328 
1329     /** Gaz List Save Action Listener */
1330     class ListSaveListener implements ActionListener {
1331         public void actionPerformed(ActionEvent e) {
1332           if null == gazList ) {
1333             JOptionPane.showMessageDialog(
1334               Gaze.this,"The Gazetteer List is null and cannot be saved.",
1335               "Gazetteer List Save failure.",JOptionPane.ERROR_MESSAGE);
1336           else {
1337 
1338             try {
1339               gazList.updateContent(listArea.getText());
1340               gazList.setMode(gazList.LIST_MODE);
1341               gazList.store();
1342               JOptionPane.showMessageDialog(
1343                 Gaze.this,
1344                 "Gazetteer List saved sucessfully.\n"
1345                 +gazList.getURL(),
1346                 "Gazetteer List Save",
1347                 JOptionPane.PLAIN_MESSAGE);
1348 
1349               reinitializeGazetteer();
1350 
1351             catch (ResourceInstantiationException x) {
1352               JOptionPane.showMessageDialog(
1353                 Gaze.this,
1354                 "Unable to save the Gazetteer List.\n"
1355                 +"Due to : "+x.getClass()+":"+x.getMessage(),
1356                 "Gazetteer List Save failure.",
1357                 JOptionPane.ERROR_MESSAGE);
1358             // catch
1359           // else
1360         }
1361     }//gaz list save action listener
1362 
1363     /** Gaz List Save All Action Listener */
1364     class ListSaveAllListener implements ActionListener {
1365         public void actionPerformed(ActionEvent e) {
1366               if (null!=gazList && null!=listArea) {
1367                 boolean mdf = gazList.isModified();
1368                 gazList.updateContent(listArea.getText());
1369                 gazList.setMode(gazList.LIST_MODE);
1370                 gazList.setModified(mdf);
1371               }
1372 
1373               GazetteerList gl = null ;
1374               StringBuffer allListsStr = new StringBuffer();
1375               boolean totalSuccess = true;
1376               boolean totalFailure = true;
1377               boolean anythingHappened = false;
1378 
1379               LinearNode node = null;
1380 
1381               for int i = ; i < linear.size() ; i++ ) {
1382                 node = (LinearNode)linear.get(i);
1383                 gl = (GazetteerList)linear.getListsByNode().get(node);
1384                 try {
1385                   if (gl.isModified()) {
1386                     anythingHappened = true;
1387                     gl.setMode(gl.LIST_MODE);
1388                     gl.store();
1389                     allListsStr.append("\nSAVED : "+
1390                       node.getList());
1391                     totalFailure = false;
1392                   }
1393                 catch (ResourceInstantiationException x ) {
1394                   allListsStr.append("\nFAILED : ");
1395                   allListsStr.append(node.getList());
1396                   totalSuccess = false;
1397                 }
1398               }//for
1399 
1400               String msg = null;
1401               if (!anythingHappened) {
1402                 msg = "There were no modified Gazetteer Lists to be saved.\n";
1403               else {
1404                 if (totalFailure) {
1405                   msg = "Not even one modified Gazetteer List was saved.\n";
1406                 else {
1407                   if (totalSuccess) {
1408                     msg = "All Modified Gazetteer Lists saved sucessfuly.\n";
1409                   else {
1410                     msg = "Some of the Modified Gazetteer Lists were saved sucessfuly.\n";
1411                   // else
1412                 // else
1413               //else
1414               JOptionPane.showMessageDialog(
1415                 Gaze.this,
1416                 msg+allListsStr,
1417                 "Gazetteer List Save All",
1418                 JOptionPane.PLAIN_MESSAGE);
1419 
1420               reinitializeGazetteer();
1421         }
1422     }//gaz list save all action listener
1423 
1424   /** Listener for right click on the Linear Definition list */
1425   class LinearPopupListener extends MouseAdapter {
1426     public void mouseClicked(MouseEvent e) {
1427       if(SwingUtilities.isRightMouseButton(e)){
1428         /* invoke popup*/
1429         linearPopup.show(linearList,e.getX(),e.getY());
1430       // if right button
1431     // mouse clicked
1432   // class LinearPopupListener
1433 
1434   /**Listener for the Edit action of the LinearDefinition popup*/
1435   class LinearPopupEditListener implements ActionListener{
1436     public void actionPerformed(ActionEvent e) {
1437       LinearNode lnode =
1438         (LinearNodelinearList.getSelectedValue();
1439 
1440       Vector lists = new Vector(listSet);
1441       Vector majors = new Vector(linear.getMajors());
1442       Vector minors = new Vector(linear.getMinors());
1443       Vector languages = new Vector(linear.getLanguages());
1444 
1445       Collections.sort(lists);
1446       Collections.sort(majors);
1447       Collections.sort(minors);
1448       Collections.sort(languages);
1449 
1450       LinearNodeInput dialog =
1451         new LinearNodeInput(
1452           LDA_EDIT,
1453           linearList.getSelectedIndex(),
1454           lists,
1455           majors,
1456           minors,
1457           languages,
1458           lnode.getList(),
1459           lnode.getMajorType(),
1460           lnode.getMinorType(),
1461           lnode.getLanguage());
1462       dialog.setTitle("Edit Linear Node");
1463       dialog.setLocationRelativeTo(linearLabel);
1464       dialog.setResizable(false);
1465       dialog.setVisible(true);
1466     // actionPerformed
1467   // class LinearPopupEditListener
1468 
1469   /**Listener for the Insert action of the LinearDefinition popup*/
1470   class LinearPopupInsertListener implements ActionListener{
1471     public void actionPerformed(ActionEvent e) {
1472 
1473       Vector lists = new Vector(listSet);
1474       Vector majors = new Vector(linear.getMajors());
1475       Vector minors = new Vector(linear.getMinors());
1476       Vector languages = new Vector(linear.getLanguages());
1477 
1478       Collections.sort(lists);
1479       Collections.sort(majors);
1480       Collections.sort(minors);
1481       Collections.sort(languages);
1482 
1483       LinearNodeInput dialog =
1484         new LinearNodeInput(
1485           LDA_INSERT,
1486           linearList.getSelectedIndex(),
1487           lists,
1488           majors,
1489           minors,
1490           languages);
1491 
1492       dialog.setTitle("Insert Linear Node");
1493       dialog.setLocationRelativeTo(linearLabel);
1494       dialog.setResizable(false);
1495       dialog.setVisible(true);
1496     // actionPerformed
1497   // class LinearPopupInsertListener
1498 
1499   /**Listener for the Remove action of the LinearDefinition popup*/
1500   class LinearPopupRemoveListener implements ActionListener{
1501     public void actionPerformed(ActionEvent e) {
1502       int [] indices = linearList.getSelectedIndices();
1503       for int i = (indices.length-1; i > -; i-- ){
1504         linear.remove(indices[i]);
1505       // for
1506       linearList.setListData(linear.toArray());
1507     }
1508   // class LinearPopupRemoveListener
1509 
1510   /**A dialog for input of a LinearNode. */
1511   class LinearNodeInput extends JDialog {
1512     /** the action that has been performed */
1513     private int action = -1;
1514     /** the position at which the action has been performed */
1515     private int position = -1;
1516 
1517     protected JPanel jPanel1 = new JPanel();
1518     protected JLabel jLabel1 = new JLabel();
1519     protected JComboBox listCombo = new JComboBox();
1520     protected JLabel jLabel2 = new JLabel();
1521     protected JComboBox majorCombo = new JComboBox();
1522     protected JLabel jLabel3 = new JLabel();
1523     protected JComboBox minorCombo = new JComboBox();
1524     protected JLabel jLabel4 = new JLabel();
1525     protected JComboBox languagesCombo = new JComboBox();
1526     protected JLabel jLabel5 = new JLabel();
1527     protected JLabel jLabel6 = new JLabel();
1528     protected GridBagLayout gridBagLayout1 = new GridBagLayout();
1529     protected JButton btnOk = new JButton();
1530     protected JButton btnCancel = new JButton();
1531 
1532     /** default constructor
1533      @param anAction one of a set of predefined actions
1534      @param pos the position/index where the action occured
1535      *   */
1536     public LinearNodeInput(int anAction, int pos) {
1537       try {
1538         action = anAction;
1539         position = pos;
1540         jbInit();
1541       }
1542       catch(Exception e) {
1543         e.printStackTrace();
1544       }
1545     // default constructor
1546 
1547     /** Construct with providing the combobox lists
1548      @param anAction one of a set of predefined actions
1549      @param pos the position/index where the action occured
1550      @param lists the lists to be loaded in the lists combo box
1551      @param majors the major types to be loaded in the major type combo box
1552      @param minors the minor types to be loaded in the minor type combo box
1553      @param languages the languages to be loaded in the languages combo box*/
1554     public LinearNodeInput(int anAction,int pos,Vector lists, Vector majors,
1555                             Vector minors, Vector languages)
1556     {
1557       try {
1558         action = anAction;
1559         position = pos;
1560         if (null!=lists)
1561           listCombo = new JComboBox(lists);
1562 
1563         if (null!=majors)
1564           majorCombo = new JComboBox(majors);
1565 
1566         if (null!=minors)
1567           minorCombo = new JComboBox(minors);
1568 
1569         if (null!=languages)
1570           languagesCombo = new JComboBox(languages);
1571 
1572         jbInit();
1573       }
1574       catch(Exception e) {
1575         e.printStackTrace();
1576       }
1577     // constructor with combo lists
1578 
1579     /** Construct with providing the combobox lists and the current values of the members
1580      @param anAction one of a set of predefined actions
1581      @param pos the position/index where the action occured
1582      @param lists the lists to be loaded in the lists combo box
1583      @param majors the major types to be loaded in the major type combo box
1584      @param minors the minor types to be loaded in the minor type combo box
1585      @param languagesList the languages to be loaded in the languages combo box
1586      */
1587     public LinearNodeInput(int anAction,int pos,
1588                     Vector lists, Vector majors, Vector minors,
1589                     Vector languagesList,
1590                     String list,String major, String minor, String languages)
1591     {
1592       try {
1593         action = anAction;
1594         position = pos;
1595         if (null!=lists)
1596           listCombo = new JComboBox(lists);
1597 
1598         if (null!=majors)
1599           majorCombo = new JComboBox(majors);
1600 
1601         if (null!=minors)
1602           minorCombo = new JComboBox(minors);
1603 
1604         if (null!=languagesList)
1605           languagesCombo = new JComboBox(languagesList);
1606 
1607         if (null!=list)
1608           listCombo.setSelectedItem(list);
1609 
1610 
1611         if (null!=major)
1612           majorCombo.setSelectedItem(major);
1613 
1614         if (null!=minor)
1615           minorCombo.setSelectedItem(minor);
1616         else
1617           minorCombo.setSelectedItem("");
1618 
1619         if (null!=languages)
1620           languagesCombo.setSelectedItem(languages);
1621         else
1622           languagesCombo.setSelectedItem("");
1623 
1624         jbInit();
1625       }
1626       catch(Exception e) {
1627         e.printStackTrace();
1628       }
1629     // constructor with combo lists
1630 
1631     private void jbInit() throws Exception {
1632       jLabel1.setAlignmentX((float0.5);
1633       jLabel1.setAlignmentY((float0.0);
1634       jLabel1.setText("Gazetteer List*");
1635       jPanel1.setLayout(gridBagLayout1);
1636       jLabel2.setText("Major Type*");
1637       jLabel3.setText("Minor Type");
1638       jLabel4.setText("Languages (comma-separated)");
1639       jLabel5.setText("Select, enter or alter the members of the Linear Node");
1640       jLabel6.setToolTipText("");
1641       jLabel6.setText("The members marked with \"*\" are mandatory.");
1642       btnOk.setText("OK");
1643       btnCancel.setText("Cancel");
1644       listCombo.setEditable(true);
1645       majorCombo.setEditable(true);
1646       minorCombo.setEditable(true);
1647       languagesCombo.setEditable(true);
1648       this.getContentPane().add(jPanel1,  BorderLayout.CENTER);
1649       jPanel1.add(jLabel5,           new GridBagConstraints(00210.00.0
1650               ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(510100)220));
1651       jPanel1.add(jLabel1,       new GridBagConstraints(01210.00.0
1652               ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(02000)00));
1653       jPanel1.add(listCombo,         new GridBagConstraints(02211.00.0
1654               ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(020060)00));
1655       jPanel1.add(jLabel2,      new GridBagConstraints(03210.00.0
1656               ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(02000)00));
1657       jPanel1.add(majorCombo,      new GridBagConstraints(04211.00.0
1658               ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(020060)00));
1659       jPanel1.add(jLabel3,      new GridBagConstraints(05210.00.0
1660               ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(020060)00));
1661       jPanel1.add(minorCombo,      new GridBagConstraints(06211.00.0
1662               ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(020060)00));
1663       jPanel1.add(jLabel4,       new GridBagConstraints(07210.00.0
1664               ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(02000)00));
1665       jPanel1.add(languagesCombo,      new GridBagConstraints(08211.00.0
1666               ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(020060)00));
1667       jPanel1.add(jLabel6,        new GridBagConstraints(09210.00.0
1668               ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1010150)00));
1669       jPanel1.add(btnOk,          new GridBagConstraints(010110.00.0
1670               ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(015000)00));
1671       jPanel1.add(btnCancel,         new GridBagConstraints(110110.00.0
1672               ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(00050)00));
1673 
1674       this.setSize(new Dimension(338318));
1675 
1676       createListeners();
1677     }
1678 
1679     /** Create the Action Listeners for the dialog*/
1680     private void createListeners() {
1681         btnOk.addActionListenernew ActionListener() {
1682           public void actionPerformed(ActionEvent e) {
1683             LinearNode ln = new LinearNode(
1684                 (String)listCombo.getSelectedItem(),
1685                 (String)majorCombo.getSelectedItem(),
1686                 (String)minorCombo.getSelectedItem(),
1687                 (String)languagesCombo.getSelectedItem()
1688               );
1689             if ((== ln.getList().trim().length())
1690               ||
1691               (== ln.getMajorType().trim().length())) {
1692               JOptionPane.showMessageDialog(Gaze.this,
1693               "This is not a valid Linear Node.\n"+
1694               "List and Major Type are mandatory\n"+
1695               "List : "+ln.getList()+
1696               "\nMajor Type : "+ln.getMajorType(),
1697               "Invalid Linear Node",JOptionPane.ERROR_MESSAGE );
1698             else {
1699               performLinearAction(action,position,ln);
1700             }
1701             dispose();
1702           }
1703         });
1704 
1705         btnCancel.addActionListenernew ActionListener() {
1706           public void actionPerformed(ActionEvent e) {
1707             dispose();   }  });
1708 
1709           addKeyListener(new KeyListener(){
1710 
1711           public void keyTyped(KeyEvent kev){}
1712 
1713           public void keyReleased(KeyEvent kev) {
1714             if (kev.VK_ENTER == kev.getKeyCode()) {
1715               LinearNode ln = new LinearNode(
1716                   (String)listCombo.getSelectedItem(),
1717                   (String)majorCombo.getSelectedItem(),
1718                   (String)minorCombo.getSelectedItem(),
1719                   (String)languagesCombo.getSelectedItem()
1720                 );
1721               performLinearAction(action,position,ln);
1722               dispose();
1723             // if enter
1724             else {
1725               if (kev.VK_ESCAPE == kev.getKeyCode()) {
1726                 dispose();
1727               // if escape
1728             // else
1729           // keyReleased()
1730 
1731           public void keyPressed(KeyEvent kev) {}
1732 
1733         })// add esc enter key listener
1734 
1735     // createListeners()
1736 
1737   }// class LinearNodeInput
1738 
1739 
1740   /** Reacts on all Create New Mapping actions performed either
1741    *  through the menu, either through the new buton. */
1742   class MappingNewListener implements ActionListener {
1743         public void actionPerformed(ActionEvent e) {
1744           JFileChooser chooser = MainFrame.getFileChooser();
1745           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1746 
1747           int result = chooser.showDialog(Gaze.this, "New");
1748           if result == JFileChooser.APPROVE_OPTION ) {
1749             File selected = chooser.getSelectedFile();
1750             try {
1751               if (!selected.createNewFile()){
1752                 JOptionPane.showMessageDialog(
1753                   Gaze.this,
1754                   "Cannot Create Mapping Definition.\n"+
1755                   selected.getAbsolutePath(),
1756                   "Mapping Definition Create Failure",
1757                   JOptionPane.ERROR_MESSAGE
1758                 );
1759               // if
1760               URL lurl = new URL("file:///"+selected.getAbsolutePath());
1761               mapping = new MappingDefinition();
1762               mapping.setURL(lurl);
1763               mapping.load();
1764 
1765               // remove the old tree from the scroll pane
1766               if (null != oTree)
1767                 ontologyScroll.getViewport().remove(oTree);
1768 
1769               oTree = new JTree();
1770               ontologyScroll.getViewport().add(oTree);
1771               oTree.setVisible(false);
1772               oTree.updateUI();
1773 
1774               // set the list data with the nodes of the gaz
1775               mappingList.setListData(mapping.toArray());
1776 
1777 
1778             catch (ResourceInstantiationException x) {
1779               JOptionPane.showMessageDialog(Gaze.this,
1780                 "Unable to load Mapping Definition (corrupted format).\n"
1781                 +"file:///"+selected.getAbsolutePath()+"\n"
1782                 +"Due to:\nResourceInstantiationException:"+x.getMessage()
1783                 ,"Mapping Definition Load Failure",
1784                 JOptionPane.ERROR_MESSAGE);
1785             catch (Exception x) {
1786               JOptionPane.showMessageDialog(Gaze.this,
1787                 "Unable to load linear definition (corrupted format).\n"
1788                 +"file:///"+selected.getAbsolutePath()+"\n"
1789                 +"Due to:\n"+x.getClass()+":"+x.getMessage()
1790                 ,"Linear Definition Load Failure",
1791                 JOptionPane.ERROR_MESSAGE);
1792             }
1793           // approve
1794         // actionPerformed(ActionEvent)
1795     // class MappingNewListener
1796 
1797 
1798   /** Reacts on all Load Mapping actions performed either
1799    *  through the menu, wither through the load buton. */
1800   class MappingLoadListener implements ActionListener {
1801         public void actionPerformed(ActionEvent e) {
1802           JFileChooser chooser = MainFrame.getFileChooser();
1803           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1804 
1805           int result = chooser.showOpenDialog(Gaze.this);
1806           if result == JFileChooser.APPROVE_OPTION ) {
1807             File selected = chooser.getSelectedFile();
1808             try {
1809               URL lurl = new URL("file:///"+selected.getAbsolutePath());
1810               mapping = new MappingDefinition();
1811               mapping.setURL(lurl);
1812               mapping.load();
1813 
1814               // set the list data with the nodes of the gaz
1815               mappingList.setListData(mapping.toArray());
1816 
1817               reinitializeGazetteer();
1818             catch (ResourceInstantiationException x) {
1819               JOptionPane.showMessageDialog(Gaze.this,
1820                 "Unable to load Mapping Definition (corrupted format).\n"
1821                 +"file:///"+selected.getAbsolutePath()+"\n"
1822                 +"Due to:\nResourceInstantiationException:"+x.getMessage()
1823                 ,"Mapping Definition Load Failure",
1824                 JOptionPane.ERROR_MESSAGE);
1825             catch (Exception x) {
1826               JOptionPane.showMessageDialog(Gaze.this,
1827                 "Unable to load linear definition (corrupted format).\n"
1828                 +"file:///"+selected.getAbsolutePath()+"\n"
1829                 +"Due to:\n"+x.getClass()+":"+x.getMessage()
1830                 ,"Linear Definition Load Failure",
1831                 JOptionPane.ERROR_MESSAGE);
1832             }
1833           // approve
1834         // actionPerformed(ActionEvent)
1835     // class MappingLoadListener
1836 
1837     /** Reacts on all Save As Mapping Definition actions. */
1838     class MappingSaveAsListener implements ActionListener {
1839         public void actionPerformed(ActionEvent e) {
1840           if null == mapping ) {
1841             JOptionPane.showMessageDialog(
1842               Gaze.this,"The Mapping Definition is null and cannot be saved.",
1843               "Mapping Definition Save As Failure.",JOptionPane.ERROR_MESSAGE);
1844           else {
1845             JFileChooser chooser = MainFrame.getFileChooser();
1846             chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1847 
1848             int result = chooser.showSaveDialog(Gaze.this);
1849             if result == JFileChooser.APPROVE_OPTION ) {
1850               File selected = chooser.getSelectedFile();
1851               URL lurl;
1852               try {
1853                 lurl = new URL("file:///"+selected.getAbsolutePath());
1854                 mapping.setURL(lurl);
1855                 mapping.store();
1856                 JOptionPane.showMessageDialog(
1857                   Gaze.this,
1858                   "Mapping Definition saved sucessfuly.\n"
1859                   +lurl,
1860                   "Mapping Definition Save As",
1861                   JOptionPane.PLAIN_MESSAGE);
1862 
1863                   reinitializeGazetteer();
1864 
1865               catch (MalformedURLException x) {
1866                 JOptionPane.showMessageDialog(Gaze.this,"Cannot save Mapping Definition.\n"
1867                   +"Due to "+x.getClass()+":"+x.getMessage(),
1868                   "Mapping Definition Save As Failure",JOptionPane.ERROR_MESSAGE);
1869               catch (ResourceInstantiationException x) {
1870                 JOptionPane.showMessageDialog(
1871                   Gaze.this,
1872                   "Unable to save the Mapping Defintion.\n"
1873                   +"Due to : "+x.getClass()+":"+x.getMessage(),
1874                   "Mapping Definition Save Failure.",
1875                   JOptionPane.ERROR_MESSAGE);
1876               // catch
1877             // approved
1878           // else
1879         }
1880     }// class MappingSaveListener
1881 
1882   /** Reacts on all Mapping Definition Save As events */
1883   class MappingSaveListener implements ActionListener {
1884     public void actionPerformed(ActionEvent e) {
1885       if null == mapping ) {
1886         JOptionPane.showMessageDialog(
1887           Gaze.this,"The Mapping Definition is null and cannot be saved.",
1888           "Mapping Definition Save failure.",JOptionPane.ERROR_MESSAGE);
1889       else {
1890 
1891         try {
1892           mapping.store();
1893           JOptionPane.showMessageDialog(
1894             Gaze.this,
1895             "Mapping Definition saved sucessfuly.",
1896             "Mapping Definition Save",
1897             JOptionPane.PLAIN_MESSAGE);
1898           reinitializeGazetteer();
1899         catch (ResourceInstantiationException x) {
1900           JOptionPane.showMessageDialog(
1901             Gaze.this,
1902             "Unable to save the Mapping Definition.\n"
1903             +"Due to : "+x.getClass()+":"+x.getMessage(),
1904             "Mapping Definition Save failure.",
1905             JOptionPane.ERROR_MESSAGE);
1906         // catch
1907       // else
1908     // actionPerformed(ActionEvent)
1909   // class MappingSaveListener
1910 
1911   /** Reacts on all Load Ontology actions performed either
1912    *  through the menu, wither through the load buton. */
1913   class OntologyLoadListener implements ActionListener {
1914         public void actionPerformed(ActionEvent e) {
1915           JFileChooser chooser = MainFrame.getFileChooser();
1916           chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1917 
1918           int result = chooser.showOpenDialog(Gaze.this);
1919           if result == JFileChooser.APPROVE_OPTION ) {
1920             File selected = chooser.getSelectedFile();
1921             try {
1922               URL ourl = new URL("file:///"+selected.getAbsolutePath());
1923               try {
1924                 ontology = OntologyUtilities.getOntology(ourl);
1925                 ontology.addOntologyModificationListener(Gaze.this);
1926               catch (ResourceInstantiationException x) {
1927                 x.printStackTrace(Err.getPrintWriter());
1928               }
1929               if (null == ontology)
1930                 throw new GateRuntimeException("can not Load ontology by url.\n"
1931                   +"ontology is null.\n"
1932                   +"url = "+ourl);
1933 
1934               // remove the old tree from the scroll pane
1935               if (null != oTree)
1936                 ontologyScroll.getViewport().remove(oTree);
1937 
1938               // check if there is already a tree for this ontology
1939               oTree = (JTreeontologyTrees.get(ontology);
1940 
1941               if (null == oTree) {
1942                 Map namesVsNodes = new HashMap();
1943                 ClassNode root = ClassNode.createRootNode(ontology,mapping,namesVsNodes);
1944                 OntoTreeModel model = new OntoTreeModel(root);
1945                 MappingTreeView view = new MappingTreeView(model,mapping,Gaze.this);
1946                 oTree = view;
1947                 ontologyTrees.put(ontology,oTree);
1948               // ontology tree has not been previously creted
1949 
1950               ontologyScroll.getViewport().add(oTree,null);
1951               oTree.setVisible(true);
1952 
1953 
1954             catch (Exception x) {
1955               JOptionPane.showMessageDialog(Gaze.this,
1956                 "Unable to load Ontology.\n"
1957                 +"file:///"+selected.getAbsolutePath()+"\n"
1958                 +"Due to:\n"+x.getClass()+":"+x.getMessage()
1959                 ,"Ontology Load Failure",
1960                 JOptionPane.ERROR_MESSAGE);
1961             }
1962           // approve
1963         // actionPerformed(ActionEvent)
1964     // class OntologyLoadListener
1965 
1966 // class Gaze