@Override
 public Box getCaretShape() {
   TextLocation caretLocation = getCaretLocation();
   TypedLayout line = getLines().get(caretLocation.line);
   Box caretShape = line.getCaretShape(caretLocation.index);
   caretShape.translate(getXOffset(line), getY(caretLocation));
   return caretShape;
 }
Exemple #2
0
 public int getAbsoluteY(TextLocation location) {
   int height = 0;
   for (int i = 0; i < location.line; i++) {
     TypedLayout layout = getLines().get(i);
     height += layout.getHeightWithLeading();
   }
   return height;
 }
 public TypedLayout getLineAt(int y) {
   int remainingY = y - getYOffset();
   ArrayList<TypedLayout> lines = getLines();
   for (TypedLayout line : lines) {
     int lineHeight = line.getHeight();
     if (lineHeight > remainingY) return line;
     else remainingY -= lineHeight;
   }
   return lines.get(lines.size() - 1);
 }
  @Override
  public Dimension getTextDimensions() {
    if (!hasText()) return new Dimension(0, 0);

    int height = 0;
    int width = 0;
    for (TypedLayout layout : getLines()) {
      height += layout.getHeight();
      int lineWidth = layout.getWidth();
      if (lineWidth > width) width = lineWidth;
    }
    return new Dimension(width, height);
  }
 @Override
 public TextLocation getLocationAt(Point point) {
   int remainingY = point.y - getYOffset();
   ArrayList<TypedLayout> lines = getLines();
   for (int lineNumber = 0; lineNumber < lines.size(); lineNumber++) {
     TypedLayout line = lines.get(lineNumber);
     int lineHeight = line.getHeight();
     if (lineHeight > remainingY) {
       int lineIndex = line.getIndexAt(point.x - getXOffset(line));
       return TextLocation.at(lineNumber, lineIndex);
     } else {
       remainingY -= lineHeight;
     }
   }
   return TextLocation.fromIndex(lines, getText().length());
 }
Exemple #6
0
  public void moveCaretToNewLine(int lineDelta) {
    ArrayList<TypedLayout> lines = getLines();
    int newLineNumber = caretLocation.line + lineDelta;
    if (newLineNumber >= 0 && newLineNumber < lines.size()) {
      TextLocation origin = verticalOrigin != null ? verticalOrigin : caretLocation;
      int desiredX = lines.get(origin.line).getX(origin.index);

      TypedLayout newLine = lines.get(newLineNumber);
      int newIndex = newLine.getIndexAt(desiredX);

      TextLocation newLocation = TextLocation.at(newLineNumber, newIndex);
      setCaretLocation(newLocation);

      verticalOrigin = origin;
    }
  }
  @Override
  public ArrayList<Box> getSelectionRegions() {
    ArrayList<Box> regions = new ArrayList<Box>();

    boolean startsAtCaret = getCaretLocation().before(getSelectionLocation());
    TextLocation start = startsAtCaret ? getCaretLocation() : getSelectionLocation();
    TextLocation end = startsAtCaret ? getSelectionLocation() : getCaretLocation();

    ArrayList<TypedLayout> lines = getLines();
    int y = getY(start);
    for (int i = start.line; i <= end.line; i++) {
      TypedLayout line = lines.get(i);
      int startX = i == start.line ? line.getX(start.index) + getXOffset(line) : 0;
      int endX =
          i == end.line ? line.getX(end.index) + getXOffset(line) : getContainer().getWidth();

      regions.add(new Box(startX, y, endX - startX, line.getHeight()));

      y += line.getHeight() + line.getLeading();
    }

    return regions;
  }
Exemple #8
0
 public int getXOffset(TypedLayout line) {
   HorizontalAlignmentValue horizontalAlignment =
       getContainer().getStyle().getCompiledHorizontalAlignment();
   return horizontalAlignment.getX(line.getWidth(), getContainer().getBounds());
 }
Exemple #9
0
 public void sendCaretToEndOfLine() {
   final TextLocation caret = getCaretLocation();
   TypedLayout caretLine = getLines().get(caret.line);
   setCaretLocation(TextLocation.at(caret.line, caretLine.visibleLength()));
 }