/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
ViewVC logotype

Contents of /branches/1.0-gt2-2.6/src/skrueger/geotools/selection/StyledLayerSelectionModel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 428 - (show annotations)
Sun Oct 4 14:28:07 2009 UTC (15 years, 5 months ago) by alfonx
File MIME type: text/plain
File size: 10070 byte(s)
* Changed the constructor of AttributetableDialog to be more standard
* StyledFeatureCollectionTableModel now uses the Filter from StyledFeaturesInterface
* Created a test case for AttributeTableJDialog
1 /*******************************************************************************
2 * Copyright (c) 2009 Martin O. J. Schmitz.
3 *
4 * This file is part of the SCHMITZM library - a collection of utility
5 * classes based on Java 1.6, focusing (not only) on Java Swing
6 * and the Geotools library.
7 *
8 * The SCHMITZM project is hosted at:
9 * http://wald.intevation.org/projects/schmitzm/
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License (license.txt)
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * or try this link: http://www.gnu.org/licenses/lgpl.html
25 *
26 * Contributors:
27 * Martin O. J. Schmitz - initial API and implementation
28 * Stefan A. Krüger - additional utility classes
29 ******************************************************************************/
30 /**
31 Copyright 2008 Stefan Alfons Krüger
32
33 atlas-framework - This file is part of the Atlas Framework
34
35 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
36 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
37 You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
38
39 Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
40 Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
41 Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
42 **/
43
44 package skrueger.geotools.selection;
45
46 import java.beans.PropertyChangeEvent;
47 import java.beans.PropertyChangeListener;
48 import java.util.Collection;
49 import java.util.HashSet;
50 import java.util.Vector;
51
52 import javax.swing.event.EventListenerList;
53
54 import org.apache.log4j.Logger;
55 import org.opengis.feature.simple.SimpleFeature;
56
57 import schmitzm.swing.event.PropertyChangeEmitter;
58 import skrueger.geotools.StyledLayerInterface;
59
60 /**
61 * This manager holds a set of objects which are <i>selected</i> for a {@link StyledLayerInterface}.
62 * Several components can connect to this model to keep their selection synchronized.
63 * @see #addSelectionListener(java.beans.PropertyChangeListener)
64 * @see StyledLayerSelectionModelSynchronizer
65 * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
66 */
67 public abstract class StyledLayerSelectionModel<E> extends PropertyChangeEmitter<StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>>> {
68 /** A static logger for this class */
69 protected final Logger LOGGER = Logger.getLogger(this.getClass());
70
71 /** Indicates that the selection has changed in {@link PropertyChangeEvent}. */
72 public final static String SELECTION = "SELECTION";
73
74
75 /** Holds the connected listeners. */
76 protected EventListenerList listenerList = new EventListenerList();
77
78 /** Holds the current selection (e.g. {@link SimpleFeature Features}). */
79 protected final HashSet<E> selectionObjects;
80
81 /** Holds the styled map whose selection is managed by this class. */
82 private final StyledLayerInterface<?> styledLayer;
83
84
85 /** Indicates whether a selection change is a part of multiple
86 * changes. If {@code true} {@link #refreshSelection()} has NO effect
87 * until {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
88 * is called. */
89 private boolean valueIsAdjusting = false;
90
91 /**
92 * Creates a new selection model.
93 * @param styledLayer styled layer the selection is controlled of
94 */
95 public StyledLayerSelectionModel(StyledLayerInterface<?> styledLayer) {
96 this.selectionObjects = new HashSet<E>();
97 this.styledLayer = styledLayer;
98 }
99
100 /**
101 * Fires an event to every connected listener to update their selection
102 * according to the selection of this model.<br>
103 * <b>Does nothing if adjusting is <code>true</code></b>.
104 */
105 public void refreshSelection() {
106 if ( getValueIsAdjusting() )
107 return;
108 firePropertyChangeEvent( createSelectionChangeEvent(null) );
109 }
110
111 /**
112 * Clears the selection and fires an event to every connected listener
113 * to update their selection.
114 */
115 public void clearSelection() {
116 selectionObjects.clear();
117 refreshSelection();
118 }
119
120 /**
121 * Creates a simple {@link PropertyChangeEvent} for property {@link #SELECTION}
122 * with no new and old value, just to inform the listeners THAT
123 * some selection has changed.
124 * Subclasses may overwrite this method to create more sophisticated
125 * events.
126 * @param respObject object which is responsible for the selection change; this
127 * object should ignore this event to avoid event circles (can be {@code null}
128 * in case of general refresh events; in this case all connected
129 * components will refresh their selection)
130 *
131 */
132 public StyledLayerSelectionEvent createSelectionChangeEvent(Object respObject) {
133 if ( respObject == null )
134 respObject = this;
135 return new StyledLayerSelectionEvent(this,respObject,SELECTION,null,null);
136 }
137
138
139 /**
140 * Returns whether the current selection change is a part of multiple
141 * changes. If {@code true} {@link #refreshSelection()} has no effect
142 * and no {@link StyledLayerSelectionEvent} is fired until
143 * {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
144 * is called.
145 */
146 public boolean getValueIsAdjusting() {
147 return this.valueIsAdjusting;
148 }
149
150 /**
151 * Sets whether the following selection changes are part of multiple
152 * changes. If {@code true} {@link #refreshSelection()} has no effect
153 * and no {@link StyledLayerSelectionEvent} event is fired.
154 * If the value is set from {@code true} to {@code false} an automatic
155 * refresh is initiated.
156 * @see #refreshSelection()
157 */
158 public void setValueIsAdjusting(boolean valueIsAdjusting) {
159 if ( valueIsAdjusting != this.valueIsAdjusting ) {
160 this.valueIsAdjusting = valueIsAdjusting;
161 if ( !this.valueIsAdjusting )
162 refreshSelection();
163 }
164 }
165
166
167 /**
168 * Extends the current selection by an individual object.
169 * @param selectedObject defines the (new) selected object
170 * @return {@code true} if selection has changed by calling this method
171 */
172 public boolean addSelection(E selectedObject) {
173
174 if ( selectionObjects.add(selectedObject) ) {
175 refreshSelection();
176 return true;
177 }
178 return false;
179 }
180
181 /**
182 * Removes an individual object from the current selection.
183 * @param unselectedObject defines an object which will be unselected
184 * @return {@code true} if selection has changed by calling this method
185 */
186 public boolean removeSelection(E unselectedObject) {
187 if ( selectionObjects.remove(unselectedObject) ) {
188 refreshSelection();
189 return true;
190 }
191 return false;
192 }
193
194 /**
195 * Extends the current selection by individual objects.
196 * @param selectedObjects defines some objects which will be selected
197 * @return {@code true} if selection has changed by calling this method
198 */
199 public boolean addSelection(Collection<E> selectedObjects) {
200 if ( selectionObjects.addAll(selectedObjects) ) {
201 refreshSelection();
202 return true;
203 }
204 return false;
205 }
206
207 /**
208 * Removes individual objects from the current selection.
209 * @param unselectedObjects defines some objects which will be unselected
210 * @return {@code true} if selection has changed by calling this method
211 */
212 public boolean removeSelection(Collection<E> unselectedObjects) {
213 if ( selectionObjects.removeAll(unselectedObjects) ) {
214 refreshSelection();
215 return true;
216 }
217 return false;
218 }
219
220 /**
221 * Returns all selected objects as list.
222 * @return a copy of the original list, so changes have no effect!
223 */
224 public Vector<E> getSelection() {
225 return new Vector<E>(selectionObjects);
226 }
227
228 /**
229 * Adds a listener to the listener list. Only alias for {@link #addListener(PropertyChangeListener)}.
230 * @param listener a listener
231 */
232 public void addSelectionListener(StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>> listener) {
233 this.addListener(listener);
234 }
235
236 /**
237 * Removes a listener from the listener list. Only alias for {@link #removeListener(PropertyChangeListener)}.
238 * @param listener a listener
239 */
240 public void removeSelectionListener(StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>> listener) {
241 this.removeListener(listener);
242 }
243
244 public StyledLayerInterface<?> getStyledLayer() {
245 return styledLayer;
246 }
247
248
249 }

Properties

Name Value
svn:eol-style native
svn:keywords Id
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26