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: * FloatDimension.java
029: * -------------------
030: * (C)opyright 2002-2005, by Thomas Morgner and Contributors.
031: *
032: * Original Author: Thomas Morgner;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: FloatDimension.java,v 1.4 2005/11/03 09:26:51 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 05-Dec-2002 : Updated Javadocs (DG);
040: * 29-Apr-2003 : Moved to JCommon
041: *
042: */
043:
044: package org.jfree.ui;
045:
046: import java.awt.geom.Dimension2D;
047: import java.io.Serializable;
048:
049: /**
050: * A dimension object specified using <code>float</code> values.
051: *
052: * @author Thomas Morgner
053: */
054: public class FloatDimension extends Dimension2D implements Serializable {
055:
056: /** For serialization. */
057: private static final long serialVersionUID = 5367882923248086744L;
058:
059: /** The width. */
060: private float width;
061:
062: /** The height. */
063: private float height;
064:
065: /**
066: * Creates a new dimension object with width and height set to zero.
067: */
068: public FloatDimension() {
069: this .width = 0.0f;
070: this .height = 0.0f;
071: }
072:
073: /**
074: * Creates a new dimension that is a copy of another dimension.
075: *
076: * @param fd the dimension to copy.
077: */
078: public FloatDimension(final FloatDimension fd) {
079: this .width = fd.width;
080: this .height = fd.height;
081: }
082:
083: /**
084: * Creates a new dimension.
085: *
086: * @param width the width.
087: * @param height the height.
088: */
089: public FloatDimension(final float width, final float height) {
090: this .width = width;
091: this .height = height;
092: }
093:
094: /**
095: * Returns the width.
096: *
097: * @return the width.
098: */
099: public double getWidth() {
100: return this .width;
101: }
102:
103: /**
104: * Returns the height.
105: *
106: * @return the height.
107: */
108: public double getHeight() {
109: return this .height;
110: }
111:
112: /**
113: * Sets the width.
114: *
115: * @param width the width.
116: */
117: public void setWidth(final double width) {
118: this .width = (float) width;
119: }
120:
121: /**
122: * Sets the height.
123: *
124: * @param height the height.
125: */
126: public void setHeight(final double height) {
127: this .height = (float) height;
128: }
129:
130: /**
131: * Sets the size of this <code>Dimension</code> object to the specified
132: * width and height. This method is included for completeness, to parallel
133: * the {@link java.awt.Component#getSize() getSize} method of
134: * {@link java.awt.Component}.
135: *
136: * @param width the new width for the <code>Dimension</code> object
137: * @param height the new height for the <code>Dimension</code> object
138: */
139: public void setSize(final double width, final double height) {
140: setHeight((float) height);
141: setWidth((float) width);
142: }
143:
144: /**
145: * Creates and returns a copy of this object.
146: *
147: * @return a clone of this instance.
148: * @see java.lang.Cloneable
149: */
150: public Object clone() {
151: return super .clone();
152: }
153:
154: /**
155: * Returns a string representation of the object. In general, the
156: * <code>toString</code> method returns a string that
157: * "textually represents" this object. The result should
158: * be a concise but informative representation that is easy for a
159: * person to read.
160: * <p>
161: *
162: * @return a string representation of the object.
163: */
164: public String toString() {
165: return getClass().getName() + ":={width=" + getWidth()
166: + ", height=" + getHeight() + "}";
167: }
168:
169: /**
170: * Tests this object for equality with another object.
171: *
172: * @param o the other object.
173: *
174: * @return <code>true</code> or <code>false</code>.
175: */
176: public boolean equals(final Object o) {
177: if (this == o) {
178: return true;
179: }
180: if (!(o instanceof FloatDimension)) {
181: return false;
182: }
183:
184: final FloatDimension floatDimension = (FloatDimension) o;
185:
186: if (this .height != floatDimension.height) {
187: return false;
188: }
189: if (this .width != floatDimension.width) {
190: return false;
191: }
192:
193: return true;
194: }
195:
196: /**
197: * Returns a hash code.
198: *
199: * @return A hash code.
200: */
201: public int hashCode() {
202: int result;
203: result = Float.floatToIntBits(this .width);
204: result = 29 * result + Float.floatToIntBits(this.height);
205: return result;
206: }
207: }
|