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
029package org.jfree.chart.ui;
030
031import java.io.Serializable;
032import org.jfree.chart.util.PublicCloneable;
033
034/**
035 * A simple class for representing the dimensions of an object.  It would be
036 * better to use {@code Dimension2D}, but this class is broken on various
037 * JDK releases (particularly JDK 1.3.1, refer to bugs 4189446 and 4976448 on 
038 * the Java bug parade).
039 */
040public class Size2D implements Cloneable, PublicCloneable, Serializable {
041
042    /** For serialization. */ 
043    private static final long serialVersionUID = 2558191683786418168L;
044    
045    /** The width. */
046    public double width;
047
048    /** The height. */
049    public double height;
050
051    /**
052     * Creates a new instance with zero width and height.
053     */
054    public Size2D() {
055        this(0.0, 0.0);
056    }
057    
058    /**
059     * Creates a new instance with the specified width and height.
060     *
061     * @param width  the width.
062     * @param height  the height.
063     */
064    public Size2D(double width, double height) {
065        this.width = width;
066        this.height = height;
067    }
068
069    /**
070     * Returns the width.
071     *
072     * @return The width.
073     */
074    public double getWidth() {
075        return this.width;
076    }
077    
078    /**
079     * Sets the width.
080     * 
081     * @param width  the width.
082     */
083    public void setWidth(double width) {
084        this.width = width;
085    }
086
087    /**
088     * Returns the height.
089     *
090     * @return The height.
091     */
092    public double getHeight() {
093        return this.height;
094    }
095    
096    /**
097     * Sets the height.
098     * 
099     * @param height  the height.
100     */
101    public void setHeight(double height) {
102        this.height = height;
103    }
104    
105    /**
106     * Returns a string representation of this instance, mostly used for 
107     * debugging purposes.
108     * 
109     * @return A string.
110     */
111    @Override
112    public String toString() {
113        return "Size2D[width=" + this.width + ", height=" + this.height + "]";   
114    }
115
116    /**
117     * Compares this instance for equality with an arbitrary object.
118     * 
119     * @param obj  the object ({@code null} permitted).
120     * 
121     * @return A boolean.
122     */
123    @Override
124    public boolean equals(Object obj) {
125        if (this == obj) {
126            return true;
127        }
128        if (!(obj instanceof Size2D)) {
129            return false;
130        }
131        Size2D that = (Size2D) obj;
132        if (this.width != that.width) {
133            return false;
134        }
135        if (this.height != that.height) {
136            return false;
137        }
138        return true;
139    }
140
141    @Override
142    public int hashCode() {
143        int hash = 5;
144        hash = 29 * hash + (int) (Double.doubleToLongBits(this.width) ^ (Double.doubleToLongBits(this.width) >>> 32));
145        hash = 29 * hash + (int) (Double.doubleToLongBits(this.height) ^ (Double.doubleToLongBits(this.height) >>> 32));
146        return hash;
147    }
148    
149    /**
150     * Returns a clone of this object.
151     * 
152     * @return A clone.
153     * 
154     * @throws CloneNotSupportedException if the object cannot be cloned.
155     */
156    @Override
157    public Object clone() throws CloneNotSupportedException {
158        return super.clone();
159    }
160    
161}