[Schmitzm-commits] r462 - in branches/1.0-gt2-2.6/src/schmitzm: jfree/chart/style swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 13 13:28:26 CEST 2009


Author: alfonx
Date: 2009-10-13 13:28:25 +0200 (Tue, 13 Oct 2009)
New Revision: 462

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/swing/JPanel.java
Log:
* GP-Feature: ChartPlotstyle now supports to center a normalized style properly. The GUI in DesignAtlasChartJDialog still has to be simplified though.
* Added support for TitledBorder in schmitzm JPanel

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-13 09:22:23 UTC (rev 461)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java	2009-10-13 11:28:25 UTC (rev 462)
@@ -29,15 +29,20 @@
  ******************************************************************************/
 package schmitzm.jfree.chart.style;
 
+import java.awt.BasicStroke;
 import java.awt.Color;
 
 import org.apache.log4j.Category;
 import org.jfree.chart.plot.CategoryPlot;
 import org.jfree.chart.plot.Plot;
+import org.jfree.chart.plot.ValueMarker;
 import org.jfree.chart.plot.XYPlot;
+import org.jfree.data.Range;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+import org.jfree.ui.Layer;
 import org.jfree.ui.RectangleInsets;
 
-import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.lang.LangUtil;
 import skrueger.geotools.Copyable;
 
@@ -45,364 +50,488 @@
  * This class defines the rendering style the charts plot(s). The following
  * properties are available:
  * <ul>
