Package org.fife.ui.rsyntaxtextarea.folding

Examples of org.fife.ui.rsyntaxtextarea.folding.FoldManager


  protected View getViewAtPoint(int x, int y, Rectangle alloc) {

    int lineCount = getViewCount();
    int curY = alloc.y + getOffset(Y_AXIS, 0); // Always at least 1 line
    host = (RSyntaxTextArea)getContainer();
    FoldManager fm = host.getFoldManager();

    for (int line=1; line<lineCount; line++) {
      int span = getSpan(Y_AXIS, line-1);
      if (y<curY+span) {
        childAllocation2(line-1, curY, alloc);
        return getView(line-1);
      }
      curY += span;
      Fold fold = fm.getFoldForLine(line-1);
      if (fold!=null && fold.isCollapsed()) {
        line += fold.getCollapsedLineCount();
      }
    }
View Full Code Here


    Graphics2D g2d = (Graphics2D)g;
    host = (RSyntaxTextArea)getContainer();
    int ascent = host.getMaxAscent();
    int fontHeight = host.getLineHeight();
    FoldManager fm = host.getFoldManager();
    TokenPainter painter = host.getTokenPainter();
    Element root = getElement();

    // Whether token styles should always be painted, even in selections
    int selStart = host.getSelectionStart();
    int selEnd = host.getSelectionEnd();
    boolean useSelectedTextColor = host.getUseSelectedTextColor();

    int n = getViewCount()// Number of lines.
    int x = alloc.x + getLeftInset();
    tempRect.y = alloc.y + getTopInset();
    Rectangle clip = g.getClipBounds();
    for (int i = 0; i < n; i++) {

      tempRect.x = x + getOffset(X_AXIS, i);
      //tempRect.y = y + getOffset(Y_AXIS, i);
      tempRect.width = getSpan(X_AXIS, i);
      tempRect.height = getSpan(Y_AXIS, i);
      //System.err.println("For line " + i + ": tempRect==" + tempRect);

      if (tempRect.intersects(clip)) {
        Element lineElement = root.getElement(i);
        int startOffset = lineElement.getStartOffset();
        int endOffset = lineElement.getEndOffset()-1; // Why always "-1"?
        View view = getView(i);
        if (!useSelectedTextColor || selStart==selEnd ||
            (startOffset>=selEnd || endOffset<selStart)) {
          drawView(painter, g2d, alloc, view, fontHeight,
              tempRect.y+ascent);
        }
        else {
          //System.out.println("Drawing line with selection: " + i);
          drawViewWithSelection(painter, g2d, alloc, view, fontHeight,
              tempRect.y+ascent, selStart, selEnd);
        }
      }

      tempRect.y += tempRect.height;

      Fold possibleFold = fm.getFoldForLine(i);
      if (possibleFold!=null && possibleFold.isCollapsed()) {
        i += possibleFold.getCollapsedLineCount();
        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c!=null) {
View Full Code Here

      // to speed this back up!
      Rectangle r = (Rectangle)modelToView(offs, alloc, Bias.Forward);
      if (r!=null) {
        if (host.isCodeFoldingEnabled()) {
          int line = host.getLineOfOffset(offs);
          FoldManager fm = host.getFoldManager();
          if (fm.isLineHidden(line)) {
            return -1;
          }
        }
        return r.y;
      }
View Full Code Here

    @Override
    public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
      RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
      if (rsta.isCodeFoldingEnabled()) {
        FoldManager fm = rsta.getFoldManager();
        for (int i=0; i<fm.getFoldCount(); i++) {
          expand(fm.getFold(i));
        }
        possiblyRepaintGutter(rsta);
      }
      else {
        UIManager.getLookAndFeel().provideErrorFeedback(rsta);
View Full Code Here

    }

    protected Fold getClosestFold(RSyntaxTextArea textArea) {
      int offs = textArea.getCaretPosition();
      int line = textArea.getCaretLineNumber();
      FoldManager fm = textArea.getFoldManager();
      Fold fold = fm.getFoldForLine(line);
      if (fold==null) {
        fold = fm.getDeepestOpenFoldContaining(offs);
      }
      return fold;
    }
View Full Code Here

      int line = root.getElementIndex(offs);
      int end = root.getElement(line).getEndOffset() - 1;
      if (offs==end) {// If we're already at the end of the line...
        RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
        if (rsta.isCodeFoldingEnabled()) { // Start of next visible line
          FoldManager fm = rsta.getFoldManager();
          int lineCount = root.getElementCount();
          while (++line<lineCount && fm.isLineHidden(line));
          if (line<lineCount) { // Found a lower visible line
            offs = root.getElement(line).getStartOffset();
          }
          // No lower visible line - we're already at last visible offset
          return offs;
View Full Code Here

   */
  public Token getTokenListForPhysicalLineAbove(int offset) {
    RSyntaxDocument document = (RSyntaxDocument)getDocument();
    Element map = document.getDefaultRootElement();
int line = map.getElementIndex(offset);
FoldManager fm = host.getFoldManager();
if (fm==null) {
  line--;
  if (line>=0) {
    return document.getTokenListForLine(line);
  }
}
else {
  line = fm.getVisibleLineAbove(line);
  if (line>=0) {
    return document.getTokenListForLine(line);
  }
}
//    int line = map.getElementIndex(offset) - 1;
View Full Code Here

  if (line<lineCount-1) {
    return document.getTokenListForLine(line+1);
  }
}
else {
  FoldManager fm = host.getFoldManager();
  line = fm.getVisibleLineBelow(line);
  if (line>=0 && line<lineCount) {
    return document.getTokenListForLine(line);
  }
}
//    int line = map.getElementIndex(offset);
View Full Code Here

      // NOTE:  lineHeight is not initially set here, leading to the
      // current line not being highlighted when a document is first
      // opened.  So, we set it here just in case.
      lineHeight = host!=null ? host.getLineHeight() : lineHeight;
if (host.isCodeFoldingEnabled()) {
  FoldManager fm = host.getFoldManager();
  int hiddenCount = fm.getHiddenLineCountAbove(line);
  line -= hiddenCount;
}
      r = new Rectangle(alloc.x, alloc.y + line*lineHeight,
                  alloc.width, lineHeight);
    }
View Full Code Here

    lineHeight = host.getLineHeight();
    ascent = host.getMaxAscent();//metrics.getAscent();
    int heightAbove = clip.y - alloc.y;
    int linesAbove = Math.max(0, heightAbove / lineHeight);

    FoldManager fm = host.getFoldManager();
    linesAbove += fm.getHiddenLineCountAbove(linesAbove, true);
    Rectangle lineArea = lineToRect(a, linesAbove);
    int y = lineArea.y + ascent;
    int x = lineArea.x;
    Element map = getElement();
    int lineCount = map.getElementCount();

    // Whether token styles should always be painted, even in selections
    int selStart = host.getSelectionStart();
    int selEnd = host.getSelectionEnd();
    boolean useSelectedTextColor = host.getUseSelectedTextColor();

    RSyntaxTextAreaHighlighter h =
          (RSyntaxTextAreaHighlighter)host.getHighlighter();

    Graphics2D g2d = (Graphics2D)g;
    Token token;
    //System.err.println("Painting lines: " + linesAbove + " to " + (endLine-1));

    TokenPainter painter = host.getTokenPainter();
    int line = linesAbove;
    //int count = 0;
    while (y<clip.y+clip.height+ascent && line<lineCount) {

      Fold fold = fm.getFoldForLine(line);
      Element lineElement = map.getElement(line);
      int startOffset = lineElement.getStartOffset();
      //int endOffset = (line==lineCount ? lineElement.getEndOffset()-1 :
      //              lineElement.getEndOffset()-1);
      int endOffset = lineElement.getEndOffset()-1; // Why always "-1"?
      h.paintLayeredHighlights(g2d, startOffset, endOffset,
                a, host, this);
 
      // Paint a line of text.
      token = document.getTokenListForLine(line);
      if (!useSelectedTextColor || selStart==selEnd ||
          (startOffset>=selEnd || endOffset<selStart)) {
        drawLine(painter, token, g2d, x,y);
      }
      else {
        //System.out.println("Drawing line with selection: " + line);
        drawLineWithSelection(painter,token,g2d, x,y, selStart, selEnd);
      }

      if (fold!=null && fold.isCollapsed()) {

        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c!=null) {
          g.setColor(c);
          g.drawLine(x,y+lineHeight-ascent-1,
              host.getWidth(),y+lineHeight-ascent-1);
        }

        // Skip to next line to paint, taking extra care for lines with
        // block ends and begins together, e.g. "} else {"
        do {
          int hiddenLineCount = fold.getLineCount();
          if (hiddenLineCount==0) {
            // Fold parser identified a zero-line fold region.
            // This is really a bug, but we'll be graceful here
            // and avoid an infinite loop.
            break;
          }
          line += hiddenLineCount;
          fold = fm.getFoldForLine(line);
        } while (fold!=null && fold.isCollapsed());

      }

      y += lineHeight;
View Full Code Here

TOP

Related Classes of org.fife.ui.rsyntaxtextarea.folding.FoldManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.