KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > FloatDimension


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  * FloatDimension.java
29  * -------------------
30  * (C)opyright 2002-2005, by Thomas Morgner and Contributors.
31  *
32  * Original Author: Thomas Morgner;
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: FloatDimension.java,v 1.4 2005/11/03 09:26:51 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 05-Dec-2002 : Updated Javadocs (DG);
40  * 29-Apr-2003 : Moved to JCommon
41  *
42  */

43
44 package org.jfree.ui;
45
46 import java.awt.geom.Dimension2D JavaDoc;
47 import java.io.Serializable JavaDoc;
48
49 /**
50  * A dimension object specified using <code>float</code> values.
51  *
52  * @author Thomas Morgner
53  */

54 public class FloatDimension extends Dimension2D JavaDoc
55                             implements Serializable JavaDoc {
56
57     /** For serialization. */
58     private static final long serialVersionUID = 5367882923248086744L;
59     
60     /** The width. */
61     private float width;
62
63     /** The height. */
64     private float height;
65
66     /**
67      * Creates a new dimension object with width and height set to zero.
68      */

69     public FloatDimension() {
70         this.width = 0.0f;
71         this.height = 0.0f;
72     }
73
74     /**
75      * Creates a new dimension that is a copy of another dimension.
76      *
77      * @param fd the dimension to copy.
78      */

79     public FloatDimension(final FloatDimension fd) {
80         this.width = fd.width;
81         this.height = fd.height;
82     }
83
84     /**
85      * Creates a new dimension.
86      *
87      * @param width the width.
88      * @param height the height.
89      */

90     public FloatDimension(final float width, final float height) {
91         this.width = width;
92         this.height = height;
93     }
94
95     /**
96      * Returns the width.
97      *
98      * @return the width.
99      */

100     public double getWidth() {
101         return this.width;
102     }
103
104     /**
105      * Returns the height.
106      *
107      * @return the height.
108      */

109     public double getHeight() {
110         return this.height;
111     }
112
113     /**
114      * Sets the width.
115      *
116      * @param width the width.
117      */

118     public void setWidth(final double width) {
119         this.width = (float) width;
120     }
121
122     /**
123      * Sets the height.
124      *
125      * @param height the height.
126      */

127     public void setHeight(final double height) {
128         this.height = (float) height;
129     }
130
131     /**
132      * Sets the size of this <code>Dimension</code> object to the specified
133      * width and height. This method is included for completeness, to parallel
134      * the {@link java.awt.Component#getSize() getSize} method of
135      * {@link java.awt.Component}.
136      *
137      * @param width the new width for the <code>Dimension</code> object
138      * @param height the new height for the <code>Dimension</code> object
139      */

140     public void setSize(final double width, final double height) {
141         setHeight((float) height);
142         setWidth((float) width);
143     }
144
145     /**
146      * Creates and returns a copy of this object.
147      *
148      * @return a clone of this instance.
149      * @see java.lang.Cloneable
150      */

151     public Object JavaDoc clone() {
152         return super.clone();
153     }
154
155     /**
156      * Returns a string representation of the object. In general, the
157      * <code>toString</code> method returns a string that
158      * "textually represents" this object. The result should
159      * be a concise but informative representation that is easy for a
160      * person to read.
161      * <p>
162      *
163      * @return a string representation of the object.
164      */

165     public String JavaDoc toString() {
166         return getClass().getName() + ":={width=" + getWidth() + ", height="
167                 + getHeight() + "}";
168     }
169
170     /**
171      * Tests this object for equality with another object.
172      *
173      * @param o the other object.
174      *
175      * @return <code>true</code> or <code>false</code>.
176      */

177     public boolean equals(final Object JavaDoc o) {
178         if (this == o) {
179             return true;
180         }
181         if (!(o instanceof FloatDimension)) {
182             return false;
183         }
184
185         final FloatDimension floatDimension = (FloatDimension) o;
186
187         if (this.height != floatDimension.height) {
188             return false;
189         }
190         if (this.width != floatDimension.width) {
191             return false;
192         }
193
194         return true;
195     }
196
197     /**
198      * Returns a hash code.
199      *
200      * @return A hash code.
201      */

202     public int hashCode() {
203         int result;
204         result = Float.floatToIntBits(this.width);
205         result = 29 * result + Float.floatToIntBits(this.height);
206         return result;
207     }
208 }
209
210
Popular Tags