[Schmitzm-commits] r259 - in trunk/src/schmitzm/jfree: . chart/style feature/style

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 31 18:48:05 CEST 2009


Author: mojays
Date: 2009-07-31 18:48:04 +0200 (Fri, 31 Jul 2009)
New Revision: 259

Modified:
   trunk/src/schmitzm/jfree/JFreeChartUtil.java
   trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
   trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
   trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java
Log:
Unit for ChartAxisStyle
Sort, normalize and force categories for FeatureChartStyle

Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java	2009-07-31 15:27:19 UTC (rev 258)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java	2009-07-31 16:48:04 UTC (rev 259)
@@ -71,8 +71,10 @@
 import org.jfree.chart.title.Title;
 import org.jfree.chart.urls.StandardXYURLGenerator;
 import org.jfree.chart.urls.XYURLGenerator;
+import org.jfree.data.category.CategoryDataset;
 import org.jfree.data.function.Function2D;
 import org.jfree.data.function.LineFunction2D;
+import org.jfree.data.general.Dataset;
 import org.jfree.data.general.DatasetUtilities;
 import org.jfree.data.statistics.Regression;
 import org.jfree.data.xy.XYDataset;
@@ -251,6 +253,28 @@
   }
 
   /**
+   * Creates a {@link Dataset} for 2 or more attributes of a {@link FeatureCollection}.
+   * According to the feature attribute type the method decides whether a {@link XYDataset}
+   * or a {@link CategoryDataset} is created:<br>
+   * In case of an non-numeric X attribute a {@link CategoryDataset} is created always.
+   * Otherwise the default is to create a {@link XYDataset}. The flag {@code forceCat}
+   * can be used to create {@link CategoryDataset} for numeric X attributes.  
+   * @param fc       a {@link FeatureCollection}
+   * @param forceCat forces a {@link CategoryDataset} also for numeric X attributes
+   * @param xAttr feature attribute used for the X-value
+   * @param yAttr feature attribute(s) used for the Y-value (at least one; for each a
+   *              series is created in the dataset)
+   */
+  public static Dataset createDataset(FeatureCollection fc, boolean forceCat, boolean sot, String xAttr, String... yAttr) {
+    
+    
+    
+    
+    return null;
+  }
+  
+  
+  /**
    * Creates a {@link XYDataset} for 2 attributes of a {@link FeatureCollection}.
    * @param fc    a {@link FeatureCollection}
    * @param seriesKey   a (unique) key for the {@link XYSeries} in the dataset
@@ -281,10 +305,19 @@
       Feature f = fi.next();
       Number xValue = (Number)f.getAttribute(xAttr);
       Number yValue = (Number)f.getAttribute(yAttr);
+      // x-value NULL not permitted for XY dateset
+      if ( xValue == null )
+        continue;
+//      // TODO: here maybe filtering the several NULL aliases
+//      if ( yValue is a NULL alias )
+//        yValue = null;
+//      // TODO: her maybe ignore NULL values completely        
+//      if ( yValue == null )
+//        continue;
       xySeries.add(xValue, yValue);
-      // Mapping between FID und data index in series
+      // Mapping between FID and data index in series
       mapping.setMapping(f.getID(), seriesKey, i);
-      LOGGER.debug(f.getID() + " --> "+i);
+      //LOGGER.debug(f.getID() + " --> "+i);
     }
     return dataset;
   }

Modified: trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java	2009-07-31 15:27:19 UTC (rev 258)
+++ trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java	2009-07-31 16:48:04 UTC (rev 259)
@@ -177,8 +177,13 @@
       return;
     }
 
+    // If unit is set, add it to axis title
+    String axisLabel = getLabel();
+    if ( getUnitString() != null )
+      axisLabel += " ["+getUnitString().trim()+"]";
+    
     // Apply common attributes
-    axis.setLabel( getLabel() );
+    axis.setLabel( axisLabel );
     axis.setLabelPaint( getPaint() );
     axis.setLabelAngle( getLabelAngle() );
     axis.setVisible( isVisible() );
@@ -258,11 +263,19 @@
       LOGGER.warn("Only 0 or 90 degrees (horizontal/vertical) can be applied to values of "+LangUtil.getSimpleClassName(axis)+": "+angle);
   }
 
-public void setUnitString(String unitString) {
-	this.unitString = unitString;
+  /**
+   * Sets a unit for the axis.
+   * @param unitString a string representing the unit
+   */
+  public void setUnitString(String unitString) {
+  	this.unitString = unitString;
+  }
+  
+  /**
+   * Returns a unit for the axis.
+   * @param unitString a string representing the unit
+   */
+  public String getUnitString() {
+  	return unitString;
+  }
 }
-
-public String getUnitString() {
-	return unitString;
-}
-}

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2009-07-31 15:27:19 UTC (rev 258)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2009-07-31 16:48:04 UTC (rev 259)
@@ -231,6 +231,10 @@
     Boolean visible = XMLUtil.getBooleanAttribute(element, "visible");
     if ( visible != null )
       style.setVisible( visible );
