int h = getHeight(); int w = getWidth();
int h = this.getHeight(); int w = this.getWidth();
    private void paintAxis(Graphics gx) {      setFonts(gx);      Graphics classPgx = m_classPanel.getGraphics();      int mxs = m_XaxisStart;      int mxe = m_XaxisEnd;      int mys = m_YaxisStart;      int mye = m_YaxisEnd;      m_axisChanged = false;      int h = getHeight();      int w = getWidth();      int hf = m_labelMetrics.getAscent();      int mswx=0;      int mswy=0;      //      determineBounds();      int fieldWidthX = (int)((Math.log(m_maxX)/Math.log(10)))+1;      int precisionX = 1;      if ((Math.abs(m_maxX-m_minX) < 1) && ((m_maxY-m_minX) != 0)) {	precisionX = (int)Math.abs(((Math.log(Math.abs(m_maxX-m_minX)) / 				     Math.log(10))))+1;      }      String maxStringX = Utils.doubleToString(m_maxX,					       fieldWidthX+1+precisionX					       ,precisionX);      mswx = m_labelMetrics.stringWidth(maxStringX);      int fieldWidthY = (int)((Math.log(m_maxY)/Math.log(10)))+1;      int precisionY = 1;      if (Math.abs((m_maxY-m_minY)) < 1 && ((m_maxY-m_minY) != 0)) {	precisionY = (int)Math.abs(((Math.log(Math.abs(m_maxY-m_minY)) / 				     Math.log(10))))+1;      }      String maxStringY = Utils.doubleToString(m_maxY,					       fieldWidthY+1+precisionY					       ,precisionY);      String minStringY = Utils.doubleToString(m_minY,					       fieldWidthY+1+precisionY					       ,precisionY);      if (m_plotInstances.attribute(m_yIndex).isNumeric()) {	mswy = (m_labelMetrics.stringWidth(maxStringY) > 		m_labelMetrics.stringWidth(minStringY))	  ? m_labelMetrics.stringWidth(maxStringY)	  : m_labelMetrics.stringWidth(minStringY);      } else {	mswy = m_labelMetrics.stringWidth("MM");      }      m_YaxisStart = m_axisPad;      m_XaxisStart = 0+m_axisPad+m_tickSize+mswy;      m_XaxisEnd = w-m_axisPad-(mswx/2);            m_YaxisEnd = h-m_axisPad-(2 * hf)-m_tickSize;      //I'm putting my draw shapes here because they rely       //on the m_axis values but also need to be painted first      drawShapes(gx);      // draw the class legend      m_attrib.setColor(m_cIndex, m_maxC, m_minC);      if ((!m_colourUsingPreds) && 	  m_plotInstances.attribute(m_cIndex).isNumeric()) {	m_classPanel.setNumeric(m_maxC, m_minC);      } else { //if ((!m_colourUsingPreds) && 	//m_plotInstances.attribute(m_cIndex).isNominal()) {	m_classPanel.setNominal(m_plotInstances, m_cIndex);	newColorAttribute(m_cIndex, m_plotInstances);      }      // draw axis      gx.setColor(Color.green);      if (m_plotInstances.attribute(m_xIndex).isNumeric()) {	if (w > (2 * mswx)) {	  gx.drawString(maxStringX, 			m_XaxisEnd-(mswx/2),			m_YaxisEnd+hf+m_tickSize);	  fieldWidthX = (int)((Math.log(m_minX)/Math.log(10)))+1;	  maxStringX = Utils.doubleToString(m_minX,					    fieldWidthX+1+precisionX,					    precisionX);	  mswx = m_labelMetrics.stringWidth(maxStringX);	  gx.drawString(maxStringX,			(m_XaxisStart-(mswx/2)),			m_YaxisEnd+hf+m_tickSize);	  // draw the middle value	  if (w > (3 * mswx) && 	      (m_plotInstances.attribute(m_xIndex).isNumeric())) {	    double mid = m_minX+((m_maxX-m_minX)/2.0);	    int fieldWidth = (int)((Math.log(mid)/Math.log(10)))+1;	    String maxString = Utils.doubleToString(mid,						    fieldWidth+1+precisionX,						    precisionX);	    int sw = m_labelMetrics.stringWidth(maxString);	    double mx = m_XaxisStart+((double)(m_XaxisEnd-m_XaxisStart)/2.0);	    gx.drawString(maxString,			  (int)(mx-(((double)sw)/2.0)),			  m_YaxisEnd+hf+m_tickSize);	    gx.drawLine((int)mx,m_YaxisEnd,(int)mx,m_YaxisEnd+m_tickSize);	  }	}      } else {	int numValues = m_plotInstances.attribute(m_xIndex).numValues();	int div = (numValues % 2 > 0) ? (numValues/2)+1 : (numValues/2);	int maxXStringWidth = (m_XaxisEnd - m_XaxisStart) / numValues;	for (int i=0;i<numValues;i++) {	  String val = m_plotInstances.attribute(m_xIndex).value(i);	  int sw = m_labelMetrics.stringWidth(val);	  int rm;	  // truncate string if necessary	  if (sw > maxXStringWidth) {	    int incr = (sw / val.length());	    rm = (sw - maxXStringWidth) / incr;	    if (rm == 0) {	      rm = 1;	    }	    val = val.substring(0,val.length()-rm);	    sw = m_labelMetrics.stringWidth(val);	  }	  if (i == 0) {	    gx.drawString(val,(int)convertToPanelX(i),			  m_YaxisEnd+hf+m_tickSize);	  } else if (i == numValues -1) {	    if ((i % 2) == 0) {	      gx.drawString(val,			    m_XaxisEnd-sw,			    m_YaxisEnd+hf+m_tickSize);	    } else {	       gx.drawString(val,			    m_XaxisEnd-sw,			    m_YaxisEnd+(2*hf)+m_tickSize);	    }	  } else {	    if ((i % 2) == 0) {	      gx.drawString(val,			    (int)convertToPanelX(i)-(sw/2),			    m_YaxisEnd+hf+m_tickSize);	    } else {	      gx.drawString(val,			    (int)convertToPanelX(i)-(sw/2),			    m_YaxisEnd+(2*hf)+m_tickSize);	    }	  }	  gx.drawLine((int)convertToPanelX(i),		      m_YaxisEnd,		      (int)convertToPanelX(i),		      m_YaxisEnd+m_tickSize);	}	      }      // draw the y axis      if (m_plotInstances.attribute(m_yIndex).isNumeric()) {	if (h > (2 * hf)) {	  gx.drawString(maxStringY, 			m_XaxisStart-mswy-m_tickSize,			m_YaxisStart+(hf));	  gx.drawString(Utils.doubleToString(m_minY,					     fieldWidthY+1+precisionY,					     precisionY),			(m_XaxisStart-mswy-m_tickSize),			m_YaxisEnd);	  // draw the middle value	  if (w > (3 * hf) && 	      (m_plotInstances.attribute(m_yIndex).isNumeric())) {	    double mid = m_minY+((m_maxY-m_minY)/2.0);	    int fieldWidth = (int)((Math.log(mid)/Math.log(10)))+1;	    String maxString = Utils.doubleToString(mid,						    fieldWidth+1+precisionY,						    precisionY);	    int sw = m_labelMetrics.stringWidth(maxString);	    double mx = m_YaxisStart+((double)(m_YaxisEnd-m_YaxisStart)/2.0);	    gx.drawString(maxString,			  m_XaxisStart-sw-m_tickSize-1,			  (int)(mx+(((double)hf)/2.0)));	    gx.drawLine(m_XaxisStart-m_tickSize,(int)mx,m_XaxisStart,(int)mx);	  }	}      } else {	int numValues = m_plotInstances.attribute(m_yIndex).numValues();	int div = ((numValues % 2) == 0) ? (numValues/2) : (numValues/2+1);	int maxYStringHeight = (m_YaxisEnd - m_XaxisStart) / div;	int sw = m_labelMetrics.stringWidth("M");	for (int i=0;i<numValues;i++) {	  // can we at least print 2 characters	  if (maxYStringHeight >= (2*hf)) {	    String val = m_plotInstances.attribute(m_yIndex).value(i);	    int numPrint = ((maxYStringHeight/hf) > val.length()) ?	      val.length() :	      (maxYStringHeight/hf);	    	    for (int j=0;j<numPrint;j++) {	      String ll = val.substring(j,j+1);	      if (val.charAt(j) == '_' || val.charAt(j) == '-') {		ll = "|";	      }	      if (i == 0) {		gx.drawString(ll,m_XaxisStart-sw-m_tickSize-1,			      (int)convertToPanelY(i)			      -((numPrint-1)*hf)			      +(j*hf)			      +(hf/2));	      } else if (i == (numValues-1)) {		if ((i % 2) == 0) {		  gx.drawString(ll,m_XaxisStart-sw-m_tickSize-1,				(int)convertToPanelY(i)				+(j*hf)				+(hf/2));		} else {		  gx.drawString(ll,m_XaxisStart-(2*sw)-m_tickSize-1,				(int)convertToPanelY(i)				+(j*hf)				+(hf/2));		}	      } else {		if ((i % 2) == 0) {		  gx.drawString(ll,m_XaxisStart-sw-m_tickSize-1,				(int)convertToPanelY(i)				-(((numPrint-1)*hf)/2)				+(j*hf)				+(hf/2));		} else {		  gx.drawString(ll,m_XaxisStart-(2*sw)-m_tickSize-1,				(int)convertToPanelY(i)				-(((numPrint-1)*hf)/2)				  +(j*hf)				+(hf/2));		}	      }	    }	  }	  gx.drawLine(m_XaxisStart-m_tickSize,		      (int)convertToPanelY(i),		      m_XaxisStart,		      (int)convertToPanelY(i));	}      }      gx.drawLine(m_XaxisStart,		  m_YaxisStart,		  m_XaxisStart,		  m_YaxisEnd);      gx.drawLine(m_XaxisStart,		  m_YaxisEnd,		  m_XaxisEnd,		  m_YaxisEnd);      if (m_XaxisStart != mxs || m_XaxisEnd != mxe ||	  m_YaxisStart != mys || m_YaxisEnd != mye) {	m_axisChanged = true;      }    }