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  package zeus.gui.graph;
25  
26  import java.awt.Color;
27  import java.awt.event.*;
28  import javax.swing.event.*;
29  import java.util.*;
30  
31  public abstract class AbstractGraphModel implements GraphModel {
32     private static final int STRUCTURE_CHANGED  = 0;
33     private static final int NODE_ADDED         = 1;
34     private static final int NODE_REMOVED       = 2;
35     private static final int NODE_STATE_CHANGED = 3;
36  
37     protected EventListenerList graphModelListeners = new EventListenerList();
38  
39  
40     public abstract Enumeration nodes();
41     public abstract void        setValue(GraphNode node, Object user_object);
42     public abstract boolean     isNodeEditable(GraphNode node);
43  
44     public Color getLinkColor(GraphNode from, GraphNode to) {
45        return Color.black;
46     }
47     public boolean isLinkVisible(GraphNode from, GraphNode to) {
48        return true;
49     }
50     public Vector getViewRelations(GraphNode node) {
51        return new Vector(10);
52     }
53     protected void fireGraphStructureChanged() {
54        fireGraphAction(STRUCTURE_CHANGED,null);
55     }
56     protected void fireGraphNodeAdded(GraphNode node) {
57        fireGraphAction(NODE_ADDED,node);
58     }
59     protected void fireGraphNodeRemoved(GraphNode node) {
60        fireGraphAction(NODE_REMOVED,node);
61     }
62     protected void fireGraphNodeStateChanged(GraphNode node) {
63        fireGraphAction(NODE_STATE_CHANGED,node);
64     }
65     public void addGraphModelListener(GraphModelListener x) {
66        graphModelListeners.add(GraphModelListener.class, x);
67     }
68     public void removeGraphModelListener(GraphModelListener x) {
69        graphModelListeners.remove(GraphModelListener.class, x);
70     }
71     private void fireGraphAction(int type, GraphNode node) {
72        GraphModelEvent evt = new GraphModelEvent(this,node);
73        Object[] listeners = graphModelListeners.getListenerList();
74        for(int i = listeners.length-2; i >= 0; i -= 2) {
75           if (listeners[i] == GraphModelListener.class) {
76              GraphModelListener cl = (GraphModelListener)listeners[i+1];
77              switch(type) {
78                 case STRUCTURE_CHANGED:
79                      cl.graphStructureChanged(evt);
80                      break;
81                 case NODE_ADDED:
82                      cl.graphNodeAdded(evt);
83                      break;
84                 case NODE_REMOVED:
85                      cl.graphNodeRemoved(evt);
86                      break;
87                 case NODE_STATE_CHANGED:
88                      cl.graphNodeStateChanged(evt);
89                      break;
90              }
91           }
92        }
93     }
94  
95  }