Source for org.jfree.chart.plot.CombinedDomainXYPlot

   1: /* ===========================================================
   2:  * JFreeChart : a free chart library for the Java(tm) platform
   3:  * ===========================================================
   4:  *
   5:  * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
   6:  *
   7:  * Project Info:  http://www.jfree.org/jfreechart/index.html
   8:  *
   9:  * This library is free software; you can redistribute it and/or modify it 
  10:  * under the terms of the GNU Lesser General Public License as published by 
  11:  * the Free Software Foundation; either version 2.1 of the License, or 
  12:  * (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but 
  15:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  16:  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
  17:  * License for more details.
  18:  *
  19:  * You should have received a copy of the GNU Lesser General Public
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
  22:  * USA.  
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
  25:  * in the United States and other countries.]
  26:  *
  27:  * -------------------------
  28:  * CombinedDomainXYPlot.java
  29:  * -------------------------
  30:  * (C) Copyright 2001-2006, by Bill Kelemen and Contributors.
  31:  *
  32:  * Original Author:  Bill Kelemen;
  33:  * Contributor(s):   David Gilbert (for Object Refinery Limited);
  34:  *                   Anthony Boulestreau;
  35:  *                   David Basten;
  36:  *                   Kevin Frechette (for ISTI);
  37:  *                   Nicolas Brodu;
  38:  *
  39:  * $Id: CombinedDomainXYPlot.java,v 1.9.2.2 2006/08/23 09:44:17 mungady Exp $
  40:  *
  41:  * Changes:
  42:  * --------
  43:  * 06-Dec-2001 : Version 1 (BK);
  44:  * 12-Dec-2001 : Removed unnecessary 'throws' clause from constructor (DG);
  45:  * 18-Dec-2001 : Added plotArea attribute and get/set methods (BK);
  46:  * 22-Dec-2001 : Fixed bug in chartChanged with multiple combinations of 
  47:  *               CombinedPlots (BK);
  48:  * 08-Jan-2002 : Moved to new package com.jrefinery.chart.combination (DG);
  49:  * 25-Feb-2002 : Updated import statements (DG);
  50:  * 28-Feb-2002 : Readded "this.plotArea = plotArea" that was deleted from 
  51:  *               draw() method (BK);
  52:  * 26-Mar-2002 : Added an empty zoom method (this method needs to be written so
  53:  *               that combined plots will support zooming (DG);
  54:  * 29-Mar-2002 : Changed the method createCombinedAxis adding the creation of 
  55:  *               OverlaidSymbolicAxis and CombinedSymbolicAxis(AB);
  56:  * 23-Apr-2002 : Renamed CombinedPlot-->MultiXYPlot, and simplified the    
  57:  *               structure (DG);
  58:  * 23-May-2002 : Renamed (again) MultiXYPlot-->CombinedXYPlot (DG);
  59:  * 19-Jun-2002 : Added get/setGap() methods suggested by David Basten (DG);
  60:  * 25-Jun-2002 : Removed redundant imports (DG);
  61:  * 16-Jul-2002 : Draws shared axis after subplots (to fix missing gridlines),
  62:  *               added overrides of 'setSeriesPaint()' and 'setXYItemRenderer()'
  63:  *               that pass changes down to subplots (KF);
  64:  * 09-Oct-2002 : Added add(XYPlot) method (DG);
  65:  * 26-Mar-2003 : Implemented Serializable (DG);
  66:  * 16-May-2003 : Renamed CombinedXYPlot --> CombinedDomainXYPlot (DG);
  67:  * 04-Aug-2003 : Removed leftover code that was causing domain axis drawing 
  68:  *               problem (DG);
  69:  * 08-Aug-2003 : Adjusted totalWeight in remove() method (DG);
  70:  * 21-Aug-2003 : Implemented Cloneable (DG);
  71:  * 11-Sep-2003 : Fix cloning support (subplots) (NB);
  72:  * 15-Sep-2003 : Fixed error in cloning (DG);
  73:  * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
  74:  * 17-Sep-2003 : Updated handling of 'clicks' (DG);
  75:  * 12-Nov-2004 : Implemented the new Zoomable interface (DG);
  76:  * 25-Nov-2004 : Small update to clone() implementation (DG);
  77:  * 21-Feb-2005 : The getLegendItems() method now returns the fixed legend
  78:  *               items if set (DG);
  79:  * 05-May-2005 : Removed unused draw() method (DG);
  80:  * ------------- JFREECHART 1.0.0 ---------------------------------------------
  81:  * 23-Aug-2006 : Override setFixedRangeAxisSpace() to update subplots (DG);
  82:  *
  83:  */
  84: 
  85: package org.jfree.chart.plot;
  86: 
  87: import java.awt.Graphics2D;
  88: import java.awt.geom.Point2D;
  89: import java.awt.geom.Rectangle2D;
  90: import java.io.Serializable;
  91: import java.util.Collections;
  92: import java.util.Iterator;
  93: import java.util.List;
  94: 
  95: import org.jfree.chart.LegendItemCollection;
  96: import org.jfree.chart.axis.AxisSpace;
  97: import org.jfree.chart.axis.AxisState;
  98: import org.jfree.chart.axis.NumberAxis;
  99: import org.jfree.chart.axis.ValueAxis;
 100: import org.jfree.chart.event.PlotChangeEvent;
 101: import org.jfree.chart.event.PlotChangeListener;
 102: import org.jfree.chart.renderer.xy.XYItemRenderer;
 103: import org.jfree.data.Range;
 104: import org.jfree.ui.RectangleEdge;
 105: import org.jfree.ui.RectangleInsets;
 106: import org.jfree.util.ObjectUtilities;
 107: import org.jfree.util.PublicCloneable;
 108: 
 109: /**
 110:  * An extension of {@link XYPlot} that contains multiple subplots that share a 
 111:  * common domain axis.
 112:  */
 113: public class CombinedDomainXYPlot extends XYPlot 
 114:                                   implements Cloneable, PublicCloneable, 
 115:                                              Serializable,
 116:                                              PlotChangeListener {
 117: 
 118:     /** For serialization. */
 119:     private static final long serialVersionUID = -7765545541261907383L;
 120:     
 121:     /** Storage for the subplot references. */
 122:     private List subplots;
 123: 
 124:     /** Total weight of all charts. */
 125:     private int totalWeight = 0;
 126: 
 127:     /** The gap between subplots. */
 128:     private double gap = 5.0;
 129: 
 130:     /** Temporary storage for the subplot areas. */
 131:     private transient Rectangle2D[] subplotAreas;
 132:     // TODO:  the subplot areas needs to be moved out of the plot into the plot
 133:     //        state
 134:     
 135:     /**
 136:      * Default constructor.
 137:      */
 138:     public CombinedDomainXYPlot() {
 139:         this(new NumberAxis());      
 140:     }
 141:     
 142:     /**
 143:      * Creates a new combined plot that shares a domain axis among multiple 
 144:      * subplots.
 145:      *
 146:      * @param domainAxis  the shared axis.
 147:      */
 148:     public CombinedDomainXYPlot(ValueAxis domainAxis) {
 149: 
 150:         super(
 151:             null,        // no data in the parent plot
 152:             domainAxis,
 153:             null,        // no range axis
 154:             null         // no rendereer
 155:         );  
 156: 
 157:         this.subplots = new java.util.ArrayList();
 158: 
 159:     }
 160: 
 161:     /**
 162:      * Returns a string describing the type of plot.
 163:      *
 164:      * @return The type of plot.
 165:      */
 166:     public String getPlotType() {
 167:         return "Combined_Domain_XYPlot";
 168:     }
 169: 
 170:     /**
 171:      * Sets the orientation for the plot (also changes the orientation for all 
 172:      * the subplots to match).
 173:      * 
 174:      * @param orientation  the orientation (<code>null</code> not allowed).
 175:      */
 176:     public void setOrientation(PlotOrientation orientation) {
 177: 
 178:         super.setOrientation(orientation);
 179:         Iterator iterator = this.subplots.iterator();
 180:         while (iterator.hasNext()) {
 181:             XYPlot plot = (XYPlot) iterator.next();
 182:             plot.setOrientation(orientation);
 183:         }
 184: 
 185:     }
 186: 
 187:     /**
 188:      * Returns the range for the specified axis.  This is the combined range 
 189:      * of all the subplots.
 190:      *
 191:      * @param axis  the axis.
 192:      *
 193:      * @return The range (possibly <code>null</code>).
 194:      */
 195:     public Range getDataRange(ValueAxis axis) {
 196: 
 197:         Range result = null;
 198:         if (this.subplots != null) {
 199:             Iterator iterator = this.subplots.iterator();
 200:             while (iterator.hasNext()) {
 201:                 XYPlot subplot = (XYPlot) iterator.next();
 202:                 result = Range.combine(result, subplot.getDataRange(axis));
 203:             }
 204:         }
 205:         return result;
 206: 
 207:     }
 208: 
 209:     /**
 210:      * Returns the gap between subplots, measured in Java2D units.
 211:      *
 212:      * @return The gap (in Java2D units).
 213:      */
 214:     public double getGap() {
 215:         return this.gap;
 216:     }
 217: 
 218:     /**
 219:      * Sets the amount of space between subplots and sends a 
 220:      * {@link PlotChangeEvent} to all registered listeners.
 221:      *
 222:      * @param gap  the gap between subplots (in Java2D units).
 223:      */
 224:     public void setGap(double gap) {
 225:         this.gap = gap;
 226:         notifyListeners(new PlotChangeEvent(this));
 227:     }
 228: 
 229:     /**
 230:      * Adds a subplot (with a default 'weight' of 1) and sends a 
 231:      * {@link PlotChangeEvent} to all registered listeners.
 232:      * <P>
 233:      * The domain axis for the subplot will be set to <code>null</code>.
 234:      *
 235:      * @param subplot  the subplot (<code>null</code> not permitted).
 236:      */
 237:     public void add(XYPlot subplot) {
 238:         // defer argument checking
 239:         add(subplot, 1);
 240:     }
 241: 
 242:     /**
 243:      * Adds a subplot with the specified weight and sends a 
 244:      * {@link PlotChangeEvent} to all registered listeners.  The weight 
 245:      * determines how much space is allocated to the subplot relative to all 
 246:      * the other subplots.
 247:      * <P>
 248:      * The domain axis for the subplot will be set to <code>null</code>.
 249:      *
 250:      * @param subplot  the subplot (<code>null</code> not permitted).
 251:      * @param weight  the weight (must be >= 1).
 252:      */
 253:     public void add(XYPlot subplot, int weight) {
 254: 
 255:         if (subplot == null) {
 256:             throw new IllegalArgumentException("Null 'subplot' argument.");
 257:         }
 258:         if (weight <= 0) {
 259:             throw new IllegalArgumentException("Require weight >= 1.");
 260:         }
 261: 
 262:         // store the plot and its weight
 263:         subplot.setParent(this);
 264:         subplot.setWeight(weight);
 265:         subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0), false);
 266:         subplot.setDomainAxis(null);
 267:         subplot.addChangeListener(this);
 268:         this.subplots.add(subplot);
 269: 
 270:         // keep track of total weights
 271:         this.totalWeight += weight;
 272: 
 273:         ValueAxis axis = getDomainAxis();
 274:         if (axis != null) {
 275:             axis.configure();
 276:         }
 277:         
 278:         notifyListeners(new PlotChangeEvent(this));
 279: 
 280:     }
 281: 
 282:     /**
 283:      * Removes a subplot from the combined chart and sends a 
 284:      * {@link PlotChangeEvent} to all registered listeners.
 285:      *
 286:      * @param subplot  the subplot (<code>null</code> not permitted).
 287:      */
 288:     public void remove(XYPlot subplot) {
 289:         if (subplot == null) {
 290:             throw new IllegalArgumentException(" Null 'subplot' argument.");   
 291:         }
 292:         int position = -1;
 293:         int size = this.subplots.size();
 294:         int i = 0;
 295:         while (position == -1 && i < size) {
 296:             if (this.subplots.get(i) == subplot) {
 297:                 position = i;
 298:             }
 299:             i++;
 300:         }
 301:         if (position != -1) {
 302:             this.subplots.remove(position);
 303:             subplot.setParent(null);
 304:             subplot.removeChangeListener(this);
 305:             this.totalWeight -= subplot.getWeight();
 306: 
 307:             ValueAxis domain = getDomainAxis();
 308:             if (domain != null) {
 309:                 domain.configure();
 310:             }
 311:             notifyListeners(new PlotChangeEvent(this));
 312:         }
 313:     }
 314: 
 315:     /**
 316:      * Returns the list of subplots.
 317:      *
 318:      * @return An unmodifiable list of subplots.
 319:      */
 320:     public List getSubplots() {
 321:         return Collections.unmodifiableList(this.subplots);
 322:     }
 323: 
 324:     /**
 325:      * Calculates the axis space required.
 326:      * 
 327:      * @param g2  the graphics device.
 328:      * @param plotArea  the plot area.
 329:      * 
 330:      * @return The space.
 331:      */
 332:     protected AxisSpace calculateAxisSpace(Graphics2D g2, 
 333:                                            Rectangle2D plotArea) {
 334:         
 335:         AxisSpace space = new AxisSpace();
 336:         PlotOrientation orientation = getOrientation();
 337:         
 338:         // work out the space required by the domain axis...
 339:         AxisSpace fixed = getFixedDomainAxisSpace();
 340:         if (fixed != null) {
 341:             if (orientation == PlotOrientation.HORIZONTAL) {
 342:                 space.setLeft(fixed.getLeft());
 343:                 space.setRight(fixed.getRight());
 344:             }
 345:             else if (orientation == PlotOrientation.VERTICAL) {
 346:                 space.setTop(fixed.getTop());
 347:                 space.setBottom(fixed.getBottom());                
 348:             }
 349:         }
 350:         else {
 351:             ValueAxis xAxis = getDomainAxis();
 352:             RectangleEdge xEdge = Plot.resolveDomainAxisLocation(
 353:                 getDomainAxisLocation(), orientation
 354:             );
 355:             if (xAxis != null) {
 356:                 space = xAxis.reserveSpace(g2, this, plotArea, xEdge, space);
 357:             }
 358:         }
 359:         
 360:         Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);
 361:         
 362:         // work out the maximum height or width of the non-shared axes...
 363:         int n = this.subplots.size();
 364:         this.subplotAreas = new Rectangle2D[n];
 365:         double x = adjustedPlotArea.getX();
 366:         double y = adjustedPlotArea.getY();
 367:         double usableSize = 0.0;
 368:         if (orientation == PlotOrientation.HORIZONTAL) {
 369:             usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
 370:         }
 371:         else if (orientation == PlotOrientation.VERTICAL) {
 372:             usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
 373:         }
 374: 
 375:         for (int i = 0; i < n; i++) {
 376:             XYPlot plot = (XYPlot) this.subplots.get(i);
 377: 
 378:             // calculate sub-plot area
 379:             if (orientation == PlotOrientation.HORIZONTAL) {
 380:                 double w = usableSize * plot.getWeight() / this.totalWeight;
 381:                 this.subplotAreas[i] = new Rectangle2D.Double(
 382:                     x, y, w, adjustedPlotArea.getHeight()
 383:                 );
 384:                 x = x + w + this.gap;
 385:             }
 386:             else if (orientation == PlotOrientation.VERTICAL) {
 387:                 double h = usableSize * plot.getWeight() / this.totalWeight;
 388:                 this.subplotAreas[i] = new Rectangle2D.Double(
 389:                     x, y, adjustedPlotArea.getWidth(), h
 390:                 );
 391:                 y = y + h + this.gap;
 392:             }
 393: 
 394:             AxisSpace subSpace = plot.calculateRangeAxisSpace(
 395:                 g2, this.subplotAreas[i], null
 396:             );
 397:             space.ensureAtLeast(subSpace);
 398: 
 399:         }
 400: 
 401:         return space;
 402:     }
 403:     
 404:     /**
 405:      * Draws the plot within the specified area on a graphics device.
 406:      * 
 407:      * @param g2  the graphics device.
 408:      * @param area  the plot area (in Java2D space).
 409:      * @param anchor  an anchor point in Java2D space (<code>null</code> 
 410:      *                permitted).
 411:      * @param parentState  the state from the parent plot, if there is one 
 412:      *                     (<code>null</code> permitted).
 413:      * @param info  collects chart drawing information (<code>null</code> 
 414:      *              permitted).
 415:      */
 416:     public void draw(Graphics2D g2,
 417:                      Rectangle2D area,
 418:                      Point2D anchor,
 419:                      PlotState parentState,
 420:                      PlotRenderingInfo info) {
 421:         
 422:         // set up info collection...
 423:         if (info != null) {
 424:             info.setPlotArea(area);
 425:         }
 426: 
 427:         // adjust the drawing area for plot insets (if any)...
 428:         RectangleInsets insets = getInsets();
 429:         insets.trim(area);
 430: 
 431:         AxisSpace space = calculateAxisSpace(g2, area);
 432:         Rectangle2D dataArea = space.shrink(area, null);
 433: 
 434:         // set the width and height of non-shared axis of all sub-plots
 435:         setFixedRangeAxisSpaceForSubplots(space);
 436: 
 437:         // draw the shared axis
 438:         ValueAxis axis = getDomainAxis();
 439:         RectangleEdge edge = getDomainAxisEdge();
 440:         double cursor = RectangleEdge.coordinate(dataArea, edge);
 441:         AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info);
 442:         if (parentState == null) {
 443:             parentState = new PlotState();
 444:         }
 445:         parentState.getSharedAxisStates().put(axis, axisState);
 446:         
 447:         // draw all the subplots
 448:         for (int i = 0; i < this.subplots.size(); i++) {
 449:             XYPlot plot = (XYPlot) this.subplots.get(i);
 450:             PlotRenderingInfo subplotInfo = null;
 451:             if (info != null) {
 452:                 subplotInfo = new PlotRenderingInfo(info.getOwner());
 453:                 info.addSubplotInfo(subplotInfo);
 454:             }
 455:             plot.draw(
 456:                 g2, this.subplotAreas[i], anchor, parentState, subplotInfo
 457:             );
 458:         }
 459: 
 460:         if (info != null) {
 461:             info.setDataArea(dataArea);
 462:         }
 463:         
 464:     }
 465: 
 466:     /**
 467:      * Returns a collection of legend items for the plot.
 468:      *
 469:      * @return The legend items.
 470:      */
 471:     public LegendItemCollection getLegendItems() {        
 472:         LegendItemCollection result = getFixedLegendItems();
 473:         if (result == null) {
 474:             result = new LegendItemCollection();
 475:             if (this.subplots != null) {
 476:                 Iterator iterator = this.subplots.iterator();
 477:                 while (iterator.hasNext()) {
 478:                     XYPlot plot = (XYPlot) iterator.next();
 479:                     LegendItemCollection more = plot.getLegendItems();
 480:                     result.addAll(more);
 481:                 }
 482:             }
 483:         }
 484:         return result;
 485:     }
 486: 
 487:     /**
 488:      * Multiplies the range on the range axis/axes by the specified factor.
 489:      *
 490:      * @param factor  the zoom factor.
 491:      * @param info  the plot rendering info.
 492:      * @param source  the source point.
 493:      */
 494:     public void zoomRangeAxes(double factor, PlotRenderingInfo info, 
 495:                               Point2D source) {
 496:         XYPlot subplot = findSubplot(info, source);
 497:         if (subplot != null) {
 498:             subplot.zoomRangeAxes(factor, info, source);
 499:         }
 500:     }
 501: 
 502:     /**
 503:      * Zooms in on the range axes.
 504:      *
 505:      * @param lowerPercent  the lower bound.
 506:      * @param upperPercent  the upper bound.
 507:      * @param info  the plot rendering info.
 508:      * @param source  the source point.
 509:      */
 510:     public void zoomRangeAxes(double lowerPercent, double upperPercent, 
 511:                               PlotRenderingInfo info, Point2D source) {
 512:         XYPlot subplot = findSubplot(info, source);
 513:         if (subplot != null) {
 514:             subplot.zoomRangeAxes(lowerPercent, upperPercent, info, source);
 515:         }
 516:     }
 517: 
 518:     /**
 519:      * Returns the subplot (if any) that contains the (x, y) point (specified 
 520:      * in Java2D space).
 521:      * 
 522:      * @param info  the chart rendering info.
 523:      * @param source  the source point.
 524:      * 
 525:      * @return A subplot (possibly <code>null</code>).
 526:      */
 527:     public XYPlot findSubplot(PlotRenderingInfo info, Point2D source) {
 528:         XYPlot result = null;
 529:         int subplotIndex = info.getSubplotIndex(source);
 530:         if (subplotIndex >= 0) {
 531:             result =  (XYPlot) this.subplots.get(subplotIndex);
 532:         }
 533:         return result;
 534:     }
 535:     
 536:     /**
 537:      * Sets the item renderer FOR ALL SUBPLOTS.  Registered listeners are 
 538:      * notified that the plot has been modified.
 539:      * <P>
 540:      * Note: usually you will want to set the renderer independently for each 
 541:      * subplot, which is NOT what this method does.
 542:      *
 543:      * @param renderer the new renderer.
 544:      */
 545:     public void setRenderer(XYItemRenderer renderer) {
 546: 
 547:         super.setRenderer(renderer);  // not strictly necessary, since the 
 548:                                       // renderer set for the
 549:                                       // parent plot is not used
 550: 
 551:         Iterator iterator = this.subplots.iterator();
 552:         while (iterator.hasNext()) {
 553:             XYPlot plot = (XYPlot) iterator.next();
 554:             plot.setRenderer(renderer);
 555:         }
 556: 
 557:     }
 558: 
 559:     /**
 560:      * Sets the fixed range axis space.
 561:      *
 562:      * @param space  the space (<code>null</code> permitted).
 563:      */
 564:     public void setFixedRangeAxisSpace(AxisSpace space) {
 565:         super.setFixedRangeAxisSpace(space);
 566:         setFixedRangeAxisSpaceForSubplots(space);
 567:         this.notifyListeners(new PlotChangeEvent(this));
 568:     }
 569:     
 570:     /**
 571:      * Sets the size (width or height, depending on the orientation of the 
 572:      * plot) for the domain axis of each subplot.
 573:      *
 574:      * @param space  the space.
 575:      */
 576:     protected void setFixedRangeAxisSpaceForSubplots(AxisSpace space) {
 577: 
 578:         Iterator iterator = this.subplots.iterator();
 579:         while (iterator.hasNext()) {
 580:             XYPlot plot = (XYPlot) iterator.next();
 581:             plot.setFixedRangeAxisSpace(space);
 582:         }
 583: 
 584:     }
 585: 
 586:     /**
 587:      * Handles a 'click' on the plot by updating the anchor values.
 588:      *
 589:      * @param x  x-coordinate, where the click occured.
 590:      * @param y  y-coordinate, where the click occured.
 591:      * @param info  object containing information about the plot dimensions.
 592:      */
 593:     public void handleClick(int x, int y, PlotRenderingInfo info) {
 594:         Rectangle2D dataArea = info.getDataArea();
 595:         if (dataArea.contains(x, y)) {
 596:             for (int i = 0; i < this.subplots.size(); i++) {
 597:                 XYPlot subplot = (XYPlot) this.subplots.get(i);
 598:                 PlotRenderingInfo subplotInfo = info.getSubplotInfo(i);
 599:                 subplot.handleClick(x, y, subplotInfo);
 600:             }
 601:         }
 602:     }
 603:     
 604:     /**
 605:      * Receives a {@link PlotChangeEvent} and responds by notifying all 
 606:      * listeners.
 607:      * 
 608:      * @param event  the event.
 609:      */
 610:     public void plotChanged(PlotChangeEvent event) {
 611:         notifyListeners(event);
 612:     }
 613: 
 614:     /**
 615:      * Tests this plot for equality with another object.
 616:      *
 617:      * @param obj  the other object.
 618:      *
 619:      * @return <code>true</code> or <code>false</code>.
 620:      */
 621:     public boolean equals(Object obj) {
 622: 
 623:         if (obj == null) {
 624:             return false;
 625:         }
 626: 
 627:         if (obj == this) {
 628:             return true;
 629:         }
 630: 
 631:         if (!(obj instanceof CombinedDomainXYPlot)) {
 632:             return false;
 633:         }
 634:         if (!super.equals(obj)) {
 635:             return false;
 636:         }
 637: 
 638:         CombinedDomainXYPlot p = (CombinedDomainXYPlot) obj;
 639:         if (this.totalWeight != p.totalWeight) {
 640:             return false;
 641:         }
 642:         if (this.gap != p.gap) {
 643:             return false;
 644:         }
 645:         if (!ObjectUtilities.equal(this.subplots, p.subplots)) {
 646:             return false;
 647:         }
 648: 
 649:         return true;
 650:     }
 651:     
 652:     /**
 653:      * Returns a clone of the annotation.
 654:      * 
 655:      * @return A clone.
 656:      * 
 657:      * @throws CloneNotSupportedException  this class will not throw this 
 658:      *         exception, but subclasses (if any) might.
 659:      */
 660:     public Object clone() throws CloneNotSupportedException {
 661:         
 662:         CombinedDomainXYPlot result = (CombinedDomainXYPlot) super.clone(); 
 663:         result.subplots = (List) ObjectUtilities.deepClone(this.subplots);
 664:         for (Iterator it = result.subplots.iterator(); it.hasNext();) {
 665:             Plot child = (Plot) it.next();
 666:             child.setParent(result);
 667:         }
 668:         
 669:         // after setting up all the subplots, the shared domain axis may need 
 670:         // reconfiguring
 671:         ValueAxis domainAxis = result.getDomainAxis();
 672:         if (domainAxis != null) {
 673:             domainAxis.configure();
 674:         }
 675:         
 676:         return result;
 677:         
 678:     }
 679:     
 680: }