J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package java.awt.geom; |
| 27 | |
| 28 | /** |
| 29 | * The <code>Dimension2D</code> class is to encapsulate a width |
| 30 | * and a height dimension. |
| 31 | * <p> |
| 32 | * This class is only the abstract superclass for all objects that |
| 33 | * store a 2D dimension. |
| 34 | * The actual storage representation of the sizes is left to |
| 35 | * the subclass. |
| 36 | * |
| 37 | * @author Jim Graham |
| 38 | * @since 1.2 |
| 39 | */ |
| 40 | public abstract class Dimension2D implements Cloneable { |
| 41 | |
| 42 | /** |
| 43 | * This is an abstract class that cannot be instantiated directly. |
| 44 | * Type-specific implementation subclasses are available for |
| 45 | * instantiation and provide a number of formats for storing |
| 46 | * the information necessary to satisfy the various accessor |
| 47 | * methods below. |
| 48 | * |
| 49 | * @see java.awt.Dimension |
| 50 | * @since 1.2 |
| 51 | */ |
| 52 | protected Dimension2D() { |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the width of this <code>Dimension</code> in double |
| 57 | * precision. |
| 58 | * @return the width of this <code>Dimension</code>. |
| 59 | * @since 1.2 |
| 60 | */ |
| 61 | public abstract double getWidth(); |
| 62 | |
| 63 | /** |
| 64 | * Returns the height of this <code>Dimension</code> in double |
| 65 | * precision. |
| 66 | * @return the height of this <code>Dimension</code>. |
| 67 | * @since 1.2 |
| 68 | */ |
| 69 | public abstract double getHeight(); |
| 70 | |
| 71 | /** |
| 72 | * Sets the size of this <code>Dimension</code> object to the |
| 73 | * specified width and height. |
| 74 | * This method is included for completeness, to parallel the |
| 75 | * {@link java.awt.Component#getSize getSize} method of |
| 76 | * {@link java.awt.Component}. |
| 77 | * @param width the new width for the <code>Dimension</code> |
| 78 | * object |
| 79 | * @param height the new height for the <code>Dimension</code> |
| 80 | * object |
| 81 | * @since 1.2 |
| 82 | */ |
| 83 | public abstract void setSize(double width, double height); |
| 84 | |
| 85 | /** |
| 86 | * Sets the size of this <code>Dimension2D</code> object to |
| 87 | * match the specified size. |
| 88 | * This method is included for completeness, to parallel the |
| 89 | * <code>getSize</code> method of <code>Component</code>. |
| 90 | * @param d the new size for the <code>Dimension2D</code> |
| 91 | * object |
| 92 | * @since 1.2 |
| 93 | */ |
| 94 | public void setSize(Dimension2D d) { |
| 95 | setSize(d.getWidth(), d.getHeight()); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Creates a new object of the same class as this object. |
| 100 | * |
| 101 | * @return a clone of this instance. |
| 102 | * @exception OutOfMemoryError if there is not enough memory. |
| 103 | * @see java.lang.Cloneable |
| 104 | * @since 1.2 |
| 105 | */ |
| 106 | public Object clone() { |
| 107 | try { |
| 108 | return super.clone(); |
| 109 | } catch (CloneNotSupportedException e) { |
| 110 | // this shouldn't happen, since we are Cloneable |
| 111 | throw new InternalError(); |
| 112 | } |
| 113 | } |
| 114 | } |