Source for org.jfree.ui.Size2D

   1: /* ========================================================================
   2:  * JCommon : a free general purpose class library for the Java(tm) platform
   3:  * ========================================================================
   4:  *
   5:  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
   6:  * 
   7:  * Project Info:  http://www.jfree.org/jcommon/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:  * Size2D.java
  29:  * -----------
  30:  * (C) Copyright 2000-2005, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: Size2D.java,v 1.8 2005/11/16 15:58:41 taqua Exp $
  36:  *
  37:  * Changes (from 26-Oct-2001)
  38:  * --------------------------
  39:  * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
  40:  * 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  41:  * 10-Nov-2004 : Added default constructor, added setWidth() and setHeight() 
  42:  *               methods, added equals() method, implemented Cloneable, 
  43:  *               PublicCloneable and Serializable (DG);
  44:  * 02-Feb-2005 : Added toString() method (DG);
  45:  *
  46:  */
  47: 
  48: package org.jfree.ui;
  49: 
  50: import java.io.Serializable;
  51: 
  52: import org.jfree.util.PublicCloneable;
  53: 
  54: /**
  55:  * A simple class for representing the dimensions of an object.  It would be
  56:  * better to use <code>Dimension2D</code>, but this class is broken on various
  57:  * JDK releases (particularly JDK 1.3.1, refer to bugs 4189446 and 4976448 on 
  58:  * the Java bug parade).
  59:  *
  60:  * @author David Gilbert
  61:  */
  62: public class Size2D implements Cloneable, PublicCloneable, Serializable {
  63: 
  64:     /** For serialization. */ 
  65:     private static final long serialVersionUID = 2558191683786418168L;
  66:     
  67:     /** The width. */
  68:     public double width;
  69: 
  70:     /** The height. */
  71:     public double height;
  72: 
  73:     /**
  74:      * Creates a new instance with zero width and height.
  75:      */
  76:     public Size2D() {
  77:         this(0.0, 0.0);
  78:     }
  79:     
  80:     /**
  81:      * Creates a new instance with the specified width and height.
  82:      *
  83:      * @param width  the width.
  84:      * @param height  the height.
  85:      */
  86:     public Size2D(final double width, final double height) {
  87:         this.width = width;
  88:         this.height = height;
  89:     }
  90: 
  91:     /**
  92:      * Returns the width.
  93:      *
  94:      * @return The width.
  95:      */
  96:     public double getWidth() {
  97:         return this.width;
  98:     }
  99:     
 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: }