- *   <li>foreground transparency</li>
- *   <li>background color and transparency</li>
- *   <li>insets margins</li>
- *   <li>domain grid line visibility and color (only applicable for {@link XYPlot} 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 {@link XYPlot} and
- *       {@link CategoryPlot})</li>
+ * <li>foreground transparency</li>
+ * <li>background color and transparency</li>
+ * <li>insets margins</li>
+ * <li>domain grid line visibility and color (only applicable for {@link XYPlot}
+ * 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
+ * {@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> {
-  /** Logger for this class */
-  protected final Category LOGGER = LangUtil.createLogger(this);
+	private static final ValueMarker MARKER = new ValueMarker(0., Color.black,
+			new BasicStroke(1f));
 
-  /** Holds the inner margins of the plot. */
-  protected RectangleInsets insets = null;;
-  /** Holds the foreground transparency. */
-  protected Float foregroundAlpha = 1.0f;
-  /** Holds the background color of the plot. */
-  protected Color backgroundPaint = null;
-  /** Holds the background transparency. */
-  protected Float backgroundAlpha = 1.0f;
-  /** Holds whether the domain grid line is visible. */
-  protected Boolean domainGridlineVisible = null;
-  /** Holds the color of the domain grid line. */
-  protected Color domainGridlinePaint = null;
-  /** Holds whether the range grid line is visible. */
-  protected Boolean rangeGridlineVisible = null;
-  /** Holds the color of the range grid line. */
-  protected Color rangeGridlinePaint = null;
-  /** Holds whether crosshair lines are visible (on 0/0). */
-  protected Boolean crosshairVisible = null;
-  /** Holds the color of the range grid line. */
-  protected Color crosshairPaint = null;
-  
-  
-  /**
-   * Creates a new style with default values.
-   */
-  public ChartPlotStyle() {
-  }
+	/** Logger for this class */
+	protected final Category LOGGER = LangUtil.createLogger(this);
 
-  /**
-   * Creates a (deep) clone of this style.
-   */
-  @Override
-  public ChartPlotStyle copy() {
-    return copyTo( new ChartPlotStyle() );
-  }
-  
-  /**
-   * 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
-   */
-  @Override
-  public ChartPlotStyle copyTo(ChartPlotStyle dest) {
-    if ( dest == null )
-      return copy();
+	/** Holds the inner margins of the plot. */
+	protected RectangleInsets insets = null;;
+	/** Holds the foreground transparency. */
+	protected Float foregroundAlpha = 1.0f;
+	/** Holds the background color of the plot. */
+	protected Color backgroundPaint = null;
+	/** Holds the background transparency. */
+	protected Float backgroundAlpha = 1.0f;
+	/** Holds whether the domain grid line is visible. */
+	protected Boolean domainGridlineVisible = null;
+	/** Holds the color of the domain grid line. */
+	protected Color domainGridlinePaint = null;
+	/** Holds whether the range grid line is visible. */
+	protected Boolean rangeGridlineVisible = null;
+	/** Holds the color of the range grid line. */
+	protected Color rangeGridlinePaint = null;
+	/** Holds whether crosshair lines are visible (on 0/0). */
+	protected Boolean crosshairVisible = null;
+	/** Holds the color of the range grid line. */
+	protected Color crosshairPaint = null;
+	/**
+	 * Boolean determining whether the plot will be centered around the axis
+	 * origin and will have extends: Xmax = -Xmin && Ymax = -Ymin
+	 **/
+	protected boolean centerOriginSymetrically = false;
 
-    dest.setInsets( getInsets() );
-    dest.setForegroundAlpha( getForegroundAlpha() );
-    dest.setBackgroundPaint( getBackgroundPaint() );
-    dest.setBackgroundAlpha( getBackgroundAlpha() );
-    dest.setDomainGridlineVisible( isDomainGridlineVisible() );
-    dest.setDomainGridlinePaint( getDomainGridlinePaint() );
-    dest.setRangeGridlineVisible( isRangeGridlineVisible() );
-    dest.setRangeGridlinePaint( getRangeGridlinePaint() );
-    dest.setCrosshairVisible( isCrosshairVisible() );
-    dest.setCrosshairPaint( getCrosshairPaint() );
+	//
+	// private int absMaxY;
+	//
+	// private int absMaxX;
 
-    return dest;
-  }
+	/**
+	 * Creates a new style with default values.
+	 */
+	public ChartPlotStyle() {
+	}
 
-  /**
-   * Returns the inner margin of the plot.
-   */
-  public RectangleInsets getInsets() {
-    return insets;
-  }
+	/**
+	 * Creates a (deep) clone of this style.
+	 */
+	@Override
+	public ChartPlotStyle copy() {
+		return copyTo(new ChartPlotStyle());
+	}
 
-  /**
-   * Sets the inner margin of the plot.
-   */
-  public void setInsets(RectangleInsets insets) {
-    this.insets = insets;
-  }
-  
-  /**
-   * Returns the transparency of the foreground.
-   * @return {@code null} if no specific transparency is set for the plot
-   */
-  public Float getForegroundAlpha() {
-    return foregroundAlpha;
-  }
+	/**
+	 * 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
+	 */
+	@Override
+	public ChartPlotStyle copyTo(ChartPlotStyle dest) {
+		if (dest == null)
+			return copy();
 
-  /**
-   * Sets the transparency of the foreground.
-   * @param alpha  transparency value (0..1); can be {@code null} to reset
-   *               to a non-specific value
-   */
-  public void setForegroundAlpha(Float alpha) {
-    this.foregroundAlpha = alpha;
-  }
+		dest.setInsets(getInsets());
+		dest.setForegroundAlpha(getForegroundAlpha());
+		dest.setBackgroundPaint(getBackgroundPaint());
+		dest.setBackgroundAlpha(getBackgroundAlpha());
+		dest.setDomainGridlineVisible(isDomainGridlineVisible());
+		dest.setDomainGridlinePaint(getDomainGridlinePaint());
+		dest.setRangeGridlineVisible(isRangeGridlineVisible());
+		dest.setRangeGridlinePaint(getRangeGridlinePaint());
+		dest.setCrosshairVisible(isCrosshairVisible());
+		dest.setCrosshairPaint(getCrosshairPaint());
 
-  /**
-   * Returns the transparency of the background.
-   * @return {@code null} if no specific transparency is set for the plot
-   */
-  public Float getBackgroundAlpha() {
-    return backgroundAlpha;
-  }
+		return dest;
+	}
 
-  /**
-   * Sets the transparency of the background.
-   * @param alpha  transparency value (0..1); can be {@code null} to reset
-   *               to a non-specific value
-   */
-  public void setBackgroundAlpha(Float alpha) {
-    this.backgroundAlpha = alpha;
-  }
+	/**
+	 * Returns the inner margin of the plot.
+	 */
+	public RectangleInsets getInsets() {
+		return insets;
+	}
 
-  /**
-   * Returns the background color of the plot.
-   * @return {@code null} if no specific color is set
-   */
-  public Color getBackgroundPaint() {
-    return backgroundPaint;
-  }
+	/**
+	 * Sets the inner margin of the plot.
+	 */
+	public void setInsets(RectangleInsets insets) {
+		this.insets = insets;
+	}
 
-  /**
-   * Sets the background color of the plot.
-   * @param color  background color for the plot (can be {@code null} to reset
-   *               to a non-specific color)
-   */
-  public void setBackgroundPaint(Color color) {
-    this.backgroundPaint = color;
-  }
+	/**
+	 * Returns the transparency of the foreground.
+	 * 
+	 * @return {@code null} if no specific transparency is set for the plot
+	 */
+	public Float getForegroundAlpha() {
+		return foregroundAlpha;
+	}
 
-  
-  /**
-   * Returns whether the plot's domain grid line is visible.
-   * @return {@code null} if property is not set for the plot
-   */
-  public Boolean isDomainGridlineVisible() {
-    return domainGridlineVisible;
-  }
+	/**
+	 * Sets the transparency of the foreground.
+	 * 
+	 * @param alpha
+	 *            transparency value (0..1); can be {@code null} to reset to a
+	 *            non-specific value
+	 */
+	public void setForegroundAlpha(Float alpha) {
+		this.foregroundAlpha = alpha;
+	}
 
-  /**
-   * Sets whether the plot's domain grid line is visible.
-   * @param visible indicates the visibility of the grid line (can be
-   *                {@code null} to reset to a non-specific property)
-   */
-  public void setDomainGridlineVisible(Boolean visible) {
-    domainGridlineVisible = visible;
-  }
+	/**
+	 * Returns the transparency of the background.
+	 * 
+	 * @return {@code null} if no specific transparency is set for the plot
+	 */
+	public Float getBackgroundAlpha() {
+		return backgroundAlpha;
+	}
 
-  /**
-   * Returns the color of the plot's domain grid line.
-   * @return {@code null} if no specific color is set
-   */
-  public Color getDomainGridlinePaint() {
-    return domainGridlinePaint;
-  }
+	/**
+	 * Sets the transparency of the background.
+	 * 
+	 * @param alpha
+	 *            transparency value (0..1); can be {@code null} to reset to a
+	 *            non-specific value
+	 */
+	public void setBackgroundAlpha(Float alpha) {
+		this.backgroundAlpha = alpha;
+	}
 
-  /**
-   * Sets the color of the plot's domain grid line.
-   * @param color  color for the domain grid line (can be {@code null} to reset
-   *               to a non-specific color)
-   */
-  public void setDomainGridlinePaint(Color color) {
-    this.domainGridlinePaint = color;
-  }
+	/**
+	 * Returns the background color of the plot.
+	 * 
+	 * @return {@code null} if no specific color is set
+	 */
+	public Color getBackgroundPaint() {
+		return backgroundPaint;
+	}
 
-  /**
-   * Returns whether the plot's range grid line is visible.
-   * @return {@code null} if property is not set for the plot
-   */
-  public Boolean isRangeGridlineVisible() {
-    return rangeGridlineVisible;
-  }
+	/**
+	 * Sets the background color of the plot.
+	 * 
+	 * @param color
+	 *            background color for the plot (can be {@code null} to reset to
+	 *            a non-specific color)
+	 */
+	public void setBackgroundPaint(Color color) {
+		this.backgroundPaint = color;
+	}
 
-  /**
-   * Sets whether the plot's range grid line is visible.
-   * @param visible indicates the visibility of the grid line (can be
-   *                {@code null} to reset to a non-specific property)
-   */
-  public void setRangeGridlineVisible(Boolean visible) {
-    rangeGridlineVisible = visible;
-  }
+	/**
+	 * Returns whether the plot's domain grid line is visible.
+	 * 
+	 * @return {@code null} if property is not set for the plot
+	 */
+	public Boolean isDomainGridlineVisible() {
+		return domainGridlineVisible;
+	}
 
-  /**
-   * Returns the color of the plot's range grid line.
-   * @return {@code null} if no specific color is set
-   */
-  public Color getRangeGridlinePaint() {
-    return rangeGridlinePaint;
-  }
+	/**
+	 * Sets whether the plot's domain grid line is visible.
+	 * 
+	 * @param visible
+	 *            indicates the visibility of the grid line (can be {@code null}
+	 *            to reset to a non-specific property)
+	 */
+	public void setDomainGridlineVisible(Boolean visible) {
+		domainGridlineVisible = visible;
+	}
 
-  /**
-   * Sets the color of the plot's range grid line.
-   * @param color  color for the range grid line (can be {@code null} to reset
-   *               to a non-specific color)
-   */
-  public void setRangeGridlinePaint(Color color) {
-    this.rangeGridlinePaint = color;
-  }
-  
-  /**
-   * Returns whether the plot's crosshair lines are visible.
-   * @return {@code null} if property is not set for the plot
-   */
-  public Boolean isCrosshairVisible() {
-    return crosshairVisible;
-  }
+	/**
+	 * Returns the color of the plot's domain grid line.
+	 * 
+	 * @return {@code null} if no specific color is set
+	 */
+	public Color getDomainGridlinePaint() {
+		return domainGridlinePaint;
+	}
 
-  /**
-   * Sets whether the plot's crosshair lines are visible.
-   * @param visible indicates the visibility of the crosshair lines (can be
-   *                {@code null} to reset to a non-specific property)
-   */
-  public void setCrosshairVisible(Boolean visible) {
-    crosshairVisible = visible;
-  }
+	/**
+	 * Sets the color of the plot's domain grid line.
+	 * 
+	 * @param color
+	 *            color for the domain grid line (can be {@code null} to reset
+	 *            to a non-specific color)
+	 */
+	public void setDomainGridlinePaint(Color color) {
+		this.domainGridlinePaint = color;
+	}
 
-  /**
-   * Returns the color of the plot's crosshair lines.
-   * @return {@code null} if no specific color is set
-   */
-  public Color getCrosshairPaint() {
-    return crosshairPaint;
-  }
+	/**
+	 * Returns whether the plot's range grid line is visible.
+	 * 
+	 * @return {@code null} if property is not set for the plot
+	 */
+	public Boolean isRangeGridlineVisible() {
+		return rangeGridlineVisible;
+	}
 
-  /**
-   * Sets the color of the plot's crosshair lines.
-   * @param color  color for the crosshair lines (can be {@code null} to reset
-   *               to a non-specific color)
-   */
-  public void setCrosshairPaint(Color color) {
-    this.crosshairPaint = color;
-  }
+	/**
+	 * Sets whether the plot's range grid line is visible.
+	 * 
+	 * @param visible
+	 *            indicates the visibility of the grid line (can be {@code null}
+	 *            to reset to a non-specific property)
+	 */
+	public void setRangeGridlineVisible(Boolean visible) {
+		rangeGridlineVisible = visible;
+	}
 
-  /**
-   * Applies the style to a specific plot.<br>
-   * Note: Some style properties can only be applied to specific plot types.
-   * @param plot a plot
-   */
-  public void applyToPlot(Plot plot) {
-    if (plot == null) {
-      LOGGER.debug("No plot to be customised.");
-      return;
-    }
-    
-    // Apply common attributes
-    if ( getForegroundAlpha() != null )
-      plot.setForegroundAlpha( getForegroundAlpha() );
-    if ( getBackgroundAlpha() != null )
-      plot.setBackgroundAlpha( getBackgroundAlpha() );
-    if ( getBackgroundPaint() != null )
-      plot.setBackgroundPaint( getBackgroundPaint() );
-    if ( getInsets() != null )
-      plot.setInsets(insets);
-    
-    // Apply margin according to the specific renderer type
-    if (plot instanceof CategoryPlot)
-      applyToCategoryPlot((CategoryPlot)plot);
-    if (plot instanceof XYPlot)
-      applyToXYPlot((XYPlot)plot);
+	/**
+	 * Returns the color of the plot's range grid line.
+	 * 
+	 * @return {@code null} if no specific color is set
+	 */
+	public Color getRangeGridlinePaint() {
+		return rangeGridlinePaint;
+	}
 
-    // notify the listeners about style change
-    JFreeChartUtil.fireChangeEvent(plot);
-  }
-  
-  
-  /**
-   * Applies style properties which can only be applied to
-   * {@link CategoryPlot}.<br>
-   * Called by {@link #applyToPlot(Plot)}. 
-   * @param plot a {@link CategoryPlot}
-   */
-  protected void applyToCategoryPlot(CategoryPlot plot) {
-    if ( isDomainGridlineVisible() != null )
-      plot.setDomainGridlinesVisible( isDomainGridlineVisible() );
-    if ( getDomainGridlinePaint() != null )
-      plot.setDomainGridlinePaint( getDomainGridlinePaint() );
-    if ( isRangeGridlineVisible() != null )
-      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() );
-    }
-  }
+	/**
+	 * Sets the color of the plot's range grid line.
+	 * 
+	 * @param color
+	 *            color for the range grid line (can be {@code null} to reset to
+	 *            a non-specific color)
+	 */
+	public void setRangeGridlinePaint(Color color) {
+		this.rangeGridlinePaint = color;
+	}
 
-  /**
-   * Applies style properties which can only be applied to
-   * {@link XYPlot}.<br>
-   * Called by {@link #applyToPlot(Plot)}. 
-   * @param plot a {@link XYPlot}
-   */
-  protected void applyToXYPlot(XYPlot plot) {
-    if ( isDomainGridlineVisible() != null )
-      plot.setDomainGridlinesVisible( isDomainGridlineVisible() );
-    if ( getDomainGridlinePaint() != null )
-      plot.setDomainGridlinePaint( getDomainGridlinePaint() );
-    if ( isRangeGridlineVisible() != null )
-      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() );
-    }
+	/**
+	 * Returns whether the plot's crosshair lines are visible.
+	 * 
+	 * @return {@code null} if property is not set for the plot
+	 */
+	public Boolean isCrosshairVisible() {
+		return crosshairVisible;
+	}
 
