[Schmitzm-commits] r681 - in branches/2.0-RC2/src: schmitzm/jfree/feature/style skrueger skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Feb 9 23:08:27 CET 2010


Author: alfonx
Date: 2010-02-09 23:08:26 +0100 (Tue, 09 Feb 2010)
New Revision: 681

Modified:
   branches/2.0-RC2/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
   branches/2.0-RC2/src/skrueger/AttributeMetadata.java
   branches/2.0-RC2/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
Log:
* NODATA handling in the attribute table
* NODATA buttons in DesignAtlasChartDialog

Modified: branches/2.0-RC2/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2010-02-05 19:46:10 UTC (rev 680)
+++ branches/2.0-RC2/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2010-02-09 22:08:26 UTC (rev 681)
@@ -340,6 +340,9 @@
         for (int i=0; i<max; i++) {
           destFCS.setAttributeName(i, null);
           destFCS.setAttributeNormalized(i, null);
+          
+          // Added by SK. In this special case we don't 
+          destFCS.setNoDataValues(i, getNoDataValues(i));
         }
         // Copy attribute names and normalization
         for (Integer idx : attrNames.keySet() )
@@ -348,6 +351,7 @@
         for (Integer idx : normalizeAttr.keySet() )
           if ( isAttributeNormalized(idx) )
             destFCS.setAttributeNormalized(idx, isAttributeNormalized(idx));
+        
       }
       
       return dest;

Modified: branches/2.0-RC2/src/skrueger/AttributeMetadata.java
===================================================================
--- branches/2.0-RC2/src/skrueger/AttributeMetadata.java	2010-02-05 19:46:10 UTC (rev 680)
+++ branches/2.0-RC2/src/skrueger/AttributeMetadata.java	2010-02-09 22:08:26 UTC (rev 681)
@@ -31,6 +31,7 @@
 
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.log4j.Logger;
 import org.geotools.feature.NameImpl;
