[Schmitzm-commits] r830 - branches/2.0-GP14/src/schmitzm/jfree/chart/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed May 5 17:55:40 CEST 2010
Author: alfonx
Date: 2010-05-05 17:55:39 +0200 (Wed, 05 May 2010)
New Revision: 830
Modified:
branches/2.0-GP14/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
Log:
Feature: X-Achsis Labels are centered when they are not rotated.
Modified: branches/2.0-GP14/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
===================================================================
--- branches/2.0-GP14/src/schmitzm/jfree/chart/style/ChartAxisStyle.java 2010-05-05 15:43:39 UTC (rev 829)
+++ branches/2.0-GP14/src/schmitzm/jfree/chart/style/ChartAxisStyle.java 2010-05-05 15:55:39 UTC (rev 830)
@@ -45,284 +45,337 @@
/**
* This class is defines the design style of a chart {@link Axis}.
+ *
* @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
* @version 1.0
*/
public class ChartAxisStyle extends ChartLabelStyle {
- /** Holds the angle (in degrees) the label is rotated by. */
- protected Double angleDegr = 0.0;
- /** Holds the angle (in degrees) the axis values are rotated by. */
- protected Double valuesAngleDegr = 0.0;
- /** Holds whether the axis is visible. */
- protected boolean visible = true;
- /** Holds the number format to display the axis values. */
- protected Format valuesFormat = null;
- /** Holds a String that reflects the values units */
- protected String unitString = null;
- /** Indicates whether the unit is visible in axis label (Default is {@code true}). */
- protected boolean unitStringVisible = true;
+ /** Holds the angle (in degrees) the label is rotated by. */
+ protected Double angleDegr = 0.0;
+ /** Holds the angle (in degrees) the axis values are rotated by. */
+ protected Double valuesAngleDegr = 0.0;
+ /** Holds whether the axis is visible. */
+ protected boolean visible = true;
+ /** Holds the number format to display the axis values. */
+ protected Format valuesFormat = null;
+ /** Holds a String that reflects the values units */
+ protected String unitString = null;
+ /**
+ * Indicates whether the unit is visible in axis label (Default is {@code
+ * true}).
+ */
+ protected boolean unitStringVisible = true;
- /**
- * Creates a new style with default values (empty label, color black, angle 0).
- */
- public ChartAxisStyle() {
- this("",Color.BLACK, 0.0 ,0.0);
- }
+ /**
+ * Creates a new style with default values (empty label, color black, angle
+ * 0).
+ */
+ public ChartAxisStyle() {
+ this("", Color.BLACK, 0.0, 0.0);
+ }
- /**
- * Creates a new style.
- * @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 ChartAxisStyle(String title, Color color, Double labelAngle, Double valuesAngle) {
- super(title,color);
- setLabelAngle(labelAngle);
- setValuesAngle(valuesAngle);
- }
-
- /**
- * Creates a new style.
- * @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 ChartAxisStyle(Translation title, Color color, Double labelAngle, Double valuesAngle) {
- super(title,color);
- setLabelAngle(labelAngle);
- setValuesAngle(valuesAngle);
- }
+ /**
+ * Creates a new style.
+ *
+ * @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 ChartAxisStyle(String title, Color color, Double labelAngle,
+ Double valuesAngle) {
+ super(title, color);
+ setLabelAngle(labelAngle);
+ setValuesAngle(valuesAngle);
+ }
- /**
- * Creates a (deep) clone of this style.
- */
- @Override
- public ChartAxisStyle copy() {
- return copyTo( new ChartAxisStyle() );
- }
-
- /**
- * Copies all properties of this style to another one.
- * @param dest destination object (if {@code null} the copy
- * is created by {@link #copy()})
- * @return {@code dest} or the new instance
- */
- public ChartAxisStyle copyTo(ChartAxisStyle dest) {
- // copy the super class properties
- dest = (ChartAxisStyle)copyTo((ChartLabelStyle)dest);
- // copy this classes properties
- dest.setLabelAngle( getLabelAngle() );
- dest.setValuesAngle( getValuesAngle() );
- dest.setVisible( isVisible() );
- dest.setValuesFormat( getValuesFormat() );
- dest.setUnitString( getUnitString() );
- dest.setUnitVisible( isUnitVisible() );
- return dest;
- }
+ /**
+ * Creates a new style.
+ *
+ * @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 ChartAxisStyle(Translation title, Color color, Double labelAngle,
+ Double valuesAngle) {
+ super(title, color);
+ setLabelAngle(labelAngle);
+ setValuesAngle(valuesAngle);
+ }
- /**
- * Returns the angle (in degrees) the label text is rotated by.
- */
- public Double getLabelAngle() {
- return angleDegr;
- }
+ /**
+ * Creates a (deep) clone of this style.
+ */
+ @Override
+ public ChartAxisStyle copy() {
+ return copyTo(new ChartAxisStyle());
+ }
- /**
- * Returns the angle (in radian) the label text is rotated by.
- */
- public Double getLabelAngleRadian() {
- return angleDegr == null ? null : angleDegr * Math.PI / 180;
- }
+ /**
+ * Copies all properties of this style to another one.
+ *
+ * @param dest
+ * destination object (if {@code null} the copy is created by
+ * {@link #copy()})
+ * @return {@code dest} or the new instance
+ */
+ public ChartAxisStyle copyTo(ChartAxisStyle dest) {
+ // copy the super class properties
+ dest = (ChartAxisStyle) copyTo((ChartLabelStyle) dest);
+ // copy this classes properties
+ dest.setLabelAngle(getLabelAngle());
+ dest.setValuesAngle(getValuesAngle());
+ dest.setVisible(isVisible());
+ dest.setValuesFormat(getValuesFormat());
+ dest.setUnitString(getUnitString());
+ dest.setUnitVisible(isUnitVisible());
+ return dest;
+ }
- /**
- * Sets the angle (in degrees) the label text is rotated by.
- * @param color Color for the label text
- */
- public void setLabelAngle(Double angle) {
- this.angleDegr = angle;
- }
+ /**
+ * Returns the angle (in degrees) the label text is rotated by.
+ */
+ public Double getLabelAngle() {
+ return angleDegr;
+ }
- /**
- * Returns the angle (in degrees) the axis values are rotated by.
- */
- public Double getValuesAngle() {
- return valuesAngleDegr;
- }
+ /**
+ * Returns the angle (in radian) the label text is rotated by.
+ */
+ public Double getLabelAngleRadian() {
+ return angleDegr == null ? null : angleDegr * Math.PI / 180;
+ }
- /**
- * Returns the angle (in radian) the axis values are rotated by.
- */
- public double getValuesAngleRadian() {
- return valuesAngleDegr * Math.PI / 180;
- }
+ /**
+ * Sets the angle (in degrees) the label text is rotated by.
+ *
+ * @param color
+ * Color for the label text
+ */
+ public void setLabelAngle(Double angle) {
+ this.angleDegr = angle;
+ }
- /**
- * Sets the angle (in degrees) the label text is rotated by.
- * @param color Color for the label text
- */
- public void setValuesAngle(Double angel) {
- this.valuesAngleDegr = angel;
- }
+ /**
+ * Returns the angle (in degrees) the axis values are rotated by.
+ */
+ public Double getValuesAngle() {
+ return valuesAngleDegr;
+ }
- /**
- * Returns whether the axis is visible.
- */
- public boolean isVisible() {
- return visible;
- }
+ /**
+ * Returns the angle (in radian) the axis values are rotated by.
+ */
+ public double getValuesAngleRadian() {
+ return valuesAngleDegr * Math.PI / 180;
+ }
- /**
- * Sets whether the axis is visible.
- */
- public void setVisible(boolean visible) {
- this.visible = visible;
- }
+ /**
+ * Sets the angle (in degrees) the label text is rotated by.
+ *
+ * @param color
+ * Color for the label text
+ */
+ public void setValuesAngle(Double angel) {
+ this.valuesAngleDegr = angel;
+ }
- /**
- * Returns the (number) format for the axis values.
- */
- public Format getValuesFormat() {
- return valuesFormat;
- }
+ /**
+ * Returns whether the axis is visible.
+ */
+ public boolean isVisible() {
+ return visible;
+ }
- /**
- * Sets the (number) format for the axis values.
- */
- public void setValuesFormat(Format format) {
- this.valuesFormat = format;
- }
-
- /**
- * Applies the style to a specific axis.<br>
- * Note: Some style properties can only be applied to specific axis types.
- * @param axis an axis
- */
- public void applyToAxis(Axis axis) {
- if (axis == null) {
- LOGGER.debug("No axis to be customised.");
- return;
- }
+ /**
+ * Sets whether the axis is visible.
+ */
+ public void setVisible(boolean visible) {
+ this.visible = visible;
+ }
- // If unit is set, add it to axis title
- String axisLabel = getLabel();
- String unitString = getUnitString();
- if ( isUnitVisible() && unitString != null && !"".equals(unitString.trim()) )
- axisLabel += " ["+unitString.trim()+"]";
-
- // Apply common attributes
- axis.setLabel( axisLabel );
- if (getPaint() != null)
- axis.setLabelPaint( getPaint() );
- if (getLabelAngle() != null)
- axis.setLabelAngle( getLabelAngle() );
- axis.setVisible( isVisible() );
+ /**
+ * Returns the (number) format for the axis values.
+ */
+ public Format getValuesFormat() {
+ return valuesFormat;
+ }
- // Apply values format and angel according to the specific axis type
- if (axis instanceof CategoryAxis)
- applyToCategoryAxis((CategoryAxis)axis);
- else if (axis instanceof NumberAxis)
- applyToNumberAxis((NumberAxis)axis);
- else if (axis instanceof DateAxis)
- applyToDateAxis((DateAxis) axis);
- else
- LOGGER.warn("Only basic style properties applied to axis because of an unexpected axis type: " + LangUtil.getSimpleClassName(axis));
- }
-
-
- /**
- * Applies style properties which can only be applied to
- * {@link CategoryAxis} (values angle).<br>
- * Called by {@link #applyToAxis(Axis)}.
- * @param axis a {@link CategoryAxis}
- */
- protected void applyToCategoryAxis(CategoryAxis axis) {
- // any angle can be applied
- axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions( getValuesAngleRadian() ));
- // format can not be applied to category axis values,
- // so give a warn if style should apply one
- if ( getValuesFormat() != null )
- LOGGER.warn("Not any axis values format can be applied to "+LangUtil.getSimpleClassName(axis));
- }
+ /**
+ * Sets the (number) format for the axis values.
+ */
+ public void setValuesFormat(Format format) {
+ this.valuesFormat = format;
+ }
- /**
- * Applies style properties which can only be applied to
- * {@link NumberAxis} (values angle and format).<br>
- * Called by {@link #applyToAxis(Axis)}.
- * @param axis a {@link NumberAxis}
- */
- protected void applyToNumberAxis(NumberAxis axis) {
- // Only NumberFormat can be applied to NumberAxis
- if ( getValuesFormat() instanceof NumberFormat )
- axis.setNumberFormatOverride( (NumberFormat)getValuesFormat() );
- else
- // Give a warn if another format should be applied
- if ( getValuesFormat() != null )
- LOGGER.warn("Only a NumberFormat can not be applied to values of "+LangUtil.getSimpleClassName(axis)+": "+LangUtil.getSimpleClassName(getValuesFormat()));
-
- // Only a 0 or 90 degree angle can be applied to NumberAxis
- double angle = getValuesAngle();
- if ( angle == 90 || angle == 0 )
- axis.setVerticalTickLabels( angle == 90 );
- else
- // Give a warn if another angle should be applied to NumberAxis
- LOGGER.warn("Only 0 or 90 degrees (horizontal/vertical) can be applied to values of "+LangUtil.getSimpleClassName(axis)+": "+angle);
- }
+ /**
+ * Applies the style to a specific axis.<br>
+ * Note: Some style properties can only be applied to specific axis types.
+ *
+ * @param axis
+ * an axis
+ */
+ public void applyToAxis(Axis axis) {
+ if (axis == null) {
+ LOGGER.debug("No axis to be customised.");
+ return;
+ }
- /**
- * Applies style properties which can only be applied to
- * {@link DateAxis} (values angle and format).<br>
- * Called by {@link #applyToAxis(Axis)}.
- * @param axis a {@link DateAxis}
- */
- protected void applyToDateAxis(DateAxis axis) {
- // Only DateFormat can be applied to NumberAxis
- if ( getValuesFormat() instanceof DateFormat )
- axis.setDateFormatOverride( (DateFormat)getValuesFormat() );
- else
- // Give a warn if another format should be applied
- if ( getValuesFormat() != null )
- LOGGER.warn("Only a DateFormat can not be applied to values of "+LangUtil.getSimpleClassName(axis)+": "+LangUtil.getSimpleClassName(getValuesFormat()));
-
- // Only a 0 or 90 degree angle can be applied to DateAxis
- double angle = getValuesAngle();
- if ( angle == 90 || angle == 0 )
- axis.setVerticalTickLabels( angle == 90 );
- else
- // Give a warn if another angle should be applied to DateAxis
- LOGGER.warn("Only 0 or 90 degrees (horizontal/vertical) can be applied to values of "+LangUtil.getSimpleClassName(axis)+": "+angle);
- }
+ // If unit is set, add it to axis title
+ String axisLabel = getLabel();
+ String unitString = getUnitString();
+ if (isUnitVisible() && unitString != null
+ && !"".equals(unitString.trim()))
+ axisLabel += " [" + unitString.trim() + "]";
- /**
- * Sets a unit for the axis.
- * @param unitString a string representing the unit
- */
- public void setUnitString(String unitString) {
- this.unitString = unitString;
- }
-
- /**
- * Returns a unit for the axis.
- * @param unitString a string representing the unit
- */
- public String getUnitString() {
- return unitString;
- }
+ // Apply common attributes
+ axis.setLabel(axisLabel);
+ if (getPaint() != null)
+ axis.setLabelPaint(getPaint());
+ if (getLabelAngle() != null)
+ axis.setLabelAngle(getLabelAngle());
+ axis.setVisible(isVisible());
- /**
- * Sets whether the unit string is visible in the axis label. In case
- * of normalized data it may be useful to "deactivate" the unit without
- * clearing the whole unit string.
- */
- public void setUnitVisible(boolean visible) {
- this.unitStringVisible = visible;
- }
+ // Apply values format and angel according to the specific axis type
+ if (axis instanceof CategoryAxis)
+ applyToCategoryAxis((CategoryAxis) axis);
+ else if (axis instanceof NumberAxis)
+ applyToNumberAxis((NumberAxis) axis);
+ else if (axis instanceof DateAxis)
+ applyToDateAxis((DateAxis) axis);
+ else
+ LOGGER
+ .warn("Only basic style properties applied to axis because of an unexpected axis type: "
+ + LangUtil.getSimpleClassName(axis));
+ }
- /**
- * Returns whether the unit string is visible in the axis label.
- */
- public boolean isUnitVisible() {
- return this.unitStringVisible;
- }
+ /**
+ * Applies style properties which can only be applied to
+ * {@link CategoryAxis} (values angle).<br>
+ * Called by {@link #applyToAxis(Axis)}.
+ *
+ * @param axis
+ * a {@link CategoryAxis}
+ */
+ protected void applyToCategoryAxis(CategoryAxis axis) {
+ // any angle can be applied
+ // Angle > 0 -> create a rotated label with right alignment to the tick
+ // Angle = 0 -> STANDARD (centered alignment to the tick)
+ if (getValuesAngleRadian() != 0.0)
+ axis.setCategoryLabelPositions(CategoryLabelPositions
+ .createUpRotationLabelPositions(getValuesAngleRadian()));
+ else
+ axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
+
+ // format can not be applied to category axis values,
+ // so give a warn if style should apply one
+ if (getValuesFormat() != null)
+ LOGGER.warn("Not any axis values format can be applied to "
+ + LangUtil.getSimpleClassName(axis));
+ }
+
+ /**
+ * Applies style properties which can only be applied to {@link NumberAxis}
+ * (values angle and format).<br>
+ * Called by {@link #applyToAxis(Axis)}.
+ *
+ * @param axis
+ * a {@link NumberAxis}
+ */
+ protected void applyToNumberAxis(NumberAxis axis) {
+ // Only NumberFormat can be applied to NumberAxis
+ if (getValuesFormat() instanceof NumberFormat)
+ axis.setNumberFormatOverride((NumberFormat) getValuesFormat());
+ else
+ // Give a warn if another format should be applied
+ if (getValuesFormat() != null)
+ LOGGER.warn("Only a NumberFormat can not be applied to values of "
+ + LangUtil.getSimpleClassName(axis) + ": "
+ + LangUtil.getSimpleClassName(getValuesFormat()));
+
+ // Only a 0 or 90 degree angle can be applied to NumberAxis
+ double angle = getValuesAngle();
+ if (angle == 90 || angle == 0)
+ axis.setVerticalTickLabels(angle == 90);
+ else
+ // Give a warn if another angle should be applied to NumberAxis
+ LOGGER
+ .warn("Only 0 or 90 degrees (horizontal/vertical) can be applied to values of "
+ + LangUtil.getSimpleClassName(axis) + ": " + angle);
+ }
+
+ /**
+ * Applies style properties which can only be applied to {@link DateAxis}
+ * (values angle and format).<br>
+ * Called by {@link #applyToAxis(Axis)}.
+ *
+ * @param axis
+ * a {@link DateAxis}
+ */
+ protected void applyToDateAxis(DateAxis axis) {
+ // Only DateFormat can be applied to NumberAxis
+ if (getValuesFormat() instanceof DateFormat)
+ axis.setDateFormatOverride((DateFormat) getValuesFormat());
+ else
+ // Give a warn if another format should be applied
+ if (getValuesFormat() != null)
+ LOGGER.warn("Only a DateFormat can not be applied to values of "
+ + LangUtil.getSimpleClassName(axis) + ": "
+ + LangUtil.getSimpleClassName(getValuesFormat()));
+
+ // Only a 0 or 90 degree angle can be applied to DateAxis
+ double angle = getValuesAngle();
+ if (angle == 90 || angle == 0)
+ axis.setVerticalTickLabels(angle == 90);
+ else
+ // Give a warn if another angle should be applied to DateAxis
+ LOGGER
+ .warn("Only 0 or 90 degrees (horizontal/vertical) can be applied to values of "
+ + LangUtil.getSimpleClassName(axis) + ": " + angle);
+ }
+
+ /**
+ * Sets a unit for the axis.
+ *
+ * @param unitString
+ * a string representing the unit
+ */
+ public void setUnitString(String unitString) {
+ this.unitString = unitString;
+ }
+
+ /**
+ * Returns a unit for the axis.
+ *
+ * @param unitString
+ * a string representing the unit
+ */
+ public String getUnitString() {
+ return unitString;
+ }
+
+ /**
+ * Sets whether the unit string is visible in the axis label. In case of
+ * normalized data it may be useful to "deactivate" the unit without
+ * clearing the whole unit string.
+ */
+ public void setUnitVisible(boolean visible) {
+ this.unitStringVisible = visible;
+ }
+
+ /**
+ * Returns whether the unit string is visible in the axis label.
+ */
+ public boolean isUnitVisible() {
+ return this.unitStringVisible;
+ }
}
More information about the Schmitzm-commits
mailing list