annotate java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/CollectionModel.java @ 1:e3935c01cde2 tip

moved license of PdPersistenceManager to the beginning of the file
author Fiore Martin <f.martin@qmul.ac.uk>
date Tue, 08 Jul 2014 19:52:03 +0100
parents 78b7fc5391a2
children
rev   line source
f@0 1 /*
f@0 2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
f@0 3
f@0 4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
f@0 5
f@0 6 This program is free software: you can redistribute it and/or modify
f@0 7 it under the terms of the GNU General Public License as published by
f@0 8 the Free Software Foundation, either version 3 of the License, or
f@0 9 (at your option) any later version.
f@0 10
f@0 11 This program is distributed in the hope that it will be useful,
f@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
f@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@0 14 GNU General Public License for more details.
f@0 15
f@0 16 You should have received a copy of the GNU General Public License
f@0 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
f@0 18 */
f@0 19 package uk.ac.qmul.eecs.ccmi.diagrammodel;
f@0 20
f@0 21 import java.util.Collection;
f@0 22 import java.util.concurrent.locks.ReentrantLock;
f@0 23
f@0 24 import javax.swing.event.ChangeListener;
f@0 25
f@0 26 /**
f@0 27 *
f@0 28 * Represents the collection side of a DiagramModel instance.
f@0 29 *
f@0 30 * @param <N> a type extending DiagramNode
f@0 31 * @param <E> a type extending DiagramEdge
f@0 32 */
f@0 33 public interface CollectionModel<N extends DiagramNode, E extends DiagramEdge> {
f@0 34 /**
f@0 35 * Adds a collection listener to the model.
f@0 36 * @param listener the listener to be added
f@0 37 */
f@0 38 void addCollectionListener(CollectionListener listener);
f@0 39 /**
f@0 40 * Removed a collection listener to the model.
f@0 41 * @param listener the listener to be removed
f@0 42 */
f@0 43 void removeCollectionListener (CollectionListener listener);
f@0 44
f@0 45 /**
f@0 46 * insert a DiagramNode into the diagram model
f@0 47 * @param n the DiagramNode to be inserted in the collection
f@0 48 * @param source the source of the action. This will be reported as the source of the event
f@0 49 * generated by this action to the registered listeners. If null the CollectionModel instance
f@0 50 * itself will be used as source
f@0 51 * @return true if this collection changed as a result of the call
f@0 52 */
f@0 53 boolean insert(N n, Object source) ;
f@0 54
f@0 55 /**
f@0 56 * insert a DiagramEdge into the diagram model
f@0 57 * @param e the DiagramNode to be inserted in the collection
f@0 58 * @param source the source of the action. This will be reported as the source of the event
f@0 59 * generated by this action to the registered listeners. If null the CollectionModel instance
f@0 60 * itself will be used as source
f@0 61 * @return true if this collection changed as a result of the call
f@0 62 */
f@0 63 boolean insert(E e, Object source);
f@0 64
f@0 65 /**
f@0 66 * Removes a DiagramElement from the model
f@0 67 * @param e the diagramElement to be removed
f@0 68 * @param source the source of the action. This will be reported as the source of the event
f@0 69 * generated by this action to the registered listeners. If null the CollectionModel instance
f@0 70 * itself will be used as source
f@0 71 * @return true if this collection changed as a result of the call
f@0 72 */
f@0 73 boolean takeOut(DiagramElement e, Object source);
f@0 74
f@0 75 /**
f@0 76 * Returns the diagram nodes contained by the model as a collection
f@0 77 * @return the collection of diagram nodes
f@0 78 */
f@0 79 Collection<N> getNodes();
f@0 80
f@0 81 /**
f@0 82 * Returns the diagram edges contained by the model as a collection
f@0 83 * @return the collection of diagram edges
f@0 84 */
f@0 85 Collection<E> getEdges();
f@0 86
f@0 87 /**
f@0 88 * return a list of nodes and edges in the model as a unique collection
f@0 89 * of diagram elements.
f@0 90 * @return the collection of diagram elements
f@0 91 */
f@0 92 Collection<DiagramElement> getElements();
f@0 93
f@0 94 /**
f@0 95 * Add a change listener to the model. the listeners will be fired each time the model
f@0 96 * goes from the unmodified to modified state. The model is modified when a either a
f@0 97 * node or an edge are inserted or removed or changed when they are within the model.
f@0 98 * @param l a ChangeListener to add to the model
f@0 99 */
f@0 100 void addChangeListener(ChangeListener l);
f@0 101
f@0 102 /**
f@0 103 * Removes a change listener from the model.
f@0 104 * @param l a ChangeListener to remove from the model
f@0 105 */
f@0 106 void removeChangeListener(ChangeListener l);
f@0 107
f@0 108 /**
f@0 109 * Returns true if the model has been modified
f@0 110 * @return true if the model has been modified
f@0 111 */
f@0 112 boolean isModified();
f@0 113
f@0 114 /**
f@0 115 * Sets the model as unmodified. This entails that {@link #isModified()} will return
f@0 116 * false unless the model doesn't get modified again. After this call a new modification
f@0 117 * of the model would trigger the associated change listeners again.
f@0 118 */
f@0 119 void setUnmodified();
f@0 120
f@0 121 /**
f@0 122 * Sorts the nodes and edges is the model. The ordering method is given by a diagram
f@0 123 * element comparator.
f@0 124 * @see DiagramElementComparator
f@0 125 */
f@0 126 void sort();
f@0 127
f@0 128 /**
f@0 129 * Returns a reentrant lock that can be used to access the nodes and edges via {@code getNodes()}
f@0 130 * and {@code getEdges()} and the change methods in a synchronized fashion.
f@0 131 * @return a lock object
f@0 132 */
f@0 133 ReentrantLock getMonitor();
f@0 134
f@0 135 }