001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
004    
005    package graphlab.library.event;
006    
007    import graphlab.library.BaseEdge;
008    import graphlab.library.BaseGraph;
009    import graphlab.library.BaseVertex;
010    
011    /**
012     * Happens when an edge's color or weight changes or a new edge
013     * is added to the graph.
014     *
015     * @author Omid Aladini
016     */
017    public class EdgeEvent<VertexType extends BaseVertex, EdgeType extends BaseEdge<VertexType>>
018            implements Event {
019        public final EdgeType edge;
020        public final BaseGraph<VertexType, EdgeType> graph;
021        public final EventType eventType;
022    
023        public static enum EventType {
024            COLOR_CHANGE,
025            WEIGHT_CHANGE,
026            NEW_EDGE,
027            MARK
028        }
029    
030        /**
031         * Constructs an event that means an event is occured on a specified edge.
032         *
033         * @param edge The edge which the event occurs on it.
034         * @param et   Type of the event occured on the first parameter <code>edge</code>;
035         * @throws NullPointerException if <code>edge</code> is null.
036         */
037        public EdgeEvent(BaseGraph<VertexType, EdgeType> graph, EdgeType edge, EventType et) {
038            if (edge == null || et == null || graph == null)
039                throw new NullPointerException("Null argument supplied.");
040    
041            eventType = et;
042            this.edge = edge;
043            this.graph = graph;
044        }
045    
046        /**
047         * Constructs an event that means a new edge is added to the graph.
048         *
049         * @param edge The edge which the event occurs on it.
050         * @throws NullPointerException if <code>edge</code> is null.
051         */
052        public EdgeEvent(BaseGraph<VertexType, EdgeType> graph, EdgeType edge) {
053            this(graph, edge, EventType.NEW_EDGE);
054        }
055    
056        public String getID() {
057            return "EdgeEvent";
058        }
059    
060        public String getDescription() {
061            return "Edge event:" + eventType;
062        }
063    
064        private String message;
065    
066        public String getMessage() {
067            return message;
068        }
069    
070        public void setMessage(String message) {
071            this.message = message;
072        }
073    }