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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 3 18:12:02 CEST 2009


Author: mojays
Date: 2009-07-03 18:12:02 +0200 (Fri, 03 Jul 2009)
New Revision: 190

Added:
   trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
   trunk/src/schmitzm/jfree/feature/style/
   trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
Removed:
   trunk/src/schmitzm/jfree/style/feature/FeatureChartStyle.java
Modified:
   trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java
Log:
Chart style creation moved from (static) utility classes to ChartStyleXMLFactory and FeatureChartStyleXMLFactory

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java	2009-07-03 15:21:47 UTC (rev 189)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java	2009-07-03 16:12:02 UTC (rev 190)
@@ -11,28 +11,15 @@
 
 package schmitzm.jfree.chart.style;
 
-import java.awt.Paint;
 import java.io.IOException;
 import java.net.URL;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.text.SimpleDateFormat;
-import java.util.List;
-import java.util.Random;
 
 import org.jdom.Document;
-import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.ui.RectangleInsets;
 
-
 import schmitzm.io.IOUtil;
 import schmitzm.jfree.chart.style.ChartStyle.ChartType;
-import schmitzm.lang.LangUtil;
-import schmitzm.swing.SwingUtil;
-import schmitzm.xml.XMLUtil;
 
 /**
  * This class contains static utility methods related to chart styling.
@@ -42,15 +29,29 @@
 public class ChartStyleUtil {
   private static final SAXBuilder SAX_BUILDER = new SAXBuilder();
 
+  /** Instance of {@link ChartStyleXMLFactory}. */
+  public static final ChartStyleXMLFactory CHART_STYLE_FACTORY = new ChartStyleXMLFactory();
+  
   /**
+   * Returns the chart style for a given string.
+   */
+  public static ChartType getChartType(String typeStr) {
+    try {
+      return ChartType.valueOf( typeStr.toUpperCase() );
+    } catch (IllegalArgumentException err){
+      throw new UnsupportedOperationException("Unknown chart style type: "+typeStr);
+    }
+  }
+
+  /**
    * Reads a chart definition from {@link URL}. The URL must refers to
    * a resource which contains exactly one chart definition as root element.<br>
    * <b>The filename is taken as chart ID</b>
    * @param url refers to XML resource
    */
