public void rebuild() { if (!isNull()) { myParagraphCursor.clear(); myParagraphCursor.fill(); moveTo(myWordIndex, myCharIndex); } }
public boolean previousParagraph() { if (!isNull()) { if (!myParagraphCursor.isFirst()) { myParagraphCursor = myParagraphCursor.previous(); moveToParagraphStart(); return true; } } return false; }
public boolean nextParagraph() { if (!isNull()) { if (!myParagraphCursor.isLast()) { myParagraphCursor = myParagraphCursor.next(); moveToParagraphStart(); return true; } } return false; }
@Override public ZLTextPosition getEndPosition() { if (isEmpty()) { return null; } final ZLTextParagraphCursor cursor = ZLTextParagraphCursor.cursor(myView.getModel(), myRightMostRegionSoul.ParagraphIndex); final ZLTextElement element = cursor.getElement(myRightMostRegionSoul.EndElementIndex); return new ZLTextFixedPosition( myRightMostRegionSoul.ParagraphIndex, myRightMostRegionSoul.EndElementIndex, element instanceof ZLTextWord ? ((ZLTextWord) element).Length : 0); }
public ZLTextMark getPosition() { if (myParagraphCursor == null) { return new ZLTextMark(); } final ZLTextParagraphCursor paragraph = myParagraphCursor; int paragraphLength = paragraph.getParagraphLength(); int wordIndex = myWordIndex; while ((wordIndex != paragraphLength) && (!(paragraph.getElement(wordIndex) instanceof ZLTextWord))) { wordIndex++; } if (wordIndex != paragraphLength) { return new ZLTextMark( paragraph.Index, ((ZLTextWord) paragraph.getElement(wordIndex)).getParagraphOffset(), 0); } return new ZLTextMark(paragraph.Index + 1, 0, 0); }
public void setCharIndex(int charIndex) { charIndex = Math.max(0, charIndex); myCharIndex = 0; if (charIndex > 0) { ZLTextElement element = myParagraphCursor.getElement(myWordIndex); if (element instanceof ZLTextWord) { if (charIndex <= ((ZLTextWord) element).Length) { myCharIndex = charIndex; } } } }
public void traverse(ZLTextPosition from, ZLTextPosition to) { final int fromParagraph = from.getParagraphIndex(); final int toParagraph = to.getParagraphIndex(); ZLTextParagraphCursor cursor = ZLTextParagraphCursor.cursor(myView.getModel(), fromParagraph); for (int i = fromParagraph; i <= toParagraph; ++i) { final int fromElement = i == fromParagraph ? from.getElementIndex() : 0; final int toElement = i == toParagraph ? to.getElementIndex() : cursor.getParagraphLength() - 1; for (int j = fromElement; j <= toElement; j++) { final ZLTextElement element = cursor.getElement(j); if (element == ZLTextElement.HSpace) { processSpace(); } else if (element instanceof ZLTextWord) { processWord((ZLTextWord) element); } } if (i < toParagraph) { processEndOfParagraph(); cursor = cursor.next(); } } }
public void moveTo(int wordIndex, int charIndex) { if (!isNull()) { if (wordIndex == 0 && charIndex == 0) { myWordIndex = 0; myCharIndex = 0; } else { wordIndex = Math.max(0, wordIndex); int size = myParagraphCursor.getParagraphLength(); if (wordIndex > size) { myWordIndex = size; myCharIndex = 0; } else { myWordIndex = wordIndex; setCharIndex(charIndex); } } } }
public ZLTextElement getElement() { return myParagraphCursor.getElement(myWordIndex); }
public boolean isEndOfParagraph() { return myWordIndex == myParagraphCursor.getParagraphLength(); }
public void moveToParagraph(int paragraphIndex) { if (!isNull() && (paragraphIndex != myParagraphCursor.Index)) { myParagraphCursor = ZLTextParagraphCursor.cursor(myParagraphCursor.myModel, paragraphIndex); moveToParagraphStart(); } }
public void moveToParagraphEnd() { if (!isNull()) { myWordIndex = myParagraphCursor.getParagraphLength(); myCharIndex = 0; } }