Package org.fife.ui.rsyntaxtextarea.folding

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


    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();

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

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


    int line = linesAbove;
//int count = 0;
    while (y<clip.y+clip.height+lineHeight && 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);
      drawLine(token, g2d, x,y);

      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,
              alloc.width,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


    // we can position to.
    else {

      Element map = doc.getDefaultRootElement();
      int lineIndex = Math.abs((y - alloc.y) / lineHeight);//metrics.getHeight() );
FoldManager fm = host.getFoldManager();
//System.out.print("--- " + lineIndex);
lineIndex += fm.getHiddenLineCountAbove(lineIndex, true);
//System.out.println(" => " + lineIndex);
      if (lineIndex >= map.getElementCount()) {
        return host.getLastVisibleOffset();
      }
View Full Code Here

    if (metrics != null) {
      // 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;
      FoldManager fm = host.getFoldManager();
      if (!fm.isLineHidden(line)) {
        line -= fm.getHiddenLineCountAbove(line);
        return alloc.y + line*lineHeight;
      }
    }

    return -1;
View Full Code Here

    // When line wrap is not enabled, take the faster code path.
    if (textArea==null) {
      return;
    }
    RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
    FoldManager fm = rsta.getFoldManager();
    if (!fm.isCodeFoldingSupportedAndEnabled()) {
      super.paintComponent(g);
      return;
    }

    visibleRect = g.getClipBounds(visibleRect);
    if (visibleRect==null) { // ???
      visibleRect = getVisibleRect();
    }
    //System.out.println("IconRowHeader repainting: " + visibleRect);
    if (visibleRect==null) {
      return;
    }

    g.setColor(getBackground());
    g.fillRect(0,visibleRect.y, width,visibleRect.height);

    if (textArea.getLineWrap()) {
      paintComponentWrapped(g);
      return;
    }

    Document doc = textArea.getDocument();
    Element root = doc.getDefaultRootElement();
    textAreaInsets = textArea.getInsets(textAreaInsets);

    // Get the first line to paint.
    int cellHeight = textArea.getLineHeight();
    int topLine = (visibleRect.y-textAreaInsets.top)/cellHeight;

    // Get where to start painting (top of the row).
    // We need to be "scrolled up" up just enough for the missing part of
    // the first line.
    int y = topLine*cellHeight + textAreaInsets.top;

    // AFTER calculating visual offset to paint at, account for folding.
    topLine += fm.getHiddenLineCountAbove(topLine, true);

    // Paint the active line range.
    if (activeLineRangeStart>-1 && activeLineRangeEnd>-1) {
      Color activeLineRangeColor = getActiveLineRangeColor();
      g.setColor(activeLineRangeColor);
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

      int line = root.getElementIndex(offs);
      int start = root.getElement(line).getStartOffset();
      if (offs==start) {// If we're already at the start of the line...
        RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
        if (rsta.isCodeFoldingEnabled()) { // End of next visible line
          FoldManager fm = rsta.getFoldManager();
          while (--line>=0 && fm.isLineHidden(line));
          if (line>=0) { // Found an earlier visible line
            offs = root.getElement(line).getEndOffset() - 1;
          }
          // No earlier visible line - we must be at offs==0...
          return offs;
View Full Code Here

    if (rsta.isCodeFoldingEnabled()) { // Should always be true
      int offs = rsta.viewToModel(p); // TODO: Optimize me
      if (offs>-1) {
        try {
          int line = rsta.getLineOfOffset(offs);
          FoldManager fm = rsta.getFoldManager();
          fold = fm.getFoldForLine(line);
          if (fold==null) {
            fold = fm.getDeepestOpenFoldContaining(offs);
          }
        } catch (BadLocationException ble) {
          ble.printStackTrace(); // Never happens
        }
      }
View Full Code Here

    String text = null;

    RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
    if (rsta.isCodeFoldingEnabled()) {
      FoldManager fm = rsta.getFoldManager();
      int pos = rsta.viewToModel(new Point(0, e.getY()));
      if (pos>=0) { // Not -1
        int line = 0;
        try {
          line = rsta.getLineOfOffset(pos);
        } catch (BadLocationException ble) {
          ble.printStackTrace(); // Never happens
          return null;
        }
        Fold fold = fm.getFoldForLine(line);
        if (fold!=null && fold.isCollapsed()) {

          int endLine = fold.getEndLine();
          if (fold.getLineCount()>25) { // Not too big
            endLine = fold.getStartLine() + 25;
View Full Code Here

    if (textAreaInsets!=null) {
      y += textAreaInsets.top;
    }

    // Get the first and last lines to paint.
    FoldManager fm = rsta.getFoldManager();
    topLine += fm.getHiddenLineCountAbove(topLine, true);

    int width = getWidth();
    int x = width - 10;
    int line = topLine;
    boolean paintingOutlineLine = foldWithOutlineShowing!=null &&
        foldWithOutlineShowing.containsLine(line);

    while (y<visibleRect.y+visibleRect.height) {
      if (paintingOutlineLine) {
        g.setColor(getForeground());
        int w2 = width/2;
        if (line==foldWithOutlineShowing.getEndLine()) {
          int y2 = y+cellHeight/2;
          g.drawLine(w2,y, w2,y2);
          g.drawLine(w2,y2, width-2,y2);
          paintingOutlineLine = false;
        }
        else {
          g.drawLine(w2,y, w2,y+cellHeight);
        }
      }
      Fold fold = fm.getFoldForLine(line);
      if (fold!=null) {
        if (fold==foldWithOutlineShowing && !fold.isCollapsed()) {
          g.setColor(getForeground());
          int w2 = width/2;
          g.drawLine(w2,y+cellHeight/2, w2,y+cellHeight);
          paintingOutlineLine = true;
        }
        if (fold.isCollapsed()) {
          collapsedFoldIcon.paintIcon(this, g, x, y);
          // 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());
        }
        else {
          expandedFoldIcon.paintIcon(this, g, x, y);
        }
View Full Code Here

TOP

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

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.