/**
   * Adds a highlight to the view. Returns a tag that can be used to refer to the highlight.
   *
   * @param p0 the start offset of the range to highlight >= 0
   * @param p1 the end offset of the range to highlight >= p0
   * @param p the painter to use to actually render the highlight
   * @return an object that can be used as a tag to refer to the highlight
   * @exception BadLocationException if the specified location is invalid
   */
  public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p)
      throws BadLocationException {
    if (p0 < 0) {
      throw new BadLocationException("Invalid start offset", p0);
    }

    if (p1 < p0) {
      throw new BadLocationException("Invalid end offset", p1);
    }

    Document doc = component.getDocument();
    HighlightInfo i =
        (getDrawsLayeredHighlights() && (p instanceof LayeredHighlighter.LayerPainter))
            ? new LayeredHighlightInfo()
            : new HighlightInfo();
    i.painter = p;
    i.p0 = doc.createPosition(p0);
    i.p1 = doc.createPosition(p1);
    highlights.addElement(i);
    safeDamageRange(p0, p1);
    return i;
  }