Mercurial > hg > ccmieditor
comparison java/src/uk/ac/qmul/eecs/ccmi/gui/DiagramEventSource.java @ 3:9e67171477bc
PHANTOM Omni Heptic device release
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Wed, 25 Apr 2012 17:09:09 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:4b2f975e35fa | 3:9e67171477bc |
---|---|
1 /* | |
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool | |
3 | |
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) | |
5 | |
6 This program is free software: you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation, either version 3 of the License, or | |
9 (at your option) any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 */ | |
19 package uk.ac.qmul.eecs.ccmi.gui; | |
20 | |
21 /** | |
22 * This class identifies the source of a diagram event, that is an event generated by an action | |
23 * in the diagram such as for instance a node insertion, deletion or renaming. The class carries informations | |
24 * about how the event was generated (from the tree, from the graph etc.) and if the event was | |
25 * generated by the local user or another user co-editing the diagram. In either case an id of the | |
26 * user is conveyed as well. An id is just a String each user assigns to themselves through a user | |
27 * interface panel. | |
28 */ | |
29 public class DiagramEventSource { | |
30 /** | |
31 * An enumeration of the different ways an event can be generated. NONE is for when the | |
32 * information is not relevant (as normally no event listener will be triggered by the event). | |
33 * PERS is for actions triggered when rebuilding a diagram from a ccmi file, so not as a consequence | |
34 * of a direct user action. | |
35 */ | |
36 public static enum Type{ | |
37 TREE, | |
38 GRPH, // graph | |
39 HAPT, // haptics | |
40 PERS, // persistence | |
41 NONE; | |
42 } | |
43 | |
44 /* constructor used only by the static event sources */ | |
45 private DiagramEventSource(Type type){ | |
46 this.type = type; | |
47 local = true; | |
48 } | |
49 | |
50 /** | |
51 * Creates a new DiagramEventSource out of a previous one (normally one of the static default sources). | |
52 * The type of the new object will be the same as the one passed as argument. Object created through | |
53 * this constructor are marked as non local | |
54 * | |
55 * @see #isLocal() | |
56 * @param eventSource an instance of this class | |
57 */ | |
58 public DiagramEventSource(DiagramEventSource eventSource){ | |
59 this.type = eventSource.type; | |
60 local = false; | |
61 } | |
62 | |
63 /** | |
64 * Returns true if the event is local, that is it's has been generated from an action of | |
65 * the local user and not from a message coming from the server. | |
66 * | |
67 * @return {@code true} if the event has been generated by the local user | |
68 */ | |
69 public boolean isLocal(){ | |
70 return local; | |
71 } | |
72 | |
73 /** | |
74 * Returns a copy of this event source that is marked as local. | |
75 * | |
76 * @return a local copy of this event source | |
77 * @see #isLocal() | |
78 */ | |
79 public DiagramEventSource getLocalSource(){ | |
80 return new DiagramEventSource(type); | |
81 } | |
82 | |
83 /** | |
84 * Returns the name of the diagram where the event happened, that has this | |
85 * object as source. | |
86 * | |
87 * @return the name of the diagram | |
88 */ | |
89 public String getDiagramName(){ | |
90 return diagramName; | |
91 } | |
92 | |
93 /** | |
94 * Sets the name of the diagram where the event happened, that has this | |
95 * object as source. | |
96 * | |
97 * @param diagramName the name of the diagram | |
98 */ | |
99 public void setDiagramName(String diagramName){ | |
100 this.diagramName = diagramName; | |
101 } | |
102 | |
103 /** | |
104 * The String representation of this object is the concatenation of the type | |
105 * and the ID. | |
106 * | |
107 * @return a String representing this object | |
108 */ | |
109 @Override | |
110 public String toString(){ | |
111 return (local ? ISLOCAL_CHAR : ISNOTLOCAL_CHAR )+type.toString(); | |
112 } | |
113 | |
114 /** | |
115 * Returns an instance of this class out of a string representation, such as | |
116 * returned by {@code toString()} | |
117 * @param s a String representation of a {@code DiagramEventSource} instance, such as | |
118 * returned by {@code toString()} | |
119 * @return a new instance of {@code DiagramEventSource} | |
120 */ | |
121 public static DiagramEventSource valueOf(String s){ | |
122 Type t = Type.valueOf(s.substring(1, 5)); | |
123 DiagramEventSource toReturn = new DiagramEventSource(t); | |
124 toReturn.local = (s.charAt(0) == ISLOCAL_CHAR) ? true : false; | |
125 return toReturn; | |
126 } | |
127 | |
128 private boolean local; | |
129 public final Type type; | |
130 private String diagramName; | |
131 private static char ISLOCAL_CHAR = 'L'; | |
132 private static char ISNOTLOCAL_CHAR = 'R'; | |
133 | |
134 /** Source for events triggered by the local user through the tree. These static sources | |
135 * are used when the diagram is not shared with any other user. When it is, a new DiagramEventSource | |
136 * will be created, which includes informations about the id and locality of the user who generated the event | |
137 */ | |
138 public static DiagramEventSource TREE = new DiagramEventSource(Type.TREE); | |
139 /** Source for events triggered by the local user through the graph */ | |
140 public static DiagramEventSource GRPH = new DiagramEventSource(Type.GRPH); | |
141 /** Source for events triggered by the local user through the haptic device */ | |
142 public static DiagramEventSource HAPT = new DiagramEventSource(Type.HAPT); | |
143 /** Source for events triggered by the local user when opening a file */ | |
144 public static DiagramEventSource PERS = new DiagramEventSource(Type.PERS); | |
145 /** Source for events not relevant to model listeners */ | |
146 public static DiagramEventSource NONE = new DiagramEventSource(Type.NONE); | |
147 | |
148 } |