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