/[schmitzm]/trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
ViewVC logotype

Annotation of /trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 111 - (hide annotations)
Tue May 12 23:33:14 2009 UTC (15 years, 9 months ago) by alfonx
File MIME type: text/plain
File size: 8571 byte(s)
* Fixed some bugs with the SelectionListeners and the JMapPane. To make this work,  StyledFeatureLayerSelectionModel now extends StyledLayerSelectionModel<String>. So the selection is remembered as a Set of Feature-IDs. This change was needed, because Feature.java doesn't overwrite the equals method, and therefore the HashSet didn't function as expected.
* Added new Tools and BUttons to MapPaneToolBar.java to select features
* Changed a lot in MapPaneToolBar.java. It now allows to position Spaces, Actions and Tools via the ID field. (the new feature is to mix them)
* Fixed a bug in AV's ClickInfoPanel that would suddenly pop up an AtlasViewer if started from Geopublisher under special circumstances.
* Moving layers in the legend is using MapContext's move method instead of remove and insert.
* LayerPanel's remember* Maps now all have the MapLayer's ID as a key. 

This commit includes latest schmitzm.jar and av.jar. The av.jar is also commited to the ISDSS, but the ISDSS will still have the old schmitzm.jar. Latest schmitzm.jar in ISDSS should be updated ASAP. I just don't know where to put it.
1 mojays 102 /**
2     Copyright 2008 Stefan Alfons Krüger
3    
4 alfonx 96 atlas-framework - This file is part of the Atlas Framework
5    
6     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.
7     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.
8     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
9    
10     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.
11     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.
12     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.
13     **/
14    
15     package skrueger.geotools.selection;
16    
17     import java.beans.PropertyChangeEvent;
18 mojays 102 import java.beans.PropertyChangeListener;
19 alfonx 96 import java.util.Collection;
20     import java.util.HashSet;
21     import java.util.Set;
22     import java.util.Vector;
23    
24 mojays 102 import javax.swing.event.EventListenerList;
25    
26 alfonx 96 import org.apache.log4j.Logger;
27     import org.geotools.feature.Feature;
28    
29     import schmitzm.swing.event.PropertyChangeEmitter;
30 mojays 102 import skrueger.geotools.StyledMapInterface;
31 alfonx 96
32     /**
33 mojays 102 * This manager holds a set of objects which are <i>selected</i> for a {@link StyledMapInterface}.
34     * Several components can connect to this model to keep their selection synchronized.
35     * @see #addSelectionListener(java.beans.PropertyChangeListener)
36     * @see StyledLayerSelectionModelSynchronizer
37 alfonx 96 * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
38     */
39 mojays 102 public abstract class StyledLayerSelectionModel<E> extends PropertyChangeEmitter<StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>>> {
40 alfonx 96 /** A static logger for this class */
41 alfonx 97 protected final Logger LOGGER = Logger.getLogger(this.getClass());
42 mojays 102
43 alfonx 96 /** Indicates that the selection has changed in {@link PropertyChangeEvent}. */
44     public final static String SELECTION = "SELECTION";
45 mojays 102
46    
47     /** Holds the connected listeners. */
48     protected EventListenerList listenerList = new EventListenerList();
49    
50     /** Holds the current selection (e.g. {@link Feature Features}). */
51 alfonx 105 protected final HashSet<E> selectionObjects;
52 mojays 102
53     /** Holds the styled map whose selection is managed by this class. */
54     protected final StyledMapInterface<?> styledMap;
55    
56    
57 alfonx 96 /** Indicates whether a selection change is a part of multiple
58 mojays 102 * changes. If {@code true} {@link #refreshSelection()} has NO effect
59     * until {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
60 alfonx 96 * is called. */
61     private boolean valueIsAdjusting = false;
62    
63     /**
64 mojays 102 * Creates a new selection model.
65     * @param styledMap styled map the selection is controlled of
66 alfonx 96 */
67 mojays 102 public StyledLayerSelectionModel(StyledMapInterface<?> styledMap) {
68     this.selectionObjects = new HashSet<E>();
69     this.styledMap = styledMap;
70     }
71    
72     /**
73     * Fires an event to every connected listener to update their selection
74     * according to the selection of this model.<br>
75     * <b>Does nothing if adjusting is <code>true</code></b>.
76     */
77 alfonx 96 public void refreshSelection() {
78     if ( getValueIsAdjusting() )
79     return;
80     firePropertyChangeEvent( createSelectionChangeEvent(null) );
81     }
82 mojays 102
83 alfonx 96 /**
84     * Clears the selection and fires an event to every connected listener
85     * to update their selection.
86     */
87     public void clearSelection() {
88 mojays 102 selectionObjects.clear();
89 alfonx 96 refreshSelection();
90     }
91    
92     /**
93     * Creates a simple {@link PropertyChangeEvent} for property {@link #SELECTION}
94     * with no new and old value, just to inform the listeners THAT
95     * some selection has changed.
96     * Subclasses may overwrite this method to create more sophisticated
97     * events.
98     * @param respObject object which is responsible for the selection change; this
99     * object should ignore this event to avoid event circles (can be {@code null}
100     * in case of general refresh events; in this case all connected
101     * components will refresh their selection)
102 mojays 102 *
103 alfonx 96 */
104     public StyledLayerSelectionEvent createSelectionChangeEvent(Object respObject) {
105     if ( respObject == null )
106     respObject = this;
107     return new StyledLayerSelectionEvent(this,respObject,SELECTION,null,null);
108     }
109 mojays 102
110    
111     /**
112 alfonx 96 * Returns whether the current selection changes are a part of multiple
113 mojays 102 * changes. If {@code true} {@link #refreshSelection()} has no effect
114     * and no {@link StyledLayerSelectionEvent} is fired until
115 alfonx 96 * {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
116     * is called.
117     */
118     public boolean getValueIsAdjusting() {
119     return this.valueIsAdjusting;
120     }
121 mojays 102
122     /**
123 alfonx 96 * Sets whether the following selection changes are a part of multiple
124 mojays 102 * changes. If {@code true} {@link #refreshSelection()} has no effect
125     * and no {@link StyledLayerSelectionEvent} event is fired.
126 alfonx 96 * If the value is set from {@code true} to {@code false} an automatic
127     * refresh is initiated.
128     * @see #refreshSelection()
129     */
130     public void setValueIsAdjusting(boolean valueIsAdjusting) {
131     if ( valueIsAdjusting != this.valueIsAdjusting ) {
132     this.valueIsAdjusting = valueIsAdjusting;
133     if ( !this.valueIsAdjusting )
134     refreshSelection();
135     }
136     }
137    
138 mojays 102
139 alfonx 96 /**
140 mojays 102 * Extends the current selection by an individual object.
141     * @param selectedObject defines the (new) selected object
142 alfonx 96 * @return {@code true} if selection has changed by calling this method
143     */
144 mojays 102 public boolean addSelection(E selectedObject) {
145 alfonx 111
146 mojays 102 if ( selectionObjects.add(selectedObject) ) {
147 alfonx 96 refreshSelection();
148     return true;
149     }
150     return false;
151     }
152    
153     /**
154 mojays 102 * Removes an individual object from the current selection.
155     * @param unselectedObject defines an object which will be unselected
156 alfonx 96 * @return {@code true} if selection has changed by calling this method
157     */
158 mojays 102 public boolean removeSelection(E unselectedObject) {
159     if ( selectionObjects.remove(unselectedObject) ) {
160 alfonx 96 refreshSelection();
161     return true;
162     }
163     return false;
164     }
165    
166     /**
167 mojays 102 * Extends the current selection by individual objects.
168     * @param selectedObjects defines some objects which will be selected
169 alfonx 96 * @return {@code true} if selection has changed by calling this method
170     */
171 mojays 102 public boolean addSelection(Collection<E> selectedObjects) {
172     if ( selectionObjects.addAll(selectedObjects) ) {
173 alfonx 96 refreshSelection();
174     return true;
175     }
176     return false;
177     }
178 mojays 102
179 alfonx 96 /**
180 mojays 102 * Removes individual objects from the current selection.
181     * @param unselectedObjects defines some objects which will be unselected
182 alfonx 96 * @return {@code true} if selection has changed by calling this method
183     */
184 mojays 102 public boolean removeSelection(Collection<E> unselectedObjects) {
185     if ( selectionObjects.removeAll(unselectedObjects) ) {
186 alfonx 96 refreshSelection();
187     return true;
188     }
189     return false;
190     }
191 mojays 102
192 alfonx 96 /**
193 mojays 102 * Returns all selected objects as list.
194 alfonx 96 * @return a copy of the original list, so changes have no effect!
195     */
196     public Vector<E> getSelection() {
197 mojays 102 return new Vector<E>(selectionObjects);
198 alfonx 96 }
199    
200 mojays 102 /**
201     * Adds a listener to the listener list. Only alias for {@link #addListener(PropertyChangeListener)}.
202     * @param listener a listener
203     */
204     public void addSelectionListener(StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>> listener) {
205     this.addListener(listener);
206     }
207    
208     /**
209     * Removes a listener from the listener list. Only alias for {@link #removeListener(PropertyChangeListener)}.
210     * @param listener a listener
211     */
212     public void removeSelectionListener(StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>> listener) {
213     this.removeListener(listener);
214     }
215    
216    
217 alfonx 96 }

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