13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package org.jemmy;
26
27
28 import java.io.Serializable;
29
30
31 /**
32 * Replacement for java.awt.Dimension
33 * @author Alexander Kouznetsov <mrkam@mail.ru>
34 */
35 public class Dimension implements Serializable {
36
37 /**
38 * The width dimension; negative values can be used.
39 *
40 * @serial
41 * @see #getSize
42 * @see #setSize
43 */
44 public int width;
45
46 /**
47 * The height dimension; negative values can be used.
48 *
49 * @serial
50 * @see #getSize
51 * @see #setSize
52 */
53 public int height;
87 public Dimension(int width, int height) {
88 this.width = width;
89 this.height = height;
90 }
91
92 /**
93 * Constructs a <code>Dimension</code> and initializes
94 * it to the specified width and specified height. All {@code double}
95 * values are rounded and stored as {@code int} values.
96 *
97 * @param width the specified width
98 * @param height the specified height
99 */
100 public Dimension(double width, double height) {
101 this.width = (int) Math.round(width);
102 this.height = (int) Math.round(height);
103 }
104
105 /**
106 * {@inheritDoc}
107 * @return
108 */
109 public double getWidth() {
110 return width;
111 }
112
113 /**
114 * {@inheritDoc}
115 * @return
116 */
117 public double getHeight() {
118 return height;
119 }
120
121 /**
122 * Sets the size of this <code>Dimension</code> object to
123 * the specified width and height in double precision.
124 * Note that if <code>width</code> or <code>height</code>
125 * are larger than <code>Integer.MAX_VALUE</code>, they will
126 * be reset to <code>Integer.MAX_VALUE</code>.
127 *
128 * @param width the new width for the <code>Dimension</code> object
129 * @param height the new height for the <code>Dimension</code> object
130 */
131 public void setSize(double width, double height) {
132 this.width = (int) Math.ceil(width);
133 this.height = (int) Math.ceil(height);
134 }
135
147 * Sets the size of this <code>Dimension</code> object to the specified size.
148 * @param d the new size for this <code>Dimension</code> object
149 * @see Dimension#getSize
150 */
151 public void setSize(Dimension d) {
152 setSize(d.width, d.height);
153 }
154
155 /**
156 * Sets the size of this <code>Dimension</code> object
157 * to the specified width and height.
158 * @param width the new width for this <code>Dimension</code> object
159 * @param height the new height for this <code>Dimension</code> object
160 * @see Dimension#getSize
161 */
162 public void setSize(int width, int height) {
163 this.width = width;
164 this.height = height;
165 }
166
167 /**
168 * Checks whether two dimension objects have equal values.
169 * @param obj
170 * @return
171 */
172 @Override
173 public boolean equals(Object obj) {
174 if (obj instanceof Dimension) {
175 Dimension d = (Dimension)obj;
176 return (width == d.width) && (height == d.height);
177 }
178 return false;
179 }
180
181 /**
182 * Returns the hash code for this <code>Dimension</code>.
183 *
184 * @return a hash code for this <code>Dimension</code>
185 */
186 @Override
187 public int hashCode() {
188 int sum = width + height;
189 return sum * (sum + 1)/2 + width;
190 }
191
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package org.jemmy;
26
27
28 import java.io.Serializable;
29
30
31 /**
32 * Replacement for java.awt.Dimension
33 * @author mrkam
34 */
35 public class Dimension implements Serializable {
36
37 /**
38 * The width dimension; negative values can be used.
39 *
40 * @serial
41 * @see #getSize
42 * @see #setSize
43 */
44 public int width;
45
46 /**
47 * The height dimension; negative values can be used.
48 *
49 * @serial
50 * @see #getSize
51 * @see #setSize
52 */
53 public int height;
87 public Dimension(int width, int height) {
88 this.width = width;
89 this.height = height;
90 }
91
92 /**
93 * Constructs a <code>Dimension</code> and initializes
94 * it to the specified width and specified height. All {@code double}
95 * values are rounded and stored as {@code int} values.
96 *
97 * @param width the specified width
98 * @param height the specified height
99 */
100 public Dimension(double width, double height) {
101 this.width = (int) Math.round(width);
102 this.height = (int) Math.round(height);
103 }
104
105 /**
106 * {@inheritDoc}
107 */
108 public double getWidth() {
109 return width;
110 }
111
112 /**
113 * {@inheritDoc}
114 */
115 public double getHeight() {
116 return height;
117 }
118
119 /**
120 * Sets the size of this <code>Dimension</code> object to
121 * the specified width and height in double precision.
122 * Note that if <code>width</code> or <code>height</code>
123 * are larger than <code>Integer.MAX_VALUE</code>, they will
124 * be reset to <code>Integer.MAX_VALUE</code>.
125 *
126 * @param width the new width for the <code>Dimension</code> object
127 * @param height the new height for the <code>Dimension</code> object
128 */
129 public void setSize(double width, double height) {
130 this.width = (int) Math.ceil(width);
131 this.height = (int) Math.ceil(height);
132 }
133
145 * Sets the size of this <code>Dimension</code> object to the specified size.
146 * @param d the new size for this <code>Dimension</code> object
147 * @see Dimension#getSize
148 */
149 public void setSize(Dimension d) {
150 setSize(d.width, d.height);
151 }
152
153 /**
154 * Sets the size of this <code>Dimension</code> object
155 * to the specified width and height.
156 * @param width the new width for this <code>Dimension</code> object
157 * @param height the new height for this <code>Dimension</code> object
158 * @see Dimension#getSize
159 */
160 public void setSize(int width, int height) {
161 this.width = width;
162 this.height = height;
163 }
164
165 @Override
166 public boolean equals(Object obj) {
167 if (obj instanceof Dimension) {
168 Dimension d = (Dimension)obj;
169 return (width == d.width) && (height == d.height);
170 }
171 return false;
172 }
173
174 /**
175 * Returns the hash code for this <code>Dimension</code>.
176 *
177 * @return a hash code for this <code>Dimension</code>
178 */
179 @Override
180 public int hashCode() {
181 int sum = width + height;
182 return sum * (sum + 1)/2 + width;
183 }
184
|