/*     */ protected void drawLine(
     int paramInt1, int paramInt2, Graphics paramGraphics, int paramInt3, int paramInt4)
       /*     */ {
   /* 105 */ Element localElement1 = getElement();
   /* 106 */ Element localElement2 =
       localElement1.getElement(localElement1.getElementIndex(paramInt1));
   /*     */ try
   /*     */ {
     /* 110 */ if (localElement2.isLeaf()) {
       /* 111 */ drawText(
           localElement2, paramInt1, paramInt2, paramGraphics, paramInt3, paramInt4);
       /*     */ }
     /*     */ else {
       /* 114 */ int i = localElement2.getElementIndex(paramInt1);
       /* 115 */ int j = localElement2.getElementIndex(paramInt2);
       /* 116 */ for (; i <= j; i++) {
         /* 117 */ Element localElement3 = localElement2.getElement(i);
         /* 118 */ int k = Math.max(localElement3.getStartOffset(), paramInt1);
         /* 119 */ int m = Math.min(localElement3.getEndOffset(), paramInt2);
         /* 120 */ paramInt3 = drawText(localElement3, k, m, paramGraphics, paramInt3, paramInt4);
         /*     */ }
       /*     */ }
     /*     */ } catch (BadLocationException localBadLocationException) {
     /* 124 */ throw new StateInvariantError("Can't render: " + paramInt1 + "," + paramInt2);
     /*     */ }
   /*     */ }
Example #2
0
 protected int getViewIndexAtPosition(int pos) {
   Element elem = getElement();
   if (elem.isLeaf()) {
     return 0;
   }
   return super.getViewIndexAtPosition(pos);
 }
Example #3
0
 protected void loadChildren(ViewFactory f) {
   Element elem = getElement();
   if (elem.isLeaf()) {
     View v = new LabelView(elem);
     append(v);
   } else {
     super.loadChildren(f);
   }
 }
 /**
  * Returns the last child of <code>parent</code> that is a leaf. If the last child is a not a
  * leaf, this method is called with the last child.
  */
 private Element getDeepestLeaf(Element parent) {
   if (parent.isLeaf()) {
     return parent;
   }
   int childCount = parent.getElementCount();
   if (childCount == 0) {
     return parent;
   }
   return getDeepestLeaf(parent.getElement(childCount - 1));
 }
  /**
   * Fetches the next Element. The strategy used to locate the next element is a depth-first search.
   *
   * @return the next element or <code>null</code> at the end of the list.
   */
  public Element next() {

    /* if current() has not been invoked
    and next is invoked, the very first
    element will be returned. */
    if (elementStack == null) {
      return first();
    }

    // no more elements
    if (elementStack.isEmpty()) {
      return null;
    }

    // get a handle to the element on top of the stack

    StackItem item = (StackItem) elementStack.peek();
    Element elem = item.getElement();
    int index = item.getIndex();

    if (index + 1 < elem.getElementCount()) {
      Element child = elem.getElement(index + 1);
      if (child.isLeaf()) {
        /* In this case we merely want to increment
        the child index of the item on top of the
        stack.*/
        item.incrementIndex();
      } else {
        /* In this case we need to push the child(branch)
        on the stack so that we can iterate over its
        children. */
        elementStack.push(new StackItem(child));
      }
      return child;
    } else {
      /* No more children for the item on top of the
      stack therefore pop the stack. */
      elementStack.pop();
      if (!elementStack.isEmpty()) {
        /* Increment the child index for the item that
        is now on top of the stack. */
        StackItem top = (StackItem) elementStack.peek();
        top.incrementIndex();
        /* We now want to return its next child, therefore
        call next() recursively. */
        return next();
      }
    }
    return null;
  }
Example #6
0
 private void parse(Element node) {
   if (!showThumbs) {
     // do not show any thumbnails
     return;
   }
   int count = node.getElementCount();
   for (int i = 0; i < count; i++) {
     Element elm = node.getElement(i);
     Debug.log(8, elm.toString());
     if (elm.isLeaf()) {
       int start = elm.getStartOffset(), end = elm.getEndOffset();
       parseRange(start, end);
     } else {
       parse(elm);
     }
   }
 }