+    // read "unit" property from attribute
+    String unit = XMLUtil.getAttribute(element, "unit");
+    if ( unit != null )
+      style.setUnitString(unit);
 
     // read the axis title from child <title>
     Element axisTitleElem = element.getChild("title");
@@ -542,9 +546,10 @@
     if ( axisStyle == null )
       return null;
     
-    // Create and add child with visible attribute
+    // Create and add child with visible and unit attribute
     Element axisElem = addChildToElement(element, axisChildName);
-    XMLUtil.setNotNullAttribute(axisElem, "visible", axisStyle.isVisible()); 
+    XMLUtil.setNotNullAttribute(axisElem, "visible", axisStyle.isVisible());
+    XMLUtil.setNotNullAttribute(axisElem, "unit", axisStyle.getUnitString());
     
     // Create and add child <title>
     Element titleElem = addLabelChildToElement(axisElem, "title", axisStyle);

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java	2009-07-31 15:27:19 UTC (rev 258)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java	2009-07-31 16:48:04 UTC (rev 259)
@@ -32,7 +32,9 @@
 import org.geotools.feature.FeatureCollection;
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.CategoryDataset;
 import org.jfree.data.general.Dataset;
+import org.jfree.data.xy.XYDataset;
 
 import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.jfree.chart.style.BasicChartStyle;
@@ -65,15 +67,23 @@
 	 */
 	public FeatureBasicChartStyle(String id, ChartType type) {
 		super(id, type);
-		dummyFeatureChartStyle = new Dummy(id, 2);
+		dummyFeatureChartStyle = new Dummy(id,-1);
 	}
-
+	
 	/**
-	 * Returns the attribute count needed to specify the chart data
-	 * from feature collection.
-	 * @return always 2
+	 * Returns the maximum number of feature attributes that can be
+	 * specified by this style.
+	 * @return always -1 which indicates no limit
 	 */
 	@Override
+	public int getMaxAttributeCount() {
+	  return dummyFeatureChartStyle.getMaxAttributeCount();
+	}
+
+    /**
+     * Returns the number of feature attributes defined in this style.
+     */
+	@Override
 	public int getAttributeCount() {
 		return dummyFeatureChartStyle.getAttributeCount();
 	}
@@ -81,11 +91,10 @@
 	/**
 	 * Returns the name of a feature attribute needed to create a
 	 * chart for this style.
-	 * @param idx axis index
-	 * @see ChartStyle#DOMAIN_AXIS
-	 * @see ChartStyle#RANGE_AXIS
-	 * @see ChartStyle#RANGE_AXIS2
+     * @param idx attribute index (0=domain; 1=1st range series;
+     *            2=2nd range series; ...)
 	 */
+    @Override
 	public String getAttributeName(int idx) {
 		return dummyFeatureChartStyle.getAttributeName(idx);
 	}
@@ -93,84 +102,92 @@
 	/**
 	 * Sets the name of a feature attribute needed to create a
 	 * chart for this style.
-	 * @param idx axis index
+     * @param idx attribute index (0=domain; 1=1st range series;
+     *            2=2nd range series; ...)
 	 * @param attrName feature attribute name 
-	 * @see ChartStyle#DOMAIN_AXIS
-	 * @see ChartStyle#RANGE_AXIS
-	 * @see ChartStyle#RANGE_AXIS2
 	 */
 	@Override
 	public void setAttributeName(int idx, String attrName) {
 		dummyFeatureChartStyle.setAttributeName(idx,attrName);
 	}
 
-	/**
-	 * Creates an appropriate {@link Dataset} for the attributes defined
-	 * by this style (according to the attributes types in the given
-	 * {@link FeatureCollection}) and calls {@link #applyToDataset(Dataset)}.
-	 * @see schmitzm.jfree.feature.style.FeatureChartStyle#applyToFeatureCollection(org.geotools.feature.FeatureCollection)
-	 */
-	@Override
-	public JFreeChart applyToFeatureCollection(FeatureCollection fc) {
-		//    Dataset dataset = null; // TODO: Create dataset from FeatureCollection by utility method
-		Dataset dataset = JFreeChartUtil.createXYDataset(fc, getTitleStyle().getLabel(), getAttributeName(DOMAIN_AXIS), getAttributeName(RANGE_AXIS));
-		return applyToDataset(dataset);
-	}
 
-
 	/**
-	 * Shall the domain axis values be sorted when the {@link JFreeChart}
-	 * {@link Dataset} is created? <code>false</code> is the default.
+	 * Sets whether the features are sorted according to the
+	 * domain attribute (before creating a {@link Dataset}).
 	 */
+    @Override
 	public void setSortDomainAxis(boolean sortDomainAxis){
-		dummyFeatureChartStyle.setSortDomainAxis(sortDomainAxis);
+	  dummyFeatureChartStyle.setSortDomainAxis(sortDomainAxis);
 	}
 
 	/**
-	 * Are the domain axis values sorted when the {@link JFreeChart}
-	 * {@link Dataset} is created? <code>false</code> is the default.
+	 * Returns whether the features are sorted according to the
+	 * domain attribute (before creating a {@link Dataset}).
+     * @return {@code false} as default
 	 */
