[Schmitzm-commits] r102 - trunk/src/skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri May 8 15:47:33 CEST 2009


Author: mojays
Date: 2009-05-08 15:47:33 +0200 (Fri, 08 May 2009)
New Revision: 102

Modified:
   trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
Log:


Modified: trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
===================================================================
--- trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java	2009-05-08 13:17:02 UTC (rev 101)
+++ trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java	2009-05-08 13:47:33 UTC (rev 102)
@@ -1,6 +1,6 @@
-/** 
- Copyright 2008 Stefan Alfons Krüger 
- 
+/**
+ Copyright 2008 Stefan Alfons Krüger
+
  atlas-framework - This file is part of the Atlas Framework
 
  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.
@@ -15,61 +15,77 @@
 package skrueger.geotools.selection;
 
 import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.Vector;
 
+import javax.swing.event.EventListenerList;
+
 import org.apache.log4j.Logger;
 import org.geotools.feature.Feature;
 
 import schmitzm.swing.event.PropertyChangeEmitter;
+import skrueger.geotools.StyledMapInterface;
 
 /**
- * This manager takes care of every object selection for a {@link DpLayer}
- * in the several atlas components and informs the appropriate components  
- * to keep the selection synchronized.
+ * This manager holds a set of objects which are <i>selected</i> for a {@link StyledMapInterface}.
+ * Several components can connect to this model to keep their selection synchronized.
+ * @see #addSelectionListener(java.beans.PropertyChangeListener)
+ * @see StyledLayerSelectionModelSynchronizer
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
  */
