Package com.google.collide.shared.document.anchor

Examples of com.google.collide.shared.document.anchor.Anchor


   * @param height the height in pixels of the spacer
   */
  Spacer createSpacer(LineInfo lineInfo, int height, Buffer buffer, String cssClass) {
    int lineNumber = lineInfo.number();
    // create an anchor on the current line
    Anchor anchor =
        document.getAnchorManager().createAnchor(SPACER_ANCHOR_TYPE, lineInfo.line(), lineNumber,
            AnchorManager.IGNORE_COLUMN);
    anchor.setRemovalStrategy(RemovalStrategy.SHIFT);
    // account for the height of the line the spacer is on
    Spacer spacer = new Spacer(anchor, height, this, buffer, cssClass);
    spacers.add(spacer);
    totalSpacerHeight += height;
    invalidateLineNumberAndFollowing(lineNumber);
View Full Code Here


  /**
   * Returns a cached {@link LineInfo} for this {@link Line} if it exists, or
   * null.
   */
  public static LineInfo getCachedLineInfo(Line line) {
    Anchor anchorWithLineNumber =
        line.getDocument().getAnchorManager().findAnchorWithLineNumber(line);
    return anchorWithLineNumber != null ? anchorWithLineNumber.getLineInfo() : null;
  }
View Full Code Here

  }

  private void handleLineEnteredViewport(Line line, int lineNumber, Element lineElement) {
    assert line.getTag(LINE_TAG_LINE_NUMBER_CACHE_ANCHOR) == null;

    Anchor anchor =
        line.getDocument()
            .getAnchorManager()
            .createAnchor(VIEWPORT_RENDERER_ANCHOR_TYPE, line, lineNumber,
                AnchorManager.IGNORE_COLUMN);
View Full Code Here

      buffer.setMaxLineLength(lineLength);
    }
  }

  private void handleLineLeftViewport(Line line) {
    Anchor anchor = line.getTag(LINE_TAG_LINE_NUMBER_CACHE_ANCHOR);
    if (anchor == null) {
      /*
       * The line was in the viewport when the change occurred, but never
       * rendered with it there, so it never got a line number cache anchor
       * assigned
 
View Full Code Here

  /**
   * Returns a cached line number for this line if it exists, or -1.
   */
  public static int getCachedLineNumber(Line line) {
    Anchor anchorWithLineNumber =
        line.getDocument().getAnchorManager().findAnchorWithLineNumber(line);
    return anchorWithLineNumber != null ? anchorWithLineNumber.getLineNumber() : -1;
  }
View Full Code Here

  private void calculateNextChunk() {
    // Get the previous anchor for this line
    AnchorManager anchorManager = document.getAnchorManager();

    if (prevAnchor == null) {
      Anchor startSearchAnchor = document.getAnchorManager().createAnchor(
          START_SEARCH_ANCHOR_TYPE, line, AnchorManager.IGNORE_LINE_NUMBER, 1);
      prevAnchor = document.getAnchorManager().getPreviousAnchor(startSearchAnchor, anchorType);
      document.getAnchorManager().removeAnchor(startSearchAnchor);
      if (prevAnchor == null) {
        return;
      }
    } else {
      // We have hit an anchor on this line already, get the next one.
      prevAnchor = anchorManager.getNextAnchor(prevAnchor, anchorType);
    }

    Anchor nextAnchor = anchorManager.getNextAnchor(prevAnchor, anchorType);
    if (nextAnchor != null && nextAnchor.getLine() == line) {
      nextChunkLength = nextAnchor.getColumn() - linePosition;
    } else {
      nextChunkLength = line.getText().length() - linePosition;
    }

    assert (nextChunkLength >= 0) : "Got a negative chunk length";
View Full Code Here

    return selection;
  }

  private Anchor createSelectionAnchor(Line line, int lineNumber, int column, Document document,
      AnchorListener anchorListener) {
    Anchor anchor =
        document.getAnchorManager().createAnchor(SELECTION_ANCHOR_TYPE, line, lineNumber, column);
    anchor.setRemovalStrategy(Anchor.RemovalStrategy.SHIFT);
    anchor.getShiftListenerRegistrar().add(anchorListener);
    return anchor;
  }
View Full Code Here

  public Position[] getSelectionRange(boolean inclusiveEnd) {
    Preconditions.checkArgument(
        hasSelection() || !inclusiveEnd, "There must be a selection if inclusiveEnd is requested.");
    Position[] selection = new Position[2];

    Anchor beginAnchor = getEarlierSelectionAnchor();
    Anchor endAnchor = getLaterSelectionAnchor();

    selection[0] = new Position(beginAnchor.getLineInfo(), beginAnchor.getColumn());

    if (inclusiveEnd) {
      Preconditions.checkState(hasSelection(),
          "Can't get selection range inclusive end when nothing is selected");
      selection[1] =
          PositionUtils.getPosition(endAnchor.getLine(), endAnchor.getLineNumber(),
              endAnchor.getColumn(), -1);
    } else {
      selection[1] = new Position(endAnchor.getLineInfo(), endAnchor.getColumn());
    }

    return selection;
  }
View Full Code Here

        newGrowForward && AnchorUtils.compare(baseAnchor, minimumDragSelectionUpperBound) >= 0;
    boolean newSelectionIsBehindMinimum =
        !newGrowForward && AnchorUtils.compare(baseAnchor, minimumDragSelectionLowerBound) <= 0;

    // Move base anchor to correct minimum selection bound
    Anchor newBaseAnchorPosition = null;
    if (newSelectionIsBehindMinimum) {
      newBaseAnchorPosition = minimumDragSelectionUpperBound;
    } else if (newSelectionIsAheadOfMinimum) {
      newBaseAnchorPosition = minimumDragSelectionLowerBound;
    }

    if (newBaseAnchorPosition != null) {
      moveAnchor(baseAnchor, newBaseAnchorPosition.getLineInfo(),
          newBaseAnchorPosition.getColumn(), false);
    }
  }
View Full Code Here

   * Sets specified strategy to earlier selection anchor and runs routine;
   * initial strategy is restored before return.
   */
  private void runWithEarlierAnchorPlacementStrategy(InsertionPlacementStrategy strategy,
      Runnable runnable) {
    Anchor earlierSelectionAnchor = getEarlierSelectionAnchor();
    InsertionPlacementStrategy existingInsertionPlacementStrategy =
        earlierSelectionAnchor.getInsertionPlacementStrategy();
    earlierSelectionAnchor.setInsertionPlacementStrategy(strategy);

    try {
      runnable.run();
    } finally {
      earlierSelectionAnchor.setInsertionPlacementStrategy(existingInsertionPlacementStrategy);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.collide.shared.document.anchor.Anchor

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.