/**
 * Chart2D, a java library for drawing two dimensional charts.
 * Copyright (C) 2001 Jason J. Simas
 *
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package net.sourceforge.chart2d;


import java.util.Vector;


/**
 * Shared binding helpers for connecting charts and property objects.
 */
final class PropertyBindingUtils {

  private PropertyBindingUtils() {}


  static Object2DProperties replaceObject2DProperties (
    Object2D owner, Object2DProperties current, Object2DProperties next) {

    next.addObject2D (owner);
    if (current != null) current.removeObject2D (owner);
    return next;
  }


  static Chart2DProperties replaceChart2DProperties (
    Chart2D owner, Chart2DProperties current, Chart2DProperties next) {

    next.addChart2D (owner);
    if (current != null) current.removeChart2D (owner);
    return next;
  }


  static LegendProperties replaceLegendProperties (
    Chart2D owner, LegendProperties current, LegendProperties next) {

    next.addChart2D (owner);
    if (current != null) current.removeChart2D (owner);
    return next;
  }


  static GraphChart2DProperties replaceGraphChart2DProperties (
    GraphChart2D owner, GraphChart2DProperties current,
    GraphChart2DProperties next) {

    next.addGraphChart2D (owner);
    if (current != null) current.removeGraphChart2D (owner);
    return next;
  }


  static PieChart2DProperties replacePieChart2DProperties (
    PieChart2D owner, PieChart2DProperties current, PieChart2DProperties next) {

    next.addPieChart2D (owner);
    if (current != null) current.removePieChart2D (owner);
    return next;
  }


  static Dataset replaceDataset (Chart2D owner, Dataset current, Dataset next) {

    next.addChart2D (owner);
    if (current != null) current.removeChart2D (owner);
    return next;
  }


  static MultiColorsProperties replaceMultiColorsProperties (
    Object2D owner, MultiColorsProperties current, MultiColorsProperties next) {

    next.addObject2D (owner);
    if (current != null) current.removeObject2D (owner);
    return next;
  }


  static void addGraphProperties (
    GraphChart2D owner, Vector target, GraphProperties graphProps) {

    graphProps.addGraphChart2D (owner);
    target.add (graphProps);
  }


  static void removeGraphProperties (
    GraphChart2D owner, Vector target, GraphProperties graphProps) {

    graphProps.removeGraphChart2D (owner);
    target.remove (graphProps);
  }


  static void addDataset (Chart2D owner, Vector target, Dataset dataset) {

    dataset.addChart2D (owner);
    target.add (dataset);
  }


  static void removeDataset (Chart2D owner, Vector target, Dataset dataset) {

    dataset.removeChart2D (owner);
    target.remove (dataset);
  }


  static void addMultiColorsProperties (
    Object2D owner, Vector target, MultiColorsProperties props) {

    props.addObject2D (owner);
    target.add (props);
  }


  static void removeMultiColorsProperties (
    Object2D owner, Vector target, MultiColorsProperties props) {

    props.removeObject2D (owner);
    target.remove (props);
  }


  static void addWarningRegionProperties (
    GraphChart2D owner, Vector target, WarningRegionProperties props) {

    props.addGraphChart2D (owner);
    target.add (props);
  }


  static void removeWarningRegionProperties (
    GraphChart2D owner, Vector target, WarningRegionProperties props) {

    props.removeGraphChart2D (owner);
    target.remove (props);
  }
}
