Program: 76650
Project: 76650
Buggy source:
/** 
 * Draw the axes using the current range, label, and title information. If the argument is true, clear the display before redrawing.
 */
public synchronized void drawPlot(Graphics graphics,boolean clearfirst){
  if (graphics == null) {
    System.out.println("String_Node_Str");
    return;
  }
  Thread.yield();
  Rectangle drawRect=bounds();
  graphics.setPaintMode();
  if (clearfirst) {
    graphics.clearRect(0,0,drawRect.width,drawRect.height);
  }
  graphics.setFont(_titlefont);
  FontMetrics tfm=graphics.getFontMetrics();
  graphics.setFont(_superscriptfont);
  FontMetrics sfm=graphics.getFontMetrics();
  graphics.setFont(_labelfont);
  FontMetrics lfm=graphics.getFontMetrics();
  if (_errorMsg != null) {
    int fheight=lfm.getHeight() + 2;
    int msgy=fheight;
    graphics.setColor(Color.black);
    for (int i=0; i < _errorMsg.length; i++) {
      graphics.drawString(_errorMsg[i],10,msgy);
      msgy+=fheight;
    }
    return;
  }
  if (!_xRangeGiven) {
    if (_xBottom > _xTop) {
      _setXRange(0,0);
    }
 else {
      _setXRange(_xBottom,_xTop);
    }
  }
  if (!_yRangeGiven) {
    if (_yBottom > _yTop) {
      _setYRange(0,0);
    }
 else {
      _setYRange(_yBottom,_yTop);
    }
  }
  int titley=0;
  int titlefontheight=tfm.getHeight();
  if (_title != null || _yExp != 0) {
    titley=titlefontheight + _topPadding;
  }
  graphics.setFont(_labelfont);
  int labelheight=lfm.getHeight();
  int halflabelheight=labelheight / 2;
  int ySPos=drawRect.height - 5;
  if (_xExp != 0 && _xticks == null) {
    int xSPos=drawRect.x + drawRect.width - _rightPadding;
    String superscript=Integer.toString(_xExp);
    xSPos-=sfm.stringWidth(superscript);
    graphics.setFont(_superscriptfont);
    graphics.drawString(superscript,xSPos,ySPos - halflabelheight);
    xSPos-=lfm.stringWidth("String_Node_Str");
    graphics.setFont(_labelfont);
    graphics.drawString("String_Node_Str",xSPos,ySPos);
    _bottomPadding=(3 * labelheight) / 2 + 5;
  }
  if (_xlabel != null && _bottomPadding < labelheight + 5) {
    _bottomPadding=titlefontheight + 5;
  }
  _uly=drawRect.y + titley + 5;
  _lry=drawRect.height - labelheight - _bottomPadding- 3;
  int height=_lry - _uly;
  _yscale=height / (_yMax - _yMin);
  _ytickscale=height / (_ytickMax - _ytickMin);
  int ny=2 + height / (labelheight + 10);
  double yStep=_roundUp((_ytickMax - _ytickMin) / (double)ny);
  double yStart=yStep * Math.ceil(_ytickMin / yStep);
  int widesty=0;
  String ylabels[]=new String[ny];
  int ylabwidth[]=new int[ny];
  int ind=0;
  if (_yticks == null) {
    int numfracdigits=_numFracDigits(yStep);
    for (double ypos=yStart; ypos <= _yMax; ypos+=yStep) {
      if (ind >= ny)       break;
      String yl=_formatNum(ypos,numfracdigits);
      ylabels[ind]=yl;
      int lw=lfm.stringWidth(yl);
      ylabwidth[ind++]=lw;
      if (lw > widesty) {
        widesty=lw;
      }
    }
  }
 else {
    Enumeration nl=_yticklabels.elements();
    while (nl.hasMoreElements()) {
      String label=(String)nl.nextElement();
      int lw=lfm.stringWidth(label);
      if (lw > widesty) {
        widesty=lw;
      }
    }
  }
  if (_ylabel != null) {
    _ulx=drawRect.x + widesty + lfm.stringWidth("String_Node_Str")+ _leftPadding;
  }
 else {
    _ulx=drawRect.x + widesty + _leftPadding;
  }
  int legendwidth=_drawLegend(graphics,drawRect.width - _rightPadding,_uly);
  _lrx=drawRect.width - legendwidth - _rightPadding;
  int width=_lrx - _ulx;
  _xscale=width / (_xMax - _xMin);
  _xtickscale=width / (_xtickMax - _xtickMin);
  graphics.setColor(_background);
  graphics.fillRect(_ulx,_uly,width,height);
  graphics.setColor(_foreground);
  graphics.drawRect(_ulx,_uly,width,height);
  int tickLength=5;
  int xCoord1=_ulx + tickLength;
  int xCoord2=_lrx - tickLength;
  if (_yticks == null) {
    ind=0;
    for (double ypos=yStart; ypos <= _ytickMax; ypos+=yStep) {
      if (ind >= ny)       break;
      int yCoord1=_lry - (int)((ypos - _ytickMin) * _ytickscale);
      int offset=0;
      if (ind > 0)       offset=halflabelheight;
      graphics.drawLine(_ulx,yCoord1,xCoord1,yCoord1);
      graphics.drawLine(_lrx,yCoord1,xCoord2,yCoord1);
      if (_grid && yCoord1 != _uly && yCoord1 != _lry) {
        graphics.setColor(Color.lightGray);
        graphics.drawLine(xCoord1,yCoord1,xCoord2,yCoord1);
        graphics.setColor(_foreground);
      }
      graphics.drawString(ylabels[ind],_ulx - ylabwidth[ind++] - 4,yCoord1 + offset);
    }
    if (_yExp != 0) {
      graphics.drawString("String_Node_Str",2,titley);
      graphics.setFont(_superscriptfont);
      graphics.drawString(Integer.toString(_yExp),lfm.stringWidth("String_Node_Str") + 2,titley - halflabelheight);
      graphics.setFont(_labelfont);
    }
  }
 else {
    Enumeration nt=_yticks.elements();
    Enumeration nl=_yticklabels.elements();
    while (nl.hasMoreElements()) {
      String label=(String)nl.nextElement();
      double ypos=((Double)(nt.nextElement())).doubleValue();
      if (ypos > _yMax || ypos < _yMin)       continue;
      int yCoord1=_lry - (int)((ypos - _yMin) * _ytickscale);
      int offset=0;
      if (ypos < _lry - labelheight)       offset=halflabelheight;
      graphics.drawLine(_ulx,yCoord1,xCoord1,yCoord1);
      graphics.drawLine(_lrx,yCoord1,xCoord2,yCoord1);
      if (_grid && yCoord1 != _uly && yCoord1 != _lry) {
        graphics.setColor(Color.lightGray);
        graphics.drawLine(xCoord1,yCoord1,xCoord2,yCoord1);
        graphics.setColor(_foreground);
      }
      graphics.drawString(label,_ulx - lfm.stringWidth(label) - 3,yCoord1 + offset);
    }
  }
  int yCoord1=_uly + tickLength;
  int yCoord2=_lry - tickLength;
  if (_xticks == null) {
    int nx=10;
    double xStep=0.0;
    int numfracdigits=0;
    int charwidth=lfm.stringWidth("String_Node_Str");
    int count=0;
    while (count++ <= 10) {
      xStep=_roundUp((_xtickMax - _xtickMin) / (double)nx);
      numfracdigits=_numFracDigits(xStep);
      int intdigits=_numIntDigits(_xtickMax);
      int inttemp=_numIntDigits(_xtickMin);
      if (intdigits < inttemp) {
        intdigits=inttemp;
      }
      int maxlabelwidth=charwidth * (numfracdigits + 2 + intdigits);
      int savenx=nx;
      nx=2 + width / (maxlabelwidth + 10);
      if (nx - savenx <= 1 || savenx - nx <= 1)       break;
    }
    xStep=_roundUp((_xtickMax - _xtickMin) / (double)nx);
    numfracdigits=_numFracDigits(xStep);
    double xStart=xStep * Math.ceil(_xtickMin / xStep);
    for (double xpos=xStart; xpos <= _xtickMax; xpos+=xStep) {
      String xticklabel=_formatNum(xpos,numfracdigits);
      xCoord1=_ulx + (int)((xpos - _xtickMin) * _xtickscale);
      graphics.drawLine(xCoord1,_uly,xCoord1,yCoord1);
      graphics.drawLine(xCoord1,_lry,xCoord1,yCoord2);
      if (_grid && xCoord1 != _ulx && xCoord1 != _lrx) {
        graphics.setColor(Color.lightGray);
        graphics.drawLine(xCoord1,yCoord1,xCoord1,yCoord2);
        graphics.setColor(_foreground);
      }
      int labxpos=xCoord1 - lfm.stringWidth(xticklabel) / 2;
      graphics.drawString(xticklabel,labxpos,_lry + 3 + labelheight);
    }
  }
 else {
    Enumeration nt=_xticks.elements();
    Enumeration nl=_xticklabels.elements();
    while (nl.hasMoreElements()) {
      String label=(String)nl.nextElement();
      double xpos=((Double)(nt.nextElement())).doubleValue();
      if (xpos > _xMax || xpos < _xMin)       continue;
      xCoord1=_ulx + (int)((xpos - _xtickMin) * _xtickscale);
      graphics.drawLine(xCoord1,_uly,xCoord1,yCoord1);
      graphics.drawLine(xCoord1,_lry,xCoord1,yCoord2);
      if (_grid && xCoord1 != _ulx && xCoord1 != _lrx) {
        graphics.setColor(Color.lightGray);
        graphics.drawLine(xCoord1,yCoord1,xCoord1,yCoord2);
        graphics.setColor(_foreground);
      }
      int labxpos=xCoord1 - lfm.stringWidth(label) / 2;
      graphics.drawString(label,labxpos,_lry + 3 + labelheight);
    }
  }
  graphics.setColor(_foreground);
  if (_title != null) {
    graphics.setFont(_titlefont);
    int titlex=_ulx + (width - tfm.stringWidth(_title)) / 2;
    graphics.drawString(_title,titlex,titley);
  }
  graphics.setFont(_labelfont);
  if (_xlabel != null) {
    int labelx=_ulx + (width - lfm.stringWidth(_xlabel)) / 2;
    graphics.drawString(_xlabel,labelx,ySPos);
  }
  int charcenter=2 + lfm.stringWidth("String_Node_Str") / 2;
  int charheight=labelheight;
  if (_ylabel != null) {
    int yl=_ylabel.length();
    int starty=_uly + (_lry - _uly) / 2 - yl * charheight / 2 + charheight;
    for (int i=0; i < yl; i++) {
      String nchar=_ylabel.substring(i,i + 1);
      int cwidth=lfm.stringWidth(nchar);
      graphics.drawString(nchar,charcenter - cwidth / 2,starty);
      starty+=charheight;
    }
  }
}

