f@0: /* f@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool f@0: f@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@0: package uk.ac.qmul.eecs.ccmi.network; f@0: f@0: import uk.ac.qmul.eecs.ccmi.gui.DiagramEventSource; f@0: f@0: /** f@0: * This class represent a source of an editing action. An editing action is initiated when f@0: * the user gets the lock on a certain element and terminates when the user after changing f@0: * the diagram model somehow yields the lock back to the server. f@0: * f@0: */ f@0: public class DiagramEventActionSource extends DiagramEventSource{ f@0: f@0: public long getTimestamp() { f@0: return timestamp; f@0: } f@0: f@0: public void setTimestamp(long timestamp) { f@0: this.timestamp = timestamp; f@0: } f@0: f@0: public DiagramEventActionSource (DiagramEventSource eventSource, Command.Name cmd, long elementID, String elementName) { f@0: super(eventSource); f@0: this.cmd = cmd; f@0: this.elementID = elementID; f@0: this.saveID = elementID; f@0: this.elementName = elementName; f@0: userName = AwarenessMessage.getDefaultUserName(); f@0: timestamp = System.currentTimeMillis(); f@0: } f@0: f@0: public Command.Name getCmd() { f@0: return cmd; f@0: } f@0: f@0: public long getElementID(){ f@0: return elementID; f@0: } f@0: f@0: public void setElementID(long ID){ f@0: elementID = ID; f@0: } f@0: f@0: long getSaveID(){ f@0: return saveID; f@0: } f@0: f@0: public String getElementName(){ f@0: return elementName; f@0: } f@0: f@0: public void setElementName(String elementName){ f@0: this.elementName = elementName; f@0: } f@0: f@0: public void setUserName(String name){ f@0: this.userName = name; f@0: } f@0: f@0: public String getUserName(){ f@0: return userName; f@0: } f@0: f@0: /** f@0: * f@0: * The local user never gets this informations from itself are they are attached to f@0: * AwernessMessages they receive only from other users. Therefore instances of this class f@0: * are never considered local. f@0: */ f@0: @Override f@0: public boolean isLocal(){ f@0: return false; f@0: } f@0: f@0: /** f@0: * Returns an instance of {@code DiagramEventActionSource} out of a f@0: * String passed as argument f@0: * @param s a string representation of a {@code DiagramEventActionSource} instance, as f@0: * returned by toString. f@0: * @return an instance of {@code DiagramEventActionSource} f@0: */ f@0: public static DiagramEventActionSource valueOf(String s){ f@0: if(s.isEmpty()) f@0: return NULL; f@0: String[] strings = s.split(SEPARATOR); f@0: long id = Long.parseLong(strings[1]); f@0: String elementName = strings[2]; f@0: long timestamp = Long.parseLong(strings[3]); f@0: DiagramEventSource eventSource = DiagramEventSource.valueOf(strings[5]); f@0: DiagramEventActionSource toReturn = new DiagramEventActionSource(eventSource,Command.Name.valueOf(strings[0]),id,elementName); f@0: toReturn.setUserName(strings[4]); f@0: toReturn.setTimestamp(timestamp); f@0: return toReturn; f@0: } f@0: f@0: /** f@0: * Encodes this object into a String. the encoding is done by concatenating the command name f@0: * with the string representation of the event source. the command name is encoded in a fixed length f@0: * string and padded with white spaces if such length is greater than the command name's. f@0: */ f@0: @Override f@0: public String toString(){ f@0: StringBuilder builder = new StringBuilder(cmd.name()); f@0: builder.append(SEPARATOR); f@0: builder.append(elementID); f@0: builder.append(SEPARATOR); f@0: builder.append(elementName); f@0: builder.append(SEPARATOR); f@0: builder.append(timestamp); f@0: builder.append(SEPARATOR); f@0: builder.append(userName); f@0: builder.append(SEPARATOR); f@0: builder.append(super.toString()); f@0: return builder.toString(); f@0: } f@0: f@0: f@0: f@0: private String userName; f@0: private Command.Name cmd; f@0: private long elementID; f@0: private long saveID; f@0: private String elementName; f@0: private static final String SEPARATOR = "\n"; f@0: private long timestamp; f@0: f@0: public static DiagramEventActionSource NULL = new DiagramEventActionSource(DiagramEventSource.NONE,Command.Name.NONE,-1,""){ f@0: @Override f@0: public String toString(){ f@0: return ""; f@0: } f@0: }; f@0: f@0: }