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