private boolean hasTextAt(StyledDocument document, int x, int y) {
    Element element = document.getCharacterElement(viewToModel(new Point(x, y)));
    try {
      String text = document.getText(element.getStartOffset(), element.getEndOffset() - element.getStartOffset());
      return !text.trim().isEmpty();
    }
    catch (BadLocationException ignored) {
      return false;
    }
  }
private boolean hasTextAt(StyledDocument document, int x, int y)