fiore@0: /* fiore@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool fiore@0: fiore@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) fiore@0: fiore@0: This program is free software: you can redistribute it and/or modify fiore@0: it under the terms of the GNU General Public License as published by fiore@0: the Free Software Foundation, either version 3 of the License, or fiore@0: (at your option) any later version. fiore@0: fiore@0: This program is distributed in the hope that it will be useful, fiore@0: but WITHOUT ANY WARRANTY; without even the implied warranty of fiore@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fiore@0: GNU General Public License for more details. fiore@0: fiore@0: You should have received a copy of the GNU General Public License fiore@0: along with this program. If not, see . fiore@0: */ fiore@0: package uk.ac.qmul.eecs.ccmi.diagrammodel; fiore@0: fiore@0: import java.util.EventObject; fiore@0: fiore@0: /** fiore@3: * ElementChangedEvent is used to notify the model listeners that an element ({@code DiagramNode} fiore@3: * or {@code DiagramEdge}) in the model has been changed (e.g. it has a new name). fiore@0: * fiore@0: */ fiore@0: @SuppressWarnings("serial") fiore@0: public class ElementChangedEvent extends EventObject { fiore@0: fiore@3: /** fiore@3: * Creates a new instance of {@code ElementChangedEvent} fiore@3: * fiore@3: * @param element the element that has been changed fiore@5: * @param args the arguments of this change event, if any fiore@3: * @param changeType it's a {@code String} identifying the change type. Subclasses of {@code DiagramNode} and fiore@3: * {@code DiagramEdge} can define their own change events and and make listeners aware of them via their fiore@3: * {@code notifyChnage()} method. Listeners (defined outside this package as well) can then identify such changes using this string. fiore@3: * @param source the source of the change that triggered this event fiore@3: */ fiore@3: public ElementChangedEvent( DiagramElement element, Object args, String changeType, Object source) { fiore@0: super(source); fiore@0: this.changeType = changeType; fiore@0: this.element = element; fiore@3: this.arguments = args; fiore@0: } fiore@0: fiore@0: /** fiore@0: * A String representing the change type. Subclasses of DiagramNode and DiagramEdge fiore@0: * can throw their own events by passing as argument a String that describes the change. fiore@0: * Such events will have no effect in the model but will be fired to all the registered ChangeEventListener. fiore@0: * fiore@0: * @return a String describing the change type fiore@0: */ fiore@0: public String getChangeType(){ fiore@0: return changeType; fiore@0: } fiore@0: fiore@0: /** fiore@0: * Returns the DiagramElement that has been affected by this change fiore@0: * @return the DiagramElement that has been affected by this change fiore@0: */ fiore@0: public DiagramElement getDiagramElement(){ fiore@0: return element; fiore@0: } fiore@0: fiore@3: /** fiore@3: * Returns the arguments of the change if the the change type has any fiore@3: * fiore@3: * @return an object representing the arguments or null fiore@3: */ fiore@3: public Object getArguments(){ fiore@3: return arguments; fiore@3: } fiore@3: fiore@0: private String changeType; fiore@3: private DiagramElement element; fiore@3: private Object arguments; fiore@3: fiore@3: /** fiore@3: * This class is returned by {@link ElementChangedEvent#getArguments()} when a node property is fiore@3: * changed. It holds the informations about the property type and the property index, so that fiore@3: * listeners can retrieve the property when handling the event. fiore@3: * fiore@3: */ fiore@3: public static class PropertyChangeArgs { fiore@3: public PropertyChangeArgs(String type, int index, String oldValue){ fiore@3: this.type = type; fiore@3: this.index = index; fiore@3: this.oldValue = oldValue; fiore@3: } fiore@3: fiore@3: public String getPropertyType(){ fiore@3: return type; fiore@3: } fiore@3: fiore@3: public int getPropertyIndex(){ fiore@3: return index; fiore@3: } fiore@3: fiore@3: public String getOldValue(){ fiore@3: return oldValue; fiore@3: } fiore@3: fiore@3: private String type; fiore@3: private String oldValue; fiore@3: private int index; fiore@3: } fiore@0: }