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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Mar 1 17:38:14 CET 2010


Author: mojays
Date: 2010-03-01 17:38:12 +0100 (Mon, 01 Mar 2010)
New Revision: 734

Added:
   trunk/src/schmitzm/jfree/feature/style/FeatureChartAxisStyle.java
Modified:
   trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyle.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:
- setUnitVisible(boolean) moved from FeatureChartStyle (and Dummy/FeatureBasicChartStyle/FeatureScatterChartStyle) to ChartStyle (and AbstractChartStyle)
- new FeatureChartAxisStyle which displays the AggregationFunction in axis title
- FeatureChartStyleXMLFactory: conversion from ChartAxisStyle to FeatureChartAxisStyle


Modified: trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2010-02-28 18:13:58 UTC (rev 733)
+++ trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2010-03-01 16:38:12 UTC (rev 734)
@@ -376,6 +376,22 @@
   }
   
   /**
+   * Updates the unitVisible parameter for all axes at once.
+   * 
+   * @param visible
+   *            <code>true</code> if unit string shall be displayed in the
+   *            chart.
+   */
+  @Override
+  public void setUnitVisible(boolean visible) {
+      // TODO MArtin! Funktioniert so leider nicht. Warum ist hier
+      // getAxisCount() immer 0 ????
+      for (int axisIndex = 0; axisIndex < getAxisCount(); axisIndex++) {
+          getAxisStyle(axisIndex).setUnitVisible(visible);
+      }
+  }
+
+  /**
    * Returns count of renderer for the chart.
    */
   public int getRendererCount() {

Modified: trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java	2010-02-28 18:13:58 UTC (rev 733)
+++ trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java	2010-03-01 16:38:12 UTC (rev 734)
@@ -118,6 +118,7 @@
     dest.setVisible( isVisible() );
     dest.setValuesFormat( getValuesFormat() );
     dest.setUnitString( getUnitString() );
+    dest.setUnitVisible( isUnitVisible() );
     return dest;
   }
 

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyle.java	2010-02-28 18:13:58 UTC (rev 733)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyle.java	2010-03-01 16:38:12 UTC (rev 734)
@@ -186,6 +186,15 @@
    */
   public void setAxisStyle(int axis, ChartAxisStyle style);
 
+  /**
+   * Updates the unitVisible parameter for all axes at once.
+   * 
+   * @param visible
+   *            <code>true</code> if unit string shall be displayed in the
+   *            chart.
+   */
+  public void setUnitVisible(boolean visible);
+
   
   /**
    * Returns count of renderer for the chart.

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java	2010-02-28 18:13:58 UTC (rev 733)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java	2010-03-01 16:38:12 UTC (rev 734)
@@ -319,18 +319,4 @@
       Dataset    dataset = FeatureChartUtil.createDataset(fc,this);
       return applyToDataset(dataset);
     }
-
-	/**
-	 * Updates the unitVisible parameter for all axes at once.
-	 * 
-	 * @param visible
-	 *            <code>true</code> if unit string shall be displayed in the
-	 *            chart.
-	 */
-	@Override
-	public void setUnitVisible(boolean visible) {
-		dummyFeatureChartStyle.setUnitVisible(visible);
-	}
-    
- 
 }

