1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
15 package org.simantics.utils.ui.gfx;
17 import org.simantics.utils.ObjectUtils;
22 * @author Toni Kalajainen
24 public final class Dimensions {
26 public final static Double INCH = 25.4;
28 /** Pixel size, may be null if unknown */
29 public final PixelDimension pixelDimension;
31 /** Physical size, may be null if unknown */
32 public final PhysicalDimension physicaldimension;
34 public Dimensions(PixelDimension pixelDimension, PhysicalDimension physicalDimension)
36 this.physicaldimension = physicalDimension;
37 this.pixelDimension = pixelDimension;
41 public int hashCode() {
43 if (pixelDimension!=null) code^= pixelDimension.hashCode();
44 if (physicaldimension!=null) code^= physicaldimension.hashCode();
49 public boolean equals(Object obj) {
50 if (!(obj instanceof Dimensions)) return false;
51 Dimensions other = (Dimensions) obj;
52 return ObjectUtils.objectEquals(other.physicaldimension, physicaldimension) &&
53 ObjectUtils.objectEquals(other.pixelDimension, pixelDimension);
58 public PhysicalDimension getPhysicaldimension() {
59 return physicaldimension;
62 public PixelDimension getPixelDimension() {
63 return pixelDimension;
67 * Calculate horizontal Dots per inch.
68 * @return horizontal DPI or null if value is not available
70 public Double getHorizontalDPI()
72 if (pixelDimension==null || physicaldimension==null) return null;
73 if (physicaldimension.width==0) return null;
74 return (((double) pixelDimension.width)/physicaldimension.width)*INCH;
78 * Calculate vertical Dots per inch.
79 * @return Vertical DPI or null if value is not available
81 public Double getVerticalDPI()
83 if (pixelDimension==null || physicaldimension==null) return null;
84 if (physicaldimension.height==0) return null;
85 return (((double) pixelDimension.height)/physicaldimension.height)*INCH;
89 public String toString() {
90 return "Dimensions [" + physicaldimension + ", " + pixelDimension + "]";
94 * returns aspect ratio (width / height)
95 * @return returns aspect ratio (width / height)
97 public double getAspectRatio()
99 if (physicaldimension!=null)
100 return physicaldimension.getAspectRatio();
101 if (pixelDimension!=null)
102 return pixelDimension.getAspectRatio();