1. /*
  2. * @(#)Insets.java 1.25 00/02/02
  3. *
  4. * Copyright 1995-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;
  11. /**
  12. * An <code>Insets</code> object is a representation of the borders
  13. * of a container. It specifies the space that a container must leave
  14. * at each of its edges. The space can be a border, a blank space, or
  15. * a title.
  16. *
  17. * @version 1.25, 02/02/00
  18. * @author Arthur van Hoff
  19. * @author Sami Shaio
  20. * @see java.awt.LayoutManager
  21. * @see java.awt.Container
  22. * @since JDK1.0
  23. */
  24. public class Insets implements Cloneable, java.io.Serializable {
  25. /**
  26. * The inset from the top.
  27. * This value is added to the Top of the rectangle
  28. * to yield a new location for the Top.
  29. *
  30. * @serial
  31. * @see #clone()
  32. */
  33. public int top;
  34. /**
  35. * The inset from the left.
  36. * This value is added to the Left of the rectangle
  37. * to yield a new location for the Left edge.
  38. *
  39. * @serial
  40. * @see #clone()
  41. */
  42. public int left;
  43. /**
  44. * The inset from the bottom.
  45. * This value is subtracted from the Bottom of the rectangle
  46. * to yield a new location for the Bottom.
  47. *
  48. * @serial
  49. * @see #clone()
  50. */
  51. public int bottom;
  52. /**
  53. * The inset from the right.
  54. * This value is subtracted from the Right of the rectangle
  55. * to yield a new location for the Right edge.
  56. *
  57. * @serial
  58. * @see #clone()
  59. */
  60. public int right;
  61. /*
  62. * JDK 1.1 serialVersionUID
  63. */
  64. private static final long serialVersionUID = -2272572637695466749L;
  65. static {
  66. /* ensure that the necessary native libraries are loaded */
  67. Toolkit.loadLibraries();
  68. initIDs();
  69. }
  70. /**
  71. * Creates and initializes a new <code>Insets</code> object with the
  72. * specified top, left, bottom, and right insets.
  73. * @param top the inset from the top.
  74. * @param left the inset from the left.
  75. * @param bottom the inset from the bottom.
  76. * @param right the inset from the right.
  77. */
  78. public Insets(int top, int left, int bottom, int right) {
  79. this.top = top;
  80. this.left = left;
  81. this.bottom = bottom;
  82. this.right = right;
  83. }
  84. /**
  85. * Checks whether two insets objects are equal. Two instances
  86. * of <code>Insets</code> are equal if the four integer values
  87. * of the fields <code>top</code>, <code>left</code>,
  88. * <code>bottom</code>, and <code>right</code> are all equal.
  89. * @return <code>true</code> if the two insets are equal;
  90. * otherwise <code>false</code>.
  91. * @since JDK1.1
  92. */
  93. public boolean equals(Object obj) {
  94. if (obj instanceof Insets) {
  95. Insets insets = (Insets)obj;
  96. return ((top == insets.top) && (left == insets.left) &&
  97. (bottom == insets.bottom) && (right == insets.right));
  98. }
  99. return false;
  100. }
  101. /**
  102. * Returns the hash code for this Insets.
  103. *
  104. * @return a hash code for this Insets.
  105. */
  106. public int hashCode() {
  107. int sum1 = left + bottom;
  108. int sum2 = right + top;
  109. int val1 = sum1 * (sum1 + 1)/2 + left;
  110. int val2 = sum2 * (sum2 + 1)/2 + top;
  111. int sum3 = val1 + val2;
  112. return sum3 * (sum3 + 1)/2 + val2;
  113. }
  114. /**
  115. * Returns a string representation of this <code>Insets</code> object.
  116. * This method is intended to be used only for debugging purposes, and
  117. * the content and format of the returned string may vary between
  118. * implementations. The returned string may be empty but may not be
  119. * <code>null</code>.
  120. *
  121. * @return a string representation of this <code>Insets</code> object.
  122. */
  123. public String toString() {
  124. return getClass().getName() + "[top=" + top + ",left=" + left + ",bottom=" + bottom + ",right=" + right + "]";
  125. }
  126. /**
  127. * Create a copy of this object.
  128. * @return a copy of this <code>Insets</code> object.
  129. */
  130. public Object clone() {
  131. try {
  132. return super.clone();
  133. } catch (CloneNotSupportedException e) {
  134. // this shouldn't happen, since we are Cloneable
  135. throw new InternalError();
  136. }
  137. }
  138. /**
  139. * Initialize JNI field and method IDs
  140. */
  141. private static native void initIDs();
  142. }