View Javadoc

1   package edu.uci.ics.jung.graph.event;
2   
3   import edu.uci.ics.jung.graph.Graph;
4   
5   /**
6    * 
7    * 
8    * @author tom nelson
9    *
10   * @param <V> the vertex type
11   * @param <E> the edge type
12   */
13  public abstract class GraphEvent<V,E> {
14  	
15  	protected Graph<V,E> source;
16  	protected Type type;
17  
18  	/**
19  	 * Creates an instance with the specified {@code source} graph and {@code Type}
20  	 * (vertex/edge addition/removal).
21  	 */
22  	public GraphEvent(Graph<V, E> source, Type type) {
23  		this.source = source;
24  		this.type = type;
25  	}
26  	
27  	/**
28  	 * Types of graph events.
29  	 */
30  	public static enum Type {
31  		VERTEX_ADDED,
32  		VERTEX_REMOVED,
33  		EDGE_ADDED,
34  		EDGE_REMOVED
35  	}
36  	
37      /**
38       * An event type pertaining to graph vertices.
39       */
40  	public static class Vertex<V,E> extends GraphEvent<V,E> {
41  		protected V vertex;
42  		
43  		/**
44  		 * Creates a graph event for the specified graph, vertex, and type.
45  		 */
46  		public Vertex(Graph<V,E> source, Type type, V vertex) {
47  			super(source,type);
48  			this.vertex = vertex;
49  		}
50  		
51  		/**
52  		 * Retrieves the vertex associated with this event.
53  		 */
54  		public V getVertex() {
55  			return vertex;
56  		}
57  		
58  		@Override
59  	    public String toString() {
60  			return "GraphEvent type:"+type+" for "+vertex;
61  		}
62  		
63  	}
64  	
65  	/**
66  	 * An event type pertaining to graph edges.
67  	 */
68  	public static class Edge<V,E> extends GraphEvent<V,E> {
69  		protected E edge;
70  		
71          /**
72           * Creates a graph event for the specified graph, edge, and type.
73           */
74  		public Edge(Graph<V,E> source, Type type, E edge) {
75  			super(source,type);
76  			this.edge = edge;
77  		}
78  		
79  		/**
80  		 * Retrieves the edge associated with this event.
81  		 */
82  		public E getEdge() {
83  			return edge;
84  		}
85  		
86  		@Override
87      	public String toString() {
88  			return "GraphEvent type:"+type+" for "+edge;
89  		}
90  		
91  	}
92  	
93  	/**
94  	 * @return the source
95  	 */
96  	public Graph<V, E> getSource() {
97  		return source;
98  	}
99  	
100 	/**
101 	 * @return the type
102 	 */
103 	public Type getType() {
104 		return type;
105 	}
106 }