Package org.fife.ui.rsyntaxtextarea.folding

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


    // 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

    Element root = doc.getDefaultRootElement();
    int topPosition = textArea.viewToModel(
                new Point(visibleRect.x,visibleRect.y));
    int topLine = root.getElementIndex(topPosition);
    int cellHeight = textArea.getLineHeight();
    FoldManager fm = ((RSyntaxTextArea)textArea).getFoldManager();

    // Compute the y at which to begin painting text, taking into account
    // that 1 logical line => at least 1 physical line, so it may be that
    // y<0.  The computed y-value is the y-value of the top of the first
    // (possibly) partially-visible view.
    Rectangle visibleEditorRect = ui.getVisibleEditorRect();
    Rectangle r = LineNumberList.getChildViewBounds(v, topLine,
                        visibleEditorRect);
    int y = r.y;
    y += (cellHeight-collapsedFoldIcon.getIconHeight())/2;

    int visibleBottom = visibleRect.y + visibleRect.height;
    int x = width - 10;
    int line = topLine;
    boolean paintingOutlineLine = foldWithOutlineShowing!=null &&
        foldWithOutlineShowing.containsLine(line);
    int lineCount = root.getElementCount();

    while (y<visibleBottom && line<lineCount) {

      int curLineH = LineNumberList.getChildViewBounds(v, line,
          visibleEditorRect).height;

      if (paintingOutlineLine) {
        g.setColor(getForeground());
        int w2 = width/2;
        if (line==foldWithOutlineShowing.getEndLine()) {
          int y2 = y + curLineH - cellHeight/2;
          g.drawLine(w2,y, w2,y2);
          g.drawLine(w2,y2, width-2,y2);
          paintingOutlineLine = false;
        }
        else {
          g.drawLine(w2,y, w2,y+curLineH);
        }
      }
      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+curLineH);
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.