-  public static ChartStyle readStyleFromXML(URL url) throws IOException {
+  public static ChartStyle readStyleFromXML(URL url, ChartStyleXMLFactory factory) throws IOException {
     String id = IOUtil.urlToFile(url).getName();
-    return readStyleFromXML(url, id);
+    return readStyleFromXML(url, id, factory);
   }
 
   /**
@@ -59,291 +60,15 @@
    * @param url refers to XML resource
    * @param id  the ID for the style (if {@code null} the
    *            ID is taken from "id" attribute)
+   * @param factory factory to create the style with
    */
-  public static ChartStyle readStyleFromXML(URL url, String id) throws IOException {
+  public static ChartStyle readStyleFromXML(URL url, String id, ChartStyleXMLFactory factory) throws IOException {
     try {
       Document document = SAX_BUILDER.build(url);
-      return( createStyleFromXML(document.getRootElement(),null) );
+      return( factory.createStyleFromXML(document.getRootElement(),null) );
     } catch (JDOMException err) {
       throw new IOException(err);
     }
   }
 
-  /**
-   * Reads a chart definition from XML element. The chart style ID
-   * is taken from "id" attribute.
-   * @param element the XML element
-   */
-  public static ChartStyle createStyleFromXML(Element element) {
-    return( createStyleFromXML(element,null) );
-  }
-
-  /**
-   * Reads a chart definition from XML element.
-   * @param element the XML element
-   * @param id      the ID for the style (if {@code null} the
-   *                ID is taken from "id" attribute)
-   */
-  public static ChartStyle createStyleFromXML(Element element, String id) {
-    if ( id == null )
-      id = XMLUtil.getAttribute(element, "id", String.valueOf(new Random().nextInt()));
-    
-    // Determine the chart type
-    String               typeStr   = XMLUtil.getAttribute(element, "type");
-    ChartStyle.ChartType chartType = null;
-    if ("area".equalsIgnoreCase(typeStr))
-      chartType = ChartType.AREA;
-    else if ("bar".equalsIgnoreCase(typeStr))
-      chartType = ChartType.BAR;
-    else if ("line".equalsIgnoreCase(typeStr))
-      chartType = ChartType.LINE;
-    else if ("point".equalsIgnoreCase(typeStr))
-      chartType = ChartType.POINT;
-    else if ("pie".equalsIgnoreCase(typeStr))
-      chartType = ChartType.PIE;
-    else if ("gantt".equalsIgnoreCase(typeStr))
-      chartType = ChartType.GANTT;
-    else if( "timeseries".equalsIgnoreCase( typeStr ))
-      chartType = ChartType.TIMESERIES;
-    else if( "spider".equalsIgnoreCase( typeStr ))
-      chartType = ChartType.SPIDER;
-    else if( "scatter".equalsIgnoreCase( typeStr ))
-      chartType = ChartType.SCATTER;
-    else
-      throw new UnsupportedOperationException("Style style not supported: "+typeStr);
-   
-    // create a style according to the type
-    ChartStyle chartStyle = createDefaultChartStyle(id, chartType);
-    
-    // Legend visible
-    chartStyle.setLegend( XMLUtil.getBooleanAttribute(element,"legend",true) );
-    chartStyle.setTooltips( XMLUtil.getBooleanAttribute(element,"tooltips",true) );
-    chartStyle.setURLs( XMLUtil.getBooleanAttribute(element,"urls",true) );
-    
-    // Background color
-    Paint color = XMLUtil.getColorAttribute(element.getChild("background"),"paint");
-    if ( color != null )
-      chartStyle.setBackground( color );
-    
-    // Border around chart visible
-    Boolean borderVisible = XMLUtil.getBooleanAttribute(element.getChild("border"),"visible");
-    if ( borderVisible != null )
-      chartStyle.setBorderVisible( borderVisible );
-
-    // Plot orientation
-    String orientationStr = XMLUtil.getAttribute(element,"orientation","horizontal");
-    if ("horizontal".equalsIgnoreCase(orientationStr))
-      chartStyle.setOrientation( PlotOrientation.HORIZONTAL );
-    else if ("vertical".equalsIgnoreCase(orientationStr))
-      chartStyle.setOrientation( PlotOrientation.VERTICAL );
-    else
-      throw new UnsupportedOperationException("Unknown orientation definition: "+orientationStr);
-
-    // Title style
-    if ( element.getChild("title") != null );
-      chartStyle.setTitleStyle( createTitleStyleFromXML(element.getChild("title") ) );
-    // Domain axis
-    if ( element.getChild("domainAxis") != null );
-      chartStyle.setAxisStyle( ChartStyle.DOMAIN_AXIS,createAxisStyleFromXML(element.getChild("domainAxis") ) );
-    // Range axis
-    if ( element.getChild("rangeAxis") != null );
-      chartStyle.setAxisStyle( ChartStyle.RANGE_AXIS,createAxisStyleFromXML(element.getChild("rangeAxis") ) );
-    // Second range axis
-    if ( element.getChild("rangeAxis2") != null );
-      chartStyle.setAxisStyle( ChartStyle.RANGE_AXIS2,createAxisStyleFromXML(element.getChild("rangeAxis2") ) );
-
-    // Rendering of series
-    List<Element> rendererElements = element.getChildren("renderer");
-    for (int i=0; i<rendererElements.size(); i++)
-      chartStyle.setRendererStyle(i,createRendererStyleFromXML(rendererElements.get(i)));
-      
-    // Plot
-    if ( element.getChild("plot") != null );
-      chartStyle.setPlotStyle( createPlotStyleFromXML(element.getChild("plot") ) );
-      
-    return chartStyle;
-  }
-  
-  /**
-   * Creates a default style for a chart type.
-   * @param id   a (unique) ID for the style
-   * @param type a chart type
-   */
-  public static ChartStyle createDefaultChartStyle(String id, ChartType type) {
-    switch ( type ) {
-      case AREA:  
-      case LINE:  
-      case POINT: return new BasicChartStyle(id, type);
-    }
-    throw new UnsupportedOperationException("Style for this chart type not yet supported: "+type);
-  }
-  
-  /**
-   * Reads the {@link ChartLabelStyle} properties from an XML element.
-   * <ul>
-   *   <li>Attribute "paint": color of the label</li>
-   *   <li>Attribute "angle": angle of the label</li>
-   *   <li>Child element "label": the label content</li>
-   * </ul>
-   * @param element
-   * @param style
-   */
-  private static void applyLabelStyleFromXML(Element element, ChartLabelStyle style) {
-    // color in attribute
-    Paint color = XMLUtil.getColorAttribute(element, "paint");
-    if ( color != null )
-      style.setPaint( color );
-    
-    // label in child element <label>
-    Element labelElem = element.getChild("label");
-    if ( labelElem != null )
-      style.setLabel( labelElem.getTextTrim() ); 
-  }
-  
-  /**
-   * Creates a {@link ChartLabelStyle} from XML element.
-   * @param element an element
-   */
-  public static ChartLabelStyle createTitleStyleFromXML(Element element) {
-    ChartLabelStyle style = new ChartLabelStyle();
-    
-    // read the common ChartLabelStyle properties
-    applyLabelStyleFromXML(element,style);
-    
-    return style;
-  }
-  
-  /**
-   * Creates a {@link ChartLabelStyle} from XML element.
-   * @param element an element
-   */
-  public static ChartAxisStyle createAxisStyleFromXML(Element element) {
-    ChartAxisStyle style = new ChartAxisStyle();
-    
-    // read the common ChartLabelStyle properties
-    applyLabelStyleFromXML(element,style);
-    
-    // read "visible" property from attribute
-    Boolean visible = XMLUtil.getBooleanAttribute(element, "visible");
-    if ( visible != null )
-      style.setVisible( visible );
-
-    // read label angle in attribute
-    Double labelAngle = XMLUtil.getDoubleAttribute(element, "angle");
-    if ( labelAngle != null )
-      style.setLabelAngle( labelAngle );
-
-    // values format and angle from child element <valueLabels>
-    Element valuesElem = element.getChild("valueLabels");
-    if ( valuesElem != null ) {
-      Double valuesAngle = XMLUtil.getDoubleAttribute(valuesElem, "angle");
-      if ( valuesAngle != null )
-        style.setValuesAngle( valuesAngle );
-      String formatStr = XMLUtil.getAttribute(valuesElem, "numberFormat");
-      if ( formatStr != null )
-        style.setValuesFormat(new DecimalFormat(formatStr) );
-      else {
-        formatStr = XMLUtil.getAttribute(valuesElem, "dateFormat");
-        if ( formatStr != null )
-          style.setValuesFormat(new SimpleDateFormat(formatStr) );
-      }
-    }
-    
-    return style;
-  }
-  
-  /**
-   * Creates a {@link ChartRendererStyle} from XML element.
-   * @param element an element
-   */
-  public static ChartRendererStyle createRendererStyleFromXML(Element element) {
-    ChartRendererStyle style = new ChartRendererStyle();
-    
-    // read "margin" property from attribute
-    Double margin = XMLUtil.getDoubleAttribute(element, "margin");
-    if ( margin != null )
-      style.setMargin( margin );
-
-    // read series properties
-    List<Element> seriesElements = element.getChildren("series");
-    for (int i=0; i<seriesElements.size(); i++) {
-      Element seriesElement = seriesElements.get(i);
-      // series paint
-      Paint seriesPaint = XMLUtil.getColorAttribute(seriesElement, "paint");
-      if ( seriesPaint != null )
-        style.setSeriesPaint(i, seriesPaint);
-
-      // item label visibility
-      Boolean labelsVisible = XMLUtil.getBooleanAttribute(seriesElement, "itemLabelsVisible");
-      if ( labelsVisible != null )
-        style.setSeriesItemLabelsVisible(i, labelsVisible);
-
-      // item shapes visibility
-      Boolean shapesVisible = XMLUtil.getBooleanAttribute(seriesElement, "shapesVisible");
-      if ( shapesVisible != null )
-        style.setSeriesShapesVisible(i, shapesVisible);
-    }
-    return style;
-  }
-
-  /**
-   * Creates a {@link ChartPlotStyle} from XML element.
-   * @param element an element
-   */
-  public static ChartPlotStyle createPlotStyleFromXML(Element element) {
-    ChartPlotStyle style = new ChartPlotStyle();
-
-    // foreground transparency
-    Element foregroundElem = element.getChild("foreground");
-    if ( foregroundElem != null ) {
-      Float alpha = XMLUtil.getFloatAttribute(foregroundElem, "alpha");
-      if ( alpha != null )
-        style.setForegroundAlpha(alpha);
-    }
-    
-    // background color and transparency
-    Element backegroundElem = element.getChild("background");
-    if ( backegroundElem != null ) {
-      Float alpha = XMLUtil.getFloatAttribute(backegroundElem, "alpha");
-      if ( alpha != null )
-        style.setBackgroundAlpha(alpha);
-      Paint color = XMLUtil.getColorAttribute(backegroundElem, "paint");
-      if ( color != null )
-        style.setBackgroundPaint(color);
-    }
-    
-    // Insets
-    Element insetsElem = element.getChild("insets");
-    if ( insetsElem != null ) {
-      double top    = XMLUtil.getDoubleAttribute(insetsElem, "top",    0.0);
-      double bottom = XMLUtil.getDoubleAttribute(insetsElem, "bottom", 0.0);
-      double left   = XMLUtil.getDoubleAttribute(insetsElem, "left",   0.0);
-      double right  = XMLUtil.getDoubleAttribute(insetsElem, "right",  0.0);
-      style.setInsets( new RectangleInsets(top,left,bottom,right) );
-    }
-    
-    // domain grid line color and visibility
-    Element domainGridElem = element.getChild("domainGridline");
-    if ( domainGridElem != null ) {
-      Boolean visible = XMLUtil.getBooleanAttribute(domainGridElem, "visible");
-      if ( visible != null )
-        style.setDomainGridlineVisible(visible);
-      Paint color = XMLUtil.getColorAttribute(domainGridElem, "paint");
-      if ( color != null )
-        style.setDomainGridlinePaint(color);
-    }
-
-    // domain grid line color and visibility
-    Element rangeGridElem = element.getChild("domainGridline");
-    if ( rangeGridElem != null ) {
-      Boolean visible = XMLUtil.getBooleanAttribute(rangeGridElem, "visible");
-      if ( visible != null )
-        style.setDomainGridlineVisible(visible);
-      Paint color = XMLUtil.getColorAttribute(rangeGridElem, "paint");
-      if ( color != null )
-        style.setDomainGridlinePaint(color);
-    }
-
-    return style;
-  }
 }

Added: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2009-07-03 15:21:47 UTC (rev 189)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2009-07-03 16:12:02 UTC (rev 190)
@@ -0,0 +1,299 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library 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 2.1 of the License, or (at your option) any later version.
+    This library 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 Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+
+package schmitzm.jfree.chart.style;
+
+import java.awt.Paint;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.List;
+import java.util.Random;
+
+import org.jdom.Element;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.ui.RectangleInsets;
+
+import schmitzm.jfree.chart.style.ChartStyle.ChartType;
+import schmitzm.xml.XMLUtil;
+
+/**
+ * This class defines a factory to create a chart style from XML.
+ * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
+ * @version 1.0
+ */
+public class ChartStyleXMLFactory {
+  /**
+   * Reads a chart definition from XML element. The chart style ID
+   * is taken from "id" attribute.
+   * @param element the XML element
+   * @param factory factory to create the style with
+   */
+  public ChartStyle createStyleFromXML(Element element) {
+    return( createStyleFromXML(element,null) );
+  }
+
+  /**
+   * Reads a chart definition from XML element.
+   * @param element the XML element
+   * @param id      the ID for the style (if {@code null} the
+   *                ID is taken from "id" attribute)
+   */
+  public ChartStyle createStyleFromXML(Element element, String id) {
+    if ( id == null )
+      id = XMLUtil.getAttribute(element, "id", String.valueOf(new Random().nextInt()));
+    
+    // Determine the chart type from XML
+    String               typeStr   = XMLUtil.getAttribute(element, "type");
+    ChartStyle.ChartType chartType = ChartStyleUtil.getChartType(typeStr);
+
+    // apply the "rest" of the XML definition to style
+    ChartStyle chartStyle = createDefaultChartStyle(id, chartType);
+    
+    return chartStyle;
+  }
+  
+  /**
+   * Creates a default style for a chart type.
+   * @param id   a (unique) ID for the style
+   * @param type a chart type
+   */
+  public ChartStyle createDefaultChartStyle(String id, ChartType type) {
+    switch ( type ) {
+      case AREA:  
+      case LINE:  
+      case POINT: return new BasicChartStyle(id, type);
+    }
+    throw new UnsupportedOperationException("Style for this chart type not yet supported: "+type);
+  }
+  
+  /**
+   * Applies the chart style definition from XML (<b>except the type and id!!</b>)
+   * to an existing {@link ChartStyle} object.
+   * @param chartStyle an existing chart style ({@code null} not permitted!)
+   * @param element    element to read the properties from
+   */
+  public void applyStyleFromXML(ChartStyle chartStyle, Element element) {
+    // Legend visible
+    chartStyle.setLegend( XMLUtil.getBooleanAttribute(element,"legend",true) );
+    chartStyle.setTooltips( XMLUtil.getBooleanAttribute(element,"tooltips",true) );
+    chartStyle.setURLs( XMLUtil.getBooleanAttribute(element,"urls",true) );
+    
+    // Background color
+    Paint color = XMLUtil.getColorAttribute(element.getChild("background"),"paint");
+    if ( color != null )
+      chartStyle.setBackground( color );
+    
+    // Border around chart visible
+    Boolean borderVisible = XMLUtil.getBooleanAttribute(element.getChild("border"),"visible");
+    if ( borderVisible != null )
+      chartStyle.setBorderVisible( borderVisible );
+
+    // Plot orientation
+    String orientationStr = XMLUtil.getAttribute(element,"orientation","horizontal");
+    if ("horizontal".equalsIgnoreCase(orientationStr))
+      chartStyle.setOrientation( PlotOrientation.HORIZONTAL );
+    else if ("vertical".equalsIgnoreCase(orientationStr))
+      chartStyle.setOrientation( PlotOrientation.VERTICAL );
+    else
+      throw new UnsupportedOperationException("Unknown orientation definition: "+orientationStr);
+
+    // Title style
+    if ( element.getChild("title") != null );
+      chartStyle.setTitleStyle( createTitleStyleFromXML(element.getChild("title") ) );
+    // Domain axis
+    if ( element.getChild("domainAxis") != null );
+      chartStyle.setAxisStyle( ChartStyle.DOMAIN_AXIS,createAxisStyleFromXML(element.getChild("domainAxis") ) );
+    // Range axis
+    if ( element.getChild("rangeAxis") != null );
+      chartStyle.setAxisStyle( ChartStyle.RANGE_AXIS,createAxisStyleFromXML(element.getChild("rangeAxis") ) );
+    // Second range axis
+    if ( element.getChild("rangeAxis2") != null );
+      chartStyle.setAxisStyle( ChartStyle.RANGE_AXIS2,createAxisStyleFromXML(element.getChild("rangeAxis2") ) );
+
+    // Rendering of series
+    List<Element> rendererElements = element.getChildren("renderer");
+    for (int i=0; i<rendererElements.size(); i++)
+      chartStyle.setRendererStyle(i,createRendererStyleFromXML(rendererElements.get(i)));
+      
+    // Plot
+    if ( element.getChild("plot") != null );
+      chartStyle.setPlotStyle( createPlotStyleFromXML(element.getChild("plot") ) );
+  }
+  
+  /**
+   * Reads the {@link ChartLabelStyle} properties from an XML element.
+   * <ul>
+   *   <li>Attribute "paint": color of the label</li>
+   *   <li>Attribute "angle": angle of the label</li>
+   *   <li>Child element "label": the label content</li>
+   * </ul>
+   * @param element
+   * @param style
+   */
+  private void applyLabelStyleFromXML(Element element, ChartLabelStyle style) {
+    // color in attribute
+    Paint color = XMLUtil.getColorAttribute(element, "paint");
+    if ( color != null )
+      style.setPaint( color );
+    
+    // label in child element <label>
+    Element labelElem = element.getChild("label");
+    if ( labelElem != null )
+      style.setLabel( labelElem.getTextTrim() ); 
+  }
+  
+  /**
+   * Creates a {@link ChartLabelStyle} from XML element.
+   * @param element an element
+   */
+  public ChartLabelStyle createTitleStyleFromXML(Element element) {
+    ChartLabelStyle style = new ChartLabelStyle();
+    
+    // read the common ChartLabelStyle properties
+    applyLabelStyleFromXML(element,style);
+    
+    return style;
+  }
+  
+  /**
+   * Creates a {@link ChartLabelStyle} from XML element.
+   * @param element an element
+   */
+  public ChartAxisStyle createAxisStyleFromXML(Element element) {
+    ChartAxisStyle style = new ChartAxisStyle();
+    
+    // read the common ChartLabelStyle properties
+    applyLabelStyleFromXML(element,style);
+    
+    // read "visible" property from attribute
+    Boolean visible = XMLUtil.getBooleanAttribute(element, "visible");
+    if ( visible != null )
+      style.setVisible( visible );
+
+    // read label angle in attribute
+    Double labelAngle = XMLUtil.getDoubleAttribute(element, "angle");
+    if ( labelAngle != null )
+      style.setLabelAngle( labelAngle );
+
+    // values format and angle from child element <valueLabels>
+    Element valuesElem = element.getChild("valueLabels");
+    if ( valuesElem != null ) {
+      Double valuesAngle = XMLUtil.getDoubleAttribute(valuesElem, "angle");
+      if ( valuesAngle != null )
+        style.setValuesAngle( valuesAngle );
+      String formatStr = XMLUtil.getAttribute(valuesElem, "numberFormat");
+      if ( formatStr != null )
+        style.setValuesFormat(new DecimalFormat(formatStr) );
+      else {
+        formatStr = XMLUtil.getAttribute(valuesElem, "dateFormat");
+        if ( formatStr != null )
+          style.setValuesFormat(new SimpleDateFormat(formatStr) );
+      }
+    }
+    
+    return style;
+  }
+  
+  /**
+   * Creates a {@link ChartRendererStyle} from XML element.
+   * @param element an element
+   */
+  public ChartRendererStyle createRendererStyleFromXML(Element element) {
+    ChartRendererStyle style = new ChartRendererStyle();
+    
+    // read "margin" property from attribute
+    Double margin = XMLUtil.getDoubleAttribute(element, "margin");
+    if ( margin != null )
+      style.setMargin( margin );
+
+    // read series properties
+    List<Element> seriesElements = element.getChildren("series");
+    for (int i=0; i<seriesElements.size(); i++) {
+      Element seriesElement = seriesElements.get(i);
+      // series paint
+      Paint seriesPaint = XMLUtil.getColorAttribute(seriesElement, "paint");
+      if ( seriesPaint != null )
+        style.setSeriesPaint(i, seriesPaint);
+
+      // item label visibility
+      Boolean labelsVisible = XMLUtil.getBooleanAttribute(seriesElement, "itemLabelsVisible");
+      if ( labelsVisible != null )
+        style.setSeriesItemLabelsVisible(i, labelsVisible);
+
+      // item shapes visibility
+      Boolean shapesVisible = XMLUtil.getBooleanAttribute(seriesElement, "shapesVisible");
+      if ( shapesVisible != null )
+        style.setSeriesShapesVisible(i, shapesVisible);
+    }
+    return style;
+  }
+
+  /**
+   * Creates a {@link ChartPlotStyle} from XML element.
+   * @param element an element
+   */
+  public ChartPlotStyle createPlotStyleFromXML(Element element) {
+    ChartPlotStyle style = new ChartPlotStyle();
+
+    // foreground transparency
+    Element foregroundElem = element.getChild("foreground");
+    if ( foregroundElem != null ) {
+      Float alpha = XMLUtil.getFloatAttribute(foregroundElem, "alpha");
+      if ( alpha != null )
+        style.setForegroundAlpha(alpha);
+    }
+    
+    // background color and transparency
+    Element backegroundElem = element.getChild("background");
+    if ( backegroundElem != null ) {
+      Float alpha = XMLUtil.getFloatAttribute(backegroundElem, "alpha");
+      if ( alpha != null )
+        style.setBackgroundAlpha(alpha);
+      Paint color = XMLUtil.getColorAttribute(backegroundElem, "paint");
+      if ( color != null )
+        style.setBackgroundPaint(color);
+    }
+    
+    // Insets
+    Element insetsElem = element.getChild("insets");
+    if ( insetsElem != null ) {
+      double top    = XMLUtil.getDoubleAttribute(insetsElem, "top",    0.0);
+      double bottom = XMLUtil.getDoubleAttribute(insetsElem, "bottom", 0.0);
+      double left   = XMLUtil.getDoubleAttribute(insetsElem, "left",   0.0);
+      double right  = XMLUtil.getDoubleAttribute(insetsElem, "right",  0.0);
+      style.setInsets( new RectangleInsets(top,left,bottom,right) );
+    }
+    
+    // domain grid line color and visibility
+    Element domainGridElem = element.getChild("domainGridline");
+    if ( domainGridElem != null ) {
+      Boolean visible = XMLUtil.getBooleanAttribute(domainGridElem, "visible");
+      if ( visible != null )
+        style.setDomainGridlineVisible(visible);
+      Paint color = XMLUtil.getColorAttribute(domainGridElem, "paint");
+      if ( color != null )
+        style.setDomainGridlinePaint(color);
+    }
+
+    // domain grid line color and visibility
+    Element rangeGridElem = element.getChild("domainGridline");
+    if ( rangeGridElem != null ) {
+      Boolean visible = XMLUtil.getBooleanAttribute(rangeGridElem, "visible");
+      if ( visible != null )
+        style.setDomainGridlineVisible(visible);
+      Paint color = XMLUtil.getColorAttribute(rangeGridElem, "paint");
+      if ( color != null )
+        style.setDomainGridlinePaint(color);
+    }
+
+    return style;
+  }
+}

Added: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2009-07-03 15:21:47 UTC (rev 189)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2009-07-03 16:12:02 UTC (rev 190)
@@ -0,0 +1,50 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library 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 2.1 of the License, or (at your option) any later version.
+    This library 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 Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+
+package schmitzm.jfree.feature.style;
+
+import org.geotools.feature.FeatureCollection;
+import org.jfree.chart.JFreeChart;
+
+import schmitzm.jfree.chart.style.ChartStyle;
+
+/**
+ * This interface extends the chart style with several functionalities
+ * used to define a chart on a {@link FeatureCollection}.
+ * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
+ * @version 1.0
+ */
+public interface FeatureChartStyle extends ChartStyle {
+  /**
+   * 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
+   */
+  public String getAttributeName(int idx);
+  
+  /**
+   * Returns the number of feature attributes needed to create a
+   * chart for this style.
+   */
+  public int getAttributeCount();
+  
+  /**
+   * Creates a chart according to the given 
+   * @param fc  a feature collection
+   * @exception UnsupportedOperationException if the style can not be applied
+   *            to the {@link FeatureCollection} (e.g. the {@link FeatureCollection}
+   *            does not provide the required attributes)
+   */
+  public JFreeChart applyToFeatureCollection(FeatureCollection fc);
+}

Added: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2009-07-03 15:21:47 UTC (rev 189)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2009-07-03 16:12:02 UTC (rev 190)
@@ -0,0 +1,69 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library 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 2.1 of the License, or (at your option) any later version.
+    This library 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 Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+
+package schmitzm.jfree.feature.style;
+
+import org.geotools.feature.FeatureCollection;
+import org.jdom.Element;
+
+import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
+import schmitzm.jfree.chart.style.ChartStyle.ChartType;
+
+/**
+ * This class defines a factory to create a chart style from XML
+ * specialized for {@link FeatureCollection}.
+ * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
+ * @version 1.0
+ */
+public class FeatureChartStyleXMLFactory extends ChartStyleXMLFactory {
+  /**
+   * Reads a chart definition from XML element. The chart style ID
+   * is taken from "id" attribute.
+   * @param element the XML element
+   * @param factory factory to create the style with
+   */
+  @Override
+  public FeatureChartStyle createStyleFromXML(Element element) {
+    return( createStyleFromXML(element,null) );
+  }
+
+  /**
+   * Reads a chart definition from XML element.
+   * @param element the XML element
+   * @param id      the ID for the style (if {@code null} the
+   *                ID is taken from "id" attribute)
+   */
+  @Override
+  public FeatureChartStyle createStyleFromXML(Element element, String id) {
+    // apply the "rest" of the XML definition to style
+    FeatureChartStyle chartStyle = (FeatureChartStyle)super.createStyleFromXML(element, id);
+    
+    // TODO: Apply the feature properties to style!
+    
+    return chartStyle;
+  }
+
+  /**
+   * Creates a default style for a chart type.
+   * @param id   a (unique) ID for the style
+   * @param type a chart type
+   */
+  @Override
+  public FeatureChartStyle createDefaultChartStyle(String id, ChartType type) {
+    // TODO: Create special FeatureChartStyles
+//    switch ( type ) {
+//      case AREA:  
+//      case LINE:  
+//      case POINT: return new BasicChartStyle(id, type);
+//    }
+    throw new UnsupportedOperationException("Style for this chart type not yet supported for features: "+type);
+  }
+}

Added: trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2009-07-03 15:21:47 UTC (rev 189)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java	2009-07-03 16:12:02 UTC (rev 190)
@@ -0,0 +1,27 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library 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 2.1 of the License, or (at your option) any later version.
+    This library 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 Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+
+package schmitzm.jfree.feature.style;
+
+import org.geotools.feature.FeatureCollection;
+
+import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
+
+/**
+ * This class contains static utility methods related to chart styles based on
+ * {@link FeatureCollection}.
+ * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
+ * @version 1.0
+ */
+public class FeatureChartUtil {
+  /** Instance of {@link ChartStyleXMLFactory}. */
+  public static final FeatureChartStyleXMLFactory FEATURE_CHART_STYLE_FACTORY = new FeatureChartStyleXMLFactory();
+}

Deleted: trunk/src/schmitzm/jfree/style/feature/FeatureChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/style/feature/FeatureChartStyle.java	2009-07-03 15:21:47 UTC (rev 189)
+++ trunk/src/schmitzm/jfree/style/feature/FeatureChartStyle.java	2009-07-03 16:12:02 UTC (rev 190)
@@ -1,50 +0,0 @@
-/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
-
-    This library 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 2.1 of the License, or (at your option) any later version.
-    This library 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 Lesser General Public License for more details.
-    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
-
-    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
-    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
-    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
- **/
-
-package schmitzm.jfree.style.feature;
-
-import org.geotools.feature.FeatureCollection;
-import org.jfree.chart.JFreeChart;
-
-import schmitzm.jfree.chart.style.ChartStyle;
-
-/**
- * This interface extends the chart style with several functionalities
- * used to define a chart on a {@link FeatureCollection}.
- * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
- * @version 1.0
- */
-public interface FeatureChartStyle extends ChartStyle {
-  /**
-   * 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
-   */
-  public String getAttributeName(int idx);
-  
-  /**
-   * Returns the number of feature attributes needed to create a
-   * chart for this style.
-   */
-  public int getAttributeCount();
-  
-  /**
-   * Creates a chart according to the given 
-   * @param fc  a feature collection
-   * @exception UnsupportedOperationException if the style can not be applied
-   *            to the {@link FeatureCollection} (e.g. the {@link FeatureCollection}
-   *            does not provide the required attributes)
-   */
-  public JFreeChart applyToFeatureCollection(FeatureCollection fc);
-}



More information about the Schmitzm-commits mailing list