@@ -50,7 +51,7 @@
  */
 public class AttributeMetadata implements Copyable<AttributeMetadata>,
 		Comparable<AttributeMetadata> {
-	
+
 	static private final Logger LOGGER = Logger
 			.getLogger(AttributeMetadata.class);
 
@@ -75,7 +76,7 @@
 	/**
 	 * Allows to define general NODATA values for an attribute. e.g. -9999 can
 	 * be set and will always be interpreted as NULL internally and will usually
-	 * be ignored. This overcomes the problem, that 
+	 * be ignored. This overcomes the problem, that
 	 **/
 	protected HashSet<Object> nodataValues = new HashSet<Object>();
 
@@ -92,8 +93,9 @@
 	protected boolean visible = true;
 
 	/**
-	 * When listed, the attributes are listed according to their {@link #weight} (heavier
-	 * => further down)
+	 * When listed, the attributes are listed according to their {@link #weight}
+	 * (heavier => further down)
+	 * 
 	 * @see #compareTo(AttributeMetadata)
 	 **/
 	protected int weight = 0;
@@ -102,13 +104,14 @@
 	private AttributeMetadata() {
 	}
 
-	public AttributeMetadata(final AttributeDescriptor attDesc, final int weight,
-			final List<String> langs) {
+	public AttributeMetadata(final AttributeDescriptor attDesc,
+			final int weight, final List<String> langs) {
 		this(attDesc.getName(), langs);
 		setWeight(weight);
 	}
 
-	public AttributeMetadata(final AttributeDescriptor attDesc, final List<String> langs) {
+	public AttributeMetadata(final AttributeDescriptor attDesc,
+			final List<String> langs) {
 		this(attDesc.getName(), langs);
 	}
 
@@ -137,7 +140,6 @@
 		this.visible = visible;
 		this.unit = unit;
 	}
-	
 
 	/**
 	 * Creates an {@link AttributeMetadata} object with the following
@@ -151,7 +153,8 @@
 	 * @param unit
 	 *            {@link String} of the unit that the information is in
 	 */
-	public AttributeMetadata(final Name name, final Boolean visible, final String unit) {
+	public AttributeMetadata(final Name name, final Boolean visible,
+			final String unit) {
 		this.setName(name);
 		this.visible = visible;
 		this.unit = unit;
@@ -166,7 +169,7 @@
 	}
 
 	/**
-	 * Creates a new visible {@link AttributeMetadata} 
+	 * Creates a new visible {@link AttributeMetadata}
 	 */
 	public AttributeMetadata(final Name name, final String defaultTitle,
 			final List<String> langs) {
@@ -201,7 +204,7 @@
 	}
 
 	/**
-	 * Creates a new visible {@link AttributeMetadata} 
+	 * Creates a new visible {@link AttributeMetadata}
 	 */
 	public AttributeMetadata(final String localName, final String defaultTitle,
 			final List<String> langs) {
@@ -272,7 +275,8 @@
 	}
 
 	/**
-	 * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>
+	 * The fully qualified {@link Name} of the attribute, e.g.
+	 * <code>org.bla.plo:blub</code>
 	 */
 	public Name getName() {
 		return name;
@@ -335,7 +339,8 @@
 	}
 
 	/**
-	 * The fully qualified {@link Name} of the attribute, e.g. <code>org.bla.plo:blub</code>
+	 * The fully qualified {@link Name} of the attribute, e.g.
+	 * <code>org.bla.plo:blub</code>
 	 */
 	public void setName(final Name name) {
 		this.name = name;
@@ -344,7 +349,7 @@
 	public void addNodataValue(Object nodataValue) {
 		this.nodataValues.add(nodataValue);
 	}
-	
+
 	public void removeNodataValue(Object nodataValue) {
 		this.nodataValues.remove(nodataValue);
 	}
@@ -363,14 +368,15 @@
 
 	/**
 	 * Shall the end-user see this attribute?
+	 * 
 	 * @param visible
 	 */
 	public void setVisible(final Boolean visible) {
-//		// The THE_GEOM and shall never be visible! 
-//		if (name.getLocalPart().equalsIgnoreCase("the_geom"))
-//			this.visible = false;
-//		else
-//			this.visible = visible;
+		// // The THE_GEOM and shall never be visible!
+		// if (name.getLocalPart().equalsIgnoreCase("the_geom"))
+		// this.visible = false;
+		// else
+		// this.visible = visible;
 
 		this.visible = visible;
 	}
@@ -378,16 +384,17 @@
 	public void setWeight(final int weight) {
 		this.weight = weight;
 	}
-	
+
 	/**
 	 * For nicer debugging
 	 */
 	@Override
 	public String toString() {
 		StringBuffer sb = new StringBuffer();
-		if (name != null) sb.append(name.toString()+" ");
-		sb.append("weight="+weight+" ");
-		sb.append("title="+getTitle().toString());
+		if (name != null)
+			sb.append(name.toString() + " ");
+		sb.append("weight=" + weight + " ");
+		sb.append("title=" + getTitle().toString());
 		return sb.toString();
 	}
 
@@ -399,7 +406,42 @@
 	 * Note: This method is called often.
 	 */
 	public Object fiterNodata(final Object value) {
-		if (nodataValues.contains(value)) return null;
+		if (nodataValues.contains(value))
+			return null;
 		return value;
 	}
+
+	/**
+	 * @return a nicely formatted String containing all NODATA values. Strings
+	 *         are quoted fo that the empty String can be seen.
+	 */
+	public String getNoDataValuesFormatted() {
+		return formatNoDataValues(getNodataValues());
+	}
+
+	/**
+	 * @return a nicely formatted String containing all NODATA values. Strings
+	 *         are quoted fo that the empty String can be seen.
+	 */
+	public static String formatNoDataValues(Set<Object> list) {
+		String nicelyFormatted = "";
+		if (list != null) {
+			if (list.size() == 0)
+				nicelyFormatted = "";
+			else {
+				for (Object ndo : list) {
+					if (ndo instanceof String)
+						nicelyFormatted += "\"" + ndo + "\"";
+					else
+						nicelyFormatted += ndo.toString();
+
+					nicelyFormatted += ",";
+				}
+				// Remove the extra comma
+				nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted
+						.length() - 1);
+			}
+		}
+		return nicelyFormatted;
+	}
 }

Modified: branches/2.0-RC2/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/StyledFeatureCollectionTableModel.java	2010-02-05 19:46:10 UTC (rev 680)
+++ branches/2.0-RC2/src/skrueger/geotools/StyledFeatureCollectionTableModel.java	2010-02-09 22:08:26 UTC (rev 681)
@@ -30,6 +30,7 @@
 package skrueger.geotools;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Vector;
 
 import org.apache.log4j.Logger;
@@ -77,6 +78,9 @@
 	 */
 	protected String[] colTooltips = null;
 
+	/** A cache for the #sortedValuesVisibleOnly() **/
+	protected List<AttributeMetadata> amdMapVisibleOnly = null;
+
 	/**
 	 * Creates a new table model for a styled layer.
 	 * 
@@ -91,6 +95,16 @@
 	}
 
 	/**
+	 * This overwritten method filters the values for NODATA-values defined in
+	 * the {@link AttributeMetadata}
+	 */
+	@Override
+	public Object getValueAt(int row, int col) {
+		Object rawValue = super.getValueAt(row, col);
+		return amdMap.sortedValuesVisibleOnly().get(col).fiterNodata(rawValue);
+	}
+	
+	/**
 	 * Sets a new data source for the table.
 	 * 
 	 * @param fs
@@ -109,6 +123,7 @@
 		// this.featureSource = fs;
 		this.filter = filter;
 		this.amdMap = amdm;
+		this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly();
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
 		if (fs != null) {
@@ -125,20 +140,22 @@
 						.getLocalName());
 
 				// Add other visible attributes as ordered by weights
-				for (AttributeMetadata a : amdm.sortedValuesVisibleOnly()) {
+				for (AttributeMetadata a : amdMapVisibleOnly) {
 					visibleAttrNames.add(a.getLocalName());
 				}
 
-//			Tested with 2.6.x trunk from 2009-11-26 and it now works. So we only request the properties we need!			
-// 				/**
-//				 * I got NPEs when properties contained only [the_geom] ?!??!!??
-//				 */
-//				if (properties.length > 1) {
-					query = new DefaultQuery(schema.getTypeName(), filter,
-							visibleAttrNames.toArray(new String[] {}));
-//				} else {
-//					query = new DefaultQuery(schema.getTypeName(), filter);
-//				}
+				// Tested with 2.6.x trunk from 2009-11-26 and it now works. So
+				// we only request the properties we need!
+				// /**
+				// * I got NPEs when properties contained only [the_geom]
+				// ?!??!!??
+				// */
+				// if (properties.length > 1) {
+				query = new DefaultQuery(schema.getTypeName(), filter,
+						visibleAttrNames.toArray(new String[] {}));
+				// } else {
+				// query = new DefaultQuery(schema.getTypeName(), filter);
+				// }
 			}
 			fc = fs.getFeatures(query);
 		}
