f@0
|
1 /*
|
f@0
|
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
|
f@0
|
3
|
f@0
|
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
|
f@0
|
5
|
f@0
|
6 This program is free software: you can redistribute it and/or modify
|
f@0
|
7 it under the terms of the GNU General Public License as published by
|
f@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
f@0
|
9 (at your option) any later version.
|
f@0
|
10
|
f@0
|
11 This program is distributed in the hope that it will be useful,
|
f@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@0
|
14 GNU General Public License for more details.
|
f@0
|
15
|
f@0
|
16 You should have received a copy of the GNU General Public License
|
f@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@0
|
18 */
|
f@0
|
19 package uk.ac.qmul.eecs.ccmi.network;
|
f@0
|
20
|
f@0
|
21 import uk.ac.qmul.eecs.ccmi.gui.DiagramEventSource;
|
f@0
|
22
|
f@0
|
23 /**
|
f@0
|
24 * This class represent a source of an editing action. An editing action is initiated when
|
f@0
|
25 * the user gets the lock on a certain element and terminates when the user after changing
|
f@0
|
26 * the diagram model somehow yields the lock back to the server.
|
f@0
|
27 *
|
f@0
|
28 */
|
f@0
|
29 public class DiagramEventActionSource extends DiagramEventSource{
|
f@0
|
30
|
f@0
|
31 public long getTimestamp() {
|
f@0
|
32 return timestamp;
|
f@0
|
33 }
|
f@0
|
34
|
f@0
|
35 public void setTimestamp(long timestamp) {
|
f@0
|
36 this.timestamp = timestamp;
|
f@0
|
37 }
|
f@0
|
38
|
f@0
|
39 public DiagramEventActionSource (DiagramEventSource eventSource, Command.Name cmd, long elementID, String elementName) {
|
f@0
|
40 super(eventSource);
|
f@0
|
41 this.cmd = cmd;
|
f@0
|
42 this.elementID = elementID;
|
f@0
|
43 this.saveID = elementID;
|
f@0
|
44 this.elementName = elementName;
|
f@0
|
45 userName = AwarenessMessage.getDefaultUserName();
|
f@0
|
46 timestamp = System.currentTimeMillis();
|
f@0
|
47 }
|
f@0
|
48
|
f@0
|
49 public Command.Name getCmd() {
|
f@0
|
50 return cmd;
|
f@0
|
51 }
|
f@0
|
52
|
f@0
|
53 public long getElementID(){
|
f@0
|
54 return elementID;
|
f@0
|
55 }
|
f@0
|
56
|
f@0
|
57 public void setElementID(long ID){
|
f@0
|
58 elementID = ID;
|
f@0
|
59 }
|
f@0
|
60
|
f@0
|
61 long getSaveID(){
|
f@0
|
62 return saveID;
|
f@0
|
63 }
|
f@0
|
64
|
f@0
|
65 public String getElementName(){
|
f@0
|
66 return elementName;
|
f@0
|
67 }
|
f@0
|
68
|
f@0
|
69 public void setElementName(String elementName){
|
f@0
|
70 this.elementName = elementName;
|
f@0
|
71 }
|
f@0
|
72
|
f@0
|
73 public void setUserName(String name){
|
f@0
|
74 this.userName = name;
|
f@0
|
75 }
|
f@0
|
76
|
f@0
|
77 public String getUserName(){
|
f@0
|
78 return userName;
|
f@0
|
79 }
|
f@0
|
80
|
f@0
|
81 /**
|
f@0
|
82 *
|
f@0
|
83 * The local user never gets this informations from itself are they are attached to
|
f@0
|
84 * AwernessMessages they receive only from other users. Therefore instances of this class
|
f@0
|
85 * are never considered local.
|
f@0
|
86 */
|
f@0
|
87 @Override
|
f@0
|
88 public boolean isLocal(){
|
f@0
|
89 return false;
|
f@0
|
90 }
|
f@0
|
91
|
f@0
|
92 /**
|
f@0
|
93 * Returns an instance of {@code DiagramEventActionSource} out of a
|
f@0
|
94 * String passed as argument
|
f@0
|
95 * @param s a string representation of a {@code DiagramEventActionSource} instance, as
|
f@0
|
96 * returned by toString.
|
f@0
|
97 * @return an instance of {@code DiagramEventActionSource}
|
f@0
|
98 */
|
f@0
|
99 public static DiagramEventActionSource valueOf(String s){
|
f@0
|
100 if(s.isEmpty())
|
f@0
|
101 return NULL;
|
f@0
|
102 String[] strings = s.split(SEPARATOR);
|
f@0
|
103 long id = Long.parseLong(strings[1]);
|
f@0
|
104 String elementName = strings[2];
|
f@0
|
105 long timestamp = Long.parseLong(strings[3]);
|
f@0
|
106 DiagramEventSource eventSource = DiagramEventSource.valueOf(strings[5]);
|
f@0
|
107 DiagramEventActionSource toReturn = new DiagramEventActionSource(eventSource,Command.Name.valueOf(strings[0]),id,elementName);
|
f@0
|
108 toReturn.setUserName(strings[4]);
|
f@0
|
109 toReturn.setTimestamp(timestamp);
|
f@0
|
110 return toReturn;
|
f@0
|
111 }
|
f@0
|
112
|
f@0
|
113 /**
|
f@0
|
114 * Encodes this object into a String. the encoding is done by concatenating the command name
|
f@0
|
115 * with the string representation of the event source. the command name is encoded in a fixed length
|
f@0
|
116 * string and padded with white spaces if such length is greater than the command name's.
|
f@0
|
117 */
|
f@0
|
118 @Override
|
f@0
|
119 public String toString(){
|
f@0
|
120 StringBuilder builder = new StringBuilder(cmd.name());
|
f@0
|
121 builder.append(SEPARATOR);
|
f@0
|
122 builder.append(elementID);
|
f@0
|
123 builder.append(SEPARATOR);
|
f@0
|
124 builder.append(elementName);
|
f@0
|
125 builder.append(SEPARATOR);
|
f@0
|
126 builder.append(timestamp);
|
f@0
|
127 builder.append(SEPARATOR);
|
f@0
|
128 builder.append(userName);
|
f@0
|
129 builder.append(SEPARATOR);
|
f@0
|
130 builder.append(super.toString());
|
f@0
|
131 return builder.toString();
|
f@0
|
132 }
|
f@0
|
133
|
f@0
|
134
|
f@0
|
135
|
f@0
|
136 private String userName;
|
f@0
|
137 private Command.Name cmd;
|
f@0
|
138 private long elementID;
|
f@0
|
139 private long saveID;
|
f@0
|
140 private String elementName;
|
f@0
|
141 private static final String SEPARATOR = "\n";
|
f@0
|
142 private long timestamp;
|
f@0
|
143
|
f@0
|
144 public static DiagramEventActionSource NULL = new DiagramEventActionSource(DiagramEventSource.NONE,Command.Name.NONE,-1,""){
|
f@0
|
145 @Override
|
f@0
|
146 public String toString(){
|
f@0
|
147 return "";
|
f@0
|
148 }
|
f@0
|
149 };
|
f@0
|
150
|
f@0
|
151 }
|