[Schmitzm-commits] r620 - branches/2.0-RC1/src/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jan 25 18:46:06 CET 2010


Author: alfonx
Date: 2010-01-25 18:46:06 +0100 (Mon, 25 Jan 2010)
New Revision: 620

Modified:
   branches/2.0-RC1/src/skrueger/geotools/StyledFS.java
   branches/2.0-RC1/src/skrueger/geotools/XMapPane.java
Log:
TIny Bugfixing inspired by IMPETUS training

Modified: branches/2.0-RC1/src/skrueger/geotools/StyledFS.java
===================================================================
--- branches/2.0-RC1/src/skrueger/geotools/StyledFS.java	2010-01-25 17:44:22 UTC (rev 619)
+++ branches/2.0-RC1/src/skrueger/geotools/StyledFS.java	2010-01-25 17:46:06 UTC (rev 620)
@@ -38,11 +38,13 @@
 
 import javax.swing.ImageIcon;
 import javax.swing.JPanel;
+import javax.xml.transform.TransformerException;
 
 import org.apache.log4j.Logger;
 import org.geotools.data.FeatureSource;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.styling.Style;
+import org.jfree.util.AttributedStringUtilities;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.feature.type.AttributeDescriptor;
@@ -61,11 +63,16 @@
  * {@link JPanel} as a {@link MapContextManagerInterface}
  * 
  * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
