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