Example #7
0
 private int getFunctionStartOffset(String func, Element node) throws BadLocationException {
   Document doc = getDocument();
   int count = node.getElementCount();
   Pattern patDef = Pattern.compile("def\\s+" + func + "\\s*\\(");
   for (int i = 0; i < count; i++) {
     Element elm = node.getElement(i);
     if (elm.isLeaf()) {
       int start = elm.getStartOffset(), end = elm.getEndOffset();
       String line = doc.getText(start, end - start);
       Matcher matcher = patDef.matcher(line);
       if (matcher.find()) {
         return start;
       }
     } else {
       int p = getFunctionStartOffset(func, elm);
       if (p >= 0) {
         return p;
       }
     }
   }
   return -1;
 }
 /**
  * Return the text of the Document that is associated with the given Element. If the Element is
  * not a leaf Element, this will throw BadLocationException.
  *
  * @throws BadLocationException if the element is not a leaf
  */
 protected String getText(Element elt) throws BadLocationException {
   if (!elt.isLeaf())
     throw new BadLocationException("Element is not a leaf", elt.getStartOffset());
   return document.getText(elt.getStartOffset(), elt.getEndOffset());
 }
  /**
   * Iterates over the Element tree and controls the writing out of all the tags and its attributes.
   *
   * @exception IOException on any I/O error
   * @exception BadLocationException if pos represents an invalid location within the document.
   */
  public void write() throws IOException, BadLocationException {
    ElementIterator it = getElementIterator();
    Element current = null;
    Element next = null;

    wroteHead = false;
    setCurrentLineLength(0);
    replaceEntities = false;
    setCanWrapLines(false);
    if (segment == null) {
      segment = new Segment();
    }
    inPre = false;
    boolean forcedBody = false;
    while ((next = it.next()) != null) {
      if (!inRange(next)) {
        if (completeDoc
            && next.getAttributes().getAttribute(StyleConstants.NameAttribute) == HTML.Tag.BODY) {
          forcedBody = true;
        } else {
          continue;
        }
      }
      if (current != null) {

        /*
          if next is child of current increment indent
        */

        if (indentNeedsIncrementing(current, next)) {
          incrIndent();
        } else if (current.getParentElement() != next.getParentElement()) {
          /*
             next and current are not siblings
             so emit end tags for items on the stack until the
             item on top of the stack, is the parent of the
             next.
          */
          Element top = (Element) blockElementStack.peek();
          while (top != next.getParentElement()) {
            /*
               pop() will return top.
            */
            blockElementStack.pop();
            if (!synthesizedElement(top)) {
              AttributeSet attrs = top.getAttributes();
              if (!matchNameAttribute(attrs, HTML.Tag.PRE) && !isFormElementWithContent(attrs)) {
                decrIndent();
              }
              endTag(top);
            }
            top = (Element) blockElementStack.peek();
          }
        } else if (current.getParentElement() == next.getParentElement()) {
          /*
             if next and current are siblings the indent level
             is correct.  But, we need to make sure that if current is
             on the stack, we pop it off, and put out its end tag.
          */
          Element top = (Element) blockElementStack.peek();
          if (top == current) {
            blockElementStack.pop();
            endTag(top);
          }
        }
      }
      if (!next.isLeaf() || isFormElementWithContent(next.getAttributes())) {
        blockElementStack.push(next);
        startTag(next);
      } else {
        emptyTag(next);
      }
      current = next;
    }
    /* Emit all remaining end tags */

    /* A null parameter ensures that all embedded tags
       currently in the tags vector have their
       corresponding end tags written out.
    */
    closeOutUnwantedEmbeddedTags(null);

    if (forcedBody) {
      blockElementStack.pop();
      endTag(current);
    }
    while (!blockElementStack.empty()) {
      current = (Element) blockElementStack.pop();
      if (!synthesizedElement(current)) {
        AttributeSet attrs = current.getAttributes();
        if (!matchNameAttribute(attrs, HTML.Tag.PRE) && !isFormElementWithContent(attrs)) {
          decrIndent();
        }
        endTag(current);
      }
    }

    if (completeDoc) {
      writeAdditionalComments();
    }

    segment.array = null;
  }