[Schmitzm-commits] r182 - trunk/src/schmitzm/jfree/chart/style

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 3 14:44:59 CEST 2009


Author: mojays
Date: 2009-07-03 14:44:59 +0200 (Fri, 03 Jul 2009)
New Revision: 182

Modified:
   trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
   trunk/src/schmitzm/jfree/chart/style/BasicChartStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java
Log:
ID for chart styles

Modified: trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2009-07-03 10:49:32 UTC (rev 181)
+++ trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2009-07-03 12:44:59 UTC (rev 182)
@@ -57,7 +57,8 @@
   
   /** Logger for this class */
   protected final Category LOGGER = LangUtil.createLogger(this);
-
+  /** Holds a (unique) ID for the style. */
+  protected String id = "";
   /** Holds the chart type.
    *  @see  ChartStyle#ChartType */
   protected ChartType type = null;
@@ -83,22 +84,25 @@
   protected ChartPlotStyle plotStyle = null;
 
   /**
-   * Creates a line style with default values.
+   * Creates a line style with default values.
+   * @param id a (unique) ID for the style
    */
-  public AbstractChartStyle() {
-    this( ChartType.LINE );
+  public AbstractChartStyle(String id) {
+    this( id, ChartType.LINE );
   }
 
   /**
    * Creates a style with default values.
-   * @param type     style type
+   * @param id   a (unique) ID for the style
+   * @param type style type
    */
-  public AbstractChartStyle(ChartType type) {
-    this(type,null,null,null,true,true,true);
+  public AbstractChartStyle(String id, ChartType type) {
+    this(id,type,null,null,null,true,true,true);
   }
 
   /**
    * Creates a style.
+   * @param id       a (unique) ID for the style
    * @param type     style type
    * @param title    title for the chart
    * @param xTitle   title for the chart's X-axis
@@ -107,9 +111,10 @@
    * @param tooltips flag whether toolstips are generated
    * @param urls     flag whether URLs are generated
    */
-  public AbstractChartStyle(ChartType type,
+  public AbstractChartStyle(String    id,     ChartType type,
                             String    title,  String  xTitle,   String  yTitle,
                             boolean   legend, boolean tooltips, boolean urls) {
+    this.id = id;
     setType(type);
     setLegend(legend);
     setTooltips(tooltips);
@@ -121,6 +126,13 @@
       setAxisStyle(RANGE_AXIS, new ChartAxisStyle(yTitle,Color.BLACK,0.0,0.0) );
   }
 
+  /**
+   * Returns the (unique) ID for the style.
+   */
+  public String getID() {
+    return id;
+  }
+
   /**
    * Returns the type of the chart style.
    */

Modified: trunk/src/schmitzm/jfree/chart/style/BasicChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/BasicChartStyle.java	2009-07-03 10:49:32 UTC (rev 181)
+++ trunk/src/schmitzm/jfree/chart/style/BasicChartStyle.java	2009-07-03 12:44:59 UTC (rev 182)
@@ -40,32 +40,36 @@
 
   /**
    * Creates a normal line style with default values.
+   * @param id   a (unique) ID for the style
    */
-  public BasicChartStyle() {
-    this(ChartType.LINE);
+  public BasicChartStyle(String id) {
+    this(id, ChartType.LINE);
   }
 
   /**
    * Creates a normal, vertical line, bar or area style.
+   * @param id   a (unique) ID for the style
    * @param type type of the chart layout
    */
-  public BasicChartStyle(ChartType type) {
-    this(type, false, false, PlotOrientation.VERTICAL);
+  public BasicChartStyle(String id, ChartType type) {
+    this(id, type, false, false, PlotOrientation.VERTICAL);
   }
 
   /**
    * Creates a line, area or bar chart style.
+   * @param id          a (unique) ID for the style
    * @param type        style type
    * @param stacked     flag whether the chart is stacked (ignored for line charts)
    * @param stepped     flag whether the chart is stepped (ignored for bar charts)
    * @param orientation orientation of the chart ({@link PlotOrientation.VERTICAL} or {@link PlotOrientation.HORIZONTAL})
    */
-  public BasicChartStyle(ChartType type, boolean stacked, boolean stepped, PlotOrientation orientation) {
-    this(type, stacked, stepped, orientation, null, null, null, true, true, true);
+  public BasicChartStyle(String id, ChartType type, boolean stacked, boolean stepped, PlotOrientation orientation) {
+    this(id, type, stacked, stepped, orientation, null, null, null, true, true, true);
   }
 
   /**
    * Creates a chart style.
+   * @param id       a (unique) ID for the style
    * @param type     style type
    * @param stacked  flag whether the chart is stacked (ignored for line charts)
    * @param stepped  flag whether the chart is stepped (ignored for bar charts)
@@ -77,11 +81,11 @@
    * @param tooltips flag whether toolstips are generated
    * @param urls     flag whether URLs are generated
    */
-  public BasicChartStyle(ChartType type, boolean stacked,  boolean stepped,
+  public BasicChartStyle(String id, ChartType type, boolean stacked,  boolean stepped,
                          PlotOrientation orientation,
                          String title,   String xTitle,    String yTitle,
                          boolean legend, boolean tooltips, boolean urls) {
-    super(type, title, xTitle, yTitle, legend, tooltips, urls);
+    super(id, type, title, xTitle, yTitle, legend, tooltips, urls);
     setStacked( stacked );
     setStepped( stepped );
     setOrientation( orientation );

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyle.java	2009-07-03 10:49:32 UTC (rev 181)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyle.java	2009-07-03 12:44:59 UTC (rev 182)
@@ -59,6 +59,11 @@
   /** Constant for the second range axis (Y). */
   public static final int RANGE_AXIS2 = 2;
 
+  /**
+   * Returns an (unique) ID for the style.
+   */
+  public String getID();
+
   /**
    * Returns the type of the chart style.
    */

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java	2009-07-03 10:49:32 UTC (rev 181)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java	2009-07-03 12:44:59 UTC (rev 182)
@@ -16,13 +16,16 @@
 import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.util.List;
+import java.util.Random;
 
+import org.apache.poi.hssf.record.formula.functions.Rand;
 import org.jdom.Element;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.ui.RectangleInsets;
 
 
 import schmitzm.jfree.chart.style.ChartStyle.ChartType;
+import schmitzm.lang.LangUtil;
 import schmitzm.swing.SwingUtil;
 import schmitzm.xml.XMLUtil;
 
@@ -38,6 +41,7 @@
       throw new IllegalArgumentException("Element is no style element: "+element.getName());
     
     // Determine the chart type
+    String               id        = XMLUtil.getAttribute(element, "id", String.valueOf(new Random().nextInt()));
     String               typeStr   = XMLUtil.getAttribute(element, "type");
     ChartStyle.ChartType chartType = null;
     if ("area".equalsIgnoreCase(typeStr))
@@ -62,7 +66,7 @@
       throw new UnsupportedOperationException("Style style not supported: "+typeStr);
    
     // create a style according to the type
-    ChartStyle chartStyle = createDefaultChartStyle(chartType);
+    ChartStyle chartStyle = createDefaultChartStyle(id, chartType);
     
     // Legend visible
     chartStyle.setLegend( XMLUtil.getBooleanAttribute(element,"legend",true) );
@@ -115,13 +119,14 @@
   
   /**
    * 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(ChartType type) {
+  public static ChartStyle createDefaultChartStyle(String id, ChartType type) {
     switch ( type ) {
       case AREA:  
       case LINE:  
-      case POINT: return new BasicChartStyle(type);
+      case POINT: return new BasicChartStyle(id, type);
     }
     throw new UnsupportedOperationException("Style for this chart type not yet supported: "+type);
   }



More information about the Schmitzm-commits mailing list