-//TESTS
-//    plot.zoomDomainAxes(1.0, null, new Point2D.Double(50,50), true );
-//    plot.zoomDomainAxes(0.5,0.5, null, null);
-//    plot.zoomRangeAxes(0.5,0.5, null, null);
-//    Range domainAxisRange = plot.getDomainAxis().getRange();
-//    double domainAbsMax = Math.max(
-//                              Math.abs(domainAxisRange.getLowerBound()),
-//                              Math.abs(domainAxisRange.getUpperBound())
-//    );
-//    plot.getDomainAxis().setRange(-domainAbsMax, domainAbsMax);
-//    
-//    
-//    Range rangeAxisRange  = plot.getRangeAxis().getRange();
-//    double rangeAbsMax = Math.max(
-//        Math.abs(rangeAxisRange.getLowerBound()),
-//        Math.abs(rangeAxisRange.getUpperBound())
-//    );
-//    plot.getRangeAxis().setRange(-rangeAbsMax, rangeAbsMax);
+	/**
+	 * Sets whether the plot's crosshair lines are visible.
+	 * 
+	 * @param visible
+	 *            indicates the visibility of the crosshair lines (can be
+	 *            {@code null} to reset to a non-specific property)
+	 */
+	public void setCrosshairVisible(Boolean visible) {
+		crosshairVisible = visible;
+	}
 