Added: trunk/src/schmitzm/jfree/feature/style/FeatureChartAxisStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartAxisStyle.java	2010-02-28 18:13:58 UTC (rev 733)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartAxisStyle.java	2010-03-01 16:38:12 UTC (rev 734)
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+
+package schmitzm.jfree.feature.style;
+
+import java.awt.Color;
+
+import org.jfree.chart.axis.Axis;
+import org.jfree.chart.axis.CategoryAxis;
+import org.jfree.chart.axis.DateAxis;
+import org.jfree.chart.axis.NumberAxis;
+
+import schmitzm.jfree.chart.style.ChartAxisStyle;
+import schmitzm.lang.LangUtil;
+import skrueger.i8n.Translation;
+
+/**
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ *
+ */
+public class FeatureChartAxisStyle extends ChartAxisStyle {
+  /** Holds the {@link FeatureChartStyle} the axis is connected to. */
+  protected FeatureChartStyle chartStyle = null;
+  
+  /**
+   * Creates a new style with default values (empty label, color black, angle 0).
+   * @param chartStyle the chart style the axis is connected to
+   */
+  public FeatureChartAxisStyle(FeatureChartStyle chartStyle) {
+    this(chartStyle,"",Color.black,0.0,0.0);
+  }
+
+  /**
+   * Creates a new style.
+   * @param chartStyle the chart style the axis is connected to
+   * @param title axis title
+   * @param color text color for the axis title
+   * @param labelAngle angel (in degrees) the axis label is rotated by
+   * @param valuesAngle angel (in degrees) the axis values are rotated by
+   */
+  public FeatureChartAxisStyle(FeatureChartStyle chartStyle, String title, Color color, Double labelAngle, Double valuesAngle) {
+    super(title, color, labelAngle, valuesAngle);
+    this.chartStyle = chartStyle; 
+  }
+
+  /**
+   * Creates a new style.
+   * @param chartStyle the chart style the axis is connected to
+   * @param title axis title as an internationalized {@link Translation} 
+   * @param color text color for the axis title
+   * @param labelAngle angel (in degrees) the axis label is rotated by
+   * @param valuesAngle angel (in degrees) the axis values are rotated by
+   */
+  public FeatureChartAxisStyle(FeatureChartStyle chartStyle, Translation title, Color color, Double labelAngle, Double valuesAngle) {
+    super(title, color, labelAngle, valuesAngle);
+    this.chartStyle = chartStyle; 
+  }
+  
+  /**
+   * Creates a (deep) clone of this style.
+   */
+  @Override
+  public FeatureChartAxisStyle copy() {
+    return (FeatureChartAxisStyle)copyTo( new FeatureChartAxisStyle(null) );
+  }
+
+  /**
+   * Returns the chart style, the axis is connected to.
+   */
+  public FeatureChartStyle getChartStyle() {
+    return chartStyle;
+  }
+
+  /**
+   * Sets the chart style, the axis is connected to.
+   */
+  public void setChartStyle(FeatureChartStyle style) {
+    chartStyle = style;
+  }
+  
+  /**
+   * Applies the style to a specific axis.<br>
+   * Note: Some style properties can only be applied to specific axis types.
+   * @param axis an axis
+   */
+  @Override
+  public void applyToAxis(Axis axis) {
+    super.applyToAxis(axis);
+    if (axis == null) {
+      return;
+    }
+
+    // Determine the aggregation title to display with unit
+    String funcTitle = null;
+    for (int i=0; i<chartStyle.getAxisCount(); i++)
+      if ( chartStyle.getAxisStyle(i) == this ) {
+        // ToDo: ??? von welchem Attribut die Aggr.Function verwenden
+        //       Ist 'i' richtig?
+        if ( chartStyle.getAttributeAggregation(i) != null )
+          funcTitle = chartStyle.getAttributeAggregation(i).getTitle();
+        break;
+      }
+    
+    // If unit or function is set, add it to axis title
+    String axisLabel = getLabel();
+    String unitLabel = (isUnitVisible() && !"".equals(getUnitString())) ? getUnitString() : null;
+    if ( funcTitle != null && !"".equals(funcTitle.trim())) {
+      if ( unitLabel != null )
+        unitLabel += ", " + funcTitle.trim();
+      else
+        unitLabel = funcTitle.trim();
+    }
+    if ( unitLabel != null && !"".equals(unitLabel.trim()) ) {
+      axisLabel += " ["+unitLabel.trim()+"]";
+    }
+
+    // Apply common attributes
+    axis.setLabel( axisLabel );
+  }
+
+}

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2010-02-28 18:13:58 UTC (rev 733)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2010-03-01 16:38:12 UTC (rev 734)
@@ -403,15 +403,6 @@
 	public <T> T filterNoDataValue(int idx, T value);
 
 	/**
-	 * Updates the unitVisible parameter for all axes at once.
-	 * 
-	 * @param visible
-	 *            <code>true</code> if unit string shall be displayed in the
-	 *            chart.
-	 */
-	public void setUnitVisible(boolean visible);
-
-	/**
 	 * This class defines a dummy implementation of {@link FeatureChartStyle}
 	 * just to maintain the properties of the interface
 	 * {@link FeatureChartStyle}, so sub classes of {@link FeatureChartStyle}
@@ -581,9 +572,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())
@@ -593,6 +584,8 @@
 					if (isAttributeNormalized(idx))
 						destFCS.setAttributeNormalized(idx,
 								isAttributeNormalized(idx));
+				for (Integer idx : aggrFuncs.keySet())
+				    destFCS.setAttributeAggregation(idx, getAttributeAggregation(idx));
 
 			}
 
@@ -875,23 +868,6 @@
 			throw new UnsupportedOperationException(
 					"FeatureChartStyle.Dummy does not implement applyToFeatureCollection(..)");
 		}
-
-		/**
-		 * Updates the unitVisible parameter for all axes at once.
-		 * 
-		 * @param visible
-		 *            <code>true</code> if unit string shall be displayed in the
-		 *            chart.
-		 */
-		@Override
-		public void setUnitVisible(boolean visible) {
-			// TODO MArtin! Funktioniert so leider nicht. Warum ist hier
-			// getAxisCount() immer 0 ????
-			for (int axisIndex = 0; axisIndex < getAxisCount(); axisIndex++) {
-				getAxisStyle(axisIndex).setUnitVisible(visible);
-			}
-		}
-
 	}
 
 }

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2010-02-28 18:13:58 UTC (rev 733)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2010-03-01 16:38:12 UTC (rev 734)
@@ -34,6 +34,7 @@
 import org.geotools.feature.FeatureCollection;
 import org.jdom.Element;
 
