FloatDimension.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. package org.jfree.ui;
  44. import java.awt.geom.Dimension2D;
  45. import java.io.Serializable;
  46. /**
  47. * A dimension object specified using <code>float</code> values.
  48. *
  49. * @author Thomas Morgner
  50. */
  51. public class FloatDimension extends Dimension2D
  52. implements Serializable {
  53. /** For serialization. */
  54. private static final long serialVersionUID = 5367882923248086744L;
  55. /** The width. */
  56. private float width;
  57. /** The height. */
  58. private float height;
  59. /**
  60. * Creates a new dimension object with width and height set to zero.
  61. */
  62. public FloatDimension() {
  63. this.width = 0.0f;
  64. this.height = 0.0f;
  65. }
  66. /**
  67. * Creates a new dimension that is a copy of another dimension.
  68. *
  69. * @param fd the dimension to copy.
  70. */
  71. public FloatDimension(final FloatDimension fd) {
  72. this.width = fd.width;
  73. this.height = fd.height;
  74. }
  75. /**
  76. * Creates a new dimension.
  77. *
  78. * @param width the width.
  79. * @param height the height.
  80. */
  81. public FloatDimension(final float width, final float height) {
  82. this.width = width;
  83. this.height = height;
  84. }
  85. /**
  86. * Returns the width.
  87. *
  88. * @return the width.
  89. */
  90. public double getWidth() {
  91. return this.width;
  92. }
  93. /**
  94. * Returns the height.
  95. *
  96. * @return the height.
  97. */
  98. public double getHeight() {
  99. return this.height;
  100. }
  101. /**
  102. * Sets the width.
  103. *
  104. * @param width the width.
  105. */
  106. public void setWidth(final double width) {
  107. this.width = (float) width;
  108. }
  109. /**
  110. * Sets the height.
  111. *
  112. * @param height the height.
  113. */
  114. public void setHeight(final double height) {
  115. this.height = (float) height;
  116. }
  117. /**
  118. * Sets the size of this <code>Dimension</code> object to the specified
  119. * width and height. This method is included for completeness, to parallel
  120. * the {@link java.awt.Component#getSize() getSize} method of
  121. * {@link java.awt.Component}.
  122. *
  123. * @param width the new width for the <code>Dimension</code> object
  124. * @param height the new height for the <code>Dimension</code> object
  125. */
  126. public void setSize(final double width, final double height) {
  127. setHeight((float) height);
  128. setWidth((float) width);
  129. }
  130. /**
  131. * Creates and returns a copy of this object.
  132. *
  133. * @return a clone of this instance.
  134. * @see java.lang.Cloneable
  135. */
  136. public Object clone() {
  137. return super.clone();
  138. }
  139. /**
  140. * Returns a string representation of the object. In general, the
  141. * <code>toString</code> method returns a string that
  142. * "textually represents" this object. The result should
  143. * be a concise but informative representation that is easy for a
  144. * person to read.
  145. * <p>
  146. *
  147. * @return a string representation of the object.
  148. */
  149. public String toString() {
  150. return getClass().getName() + ":={width=" + getWidth() + ", height="
  151. + getHeight() + "}";
  152. }
  153. /**
  154. * Tests this object for equality with another object.
  155. *
  156. * @param o the other object.
  157. *
  158. * @return <code>true</code> or <code>false</code>.
  159. */
  160. public boolean equals(final Object o) {
  161. if (this == o) {
  162. return true;
  163. }
  164. if (!(o instanceof FloatDimension)) {
  165. return false;
  166. }
  167. final FloatDimension floatDimension = (FloatDimension) o;
  168. if (this.height != floatDimension.height) {
  169. return false;
  170. }
  171. if (this.width != floatDimension.width) {
  172. return false;
  173. }
  174. return true;
  175. }
  176. /**
  177. * Returns a hash code.
  178. *
  179. * @return A hash code.
  180. */
  181. public int hashCode() {
  182. int result;
  183. result = Float.floatToIntBits(this.width);
  184. result = 29 * result + Float.floatToIntBits(this.height);
  185. return result;
  186. }
  187. }