fiore@3: /* fiore@3: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool fiore@3: fiore@3: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) fiore@3: fiore@3: This program is free software: you can redistribute it and/or modify fiore@3: it under the terms of the GNU General Public License as published by fiore@3: the Free Software Foundation, either version 3 of the License, or fiore@3: (at your option) any later version. fiore@3: fiore@3: This program is distributed in the hope that it will be useful, fiore@3: but WITHOUT ANY WARRANTY; without even the implied warranty of fiore@3: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fiore@3: GNU General Public License for more details. fiore@3: fiore@3: You should have received a copy of the GNU General Public License fiore@3: along with this program. If not, see . fiore@3: */ fiore@3: package uk.ac.qmul.eecs.ccmi.gui; fiore@3: fiore@3: /** fiore@3: * This class identifies the source of a diagram event, that is an event generated by an action fiore@3: * in the diagram such as for instance a node insertion, deletion or renaming. The class carries informations fiore@3: * about how the event was generated (from the tree, from the graph etc.) and if the event was fiore@3: * generated by the local user or another user co-editing the diagram. In either case an id of the fiore@3: * user is conveyed as well. An id is just a String each user assigns to themselves through a user fiore@3: * interface panel. fiore@3: */ fiore@3: public class DiagramEventSource { fiore@3: /** fiore@3: * An enumeration of the different ways an event can be generated. NONE is for when the fiore@3: * information is not relevant (as normally no event listener will be triggered by the event). fiore@3: * PERS is for actions triggered when rebuilding a diagram from a ccmi file, so not as a consequence fiore@3: * of a direct user action. fiore@3: */ fiore@3: public static enum Type{ fiore@3: TREE, fiore@3: GRPH, // graph fiore@3: HAPT, // haptics fiore@3: PERS, // persistence fiore@3: NONE; fiore@3: } fiore@3: fiore@3: /* constructor used only by the static event sources */ fiore@3: private DiagramEventSource(Type type){ fiore@3: this.type = type; fiore@3: local = true; fiore@3: } fiore@3: fiore@3: /** fiore@3: * Creates a new DiagramEventSource out of a previous one (normally one of the static default sources). fiore@3: * The type of the new object will be the same as the one passed as argument. Object created through fiore@3: * this constructor are marked as non local fiore@3: * fiore@3: * @see #isLocal() fiore@3: * @param eventSource an instance of this class fiore@3: */ fiore@3: public DiagramEventSource(DiagramEventSource eventSource){ fiore@3: this.type = eventSource.type; fiore@3: local = false; fiore@3: } fiore@3: fiore@3: /** fiore@3: * Returns true if the event is local, that is it's has been generated from an action of fiore@3: * the local user and not from a message coming from the server. fiore@3: * fiore@3: * @return {@code true} if the event has been generated by the local user fiore@3: */ fiore@3: public boolean isLocal(){ fiore@3: return local; fiore@3: } fiore@3: fiore@3: /** fiore@3: * Returns a copy of this event source that is marked as local. fiore@3: * fiore@3: * @return a local copy of this event source fiore@3: * @see #isLocal() fiore@3: */ fiore@3: public DiagramEventSource getLocalSource(){ fiore@3: return new DiagramEventSource(type); fiore@3: } fiore@3: fiore@3: /** fiore@3: * Returns the name of the diagram where the event happened, that has this fiore@3: * object as source. fiore@3: * fiore@3: * @return the name of the diagram fiore@3: */ fiore@3: public String getDiagramName(){ fiore@3: return diagramName; fiore@3: } fiore@3: fiore@3: /** fiore@3: * Sets the name of the diagram where the event happened, that has this fiore@3: * object as source. fiore@3: * fiore@3: * @param diagramName the name of the diagram fiore@3: */ fiore@3: public void setDiagramName(String diagramName){ fiore@3: this.diagramName = diagramName; fiore@3: } fiore@3: fiore@3: /** fiore@3: * The String representation of this object is the concatenation of the type fiore@3: * and the ID. fiore@3: * fiore@3: * @return a String representing this object fiore@3: */ fiore@3: @Override fiore@3: public String toString(){ fiore@3: return (local ? ISLOCAL_CHAR : ISNOTLOCAL_CHAR )+type.toString(); fiore@3: } fiore@3: fiore@3: /** fiore@3: * Returns an instance of this class out of a string representation, such as fiore@3: * returned by {@code toString()} fiore@3: * @param s a String representation of a {@code DiagramEventSource} instance, such as fiore@3: * returned by {@code toString()} fiore@3: * @return a new instance of {@code DiagramEventSource} fiore@3: */ fiore@3: public static DiagramEventSource valueOf(String s){ fiore@3: Type t = Type.valueOf(s.substring(1, 5)); fiore@3: DiagramEventSource toReturn = new DiagramEventSource(t); fiore@3: toReturn.local = (s.charAt(0) == ISLOCAL_CHAR) ? true : false; fiore@3: return toReturn; fiore@3: } fiore@3: fiore@3: private boolean local; fiore@3: public final Type type; fiore@3: private String diagramName; fiore@3: private static char ISLOCAL_CHAR = 'L'; fiore@3: private static char ISNOTLOCAL_CHAR = 'R'; fiore@3: fiore@3: /** Source for events triggered by the local user through the tree. These static sources fiore@3: * are used when the diagram is not shared with any other user. When it is, a new DiagramEventSource fiore@3: * will be created, which includes informations about the id and locality of the user who generated the event fiore@3: */ fiore@3: public static DiagramEventSource TREE = new DiagramEventSource(Type.TREE); fiore@3: /** Source for events triggered by the local user through the graph */ fiore@3: public static DiagramEventSource GRPH = new DiagramEventSource(Type.GRPH); fiore@3: /** Source for events triggered by the local user through the haptic device */ fiore@3: public static DiagramEventSource HAPT = new DiagramEventSource(Type.HAPT); fiore@3: /** Source for events triggered by the local user when opening a file */ fiore@3: public static DiagramEventSource PERS = new DiagramEventSource(Type.PERS); fiore@3: /** Source for events not relevant to model listeners */ fiore@3: public static DiagramEventSource NONE = new DiagramEventSource(Type.NONE); fiore@3: fiore@3: }