[Schmitzm-commits] r181 - in trunk/src/schmitzm/geotools: feature gui

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 3 12:49:32 CEST 2009


Author: alfonx
Date: 2009-07-03 12:49:32 +0200 (Fri, 03 Jul 2009)
New Revision: 181

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
Log:
* NPE bug fixed 

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-07-02 14:44:57 UTC (rev 180)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-07-03 10:49:32 UTC (rev 181)
@@ -13,6 +13,7 @@
 
 
 import java.awt.Color;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.sql.ResultSet;
@@ -28,6 +29,7 @@
 import org.apache.log4j.Logger;
 import org.geotools.data.DataUtilities;
 import org.geotools.data.FeatureSource;
+import org.geotools.data.memory.MemoryDataStore;
 import org.geotools.factory.CommonFactoryFinder;
 import org.geotools.factory.GeoTools;
 import org.geotools.feature.AttributeType;
@@ -1166,7 +1168,24 @@
 		return sampleFeature;
 	}
 
+	/**
+	 * Erstellt eine {@link FeatureSource} basierend auf einem {@link MemoryDataStore} für eine übergebene {@link FeatureCollection}
+	 * @param features 
+	 * @return
+	 */
+	public static FeatureSource createMemoryFeatureSource(
+			FeatureCollection features) {
+		try {
+			return  new MemoryDataStore(
+					features).getFeatureSource(features
+					.getSchema().getTypeName());
+		} catch (IOException e) {
+			LOGGER.error("Creating a memory datastore for the allFeaturesCollection", e);
+			throw new RuntimeException("Creating a memory datastore for the allFeaturesCollection",e);
+		}
+	}
 
+
 //  /**
 //   * Extrahiert alle Geometrien aus einer FeatureCollection. Fuer jedes
 //   * Geometry-Attribut der FeatureCollection wird eine GeometrieCollection

Modified: trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/FeatureTablePane.java	2009-07-02 14:44:57 UTC (rev 180)
+++ trunk/src/schmitzm/geotools/gui/FeatureTablePane.java	2009-07-03 10:49:32 UTC (rev 181)
@@ -14,6 +14,7 @@
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
+import java.io.IOException;
 
 import javax.swing.BorderFactory;
 import javax.swing.JScrollPane;
@@ -26,11 +27,15 @@
 import javax.swing.event.TableModelListener;
 import javax.swing.table.TableModel;
 
+import org.apache.log4j.Logger;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.memory.MemoryDataStore;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.map.DefaultMapLayer;
 import org.geotools.styling.Style;
 
 import schmitzm.geotools.feature.AttributeTypeFilter;
+import schmitzm.geotools.feature.FeatureUtil;
 import schmitzm.geotools.styling.StylingUtil;
 import schmitzm.swing.JPanel;
 import schmitzm.swing.SortableJTable;
@@ -52,6 +57,8 @@
  * @version 1.0
  */
 public class FeatureTablePane extends JPanel {
+	final static Logger LOGGER = Logger.getLogger(FeatureTablePane.class);
+
 	/** Tabelle in der die Features angezeigt werden. */
 	protected SortableJTable featuresTable = null;
 
@@ -372,9 +379,10 @@
 			 * Add ALL features to the JMapPane as the base laye and style them
 			 * in grey
 			 */
-			if (allFeatures != null) {
+			if (allFeatures != null && mapPane != null) {
+				
 				mapPane.getContext().addLayer(
-						new DefaultMapLayer(allFeatures, StylingUtil
+						new DefaultMapLayer(FeatureUtil.createMemoryFeatureSource(allFeatures), StylingUtil
 								.createStyleSimple(allFeatures,
 										Color.lightGray, Color.darkGray)));
 			}
@@ -389,8 +397,8 @@
 				&& selectedFeatures.getSchema().getDefaultGeometry() != null) {
 
 			if (getFeatureStyle() == null) {
-				setFeatureStyle(StylingUtil.createStyleSimple(selectedFeatures, Color.red,
-						Color.white));
+				setFeatureStyle(StylingUtil.createStyleSimple(selectedFeatures,
+						Color.red, Color.white));
 			}
 			mapPane.getContext().addLayer(selectedFeatures, getFeatureStyle());
 



More information about the Schmitzm-commits mailing list