Ejemplo n.º 1
0
 public void rebuild() {
   if (!isNull()) {
     myParagraphCursor.clear();
     myParagraphCursor.fill();
     moveTo(myWordIndex, myCharIndex);
   }
 }
Ejemplo n.º 2
0
 public boolean previousParagraph() {
   if (!isNull()) {
     if (!myParagraphCursor.isFirst()) {
       myParagraphCursor = myParagraphCursor.previous();
       moveToParagraphStart();
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 3
0
 public boolean nextParagraph() {
   if (!isNull()) {
     if (!myParagraphCursor.isLast()) {
       myParagraphCursor = myParagraphCursor.next();
       moveToParagraphStart();
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 4
0
 @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);
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
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;
       }
     }
   }
 }
Ejemplo n.º 7
0
  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();
      }
    }
  }
Ejemplo n.º 8
0
 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);
       }
     }
   }
 }
Ejemplo n.º 9
0
 public ZLTextElement getElement() {
   return myParagraphCursor.getElement(myWordIndex);
 }
Ejemplo n.º 10
0
 public boolean isEndOfParagraph() {
   return myWordIndex == myParagraphCursor.getParagraphLength();
 }
Ejemplo n.º 11
0
 public void moveToParagraph(int paragraphIndex) {
   if (!isNull() && (paragraphIndex != myParagraphCursor.Index)) {
     myParagraphCursor = ZLTextParagraphCursor.cursor(myParagraphCursor.myModel, paragraphIndex);
     moveToParagraphStart();
   }
 }
Ejemplo n.º 12
0
 public void moveToParagraphEnd() {
   if (!isNull()) {
     myWordIndex = myParagraphCursor.getParagraphLength();
     myCharIndex = 0;
   }
 }