コード例 #1
0
 /**
  * When leaf Views (such as LabelView) are rendering they should call into this method. If a
  * highlight is in the given region it will be drawn immediately.
  *
  * @param g Graphics used to draw
  * @param p0 starting offset of view
  * @param p1 ending offset of view
  * @param viewBounds Bounds of View
  * @param editor JTextComponent
  * @param view View instance being rendered
  */
 public void paintLayeredHighlights(
     Graphics g, int p0, int p1, Shape viewBounds, JTextComponent editor, View view) {
   for (int counter = highlights.size() - 1; counter >= 0; counter--) {
     HighlightInfo tag = highlights.elementAt(counter);
     if (tag instanceof LayeredHighlightInfo) {
       LayeredHighlightInfo lhi = (LayeredHighlightInfo) tag;
       int start = lhi.getStartOffset();
       int end = lhi.getEndOffset();
       if ((p0 < start && p1 > start) || (p0 >= start && p0 < end)) {
         lhi.paintLayeredHighlights(g, p0, p1, viewBounds, editor, view);
       }
     }
   }
 }
コード例 #2
0
  /**
   * Changes a highlight.
   *
   * @param tag the highlight tag
   * @param p0 the beginning of the range &gt;= 0
   * @param p1 the end of the range &gt;= p0
   * @exception BadLocationException if the specified location is invalid
   */
  public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException {
    if (p0 < 0) {
      throw new BadLocationException("Invalid beginning of the range", p0);
    }

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

    Document doc = component.getDocument();
    if (tag instanceof LayeredHighlightInfo) {
      LayeredHighlightInfo lhi = (LayeredHighlightInfo) tag;
      if (lhi.width > 0 && lhi.height > 0) {
        component.repaint(lhi.x, lhi.y, lhi.width, lhi.height);
      }
      // Mark the highlights region as invalid, it will reset itself
      // next time asked to paint.
      lhi.width = lhi.height = 0;
      lhi.p0 = doc.createPosition(p0);
      lhi.p1 = doc.createPosition(p1);
      safeDamageRange(Math.min(p0, p1), Math.max(p0, p1));
    } else {
      HighlightInfo info = (HighlightInfo) tag;
      int oldP0 = info.p0.getOffset();
      int oldP1 = info.p1.getOffset();
      if (p0 == oldP0) {
        safeDamageRange(Math.min(oldP1, p1), Math.max(oldP1, p1));
      } else if (p1 == oldP1) {
        safeDamageRange(Math.min(p0, oldP0), Math.max(p0, oldP0));
      } else {
        safeDamageRange(oldP0, oldP1);
        safeDamageRange(p0, p1);
      }
      info.p0 = doc.createPosition(p0);
      info.p1 = doc.createPosition(p1);
    }
  }