-//    plot.getDomainAxis().centerRange(0);
-//    plot.getRangeAxis().centerRange(0);
-//    
-//    plot.getDomainAxis().setAutoRange(false);
-//    plot.getRangeAxis().setAutoRange(false);
-//    plot.getDomainAxis().setDefaultAutoRange( new Range(
-//        plot.getDomainAxis().getRange().getLowerBound(),
-//        plot.getDomainAxis().getRange().getUpperBound())
-//    );
-//    plot.getRangeAxis().setDefaultAutoRange( new Range(
-//        plot.getRangeAxis().getRange().getLowerBound(),
-//        plot.getRangeAxis().getRange().getUpperBound())
-//    );
-  }
+	/**
+	 * Returns the color of the plot's crosshair lines.
+	 * 
+	 * @return {@code null} if no specific color is set
+	 */
+	public Color getCrosshairPaint() {
+		return crosshairPaint;
+	}
+
+	/**
+	 * Sets the color of the plot's crosshair lines.
+	 * 
+	 * @param color
+	 *            color for the crosshair lines (can be {@code null} to reset to
+	 *            a non-specific color)
+	 */
+	public void setCrosshairPaint(Color color) {
+		this.crosshairPaint = color;
+	}
+
+	/**
+	 * Applies the style to a specific plot.<br>
+	 * Note: Some style properties can only be applied to specific plot types.
+	 * 
+	 * @param plot
+	 *            a plot
+	 */
+	public void applyToPlot(Plot plot) {
+		if (plot == null) {
+			LOGGER.debug("No plot to be customised.");
+			return;
+		}
+
+		plot.setNotify(false);
+		// Apply common attributes
+		if (getForegroundAlpha() != null)
+			plot.setForegroundAlpha(getForegroundAlpha());
+		if (getBackgroundAlpha() != null)
+			plot.setBackgroundAlpha(getBackgroundAlpha());
+		if (getBackgroundPaint() != null)
+			plot.setBackgroundPaint(getBackgroundPaint());
+		if (getInsets() != null)
+			plot.setInsets(insets);
+
+		// Apply margin according to the specific renderer type
+		if (plot instanceof CategoryPlot)
+			applyToCategoryPlot((CategoryPlot) plot);
+		if (plot instanceof XYPlot)
+			applyToXYPlot((XYPlot) plot);
+
+		plot.setNotify(true);
+		// notify the listeners about style change
+		// JFreeChartUtil.fireChangeEvent(plot);
+	}
+
+	/**
+	 * Applies style properties which can only be applied to
+	 * {@link CategoryPlot}.<br>
+	 * Called by {@link #applyToPlot(Plot)}.
+	 * 
+	 * @param plot
+	 *            a {@link CategoryPlot}
+	 */
+	protected void applyToCategoryPlot(CategoryPlot plot) {
+		if (isDomainGridlineVisible() != null)
+			plot.setDomainGridlinesVisible(isDomainGridlineVisible());
+		if (getDomainGridlinePaint() != null)
+			plot.setDomainGridlinePaint(getDomainGridlinePaint());
+		if (isRangeGridlineVisible() != null)
+			plot.setRangeGridlinesVisible(isRangeGridlineVisible());
+		if (getRangeGridlinePaint() != null)
+			plot.setRangeGridlinePaint(getRangeGridlinePaint());
+
+		if (isDomainGridlineVisible() != null)
+			plot.setDomainGridlinesVisible(isDomainGridlineVisible());
+		if (getDomainGridlinePaint() != null)
+			plot.setDomainGridlinePaint(getDomainGridlinePaint());
+		if (isRangeGridlineVisible() != null)
+			plot.setRangeGridlinesVisible(isRangeGridlineVisible());
+		if (getRangeGridlinePaint() != null)
+			plot.setRangeGridlinePaint(getRangeGridlinePaint());
+
+	}
+
+	/**
+	 * Applies style properties which can only be applied to {@link XYPlot}.<br>
+	 * Called by {@link #applyToPlot(Plot)}.
+	 * 
+	 * @param plot
+	 *            a {@link XYPlot}
+	 */
+	protected void applyToXYPlot(XYPlot plot) {
+
+		if (isDomainGridlineVisible() != null)
+			plot.setDomainGridlinesVisible(isDomainGridlineVisible());
+		if (getDomainGridlinePaint() != null)
+			plot.setDomainGridlinePaint(getDomainGridlinePaint());
+		if (isRangeGridlineVisible() != null)
+			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);
+			}
+		} else {
+			plot.removeDomainMarker(MARKER);
+			plot.removeRangeMarker(MARKER);
+		}
+		// plot.setDomainPannable(true);
+		// plot.setRangePannable(true);
+
+		if (isCenterOriginSymetrically()) {
+			plot.getRangeAxis().setAutoRange(false);
+			plot.getDomainAxis().setAutoRange(false);
+			// Calc the min/max values
+
+			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;
+				plot.getDomainAxis().setRange(new Range(-absMaxX, absMaxX));
+
+				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.");
+				plot.getRangeAxis().setAutoRange(true);
+				plot.getDomainAxis().setAutoRange(true);
+			}
+
+		} else {
+			plot.getRangeAxis().setAutoRange(true);
+			plot.getDomainAxis().setAutoRange(true);
+		}
+
+		// TESTS
+		// plot.zoomDomainAxes(1.0, null, new Point2D.Double(50,50), true );
+		// plot.zoomDomainAxes(0.5,0.5, null, null);
+		// plot.zoomRangeAxes(0.5,0.5, null, null);
+		// Range domainAxisRange = plot.getDomainAxis().getRange();
+		// double domainAbsMax = Math.max(
+		// Math.abs(domainAxisRange.getLowerBound()),
+		// Math.abs(domainAxisRange.getUpperBound())
+		// );
+		// plot.getDomainAxis().setRange(-domainAbsMax, domainAbsMax);
+		//    
+		//    
+		// Range rangeAxisRange = plot.getRangeAxis().getRange();
+		// double rangeAbsMax = Math.max(
+		// Math.abs(rangeAxisRange.getLowerBound()),
+		// Math.abs(rangeAxisRange.getUpperBound())
+		// );
+		// plot.getRangeAxis().setRange(-rangeAbsMax, rangeAbsMax);
+
+		// plot.getDomainAxis().centerRange(0);
+		// plot.getRangeAxis().centerRange(0);
+		//    
+		// plot.getDomainAxis().setAutoRange(false);
+		// plot.getRangeAxis().setAutoRange(false);
+		// plot.getDomainAxis().setDefaultAutoRange( new Range(
+		// plot.getDomainAxis().getRange().getLowerBound(),
+		// plot.getDomainAxis().getRange().getUpperBound())
+		// );
+		// plot.getRangeAxis().setDefaultAutoRange( new Range(
+		// plot.getRangeAxis().getRange().getLowerBound(),
+		// plot.getRangeAxis().getRange().getUpperBound())
+		// );
+	}
+
+	//
+	// private int getAbsMaxY() {
+	// return absMaxY;
+	// }
+	//
+	// private int getAbsMaxX() {
+	// return absMaxX;
+	// }
+
+	public void setCenterOriginSymetrically(boolean b) {
+		centerOriginSymetrically = b;
+	}
+
+	public boolean isCenterOriginSymetrically() {
+		return centerOriginSymetrically;
+	}
+	//
+	// public void setAbsMaxX(int absMaxX) {
+	// this.absMaxX = absMaxX;
+	// }
+	//
+	// public void setAbsMaxY(int absMaxY) {
+	// this.absMaxY = absMaxY;
+	// }
 }

