1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
15 package org.simantics.utils.ui.gfx;
\r
17 import org.simantics.utils.ObjectUtils;
\r
22 * @author Toni Kalajainen
\r
24 public final class Dimensions {
\r
26 public final static Double INCH = 25.4;
\r
28 /** Pixel size, may be null if unknown */
\r
29 public final PixelDimension pixelDimension;
\r
31 /** Physical size, may be null if unknown */
\r
32 public final PhysicalDimension physicaldimension;
\r
34 public Dimensions(PixelDimension pixelDimension, PhysicalDimension physicalDimension)
\r
36 this.physicaldimension = physicalDimension;
\r
37 this.pixelDimension = pixelDimension;
\r
41 public int hashCode() {
\r
43 if (pixelDimension!=null) code^= pixelDimension.hashCode();
\r
44 if (physicaldimension!=null) code^= physicaldimension.hashCode();
\r
49 public boolean equals(Object obj) {
\r
50 if (!(obj instanceof Dimensions)) return false;
\r
51 Dimensions other = (Dimensions) obj;
\r
52 return ObjectUtils.objectEquals(other.physicaldimension, physicaldimension) &&
\r
53 ObjectUtils.objectEquals(other.pixelDimension, pixelDimension);
\r
58 public PhysicalDimension getPhysicaldimension() {
\r
59 return physicaldimension;
\r
62 public PixelDimension getPixelDimension() {
\r
63 return pixelDimension;
\r
67 * Calculate horizontal Dots per inch.
\r
68 * @return horizontal DPI or null if value is not available
\r
70 public Double getHorizontalDPI()
\r
72 if (pixelDimension==null || physicaldimension==null) return null;
\r
73 if (physicaldimension.width==0) return null;
\r
74 return (((double) pixelDimension.width)/physicaldimension.width)*INCH;
\r
78 * Calculate vertical Dots per inch.
\r
79 * @return Vertical DPI or null if value is not available
\r
81 public Double getVerticalDPI()
\r
83 if (pixelDimension==null || physicaldimension==null) return null;
\r
84 if (physicaldimension.height==0) return null;
\r
85 return (((double) pixelDimension.height)/physicaldimension.height)*INCH;
\r
89 public String toString() {
\r
90 return "Dimensions [" + physicaldimension + ", " + pixelDimension + "]";
\r
94 * returns aspect ratio (width / height)
\r
95 * @return returns aspect ratio (width / height)
\r
97 public double getAspectRatio()
\r
99 if (physicaldimension!=null)
\r
100 return physicaldimension.getAspectRatio();
\r
101 if (pixelDimension!=null)
\r
102 return pixelDimension.getAspectRatio();
\r