File: FloatDimension.java

package info (click to toggle)
libbase 1.1.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 944 kB
  • sloc: java: 8,709; xml: 1,522; makefile: 18
file content (201 lines) | stat: -rw-r--r-- 4,626 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright (c) 2007 - 2009 Pentaho Corporation and Contributors.  All rights reserved.
 */

package org.pentaho.reporting.libraries.base.util;

import java.awt.geom.Dimension2D;
import java.io.Serializable;

/**
 * A dimension object specified using <code>float</code> values.
 *
 * @author Thomas Morgner
 */
public class FloatDimension extends Dimension2D implements Serializable
{

  /**
   * For serialization.
   */
  private static final long serialVersionUID = 5367882923248086744L;

  /**
   * The width.
   */
  private float width;

  /**
   * The height.
   */
  private float height;

  /**
   * Creates a new dimension object with width and height set to zero.
   */
  public FloatDimension()
  {
    this.width = 0.0f;
    this.height = 0.0f;
  }

  /**
   * Creates a new dimension that is a copy of another dimension.
   *
   * @param fd the dimension to copy.
   */
  public FloatDimension(final FloatDimension fd)
  {
    this.width = fd.width;
    this.height = fd.height;
  }

  /**
   * Creates a new dimension.
   *
   * @param width  the width.
   * @param height the height.
   */
  public FloatDimension(final float width, final float height)
  {
    this.width = width;
    this.height = height;
  }

  /**
   * Returns the width.
   *
   * @return the width.
   */
  public double getWidth()
  {
    return this.width;
  }

  /**
   * Returns the height.
   *
   * @return the height.
   */
  public double getHeight()
  {
    return this.height;
  }

  /**
   * Sets the width.
   *
   * @param width the width.
   */
  public void setWidth(final double width)
  {
    this.width = (float) width;
  }

  /**
   * Sets the height.
   *
   * @param height the height.
   */
  public void setHeight(final double height)
  {
    this.height = (float) height;
  }

  /**
   * Sets the size of this <code>Dimension</code> object to the specified width and height.  This method is included
   * for completeness, to parallel the {@link java.awt.Component#getSize() getSize} method of {@link
   * java.awt.Component}.
   *
   * @param width  the new width for the <code>Dimension</code> object
   * @param height the new height for the <code>Dimension</code> object
   */
  public void setSize(final double width, final double height)
  {
    setHeight((float) height);
    setWidth((float) width);
  }

  /**
   * Creates and returns a copy of this object.
   *
   * @return a clone of this instance.
   * @see Cloneable
   * @noinspection CloneDoesntDeclareCloneNotSupportedException
   */
  public Object clone()
  {
    return super.clone();
  }

  /**
   * Returns a string representation of the object. In general, the <code>toString</code> method returns a string that
   * "textually represents" this object. The result should be a concise but informative representation that is easy
   * for a person to read.
   * <p/>
   *
   * @return a string representation of the object.
   */
  public String toString()
  {
    return getClass().getName() + ":={width=" + getWidth() + ", height="
        + getHeight() + '}';
  }

  /**
   * Tests this object for equality with another object.
   *
   * @param o the other object.
   * @return <code>true</code> or <code>false</code>.
   */
  public boolean equals(final Object o)
  {
    if (this == o)
    {
      return true;
    }
    if (!(o instanceof FloatDimension))
    {
      return false;
    }

    final FloatDimension floatDimension = (FloatDimension) o;

    if (this.height != floatDimension.height)
    {
      return false;
    }
    if (this.width != floatDimension.width)
    {
      return false;
    }

    return true;
  }

  /**
   * Returns a hash code.
   *
   * @return A hash code.
   */
  public int hashCode()
  {
    int result;
    result = Float.floatToIntBits(this.width);
    result = 29 * result + Float.floatToIntBits(this.height);
    return result;
  }
}