[Schmitzm-commits] r247 - in trunk: dist src/schmitzm/jfree/chart/style src/schmitzm/lang

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 31 12:30:09 CEST 2009


Author: mojays
Date: 2009-07-31 12:29:47 +0200 (Fri, 31 Jul 2009)
New Revision: 247

Modified:
   trunk/dist/schmitzm-src.zip
   trunk/dist/schmitzm.jar
   trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
   trunk/src/schmitzm/lang/LangUtil.java
Log:
ChartStyle, AbstractChartStyle: new method getRendererCount()
ChartRendererStyle: new method getSeriesCount()
ChartStyleXMLFactory: write renderer style to XML
LangUtil: new method to determine the min/max value of a set of collections

Modified: trunk/dist/schmitzm-src.zip
===================================================================
(Binary files differ)

Modified: trunk/dist/schmitzm.jar
===================================================================
(Binary files differ)

Modified: trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2009-07-30 16:32:22 UTC (rev 246)
+++ trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2009-07-31 10:29:47 UTC (rev 247)
@@ -41,8 +41,10 @@
 
 import java.awt.Color;
 import java.awt.Paint;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 import java.util.Vector;
 
 import org.apache.log4j.Category;
@@ -115,6 +117,8 @@
   protected boolean urls = true;
   /** Holds the styles for the chart renderers. */
   protected Map<Integer,ChartRendererStyle> rendererStyle = new HashMap<Integer,ChartRendererStyle>();
+  /** Holds the maximum dataset index for which a renderer is specified. */
+  protected int maxRendererDatasetIdx = 0;
   /** Holds the style for the chart's plot. */
   protected ChartPlotStyle plotStyle = null;
 
@@ -330,6 +334,13 @@
   }
   
   /**
+   * Returns count of renderer for the chart.
+   */
+  public int getRendererCount() {
+    return maxRendererDatasetIdx;
+  }
+
+  /**
    * Returns the style of a dataset renderer.
    * @param dataset dataset number (starting with 0)
    * @return {@code null} if the chart has no such renderer
@@ -345,6 +356,7 @@
    */
   public void setRendererStyle(int dataset, ChartRendererStyle style) {
     rendererStyle.put(dataset, style);
+    maxRendererDatasetIdx = LangUtil.max( rendererStyle.keySet() );
   }
 
   /**

Modified: trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java	2009-07-30 16:32:22 UTC (rev 246)
+++ trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java	2009-07-31 10:29:47 UTC (rev 247)
@@ -34,6 +34,7 @@
 import java.text.DateFormat;
 import java.text.Format;
 import java.text.NumberFormat;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -77,6 +78,8 @@
   protected Map<Integer, Color> seriesPaint = new HashMap<Integer, Color>();
   /** Holds whether the shape of a series is visible. */
   protected Map<Integer, Boolean> seriesShapesVisible = new HashMap<Integer, Boolean>();
+  /** Holds the maximum series index for which a series is specified. */
+  protected int maxSeriesIdx = 0;
   /** Holds the (percentage) margin for the bars. Only applicable for {@link XYBarRenderer}. */
   protected double margin = 0.0;
   
