annotate java/src/uk/ac/qmul/eecs/ccmi/gui/DiagramEventSource.java @ 8:ea7885bd9bff tip

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