if (r0 == null || r1 == null) return;  if (color == null) g.setColor(c.getSelectionColor()); else g.setColor(color);   if (r0.y == r1.y) { r0.width = r1.x - r0.x; paintHighlight(g, r0); return; }   r0.width = rect.x + rect.width - r0.x; paintHighlight(g, r0);    r0.y += r0.height; r0.x = rect.x; r0.width = rect.width;  while (r0.y < r1.y) { paintHighlight(g, r0); r0.y += r0.height; }     r0.width = r1.x + r1.width - 1; paintHighlight(g, r0);
Rectangle l0 = ui.modelToView(t, p0, null); Rectangle l1 = ui.modelToView(t, p1, null);  if (l0.y == l1.y) paintHighlight(g, l0.union(l1)); else {          l0.width = rect.width - l0.x; paintHighlight(g, l0);  int posBelow = Utilities.getPositionBelow(t, p0, l0.x); int p1RowStart = Utilities.getRowStart(t, p1); if (posBelow != -1 && posBelow != p0 && Utilities.getRowStart(t, posBelow) != p1RowStart) { Rectangle grow = ui.modelToView(t, posBelow); grow.x = rect.x; grow.width = rect.width;   int nextPosBelow = posBelow; while (nextPosBelow != -1 && Utilities.getRowStart(t, nextPosBelow) != p1RowStart) { posBelow = nextPosBelow; nextPosBelow = Utilities.getPositionBelow(t, posBelow, l0.x);  if (nextPosBelow == posBelow) break; }       Rectangle end = ui.modelToView(t, posBelow); grow.height = end.y + end.height - grow.y;  paintHighlight(g, grow); }   l1.width = l1.x + l1.width - rect.x; l1.x = rect.x; paintHighlight(g, l1); } } catch (BadLocationException ex) { AssertionError err = new AssertionError("Unexpected bad location exception"); err.initCause(ex); throw err; }
    public void paint(Graphics g, int p0, int p1, Shape bounds,		      JTextComponent c)    {      Rectangle r0 = null;      Rectangle r1 = null;      Rectangle rect = bounds.getBounds();            try	{	  r0 = c.modelToView(p0);	  r1 = c.modelToView(p1);	}      catch (BadLocationException e)        {	  // This should never occur.          return;	}      if (r0 == null || r1 == null)	return;      if (color == null)	g.setColor(c.getSelectionColor());      else	g.setColor(color);      // Check if only one line to highlight.      if (r0.y == r1.y)	{	  r0.width = r1.x - r0.x;	  paintHighlight(g, r0);	  return;	}      // First line, from p0 to end-of-line.      r0.width = rect.x + rect.width - r0.x;      paintHighlight(g, r0);            // FIXME: All the full lines in between, if any (assumes that all lines      // have the same height -- not a good assumption with JEditorPane/JTextPane).      r0.y += r0.height;      r0.x = rect.x;      r0.width = rect.width;      while (r0.y < r1.y)	{	  paintHighlight(g, r0);	  r0.y += r0.height;	}      // Last line, from beginning-of-line to p1.      // The "-1" is neccessary else we would paint one pixel column more      // than in the case where the selection is only on one line.       r0.width = r1.x + r1.width - 1;      paintHighlight(g, r0);    }