@@ -183,14 +200,14 @@
 		if (featureArray == null || featureArray.length == 0) {
 			colNames = new String[0];
 			colTooltips = new String[0]; // Only set and used in
-											// StyledFeatureCollectionTableModel
+			// StyledFeatureCollectionTableModel
 			colClass = new Class[0];
 		} else {
 			// Struktur der Tabelle vom AttributeMetaDtaaMap übernehmen
 			SimpleFeatureType schema = featureArray[0].getFeatureType();
 			// Pruefen, welche Attribute angezeigt werden
 			attrTypes.clear();
-			for (AttributeMetadata amd : amdMap.sortedValuesVisibleOnly()) {
+			for (AttributeMetadata amd : amdMapVisibleOnly) {
 				AttributeDescriptor type = schema.getDescriptor(amd.getName());
 				if (attrFilter == null || attrFilter.accept(type))
 					attrTypes.add(type);
@@ -198,11 +215,12 @@
 			// Namen und Attribut-Indizes der angezeigten Spalten ermitteln
 			colNames = new String[attrTypes.size()];
 			colTooltips = new String[attrTypes.size()]; // Only set and used in
-														// StyledFeatureCollectionTableModel
+			// StyledFeatureCollectionTableModel
 			colClass = new Class[attrTypes.size()];
 			attrIdxForCol = new int[attrTypes.size()];
 			for (int i = 0; i < colNames.length; i++) {
-				AttributeDescriptor descriptor = schema.getDescriptor(amdMap.sortedValuesVisibleOnly().get(i).getName());
+				AttributeDescriptor descriptor = schema
+						.getDescriptor(amdMapVisibleOnly.get(i).getName());
 
 				// Not so nice in 26: find the index of an attribute...
 				int idx = schema.getAttributeDescriptors().indexOf(descriptor);
@@ -212,9 +230,10 @@
 						.getLocalName();
 				colNames[i] = amdMap.get(attName).getTitle().toString();
 				AttributeMetadata amd = amdMap.get(attName);
-				colTooltips[i] = "<html>"+amd.getDesc().toString()+"<br>"+amd.getName()+"</html>";
-				colClass[i] = schema.getAttributeDescriptors().get(idx).getType()
-						.getBinding();
+				colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>"
+						+ amd.getName() + "</html>";
+				colClass[i] = schema.getAttributeDescriptors().get(idx)
+						.getType().getBinding();
 			}
 		}
 
@@ -223,16 +242,16 @@
 		for (int i = 0; i < featureArray.length; i++)
 			if (featureArray[i] != null)
 				featureIdx.put(featureArray[i].getID(), i);
-//
-//		// translate the column names
-//		if (amdMap != null) {
-//			for (int i = 0; i < colNames.length; i++) {
-//				colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()
-//						+ "<br>" + colNames[i];
-//				colNames[i] = amdMap.get(colNames[i]).getTitle().toString();
-//
-//			}
-//		}
+		//
+		// // translate the column names
+		// if (amdMap != null) {
+		// for (int i = 0; i < colNames.length; i++) {
+		// colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()
+		// + "<br>" + colNames[i];
+		// colNames[i] = amdMap.get(colNames[i]).getTitle().toString();
+		//
+		// }
+		// }
 		if (fireTableStructureChanged)
 			fireTableStructureChanged();
 



More information about the Schmitzm-commits mailing list