1. /*
  2. * @(#)Dimension2D.java 1.13 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.geom;
  8. /**
  9. * The <code>Dimension2D</code> class is to encapsulate a width
  10. * and a height dimension.
  11. * <p>
  12. * This class is only the abstract superclass for all objects that
  13. * store a 2D dimension.
  14. * The actual storage representation of the sizes is left to
  15. * the subclass.
  16. *
  17. * @version 1.13, 12/19/03
  18. * @author Jim Graham
  19. */
  20. public abstract class Dimension2D implements Cloneable {
  21. /**
  22. * This is an abstract class that cannot be instantiated directly.
  23. * Type-specific implementation subclasses are available for
  24. * instantiation and provide a number of formats for storing
  25. * the information necessary to satisfy the various accessor
  26. * methods below.
  27. *
  28. * @see java.awt.Dimension
  29. */
  30. protected Dimension2D() {
  31. }
  32. /**
  33. * Returns the width of this <code>Dimension</code> in double
  34. * precision.
  35. * @return the width of this <code>Dimension</code>.
  36. */
  37. public abstract double getWidth();
  38. /**
  39. * Returns the height of this <code>Dimension</code> in double
  40. * precision.
  41. * @return the height of this <code>Dimension</code>.
  42. */
  43. public abstract double getHeight();
  44. /**
  45. * Sets the size of this <code>Dimension</code> object to the
  46. * specified width and height.
  47. * This method is included for completeness, to parallel the
  48. * {@link java.awt.Component#getSize getSize} method of
  49. * {@link java.awt.Component}.
  50. * @param width the new width for the <code>Dimension</code>
  51. * object
  52. * @param height the new height for the <code>Dimension</code>
  53. * object
  54. */
  55. public abstract void setSize(double width, double height);
  56. /**
  57. * Sets the size of this <code>Dimension2D</code> object to
  58. * match the specified size.
  59. * This method is included for completeness, to parallel the
  60. * <code>getSize</code> method of <code>Component</code>.
  61. * @param d the new size for the <code>Dimension2D</code>
  62. * object
  63. */
  64. public void setSize(Dimension2D d) {
  65. setSize(d.getWidth(), d.getHeight());
  66. }
  67. /**
  68. * Creates a new object of the same class as this object.
  69. *
  70. * @return a clone of this instance.
  71. * @exception OutOfMemoryError if there is not enough memory.
  72. * @see java.lang.Cloneable
  73. * @since 1.2
  74. */
  75. public Object clone() {
  76. try {
  77. return super.clone();
  78. } catch (CloneNotSupportedException e) {
  79. // this shouldn't happen, since we are Cloneable
  80. throw new InternalError();
  81. }
  82. }
  83. }