1. /*
  2. * @(#)TabStop.java 1.14 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 javax.swing.text;
  11. import java.io.Serializable;
  12. /**
  13. * This class encapsulates a single tab stop (basically as tab stops
  14. * are thought of by RTF). A tab stop is at a specified distance from the
  15. * left margin, aligns text in a specified way, and has a specified leader.
  16. * TabStops are immutable, and usually contained in TabSets.
  17. * <p>
  18. * <strong>Warning:</strong>
  19. * Serialized objects of this class will not be compatible with
  20. * future Swing releases. The current serialization support is appropriate
  21. * for short term storage or RMI between applications running the same
  22. * version of Swing. A future release of Swing will provide support for
  23. * long term persistence.
  24. *
  25. * @version 1.14 02/02/00
  26. */
  27. public class TabStop implements Serializable {
  28. /** Character following tab is positioned at location. */
  29. public static final int ALIGN_LEFT = 0;
  30. /** Characters following tab are positioned such that all following
  31. * characters up to next tab/newline end at location. */
  32. public static final int ALIGN_RIGHT = 1;
  33. /** Characters following tab are positioned such that all following
  34. * characters up to next tab/newline are centered around the tabs
  35. * location. */
  36. public static final int ALIGN_CENTER = 2;
  37. /** Characters following tab are aligned such that next
  38. * decimal/tab/newline is at the tab location, very similiar to
  39. * RIGHT_TAB, just includes decimal as additional character to look for.
  40. */
  41. public static final int ALIGN_DECIMAL = 4;
  42. public static final int ALIGN_BAR = 5;
  43. /* Bar tabs (whatever they are) are actually a separate kind of tab
  44. in the RTF spec. However, being a bar tab and having alignment
  45. properties are mutually exclusive, so the reader treats barness
  46. as being a kind of alignment. */
  47. public static final int LEAD_NONE = 0;
  48. public static final int LEAD_DOTS = 1;
  49. public static final int LEAD_HYPHENS = 2;
  50. public static final int LEAD_UNDERLINE = 3;
  51. public static final int LEAD_THICKLINE = 4;
  52. public static final int LEAD_EQUALS = 5;
  53. /** Tab type. */
  54. private int alignment;
  55. /** Location, from the left margin, that tab is at. */
  56. private float position;
  57. private int leader;
  58. /**
  59. * Creates a tab at position <code>pos</code> with a default alignment
  60. * and default leader.
  61. */
  62. public TabStop(float pos) {
  63. this(pos, ALIGN_LEFT, LEAD_NONE);
  64. }
  65. /**
  66. * Creates a tab with the specified position <code>pos</code>,
  67. * alignment <code>align</code> and leader <code>leader</code>.
  68. */
  69. public TabStop(float pos, int align, int leader) {
  70. alignment = align;
  71. this.leader = leader;
  72. position = pos;
  73. }
  74. /**
  75. * @return the postion of the tab.
  76. */
  77. public float getPosition() {
  78. return position;
  79. }
  80. /**
  81. * @return the alignment of the tab.
  82. */
  83. public int getAlignment() {
  84. return alignment;
  85. }
  86. /**
  87. * @return the leader of the tab.
  88. */
  89. public int getLeader() {
  90. return leader;
  91. }
  92. /**
  93. * Returns true if other equals the receiver.
  94. */
  95. public boolean equals(Object other)
  96. {
  97. if (other == this) {
  98. return true;
  99. }
  100. if (other instanceof TabStop) {
  101. TabStop o = (TabStop)other;
  102. return ( (alignment == o.alignment) &&
  103. (leader == o.leader) &&
  104. (position == o.position) ); /* TODO: epsilon */
  105. }
  106. return false;
  107. }
  108. /**
  109. * Returns the hashCode for the object. This must be defined
  110. * here to ensure 100% pure.
  111. *
  112. * @return the hashCode for the object
  113. */
  114. public int hashCode() {
  115. return super.hashCode();
  116. }
  117. /* This is for debugging; perhaps it should be removed before release */
  118. public String toString() {
  119. String buf;
  120. switch(alignment) {
  121. default:
  122. case ALIGN_LEFT:
  123. buf = "";
  124. break;
  125. case ALIGN_RIGHT:
  126. buf = "right ";
  127. break;
  128. case ALIGN_CENTER:
  129. buf = "center ";
  130. break;
  131. case ALIGN_DECIMAL:
  132. buf = "decimal ";
  133. break;
  134. case ALIGN_BAR:
  135. buf = "bar ";
  136. break;
  137. }
  138. buf = buf + "tab @" + String.valueOf(position);
  139. if (leader != LEAD_NONE)
  140. buf = buf + " (w/leaders)";
  141. return buf;
  142. }
  143. }