[Schmitzm-commits] r518 - in branches/1.0-gt2-2.6: dist src/gtmig/org/geotools/swing src/schmitzm/geotools/feature src/schmitzm/geotools/styling src/schmitzm/jfree/feature/style src/schmitzm/swing src/skrueger src/skrueger/geotools src/skrueger/i8n

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Nov 13 19:17:06 CET 2009


Author: alfonx
Date: 2009-11-13 19:16:38 +0100 (Fri, 13 Nov 2009)
New Revision: 518

Modified:
   branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6.jar
   branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
   branches/1.0-gt2-2.6/src/schmitzm/swing/StatusDialog.java
   branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
   branches/1.0-gt2-2.6/src/skrueger/i8n/I8NUtil.java
Log:
* CQLFilter.toString does not produce CQL! Useed CQL.toCQL( Filter ) instead in some places.
* Added paramter weight (for visualisation sorting) to attributeMetadata
* Added paramters X and A for Attributemetadata.. but not using it yet.. 

Modified: branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6.jar
===================================================================
(Binary files differ)

Modified: branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java	2009-11-12 10:12:39 UTC (rev 517)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java	2009-11-13 18:16:38 UTC (rev 518)
@@ -1471,10 +1471,6 @@
 
 		Rectangle curPaintArea = getVisibleRect();
 
-		// allow a single pixel margin at the right and bottom edges
-		curPaintArea.width -= 1;
-		curPaintArea.height -= 1;
-
 		labelCache.clear();
 
 		/**
@@ -1523,9 +1519,6 @@
 //			LOGGER.debug("creating a new background image");
 
 			Rectangle curPaintArea = getVisibleRect();
-			// allow a single pixel margin at the right and bottom edges
-			curPaintArea.width -= 1;
-			curPaintArea.height -= 1;
 
 			bgImage = new BufferedImage(curPaintArea.width + 1,
 					curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);
@@ -1566,12 +1559,10 @@
 	private BufferedImage getLocalImage() {
 
 		if (localImage == null) {
+
 //			LOGGER.debug("creating a new local image");
 
 			Rectangle curPaintArea = getVisibleRect();
-			// allow a single pixel margin at the right and bottom edges
-			curPaintArea.width -= 1;
-			curPaintArea.height -= 1;
 
 			localImage = new BufferedImage(curPaintArea.width + 1,
 					curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB);

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java	2009-11-12 10:12:39 UTC (rev 517)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java	2009-11-13 18:16:38 UTC (rev 518)
@@ -30,6 +30,7 @@
 
 package schmitzm.geotools.feature;
 
+import org.apache.log4j.Logger;
 import org.geotools.filter.text.cql2.CQL;
 import org.geotools.filter.text.cql2.CQLException;
 import org.opengis.filter.Filter;
@@ -40,6 +41,7 @@
  *
  */
 public class CQLFilterParser implements FilterParser {
+	private static Logger LOGGER = Logger.getLogger(CQLFilterParser.class);
   /** Factory used to create the {@link Filter}. */
 //  protected FilterFactory filterFactory = null;
 
@@ -50,7 +52,7 @@
 //    this(null);
   }
 //
-//  /**
+//  /**"Exceptino while parsing : "+rule,err
 //   * Creates a new parser.
 ////   * @param filterFactory factory used to create the {@link Filter} (can be {@code null})
 //   */