Modified: branches/1.0-gt2-2.6/src/schmitzm/swing/JPanel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/swing/JPanel.java	2009-10-13 09:22:23 UTC (rev 461)
+++ branches/1.0-gt2-2.6/src/schmitzm/swing/JPanel.java	2009-10-13 11:28:25 UTC (rev 462)
@@ -34,6 +34,9 @@
 import java.awt.FlowLayout;
 import java.awt.LayoutManager;
 
+import javax.swing.BorderFactory;
+import javax.swing.border.TitledBorder;
+
 /**
  * Diese Klasse erweitert das {@link javax.swing.JPanel} aus Standard-Java um
  * einige (nuetzliche) Funktionen.
@@ -41,7 +44,11 @@
  * @version 1.0
  */
 public class JPanel extends javax.swing.JPanel {
-  /**
+
+	/** Wenn beim deaktivieren evt. ein {@link TitledBorder} ausgegraut wird, dann wird sich in dieser Variable die orginale Farbe gemerkt.**/
+  private Color backupColor = null;
+
+/**
    * Erzeugt ein neues Panel.
    * @param layout {@link LayoutManager} fuer das Panel
    * @param isDoubleBuffered Flag, ob zusaetzlicher Speicher verwendet werden soll um
@@ -76,11 +83,37 @@
   }
 
   /**
-   * Aktiviert und deaktiviert alle Komponenten des Panels.
+	 * Erzeugt ein neues Panel mit angegebenen {@link LayoutManager} und einem
+	 * {@link TitledBorder}
+	 * 
+	 * @param borderTitle
+	 *            Wenn ungleich null wird {@link TitledBorder} für das Panel
+	 *            erzeugt
+	 */
+	public JPanel(LayoutManager layout, String borderTitle) {
+		super(layout);
+		if (borderTitle != null) {
+			setBorder(BorderFactory.createTitledBorder(borderTitle));
+		}
+	}
+
+/**
+   * Aktiviert und deaktiviert alle Komponenten des Panels. 
    */
   @Override
   public void setEnabled(boolean enabled) {
     super.setEnabled(enabled);
+    
+    if (getBorder() instanceof TitledBorder) {
+    	TitledBorder tb = (TitledBorder)getBorder();
+    	if(enabled) {
+    		if (backupColor != null) tb.setTitleColor(backupColor);
+    	} else {
+    		backupColor = tb.getTitleColor();
+    		tb.setTitleColor(backupColor.brighter().brighter());
+    	}
+    }
+    
     for (Component c : getComponents())
       c.setEnabled(enabled);
   }



More information about the Schmitzm-commits mailing list