001/* ======================================================
002 * JFreeChart : a chart library for the Java(tm) platform
003 * ======================================================
004 *
005 * (C) Copyright 2000-present, by David Gilbert and Contributors.
006 *
007 * Project Info:  https://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        /** The minimum domain range. */
058        private final Range minimumDomainRange;
059
060        /** The minimum range range. */
061        private final Range minimumRangeRange;
062        
063    /**
064     * Creates a new instance.
065     * 
066     * @param minimumDomainRange the range to ensure on the domain axis
067     *                           ({@code null} permitted).
068     * @param minimumRangeRange  the range to ensure on the range axis
069     *                           ({@code null} permitted).
070     */
071        public XYDataRangeAnnotation(Range minimumDomainRange, Range minimumRangeRange) {
072                this.minimumDomainRange = minimumDomainRange;
073                this.minimumRangeRange = minimumRangeRange;
074        }
075        
076        @Override
077        public boolean getIncludeInDataBounds() {
078                return true;
079        }
080
081        @Override
082        public Range getXRange() {
083                return minimumDomainRange;
084        }
085
086        @Override
087        public Range getYRange() {
088                return minimumRangeRange;
089        }
090
091        @Override
092        public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
093                        int rendererIndex, PlotRenderingInfo info) {
094                // Nothing to do here
095        }
096
097        @Override
098        public int hashCode() {
099                final int prime = 31;
100                int result = super.hashCode();
101                result = prime * result + ((minimumDomainRange == null) ? 0 : minimumDomainRange.hashCode());
102                result = prime * result + ((minimumRangeRange == null) ? 0 : minimumRangeRange.hashCode());
103                return result;
104        }
105
106        @Override
107        public boolean equals(Object obj) {
108                if (this == obj)
109                        return true;
110                if (!super.equals(obj))
111                        return false;
112                if (getClass() != obj.getClass())
113                        return false;
114                XYDataRangeAnnotation other = (XYDataRangeAnnotation) obj;
115                if (minimumDomainRange == null) {
116                        if (other.minimumDomainRange != null)
117                                return false;
118                } else if (!minimumDomainRange.equals(other.minimumDomainRange))
119                        return false;
120                if (minimumRangeRange == null) {
121                        if (other.minimumRangeRange != null)
122                                return false;
123                } else if (!minimumRangeRange.equals(other.minimumRangeRange))
124                        return false;
125                return true;
126        }
127}