+import schmitzm.jfree.chart.style.ChartAxisStyle;
 import schmitzm.jfree.chart.style.ChartStyle;
 import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
 import schmitzm.jfree.chart.style.ChartType;
@@ -58,6 +59,15 @@
     // Apply the normal style properties
     super.applyStyleFromXML(chartStyle, element);
     
+    // Convert ChartAxisStyle to FeatureChartAxisStyle
+    for (int i=0; i<chartStyle.getAxisCount(); i++) {
+      ChartAxisStyle axisStyle = chartStyle.getAxisStyle(i);
+      if ( axisStyle != null ) {
+        FeatureChartAxisStyle featureAxisStyle = (FeatureChartAxisStyle)axisStyle.copyTo( new FeatureChartAxisStyle(chartStyle) );
+        chartStyle.setAxisStyle(i, featureAxisStyle);
+      }
+    }
+    
     // Attribute definitions in <attributes> element
     Element featureElement = element.getChild("featureAttributes");
     if ( featureElement == null )
@@ -142,6 +152,4 @@
 
     return root;
   }
-
-
 }

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java	2010-02-28 18:13:58 UTC (rev 733)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java	2010-03-01 16:38:12 UTC (rev 734)
@@ -335,16 +335,4 @@
     Dataset dataset = FeatureChartUtil.createDataset(fc,this);
     return applyToDataset(dataset);
   }
-
-  /**
-   * Updates the unitVisible parameter for all axes at once.
-   * 
-   * @param visible
-   *            <code>true</code> if unit string shall be displayed in the
-   *            chart.
-   */
-   @Override
-   public void setUnitVisible(boolean visible) {
-	  dummyFeatureChartStyle.setUnitVisible(visible);
-   }
 }



More information about the Schmitzm-commits mailing list