Exemplo n.º 1
0
 private void updateChildCollapsedLineCount(int count) {
   childCollapsedLineCount += count;
   // if (childCollapsedLineCount>getLineCount()) {
   //	Thread.dumpStack();
   // }
   if (!collapsed && parent != null) {
     parent.updateChildCollapsedLineCount(count);
   }
 }
Exemplo n.º 2
0
  /**
   * Sets whether this <code>Fold</code> is collapsed. Calling this method will update both the text
   * area and all <code>Gutter</code> components.
   *
   * @param collapsed Whether this fold should be collapsed.
   * @see #isCollapsed()
   * @see #toggleCollapsedState()
   */
  public void setCollapsed(boolean collapsed) {

    if (collapsed != this.collapsed) {

      // Change our fold state and cached info about folded line count.
      int lineCount = getLineCount();
      int linesToCollapse = lineCount - childCollapsedLineCount;
      if (!collapsed) { // If we're expanding
        linesToCollapse = -linesToCollapse;
      }
      // System.out.println("Hiding lines: " + linesToCollapse +
      //		" (" + lineCount + ", " + linesToCollapse + ")");
      this.collapsed = collapsed;
      if (parent != null) {
        parent.updateChildCollapsedLineCount(linesToCollapse);
      }

      // If an end point of the selection is being hidden, move the caret
      // "out" of the fold.
      if (collapsed) {
        int dot = textArea.getSelectionStart(); // Forgive variable name
        Element root = textArea.getDocument().getDefaultRootElement();
        int dotLine = root.getElementIndex(dot);
        boolean updateCaret = containsLine(dotLine);
        if (!updateCaret) {
          int mark = textArea.getSelectionEnd();
          if (mark != dot) {
            int markLine = root.getElementIndex(mark);
            updateCaret = containsLine(markLine);
          }
        }
        if (updateCaret) {
          dot = root.getElement(getStartLine()).getEndOffset() - 1;
          textArea.setCaretPosition(dot);
        }
      }

      textArea.foldToggled(this);
    }
  }