gt:         if (orientation == PlotOrientation.VERTICAL) {
context: /* ===========================================================
   * JFreeChart : a free chart library for the Java(tm) platform
   * ===========================================================
   *
   * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors.
   *
   * Project Info:  http://www.jfree.org/jfreechart/index.html
   *
   * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
   * USA.
   *
   * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   * Other names may be trademarks of their respective owners.]
   *
   * ------------------------
   * CombinedRangeXYPlot.java
   * ------------------------
   * (C) Copyright 2001-2012, by Bill Kelemen and Contributors.
   *
   * Original Author:  Bill Kelemen;
   * Contributor(s):   David Gilbert (for Object Refinery Limited);
   *                   Anthony Boulestreau;
   *                   David Basten;
   *                   Kevin Frechette (for ISTI);
   *                   Arnaud Lelievre;
   *                   Nicolas Brodu;
   *                   Petr Kubanek (bug 1606205);
   *
   * Changes:
   * --------
   * 06-Dec-2001 : Version 1 (BK);
   * 12-Dec-2001 : Removed unnecessary 'throws' clause from constructor (DG);
   * 18-Dec-2001 : Added plotArea attribute and get/set methods (BK);
   * 22-Dec-2001 : Fixed bug in chartChanged with multiple combinations of
   *               CombinedPlots (BK);
   * 08-Jan-2002 : Moved to new package com.jrefinery.chart.combination (DG);
   * 25-Feb-2002 : Updated import statements (DG);
   * 28-Feb-2002 : Readded "this.plotArea = plotArea" that was deleted from
   *               draw() method (BK);
   * 26-Mar-2002 : Added an empty zoom method (this method needs to be written
   *               so that combined plots will support zooming (DG);
   * 29-Mar-2002 : Changed the method createCombinedAxis adding the creation of
   *               OverlaidSymbolicAxis and CombinedSymbolicAxis(AB);
   * 23-Apr-2002 : Renamed CombinedPlot-->MultiXYPlot, and simplified the
   *               structure (DG);
   * 23-May-2002 : Renamed (again) MultiXYPlot-->CombinedXYPlot (DG);
   * 19-Jun-2002 : Added get/setGap() methods suggested by David Basten (DG);
   * 25-Jun-2002 : Removed redundant imports (DG);
   * 16-Jul-2002 : Draws shared axis after subplots (to fix missing gridlines),
   *               added overrides of 'setSeriesPaint()' and 'setXYItemRenderer()'
   *               that pass changes down to subplots (KF);
   * 09-Oct-2002 : Added add(XYPlot) method (DG);
   * 26-Mar-2003 : Implemented Serializable (DG);
   * 16-May-2003 : Renamed CombinedXYPlot --> CombinedRangeXYPlot (DG);
   * 26-Jun-2003 : Fixed bug 755547 (DG);
   * 16-Jul-2003 : Removed getSubPlots() method (duplicate of getSubplots()) (DG);
   * 08-Aug-2003 : Adjusted totalWeight in remove() method (DG);
   * 21-Aug-2003 : Implemented Cloneable (DG);
   * 08-Sep-2003 : Added internationalization via use of properties
   *               resourceBundle (RFE 690236) (AL);
   * 11-Sep-2003 : Fix cloning support (subplots) (NB);
   * 15-Sep-2003 : Fixed error in cloning (DG);
   * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
   * 17-Sep-2003 : Updated handling of 'clicks' (DG);
   * 12-Nov-2004 : Implements the new Zoomable interface (DG);
   * 25-Nov-2004 : Small update to clone() implementation (DG);
   * 21-Feb-2005 : The getLegendItems() method now returns the fixed legend
   *               items if set (DG);
   * 05-May-2005 : Removed unused draw() method (DG);
   * ------------- JFREECHART 1.0.x ---------------------------------------------
   * 13-Sep-2006 : Updated API docs (DG);
   * 06-Feb-2007 : Fixed bug 1606205, draw shared axis after subplots (DG);
   * 23-Mar-2007 : Reverted previous patch (DG);
   * 17-Apr-2007 : Added null argument checks to findSubplot() (DG);
   * 18-Jul-2007 : Fixed bug in removeSubplot (DG);
   * 27-Nov-2007 : Modified setFixedDomainAxisSpaceForSubplots() so as not to
   *               trigger change events in subplots (DG);
   * 27-Mar-2008 : Add documentation for getDataRange() method (DG);
   * 31-Mar-2008 : Updated getSubplots() to return EMPTY_LIST for null
   *               subplots, as suggested by Richard West (DG);
   * 28-Apr-2008 : Fixed zooming problem (see bug 1950037) (DG);
   * 11-Aug-2008 : Don't store totalWeight of subplots, calculate it as
   *               required (DG);
   * 21-Dec-2011 : Apply patch 3447161 by Ulrich Voigt and Martin Hoeller (MH);
   *
   */
  
  package org.jfree.chart.plot;
  
  import java.awt.Graphics2D;
  import java.awt.geom.Point2D;
  import java.awt.geom.Rectangle2D;
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.List;
  
  import org.jfree.chart.LegendItemCollection;
  import org.jfree.chart.axis.AxisSpace;
  import org.jfree.chart.axis.AxisState;
  import org.jfree.chart.axis.NumberAxis;
  import org.jfree.chart.axis.ValueAxis;
  import org.jfree.chart.event.PlotChangeEvent;
  import org.jfree.chart.event.PlotChangeListener;
  import org.jfree.chart.renderer.xy.XYItemRenderer;
  import org.jfree.chart.util.ParamChecks;
  import org.jfree.chart.util.ShadowGenerator;
  import org.jfree.data.Range;
  import org.jfree.ui.RectangleEdge;
  import org.jfree.ui.RectangleInsets;
  import org.jfree.util.ObjectUtilities;
  
  /**
   * An extension of {@link XYPlot} that contains multiple subplots that share a
   * common range axis.
   */
  public class CombinedRangeXYPlot extends XYPlot
          implements PlotChangeListener {
  
      /** For serialization. */
      private static final long serialVersionUID = -5177814085082031168L;
  
      /** Storage for the subplot references. */
      private List subplots;
  
      /** The gap between subplots. */
      private double gap = 5.0;
  
      /** Temporary storage for the subplot areas. */
      private transient Rectangle2D[] subplotAreas;
  
      /**
       * Default constructor.
       */
      public CombinedRangeXYPlot() {
          this(new NumberAxis());
      }
  
      /**
       * Creates a new plot.
       *
       * @param rangeAxis  the shared axis.
       */
      public CombinedRangeXYPlot(ValueAxis rangeAxis) {
  
          super(null, // no data in the parent plot
                null,
                rangeAxis,
                null);
  
          this.subplots = new java.util.ArrayList();
  
      }
  
      /**
       * Returns a string describing the type of plot.
       *
       * @return The type of plot.
       */
      @Override
      public String getPlotType() {
          return localizationResources.getString("Combined_Range_XYPlot");
      }
  
      /**
       * Returns the space between subplots.
       *
       * @return The gap.
       *
       * @see #setGap(double)
       */
      public double getGap() {
          return this.gap;
      }
  
      /**
       * Sets the amount of space between subplots.
       *
       * @param gap  the gap between subplots.
       *
       * @see #getGap()
       */
      public void setGap(double gap) {
          this.gap = gap;
      }
  
      /**
       * Adds a subplot, with a default 'weight' of 1.
       * <br><br>
       * You must ensure that the subplot has a non-null domain axis.  The range
       * axis for the subplot will be set to <code>null</code>.
       *
       * @param subplot  the subplot.
       */
      public void add(XYPlot subplot) {
          add(subplot, 1);
      }
  
      /**
       * Adds a subplot with a particular weight (greater than or equal to one).
       * The weight determines how much space is allocated to the subplot
       * relative to all the other subplots.
       * <br><br>
       * You must ensure that the subplot has a non-null domain axis.  The range
       * axis for the subplot will be set to <code>null</code>.
       *
       * @param subplot  the subplot (<code>null</code> not permitted).
       * @param weight  the weight (must be 1 or greater).
       */
      public void add(XYPlot subplot, int weight) {
          ParamChecks.nullNotPermitted(subplot, "subplot");
          if (weight <= 0) {
              String msg = "The 'weight' must be positive.";
              throw new IllegalArgumentException(msg);
          }
  
          // store the plot and its weight
          subplot.setParent(this);
          subplot.setWeight(weight);
          subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
          subplot.setRangeAxis(null);
          subplot.addChangeListener(this);
          this.subplots.add(subplot);
          configureRangeAxes();
          fireChangeEvent();
  
      }
  
      /**
       * Removes a subplot from the combined chart.
       *
       * @param subplot  the subplot (<code>null</code> not permitted).
       */
      public void remove(XYPlot subplot) {
          ParamChecks.nullNotPermitted(subplot, "subplot");
          int position = -1;
          int size = this.subplots.size();
          int i = 0;
          while (position == -1 && i < size) {
              if (this.subplots.get(i) == subplot) {
                  position = i;
              }
              i++;
          }
          if (position != -1) {
              this.subplots.remove(position);
              subplot.setParent(null);
              subplot.removeChangeListener(this);
              configureRangeAxes();
              fireChangeEvent();
          }
      }
  
      /**
       * Returns the list of subplots.  The returned list may be empty, but is
       * never <code>null</code>.
       *
       * @return An unmodifiable list of subplots.
       */
      public List getSubplots() {
          if (this.subplots != null) {
              return Collections.unmodifiableList(this.subplots);
          }
          else {
              return Collections.EMPTY_LIST;
          }
      }
  
      /**
       * Calculates the space required for the axes.
       *
       * @param g2  the graphics device.
       * @param plotArea  the plot area.
       *
       * @return The space required for the axes.
       */
      @Override
      protected AxisSpace calculateAxisSpace(Graphics2D g2,
                                             Rectangle2D plotArea) {
  
          AxisSpace space = new AxisSpace();
          PlotOrientation orientation = getOrientation();
  
          // work out the space required by the domain axis...
          AxisSpace fixed = getFixedRangeAxisSpace();
          if (fixed != null) {
              if (orientation == PlotOrientation.VERTICAL) {
                  space.setLeft(fixed.getLeft());
                  space.setRight(fixed.getRight());
              }
              else if (orientation == PlotOrientation.HORIZONTAL) {
                  space.setTop(fixed.getTop());
                  space.setBottom(fixed.getBottom());
              }
          }
          else {
              ValueAxis valueAxis = getRangeAxis();
              RectangleEdge valueEdge = Plot.resolveRangeAxisLocation(
                  getRangeAxisLocation(), orientation
              );
              if (valueAxis != null) {
                  space = valueAxis.reserveSpace(g2, this, plotArea, valueEdge,
                          space);
              }
          }
  
          Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);
          // work out the maximum height or width of the non-shared axes...
          int n = this.subplots.size();
          int totalWeight = 0;
          for (int i = 0; i < n; i++) {
              XYPlot sub = (XYPlot) this.subplots.get(i);
              totalWeight += sub.getWeight();
          }
  
          // calculate plotAreas of all sub-plots, maximum vertical/horizontal
          // axis width/height
          this.subplotAreas = new Rectangle2D[n];
          double x = adjustedPlotArea.getX();
          double y = adjustedPlotArea.getY();
          double usableSize = 0.0;
  