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 * @param source the graph whose event this is
23 * @param type the type of event this is
24 */
25 public GraphEvent(Graph<V, E> source, Type type) {
26 this.source = source;
27 this.type = type;
28 }
29
30 /**
31 * Types of graph events.
32 */
33 public static enum Type {
34 VERTEX_ADDED,
35 VERTEX_REMOVED,
36 EDGE_ADDED,
37 EDGE_REMOVED
38 }
39
40 /**
41 * An event type pertaining to graph vertices.
42 */
43 public static class Vertex<V,E> extends GraphEvent<V,E> {
44 protected V vertex;
45
46 /**
47 * Creates a graph event for the specified graph, vertex, and type.
48 *
49 * @param source the graph whose event this is
50 * @param type the type of event this is
51 * @param vertex the vertex involved in this event
52 */
53 public Vertex(Graph<V,E> source, Type type, V vertex) {
54 super(source,type);
55 this.vertex = vertex;
56 }
57
58 /**
59 * @return the vertex associated with this event
60 */
61 public V getVertex() {
62 return vertex;
63 }
64
65 @Override
66 public String toString() {
67 return "GraphEvent type:"+type+" for "+vertex;
68 }
69
70 }
71
72 /**
73 * An event type pertaining to graph edges.
74 */
75 public static class Edge<V,E> extends GraphEvent<V,E> {
76 protected E edge;
77
78 /**
79 * Creates a graph event for the specified graph, edge, and type.
80 *
81 * @param source the graph whose event this is
82 * @param type the type of event this is
83 * @param edge the edge involved in this event
84 */
85 public Edge(Graph<V,E> source, Type type, E edge) {
86 super(source,type);
87 this.edge = edge;
88 }
89
90 /**
91 * @return the edge associated with this event.
92 */
93 public E getEdge() {
94 return edge;
95 }
96
97 @Override
98 public String toString() {
99 return "GraphEvent type:"+type+" for "+edge;
100 }
101
102 }
103
104 /**
105 * @return the source
106 */
107 public Graph<V, E> getSource() {
108 return source;
109 }
110
111 /**
112 * @return the type
113 */
114 public Type getType() {
115 return type;
116 }
117 }