-public abstract class StyledLayerSelectionModel<E> extends PropertyChangeEmitter {
+public abstract class StyledLayerSelectionModel<E> extends PropertyChangeEmitter<StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>>> {
   /** A static logger for this class  */
   protected final Logger LOGGER = Logger.getLogger(this.getClass());
-	
-  /** Holds the current selection as {@link Feature}-list. This
-   *  is the basis to create the other selection objects. */
-  protected final Set<E> selectionFeatures;
-	
+
   /** Indicates that the selection has changed in {@link PropertyChangeEvent}. */
   public final static String SELECTION = "SELECTION";
-  
-  
+
+
+  /** Holds the connected listeners. */
+  protected EventListenerList listenerList = new EventListenerList();
+
+  /** Holds the current selection (e.g. {@link Feature Features}). */
+  protected final Set<E> selectionObjects;
+
+  /** Holds the styled map whose selection is managed by this class. */
+  protected final StyledMapInterface<?> styledMap;
+
+
   /** Indicates whether a selection change is a part of multiple
-   *  changes. If {@code true} {@link #resetSelectionObjects()} is not
-   *  called and no {@code DpLayerSelectionEvent} event is fired until
-   *  {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
+   *  changes. If {@code true} {@link #refreshSelection()} has NO effect
+   *  until {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
    *  is called. */
   private boolean valueIsAdjusting = false;
 
-  public StyledLayerSelectionModel() {
-	  this.selectionFeatures = new HashSet<E>();
-}
   /**
-   * Reset all selection objects and fires an event to every connected
-   * listener to update their selection according to the selection
-   * of this manager. <b>Does nothing if adjusting is <code>true</code></b>.
+   * Creates a new selection model.
+   * @param styledMap styled map the selection is controlled of
    */
+  public StyledLayerSelectionModel(StyledMapInterface<?> styledMap) {
+	this.selectionObjects = new HashSet<E>();
+	this.styledMap         = styledMap;
+  }
+
+  /**
+   * Fires an event to every connected listener to update their selection
+   * according to the selection of this model.<br>
+   * <b>Does nothing if adjusting is <code>true</code></b>.
+   */
   public void refreshSelection() {
     if ( getValueIsAdjusting() )
       return;
     firePropertyChangeEvent( createSelectionChangeEvent(null) );
   }
-  
+
   /**
    * Clears the selection and fires an event to every connected listener
    * to update their selection.
    */
   public void clearSelection() {
-    clearSelectionObjects();
+    selectionObjects.clear();
     refreshSelection();
   }
 
@@ -83,30 +99,30 @@
    *                   object should ignore this event to avoid event circles (can be {@code null}
    *                   in case of general refresh events; in this case all connected
    *                   components will refresh their selection)
-   *                   
+   *
    */
   public StyledLayerSelectionEvent createSelectionChangeEvent(Object respObject) {
     if ( respObject == null )
       respObject = this;
     return new StyledLayerSelectionEvent(this,respObject,SELECTION,null,null);
   }
-  
-  
-  /** 
+
+
+  /**
    * Returns whether the current selection changes are a part of multiple
-   * changes. If {@code true} {@link #resetSelectionObjects()} is not
-   * called and no {@code DpLayerSelectionEvent} event is fired until
+   * changes. If {@code true} {@link #refreshSelection()} has no effect
+   * and no {@link StyledLayerSelectionEvent} is fired until
    * {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
    * is called.
    */
   public boolean getValueIsAdjusting() {
     return this.valueIsAdjusting;
   }
-  
-  /** 
+
+  /**
    * Sets whether the following selection changes are a part of multiple
-   * changes. If {@code true} {@link #resetSelectionObjects()} is not
-   * called and no {@code DpLayerSelectionEvent} event is fired.
+   * changes. If {@code true} {@link #refreshSelection()} has no effect
+   * and no {@link StyledLayerSelectionEvent} event is fired.
    * If the value is set from {@code true} to {@code false} an automatic
    * refresh is initiated.
    * @see #refreshSelection()
@@ -118,22 +134,15 @@
         refreshSelection();
     }
   }
-  
-  /**
-   * Clears all selection objects.
-   */
-  protected void clearSelectionObjects() {
-    selectionFeatures.clear();
-    refreshSelection();
-  }
 
+
   /**
-   * Extends the current selection by an individual feature.
-   * @param feature defines a feature of the layer
+   * Extends the current selection by an individual object.
+   * @param selectedObject defines the (new) selected object
    * @return {@code true} if selection has changed by calling this method
    */
-  public boolean addSelection(E feature) {
-    if ( selectionFeatures.add(feature) ) {
+  public boolean addSelection(E selectedObject) {
+    if ( selectionObjects.add(selectedObject) ) {
       refreshSelection();
       return true;
     }
@@ -141,12 +150,12 @@
   }
 
   /**
-   * Removes an individual feature from the current selection.
-   * @param feature defines a feature of the layer
+   * Removes an individual object from the current selection.
+   * @param unselectedObject defines an object which will be unselected
    * @return {@code true} if selection has changed by calling this method
    */
-  public boolean removeSelection(E feature) {
-    if ( selectionFeatures.remove(feature) ) {
+  public boolean removeSelection(E unselectedObject) {
+    if ( selectionObjects.remove(unselectedObject) ) {
       refreshSelection();
       return true;
     }
@@ -154,38 +163,54 @@
   }
 
   /**
-   * Extends the current selection by individual features.
-   * @param features defines some features of the layer
+   * Extends the current selection by individual objects.
+   * @param selectedObjects defines some objects which will be selected
    * @return {@code true} if selection has changed by calling this method
    */
-  public boolean addSelection(Collection<E> features) {
-    if ( selectionFeatures.addAll(features) ) {
+  public boolean addSelection(Collection<E> selectedObjects) {
+    if ( selectionObjects.addAll(selectedObjects) ) {
       refreshSelection();
       return true;
     }
     return false;
   }
-  
+
   /**
-   * Removes individual features from the current selection.
-   * @param features defines some features of the layer
+   * Removes individual objects from the current selection.
+   * @param unselectedObjects defines some objects which will be unselected
    * @return {@code true} if selection has changed by calling this method
    */
-  public boolean removeSelection(Collection<E> features) {
-    if ( selectionFeatures.removeAll(features) ) {
+  public boolean removeSelection(Collection<E> unselectedObjects) {
+    if ( selectionObjects.removeAll(unselectedObjects) ) {
       refreshSelection();
       return true;
     }
     return false;
   }
-  
+
   /**
-   * Returns all selected {@link Feature Features} as list.
+   * Returns all selected objects as list.
    * @return a copy of the original list, so changes have no effect!
    */
   public Vector<E> getSelection() {
-    return new Vector<E>(selectionFeatures);
+    return new Vector<E>(selectionObjects);
   }
 
-  
+  /**
+   * Adds a listener to the listener list. Only alias for {@link #addListener(PropertyChangeListener)}.
+   * @param listener a listener
+   */
+  public void addSelectionListener(StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>> listener) {
+    this.addListener(listener);
+  }
+
+  /**
+   * Removes a listener from the listener list. Only alias for {@link #removeListener(PropertyChangeListener)}.
+   * @param listener a listener
+   */
+  public void removeSelectionListener(StyledLayerSelectionModelSynchronizer<StyledLayerSelectionModel<E>> listener) {
+    this.removeListener(listener);
+  }
+
+
 }



More information about the Schmitzm-commits mailing list