[Schmitzm-commits] r402 - trunk/src/schmitzm/geotools/gui

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Sep 14 15:16:12 CEST 2009


Author: mojays
Date: 2009-09-14 15:16:11 +0200 (Mon, 14 Sep 2009)
New Revision: 402

Modified:
   trunk/src/schmitzm/geotools/gui/JMapPane.java
Log:
Reference to AttributeMetaData replaces by general is/setMapLayerSelectable(.)

Modified: trunk/src/schmitzm/geotools/gui/JMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-09-14 13:15:51 UTC (rev 401)
+++ trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-09-14 13:16:11 UTC (rev 402)
@@ -60,6 +60,7 @@
 import org.geotools.coverage.grid.GridGeometry2D;
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
 import org.geotools.coverage.grid.io.AbstractGridFormat;
+import org.geotools.coverage.io.AbstractGridCoverageReader;
 import org.geotools.data.FeatureSource;
 import org.geotools.data.memory.MemoryFeatureCollection;
 import org.geotools.factory.GeoTools;
@@ -79,9 +80,9 @@
 import org.geotools.map.DefaultMapContext;
 import org.geotools.map.MapContext;
 import org.geotools.map.MapLayer;
+import org.geotools.map.event.MapLayerListEvent;
 import org.geotools.parameter.Parameter;
 import org.geotools.referencing.CRS;
-import org.geotools.referencing.crs.DefaultGeographicCRS;
 import org.geotools.renderer.GTRenderer;
 import org.geotools.renderer.lite.RendererUtilities;
 import org.geotools.renderer.lite.StreamingRenderer;
@@ -99,7 +100,6 @@
 import org.opengis.referencing.operation.TransformException;
 
 import schmitzm.geotools.FilterUtil;
-import schmitzm.geotools.GTUtil;
 import schmitzm.geotools.JTSUtil;
 import schmitzm.geotools.grid.GridUtil;
 import schmitzm.geotools.io.GeoImportUtil;
@@ -110,11 +110,10 @@
 import schmitzm.geotools.map.event.JMapPaneEvent;
 import schmitzm.geotools.map.event.JMapPaneListener;
 import schmitzm.geotools.map.event.MapAreaChangedEvent;
+import schmitzm.geotools.map.event.MapLayerListAdapter;
 import schmitzm.geotools.map.event.ScaleChangedEvent;
 import schmitzm.geotools.styling.StylingUtil;
 import schmitzm.swing.SwingUtil;
-import skrueger.AttributeMetaData;
-import skrueger.geotools.StyledLayerUtil;
 
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
@@ -351,8 +350,10 @@
 	/** An (transparent) image to paint over the map in the lower right corner **/
 	private BufferedImage mapImage = null;
 
-	/** A cache to optionally supply AttributeMetaData to the {@link JMapPane}. */
-	final protected HashMap<String, Map<Integer, AttributeMetaData>> attributeMetaDataMapCache = new HashMap<String, Map<Integer, AttributeMetaData>>();
+    /** Holds a flag for each layer, whether it is regarded or ignored on 
+     *  {@link #SELECT_TOP}, {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP}
+     *  actions. */
+    protected HashMap<MapLayer, Boolean> mapLayerSelectable = new HashMap<MapLayer, Boolean>();
 
 	/**
 	 * Erzeugt ein neues MapPane.
@@ -562,6 +563,20 @@
 						}
 					}
 				});
+        // The default is to regard a layer on selection
+        // actions
+        getContext().addMapLayerListListener(
+            new MapLayerListAdapter() {
+              @Override
+              public void layerAdded(MapLayerListEvent e) {
+                setMapLayerSelectable(e.getLayer(),true);
+              }
+              @Override
+              public void layerRemoved(MapLayerListEvent e) {
+                // remove reference to layer
+                mapLayerSelectable.remove(e.getLayer());
+              }
+        });
 	}
 
 	/**
@@ -1541,27 +1556,13 @@
 			MapLayer layer = layerList[i];
 			if (!layer.isVisible())
 				continue;
+            if ( !isMapLayerSelectable(layer) ) {
+              LOGGER.debug("Ignoring layer " + layer.getTitle() + " because it is not declared as selectable!");
+              continue;
+            }
 
-			if (attributeMetaDataMapCache.containsKey(layer.getTitle())) {
-				/* AttributeMetaData is available... */
-				Map<Integer, AttributeMetaData> amdMap = attributeMetaDataMapCache
-						.get(layer.getTitle());
-
-				if (StyledLayerUtil.getVisibleAttributeMetaData(amdMap, true)
-						.size() == 0) {
-					LOGGER.debug("Ignoring layer " + layer.getTitle()
-							+ " because it has no visible attributes");
-					continue;
-				}
-			}
-
 			LOGGER.debug("mode = " + mode);
 
-			/*
-			 * SK: Change! If AttributeMetadata is provided, we check whether
-			 * any attribute is
-			 */
-
 			// Bei einem Raster-Layer, das die BB schneidet, abbrechen, wenn nur
 			// im obersten (sichtbaren) Layer gesucht wird.
 			// Ansonsten Raster-Layer einfach uebergehen.
@@ -2707,16 +2708,26 @@
 
 	}
 
-	/**
-	 * Allows to optionally supply the {@link JMapPane} with meta information
-	 * about layers. This is used (when supplied) for the algorithm that selects
-	 * features with a mouse click.
-	 * 
-	 * @param layerID
-	 * @param atm
-	 */
-	public void setAttributeMetaDataFor(String layerID,
-			Map<Integer, AttributeMetaData> aMDMap) {
-		attributeMetaDataMapCache.put(layerID, aMDMap);
-	}
+    /**
+     * Sets whether a layer is regarded or ignored on 
+     * {@link #SELECT_TOP}, {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP}
+     * actions. 
+     * @param layer a layer
+     * @param selectable if {@code false} the layer is ignored during the
+     *        upper mentioned actions
+     */
+    public void setMapLayerSelectable(MapLayer layer, boolean selectable) {
+      mapLayerSelectable.put(layer, selectable);
+    }
+
+    /**
+     * Returns whether a layer is regarded or ignored on 
+     * {@link #SELECT_TOP}, {@link #SELECT_ALL} and {@link #SELECT_ONE_FROM_TOP}
+     * actions. 
+     * @param layer a layer
+     */
+    public boolean isMapLayerSelectable(MapLayer layer) {
+      Boolean selectable = mapLayerSelectable.get(layer);
+      return selectable != null && selectable;
+    }
 }



More information about the Schmitzm-commits mailing list