001/* ========================================================================
002 * JCommon : a free general purpose class library for the Java(tm) platform
003 * ========================================================================
004 *
005 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006 * 
007 * Project Info:  http://www.jfree.org/jcommon/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 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025 * in the United States and other countries.]
026 * 
027 * -----------
028 * Size2D.java
029 * -----------
030 * (C) Copyright 2000-2005, by Object Refinery Limited.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   -;
034 *
035 * $Id: Size2D.java,v 1.8 2005/11/16 15:58:41 taqua Exp $
036 *
037 * Changes (from 26-Oct-2001)
038 * --------------------------
039 * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
040 * 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
041 * 10-Nov-2004 : Added default constructor, added setWidth() and setHeight() 
042 *               methods, added equals() method, implemented Cloneable, 
043 *               PublicCloneable and Serializable (DG);
044 * 02-Feb-2005 : Added toString() method (DG);
045 *
046 */
047
048package org.jfree.ui;
049
050import java.io.Serializable;
051
052import org.jfree.util.PublicCloneable;
053
054/**
055 * A simple class for representing the dimensions of an object.  It would be
056 * better to use <code>Dimension2D</code>, but this class is broken on various
057 * JDK releases (particularly JDK 1.3.1, refer to bugs 4189446 and 4976448 on 
058 * the Java bug parade).
059 *
060 * @author David Gilbert
061 */
062public class Size2D implements Cloneable, PublicCloneable, Serializable {
063
064    /** For serialization. */ 
065    private static final long serialVersionUID = 2558191683786418168L;
066    
067    /** The width. */
068    public double width;
069
070    /** The height. */
071    public double height;
072
073    /**
074     * Creates a new instance with zero width and height.
075     */
076    public Size2D() {
077        this(0.0, 0.0);
078    }
079    
080    /**
081     * Creates a new instance with the specified width and height.
082     *
083     * @param width  the width.
084     * @param height  the height.
085     */
086    public Size2D(final double width, final double height) {
087        this.width = width;
088        this.height = height;
089    }
090
091    /**
092     * Returns the width.
093     *
094     * @return The width.
095     */
096    public double getWidth() {
097        return this.width;
098    }
099    
100    /**
101     * Sets the width.
102     * 
103     * @param width  the width.
104     */
105    public void setWidth(final double width) {
106        this.width = width;
107    }
108
109    /**
110     * Returns the height.
111     *
112     * @return The height.
113     */
114    public double getHeight() {
115        return this.height;
116    }
117    
118    /**
119     * Sets the height.
120     * 
121     * @param height  the height.
122     */
123    public void setHeight(final double height) {
124        this.height = height;
125    }
126    
127    /**
128     * Returns a string representation of this instance, mostly used for 
129     * debugging purposes.
130     * 
131     * @return A string.
132     */
133    public String toString() {
134        return "Size2D[width=" + this.width + ", height=" + this.height + "]";   
135    }
136
137    /**
138     * Compares this instance for equality with an arbitrary object.
139     * 
140     * @param obj  the object (<code>null</code> permitted).
141     * 
142     * @return A boolean.
143     */
144    public boolean equals(final Object obj) {
145        if (this == obj) {
146            return true;
147        }
148        if (!(obj instanceof Size2D)) {
149            return false;
150        }
151        final Size2D that = (Size2D) obj;
152        if (this.width != that.width) {
153            return false;
154        }
155        if (this.height != that.height) {
156            return false;
157        }
158        return true;
159    }
160    
161    /**
162     * Returns a clone of this object.
163     * 
164     * @return A clone.
165     * 
166     * @throws CloneNotSupportedException if the object cannot be cloned.
167     */
168    public Object clone() throws CloneNotSupportedException {
169        return super.clone();
170    }
171    
172}