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 General Public License (GPL): http://www.gnu.org/licenses/
004    package graphlab.graph.event;
005    
006    import graphlab.graph.graph.GraphModel;
007    import graphlab.graph.graph.GraphPoint;
008    
009    import java.awt.event.MouseWheelEvent;
010    
011    /**
012     * An event which indicates that a graph action occurred.
013     *
014     * @author Azin Azadi
015     */
016    public class GraphEvent {
017        public final static String EVENT_KEY = "GraphEvent";
018    
019    
020        public static final int CLICKED = 0;
021        public static final int MOUSE_ENTERED_EXITED = 3;
022        public static final int NOTIFIED = 5;
023    
024    
025        /**
026         * indicates the start of dragging of mouse on graph.
027         * It is somehow like Mouse Pressed event in swing.
028         */
029        public static final int DRAGGING_STARTED = 12;
030        /**
031         * after start of dragging ,DRAGGING mouse move event will occur until the
032         * drop action
033         */
034        public static final int DRAGGING = 6;
035        /**
036         * indicates drop action after a drag event. (Dragging finished)
037         */
038        public static final int DROPPED = 7;
039        /**
040         * indicates moving of the mouse on graph
041         */
042        public static final int MOUSE_MOVED = 8;
043        /**
044         * indicates moving the wheel of the mouse on graph
045         */
046        public static final int MOUSE_WHEEL_MOVED = 9;
047    
048        public int eventType;
049        public GraphModel graph;
050    
051        /**
052         * position of mouse according to top left point of graph
053         */
054        public GraphPoint mousePos;
055    
056        /**
057         * the amount which mouse wheel is scrolled, positive or negative
058         *
059         * @see MouseWheelEvent
060         */
061        public int mouseWheelMoveAmount;
062        public int mouseBtn;
063    
064        /**
065         * @see javax.swing.event.MenuEvent -> getModifiersEx
066         */
067        public int modifiers;
068    
069        /**
070         * in the case that event occurs because of a GRAPH_MOUSE_ENTERED_EXITED event
071         * isMouseEntered will show that is mouse entered to the vertex (true) otherwise mouse exited
072         * from the vertex (false)
073         */
074        public boolean isMouseEntered;
075    
076        /**
077         * in the case that event occurs because of a NOTIFIED of UNNOTIFIED event
078         * isNotified will show that is vertex notified (true) or unNotified (false)
079         */
080        public boolean isNotified;
081    
082        /**
083         * in the case that event occurs because of a DRAGGING_STARTED or DRAGGING_FINISHED event
084         * isDragged will show that is vertex Dragged (true) or Dropped (false)
085         */
086        private boolean isDragged;
087    
088    
089        public GraphEvent(int eventType, GraphModel e, GraphPoint mousePos, int mouseBtn_or_mouseWheelMoveAmount, boolean isNotified, boolean isMouseEntered, boolean isDragged, int modifiersEx) {
090            this.eventType = eventType;
091            this.graph = e;
092            this.mousePos = mousePos;
093            this.isMouseEntered = isMouseEntered;
094            this.isNotified = isNotified;
095            this.modifiers = modifiersEx;
096            if (eventType != MOUSE_WHEEL_MOVED)
097                this.mouseBtn = mouseBtn_or_mouseWheelMoveAmount;
098            else
099                this.mouseWheelMoveAmount = mouseBtn_or_mouseWheelMoveAmount;
100        }
101    
102        public static GraphEvent mouseClicked(GraphModel g, GraphPoint mousePos, int mouseBtn, int modifiersEx) {
103            return new GraphEvent(CLICKED, g, mousePos, mouseBtn, false, false, false, modifiersEx);
104        }
105    
106        public static GraphEvent mouseEntered(GraphModel g, GraphPoint mousePos, int mouseBtn, int modifiersEx) {
107            return new GraphEvent(MOUSE_ENTERED_EXITED, g, mousePos, mouseBtn, false, true, false, modifiersEx);
108        }
109    
110        public static GraphEvent mouseExited(GraphModel g, GraphPoint mousePos, int mouseBtn, int modifiersEx) {
111            return new GraphEvent(MOUSE_ENTERED_EXITED, g, mousePos, mouseBtn, false, false, false, modifiersEx);
112        }
113    
114        public static GraphEvent mouseDraggingStarted(GraphModel g, GraphPoint mousePos, int mouseBtn, int modifiersEx) {
115            return new GraphEvent(DRAGGING_STARTED, g, mousePos, mouseBtn, false, false, true, modifiersEx);
116        }
117    
118        public static GraphEvent dragging(GraphModel g, GraphPoint mousePos, int mouseBtn, int modifiersEx) {
119            return new GraphEvent(DRAGGING, g, mousePos, mouseBtn, false, false, true, modifiersEx);
120        }
121    
122        public static GraphEvent mouseDropped(GraphModel g, GraphPoint mousePos, int mouseBtn, int modifiersEx) {
123            return new GraphEvent(DROPPED, g, mousePos, mouseBtn, false, false, false, modifiersEx);
124        }
125    
126        public static GraphEvent mouseMoved(GraphModel g, GraphPoint mousePos, int mouseBtn, int modifiersEx) {
127            return new GraphEvent(MOUSE_MOVED, g, mousePos, mouseBtn, false, false, false, modifiersEx);
128        }
129    
130        public static GraphEvent graphNotified(GraphModel g, int modifiersEx) {
131            return new GraphEvent(NOTIFIED, g, null, 0, true, false, false, modifiersEx);
132        }
133    
134        public static GraphEvent graphUnNotified(GraphModel g, int modifiersEx) {
135            return new GraphEvent(NOTIFIED, g, null, 0, false, false, false, modifiersEx);
136        }
137    
138        public static GraphEvent mouseWheelMoved(GraphModel g, GraphPoint mousePos, int mouseWheelMoveAmount, int modifiersEx) {
139            return new GraphEvent(MOUSE_WHEEL_MOVED, g, mousePos, mouseWheelMoveAmount, false, false, false, modifiersEx);
140        }
141    
142    }