xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r620452 - in /xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics: image/loader/ImageSize.java java2d/Dimension2DDouble.java
Date Mon, 11 Feb 2008 10:48:29 GMT
Author: jeremias
Date: Mon Feb 11 02:48:27 2008
New Revision: 620452

URL: http://svn.apache.org/viewvc?rev=620452&view=rev
Log:
Second time I needed a double-based Dimension2D so make the one in ImageSize public.

Added:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/Dimension2DDouble.java
  (with props)
Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSize.java

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSize.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSize.java?rev=620452&r1=620451&r2=620452&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSize.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageSize.java
Mon Feb 11 02:48:27 2008
@@ -22,6 +22,7 @@
 import java.awt.Dimension;
 import java.awt.geom.Dimension2D;
 
+import org.apache.xmlgraphics.java2d.Dimension2DDouble;
 import org.apache.xmlgraphics.util.UnitConv;
 
 /**
@@ -190,32 +191,9 @@
      * @return the size in points
      */
     public Dimension2D getDimensionPt() {
-        return new DoubleDimension2D(getWidthMpt() / 1000.0, getHeightMpt() / 1000.0);
+        return new Dimension2DDouble(getWidthMpt() / 1000.0, getHeightMpt() / 1000.0);
     }
     
-    private static final class DoubleDimension2D extends Dimension2D {
-        private double width;
-        private double height;
-
-        private DoubleDimension2D(double width, double height) {
-            this.width = width;
-            this.height = height;
-        }
-
-        public double getWidth() {
-            return width;
-        }
-
-        public double getHeight() {
-            return height;
-        }
-
-        public void setSize(double w, double h) {
-            this.width = w;
-            this.height = h;
-        }
-    }
-
     /**
      * Returns the size in pixels as a Dimension object.
      * @return the size in pixels

Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/Dimension2DDouble.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/Dimension2DDouble.java?rev=620452&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/Dimension2DDouble.java
(added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/Dimension2DDouble.java
Mon Feb 11 02:48:27 2008
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.java2d;
+
+import java.awt.geom.Dimension2D;
+import java.io.Serializable;
+
+/**
+ * Subclass of Dimension2D which takes double values.
+ */
+public class Dimension2DDouble extends Dimension2D implements Serializable {
+    
+    private static final long serialVersionUID = 7909028357685520189L;
+    
+    private double width;
+    private double height;
+
+    /**
+     * Default constructor.
+     */
+    public Dimension2DDouble() {
+        this.width = 0;
+        this.height = 0;
+    }
+
+    /**
+     * Main constructor.
+     * @param width initial width
+     * @param height initial height
+     */
+    public Dimension2DDouble(double width, double height) {
+        this.width = width;
+        this.height = height;
+    }
+
+    /** {@inheritDoc} */
+    public double getWidth() {
+        return width;
+    }
+
+    /** {@inheritDoc} */
+    public double getHeight() {
+        return height;
+    }
+
+    /** {@inheritDoc} */
+    public void setSize(double w, double h) {
+        this.width = w;
+        this.height = h;
+    }
+
+    /** {@inheritDoc} */
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof Dimension2DDouble) {
+            final Dimension2DDouble other = (Dimension2DDouble)obj;
+            if (Double.doubleToLongBits(height) != Double.doubleToLongBits(other.height))
{
+                return false;
+            }
+            if (Double.doubleToLongBits(width) != Double.doubleToLongBits(other.width)) {
+                return false;
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /** {@inheritDoc} */
+    public int hashCode() {
+        double sum = width + height;
+        return (int)(sum * (sum + 1) / 2 + width);
+    }
+    
+    /** {@inheritDoc} */
+    public String toString() {
+        return getClass().getName() + "[width=" + width + ",height=" + height + "]";
+    }
+}
\ No newline at end of file

Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/Dimension2DDouble.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/Dimension2DDouble.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message