Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
  @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);
  }
Ejemplo n.º 3
0
  @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;
  }
Ejemplo n.º 4
0
 @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());
 }