public void paint(Graphics g,Shape a){
  Shape originalA=a;
  a=adjustPaintRegion(a);
  Rectangle alloc=(Rectangle)a;
  tabBase=alloc.x;
  JTextComponent host=(JTextComponent)getContainer();
  Highlighter h=host.getHighlighter();
  g.setFont(host.getFont());
  sel0=host.getSelectionStart();
  sel1=host.getSelectionEnd();
  unselected=(host.isEnabled()) ? host.getForeground() : host.getDisabledTextColor();
  Caret c=host.getCaret();
  selected=c.isSelectionVisible() && h != null ? host.getSelectedTextColor() : unselected;
  updateMetrics();
  Rectangle clip=g.getClipBounds();
  int fontHeight=metrics.getHeight();
  int heightBelow=(alloc.y + alloc.height) - (clip.y + clip.height);
  int heightAbove=clip.y - alloc.y;
  int linesBelow, linesAbove, linesTotal;
  if (fontHeight > 0) {
    linesBelow=Math.max(0,heightBelow / fontHeight);
    linesAbove=Math.max(0,heightAbove / fontHeight);
    linesTotal=alloc.height / fontHeight;
    if (alloc.height % fontHeight != 0) {
      linesTotal++;
    }
  }
 else {
    linesBelow=linesAbove=linesTotal=0;
  }
  Rectangle lineArea=lineToRect(a,linesAbove);
  int y=lineArea.y + metrics.getAscent();
  int x=lineArea.x;
  Element map=getElement();
  int lineCount=map.getElementCount();
  int endLine=Math.min(lineCount,linesTotal - linesBelow);
  lineCount--;
  LayeredHighlighter dh=(h instanceof LayeredHighlighter) ? (LayeredHighlighter)h : null;
  for (int line=linesAbove; line < endLine; line++) {
    if (dh != null) {
      Element lineElement=map.getElement(line);
      if (line == lineCount) {
        dh.paintLayeredHighlights(g,lineElement.getStartOffset(),lineElement.getEndOffset(),originalA,host,this);
      }
 else {
        dh.paintLayeredHighlights(g,lineElement.getStartOffset(),lineElement.getEndOffset() - 1,originalA,host,this);
      }
    }
    drawLine(line,g,x,y);
    y+=fontHeight;
    if (line == 0) {
      x-=firstLineOffset;
    }
  }
}

public void paint ( Graphics g , Shape a ) { Shape originalA = a ; a = adjustPaintRegion ( a ) ; Rectangle alloc = ( Rectangle ) a ; tabBase = alloc . x ; JTextComponent host = ( JTextComponent ) getContainer ( ) ; Highlighter h = host . getHighlighter ( ) ; g . setFont ( host . getFont ( ) ) ; sel0 = host . getSelectionStart ( ) ; sel1 = host . getSelectionEnd ( ) ; unselected = ( host . isEnabled ( ) ) ? host . getForeground ( ) : host . getDisabledTextColor ( ) ; Caret c = host . getCaret ( ) ; selected = c . isSelectionVisible ( ) && h != null ? host . getSelectedTextColor ( ) : unselected ; updateMetrics ( ) ; Rectangle clip = g . getClipBounds ( ) ; int fontHeight = metrics . getHeight ( ) ; int heightBelow = ( alloc . y + alloc . height ) - ( clip . y + clip . height ) ; int heightAbove = clip . y - alloc . y ; int linesBelow , linesAbove , linesTotal ; if ( fontHeight > 0 ) { linesBelow = Math . max ( 0 , heightBelow / fontHeight ) ; linesAbove = Math . max ( 0 , heightAbove / fontHeight ) ; linesTotal = alloc . height / fontHeight ; if ( alloc . height % fontHeight != 0 ) { linesTotal ++ ; } } else { linesBelow = linesAbove = linesTotal = 0 ; } Rectangle lineArea = lineToRect ( a , linesAbove ) ; int y = lineArea . y + metrics . getAscent ( ) ; int x = lineArea . x ; Element map = getElement ( ) ; int lineCount = map . getElementCount ( ) ; int endLine = Math . min ( lineCount , linesTotal - linesBelow ) ; lineCount -- ; LayeredHighlighter dh = ( h instanceof LayeredHighlighter ) ? ( LayeredHighlighter ) h : null ; for ( int line = linesAbove ; line < endLine ; line ++ ) { if ( dh != null ) { Element lineElement = map . getElement ( line ) ; if ( line == lineCount ) { dh . paintLayeredHighlights ( g , lineElement . getStartOffset ( ) , lineElement . getEndOffset ( ) , originalA , host , this ) ; } else { dh . paintLayeredHighlights ( g , lineElement . getStartOffset ( ) , lineElement . getEndOffset ( ) - 1 , originalA , host , this ) ; } } drawLine ( line , g , x , y ) ; y += fontHeight ; if ( line == 0 ) { x -= firstLineOffset ; } } }
renders using the given rendering surface and area on that surface . the view may need to do layout and create child views to enable itself to render into the given allocation .
