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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 3 16:57:50 CEST 2009


Author: mojays
Date: 2009-07-03 16:57:50 +0200 (Fri, 03 Jul 2009)
New Revision: 187

Modified:
   trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartLabelStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java
   trunk/src/schmitzm/jfree/style/feature/FeatureChartStyle.java
Log:
chart style enhancements

Modified: trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2009-07-03 14:40:10 UTC (rev 186)
+++ trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2009-07-03 14:57:50 UTC (rev 187)
@@ -36,6 +36,7 @@
 
 import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.lang.LangUtil;
+import skrueger.i8n.Translation;
 
 /**
  * This class provides an abstract implementation for chart styles.
@@ -344,6 +345,7 @@
       title = new TextTitle();
       chart.setTitle( title );
     }
+    
     if ( getTitleStyle().getLabel() != null )
       title.setText( getTitleStyle().getLabel() );
     if ( getTitleStyle().getPaint() != null )

Modified: trunk/src/schmitzm/jfree/chart/style/ChartLabelStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartLabelStyle.java	2009-07-03 14:40:10 UTC (rev 186)
+++ trunk/src/schmitzm/jfree/chart/style/ChartLabelStyle.java	2009-07-03 14:57:50 UTC (rev 187)
@@ -13,20 +13,19 @@
 
 import java.awt.Color;
 import java.awt.Paint;
+import java.util.Locale;
 
 import org.apache.log4j.Category;
-import org.jfree.chart.JFreeChart;
-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 org.jfree.data.general.Dataset;
 
 import schmitzm.lang.LangUtil;
+import skrueger.i8n.Translation;
 
 /**
- * This interface is a general super class for a design style of a chart
- * {@link Axis}.
+ * This class is a general super class for a design style of text displayed
+ * in a chart. This can be an localized text according to {@link Translation} or
+ * a simple (unlocalized) String. The {@link #setLabel(String)} method will
+ * try to decode the string for multiple languages. If this is not possible
+ * the core string is taken as label.
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
  * @version 1.0
  */
@@ -35,7 +34,7 @@
   protected final Category LOGGER = LangUtil.createLogger(this);
 
   /** Holds the label text. */
-  protected String label = null;
+  protected Translation label = null;
   /** Holds the text color of the label. */
   protected Paint paint = null;
   
@@ -48,18 +47,43 @@
 
   /**
    * Creates a new style.
-   * @param label label text
+   * @param label label text (localized or static label is provided)
    * @param color text color
    */
   public ChartLabelStyle(String label, Paint color) {
-    setLabel(label);
+    this(new Translation(label), color);
+  }
+  
+  /**
+   * Creates a new style.
+   * @param label label text (static
+   * @param color text color
+   */
+  public ChartLabelStyle(Translation label, Paint color) {
+    setLabelTranslation(label);
     setPaint(color);
   }
+
+  /**
+   * Returns the label text in the default localization.
+   * @see Locale#getDefault()
+   */
+  public String getLabel() {
+    return label.toString();
+  }
+
+  /**
+   * Sets the label text.
+   * @param label the text for the label (localized or static label is provided)
+   */
+  public void setLabel(String label) {
+    this.label = new Translation(label);
+  }
   
   /**
-   * Returns the label text.
+   * Returns the label text for all localizations.
    */
-  public String getLabel() {
+  public Translation getLabelTranslation() {
     return label;
   }
 
@@ -67,7 +91,7 @@
    * Sets the label text.
    * @param label the text for the label
    */
-  public void setLabel(String label) {
+  public void setLabelTranslation(Translation label) {
     this.label = label;
   }
   

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java	2009-07-03 14:40:10 UTC (rev 186)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java	2009-07-03 14:57:50 UTC (rev 187)
@@ -35,12 +35,26 @@
  */
 public class ChartStyleUtil {
   
+  /**
+   * 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) {
-    if (!"style".equals(element.getName()))
-      throw new IllegalArgumentException("Element is no style element: "+element.getName());
+    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               id        = XMLUtil.getAttribute(element, "id", String.valueOf(new Random().nextInt()));
     String               typeStr   = XMLUtil.getAttribute(element, "type");
     ChartStyle.ChartType chartType = null;
     if ("area".equalsIgnoreCase(typeStr))

Modified: trunk/src/schmitzm/jfree/style/feature/FeatureChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/style/feature/FeatureChartStyle.java	2009-07-03 14:40:10 UTC (rev 186)
+++ trunk/src/schmitzm/jfree/style/feature/FeatureChartStyle.java	2009-07-03 14:57:50 UTC (rev 187)
@@ -22,8 +22,24 @@
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
  * @version 1.0
  */
-public interface FeatureChartStyle extends ChartStyle {
+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



More information about the Schmitzm-commits mailing list