+    @Override
 	public boolean isSortDomainAxis() {
-		return dummyFeatureChartStyle.isSortDomainAxis();
+	  return dummyFeatureChartStyle.isSortDomainAxis();
 	}
 
-	/**
-	 * Shall the domain axis values be interpreted as a category dataset, even if
-	 * it is numeric? <code>false</code> is default.
+	/** 
+	 * Sets whether a {@link CategoryDataset} is forced for
+	 * a numeric domain attribute. The default is to create {@link XYDataset}
+	 * for a numeric and {@link CategoryDataset} for a non-numeric domain
+	 * attribute.
 	 */
+    @Override
 	public void setForceCategories(boolean forceCategories){
-		dummyFeatureChartStyle.setForceCategories(forceCategories);
+      dummyFeatureChartStyle.setForceCategories(forceCategories);
 	}
 
-	/**
-	 * Are the domain axis values interpreted as a category dataset, even if
-	 * it is numeric? <code>false</code> is default.
+	/** 
+	 * Returns whether a {@link CategoryDataset} is forced for
+	 * a numeric domain attribute. The default is to create {@link XYDataset}
+	 * for a numeric and {@link CategoryDataset} for a non-numeric domain
+	 * attribute.
+     * @return {@code false} as default
 	 */
+    @Override
 	public boolean isForceCategories(){
-		return dummyFeatureChartStyle.isForceCategories();
+      return dummyFeatureChartStyle.isForceCategories();
 	}
 
