KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > print > layout > Dimension2DImpl


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.print.layout;
15
16 import java.awt.*;
17 import java.awt.geom.*;
18
19 /**
20  * 2D Dimesnion Implementation
21  *
22  * @author Jorg Janke
23  * @version $Id: Dimension2DImpl.java,v 1.6 2003/01/04 05:27:15 jjanke Exp $
24  */

25 public class Dimension2DImpl extends Dimension2D
26 {
27     /**
28      * Constructor 0/0
29      */

30     public Dimension2DImpl()
31     {
32     } // Dimension2DImpl
33

34     /**
35      * Constructor 0/0
36      * @param dim dimension
37      */

38     public Dimension2DImpl(Dimension dim)
39     {
40         setSize (dim);
41     } // Dimension2DImpl
42

43     /**
44      * Constructor 0/0
45      * @param width width
46      * @param height height
47      */

48     public Dimension2DImpl(double width, double height)
49     {
50         setSize (width, height);
51     } // Dimension2DImpl
52

53     /** Width */
54     public double width = 0;
55     /** Height */
56     public double height = 0;
57
58     /**
59      * Set Size
60      * @param width width
61      * @param height height
62      */

63     public void setSize (double width, double height)
64     {
65         this.width = width;
66         this.height = height;
67     } // setSize
68

69     /**
70      * Set Size
71      * @param dim dimension
72      */

73     public void setSize (Dimension dim)
74     {
75         this.width = dim.getWidth();
76         this.height = dim.getHeight();
77     } // setSize
78

79     /**
80      * Add Size below existing
81      * @param width width to increase if below
82      * @param height height to add
83      */

84     public void addBelow (double width, double height)
85     {
86         if (this.width < width)
87             this.width = width;
88         this.height += height;
89     } // addBelow
90

91     /**
92      * Add Size below existing
93      * @param dim add dimension
94      */

95     public void addBelow (Dimension dim)
96     {
97         addBelow (dim.width, dim.height);
98     } // addBelow
99

100     /**
101      * Round to next Int value
102      */

103     public void roundUp()
104     {
105         width = Math.ceil(width);
106         height = Math.ceil(height);
107     } // roundUp
108

109
110     /**
111      * Get Width
112      * @return width
113      */

114     public double getWidth()
115     {
116         return width;
117     } // getWidth
118

119     /**
120      * Get Height
121      * @return height
122      */

123     public double getHeight()
124     {
125         return height;
126     } // getHeight
127

128     /*************************************************************************/
129
130     /**
131      * Hash Code
132      * @return hash code
133      */

134     public int hashCode()
135     {
136         long bits = Double.doubleToLongBits(width);
137         bits ^= Double.doubleToLongBits(height) * 31;
138         return (((int) bits) ^ ((int) (bits >> 32)));
139     } // hashCode
140

141     /**
142      * Equals
143      * @param obj object
144      * @return true if w/h is same
145      */

146     public boolean equals (Object JavaDoc obj)
147     {
148         if (obj != null && obj instanceof Dimension2D)
149         {
150             Dimension2D d = (Dimension2D)obj;
151             if (d.getWidth() == width && d.getHeight() == height)
152                 return true;
153         }
154         return false;
155     } // equals
156

157     /**
158      * String Representation
159      * @return info
160      */

161     public String JavaDoc toString()
162     {
163         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
164         sb.append("Dimension2D[w=").append(width).append(",h=").append(height).append("]");
165         return sb.toString();
166     } // toString
167

168 } // Dimension2DImpl
169
Popular Tags