/[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 97 - (hide annotations)
Fri May 8 12:10:42 2009 UTC (15 years, 9 months ago) by alfonx
File MIME type: text/plain
File size: 7473 byte(s)
(Hacking Session in action - atomic commits can't be ensured)
- Remodeling the SelectionModels
1 alfonx 96 /**
2     Copyright 2008 Stefan Alfons Krüger
3    
4     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     import java.util.Collection;
19     import java.util.HashSet;
20     import java.util.Set;
21     import java.util.Vector;
22    
23     import org.apache.log4j.Logger;
24     import org.geotools.feature.Feature;
25    
26     import schmitzm.swing.event.PropertyChangeEmitter;
27    
28     /**
29     * This manager takes care of every object selection for a {@link DpLayer}
30     * in the several atlas components and informs the appropriate components
31     * to keep the selection synchronized.
32     * @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany)
33     */
34     public abstract class StyledLayerSelectionModel<E> extends PropertyChangeEmitter {
35     /** A static logger for this class */
36 alfonx 97 protected final Logger LOGGER = Logger.getLogger(this.getClass());
37 alfonx 96
38     /** Holds the current selection as {@link Feature}-list. This
39     * is the basis to create the other selection objects. */
40     protected final Set<E> selectionFeatures;
41    
42     /** Indicates that the selection has changed in {@link PropertyChangeEvent}. */
43     public final static String SELECTION = "SELECTION";
44    
45    
46     /** Indicates whether a selection change is a part of multiple
47     * changes. If {@code true} {@link #resetSelectionObjects()} is not
48     * called and no {@code DpLayerSelectionEvent} event is fired until
49     * {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
50     * is called. */
51     private boolean valueIsAdjusting = false;
52    
53     public StyledLayerSelectionModel() {
54     this.selectionFeatures = new HashSet<E>();
55     }
56     /**
57     * Reset all selection objects and fires an event to every connected
58     * listener to update their selection according to the selection
59     * of this manager. <b>Does nothing if adjusting is <code>true</code></b>.
60     */
61     public void refreshSelection() {
62     if ( getValueIsAdjusting() )
63     return;
64     firePropertyChangeEvent( createSelectionChangeEvent(null) );
65     }
66    
67     /**
68     * Clears the selection and fires an event to every connected listener
69     * to update their selection.
70     */
71     public void clearSelection() {
72     clearSelectionObjects();
73     refreshSelection();
74     }
75    
76     /**
77     * Creates a simple {@link PropertyChangeEvent} for property {@link #SELECTION}
78     * with no new and old value, just to inform the listeners THAT
79     * some selection has changed.
80     * Subclasses may overwrite this method to create more sophisticated
81     * events.
82     * @param respObject object which is responsible for the selection change; this
83     * object should ignore this event to avoid event circles (can be {@code null}
84     * in case of general refresh events; in this case all connected
85     * components will refresh their selection)
86     *
87     */
88     public StyledLayerSelectionEvent createSelectionChangeEvent(Object respObject) {
89     if ( respObject == null )
90     respObject = this;
91     return new StyledLayerSelectionEvent(this,respObject,SELECTION,null,null);
92     }
93    
94    
95     /**
96     * Returns whether the current selection changes are a part of multiple
97     * changes. If {@code true} {@link #resetSelectionObjects()} is not
98     * called and no {@code DpLayerSelectionEvent} event is fired until
99     * {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
100     * is called.
101     */
102     public boolean getValueIsAdjusting() {
103     return this.valueIsAdjusting;
104     }
105    
106     /**
107     * Sets whether the following selection changes are a part of multiple
108     * changes. If {@code true} {@link #resetSelectionObjects()} is not
109     * called and no {@code DpLayerSelectionEvent} event is fired.
110     * If the value is set from {@code true} to {@code false} an automatic
111     * refresh is initiated.
112     * @see #refreshSelection()
113     */
114     public void setValueIsAdjusting(boolean valueIsAdjusting) {
115     if ( valueIsAdjusting != this.valueIsAdjusting ) {
116     this.valueIsAdjusting = valueIsAdjusting;
117     if ( !this.valueIsAdjusting )
118     refreshSelection();
119     }
120     }
121    
122     /**
123     * Clears all selection objects.
124     */
125     protected void clearSelectionObjects() {
126     selectionFeatures.clear();
127     refreshSelection();
128     }
129    
130     /**
131     * Extends the current selection by an individual feature.
132     * @param feature defines a feature of the layer
133     * @return {@code true} if selection has changed by calling this method
134     */
135     public boolean addSelection(E feature) {
136     if ( selectionFeatures.add(feature) ) {
137     refreshSelection();
138     return true;
139     }
140     return false;
141     }
142    
143     /**
144     * Removes an individual feature from the current selection.
145     * @param feature defines a feature of the layer
146     * @return {@code true} if selection has changed by calling this method
147     */
148     public boolean removeSelection(E feature) {
149     if ( selectionFeatures.remove(feature) ) {
150     refreshSelection();
151     return true;
152     }
153     return false;
154     }
155    
156     /**
157     * Extends the current selection by individual features.
158     * @param features defines some features of the layer
159     * @return {@code true} if selection has changed by calling this method
160     */
161     public boolean addSelection(Collection<E> features) {
162     if ( selectionFeatures.addAll(features) ) {
163     refreshSelection();
164     return true;
165     }
166     return false;
167     }
168    
169     /**
170     * Removes individual features from the current selection.
171     * @param features defines some features of the layer
172     * @return {@code true} if selection has changed by calling this method
173     */
174     public boolean removeSelection(Collection<E> features) {
175     if ( selectionFeatures.removeAll(features) ) {
176     refreshSelection();
177     return true;
178     }
179     return false;
180     }
181    
182     /**
183     * Returns all selected {@link Feature Features} as list.
184     * @return a copy of the original list, so changes have no effect!
185     */
186     public Vector<E> getSelection() {
187     return new Vector<E>(selectionFeatures);
188     }
189    
190    
191     }

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