X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fgfx%2FDimensions.java;h=fc2f50d68acd504fb673d73e9ff8f8a5cb9ab72f;hp=82f6ae5eccd6ddd8783aeb0ca0968303225e6298;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/Dimensions.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/Dimensions.java index 82f6ae5ec..fc2f50d68 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/Dimensions.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/Dimensions.java @@ -1,107 +1,107 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -/* - * 10.10.2006 - */ -package org.simantics.utils.ui.gfx; - -import org.simantics.utils.ObjectUtils; - - -/** - * Dimensions - * @author Toni Kalajainen - */ -public final class Dimensions { - - public final static Double INCH = 25.4; - - /** Pixel size, may be null if unknown */ - public final PixelDimension pixelDimension; - - /** Physical size, may be null if unknown */ - public final PhysicalDimension physicaldimension; - - public Dimensions(PixelDimension pixelDimension, PhysicalDimension physicalDimension) - { - this.physicaldimension = physicalDimension; - this.pixelDimension = pixelDimension; - } - - @Override - public int hashCode() { - int code = 0; - if (pixelDimension!=null) code^= pixelDimension.hashCode(); - if (physicaldimension!=null) code^= physicaldimension.hashCode(); - return code; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Dimensions)) return false; - Dimensions other = (Dimensions) obj; - return ObjectUtils.objectEquals(other.physicaldimension, physicaldimension) && - ObjectUtils.objectEquals(other.pixelDimension, pixelDimension); - } - - - - public PhysicalDimension getPhysicaldimension() { - return physicaldimension; - } - - public PixelDimension getPixelDimension() { - return pixelDimension; - } - - /** - * Calculate horizontal Dots per inch. - * @return horizontal DPI or null if value is not available - */ - public Double getHorizontalDPI() - { - if (pixelDimension==null || physicaldimension==null) return null; - if (physicaldimension.width==0) return null; - return (((double) pixelDimension.width)/physicaldimension.width)*INCH; - } - - /** - * Calculate vertical Dots per inch. - * @return Vertical DPI or null if value is not available - */ - public Double getVerticalDPI() - { - if (pixelDimension==null || physicaldimension==null) return null; - if (physicaldimension.height==0) return null; - return (((double) pixelDimension.height)/physicaldimension.height)*INCH; - } - - @Override - public String toString() { - return "Dimensions [" + physicaldimension + ", " + pixelDimension + "]"; - } - - /** - * returns aspect ratio (width / height) - * @return returns aspect ratio (width / height) - */ - public double getAspectRatio() - { - if (physicaldimension!=null) - return physicaldimension.getAspectRatio(); - if (pixelDimension!=null) - return pixelDimension.getAspectRatio(); - return 1; - } - - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* + * 10.10.2006 + */ +package org.simantics.utils.ui.gfx; + +import org.simantics.utils.ObjectUtils; + + +/** + * Dimensions + * @author Toni Kalajainen + */ +public final class Dimensions { + + public final static Double INCH = 25.4; + + /** Pixel size, may be null if unknown */ + public final PixelDimension pixelDimension; + + /** Physical size, may be null if unknown */ + public final PhysicalDimension physicaldimension; + + public Dimensions(PixelDimension pixelDimension, PhysicalDimension physicalDimension) + { + this.physicaldimension = physicalDimension; + this.pixelDimension = pixelDimension; + } + + @Override + public int hashCode() { + int code = 0; + if (pixelDimension!=null) code^= pixelDimension.hashCode(); + if (physicaldimension!=null) code^= physicaldimension.hashCode(); + return code; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Dimensions)) return false; + Dimensions other = (Dimensions) obj; + return ObjectUtils.objectEquals(other.physicaldimension, physicaldimension) && + ObjectUtils.objectEquals(other.pixelDimension, pixelDimension); + } + + + + public PhysicalDimension getPhysicaldimension() { + return physicaldimension; + } + + public PixelDimension getPixelDimension() { + return pixelDimension; + } + + /** + * Calculate horizontal Dots per inch. + * @return horizontal DPI or null if value is not available + */ + public Double getHorizontalDPI() + { + if (pixelDimension==null || physicaldimension==null) return null; + if (physicaldimension.width==0) return null; + return (((double) pixelDimension.width)/physicaldimension.width)*INCH; + } + + /** + * Calculate vertical Dots per inch. + * @return Vertical DPI or null if value is not available + */ + public Double getVerticalDPI() + { + if (pixelDimension==null || physicaldimension==null) return null; + if (physicaldimension.height==0) return null; + return (((double) pixelDimension.height)/physicaldimension.height)*INCH; + } + + @Override + public String toString() { + return "Dimensions [" + physicaldimension + ", " + pixelDimension + "]"; + } + + /** + * returns aspect ratio (width / height) + * @return returns aspect ratio (width / height) + */ + public double getAspectRatio() + { + if (physicaldimension!=null) + return physicaldimension.getAspectRatio(); + if (pixelDimension!=null) + return pixelDimension.getAspectRatio(); + return 1; + } + + +}