Package org.fife.ui.rsyntaxtextarea.folding

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


      Point p = e.getPoint();
      int line = rowAtPoint(p);

      RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
      FoldManager fm = rsta.getFoldManager();

      Fold fold = fm.getFoldForLine(line);
      if (fold!=null) {
        fold.toggleCollapsedState();
        getGutter().repaint();
        textArea.repaint();
      }
View Full Code Here


          pos = Math.max(0, pos - 1);
          if (target.isCodeFoldingEnabled()) {
            int last = target.getLineOfOffset(pos+1);
            int current = target.getLineOfOffset(pos);
            if (last!=current) { // If moving up a line...
              FoldManager fm = target.getFoldManager();
              if (fm.isLineHidden(current)) {
                while (--current>0 && fm.isLineHidden(current));
                pos = target.getLineEndOffset(current) - 1;
              }
            }
          }
        }
        break;

      case EAST:
        if(pos == -1) {
          pos = view.getStartOffset();
        }
        else {
          pos = Math.min(pos + 1, view.getDocument().getLength());
          if (target.isCodeFoldingEnabled()) {
            int last = target.getLineOfOffset(pos-1);
            int current = target.getLineOfOffset(pos);
            if (last!=current) { // If moving down a line...
              FoldManager fm = target.getFoldManager();
              if (fm.isLineHidden(current)) {
                int lineCount = target.getLineCount();
                while (++current<lineCount && fm.isLineHidden(current));
                pos = current==lineCount ?
                    target.getLineEndOffset(last)-1 : // Was the last visible line
                    target.getLineStartOffset(current);
              }
            }
View Full Code Here

    // A line containing only Token.NULL is an empty line.
    else if (token.type==Token.NULL) {
      int line = c.getLineOfOffset(offs)// Sure to be > c.getLineCount()-1 ??
//      return c.getLineStartOffset(line+1);
FoldManager fm = c.getFoldManager();
line = fm.getVisibleLineBelow(line);
return c.getLineStartOffset(line);
    }

    else {
      return token.getListOffset(c, e, 0, x);
View Full Code Here

    textAreaInsets = textArea.getInsets(textAreaInsets);
    actualTopY += textAreaInsets.top;
    int y = actualTopY + ascent;

    // Get the actual first line to paint, taking into account folding.
    FoldManager fm = null;
    if (textArea instanceof RSyntaxTextArea) {
      fm = ((RSyntaxTextArea)textArea).getFoldManager();
      topLine += fm.getHiddenLineCountAbove(topLine, true);
    }
    final int RHS_BORDER_WIDTH = getRhsBorderWidth();

/*
    // Highlight the current line's line number, if desired.
    if (textArea.getHighlightCurrentLine() && currentLine>=topLine &&
        currentLine<=bottomLine) {
      g.setColor(textArea.getCurrentLineHighlightColor());
      g.fillRect(0,actualTopY+(currentLine-topLine)*cellHeight,
            cellWidth,cellHeight);
    }
*/

    // Paint line numbers
    g.setColor(getForeground());
    boolean ltr = getComponentOrientation().isLeftToRight();
    if (ltr) {
      FontMetrics metrics = g.getFontMetrics();
      int rhs = getWidth() - RHS_BORDER_WIDTH;
      int line = topLine + 1;
      while (y<visibleRect.y+visibleRect.height+ascent && line<=textArea.getLineCount()) {
        String number = Integer.toString(line + getLineNumberingStartIndex() - 1);
        int width = metrics.stringWidth(number);
        g.drawString(number, rhs-width,y);
        y += cellHeight;
        Fold fold = fm.getFoldForLine(line-1);
        // Skip to next line to paint, taking extra care for lines with
        // block ends and begins together, e.g. "} else {"
        while (fold!=null && fold.isCollapsed()) {
          int hiddenLineCount = fold.getLineCount();
          if (hiddenLineCount==0) {
            // Fold parser identified a 0-line fold region... This
            // is really a bug, but we'll handle it gracefully.
            break;
          }
          line += hiddenLineCount;
          fold = fm.getFoldForLine(line-1);
        }
        line++;
      }
    }
    else { // rtl
      int line = topLine + 1;
      while (y<visibleRect.y+visibleRect.height && line<textArea.getLineCount()) {
        String number = Integer.toString(line + getLineNumberingStartIndex() - 1);
        g.drawString(number, RHS_BORDER_WIDTH, y);
        y += cellHeight;
        Fold fold = fm.getFoldForLine(line-1);
        // Skip to next line to paint, taking extra care for lines with
        // block ends and begins together, e.g. "} else {"
        while (fold!=null && fold.isCollapsed()) {
          line += fold.getLineCount();
          fold = fm.getFoldForLine(line);
        }
        line++;
      }
    }

View Full Code Here

    Element root = doc.getDefaultRootElement();
    int lineCount = root.getElementCount();
    int topPosition = textArea.viewToModel(
                new Point(visibleRect.x,visibleRect.y));
    int topLine = root.getElementIndex(topPosition);
    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;
    final int RHS_BORDER_WIDTH = getRhsBorderWidth();
    int rhs;
    boolean ltr = getComponentOrientation().isLeftToRight();
    if (ltr) {
      rhs = width - RHS_BORDER_WIDTH;
    }
    else { // rtl
      rhs = RHS_BORDER_WIDTH;
    }
    int visibleBottom = visibleRect.y + visibleRect.height;
    FontMetrics metrics = g.getFontMetrics();

    // Keep painting lines until our y-coordinate is past the visible
    // end of the text area.
    g.setColor(getForeground());

    while (y < visibleBottom) {

      r = LineNumberList.getChildViewBounds(v, topLine, visibleEditorRect);

      /*
      // Highlight the current line's line number, if desired.
      if (currentLineHighlighted && topLine==currentLine) {
        g.setColor(textArea.getCurrentLineHighlightColor());
        g.fillRect(0,y, width,(r.y+r.height)-y);
        g.setColor(getForeground());
      }
      */

      // Paint the line number.
      int index = (topLine+1) + getLineNumberingStartIndex() - 1;
      String number = Integer.toString(index);
      if (ltr) {
        int strWidth = metrics.stringWidth(number);
        g.drawString(number, rhs-strWidth,y+ascent);
      }
      else {
        int x = RHS_BORDER_WIDTH;
        g.drawString(number, x, y+ascent);
      }

      // The next possible y-coordinate is just after the last line
      // painted.
      y += r.height;

      // Update topLine (we're actually using it for our "current line"
      // variable now).
      Fold fold = fm.getFoldForLine(topLine);
      if (fold!=null && fold.isCollapsed()) {
        topLine += fold.getCollapsedLineCount();
      }
      topLine++;
      if (topLine>=lineCount)
View Full Code Here

    }

    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

            RSyntaxTextArea rsta = (RSyntaxTextArea)getTextArea();
            if (rsta.isCodeFoldingEnabled()) {

              int lastDot = getDot();
              FoldManager fm = rsta.getFoldManager();
              int line = 0;
              try {
                line = textArea.getLineOfOffset(dot);
              } catch (Exception e) {
                e.printStackTrace();
              }

              if (fm.isLineHidden(line)) {

                //System.out.println("filterBypass: avoiding hidden line");
                try {
                  if (dot>lastDot) { // Moving to further line
                    int lineCount = textArea.getLineCount();
                    while (++line<lineCount &&
                        fm.isLineHidden(line));
                      if (line<lineCount) {
                        dot = textArea.getLineStartOffset(line);
                      }
                      else { // No lower lines visible
                        UIManager.getLookAndFeel().
                            provideErrorFeedback(textArea);
                        return;
                      }
                  }
                  else if (dot<lastDot) { // Moving to earlier line
                    while (--line>=0 && fm.isLineHidden(line));
                    if (line>=0) {
                      dot = textArea.getLineEndOffset(line) - 1;
                    }
                  }
            } catch (Exception e) {
View Full Code Here

                        int end) {

    boolean foldsExpanded = false;
    if (textArea instanceof RSyntaxTextArea) {
      RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
      FoldManager fm = rsta.getFoldManager();
      if (fm.isCodeFoldingSupportedAndEnabled()) {
        foldsExpanded = fm.ensureOffsetNotInClosedFold(start);
        foldsExpanded |= fm.ensureOffsetNotInClosedFold(end);
      }
    }

    textArea.setSelectionStart(start);
    textArea.setSelectionEnd(end);
View Full Code Here

   */
  public Shape getChildAllocationImpl(int line, Shape a) {

    Rectangle alloc = getInsideAllocation(a);
    host = (RSyntaxTextArea)getContainer();
    FoldManager fm = host.getFoldManager();
    int y = alloc.y;

    // TODO: Make cached getOffset() calls for Y_AXIS valid even for
    // folding, to speed this up!
    for (int i=0; i<line; i++) {
      y += getSpan(Y_AXIS, i);
      Fold fold = fm.getFoldForLine(i);
      if (fold!=null && fold.isCollapsed()) {
        i += fold.getCollapsedLineCount();
      }
    }

View Full Code Here

      host = (RSyntaxTextArea)getContainer();
      if (host.isCodeFoldingEnabled()) {
        // TODO: Cache y-offsets again to speed this up
        //System.out.println("y-axis baby");
        int lineCount = host.getLineCount();
        FoldManager fm = host.getFoldManager();
        for (int i=0; i<lineCount; i++) {
          if (fm.isLineHidden(i)) {
            span -= getSpan(View.Y_AXIS, i);
          }
        }
      }
    }
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.