KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > images > Dimension


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util.images;
11
12 /**
13  * Represents the `dimension' of an image, i.e. its height and width.
14  *
15  * @author Michiel Meeuwissen
16  * @since MMBase-1.7.4
17  */

18
19
20 public class Dimension {
21
22     public static final Dimension UNDETERMINED = new Dimension(-1, -1);
23     protected int x;
24     protected int y;
25
26     protected Dimension() {
27     }
28     public Dimension(int x, int y) {
29         this.x = x;
30         this.y = y;
31     }
32     public Dimension(Dimension dim) {
33         this.x = dim.x;
34         this.y = dim.y;
35     }
36
37     public int getWidth() {
38         return x;
39     }
40     public int getHeight() {
41         return y;
42     }
43
44     public int getArea() {
45         return x * y;
46     }
47     
48     public String JavaDoc toString() {
49         return "" + x + "x" + y;
50     }
51     public boolean equals(Object JavaDoc o) {
52         if (o instanceof Dimension) {
53             Dimension dim = (Dimension) o;
54             return dim.x == x && dim.y == y;
55         } else {
56             return false;
57         }
58     }
59     public int hashCode() {
60         return (x + 1) * (y + 1);
61     }
62     /**
63      * Returns true of both x and y > 0.
64      * @since MMBase-1.8.1
65      */

66     public boolean valid() {
67         return x > 0 && y > 0;
68     }
69
70 }
71
Popular Tags