View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  /******************************************************************************
25  * TypeTreeModel.java
26  *
27  * The underlying model for the Fact Hierarchy tree
28  *****************************************************************************/
29  
30  package zeus.ontology;
31  
32  import java.util.*;
33  import javax.swing.*;
34  import javax.swing.event.*;
35  import javax.swing.tree.*;
36  import zeus.concepts.*;
37  import zeus.ontology.*;
38  
39  
40  public class TypeTreeModel extends DefaultTreeModel {
41    public static final int FACT        = 0;
42    public static final int RESTRICTION = 1;
43  
44    protected static final String DEFAULT_ROOT = "#DefaultRoot#";
45    protected static final String BASIC_TYPES  = "Basic Types";
46    protected static final String RESTRICTIONS = "Restrictions";
47    protected static final String FACTS        = "Facts";
48    protected static final String SETS         = "Set of ...";
49  
50    protected OntologyDb model;
51    protected int mode;
52  
53    public TypeTreeModel(OntologyDb model, int mode) {
54      super(new DefaultMutableTreeNode(DEFAULT_ROOT));
55      this.model = model;
56      this.mode = mode;
57      refresh();
58    }
59  
60    void refresh() {
61      root = new DefaultMutableTreeNode(DEFAULT_ROOT);
62  
63      DefaultMutableTreeNode basic, restrictions, facts, base, sets;
64      base = (DefaultMutableTreeNode)root;
65      basic = new DefaultMutableTreeNode(BASIC_TYPES);
66      restrictions = new DefaultMutableTreeNode(RESTRICTIONS);
67      facts = new DefaultMutableTreeNode(FACTS);
68  //    sets = new DefaultMutableTreeNode(SETS);
69  //    need to add sets to both restrictions and facts
70  
71      base.add(basic);
72      base.add(restrictions);
73  
74      for(int i = 0; i < OntologyDb.BASIC_TYPES.length; i++ )
75         basic.add(new DefaultMutableTreeNode(OntologyDb.BASIC_TYPES[i]));
76  
77      String[] names = model.getAllRestrictionNames();
78      for(int i = 0; i < names.length; i++ )
79         restrictions.add(new DefaultMutableTreeNode(names[i]));
80  
81      if ( mode == FACT ) {
82         base.add(facts);
83         basic.add(new DefaultMutableTreeNode(OntologyDb.OBJECT_TYPE));
84  
85         DefaultMutableTreeNode node;
86         node = new DefaultMutableTreeNode(model.getRoot());
87         facts.add(node);
88         createTree(node,model.getRoot());
89      }
90      reload();
91    }
92  
93    protected void createTree(DefaultMutableTreeNode m_node,
94                              zeus.util.TreeNode a_node) {
95  
96      // takes contents of model and inserts them into the tree
97  
98      Vector children = a_node.getChildren();
99      zeus.util.TreeNode b_node;
100     DefaultMutableTreeNode n_node;
101 
102     for(int i = 0; i < children.size(); i++ ) {
103        b_node = (zeus.util.TreeNode)children.elementAt(i);
104        n_node = new DefaultMutableTreeNode(b_node);
105        m_node.add(n_node);
106        createTree(n_node,b_node);
107     }
108   }
109 }