source: trunk/src/gcc/libjava/java/awt/Dimension.java@ 154

Last change on this file since 154 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.0 KB
Line 
1/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
2
3This file is part of GNU Classpath.
4
5GNU Classpath is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2, or (at your option)
8any later version.
9
10GNU Classpath is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with GNU Classpath; see the file COPYING. If not, write to the
17Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1802111-1307 USA.
19
20Linking this library statically or dynamically with other modules is
21making a combined work based on this library. Thus, the terms and
22conditions of the GNU General Public License cover the whole
23combination.
24
25As a special exception, the copyright holders of this library give you
26permission to link this library with independent modules to produce an
27executable, regardless of the license terms of these independent
28modules, and to copy and distribute the resulting executable under
29terms of your choice, provided that you also meet, for each linked
30independent module, the terms and conditions of the license of that
31module. An independent module is a module which is not derived from
32or based on this library. If you modify this library, you may extend
33this exception to your version of the library, but you are not
34obligated to do so. If you do not wish to do so, delete this
35exception statement from your version. */
36
37
38package java.awt;
39
40/* Written using "Java Class Libraries", 2nd edition, plus online
41 * API docs for JDK 1.2 beta from http://www.javasoft.com.
42 * Status: Believed complete and correct, except that neither toString
43 * has not been compared with JDK output.
44 */
45
46/**
47 * This class holds a width and height value pair.
48 *
49 * @author Per Bothner <[email protected]>
50 * @author Aaron M. Renn ([email protected])
51 * @date Fenruary 8, 1999.
52 */
53public class Dimension extends java.awt.geom.Dimension2D
54 implements java.io.Serializable
55{
56 /**
57 * This width of this object.
58 */
59 public int width;
60
61 /**
62 * The height of this object.
63 */
64 public int height;
65
66 /**
67 * Initializes a new instance of <code>Dimension</code> with a width
68 * and height of zero.
69 */
70 public Dimension () { }
71
72 /**
73 * Initializes a new instance of <code>Dimension</code> to have a width
74 * and height identical to that of the specified dimension object.
75 *
76 * @param dim The <code>Dimension</code> to take the width and height from.
77 */
78 public Dimension (Dimension dim)
79 {
80 this.width = dim.width;
81 this.height = dim.height;
82 }
83
84 /**
85 * Initializes a new instance of <code>Dimension</code> with the
86 * specified width and height.
87 *
88 * @param width The width of this object.
89 * @param height The height of this object.
90 */
91 public Dimension (int width, int height)
92 {
93 this.width = width;
94 this.height = height;
95 }
96
97 /**
98 * Tests this object for equality against the specified object. This will
99 * be true if and only if the specified object:
100 * <p>
101 * <ul>
102 * <li>Is not <code>null</code>.
103 * <li>Is an instance of <code>Dimension</code>.
104 * <li>Has width and height values identical to this object.
105 * </ul>
106 *
107 * @param obj The object to test against.
108 *
109 * @return <code>true</code> if the specified object is equal to this
110 * object, <code>false</code> otherwise.
111 */
112 public boolean equals (Object obj)
113 {
114 if (! (obj instanceof Dimension))
115 return false;
116 Dimension dim = (Dimension) obj;
117 return height == dim.height && width == dim.width;
118 }
119
120 /**
121 * Returns the size of this object. Not very useful.
122 *
123 * @return This object.
124 */
125 public Dimension getSize () { return new Dimension(this); }
126
127 /**
128 * Sets the width and height of this object to match that of the
129 * specified object.
130 *
131 * @param dim The <code>Dimension</code> object to get the new width and
132 * height from.
133 */
134 public void setSize (Dimension dim)
135 {
136 this.width = dim.width;
137 this.height = dim.height;
138 }
139
140 /**
141 * Sets the width and height of this object to the specified values.
142 *
143 * @param width The new width value.
144 * @param height The new height value.
145 */
146 public void setSize (int width, int height)
147 {
148 this.width = width;
149 this.height = height;
150 }
151
152 /**
153 * Returns a string representation of this object.
154 *
155 * @return A string representation of this object.
156 */
157 public String toString ()
158 {
159 return "Dimension[w:"+width+",h:"+height+']';
160 }
161
162 /* Note: There is no Dimension.hashCode. */
163
164 public double getWidth() { return width; }
165 public double getHeight() { return height; }
166
167 public void setSize (double width, double height)
168 {
169 this.width = (int) width;
170 this.height = (int) height;
171 }
172}
Note: See TracBrowser for help on using the repository browser.