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: f@0: package uk.ac.qmul.eecs.ccmi.network; f@0: f@0: import uk.ac.qmul.eecs.ccmi.gui.DiagramEventSource; f@0: import uk.ac.qmul.eecs.ccmi.utils.CharEscaper; f@0: import uk.ac.qmul.eecs.ccmi.utils.InteractionLog; f@0: f@0: /** f@0: * A command message that triggers an update in the model of the target diagram. Possible updates f@0: * are those listed in the {@code MessageName} enum. f@0: * Command messages are issued by both clients and server. Clients commands are sent after a f@0: * user action. When the server receives a command it broadcasts it to all the clients but the one f@0: * from which the command was from. f@0: * f@0: */ f@0: public class Command extends Message { f@0: public Command(Name name, String diagram, Object[] args, long timestamp, DiagramEventSource source){ f@0: super(timestamp,diagram,source); f@0: this.name = name; f@0: this.args = args; f@0: } f@0: f@0: public Command(Name name, String diagram, Object[] args, DiagramEventSource source){ f@0: super(diagram,source); f@0: this.name = name; f@0: this.args = args; f@0: } f@0: f@0: public Command(Name name, String diagram, long timestamp, DiagramEventSource source){ f@0: this(name, diagram, source); f@0: } f@0: f@0: public Command(Name name, String diagram, DiagramEventSource source){ f@0: this(name, diagram, new Object[]{},source); f@0: } f@0: f@0: @Override f@0: public DiagramEventSource getSource(){ f@0: return (DiagramEventSource)super.getSource(); f@0: } f@0: f@0: @Override f@0: public Name getName() { f@0: return name; f@0: } f@0: f@0: public Object getArgAt(int index) { f@0: return args[index]; f@0: } f@0: f@0: public Object[] getArgs(){ f@0: return args; f@0: } f@0: f@0: public int getArgNum(){ f@0: return args.length; f@0: } f@0: f@0: f@0: /** f@0: * Utility method to log, through the interaction log, the receipt of a command f@0: * @param cmd the received command f@0: * @param action a further description of the action that triggered this command f@0: */ f@0: public static void log(Command cmd, String action){ f@0: if(cmd.getName() != Command.Name.LOCAL && cmd.getName() != Command.Name.BEND f@0: && cmd.getName() != Command.Name.TRANSLATE_EDGE && cmd.getName() != Command.Name.TRANSLATE_NODE){ f@0: StringBuilder builder = new StringBuilder(cmd.getName().toString()); f@0: builder.append(' ').append(cmd.getDiagram()); f@0: for(int i=0; i