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 005 package graphlab.graph.event; 006 007 import graphlab.graph.graph.GraphPoint; 008 import graphlab.graph.graph.VertexModel; 009 010 /** 011 * An event which indicates that a vertex action occurred. 012 * 013 * @author azin azadi 014 * @see graphlab.graph.event.GraphEvent 015 */ 016 public class VertexEvent { 017 public final static String EVENT_KEY = "VertexEvent"; 018 019 020 public static final int CLICKED = 0; 021 /** 022 * DROPPED occurs in the case that mouse started dragging from a vertex and being dropped on another one, in this case 023 * a dropped event will be fired on the second vertex 024 */ 025 public static final int DROPPED = 1; 026 public static final int DRAGGING_STARTED = 2; 027 public static final int DRAGGING = 4; 028 public static final int NOTIFIED = 5; 029 public static final int PRESSED = 6; 030 /** 031 * RELEASED occurs in the case that mouse started dragging from a vertex and dropped on an empty region of the graph, 032 * in this case a RELEASED event will be fired on starting vertex 033 */ 034 public static final int RELEASED = 7; 035 public static final int DOUBLECLICKED = 8; 036 037 public int eventType; 038 public VertexModel v; 039 040 /** 041 * @see javax.swing.event.MenuEvent -> getModifiersEx 042 */ 043 public int modifiers; 044 045 public static VertexEvent clicked(VertexModel v, GraphPoint mousePos, int mouseBtn, int modifiersEx) { 046 return new VertexEvent(CLICKED, v, mousePos, mouseBtn, false, false, modifiersEx); 047 } 048 049 public static VertexEvent doubleClicked(VertexModel v, GraphPoint mousePos, int mouseBtn, int modifiersEx) { 050 return new VertexEvent(DOUBLECLICKED, v, mousePos, mouseBtn, false, false, modifiersEx); 051 } 052 053 public static VertexEvent released(VertexModel v, GraphPoint mousePos, int mouseBtn, int modifiersEx) { 054 return new VertexEvent(RELEASED, v, mousePos, mouseBtn, false, false, modifiersEx); 055 } 056 057 public static VertexEvent dropped(VertexModel v, GraphPoint mousePos, int mouseBtn, int modifiersEx) { 058 return new VertexEvent(DROPPED, v, mousePos, mouseBtn, false, false, modifiersEx); 059 } 060 061 public static VertexEvent draggingStarted(VertexModel v, GraphPoint mousePos, int mouseBtn, int modifiersEx) { 062 return new VertexEvent(DRAGGING_STARTED, v, mousePos, mouseBtn, false, false, modifiersEx); 063 } 064 065 public static VertexEvent dragging(VertexModel v, GraphPoint mousePos, int mouseBtn, int modifiersEx) { 066 return new VertexEvent(DRAGGING, v, mousePos, mouseBtn, false, false, modifiersEx); 067 } 068 069 public VertexEvent(int eventType, VertexModel v, GraphPoint mousePos, int mouseBtn, boolean isNotified, boolean isMouseEntered, int modifiersEx) { 070 this.eventType = eventType; 071 this.v = v; 072 this.mousePos = mousePos; 073 this.mouseBtn = mouseBtn; 074 this.isMouseEntered = isMouseEntered; 075 this.modifiers = modifiersEx; 076 } 077 078 //position of mouse according to top left point of vertex 079 public GraphPoint mousePos; 080 public int mouseBtn; 081 082 /** 083 * in the case that event occurs because of a VERTEX_MOUSE_ENTERED_EXITED event 084 * isMouseEntered will show that is mouse entered to the vertex (true) otherwise mouse exited 085 * from the vertex (false) 086 */ 087 public boolean isMouseEntered; 088 }