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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 26 15:21:46 CET 2009


Author: alfonx
Date: 2009-11-26 15:21:45 +0100 (Thu, 26 Nov 2009)
New Revision: 582

Modified:
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
Log:
Added now method checkAttribMetaData

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-11-26 09:18:18 UTC (rev 581)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-11-26 14:21:45 UTC (rev 582)
@@ -43,6 +43,7 @@
 import java.io.FileWriter;
 import java.net.URL;
 import java.text.DecimalFormat;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -78,6 +79,8 @@
 import org.jdom.output.XMLOutputter;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.GeometryDescriptor;
 import org.opengis.feature.type.Name;
 import org.opengis.parameter.GeneralParameterValue;
 
@@ -245,13 +248,15 @@
 	 * @param visible
 	 *            indicated whether the visible or invisible entries are
 	 *            returned
-	 *            
-	 * TODO replace with {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
+	 * 
+	 *            TODO replace with
+	 *            {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
 	 */
 	public static AttributeMetadataMap getVisibleAttributeMetaData(
 			final AttributeMetadataMap amdMap, final boolean visible) {
 
-		final AttributeMetadataMap filteredMap = new AttributeMetadataMap(amdMap.getLanguages());
+		final AttributeMetadataMap filteredMap = new AttributeMetadataMap(
+				amdMap.getLanguages());
 		for (final AttributeMetadata amd : amdMap.values())
 			if (amd.isVisible() == visible)
 				filteredMap.put(amd.getName(), amd);
@@ -1087,7 +1092,8 @@
 			final Translation labelT = rasterLegendData.get(rValue);
 			final JLabel classTitleLabel = new JLabel(labelT.toString());
 			panel.add(classTitleLabel, "sgx2"
-					+ (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5" : ""));
+					+ (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5"
+							: ""));
 			classTitleLabel.setLabelFor(iconLabel);
 
 			if (rasterLegendData.isPaintGaps()) {
@@ -1148,10 +1154,11 @@
 	public static boolean isStyleable(
 			final StyledRasterInterface<?> styledRaster) {
 		final ColorModel colorModel = getColorModel(styledRaster);
-		
-//		LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "
-//				+ colorModel != null ? colorModel.getClass().getSimpleName() : "NULL");
 
+		// LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "
+		// + colorModel != null ? colorModel.getClass().getSimpleName() :
+		// "NULL");
+
 		if (colorModel == null)
 			return true;
 		if (colorModel instanceof ComponentColorModel)
@@ -1166,35 +1173,95 @@
 	 * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a
 	 * repaint, so only use it when needed.
 	 * 
-	 * @return <code>true</code> if the {@link MapLayer}'s {@link Style} has been changed.
+	 * @return <code>true</code> if the {@link MapLayer}'s {@link Style} has
+	 *         been changed.
 	 */
-	public static boolean updateMapLayerStyleIfChangedAndKeepSelection(MapLayer mapLayer,
-			Style style2) {
+	public static boolean updateMapLayerStyleIfChangedAndKeepSelection(
+			MapLayer mapLayer, Style style2) {
 
 		Style mapLayerStyleCleaned = StylingUtil
-						.removeSelectionFeatureTypeStyle(mapLayer.getStyle());
-		
-		Style newStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(style2);
-		
-		if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned,
-				newStyleCleaned)) {
-			
+				.removeSelectionFeatureTypeStyle(mapLayer.getStyle());
+
+		Style newStyleCleaned = StylingUtil
+				.removeSelectionFeatureTypeStyle(style2);
+
+		if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, newStyleCleaned)) {
+
 			// They are different when compared without SELECTION FTS!
-			
+
 			// Now let's copy any SELECTION FTS to the now style
-			FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil.getSelectionFeatureTypeStyle( mapLayer.getStyle() );
+			FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil
+					.getSelectionFeatureTypeStyle(mapLayer.getStyle());
 			if (selectionFeatureTypeStyle != null) {
-				newStyleCleaned.featureTypeStyles().add(selectionFeatureTypeStyle);
-				// newStyleCleaned is not so clean anymore... We just alled a selcetion FTS
-			}  
-			
+				newStyleCleaned.featureTypeStyles().add(
+						selectionFeatureTypeStyle);
+				// newStyleCleaned is not so clean anymore... We just alled a
+				// selcetion FTS
+			}
+
 			mapLayer.setStyle(newStyleCleaned);
-			
+
 			return true;
-			
+
 		} else {
 			return false;
 		}
 	}
 
+	/**
+	 * After loading an atlas, the AttribteMetaData contains whatever is written
+	 * in the XML. But the DBF may have changed! This method checks an
+	 * {@link AttributeMetadataMap} against a schema and also corrects
+	 * upperCase/lowerCase problems. It will also remove any geometry column
+	 * attribute metadata.
+	 */
+	/**
+	 * After loading an atlas, the AttribteMetaData contains whatever is written
+	 * in the XML. But the DBF may have changed!
+	 */
+	public static void checkAttribMetaData(AttributeMetadataMap attributeMetaDataMap,
+			SimpleFeatureType schema) {
+
+		ArrayList<Name> willRemove = new ArrayList<Name>();
+
+		// 1. Check.. all attributes in the atm should be in the schema as well.
+		// maybe correct some upperCase/loweCase stuff
+
+		for (AttributeMetadata atm : attributeMetaDataMap.values()) {
+
+			AttributeDescriptor foundDescr = schema
+					.getDescriptor(atm.getName());
+			if (foundDescr == null) {
+				Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema,
+						atm.getLocalName());
+				if (bestMatch == null)
+					willRemove.add(atm.getName());
+				else
+					atm.setName(bestMatch);
+			} else if (foundDescr instanceof GeometryDescriptor) {
+				// We don't want GeometryColumns in here
+				willRemove.add(atm.getName());
+			}
+		}
+
+		// Remove the ones that were not findable in the schema
+		for (Name removeName : willRemove) {
+			if (attributeMetaDataMap.remove(removeName) == null){
+				LOGGER.warn("removing the AMData didn't work");
+			}
+		}
+
+		// 2. check... all attributes from the schema must have an ATM
+		for (AttributeDescriptor ad : schema.getAttributeDescriptors()) {
+			if (ad instanceof GeometryDescriptor)
+				continue;
+			if (!attributeMetaDataMap.containsKey(ad.getName())) {
+				attributeMetaDataMap.put(ad.getName(), new AttributeMetadata(
+						ad, schema.getAttributeDescriptors().indexOf(ad), attributeMetaDataMap
+								.getLanguages()));
+			}
+		}
+
+	}
+
 }



More information about the Schmitzm-commits mailing list