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.Collection;
fiore@3: import java.util.concurrent.locks.ReentrantLock;
fiore@0:
fiore@0: import javax.swing.event.ChangeListener;
fiore@0:
fiore@0: /**
fiore@0: *
fiore@0: * Represents the collection side of a DiagramModel instance.
fiore@0: *
fiore@0: * @param a type extending DiagramNode
fiore@0: * @param a type extending DiagramEdge
fiore@0: */
fiore@0: public interface CollectionModel {
fiore@0: /**
fiore@0: * Adds a collection listener to the model.
fiore@0: * @param listener the listener to be added
fiore@0: */
fiore@0: void addCollectionListener(CollectionListener listener);
fiore@0: /**
fiore@0: * Removed a collection listener to the model.
fiore@0: * @param listener the listener to be removed
fiore@0: */
fiore@0: void removeCollectionListener (CollectionListener listener);
fiore@0:
fiore@0: /**
fiore@0: * insert a DiagramNode into the diagram model
fiore@0: * @param n the DiagramNode to be inserted in the collection
fiore@3: * @param source the source of the action. This will be reported as the source of the event
fiore@3: * generated by this action to the registered listeners. If null the CollectionModel instance
fiore@3: * itself will be used as source
fiore@0: * @return true if this collection changed as a result of the call
fiore@0: */
fiore@3: boolean insert(N n, Object source) ;
fiore@0:
fiore@0: /**
fiore@0: * insert a DiagramEdge into the diagram model
fiore@0: * @param e the DiagramNode to be inserted in the collection
fiore@3: * @param source the source of the action. This will be reported as the source of the event
fiore@3: * generated by this action to the registered listeners. If null the CollectionModel instance
fiore@3: * itself will be used as source
fiore@0: * @return true if this collection changed as a result of the call
fiore@0: */
fiore@3: boolean insert(E e, Object source);
fiore@0:
fiore@0: /**
fiore@0: * Removes a DiagramElement from the model
fiore@0: * @param e the diagramElement to be removed
fiore@3: * @param source the source of the action. This will be reported as the source of the event
fiore@3: * generated by this action to the registered listeners. If null the CollectionModel instance
fiore@3: * itself will be used as source
fiore@0: * @return true if this collection changed as a result of the call
fiore@0: */
fiore@3: boolean takeOut(DiagramElement e, Object source);
fiore@0:
fiore@0: /**
fiore@3: * Returns the diagram nodes contained by the model as a collection
fiore@0: * @return the collection of diagram nodes
fiore@0: */
fiore@0: Collection getNodes();
fiore@0:
fiore@0: /**
fiore@3: * Returns the diagram edges contained by the model as a collection
fiore@0: * @return the collection of diagram edges
fiore@0: */
fiore@0: Collection getEdges();
fiore@0:
fiore@0: /**
fiore@0: * return a list of nodes and edges in the model as a unique collection
fiore@3: * of diagram elements.
fiore@3: * @return the collection of diagram elements
fiore@0: */
fiore@0: Collection getElements();
fiore@0:
fiore@0: /**
fiore@0: * Add a change listener to the model. the listeners will be fired each time the model
fiore@0: * goes from the unmodified to modified state. The model is modified when a either a
fiore@0: * node or an edge are inserted or removed or changed when they are within the model.
fiore@0: * @param l a ChangeListener to add to the model
fiore@0: */
fiore@0: void addChangeListener(ChangeListener l);
fiore@0:
fiore@0: /**
fiore@0: * Removes a change listener from the model.
fiore@0: * @param l a ChangeListener to remove from the model
fiore@0: */
fiore@0: void removeChangeListener(ChangeListener l);
fiore@0:
fiore@0: /**
fiore@0: * Returns true if the model has been modified
fiore@0: * @return true if the model has been modified
fiore@0: */
fiore@0: boolean isModified();
fiore@0:
fiore@0: /**
fiore@0: * Sets the model as unmodified. This entails that {@link #isModified()} will return
fiore@0: * false unless the model doesn't get modified again. After this call a new modification
fiore@0: * of the model would trigger the associated change listeners again.
fiore@0: */
fiore@0: void setUnmodified();
fiore@0:
fiore@0: /**
fiore@0: * Sorts the nodes and edges is the model. The ordering method is given by a diagram
fiore@0: * element comparator.
fiore@0: * @see DiagramElementComparator
fiore@0: */
fiore@0: void sort();
fiore@0:
fiore@0: /**
fiore@3: * Returns a reentrant lock that can be used to access the nodes and edges via {@code getNodes()}
fiore@3: * and {@code getEdges()} and the change methods in a synchronized fashion.
fiore@3: * @return a lock object
fiore@0: */
fiore@3: ReentrantLock getMonitor();
fiore@0:
fiore@0: }