+ * 
+ * TODO Rename to StyledShapefile
  */
 public class StyledFS implements StyledFeatureSourceInterface {
 	private static final Logger LOGGER = Logger.getLogger(StyledFS.class);
 
 	private final FeatureSource<SimpleFeatureType, SimpleFeature> fs;
+	
+	/** Caching the CRS of the layer **/
+	CoordinateReferenceSystem crs = null;
 
 	/**
 	 * A unique ID which identifies the Layer in the Atlas. It's more important
@@ -100,21 +107,22 @@
 			File sldFile) {
 
 		this.fs = fs;
+
 		id = StyledFS.class.getSimpleName()
 				+ new Random(new Date().getTime()).nextInt(10000000);
 
 		this.sldFile = sldFile;
 
+		// datei existiert, dann lesen
 		if (sldFile != null && sldFile.exists()) {
 			try {
 				style = StylingUtil.loadSLD(sldFile)[0];
-			} catch (FileNotFoundException e) {
-				LOGGER
-						.debug("The SLD file passed was empty. Leaving the Style untouched. (We are in the constructor.. so its null");
 			} catch (Exception e) {
 				LOGGER.warn("Reading SLD failed: " + sldFile, e);
+				style = null;
 			}
 		}
+
 		title = new Translation();
 		desc = new Translation();
 
@@ -147,10 +155,14 @@
 	}
 
 	public CoordinateReferenceSystem getCrs() {
-		CoordinateReferenceSystem crs = fs.getSchema().getCoordinateReferenceSystem();
-		if (fs.getSchema().getCoordinateReferenceSystem() == null) {
-			LOGGER.warn("Could not determine the CRS of "+getTitle()+". Using default "+GeoImportUtil.getDefaultCRS());
-			crs = GeoImportUtil.getDefaultCRS();
+		if (crs == null) {
+			crs = fs.getSchema()
+					.getCoordinateReferenceSystem();
+			if (fs.getSchema().getCoordinateReferenceSystem() == null) {
+				LOGGER.warn("Could not determine the CRS of " + getTitle()
+						+ ". Using default " + GeoImportUtil.getDefaultCRS());
+				crs = GeoImportUtil.getDefaultCRS();
+			}
 		}
 		return crs;
 	}
@@ -244,13 +256,15 @@
 	public AttributeMetadataMap getAttributeMetaDataMap() {
 		if (map == null) {
 
-			map = new AttributeMetadataMap(new String[] {Translation.getActiveLang()});
+			map = new AttributeMetadataMap(new String[] { Translation
+					.getActiveLang() });
 
 			// Leaving out the first one, it will be the_geom
 			for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
 				AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
 
-				AttributeMetadata attMetaData = new AttributeMetadata(attDesc.getName(), map.getLanguages());
+				AttributeMetadata attMetaData = new AttributeMetadata(attDesc
+						.getName(), map.getLanguages());
 				map.put(attDesc.getName(), attMetaData);
 			}
 		}
@@ -267,7 +281,7 @@
 	public File getSldFile() {
 		return sldFile;
 	}
-
+	
 	public void setSldFile(File sldFile) {
 		this.sldFile = sldFile;
 	}
@@ -302,13 +316,14 @@
 
 	@Override
 	public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
-//		final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
-//		if (filter == Filter.EXCLUDE)
-//			return new EmptyFeatureCollection(fc.getSchema());
-//		if (filter == Filter.INCLUDE)
-//			return fc;
-//		return fc.subCollection(filter);
-		
+		// final FeatureCollection<SimpleFeatureType, SimpleFeature> fc =
+		// getFeatureCollection();
+		// if (filter == Filter.EXCLUDE)
+		// return new EmptyFeatureCollection(fc.getSchema());
+		// if (filter == Filter.INCLUDE)
+		// return fc;
+		// return fc.subCollection(filter);
+
 		try {
 			return getFeatureSource().getFeatures(filter);
 		} catch (IOException e) {

Modified: branches/2.0-RC1/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/2.0-RC1/src/skrueger/geotools/XMapPane.java	2010-01-25 17:44:22 UTC (rev 619)
+++ branches/2.0-RC1/src/skrueger/geotools/XMapPane.java	2010-01-25 17:46:06 UTC (rev 620)
@@ -275,16 +275,16 @@
 			final AffineTransform at = xMapPane.getScreenToWorld();
 			if (at != null) {
 				Point2D transformed = at.transform(e.getPoint(), null);
-				return new DirectPosition2D(xMapPane.getMapContext().getCoordinateReferenceSystem(), transformed.getX(), transformed.getY());
+				return new DirectPosition2D(xMapPane.getMapContext()
+						.getCoordinateReferenceSystem(), transformed.getX(),
+						transformed.getY());
 			}
 			return null;
 		}
 		throw new IllegalArgumentException(
 				"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane");
 	}
-	
 
-
 	/**
 	 * Listens to changes of the "background" {@link MapContext} and triggers
 	 * repaints where needed.
@@ -419,7 +419,8 @@
 
 		@Override
 		public void layerChanged(final MapLayerListEvent event) {
-//			getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow...
+			// getLocalRenderer().setContext(getMapContext()); geht doch auch
+			// ohne?!?!? wow...
 			requestStartRendering();
 		}
 
@@ -1443,9 +1444,9 @@
 	 */
 	public void onRenderingCompleted(final long l) {
 		lastRenderingDuration = (lastRenderingDuration + l) / 2;
-//		LOGGER
-//				.debug("complete rendering after " + lastRenderingDuration
-//						+ "ms");
+		// LOGGER
+		// .debug("complete rendering after " + lastRenderingDuration
+		// + "ms");
 
 		repaintTimer.stop();
 
@@ -1661,14 +1662,17 @@
 	 *            the current map pane extent (screen units)
 	 */
 	private void resetTransforms() {
-		final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
-				getMapContext().getCoordinateReferenceSystem());
-
 		// System.out
 		// .println("paintArea in resetTeansofrms = " + getVisibleRect());
 		if (!isWellDefined())
 			return;
 
+		if (mapArea == null)
+			return;
+		
+		final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
+				getMapContext().getCoordinateReferenceSystem());
+
 		worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
 				getVisibleRect());
 
@@ -2432,8 +2436,6 @@
 		return localRenderer;
 	}
 
-
-
 	/**
 	 * Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers.
 	 * Macht nichts, wenn {@code null} uebergeben wird.
@@ -2563,10 +2565,6 @@
 		zoomToLayer(getMapContext().getLayerCount() - 1 - index);
 	}
 
-	
-	
-
-
 	/**
 	 * Aktiviert oder deaktiviert das AntiAliasing for diese
 	 * {@link SelectableXMapPane}. AntiALiasing ist besonders fuer
@@ -2581,7 +2579,7 @@
 		if (java2DHints == null) {
 			java2DHints = GeoTools.getDefaultHints();
 		}
-		
+
 		java2DHints.put(RenderingHints.KEY_ANTIALIASING,
 				aa ? RenderingHints.VALUE_ANTIALIAS_ON
 						: RenderingHints.VALUE_ANTIALIAS_OFF);
@@ -2591,7 +2589,7 @@
 		java2DHints.put(RenderingHints.KEY_RENDERING,
 				aa ? RenderingHints.VALUE_RENDER_QUALITY
 						: RenderingHints.VALUE_RENDER_SPEED);
-		
+
 	}
 
 }



More information about the Schmitzm-commits mailing list