@@ -103,6 +106,13 @@
   }
 
   /**
+   * Returns the count of series the style is defined for.
+   */
+  public int getSeriesCount() {
+    return maxSeriesIdx;
+  }
+  
+  /**
    * Returns the color, a series is painted with.
    * @param series series index
    * @return {@code null} if no specific color is set for the series
@@ -119,6 +129,7 @@
    */
   public void setSeriesPaint(int series, Color color) {
     seriesPaint.put(series,color);
+    updateSeriesCount();
   }
 
   /**
@@ -138,6 +149,7 @@
    */
   public void setSeriesItemLabelsVisible(int series, Boolean visible) {
     seriesItemLabelsVisible.put(series,visible);
+    updateSeriesCount();
   }
 
   /**
@@ -157,9 +169,22 @@
    */
   public void setSeriesShapesVisible(int series, Boolean visible) {
     seriesShapesVisible.put(series,visible);
+    updateSeriesCount();
   }
 
   /**
+   * Updates the local variable for the defined series with
+   * the maximum index (key) of the several hash maps. 
+   */
+  private void updateSeriesCount() {
+    maxSeriesIdx = LangUtil.max(
+                      seriesPaint.keySet(),
+                      seriesShapesVisible.keySet(),
+                      seriesItemLabelsVisible.keySet()
+    );
+  }
+  
+  /**
    * Applies the style to a specific renderer.<br>
    * Note: Some style properties can only be applied to specific renderer types.
    * @param renderer a renderer

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyle.java	2009-07-30 16:32:22 UTC (rev 246)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyle.java	2009-07-31 10:29:47 UTC (rev 247)
@@ -187,6 +187,11 @@
 
   
   /**
+   * Returns count of renderer for the chart.
+   */
+  public int getRendererCount();
+
+  /**
    * Returns the style of a dataset renderer.
    * @param dataset dataset number (starting with 0)
    * @return {@code null} if the chart has no such renderer

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2009-07-30 16:32:22 UTC (rev 246)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2009-07-31 10:29:47 UTC (rev 247)
@@ -101,6 +101,7 @@
       case AREA:  
       case LINE:  
       case POINT: return (E) new BasicChartStyle(id, type);
+      case SCATTER: return (E) new ScatterChartStyle(id);
     }
     throw new UnsupportedOperationException("Style for this chart type not yet supported: "+type);
   }
@@ -361,13 +362,13 @@
    * @param style           style to store
    * @param rootElementName name for the root element (if {@code null} "ChartType" is 
    *                        used)
-   * @param documentUrl     URL to store the style to
+   * @param filePath        file to store the style to
    */
-  public void writeStyleToURL(E style, String rootElementName, URL documentUrl) throws IOException, URISyntaxException {
-    final FileWriter out = new FileWriter( new File(documentUrl.toURI()) );
+  public void writeStyleToURL(E style, String rootElementName, File filePath) throws IOException, URISyntaxException {
+    final FileWriter out = new FileWriter( filePath );
     // Create XML-Document
     XMLUtil.XML_OUTPUTTER.output(
-        createElementFromStyle(style, rootElementName),
+      createElementFromStyle(style, rootElementName),
       out
     );
     out.flush();
@@ -378,7 +379,7 @@
   /**
    * Creates a XML {@link Element} representing the {@link ChartStyle}.
    * @param style           style to create an element for
-   * @param rootElementName name for the root element (if {@code null} "ChartType" is 
+   * @param rootElementName name for the root element (if {@code null} "ChartStyle" is 
    *                        used)
    */
   public Element createElementFromStyle(E style, String rootElementName) {
@@ -421,6 +422,10 @@
     if ( style.getAxisCount() > 2 )
       addAxisChildToElement(root, "rangeAxis2", style.getAxisStyle(2) );
     
+    // Renderer
+    for (int i=0; i<style.getRendererCount(); i++)
+      addRendererChildToElement(root, style.getRendererStyle(i));
+    
     // TODO: <renderer> + <plot>
     
     // Type specific style properties
@@ -489,8 +494,8 @@
    * @param element    if not {@code null} the new element is added as child to
    *                   this element
    * @param axisChildName  name of the new child
-   * @param labelStyle the label style to create the element for
-   * @return the new child element; {@code null} if {@code labelStyle} is {@code null}
+   * @param axisStyle the axis style to create the element for
+   * @return the new child element; {@code null} if {@code axisStyle} is {@code null}
    */
   private static Element addAxisChildToElement(Element element, String axisChildName, ChartAxisStyle axisStyle) {
     if ( axisStyle == null )
@@ -518,4 +523,36 @@
     return axisElem;
   }
 
+  /**
+   * Creates an child element for a {@link ChartRendererStyle}.
+   * If an element is given, the new child is automatically added. 
+   * @param element    if not {@code null} the new element is added as child to
+   *                   this element
+   * @param rendererStyle the renderer style to create the element for
+   * @return the new child element; if {@code rendererStyle} is {@code null} an empty
+   *         element is returned and added (so that the order of the renderers according
+   *         to the dataset is preserved)
+   */
+  private static Element addRendererChildToElement(Element element, ChartRendererStyle rendererStyle) {
+    // Create and add child with visible attribute
+    Element rendererElem = addChildToElement(element, "renderer"); 
+    
+    if ( rendererStyle != null ) {
+      // Margin attribute
+      if ( rendererStyle.getMargin() != null )
+        rendererElem.setAttribute("margin", String.valueOf( rendererStyle.getMargin() ));
+      // Create <series> child for all series
+      for ( int i=0; i<rendererStyle.getSeriesCount(); i++) {
+        Element seriesElem = addChildToElement(rendererElem, "series");
+        if ( rendererStyle.getSeriesPaint(i) != null )
+          seriesElem.setAttribute("paint", Integer.toHexString( rendererStyle.getSeriesPaint(i).getRGB() ));
+        if ( rendererStyle.isSeriesItemLabelsVisible(i) != null )
+          seriesElem.setAttribute("itemLabelsVisible", String.valueOf( rendererStyle.isSeriesItemLabelsVisible(i) ));
+        if ( rendererStyle.isSeriesShapesVisible(i) != null )
+          seriesElem.setAttribute("shapesVisible", String.valueOf( rendererStyle.isSeriesShapesVisible(i) ));
+      }
+    }
+    
+    return rendererElem;
+  }
 }

Modified: trunk/src/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/src/schmitzm/lang/LangUtil.java	2009-07-30 16:32:22 UTC (rev 246)
+++ trunk/src/schmitzm/lang/LangUtil.java	2009-07-31 10:29:47 UTC (rev 247)
@@ -34,6 +34,7 @@
 import java.net.URLClassLoader;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.Locale;
 import java.util.TreeSet;
@@ -789,8 +790,58 @@
       }
     });
   }
