[Schmitzm-commits] r449 - in branches/1.0-gt2-2.6/src: schmitzm/jfree/chart/style schmitzm/jfree/feature/style skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Oct 8 21:41:59 CEST 2009


Author: mojays
Date: 2009-10-08 21:41:57 +0200 (Thu, 08 Oct 2009)
New Revision: 449

Added:
   branches/1.0-gt2-2.6/src/skrueger/geotools/CopyableUtil.java
Modified:
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/BasicChartStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartLabelStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/Copyable.java
Log:
new class CopyableUtil
ChartStyles now implement Copyable

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/AbstractChartStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -65,6 +65,7 @@
 
 import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.lang.LangUtil;
+import skrueger.geotools.CopyableUtil;
 
 /**
  * This class provides an abstract implementation for chart styles.
@@ -158,7 +159,52 @@
     if ( yTitle != null )
       setAxisStyle(RANGE_AXIS, new ChartAxisStyle(yTitle,Color.BLACK,0.0,0.0) );
   }
+  
+  /**
+   * Creates a (deep) clone of this chart style.
+   */
+  @Override
+  public abstract AbstractChartStyle copy();
+  
+  /**
+   * Copies all properties of this chart style to another
+   * chart style.
+   * @param dest destination object (if {@code null} the copy
+   *             is created by {@link #copy()})
+   * @return {@code dest} or the new instance
+   * @exception IllegalArgumentException if {@code dest} is no
+   *            {@link AbstractChartStyle}
+   */
+  @Override
+  public AbstractChartStyle copyTo(ChartStyle dest) {
+    if ( dest == null )
+      return copy();
+    if ( !(dest instanceof AbstractChartStyle) )
+      throw new IllegalArgumentException(LangUtil.getSimpleClassName(this)+".copy(..) can not be applied on "+LangUtil.getSimpleClassName(dest));
 
+    AbstractChartStyle destStyle = (AbstractChartStyle)dest;
+    destStyle.id   = getID();
+    destStyle.setType( getType() );
+    destStyle.setTitleStyle( CopyableUtil.copyOrCreate(getTitleStyle(), destStyle.getTitleStyle()) );
+    destStyle.setDescStyle( CopyableUtil.copyOrCreate(getDescStyle(), destStyle.getDescStyle()) );
+    destStyle.setBackground( getBackground() );
+    destStyle.setBorderVisible( isBorderVisible() );
+    destStyle.setOrientation( getOrientation() );
+    destStyle.setLegend( hasLegend() );
+    destStyle.setTooltips( hasTooltips() );
+    destStyle.setURLs( hasURLs() );
+    destStyle.setPlotStyle( CopyableUtil.copyOrCreate(getPlotStyle(), destStyle.getPlotStyle()) );
+    
+    destStyle.axisStyle.clear();
+    for ( Integer axis : axisStyle.keySet() )
+      destStyle.setAxisStyle(axis, getAxisStyle(axis).copy() );
+    destStyle.rendererStyle.clear();
+    for ( Integer renderer : rendererStyle.keySet() )
+      destStyle.setRendererStyle(renderer, getRendererStyle(renderer).copy() );
+
+    return destStyle;
+  }
+
   /**
    * Returns the (unique) ID for the style.
    */

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/BasicChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/BasicChartStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/BasicChartStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -126,6 +126,33 @@
   }
 
   /**
+   * Creates a (deep) clone of this chart style.
+   */
+  @Override
+  public BasicChartStyle copy() {
+    return copyTo( new BasicChartStyle("") );
+  }
+  
+  /**
+   * Copies all properties of this chart style to another
+   * chart style.
+   * @param dest destination object (if {@code null} the copy
+   *             is created by {@link #copy()})
+   * @return {@code dest} or the new instance
+   * @exception IllegalArgumentException if {@code dest} is no
+   *            {@link AbstractChartStyle}
+   */
+  public BasicChartStyle copyTo(BasicChartStyle dest) {
+    // copy the super class properties
+    dest = (BasicChartStyle)copyTo((AbstractChartStyle)dest);
+    // copy this classes properties
+    dest.setStacked( isStacked() );
+    dest.setStepped( isStepped() );
+
+    return dest;
+  }
+
+  /**
    * Sets the type of the chart style.
    * @param type the chart type
    * @exception IllegalArgumentException if {@link aType} is not of

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartAxisStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartAxisStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -41,6 +41,7 @@
 import org.jfree.chart.axis.NumberAxis;
 
 import schmitzm.lang.LangUtil;
+import skrueger.geotools.Copyable;
 import skrueger.i8n.Translation;
 
 /**
@@ -94,6 +95,32 @@
   }
 
   /**
+   * 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() );
+    return dest;
+  }
+
+  /**
    * Returns the angle (in degrees) the label text is rotated by.
    */
   public Double getLabelAngle() {

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartLabelStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartLabelStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartLabelStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -35,6 +35,7 @@
 import org.apache.log4j.Category;
 
 import schmitzm.lang.LangUtil;
+import skrueger.geotools.Copyable;
 import skrueger.i8n.Translation;
 
 /**
@@ -46,7 +47,7 @@
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
  * @version 1.0
  */
-public class ChartLabelStyle {
+public class ChartLabelStyle implements Copyable<ChartLabelStyle>{
   /** Logger for this class */
   protected final Category LOGGER = LangUtil.createLogger(this);
 
@@ -87,6 +88,29 @@
     setLabelTranslation(label);
     setPaint(color);
   }
+  
+  /**
+   * Creates a (deep) clone of this style.
+   */
+  @Override
+  public ChartLabelStyle copy() {
+    return copyTo( new ChartLabelStyle() );
+  }
+  
+  /**
+   * 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 ChartLabelStyle copyTo(ChartLabelStyle dest) {
+    if ( dest == null )
+      return copy();
+    dest.setLabelTranslation( getLabelTranslation() );
+    dest.setPaint( getPaint() );
+    return dest;
+  }
 
   /**
    * Returns the label text in the default localization.

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-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -30,6 +30,9 @@
 package schmitzm.jfree.chart.style;
 
 import java.awt.Color;
+import java.awt.Insets;
+import java.awt.Stroke;
+import java.awt.geom.Point2D;
 
 import org.apache.log4j.Category;
 import org.jfree.chart.plot.CategoryPlot;
@@ -39,6 +42,7 @@
 
 import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.lang.LangUtil;
+import skrueger.geotools.Copyable;
 
 /**
  * This class defines the rendering style the charts plot(s). The following
@@ -57,7 +61,7 @@
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
  * @version 1.0
  */
-public class ChartPlotStyle {
+public class ChartPlotStyle implements Copyable<ChartPlotStyle> {
   /** Logger for this class */
   protected final Category LOGGER = LangUtil.createLogger(this);
 
@@ -90,6 +94,39 @@
   }
 
   /**
+   * 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();
+
+    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() );
+
+    return dest;
+  }
+
+  /**
    * Returns the inner margin of the plot.
    */
   public RectangleInsets getInsets() {
@@ -337,7 +374,9 @@
       plot.setDomainCrosshairPaint( getCrosshairPaint() );
       plot.setRangeCrosshairPaint( getCrosshairPaint() );
     }
-    
+
+//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);
   }

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartRendererStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartRendererStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -48,6 +48,7 @@
 
 import schmitzm.jfree.JFreeChartUtil;
 import schmitzm.lang.LangUtil;
+import skrueger.geotools.Copyable;
 
 /**
  * This class defines the rendering style the charts series. The following
@@ -62,7 +63,7 @@
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
  * @version 1.0
  */
-public class ChartRendererStyle {
+public class ChartRendererStyle implements Copyable<ChartRendererStyle> {
   /** Logger for this class */
   protected final Category LOGGER = LangUtil.createLogger(this);
 
@@ -104,6 +105,56 @@
   }
 
   /**
+   * Creates a (deep) clone of this style.
+   */
+  @Override
+  public ChartRendererStyle copy() {
+    return copyTo( new ChartRendererStyle() );
+  }
+  
+  /**
+   * 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 ChartRendererStyle copyTo(ChartRendererStyle dest) {
+    if ( dest == null )
+      return copy();
+
+    dest.setMargin( getMargin() );
+    
+    dest.seriesItemLabelsVisible.clear();
+    for ( int series : seriesItemLabelsVisible.keySet() )
+      dest.setSeriesItemLabelsVisible( series, isSeriesItemLabelsVisible(series) );
+    
+    dest.seriesPaint.clear();
+    for ( int series : seriesPaint.keySet() )
+      dest.setSeriesPaint( series, getSeriesPaint(series) );
+
+    dest.seriesShapesVisible.clear();
+    for ( int series : seriesShapesVisible.keySet() )
+      dest.setSeriesShapesVisible( series, isSeriesShapesVisible(series) );
+
+    dest.seriesLegendVisible.clear();
+    for ( int series : seriesLegendVisible.keySet() )
+      dest.setSeriesLegendVisible( series, isSeriesLegendVisible(series) );
+
+    dest.seriesLegendLabel.clear();
+    for ( int series : seriesLegendLabel.keySet() )
+      if ( getSeriesLegendLabel(series) != null )
+        dest.setSeriesLegendLabel( series, getSeriesLegendLabel(series).copy() );
+
+    dest.seriesLegendTooltip.clear();
+    for ( int series : seriesLegendTooltip.keySet() )
+      if ( getSeriesLegendTooltip(series) != null )
+        dest.setSeriesLegendTooltip( series, getSeriesLegendTooltip(series).copy() );
+
+    return dest;
+  }
+
+  /**
    * Returns the margin (percentage) between the chart bars. The margin is
    * only applicable on bar charts.
    */

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -36,7 +36,9 @@
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.data.general.Dataset;
 
+import skrueger.geotools.Copyable;
 
+
 /**
  * This interface is a general super class for a design style of a {@link JFreeChart}.
  * Sub classes should read the style from an xml element or something like that.
@@ -46,7 +48,7 @@
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
  * @version 1.0
  */
-public interface ChartStyle {
+public interface ChartStyle extends Copyable<ChartStyle> {
   final static Logger LOGGER = Logger.getLogger(ChartStyle.class);
   
   /** Constant for the domain axis (X). */

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -60,6 +60,32 @@
   }
 
   /**
+   * Creates a (deep) clone of this chart style.
+   */
+  @Override
+  public ScatterChartStyle copy() {
+    return copyTo( new ScatterChartStyle("") );
+  }
+  
+  /**
+   * Copies all properties of this chart style to another
+   * chart style.
+   * @param dest destination object (if {@code null} the copy
+   *             is created by {@link #copy()})
+   * @return {@code dest} or the new instance
+   * @exception IllegalArgumentException if {@code dest} is no
+   *            {@link AbstractChartStyle}
+   */
+  public ScatterChartStyle copyTo(ScatterChartStyle dest) {
+    // copy the super class properties
+    dest = (ScatterChartStyle)copyTo((AbstractChartStyle)dest);
+    // copy this classes properties
+    dest.setRegressionLineVisible( isRegressionLineVisible() );
+
+    return dest;
+  }
+
+  /**
    * Returns whether a regression line is shown.
    */
   public boolean isRegressionLineVisible() {

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureBasicChartStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -68,6 +68,29 @@
 		dummyFeatureChartStyle = new Dummy(id,-1);
 	}
 	
+    /**
+     * Creates a (deep) clone of this style.
+     */
+    @Override
+    public FeatureBasicChartStyle copy() {
+      return copyTo( new FeatureBasicChartStyle("") );
+    }
+    
+    /**
+     * 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 FeatureBasicChartStyle copyTo(FeatureBasicChartStyle dest) {
+      // copy the super class properties
+      dest = (FeatureBasicChartStyle)copyTo((BasicChartStyle)dest);
+      // copy this classes properties
+      dummyFeatureChartStyle.copyTo(dest);
+
+      return dest;
+    }
+
 	/**
 	 * Returns the maximum number of feature attributes that can be
 	 * specified by this style.

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureChartStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -41,8 +41,10 @@
 import org.opengis.feature.simple.SimpleFeatureType;
 
 import schmitzm.jfree.chart.style.AbstractChartStyle;
+import schmitzm.jfree.chart.style.ChartLabelStyle;
 import schmitzm.jfree.chart.style.ChartStyle;
 import schmitzm.lang.LangUtil;
+import skrueger.geotools.Copyable;
 
 /**
  * This interface extends the chart style with several functionalities
@@ -213,7 +215,41 @@
       if ( maxAttrCount > 0 && maxAttrIdx >= maxAttrCount )
         throw new IllegalArgumentException("Only "+maxAttrCount+" attributes can be specified for "+LangUtil.getSimpleClassName(this));
     }
+    
+    /**
+     * Creates a (deep) clone of this style. The properties
+     * of the super class ({@link AbstractChartStyle}) are <b>ignored</b>
+     * because they are unused for the dummy.
+     */
+    @Override
+    public Dummy copy() {
+      return copyTo( new Dummy("") );
+    }
+    
+    /**
+     * Copies all properties of this style to another one. The properties
+     * of the super class ({@link AbstractChartStyle}) are <b>ignored</b>
+     * because they are unused for the dummy.
+     * @param dest destination object (if {@code null} the copy
+     *             is created by {@link #copy()})
+     * @return {@code dest} or the new instance
+     */
+    public Dummy copyTo(Dummy dest) {
+      // !! do NOT copy the super class properties !!
+      // !! copy only this classes properties !!
+      dest.setSortDomainAxis( isSortDomainAxis() );
+      dest.setForceCategories( isForceCategories() );
 
+      dest.attrNames.clear();
+      for (Integer idx : attrNames.keySet() )
+        dest.setAttributeName(idx, getAttributeName(idx));
+      dest.normalizeAttr.clear();
+      for (Integer idx : normalizeAttr.keySet() )
+        dest.setAttributeNormalized(idx, isAttributeNormalized(idx));
+      
+      return dest;
+    }
+
     /**
      * Returns the maximum number of feature attributes that can be
      * specified by this style.

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/feature/style/FeatureScatterChartStyle.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -35,6 +35,7 @@
 import org.jfree.data.general.Dataset;
 import org.jfree.data.xy.XYDataset;
 
+import schmitzm.jfree.chart.style.BasicChartStyle;
 import schmitzm.jfree.chart.style.ScatterChartStyle;
 
 /**
@@ -73,6 +74,29 @@
   }
 
   /**
+   * Creates a (deep) clone of this style.
+   */
+  @Override
+  public FeatureScatterChartStyle copy() {
+    return copyTo( new FeatureScatterChartStyle("") );
+  }
+  
+  /**
+   * 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 FeatureScatterChartStyle copyTo(FeatureScatterChartStyle dest) {
+    // copy the super class properties
+    dest = (FeatureScatterChartStyle)copyTo((ScatterChartStyle)dest);
+    // copy this classes properties
+    dummyFeatureChartStyle.copyTo(dest);
+
+    return dest;
+  }
+
+  /**
    * Returns the maximum number of feature attributes that can be
    * specified by this style.
    * @return always 2

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/Copyable.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/Copyable.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/Copyable.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -14,5 +14,4 @@
 	 * @param t
 	 */
 	public T copy();
-	
 }

Added: branches/1.0-gt2-2.6/src/skrueger/geotools/CopyableUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/CopyableUtil.java	2009-10-07 14:23:06 UTC (rev 448)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/CopyableUtil.java	2009-10-08 19:41:57 UTC (rev 449)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+
+package skrueger.geotools;
+
+/**
+ * Some utility method for {@link Copyable}.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class CopyableUtil {
+  
+  /**
+   * Copies an {@link Copyable} to another. If possible no new destination
+   * instance is created, so the "original" destination object is
+   * also returned.<br>
+   * If {@code source} is {@code null}, the {@code dest} object
+   * is irrelevant and {@code null} is returned. If {@code dest} is NULL
+   * and {@code source} in not NULL, a new {@code source.copy()} is
+   * returned. 
+   * @param source the source object (can be {@code null})
+   * @param dest   the object, the source values are copied to (can be {@code null})
+   */
+  public static <T extends Copyable<T>> T copyOrCreate(T source, T dest) {
+    // If both objects are not NULL, the source Copyable can be applied
+    // to destination Copyable
+    if ( source != null && dest != null )
+      source.copyTo( dest );
+    // Otherwise: If source Copyable is not NULL, but destination a new
+    //            destination object is created from source and returned
+    else if ( source != null && dest == null )
+      dest = source.copy();
+    // Otherwise: source Copyable is NULL, so destination must also
+    //            be NULL
+    else 
+      dest = null;
+    
+    return dest;
+  }
+}



More information about the Schmitzm-commits mailing list