]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/PixelDimension.java
Implement ImageDescriptor.getImageData(int zoom)
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / gfx / PixelDimension.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  * 10.10.2006
14  */
15 package org.simantics.utils.ui.gfx;
16
17 import java.awt.Dimension;
18
19
20 /**
21  * PixelDimension
22  * 
23  * @author Toni Kalajainen
24  */
25 public class PixelDimension {
26
27     public final int width;
28
29     public final int height;
30
31     public PixelDimension(int width, int height) {
32         this.width = width;
33         this.height = height;
34     }
35
36     public PixelDimension(PixelDimension d) {
37         this(d.width, d.height);
38     }
39     
40     public PixelDimension(Dimension d) {
41         this(d.width, d.height);
42     }
43
44     public int getHeight() {
45         return height;
46     }
47
48     public int getWidth() {
49         return width;
50     }
51
52     public boolean equals(Object obj) {
53         if (!(obj instanceof PixelDimension))
54             return false;
55         PixelDimension d = (PixelDimension) obj;
56         return (width == d.width) && (height == d.height);
57     }
58
59     public int hashCode() {
60         int sum = width+height;
61         return sum*(sum+1)/2 + width;
62     }
63     
64     @Override
65     public String toString() {
66         return "PixelDimension [w=" + width + ", h=" + height + "]";
67     }    
68     
69     /**
70      * returns aspect ratio (width / height)
71      * @return returns aspect ratio (width / height)
72      */
73     public double getAspectRatio()
74     {
75         return (double)width / (double)height;
76     }
77     
78 }