# Coverage details for edu.uci.ics.jung.visualization.MultiPickedState

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | `* Copyright (c) 2005, the JUNG Project and the Regents of the University of`
3 |  | `* California All rights reserved.`
4 |  | `*`
5 |  | `* This software is open-source under the BSD license; see either "license.txt"`
6 |  | `* or http://jung.sourceforge.net/license.txt for a description.`
7 |  | `*`
8 |  | `*`
9 |  | `* Created on Mar 28, 2005`
10 |  | `*/`
11 |  | `package edu.uci.ics.jung.visualization;`
12 |  | ``
13 |  | `import java.awt.event.ItemEvent;`
14 |  | `import java.util.ArrayList;`
15 |  | `import java.util.Collection;`
16 |  | `import java.util.Collections;`
17 |  | `import java.util.Iterator;`
18 |  | `import java.util.LinkedHashSet;`
19 |  | `import java.util.LinkedList;`
20 |  | `import java.util.List;`
21 |  | `import java.util.Set;`
22 |  | ``
23 |  | `import edu.uci.ics.jung.graph.ArchetypeEdge;`
24 |  | `import edu.uci.ics.jung.graph.ArchetypeVertex;`
25 |  | `import edu.uci.ics.jung.graph.Edge;`
26 |  | `import edu.uci.ics.jung.graph.Vertex;`
27 |  | ``
28 |  | `/**`
29 |  | `* Maintains the state of what has been 'picked' in the graph.`
30 |  | `* The <code>Sets</code> are constructed so that their iterators`
31 |  | `* will traverse them in the order in which they are picked.`
32 |  | `*`
33 |  | `* @author Tom Nelson - RABA Technologies`
34 |  | `* @author Joshua O'Madadhain`
35 |  | `*`
36 |  | `*/`
37 | 0 | `public class MultiPickedState extends AbstractPickedState implements PickedState`
38 |  | `{`
39 |  | `/**`
40 |  | `* the 'picked' vertices`
41 |  | `*/`
42 | 0 | `protected Set pickedVertices = new LinkedHashSet();`
43 |  | ``
44 |  | `/**`
45 |  | `* the 'picked' edges`
46 |  | `*/`
47 | 0 | `protected Set pickedEdges = new LinkedHashSet();`
48 |  | ``
49 |  | `/**`
50 |  | `* @see PickedState#pick(ArchetypeVertex, boolean)`
51 |  | `*/`
52 |  | `public boolean pick(ArchetypeVertex v, boolean picked)`
53 |  | `{`
54 | 0 | `boolean prior_state = pickedVertices.contains(v);`
55 | 0 | `if (picked) {`
56 | 0 | `pickedVertices.add(v);`
57 | 0 | `if(prior_state == false) {`
58 | 0 | `firePickEvent(v, true);`
59 | 0 | `fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,`
60 |  | `v, ItemEvent.SELECTED));`
61 |  | `}`
62 |  | ``
63 |  | `} else {`
64 | 0 | `pickedVertices.remove(v);`
65 | 0 | `if(prior_state == true) {`
66 | 0 | `firePickEvent(v, false);`
67 | 0 | `fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,`
68 |  | `v, ItemEvent.DESELECTED));`
69 |  | `}`
70 |  | ``
71 |  | `}`
72 | 0 | `return prior_state;`
73 |  | `}`
74 |  | ``
75 |  | `/**`
76 |  | `* @see PickedState#pick(ArchetypeVertex, boolean)`
77 |  | `*/`
78 |  | `public boolean pick(ArchetypeEdge e, boolean picked)`
79 |  | `{`
80 | 0 | `boolean prior_state = pickedEdges.contains(e);`
81 | 0 | `if (picked) {`
82 | 0 | `pickedEdges.add(e);`
83 | 0 | `if(prior_state == false) {`
84 | 0 | `firePickEvent(e, true);`
85 | 0 | `fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,`
86 |  | `e, ItemEvent.SELECTED));`
87 |  | `}`
88 |  | `} else {`
89 | 0 | `pickedEdges.remove(e);`
90 | 0 | `if(prior_state == true) {`
91 | 0 | `firePickEvent(e, false);`
92 | 0 | `fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,`
93 |  | `e, ItemEvent.DESELECTED));`
94 |  | `}`
95 |  | `}`
96 | 0 | `return prior_state;`
97 |  | `}`
98 |  | ``
99 |  | `/**`
100 |  | `* @see edu.uci.ics.jung.visualization.PickedState#clearPickedVertices()`
101 |  | `*/`
102 |  | `public void clearPickedVertices()`
103 |  | `{`
104 | 0 | `Collection iterable_set = new LinkedList(pickedVertices);`
105 | 0 | `for (Iterator it = iterable_set.iterator(); it.hasNext(); )`
106 | 0 | `pick((ArchetypeVertex)it.next(), false);`
107 | 0 | `}`
108 |  | ``
109 |  | ``
110 |  | `/**`
111 |  | `* @see edu.uci.ics.jung.visualization.PickedState#clearPickedEdges()`
112 |  | `*/`
113 |  | `public void clearPickedEdges()`
114 |  | `{`
115 | 0 | `Collection iterable_set = new LinkedList(pickedEdges);`
116 | 0 | `for (Iterator it = iterable_set.iterator(); it.hasNext(); )`
117 | 0 | `pick((ArchetypeEdge)it.next(), false);`
118 | 0 | `}`
119 |  | ``
120 |  | `/**`
121 |  | `* @see edu.uci.ics.jung.visualization.PickedState#getPickedEdges()`
122 |  | `*/`
123 |  | `public Set getPickedEdges() {`
124 | 0 | `return Collections.unmodifiableSet(pickedEdges);`
125 |  | `}`
126 |  | ``
127 |  | `/**`
128 |  | `* @see edu.uci.ics.jung.visualization.PickedState#isPicked(ArchetypeEdge)`
129 |  | `*/`
130 |  | `public boolean isPicked(ArchetypeEdge e) {`
131 | 0 | `return pickedEdges.contains(e);`
132 |  | `}`
133 |  | ``
134 |  | `/**`
135 |  | `* @see edu.uci.ics.jung.visualization.PickedState#getPickedVertices()`
136 |  | `*/`
137 |  | `public Set getPickedVertices() {`
138 | 0 | `return Collections.unmodifiableSet(pickedVertices);`
139 |  | `}`
140 |  | ``
141 |  | `/**`
142 |  | `* @see edu.uci.ics.jung.visualization.PickedState#isPicked(ArchetypeVertex)`
143 |  | `*/`
144 |  | `public boolean isPicked(ArchetypeVertex v)`
145 |  | `{`
146 | 0 | `return pickedVertices.contains(v);`
147 |  | `}`
148 |  | ``
149 |  | `/**`
150 |  | `* @deprecated Use addItemListener`
151 |  | `* @see edu.uci.ics.jung.visualization.PickedState#addListener(edu.uci.ics.jung.visualization.PickEventListener)`
152 |  | `*/`
153 |  | `public void addListener(PickEventListener pel)`
154 |  | `{`
155 | 0 | `listenerList.add(PickEventListener.class, pel);`
156 | 0 | `}`
157 |  | ``
158 |  | `/**`
159 |  | `* @deprecated Use removeItemListener`
160 |  | `* @see edu.uci.ics.jung.visualization.PickedState#removeListener(edu.uci.ics.jung.visualization.PickEventListener)`
161 |  | `*/`
162 |  | `public void removeListener(PickEventListener pel)`
163 |  | `{`
164 | 0 | `listenerList.remove(PickEventListener.class, pel);`
165 | 0 | `}`
166 |  | ``
167 |  | `/**`
168 |  | `* @see #isPicked(ArchetypeVertex)`
169 |  | `*/`
170 |  | `public boolean isPicked(Vertex v)`
171 |  | `{`
172 | 0 | `return pickedVertices.contains(v);`
173 |  | `}`
174 |  | ``
175 |  | `/**`
176 |  | `* @see #isPicked(ArchetypeEdge)`
177 |  | `*/`
178 |  | `public boolean isPicked(Edge e)`
179 |  | `{`
180 | 0 | `return pickedEdges.contains(e);`
181 |  | `}`
182 |  | ``
183 |  | `/**`
184 |  | `* for the ItemSelectable interface contract`
185 |  | `*/`
186 |  | `public Object[] getSelectedObjects() {`
187 | 0 | `List list = new ArrayList(pickedVertices);`
188 | 0 | `list.addAll(pickedEdges);`
189 | 0 | `return list.toArray();`
190 |  | `}`
191 |  | ``
192 |  | `protected void firePickEvent(Object object, boolean picked) {`
193 | 0 | `Object[] listeners = listenerList.getListenerList();`
194 | 0 | `for ( int i = listeners.length-2; i>=0; i-=2 ) {`
195 | 0 | `if ( listeners[i]==PickEventListener.class ) {`
196 | 0 | `if(object instanceof Vertex) {`
197 | 0 | `if(picked) {`
198 | 0 | `((PickEventListener)listeners[i+1]).vertexPicked((Vertex)object);`
199 |  | `} else {`
200 | 0 | `((PickEventListener)listeners[i+1]).vertexUnpicked((Vertex)object);`
201 |  | `}`
202 |  | `} else {`
203 | 0 | `if(picked) {`
204 | 0 | `((PickEventListener)listeners[i+1]).edgePicked((Edge)object);`
205 |  | `} else {`
206 | 0 | `((PickEventListener)listeners[i+1]).edgeUnpicked((Edge)object);`
207 |  | `}`
208 |  | ``
209 |  | `}`
210 |  | `}`
211 |  | `}`
212 | 0 | `}`
213 |  | `}`

this report was generated by version 1.0.5 of jcoverage. visit www.jcoverage.com for updates. | copyright © 2003, jcoverage ltd. all rights reserved. Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.