1 15 16 package swingwt.awt.font; 17 18 22 public class TextHitInfo 23 { 24 private int charIndex; 25 private boolean isLeadingEdge; 26 27 public static TextHitInfo leading(int charIndex) { return new TextHitInfo(charIndex, true); } 28 public static TextHitInfo trailing(int charIndex) { return new TextHitInfo(charIndex, false); } 29 public static TextHitInfo beforeOffset(int offset) { return new TextHitInfo(offset - 1, false); } 30 public static TextHitInfo afterOffset(int offset) { return new TextHitInfo(offset, true); } 31 32 private TextHitInfo(int charIndex, boolean isLeadingEdge) 33 { 34 this.charIndex = charIndex; 35 this.isLeadingEdge = isLeadingEdge; 36 } 37 38 public TextHitInfo getOffsetHit(int delta) { return new TextHitInfo(charIndex + delta, isLeadingEdge); } 39 40 public int getCharIndex() { return charIndex; } 41 public boolean isLeadingEdge() { return isLeadingEdge; } 42 43 public int getInsertionIndex() 44 { 45 int insertionIndex = charIndex; 46 if (!isLeadingEdge) insertionIndex++; 47 48 return insertionIndex; 49 } 50 51 public TextHitInfo getOtherHit() 52 { 53 TextHitInfo textHitInfo; 54 55 if (isLeadingEdge) 56 textHitInfo = trailing(charIndex - 1); 57 else 58 textHitInfo = leading(charIndex + 1); 59 60 return textHitInfo; 61 } 62 63 public int hashCode() { return charIndex; } 64 public boolean equals(Object obj) 65 { 66 boolean equals = false; 67 68 if ( (obj != null) && 69 (obj instanceof TextHitInfo) && 70 (charIndex == ((TextHitInfo)obj).charIndex) && 71 (isLeadingEdge == ((TextHitInfo)obj).isLeadingEdge) ) 72 equals = true; 73 74 return equals; 75 } 76 } 77 | Popular Tags |