001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Denis M. Kishenko
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.geom.Dimension2D;
023: import java.io.Serializable;
024:
025: import org.apache.harmony.misc.HashCode;
026:
027: public class Dimension extends Dimension2D implements Serializable {
028:
029: private static final long serialVersionUID = 4723952579491349524L;
030:
031: public int width;
032: public int height;
033:
034: public Dimension(Dimension d) {
035: this (d.width, d.height);
036: }
037:
038: public Dimension() {
039: this (0, 0);
040: }
041:
042: public Dimension(int width, int height) {
043: setSize(width, height);
044: }
045:
046: @Override
047: public int hashCode() {
048: HashCode hash = new HashCode();
049: hash.append(width);
050: hash.append(height);
051: return hash.hashCode();
052: }
053:
054: @Override
055: public boolean equals(Object obj) {
056: if (obj == this ) {
057: return true;
058: }
059: if (obj instanceof Dimension) {
060: Dimension d = (Dimension) obj;
061: return (d.width == width && d.height == height);
062: }
063: return false;
064: }
065:
066: @Override
067: public String toString() {
068: // The output format based on 1.5 release behaviour. It could be obtained in the following way
069: // System.out.println(new Dimension().toString())
070: return getClass().getName()
071: + "[width=" + width + ",height=" + height + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
072: }
073:
074: public void setSize(int width, int height) {
075: this .width = width;
076: this .height = height;
077: }
078:
079: public void setSize(Dimension d) {
080: setSize(d.width, d.height);
081: }
082:
083: @Override
084: public void setSize(double width, double height) {
085: setSize((int) Math.ceil(width), (int) Math.ceil(height));
086: }
087:
088: public Dimension getSize() {
089: return new Dimension(width, height);
090: }
091:
092: @Override
093: public double getHeight() {
094: return height;
095: }
096:
097: @Override
098: public double getWidth() {
099: return width;
100: }
101:
102: }
|