[Schmitzm-commits] r455 - branches/1.0-gt2-2.6/src/skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Oct 11 23:41:54 CEST 2009


Author: alfonx
Date: 2009-10-11 23:41:53 +0200 (Sun, 11 Oct 2009)
New Revision: 455

Modified:
   branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
* Feature iterator has to be closed!

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-10-11 16:12:05 UTC (rev 454)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-10-11 21:41:53 UTC (rev 455)
@@ -55,6 +55,7 @@
 import javax.swing.ListSelectionModel;
 import javax.swing.event.ListSelectionListener;
 
+import org.geotools.feature.FeatureCollection;
 import org.geotools.map.MapLayer;
 import org.geotools.renderer.GTRenderer;
 import org.geotools.renderer.label.LabelCacheImpl;
@@ -63,6 +64,7 @@
 import org.geotools.styling.Style;
 import org.geotools.styling.visitor.DuplicatingStyleVisitor;
 import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.filter.identity.FeatureId;
 
 import schmitzm.geotools.FilterUtil;
@@ -120,7 +122,8 @@
 	public FeatureMapLayerSelectionSynchronizer(
 			StyledFeatureLayerSelectionModel layerSelModel,
 			StyledLayerInterface<?> styledLayer, MapLayer mapLayer,
-			JMapPane mapPane, MapPaneToolBar toolBar, HashMap<Object, Object> defaultGTRenderingHints) {
+			JMapPane mapPane, MapPaneToolBar toolBar,
+			HashMap<Object, Object> defaultGTRenderingHints) {
 
 		super(layerSelModel);
 		this.styledLayer = styledLayer;
@@ -130,7 +133,7 @@
 		this.toolBar = toolBar;
 		if (defaultGTRenderingHints != null)
 			this.defaultGTRenderingHints = defaultGTRenderingHints;
-		else 
+		else
 			this.defaultGTRenderingHints = new HashMap<Object, Object>();
 	}
 
@@ -181,22 +184,22 @@
 	 */
 	private void changeLayerStyle(final Vector<String> newSelection) {
 		try {
-			
+
 			Style originalStyle = mapLayer.getStyle();
 			if (newSelection.isEmpty()) {
 
 				// Check if the Style contains a SELECTION FTS
-				
-				FeatureTypeStyle[] clone = originalStyle.featureTypeStyles().toArray( new FeatureTypeStyle[] {} ).clone();
-				
+
+				FeatureTypeStyle[] clone = originalStyle.featureTypeStyles()
+						.toArray(new FeatureTypeStyle[] {}).clone();
+
 				for (FeatureTypeStyle fts : clone) {
 					if (fts.getName() != null
 							&& fts.getName().equals(SELECTION_STYLING)) {
 						originalStyle.featureTypeStyles().remove(fts);
-						
+
 						replaceRenderer();
-//						mapPane.refresh();
-						
+						// mapPane.refresh();
 
 						return;
 					}
@@ -255,20 +258,18 @@
 				if (!foundAndReplaced) {
 					originalStyle.featureTypeStyles().add(selectionFTStyle);
 				}
-				
-				
 
 				// Refresh the map
-//				mapPane.refresh();
-				
+				// mapPane.refresh();
+
 				DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();
 				dsv.visit(originalStyle);
-				Style newStyle = (Style)dsv.getCopy();
-				
-//				Style newStyle = StylingUtil.STYLE_BUILDER.createStyle();
-//				newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles());
+				Style newStyle = (Style) dsv.getCopy();
+
+				// Style newStyle = StylingUtil.STYLE_BUILDER.createStyle();
+				// newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles());
 				mapLayer.setStyle(newStyle);
-				
+
 				replaceRenderer();
 			}
 
@@ -278,9 +279,9 @@
 	}
 
 	private void replaceRenderer() {
-//
-//		// Has to be done before we apply the new Renderer
-//		mapLayer.setStyle(style);
+		//
+		// // Has to be done before we apply the new Renderer
+		// mapLayer.setStyle(style);
 
 		GTRenderer oldRenderer = mapPane.getRenderer();
 
@@ -301,16 +302,16 @@
 		mapPane.setRenderer(newRenderer);
 
 		if (oldRenderer != null) {
-			
+
 			RenderingHints java2DHints = oldRenderer.getJava2DHints();
 			if (java2DHints != null) {
 				newRenderer.setJava2DHints(java2DHints);
 			}
-			
+
 			oldRenderer.setContext(null);
 			oldRenderer = null;
 		}
-		
+
 		mapPane.refresh();
 
 	}
@@ -366,38 +367,45 @@
 		// Avoid event circles in propertyChange(..)
 		selectionChangeCausedByMe = true;
 
-		Iterator<SimpleFeature> fi = fse.getSelectionResult().iterator();
+		final FeatureCollection<SimpleFeatureType, SimpleFeature> selectionResult = fse
+				.getSelectionResult();
+		Iterator<SimpleFeature> fi = selectionResult.iterator();
+		try {
 
-		// reset the selection of the DpLayerSelectionModel
-		// layerSelModel.setValueIsAdjusting(true);
+			// reset the selection of the DpLayerSelectionModel
+			// layerSelModel.setValueIsAdjusting(true);
 
-		if (selectedTool == MapPaneToolBar.TOOL_SELECTION_ADD) {
-			layerSelModel.setValueIsAdjusting(true);
+			if (selectedTool == MapPaneToolBar.TOOL_SELECTION_ADD) {
+				layerSelModel.setValueIsAdjusting(true);
 
-			for (int fIdx = 0; fi.hasNext(); fIdx++) {
-				SimpleFeature f = fi.next();
-				layerSelModel.addSelection(f.getID());
-			}
-			layerSelModel.setValueIsAdjusting(false);
-		} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_SET) {
-			layerSelModel.setValueIsAdjusting(true);
-			layerSelModel.clearSelection();
+				for (int fIdx = 0; fi.hasNext(); fIdx++) {
+					SimpleFeature f = fi.next();
+					layerSelModel.addSelection(f.getID());
+				}
+				layerSelModel.setValueIsAdjusting(false);
+			} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_SET) {
+				layerSelModel.setValueIsAdjusting(true);
+				layerSelModel.clearSelection();
 
-			for (int fIdx = 0; fi.hasNext(); fIdx++) {
-				SimpleFeature f = fi.next();
-				layerSelModel.addSelection(f.getID());
-			}
+				for (int fIdx = 0; fi.hasNext(); fIdx++) {
+					SimpleFeature f = fi.next();
+					layerSelModel.addSelection(f.getID());
+				}
 
-			// LOGGER.debug("Setting selection to " + fi.());
+				// LOGGER.debug("Setting selection to " + fi.());
 
-			layerSelModel.setValueIsAdjusting(false);
-		} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_REMOVE) {
-			layerSelModel.setValueIsAdjusting(true);
-			for (int fIdx = 0; fi.hasNext(); fIdx++) {
-				SimpleFeature f = fi.next();
-				layerSelModel.removeSelection(f.getID());
+				layerSelModel.setValueIsAdjusting(false);
+			} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_REMOVE) {
+				layerSelModel.setValueIsAdjusting(true);
+				for (int fIdx = 0; fi.hasNext(); fIdx++) {
+					SimpleFeature f = fi.next();
+					layerSelModel.removeSelection(f.getID());
+				}
+				layerSelModel.setValueIsAdjusting(false);
 			}
-			layerSelModel.setValueIsAdjusting(false);
+
+		} finally {
+			selectionResult.close(fi);
 		}
 
 		// Show selected features in the map, which is not automatically done by



More information about the Schmitzm-commits mailing list