+  
+  /**
+   * Returns the maximum value of some integer collections.
+   * @param defMaxValue value taken as maximum if a collection is empty
+   * @param collections some collections
+   */
+  public static int max(int defMaxValue, Collection<Integer>... collections) {
+    int maxValue = defMaxValue;
+    for (Collection<Integer> collection : collections) {
+      int collMax = defMaxValue;
+      if ( collection != null && !collection.isEmpty() )
+        collMax = Collections.max(collection);
+      maxValue = Math.max( maxValue, collMax );
+    }
+    return maxValue;
+  }
+  
+  /**
+   * Returns the maximum value of some integer collections. If
+   * a collection is empty, 0 is taken as its maximum value.
+   * @param collections some collections
+   */
+  public static int max(Collection<Integer>... collections) {
+    return max(0,collections);
+  }
 
   /**
+   * Returns the minimum value of some integer collections.
+   * @param defMinValue value taken as minimum if a collection is empty
+   * @param collections some collections
+   */
+  public static int min(int defMinValue, Collection<Integer>... collections) {
+    int minValue = defMinValue;
+    for (Collection<Integer> collection : collections) {
+      int collMin = defMinValue;
+      if ( collection != null && !collection.isEmpty() )
+        collMin = Collections.min(collection);
+      minValue = Math.min( minValue, collMin );
+    }
+    return minValue;
+  }
+  
+  /**
+   * Returns the minimum value of some integer collections. If
+   * a collection is empty, 0 is taken as its minimum value.
+   * @param collections some collections
+   */
+  public static int min(Collection<Integer>... collections) {
+    return min(0,collections);
+  }
+
+  /**
    * Rundet einen Wert auf Nach- oder Vorkommastellen.
    * @param value Wert
    * @param digits Anzahl an Nachkommastellen (negative Werte runden auf



More information about the Schmitzm-commits mailing list