@@ -72,7 +74,7 @@
     try {
       return CQL.toFilter(rule);
     } catch (CQLException err) {
-      throw new RuntimeException(err);
+      throw new RuntimeException("Exceptino while parsing : "+rule,err);
     }
   }
 

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-11-12 10:12:39 UTC (rev 517)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-11-13 18:16:38 UTC (rev 518)
@@ -1084,7 +1084,7 @@
 		Style exportStyle = removeSelectionFeatureTypeStyle(origStyle);
 
 		if (!isStyleDifferent(exportStyle, exportFile)) {
-			LOGGER.debug("Style " + exportFile + " didn't change, not saving.");
+//			LOGGER.debug("Style " + exportFile + " didn't change, not saving.");
 			return false;
 		}
 

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2009-11-12 10:12:39 UTC (rev 517)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2009-11-13 18:16:38 UTC (rev 518)
@@ -363,6 +363,7 @@
 						if (chartStyle.isAttributeNormalized(attrIdx)) {
 							String attrName = chartStyle
 									.getAttributeName(attrIdx);
+							
 							StaticBin1D stat = attribStats.get(attrName);
 							if (stat == null) {
 								stat = new DynamicBin1D();

Modified: branches/1.0-gt2-2.6/src/schmitzm/swing/StatusDialog.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/swing/StatusDialog.java	2009-11-12 10:12:39 UTC (rev 517)
+++ branches/1.0-gt2-2.6/src/schmitzm/swing/StatusDialog.java	2009-11-13 18:16:38 UTC (rev 518)
@@ -107,7 +107,9 @@
    * @param relY     relative vertikale Position zum Parent-Fenster
    */
   public StatusDialog(Component parent, String title, String message, Icon icon, double relX, double relY) {
-    super((Frame)parent,true);
+//	  War: super((Frame)parent,true); aber getParentWindow ist wohl besser
+	  super( SwingUtil.getParentWindow(parent), ModalityType.APPLICATION_MODAL);
+    
     // wenn kein uebergeordnetes Fenster angegeben ist, wird es immer
     // im Vordergrund angezeigt
     if ( parent==null )

Modified: branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java	2009-11-12 10:12:39 UTC (rev 517)
+++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java	2009-11-13 18:16:38 UTC (rev 518)
@@ -29,6 +29,9 @@
  ******************************************************************************/
 package skrueger;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.log4j.Logger;
 import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.AttributeDescriptor;
@@ -36,26 +39,111 @@
 
 import skrueger.geotools.Copyable;
 import skrueger.geotools.StyledLayerInterface;
+import skrueger.i8n.I8NUtil;
 import skrueger.i8n.Translation;
 
 /**
  * This class holds meta information about an attribute/column. This information
- * is used by {@link StyledLayerInterface}.
+ * is used by {@link StyledLayerInterface} and many others.<br/>
  * 
  * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
  */
-public class AttributeMetadata implements Copyable<AttributeMetadata> {
+public class AttributeMetadata implements Copyable<AttributeMetadata>,
+		Comparable<AttributeMetadata> {
 	static private final Logger LOGGER = Logger
 			.getLogger(AttributeMetadata.class);
 
+	// public class WeightComparator implements Comparator<AttributeDescriptor>
+	// {
+	//
+	// @Override
+	// public int compare(AttributeDescriptor o1, AttributeDescriptor o2) {
+	// // TODO Auto-generated method stub
+	// return 0;
+	// }
+	//		
+	// };
+
+	/** Translation of the attribute's title **/
 	protected Translation title = new Translation();
+
+	/** Translation of the attribute's description **/
 	protected Translation desc = new Translation();
+
+	/** Is the attribute visible to the user or ignored where possible **/
 	protected boolean visible = true;
+
+	/**
+	 * The unit append to all visualizations of values of this attribute (is not
+	 * null)
+	 **/
 	protected String unit = "";
-	protected int colIdx;
+
+	/** The Name of the attribute **/
 	private Name name;
 
+	public int getWeight() {
+		return weight;
+	}
+
+	public void setWeight(int weight) {
+		this.weight = weight;
+	}
+
+	public List<Object> getNodataValues() {
+		return nodataValues;
+	}
+
+	public void setNodataValues(List<Object> nodataValues) {
+		this.nodataValues = nodataValues;
+	}
+
+	public Double getFunctionX() {
+		return functionX;
+	}
+
+	public void setFunctionX(Double functionX) {
+		this.functionX = functionX;
+	}
+
+	public Double getFunctionA() {
+		return functionA;
+	}
+
+	public void setFunctionA(Double functionA) {
+		this.functionA = functionA;
+	}
+
+	public void setVisible(boolean visible) {
+		this.visible = visible;
+	}
+
 	/**
+	 * When listed, the attributes are listed according to their weight (heavier
+	 * => further down)
+	 **/
+	protected int weight = 0;
+
+	/**
+	 * 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.
+	 **/
+	protected List<Object> nodataValues = new ArrayList<Object>();
+
+	/**
+	 * For numerical attributes the value can be transformed by VALUE*X+A when
+	 * presented on screen
+	 **/
+	protected Double functionX = 1.;
+
+	/**
+	 * For numerical attributes the value can be transformed by VALUE*X+A when
+	 * presented on screen
+	 **/
+	protected Double functionA = 0.;
+
+	/**
 	 * Creates an {@link AttributeMetadata} object with the following
 	 * information
 	 * 
@@ -148,15 +236,16 @@
 	}
 
 	public void setVisible(final Boolean visible) {
+
+		// The THE_GEOM and shall never be visible! // TODO MAKE BETTER
+		if (name.getLocalPart().equalsIgnoreCase("the_geom"))
+			this.visible = false;
+		else
+			this.visible = visible;
+		
 		this.visible = visible;
 	}
 
-	//
-	// /** @return the index of this attribute in the underlying table/dbf **/
-	// public int getColIdx() {
-	// return colIdx;
-	// }
-
 	public Translation getTitle() {
 		return title;
 	}
@@ -190,6 +279,14 @@
 		amd.setName(new NameImpl(getName().getNamespaceURI(), getName()
 				.getLocalPart()));
 
+		amd.setWeight(getWeight());
+		amd.setFunctionX(getFunctionX());
+		amd.setFunctionA(getFunctionA());
+
+		for (Object nodataValue : getNodataValues()) {
+			amd.getNodataValues().add(nodataValue);
+		}
+
 		return amd;
 	}
 
@@ -225,4 +322,22 @@
 	public void setLocalName(String localName) {
 		this.name = new NameImpl(localName);
 	}
+
+	/**
+	 * Orders the Attributes according to their weight. Heavier => further down.
+	 */
+	@Override
+	public int compareTo(AttributeMetadata atm2) {
+		// Double double1 = new Double(1./weight);
+		// double double2 = 1./atm2.getWeight();
+		return new Integer(weight).compareTo(atm2.getWeight());
+	}
+
+	/**
+	 * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes
+	 */
+	public double getQuality(List<String> languages) {
+		return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
+				.qmTranslation(languages, getDesc()) * 1.) / 3.;
+	}
 }

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java	2009-11-12 10:12:39 UTC (rev 517)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java	2009-11-13 18:16:38 UTC (rev 518)
@@ -4,25 +4,32 @@
 import java.util.List;
 import java.util.TreeMap;
 
+import org.apache.log4j.Logger;
 import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.Name;
 
 import skrueger.AttributeMetadata;
+import skrueger.i8n.I8NUtil;
 
 /**
  * An extension of TreeMap, that is copyable in the sense of the {@link Copyable} interface
  */
 public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata>
 		implements Copyable<AttributeMetadataMap> {
-
+	static private final Logger LOGGER = Logger.getLogger(AttributeMetadataMap.class);
+	
+	
 	/**
 	 * @Deprecated use get(Name name) or get(String localName)
 	 */
 	@Deprecated
 	public AttributeMetadata get(Object key) {
+		LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
+		LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
+		LOGGER.warn("PLEASE DONT USE get(Object) any MORE!");
 		return super.get(key);
 	}
-
+	
 	public AttributeMetadata get(Name name) {
 		final AttributeMetadata attributeMetadata = super.get(name);
 		if (attributeMetadata == null && name != null && !name.getLocalPart().trim().isEmpty()) {
@@ -59,4 +66,25 @@
 		list.addAll(values());
 		return list;
 	}
+
+	/**
+	 * @return a number between 0 (bad) and 1 (good) that is calculated from the amount of translation available in the visible attributes
+	 */
+	public double getQuality(List<String> languages) {
+		int allVisible = 0;
+		double colQmSum = 0.;
+		for (final AttributeMetadata oneCol : values()) {
+			
+			if (oneCol.isVisible()) {
+				allVisible++;
+				colQmSum += oneCol.getQuality(languages);
+			}
+		}
+
+		if (allVisible > 0)
+			return colQmSum / allVisible;
+		else
+			return 1.;
+
+	}
 }

Modified: branches/1.0-gt2-2.6/src/skrueger/i8n/I8NUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/i8n/I8NUtil.java	2009-11-12 10:12:39 UTC (rev 517)
+++ branches/1.0-gt2-2.6/src/skrueger/i8n/I8NUtil.java	2009-11-13 18:16:38 UTC (rev 518)
@@ -29,6 +29,7 @@
  ******************************************************************************/
 package skrueger.i8n;
 
+import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 import java.util.TreeSet;
@@ -146,4 +147,27 @@
 			return true;
 		return false;
 	}
+
+	/**
+	 * @return a {@link Double} between 0 and 1 representing the part of the
+	 *         given {@link Translation} that has been filled.
+	 * @param ac
+	 *            {@link AtlasConfig} to determine the languages to expect.
+	 * @param trans
+	 *            The {@link Translation} to check.
+	 */
+	public static double qmTranslation(final List<String> languages,
+			final Translation trans) {
+	
+		if (trans == null)
+			return 0.;
+	
+		Integer cunt = 0;
+		for (final String l : languages) {
+			final String t = trans.get(l);
+			if (!isEmpty(t))
+				cunt++;
+		}
+		return cunt.doubleValue() / (double) languages.size();
+	}
 }



More information about the Schmitzm-commits mailing list