Fixed version (ground truth):
/** 
 * Draw the axes using the current range, label, and title information. If the argument is true, clear the display before redrawing.
 */
public synchronized void drawPlot(Graphics graphics,boolean clearfirst){
  if (graphics == null) {
    System.out.println("String_Node_Str");
    return;
  }
  Thread.yield();
  Rectangle drawRect=bounds();
  graphics.setPaintMode();
  if (clearfirst) {
    graphics.clearRect(0,0,drawRect.width,drawRect.height);
  }
  graphics.setFont(_titlefont);
  FontMetrics tfm=graphics.getFontMetrics();
  graphics.setFont(_superscriptfont);
  FontMetrics sfm=graphics.getFontMetrics();
  graphics.setFont(_labelfont);
  FontMetrics lfm=graphics.getFontMetrics();
  if (_errorMsg != null) {
    int fheight=lfm.getHeight() + 2;
    int msgy=fheight;
    graphics.setColor(Color.black);
    for (int i=0; i < _errorMsg.length; i++) {
      graphics.drawString(_errorMsg[i],10,msgy);
      msgy+=fheight;
    }
    return;
  }
  if (!_xRangeGiven) {
    if (_xBottom > _xTop) {
      _setXRange(0,0);
    }
 else {
      _setXRange(_xBottom,_xTop);
    }
  }
  if (!_yRangeGiven) {
    if (_yBottom > _yTop) {
      _setYRange(0,0);
    }
 else {
      _setYRange(_yBottom,_yTop);
    }
  }
  int titley=0;
  int titlefontheight=tfm.getHeight();
  if (_title != null || _yExp != 0) {
    titley=titlefontheight + _topPadding;
  }
  graphics.setFont(_labelfont);
  int labelheight=lfm.getHeight();
  int halflabelheight=labelheight / 2;
  int ySPos=drawRect.height - 5;
  if (_xExp != 0 && _xticks == null) {
    int xSPos=drawRect.x + drawRect.width - _rightPadding;
    String superscript=Integer.toString(_xExp);
    xSPos-=sfm.stringWidth(superscript);
    graphics.setFont(_superscriptfont);
    graphics.drawString(superscript,xSPos,ySPos - halflabelheight);
    xSPos-=lfm.stringWidth("String_Node_Str");
    graphics.setFont(_labelfont);
    graphics.drawString("String_Node_Str",xSPos,ySPos);
    _bottomPadding=(3 * labelheight) / 2 + 5;
  }
  if (_xlabel != null && _bottomPadding < labelheight + 5) {
    _bottomPadding=titlefontheight + 5;
  }
  _uly=drawRect.y + titley + 5;
  _lry=drawRect.height - labelheight - _bottomPadding- 3;
  int height=_lry - _uly;
  _yscale=height / (_yMax - _yMin);
  _ytickscale=height / (_ytickMax - _ytickMin);
  int ny=2 + height / (labelheight + 10);
  double yStep=_roundUp((_ytickMax - _ytickMin) / (double)ny);
  double yStart=yStep * Math.ceil(_ytickMin / yStep);
  int widesty=0;
  String ylabels[]=new String[ny];
  int ylabwidth[]=new int[ny];
  int ind=0;
  if (_yticks == null) {
    int numfracdigits=_numFracDigits(yStep);
    for (double ypos=yStart; ypos <= _ytickMax; ypos+=yStep) {
      if (ind >= ny)       break;
      String yl=_formatNum(ypos,numfracdigits);
      ylabels[ind]=yl;
      int lw=lfm.stringWidth(yl);
      ylabwidth[ind++]=lw;
      if (lw > widesty) {
        widesty=lw;
      }
    }
  }
 else {
    Enumeration nl=_yticklabels.elements();
    while (nl.hasMoreElements()) {
      String label=(String)nl.nextElement();
      int lw=lfm.stringWidth(label);
      if (lw > widesty) {
        widesty=lw;
      }
    }
  }
  if (_ylabel != null) {
    _ulx=drawRect.x + widesty + lfm.stringWidth("String_Node_Str")+ _leftPadding;
  }
 else {
    _ulx=drawRect.x + widesty + _leftPadding;
  }
  int legendwidth=_drawLegend(graphics,drawRect.width - _rightPadding,_uly);
  _lrx=drawRect.width - legendwidth - _rightPadding;
  int width=_lrx - _ulx;
  _xscale=width / (_xMax - _xMin);
  _xtickscale=width / (_xtickMax - _xtickMin);
  graphics.setColor(_background);
  graphics.fillRect(_ulx,_uly,width,height);
  graphics.setColor(_foreground);
  graphics.drawRect(_ulx,_uly,width,height);
  int tickLength=5;
  int xCoord1=_ulx + tickLength;
  int xCoord2=_lrx - tickLength;
  if (_yticks == null) {
    ind=0;
    for (double ypos=yStart; ypos <= _ytickMax; ypos+=yStep) {
      if (ind >= ny)       break;
      int yCoord1=_lry - (int)((ypos - _ytickMin) * _ytickscale);
      int offset=0;
      if (ind > 0)       offset=halflabelheight;
      graphics.drawLine(_ulx,yCoord1,xCoord1,yCoord1);
      graphics.drawLine(_lrx,yCoord1,xCoord2,yCoord1);
      if (_grid && yCoord1 != _uly && yCoord1 != _lry) {
        graphics.setColor(Color.lightGray);
        graphics.drawLine(xCoord1,yCoord1,xCoord2,yCoord1);
        graphics.setColor(_foreground);
      }
      graphics.drawString(ylabels[ind],_ulx - ylabwidth[ind++] - 4,yCoord1 + offset);
    }
    if (_yExp != 0) {
      graphics.drawString("String_Node_Str",2,titley);
      graphics.setFont(_superscriptfont);
      graphics.drawString(Integer.toString(_yExp),lfm.stringWidth("String_Node_Str") + 2,titley - halflabelheight);
      graphics.setFont(_labelfont);
    }
  }
 else {
    Enumeration nt=_yticks.elements();
    Enumeration nl=_yticklabels.elements();
    while (nl.hasMoreElements()) {
      String label=(String)nl.nextElement();
      double ypos=((Double)(nt.nextElement())).doubleValue();
      if (ypos > _yMax || ypos < _yMin)       continue;
      int yCoord1=_lry - (int)((ypos - _yMin) * _ytickscale);
      int offset=0;
      if (ypos < _lry - labelheight)       offset=halflabelheight;
      graphics.drawLine(_ulx,yCoord1,xCoord1,yCoord1);
      graphics.drawLine(_lrx,yCoord1,xCoord2,yCoord1);
      if (_grid && yCoord1 != _uly && yCoord1 != _lry) {
        graphics.setColor(Color.lightGray);
        graphics.drawLine(xCoord1,yCoord1,xCoord2,yCoord1);
        graphics.setColor(_foreground);
      }
      graphics.drawString(label,_ulx - lfm.stringWidth(label) - 3,yCoord1 + offset);
    }
  }
  int yCoord1=_uly + tickLength;
  int yCoord2=_lry - tickLength;
  if (_xticks == null) {
    int nx=10;
    double xStep=0.0;
    int numfracdigits=0;
    int charwidth=lfm.stringWidth("String_Node_Str");
    int count=0;
    while (count++ <= 10) {
      xStep=_roundUp((_xtickMax - _xtickMin) / (double)nx);
      numfracdigits=_numFracDigits(xStep);
      int intdigits=_numIntDigits(_xtickMax);
      int inttemp=_numIntDigits(_xtickMin);
      if (intdigits < inttemp) {
        intdigits=inttemp;
      }
      int maxlabelwidth=charwidth * (numfracdigits + 2 + intdigits);
      int savenx=nx;
      nx=2 + width / (maxlabelwidth + 10);
      if (nx - savenx <= 1 || savenx - nx <= 1)       break;
    }
    xStep=_roundUp((_xtickMax - _xtickMin) / (double)nx);
    numfracdigits=_numFracDigits(xStep);
    double xStart=xStep * Math.ceil(_xtickMin / xStep);
    for (double xpos=xStart; xpos <= _xtickMax; xpos+=xStep) {
      String xticklabel=_formatNum(xpos,numfracdigits);
      xCoord1=_ulx + (int)((xpos - _xtickMin) * _xtickscale);
      graphics.drawLine(xCoord1,_uly,xCoord1,yCoord1);
      graphics.drawLine(xCoord1,_lry,xCoord1,yCoord2);
      if (_grid && xCoord1 != _ulx && xCoord1 != _lrx) {
        graphics.setColor(Color.lightGray);
        graphics.drawLine(xCoord1,yCoord1,xCoord1,yCoord2);
        graphics.setColor(_foreground);
      }
      int labxpos=xCoord1 - lfm.stringWidth(xticklabel) / 2;
      graphics.drawString(xticklabel,labxpos,_lry + 3 + labelheight);
    }
  }
 else {
    Enumeration nt=_xticks.elements();
    Enumeration nl=_xticklabels.elements();
    while (nl.hasMoreElements()) {
      String label=(String)nl.nextElement();
      double xpos=((Double)(nt.nextElement())).doubleValue();
      if (xpos > _xMax || xpos < _xMin)       continue;
      xCoord1=_ulx + (int)((xpos - _xtickMin) * _xtickscale);
      graphics.drawLine(xCoord1,_uly,xCoord1,yCoord1);
      graphics.drawLine(xCoord1,_lry,xCoord1,yCoord2);
      if (_grid && xCoord1 != _ulx && xCoord1 != _lrx) {
        graphics.setColor(Color.lightGray);
        graphics.drawLine(xCoord1,yCoord1,xCoord1,yCoord2);
        graphics.setColor(_foreground);
      }
      int labxpos=xCoord1 - lfm.stringWidth(label) / 2;
      graphics.drawString(label,labxpos,_lry + 3 + labelheight);
    }
  }
  graphics.setColor(_foreground);
  if (_title != null) {
    graphics.setFont(_titlefont);
    int titlex=_ulx + (width - tfm.stringWidth(_title)) / 2;
    graphics.drawString(_title,titlex,titley);
  }
  graphics.setFont(_labelfont);
  if (_xlabel != null) {
    int labelx=_ulx + (width - lfm.stringWidth(_xlabel)) / 2;
    graphics.drawString(_xlabel,labelx,ySPos);
  }
  int charcenter=2 + lfm.stringWidth("String_Node_Str") / 2;
  int charheight=labelheight;
  if (_ylabel != null) {
    int yl=_ylabel.length();
    int starty=_uly + (_lry - _uly) / 2 - yl * charheight / 2 + charheight;
    for (int i=0; i < yl; i++) {
      String nchar=_ylabel.substring(i,i + 1);
      int cwidth=lfm.stringWidth(nchar);
      graphics.drawString(nchar,charcenter - cwidth / 2,starty);
      starty+=charheight;
    }
  }
}