comparison java/src/uk/ac/qmul/eecs/ccmi/diagrammodel/CollectionModel.java @ 0:9418ab7b7f3f

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