001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-present, by David Gilbert and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022 * USA.
023 *
024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * --------------------------
028 * XYDataRangeAnnotation.java
029 * --------------------------
030 * (C) Copyright 2021-present, by Yuri Blankenstein and Contributors.
031 *
032 * Original Author:  Yuri Blankenstein (for ESI TNO);
033 *
034 */
035package org.jfree.chart.annotations;
036
037import java.awt.Graphics2D;
038import java.awt.geom.Rectangle2D;
039
040import org.jfree.chart.axis.ValueAxis;
041import org.jfree.chart.plot.PlotRenderingInfo;
042import org.jfree.chart.plot.XYPlot;
043import org.jfree.data.Range;
044
045/**
046 * This annotation can be put on an {@link XYPlot} to ensure a visible data
047 * range. The range values should be specified w.r.t. to the first (index 0)
048 * domain or range axis.
049 *
050 * @see XYPlot#getDataRange(ValueAxis)
051 * @see XYPlot#getDomainAxis()
052 * @see XYPlot#getRangeAxis()
053 */
054public class XYDataRangeAnnotation extends AbstractXYAnnotation implements XYAnnotationBoundsInfo {
055        private static final long serialVersionUID = 2058170262687146829L;
056
057        private final Range minimumDomainRange;
058        private final Range minimumRangeRange;
059        
060    /**
061     * Creates a new instance.
062     * 
063     * @param minimumDomainRange the range to ensure on the domain axis
064     *                           ({@code null} permitted).
065     * @param minimumRangeRange  the range to ensure on the range axis
066     *                           ({@code null} permitted).
067     */
068        public XYDataRangeAnnotation(Range minimumDomainRange, Range minimumRangeRange) {
069                this.minimumDomainRange = minimumDomainRange;
070                this.minimumRangeRange = minimumRangeRange;
071        }
072        
073        @Override
074        public boolean getIncludeInDataBounds() {
075                return true;
076        }
077
078        @Override
079        public Range getXRange() {
080                return minimumDomainRange;
081        }
082
083        @Override
084        public Range getYRange() {
085                return minimumRangeRange;
086        }
087
088        @Override
089        public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
090                        int rendererIndex, PlotRenderingInfo info) {
091                // Nothing to do here
092        }
093
094        @Override
095        public int hashCode() {
096                final int prime = 31;
097                int result = super.hashCode();
098                result = prime * result + ((minimumDomainRange == null) ? 0 : minimumDomainRange.hashCode());
099                result = prime * result + ((minimumRangeRange == null) ? 0 : minimumRangeRange.hashCode());
100                return result;
101        }
102
103        @Override
104        public boolean equals(Object obj) {
105                if (this == obj)
106                        return true;
107                if (!super.equals(obj))
108                        return false;
109                if (getClass() != obj.getClass())
110                        return false;
111                XYDataRangeAnnotation other = (XYDataRangeAnnotation) obj;
112                if (minimumDomainRange == null) {
113                        if (other.minimumDomainRange != null)
114                                return false;
115                } else if (!minimumDomainRange.equals(other.minimumDomainRange))
116                        return false;
117                if (minimumRangeRange == null) {
118                        if (other.minimumRangeRange != null)
119                                return false;
120                } else if (!minimumRangeRange.equals(other.minimumRangeRange))
121                        return false;
122                return true;
123        }
124}