-	/**
-	 * Shall the values for a given series be normalized before a
-	 * {@link Dataset} is created?
-	 * 
-	 * @param idx index, 0=domain; 1 = 1. series; 2=2. series...
-	 * @param normalize
-	 */  
-	public void setNormalize(int idx, boolean normalize){
-		dummyFeatureChartStyle.setNormalize(idx, normalize);
+    /** 
+     * Sets whether the attribute data is normalized for an
+     * attribute(before creating a {@link Dataset}).
+     * @param idx attribute index (0=domain; 1=1st range series;
+     *            2=2nd range series; ...)
+     * @param normalize indicates the normalize property
+     */  
+    @Override
+	public void setAttributeNormalized(int idx, boolean normalize){
+	  dummyFeatureChartStyle.setAttributeNormalized(idx, normalize);
 	}
 
-	/**
-	 * Are the values for a given series normalized before a
-	 * {@link Dataset} is created?
-	 * 
-	 * @param idx index, 0=domain; 1 = 1. series; 2=2. series...
-	 */  
+    /** 
+     * Returns whether the attribute data is normalized for an
+     * attribute(before creating a {@link Dataset}).
+     * @param idx attribute index (0=domain; 1=1st range series;
+     *            2=2nd range series; ...)
+     * @return {@code false} as default
+     */  
 	@Override
-	public boolean getNormalize(int idx) {
-		return dummyFeatureChartStyle.getNormalize(idx);
+	public boolean isAttributeNormalized(int idx) {
+		return dummyFeatureChartStyle.isAttributeNormalized(idx);
 	}
 
-
+    /**
+     * Creates an appropriate {@link Dataset} for the attributes defined
+     * by this style (according to the attributes types in the given
+     * {@link FeatureCollection}) and calls {@link #applyToDataset(Dataset)}.
+     * @see schmitzm.jfree.feature.style.FeatureChartStyle#applyToFeatureCollection(org.geotools.feature.FeatureCollection)
+     */
+    @Override
+    public JFreeChart applyToFeatureCollection(FeatureCollection fc) {
+        //    Dataset dataset = null; // TODO: Create dataset from FeatureCollection by utility method
+        Dataset dataset = JFreeChartUtil.createXYDataset(fc, getTitleStyle().getLabel(), getAttributeName(DOMAIN_AXIS), getAttributeName(RANGE_AXIS));
+        return applyToDataset(dataset);
+    }
 }

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2009-07-31 15:27:19 UTC (rev 258)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2009-07-31 16:48:04 UTC (rev 259)
@@ -29,12 +29,19 @@
  ******************************************************************************/
 package schmitzm.jfree.feature.style;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
 import org.geotools.feature.FeatureCollection;
 import org.jfree.chart.JFreeChart;
+import org.jfree.data.category.CategoryDataset;
 import org.jfree.data.general.Dataset;
+import org.jfree.data.xy.XYDataset;
 
 import schmitzm.jfree.chart.style.AbstractChartStyle;
 import schmitzm.jfree.chart.style.ChartStyle;
+import schmitzm.lang.LangUtil;
 
 /**
  * This interface extends the chart style with several functionalities
@@ -44,22 +51,30 @@
  */
 public interface FeatureChartStyle extends ChartStyle {
   /**
-   * Returns the number of feature attributes needed to create a
-   * chart for this style.
+   * Returns the maximum number of feature attributes that can be
+   * specified by this style.
+   * @return -1 if there is no limit for range attributes
    */
+  public int getMaxAttributeCount();
+
+  /**
+   * Returns the number of feature attributes defined in this style.
+   */
   public int getAttributeCount();
 
   /**
    * Returns the name of a feature attribute needed to create a
    * chart for this style.
-   * @param idx index, 0=domain; 1 = 1. series;  2=2. series...
+   * @param idx attribute index (0=domain; 1=1st range series;
+   *            2=2nd range series; ...)
    */
   public String getAttributeName(int idx);
   
   /**
    * Sets the name of a feature attribute needed to create a
    * chart for this style.
-   * @param idx index, 0=domain; 1 = 1. series;  2=2. series...
+   * @param idx attribute index (0=domain; 1=1st range series;
+   *            2=2nd range series; ...)
    * @param attrName feature attribute name 
    */
   public void setAttributeName(int idx, String attrName);
@@ -74,46 +89,53 @@
   public JFreeChart applyToFeatureCollection(FeatureCollection fc);
   
   /**
-	 * Shall the domain axis values be sorted when the {@link JFreeChart}
-	 * {@link Dataset} is created? <code>false</code> is the defult.
-	 */
-	public void setSortDomainAxis(boolean sort);
+   * Sets whether the features are sorted according to the
+   * domain attribute (before creating a {@link Dataset}).
+   */
+  public void setSortDomainAxis(boolean sort);
 
-	/**
-	 * Are the domain axis values sorted when the {@link JFreeChart}
-	 * {@link Dataset} is created? <code>false</code> is the defult.
-	 */
-    public boolean isSortDomainAxis();
-	/**
-	 * Shall the domain axis values be interpreted as a category dataset, evn if
-	 * it is numeric? <code>false</code> is default.
-	 */
-	public void setForceCategories(boolean forceCategories);
+  /**
+   * Returns whether the features are sorted according to the
+   * domain attribute (before creating a {@link Dataset}).
+   * @return {@code false} as default
+   */
+  public boolean isSortDomainAxis();
 
-  	/**
-  	 * Are the domain axis values interpreted as a category dataset, even if
-  	 * it is numeric? <code>false</code> is default.
-	 */
-    public boolean isForceCategories();
+  /** 
+   * Sets whether a {@link CategoryDataset} is forced for
+   * a numeric domain attribute. The default is to create {@link XYDataset}
+   * for a numeric and {@link CategoryDataset} for a non-numeric domain
+   * attribute.
+   */
+  public void setForceCategories(boolean forceCategories);
+
+  /** 
+   * Returns whether a {@link CategoryDataset} is forced for
+   * a numeric domain attribute. The default is to create {@link XYDataset}
+   * for a numeric and {@link CategoryDataset} for a non-numeric domain
+   * attribute.
+   * @return {@code false} as default
+   */
+  public boolean isForceCategories();
   
-	/**
-	 * Shall the values for a given series be normalized before a
-	 * {@link Dataset} is created? Default is <code>false</code>
-	 * 
-	 * @param idx
-	 *            index, 0=domain; 1 = 1. series; 2=2. series...
-	 * @param normalize
-	 */
-	public void setNormalize(int idx, boolean normalize);
+  /** 
+   * Sets whether the attribute data is normalized for an
+   * attribute (before creating a {@link Dataset}).
+   * @param idx attribute index (0=domain; 1=1st range series;
+   *            2=2nd range series; ...)
+   * @param normalize indicates the normalize property
+   */  
+  public void setAttributeNormalized(int idx, boolean normalize);
 	
-	/**
-	 * Are the values for a given series normalized before a
-	 * {@link Dataset} is created? Default is <code>false</code>.
-	 * 
-	 * @param idx
-	 *            index, 0=domain; 1 = 1. series; 2=2. series...
-	 */
-	public boolean getNormalize(int idx);
+  /** 
+   * Returns whether the attribute data is normalized for an
+   * attribute (before creating a {@link Dataset}).
+   * @param idx attribute index (0=domain; 1=1st range series;
+   *            2=2nd range series; ...)
+   * @param normalize indicates the normalize property
+   * @return {@code false} as default
+   */  
+  public boolean isAttributeNormalized(int idx);
 
 
   /**
@@ -131,127 +153,195 @@
    * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
    */
   public static class Dummy extends AbstractChartStyle implements FeatureChartStyle {
+    /** Indicates whether the features are sorted according to the
+     *  domain attribute (before creating a {@link Dataset}). */
+    protected boolean sortDomainAxis;
+    /** Indicates whether a {@link CategoryDataset} is forced for
+     *  a numeric domain attribute. The default is to create {@link XYDataset}
+     *  for a numeric and {@link CategoryDataset} for a non-numeric domain
+     *  attribute. */
+    protected boolean forceCategories;
+
     /** Holds the attributes needed to specify the chart data
-     *  from feature collection. */
-    protected String[] attrNames = null;
-	private boolean sortDomainAxis;
-	private boolean forceCategories;
+     *  from feature collection (0 = attribute for domain axis; others assigned
+     *  to the range axis as series). */
+    protected Map<Integer,String> attrNames = new HashMap<Integer,String>();
     
+    /** Indicates for each attribute whether the attribute data is normalized
+     *  (before creating a {@link Dataset}). */
+    protected Map<Integer,Boolean> normalizeAttr = new HashMap<Integer,Boolean>();
+    
+    /** Holds the maximum number of attributes the style can be defined
+     *  defined for (-1 = no limit). */
+    protected int maxAttrCount = -1;
 
-	/**
+    /** Holds the number of attributes the style is defined for. */
+    protected int maxAttrIdx = 0;
+
+    /**
      * Creates a new dummy. This constructor is protected so that only derived
+     * classes can instantiate a dummy! There is no limit for the number
+     * of attributes which can be defined by the style.
+     * @param id a (unique) ID for the style
+     */
+    protected Dummy(String id) {
+      this(id,-1);
+    }
+
+    /**
+     * Creates a new dummy. This constructor is protected so that only derived
      * classes can instantiate a dummy!
-     * @param id        a (unique) ID for the style
-     * @param attrCount attribute count needed to specify the chart data
-     *                  from feature collection
+     * @param id  a (unique) ID for the style
+     * @param maxAttrCount attribute count needed to specify the chart data
+     *                     from feature collection
      */
-    protected Dummy(String id, int attrCount) {
+    protected Dummy(String id, int maxAttrCount) {
       super(id);
-      this.attrNames = new String[attrCount];
+      this.maxAttrCount = maxAttrCount;
+    }
+
+    /**
+     * Updates the local variable for the number of attributes
+     * the maximum index (key) of the several hash maps. 
+     */
+    private void updateAttributeCount() {
+      // attribute names define the number of attributes, also
+      // if there are "more" normalize constraints specified
+      maxAttrIdx = LangUtil.max( attrNames.keySet() );
       
-      /**
-       * Filling the ArrayList 
-       */
+      if ( maxAttrCount > 0 && maxAttrIdx >= maxAttrCount )
+        throw new IllegalArgumentException("Only "+maxAttrCount+" attributes can be specified for "+LangUtil.getSimpleClassName(this));
     }
-    
+
     /**
-     * Returns the attribute count needed to specify the chart data
-     * from feature collection.
+     * Returns the maximum number of feature attributes that can be
+     * specified by this style.
+     * @return -1 if there is no limit for range attributes
      */
+    @Override
+    public int getMaxAttributeCount() {
+      return maxAttrCount;
+    }
+
+    /**
+     * Returns the number of feature attributes defined in this style.
+     */
+    @Override
     public int getAttributeCount() {
-      return attrNames.length;
+      return maxAttrIdx;
     }
 
     /**
      * Returns the name of a feature attribute needed to create a
      * chart for this style.
-     * @param idx index, 0=domain; 1 = 1. series;  2=2. series...
+     * @param idx attribute index (0=domain; 1=1st range series;
+     *            2=2nd range series; ...)
      */
-    public String getAttributeName(int idx) {
-      return attrNames[idx];
+    @Override
+   public String getAttributeName(int idx) {
+      return attrNames.get(idx);
     }
 
     /**
      * Sets the name of a feature attribute needed to create a
      * chart for this style.
-     * @param idx index, 0=domain; 1 = 1. series;  2=2. series...
+     * @param idx attribute index (0=domain; 1=1st range series;
+     *            2=2nd range series; ...)
      * @param attrName feature attribute name 
      */
+    @Override
     public void setAttributeName(int idx, String attrName) {
-      attrNames[idx] = attrName;
+      attrNames.put(idx,attrName);
+      updateAttributeCount();
     }
 
-    /**
-     * Does nothing, but always throws a {@link UnsupportedOperationException},
-     * because the dummy can not provide this functionality.
-     */
-    public JFreeChart applyToDataset(Dataset dataset) {
-      throw new UnsupportedOperationException("FeatureChartStyle.Dummy does not implement applyToDataset(..)");
-    }
 
     /**
-     * Does nothing, but always throws a {@link UnsupportedOperationException},
-     * because the dummy can not provide this functionality.
+     * Sets whether the features are sorted according to the
+     * domain attribute (before creating a {@link Dataset}).
      */
-    public JFreeChart applyToFeatureCollection(FeatureCollection fc) {
-      throw new UnsupportedOperationException("FeatureChartStyle.Dummy does not implement applyToFeatureCollection(..)");
-    }
-    
-    /**
-  	 * Shall the domain axis values be sorted when the {@link JFreeChart}
-  	 * {@link Dataset} is created? <code>false</code> is the default.
-  	 */
+    @Override
   	public void setSortDomainAxis(boolean sortDomainAxis){
 		this.sortDomainAxis = sortDomainAxis;
   	}
   	
-  	/**
-	 * Are the domain axis values sorted when the {@link JFreeChart}
-	 * {@link Dataset} is created? <code>false</code> is the default.
-	 */
+    /**
+     * Returns whether the features are sorted according to the
+     * domain attribute (before creating a {@link Dataset}).
+     * @return {@code false} as default
+     */
+    @Override
     public boolean isSortDomainAxis() {
 		return sortDomainAxis;
 	}
     
-  	/**
-  	 * Shall the domain axis values be interpreted as a category dataset, even if
-  	 * it is numeric? <code>false</code> is default.
-  	 */
+    /** 
+     * Sets whether a {@link CategoryDataset} is forced for
+     * a numeric domain attribute. The default is to create {@link XYDataset}
+     * for a numeric and {@link CategoryDataset} for a non-numeric domain
+     * attribute.
+     */
+    @Override
   	public void setForceCategories(boolean forceCategories){
 		this.forceCategories = forceCategories;
   	}
   	
-  	/**
-  	 * Are the domain axis values interpreted as a category dataset, even if
-  	 * it is numeric? <code>false</code> is default.
-	 */
+    /** 
+     * Returns whether a {@link CategoryDataset} is forced for
+     * a numeric domain attribute. The default is to create {@link XYDataset}
+     * for a numeric and {@link CategoryDataset} for a non-numeric domain
+     * attribute.
+     * @return {@code false} as default
+     */
+    @Override
     public boolean isForceCategories(){
     	return forceCategories;
     }
 
-  	/**
-  	 * Shall the values for a given series be normalized before a
-  	 * {@link Dataset} is created?
-  	 * 
-  	 * @param idx index, 0=domain; 1 = 1. series; 2=2. series...
-  	 * @param normalize
+    /** 
+     * Sets whether the attribute data is normalized for an
+     * attribute (before creating a {@link Dataset}).
+  	 * @param idx attribute index (0=domain; 1=1st range series;
+  	 *            2=2nd range series; ...)
+  	 * @param normalize indicates the normalize property
   	 */  
-  	public void setNormalize(int idx, boolean normalize){
-        throw new UnsupportedOperationException("");
-
+    @Override
+  	public void setAttributeNormalized(int idx, boolean normalize){
+      normalizeAttr.put(idx, normalize);
+      updateAttributeCount();
   	}
 
-  	/**
-  	 * Are the values for a given series normalized before a
-  	 * {@link Dataset} is created?
-  	 * 
-  	 * @param idx index, 0=domain; 1 = 1. series; 2=2. series...
-  	 */  
-	@Override
-	public boolean getNormalize(int idx) {
-	      throw new UnsupportedOperationException("");
+    /** 
+     * Returns whether the attribute data is normalized for an
+     * attribute (before creating a {@link Dataset}).
+     * @param idx attribute index (0=domain; 1=1st range series;
+     *            2=2nd range series; ...)
+     * @return {@code false} as default
+     */  
+  	@Override
+	public boolean isAttributeNormalized(int idx) {
+	  Boolean normalize = normalizeAttr.get(idx);
+	  return normalize != null && normalize;
 	}
 
+    /**
+     * Does nothing, but always throws a {@link UnsupportedOperationException},
+     * because the dummy can not provide this functionality.
+     */
+    @Override
+    public JFreeChart applyToDataset(Dataset dataset) {
+      throw new UnsupportedOperationException("FeatureChartStyle.Dummy does not implement applyToDataset(..)");
+    }
+
+    /**
+     * Does nothing, but always throws a {@link UnsupportedOperationException},
+     * because the dummy can not provide this functionality.
+     */
+    @Override
+    public JFreeChart applyToFeatureCollection(FeatureCollection fc) {
+      throw new UnsupportedOperationException("FeatureChartStyle.Dummy does not implement applyToFeatureCollection(..)");
+    }
+    
   }
   
 }

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2009-07-31 15:27:19 UTC (rev 258)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2009-07-31 16:48:04 UTC (rev 259)
@@ -65,32 +65,29 @@
     if ( featureElement == null )
       throw new UnsupportedOperationException("<featureAttributes> element necessary for FeatureChartStyle!");
 
-    // Read all feature attribute definitions below <featureAttributes>
-    for (Element featureAttrElem : (List<Element>)featureElement.getChildren() ) {
-      String elementName     = featureAttrElem.getName();
+    // Read domain attribute
+    Element domainAttrElem = featureElement.getChild("domainAttr");
+    if ( domainAttrElem == null )
+      throw new UnsupportedOperationException("Attribute <domainAttr> required for FeatureChartType");
+    String domainAttrName = XMLUtil.getAttribute(domainAttrElem, "name");
+    if ( domainAttrName == null )
+      throw new UnsupportedOperationException("Attribute 'name' necessary for <domainAttr> element of FeatureChartStyle!");
+    chartStyle.setAttributeName(0, domainAttrName);
+    chartStyle.setAttributeNormalized(0, XMLUtil.getBooleanAttribute(domainAttrElem, "normalize", false));
+    chartStyle.setSortDomainAxis(XMLUtil.getBooleanAttribute(domainAttrElem, "sort", false));
+    chartStyle.setForceCategories(XMLUtil.getBooleanAttribute(domainAttrElem, "forceCategories", false));
+    
+    // Read all range attribute definitions
+    int rangeAttrNo = 0;
+    for (Element featureAttrElem : (List<Element>)featureElement.getChildren("rangeAttr") ) {
       String featureAttrName = XMLUtil.getAttribute(featureAttrElem, "name");
       if ( featureAttrName == null )
-        throw new UnsupportedOperationException("Attribute 'name' necessary for <"+featureAttrElem+"> element of FeatureChartStyle!");
-      // Apply feature attribute name to style
-      try {
-        if ( "domainAttr".equals(elementName) )
-          chartStyle.setAttributeName(ChartStyle.DOMAIN_AXIS, featureAttrName);
-        else if ( "rangeAttr".equals(elementName) )
-          chartStyle.setAttributeName(ChartStyle.RANGE_AXIS, featureAttrName);
-        else if ( "rangeAttr2".equals(elementName) )
-          chartStyle.setAttributeName(ChartStyle.RANGE_AXIS2, featureAttrName);
-      } catch (ArrayIndexOutOfBoundsException err) {
-        throw new UnsupportedOperationException("<"+elementName+"> not applicable for "+LangUtil.getSimpleClassName(chartStyle));
-      }
+        throw new UnsupportedOperationException("Attribute 'name' necessary for <rangeAttr> element of FeatureChartStyle!");
+      // Apply attributes to style
+      rangeAttrNo++;
+      chartStyle.setAttributeName(rangeAttrNo, featureAttrName);
+      chartStyle.setAttributeNormalized(rangeAttrNo, XMLUtil.getBooleanAttribute(domainAttrElem, "normalize", false));
     }
-    
-    // Check whether all needed feature attributes are specified
-    int attrCount = chartStyle.getAttributeCount();
-    for (int i=0; i<attrCount; i++) {
-      String attrName = chartStyle.getAttributeName(i);
-      if ( attrName == null || "".equals(attrName) )
-        throw new UnsupportedOperationException("<featureAttributes> requires "+attrCount+" feature attribute definition for "+LangUtil.getSimpleClassName(chartStyle));
-    }
   }
 
   /**
@@ -124,13 +121,21 @@
     // Create and add element <featureAttributes>
     Element attrElem = addChildToElement(root, "featureAttributes");
     
-    // Attribute definition
+    // Domain attribute definition
     if ( style.getAttributeCount() > 0 )
-      addChildToElement(attrElem, "domainAttr", true, "name", style.getAttributeName(0));
-    if ( style.getAttributeCount() > 1 )
-      addChildToElement(attrElem, "rangeAttr", true, "name", style.getAttributeName(1));
-    if ( style.getAttributeCount() > 2 )
-      addChildToElement(attrElem, "rangeAttr2", true, "name", style.getAttributeName(2));
+      addChildToElement(attrElem, "domainAttr", false,
+          "name", style.getAttributeName(0),
+          "normalize", style.isAttributeNormalized(0),
+          "sort", style.isSortDomainAxis(),
+          "forceCategories", style.isForceCategories()
+      );
+    
+    // Range attributes definition
+    for (int i=1; i<style.getAttributeCount(); i++)
+      addChildToElement(attrElem, "rangeAttr", false,
+          "name", style.getAttributeName(i),
+          "normalize", style.isAttributeNormalized(i)
+      );
 
     return root;
   }

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java	2009-07-31 15:27:19 UTC (rev 258)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java	2009-07-31 16:48:04 UTC (rev 259)
@@ -31,7 +31,9 @@
 
 import org.geotools.feature.FeatureCollection;
 import org.jfree.chart.JFreeChart;
+import org.jfree.data.category.CategoryDataset;
 import org.jfree.data.general.Dataset;
+import org.jfree.data.xy.XYDataset;
 
 import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.jfree.chart.style.ChartStyle;
@@ -59,11 +61,19 @@
   }
 
   /**
-   * Returns the attribute count needed to specify the chart data
-   * from feature collection.
+   * Returns the maximum number of feature attributes that can be
+   * specified by this style.
    * @return always 2
    */
   @Override
+  public int getMaxAttributeCount() {
+    return dummyFeatureChartStyle.getMaxAttributeCount();
+  }
+
+  /**
+   * Returns the number of feature attributes defined in this style.
+   */
+  @Override
   public int getAttributeCount() {
     return dummyFeatureChartStyle.getAttributeCount();
   }
@@ -71,11 +81,10 @@
   /**
    * Returns the name of a feature attribute needed to create a
    * chart for this style.
-   * @param idx axis index
-   * @see ChartStyle#DOMAIN_AXIS
-   * @see ChartStyle#RANGE_AXIS
-   * @see ChartStyle#RANGE_AXIS2
+   * @param idx attribute index (0=domain; 1=1st range series;
+   *            2=2nd range series; ...)
    */
+  @Override
   public String getAttributeName(int idx) {
     return dummyFeatureChartStyle.getAttributeName(idx);
   }
@@ -83,17 +92,82 @@
   /**
    * Sets the name of a feature attribute needed to create a
    * chart for this style.
-   * @param idx axis index
+   * @param idx attribute index (0=domain; 1=1st range series;
+   *            2=2nd range series; ...)
    * @param attrName feature attribute name 
-   * @see ChartStyle#DOMAIN_AXIS
-   * @see ChartStyle#RANGE_AXIS
-   * @see ChartStyle#RANGE_AXIS2
    */
+  @Override
   public void setAttributeName(int idx, String attrName) {
     dummyFeatureChartStyle.setAttributeName(idx,attrName);
   }
 
   /**
+   * Sets whether the features are sorted according to the
+   * domain attribute (before creating a {@link Dataset}).
+   */
+  @Override
+  public void setSortDomainAxis(boolean sortDomainAxis){
+    dummyFeatureChartStyle.setSortDomainAxis(sortDomainAxis);
+  }
+
+  /**
+   * Returns whether the features are sorted according to the
+   * domain attribute (before creating a {@link Dataset}).
+   * @return {@code false} as default
+   */
+  @Override
+  public boolean isSortDomainAxis() {
+    return dummyFeatureChartStyle.isSortDomainAxis();
+  }
+
+  /** 
+   * Sets whether a {@link CategoryDataset} is forced for
+   * a numeric domain attribute. The default is to create {@link XYDataset}
+   * for a numeric and {@link CategoryDataset} for a non-numeric domain
+   * attribute.
+   */
+  @Override
+  public void setForceCategories(boolean forceCategories){
+    dummyFeatureChartStyle.setForceCategories(forceCategories);
+  }
+
+  /** 
+   * Returns whether a {@link CategoryDataset} is forced for
+   * a numeric domain attribute. The default is to create {@link XYDataset}
+   * for a numeric and {@link CategoryDataset} for a non-numeric domain
+   * attribute.
+   * @return {@code false} as default
+   */
+  @Override
+  public boolean isForceCategories(){
+    return dummyFeatureChartStyle.isForceCategories();
+  }
+
+  /** 
+   * Sets whether the attribute data is normalized for an
+   * attribute(before creating a {@link Dataset}).
+   * @param idx attribute index (0=domain; 1=1st range series;
+   *            2=2nd range series; ...)
+   * @param normalize indicates the normalize property
+   */  
+  @Override
+  public void setAttributeNormalized(int idx, boolean normalize){
+    dummyFeatureChartStyle.setAttributeNormalized(idx, normalize);
+  }
+
+  /** 
+   * Returns whether the attribute data is normalized for an
+   * attribute(before creating a {@link Dataset}).
+   * @param idx attribute index (0=domain; 1=1st range series;
+   *            2=2nd range series; ...)
+   * @return {@code false} as default
+   */  
+  @Override
+  public boolean isAttributeNormalized(int idx) {
+      return dummyFeatureChartStyle.isAttributeNormalized(idx);
+  }
+
+  /**
    * Creates an appropriate {@link Dataset} for the attributes defined
    * by this style (according to the attributes types in the given
    * {@link FeatureCollection}) and calls {@link #applyToDataset(Dataset)}.
@@ -111,60 +185,4 @@
     );
     return applyToDataset(dataset);
   }
-
-	/**
-	 * Shall the domain axis values be sorted when the {@link JFreeChart}
-	 * {@link Dataset} is created? <code>false</code> is the default.
-	 */
-	public void setSortDomainAxis(boolean sortDomainAxis){
-		dummyFeatureChartStyle.setSortDomainAxis(sortDomainAxis);
-	}
-
-	/**
-	 * Are the domain axis values sorted when the {@link JFreeChart}
-	 * {@link Dataset} is created? <code>false</code> is the default.
-	 */
-	public boolean isSortDomainAxis() {
-		return dummyFeatureChartStyle.isSortDomainAxis();
-	}
-
-	/**
-	 * Shall the domain axis values be interpreted as a category dataset, even if
-	 * it is numeric? <code>false</code> is default.
-	 */
-	public void setForceCategories(boolean forceCategories){
-		dummyFeatureChartStyle.setForceCategories(forceCategories);
-	}
-
-	/**
-	 * Are the domain axis values interpreted as a category dataset, even if
-	 * it is numeric? <code>false</code> is default.
-	 */
-	public boolean isForceCategories(){
-		return dummyFeatureChartStyle.isForceCategories();
-	}
-
-	/**
-	 * Shall the values for a given series be normalized before a
-	 * {@link Dataset} is created?
-	 * 
-	 * @param idx index, 0=domain; 1 = 1. series; 2=2. series...
-	 * @param normalize
-	 */  
-	public void setNormalize(int idx, boolean normalize){
-		dummyFeatureChartStyle.setNormalize(idx, normalize);
-	}
-
-	/**
-	 * Are the values for a given series normalized before a
-	 * {@link Dataset} is created?
-	 * 
-	 * @param idx index, 0=domain; 1 = 1. series; 2=2. series...
-	 */  
-	@Override
-	public boolean getNormalize(int idx) {
-		return dummyFeatureChartStyle.getNormalize(idx);
-	}
-
-
 }



More information about the Schmitzm-commits mailing list