[Schmitzm-commits] r479 - branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 20 13:04:44 CEST 2009


Author: mojays
Date: 2009-10-20 13:04:43 +0200 (Tue, 20 Oct 2009)
New Revision: 479

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java
Log:


Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java	2009-10-20 10:37:01 UTC (rev 478)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java	2009-10-20 11:04:43 UTC (rev 479)
@@ -33,7 +33,9 @@
 import java.awt.Color;
 
 import org.apache.log4j.Category;
+import org.jfree.chart.plot.CategoryMarker;
 import org.jfree.chart.plot.CategoryPlot;
+import org.jfree.chart.plot.Marker;
 import org.jfree.chart.plot.Plot;
 import org.jfree.chart.plot.ValueMarker;
 import org.jfree.chart.plot.XYPlot;
@@ -57,16 +59,18 @@
  * and {@link CategoryPlot})</li>
  * <li>range grid line visibility and color (only applicable for {@link XYPlot}
  * and {@link CategoryPlot})</li>
- * <li>crosshair visibility (around 0/0) and color (only applicable for
+ * <li>axis crosshair visibility and color (only applicable for
  * {@link XYPlot} and {@link CategoryPlot})</li>
+ * <li>axis crosshair centering (only applicable for
+ * {@link XYPlot} and {@link CategoryPlot})</li>
  * </ul>
  * 
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
  * @version 1.0
  */
 public class ChartPlotStyle implements Copyable<ChartPlotStyle> {
-	private static final ValueMarker MARKER = new ValueMarker(0., Color.black,
-			new BasicStroke(1f));
+	private final ValueMarker VALUE_MARKER = new ValueMarker(0., Color.black, new BasicStroke(1f));
+    private final CategoryMarker CAT_MARKER = new CategoryMarker(0., Color.black, new BasicStroke(1f));
 
 	/** Logger for this class */
 	protected final Category LOGGER = LangUtil.createLogger(this);
@@ -398,6 +402,19 @@
 			plot.setRangeGridlinesVisible(isRangeGridlineVisible());
 		if (getRangeGridlinePaint() != null)
 			plot.setRangeGridlinePaint(getRangeGridlinePaint());
+        if (isCrosshairVisible() != null && isCrosshairVisible() == true) {
+          if (getCrosshairPaint() != null)
+            CAT_MARKER.setPaint(getCrosshairPaint());
+          if (plot.getDomainMarkers(Layer.FOREGROUND) == null ||
+              !plot.getDomainMarkers(Layer.FOREGROUND).contains(CAT_MARKER))
+            plot.addDomainMarker(CAT_MARKER);
+          if (plot.getRangeMarkers(Layer.FOREGROUND) == null ||
+              !plot.getRangeMarkers(Layer.FOREGROUND).contains(CAT_MARKER))
+            plot.addRangeMarker(CAT_MARKER);
+        } else {
+          plot.removeDomainMarker(CAT_MARKER);
+          plot.removeRangeMarker(CAT_MARKER);
+        }
 
 	}
 
@@ -418,31 +435,20 @@
 			plot.setRangeGridlinesVisible(isRangeGridlineVisible());
 		if (getRangeGridlinePaint() != null)
 			plot.setRangeGridlinePaint(getRangeGridlinePaint());
-		// if (isCrosshairVisible() != null) {
-		// plot.setDomainCrosshairVisible(isCrosshairVisible());
-		// plot.setRangeCrosshairVisible(isCrosshairVisible());
-		// }
-		// if (getCrosshairPaint() != null) {
-		// plot.setDomainCrosshairPaint(getCrosshairPaint());
-		// plot.setRangeCrosshairPaint(getCrosshairPaint());
-		// }
-
 		if (isCrosshairVisible() != null && isCrosshairVisible() == true) {
-			if (getCrosshairPaint() != null)
-				MARKER.setPaint(getCrosshairPaint());
-			if (plot.getDomainMarkers(Layer.FOREGROUND) == null
-					|| !plot.getDomainMarkers(Layer.FOREGROUND)
-							.contains(MARKER)) {
-				plot.addDomainMarker(MARKER);
-			}
-			if (plot.getRangeMarkers(Layer.FOREGROUND) == null
-					|| !plot.getRangeMarkers(Layer.FOREGROUND).contains(MARKER)) {
-				plot.addRangeMarker(MARKER);
-			}
+		  if (getCrosshairPaint() != null)
+		    VALUE_MARKER.setPaint(getCrosshairPaint());
+		  if (plot.getDomainMarkers(Layer.FOREGROUND) == null ||
+		      !plot.getDomainMarkers(Layer.FOREGROUND).contains(VALUE_MARKER))
+		    plot.addDomainMarker(VALUE_MARKER);
+		  if (plot.getRangeMarkers(Layer.FOREGROUND) == null ||
+		      !plot.getRangeMarkers(Layer.FOREGROUND).contains(VALUE_MARKER))
+		    plot.addRangeMarker(VALUE_MARKER);
 		} else {
-			plot.removeDomainMarker(MARKER);
-			plot.removeRangeMarker(MARKER);
+		  plot.removeDomainMarker(VALUE_MARKER);
+		  plot.removeRangeMarker(VALUE_MARKER);
 		}
+		
 		// plot.setDomainPannable(true);
 		// plot.setRangePannable(true);
 
@@ -450,27 +456,27 @@
 			plot.getRangeAxis().setAutoRange(false);
 			plot.getDomainAxis().setAutoRange(false);
 			// Calc the min/max values
+			plot.getRangeAxis().centerRange(0);
+			plot.getDomainAxis().centerRange(0);
 
-			plot.getRangeAxis().centerRange(0.);
-			plot.getDomainAxis().centerRange(0.);
-
 			if (plot.getDataset() instanceof XYSeriesCollection) {
-				XYSeries series0 = ((XYSeriesCollection) plot.getDataset())
-						.getSeries(0);
-				double absMaxX = Math.max(Math.abs(series0.getMinX()), Math
-						.abs(series0.getMaxX())) * 1.1;
+				XYSeries series0 = ((XYSeriesCollection) plot.getDataset()).getSeries(0);
+				double absMaxX = Math.max(
+				    Math.abs(series0.getMinX()), 
+				    Math.abs(series0.getMaxX())
+				) * 1.1;
 				plot.getDomainAxis().setRange(new Range(-absMaxX, absMaxX));
 
-				double absMaxY = Math.max(Math.abs(series0.getMinY()), Math
-						.abs(series0.getMaxY())) * 1.1;
+				double absMaxY = Math.max(
+				    Math.abs(series0.getMinY()), 
+				    Math.abs(series0.getMaxY())
+				) * 1.1;
 				plot.getRangeAxis().setRange(new Range(-absMaxY, absMaxY));
 			} else {
-				LOGGER
-						.warn("CenterOriginSymetrically can ATM only be applied to datasets of type XYSeriesCollection. Autorange is activated.");
+				LOGGER.warn("CenterOriginSymetrically can ATM only be applied to datasets of type XYSeriesCollection. Autorange is activated.");
 				plot.getRangeAxis().setAutoRange(true);
 				plot.getDomainAxis().setAutoRange(true);
 			}
-
 		} else {
 			plot.getRangeAxis().setAutoRange(true);
 			plot.getDomainAxis().setAutoRange(true);
@@ -519,10 +525,18 @@
 	// return absMaxX;
 	// }
 
-	public void setCenterOriginSymetrically(boolean b) {
-		centerOriginSymetrically = b;
+    /**
+     * Sets whether the axis origin is centered in the plot.
+     * @param originSym indicated whether the axis origin should
+     *                  be centered in the plot 
+     */
+	public void setCenterOriginSymetrically(boolean originSym) {
+		centerOriginSymetrically = originSym;
 	}
 
+	/**
+	 * Returns whether the axis origin is centered in the plot. 
+	 */
 	public boolean isCenterOriginSymetrically() {
 		return centerOriginSymetrically;
 	}



More information about the Schmitzm-commits mailing list