1 7 8 22 23 package java.awt.font; 24 import java.lang.String ; 25 26 69 70 public final class TextHitInfo { 71 private int charIndex; 72 private boolean isLeadingEdge; 73 74 80 private TextHitInfo(int charIndex, boolean isLeadingEdge) { 81 this.charIndex = charIndex; 82 this.isLeadingEdge = isLeadingEdge; 83 } 84 85 89 public int getCharIndex() { 90 return charIndex; 91 } 92 93 99 public boolean isLeadingEdge() { 100 return isLeadingEdge; 101 } 102 103 109 public int getInsertionIndex() { 110 return isLeadingEdge ? charIndex : charIndex + 1; 111 } 112 113 118 public int hashCode() { 119 return charIndex; 120 } 121 122 129 public boolean equals(Object obj) { 130 return (obj instanceof TextHitInfo ) && equals((TextHitInfo )obj); 131 } 132 133 143 public boolean equals(TextHitInfo hitInfo) { 144 return hitInfo != null && charIndex == hitInfo.charIndex && 145 isLeadingEdge == hitInfo.isLeadingEdge; 146 } 147 148 154 public String toString() { 155 return "TextHitInfo[" + charIndex + (isLeadingEdge ? "L" : "T")+"]"; 156 } 157 158 165 public static TextHitInfo leading(int charIndex) { 166 return new TextHitInfo (charIndex, true); 167 } 168 169 176 public static TextHitInfo trailing(int charIndex) { 177 return new TextHitInfo (charIndex, false); 178 } 179 180 187 public static TextHitInfo beforeOffset(int offset) { 188 return new TextHitInfo (offset-1, false); 189 } 190 191 198 public static TextHitInfo afterOffset(int offset) { 199 return new TextHitInfo (offset, true); 200 } 201 202 208 public TextHitInfo getOtherHit() { 209 if (isLeadingEdge) { 210 return trailing(charIndex - 1); 211 } else { 212 return leading(charIndex + 1); 213 } 214 } 215 216 226 public TextHitInfo getOffsetHit(int delta) { 227 return new TextHitInfo (charIndex + delta, isLeadingEdge); 228 } 229 } 230 | Popular Tags |