int w = getWidth();
int w = this.getWidth();
    protected void paintNominal(Graphics gx) {      setFonts(gx);      int numClasses;      if (m_colourUsingPreds) {	numClasses = m_numPreds;      }      else {	numClasses = m_Instances.attribute(m_cIndex).numValues();      }      int maxLabelLen = 0;      int idx=0;      int legendHeight;      int w = getWidth();      int hf = m_labelMetrics.getAscent();      //System.out.println("not good");      if (m_colourUsingPreds) {	maxLabelLen = m_labelMetrics.stringWidth("88"); //if there      } //are more than 99 clusters then it's outa hand anyway      else {	for (int i=0;i<numClasses;i++) {	  if (m_Instances.attribute(m_cIndex).value(i).length() > 	      maxLabelLen) {	    maxLabelLen = m_Instances.	      attribute(m_cIndex).value(i).length();	    idx = i;	  }	}      	maxLabelLen = m_labelMetrics.stringWidth	  (m_Instances.attribute(m_cIndex).value(idx));      }      if (((w-(2*m_HorizontalPad))/(maxLabelLen+5)) >= numClasses) {	legendHeight = 1;      } else {	legendHeight = 2;      }	      int x = m_HorizontalPad;      int y = 1 + hf;      // do the first row      int ci, mp;      Color pc;      int numToDo = ((legendHeight==1) ? numClasses : (numClasses/2));      for (int i=0;i<numToDo;i++) {	/*ci = i % 10; mp = i / 10; mp *= 2;	pc = m_DefaultColors[ci];	for (int j=0;j<mp;j++) {	  pc = pc.darker();	  }*/	gx.setColor((Color)m_colorList.elementAt(i));	// can we fit the full label or will each need to be trimmed?	if ((numToDo * maxLabelLen) > (w-(m_HorizontalPad*2))) {	  String val;	  if (m_colourUsingPreds) {	    val = String.valueOf(i);	  }	  else {	    val = m_Instances.attribute(m_cIndex).value(i);	  }	  int sw = m_labelMetrics.stringWidth(val);	  int rm=0;	  // truncate string if necessary	  if (sw > ((w-(m_HorizontalPad*2)) / (numToDo))) {	    int incr = (sw / val.length());	    rm = (sw -  ((w-(m_HorizontalPad*2)) / numToDo)) / incr;	    if (rm <= 0) {	      rm = 0;	    }	    val = val.substring(0,val.length()-rm);	    sw = m_labelMetrics.stringWidth(val);	  }	  NomLabel jj = new NomLabel(val, i);	  jj.setFont(gx.getFont());	  //jj.setBackground(Color.black);	  jj.setSize(m_labelMetrics.stringWidth(jj.getText()),		     m_labelMetrics.getAscent() + 4);	  add(jj);	  jj.setLocation(x, y);	  jj.setForeground((Color)m_colorList.			   elementAt(i % m_colorList.size()));	  //gx.drawString(val,x,y);	  x += sw + 2;	} else {	  //JLabel jj = new JLabel(m_Instances.attribute(m_cIndex).value(i));	  //add(jj);	  //jj.setFont(gx.getFont());	  //jj.setLocation(x, y);	  NomLabel jj;	  if (m_colourUsingPreds) {	    jj = new NomLabel(String.valueOf(i), i);	  }	  else {	    jj = new NomLabel(m_Instances.attribute(m_cIndex).value(i), i);	  }	  jj.setFont(gx.getFont());	  //jj.setBackground(Color.black);	  jj.setSize(m_labelMetrics.stringWidth(jj.getText()),		     m_labelMetrics.getAscent() + 4);	  add(jj);	  jj.setLocation(x, y);	  jj.setForeground((Color)m_colorList.			   elementAt(i % m_colorList.size()));	  //  gx.drawString(m_Instances.attribute(m_cIndex).value(i),x,y);  	  //gx.drawString(m_Instances.attribute(m_cIndex).value(i),x,y);	  x += ((w-(m_HorizontalPad*2)) / numToDo);	}	        }      x = m_HorizontalPad;      y = 1+ hf + 5 +hf;      for (int i=numToDo;i<numClasses;i++) {	/*ci = i % 10; mp = i / 10; mp *= 2;	pc = m_DefaultColors[ci];	for (int j=0;j<mp;j++) {	  pc = pc.darker();	  }*/	gx.setColor((Color)m_colorList.elementAt(i));	if (((numClasses-numToDo+1) * maxLabelLen) > 	    (w - (m_HorizontalPad*2))) {	  String val;	  if (m_colourUsingPreds) {	    val = String.valueOf(i);	  }	  else {	    val = m_Instances.attribute(m_cIndex).value(i);	  }	  int sw = m_labelMetrics.stringWidth(val);	  int rm=0;	  // truncate string if necessary	  if (sw > ((w-(m_HorizontalPad*2)) / (numClasses-numToDo+1))) {	    int incr = (sw / val.length());	    rm = (sw -  ((w-(m_HorizontalPad*2)) / (numClasses-numToDo))) 	      / incr;	    if (rm <= 0) {	      rm = 0;	    }	    val = val.substring(0,val.length()-rm);	    sw = m_labelMetrics.stringWidth(val);	  }	  //this is the clipped string	  NomLabel jj = new NomLabel(val, i);	  jj.setFont(gx.getFont());	  //jj.setBackground(Color.black);	  jj.setSize(m_labelMetrics.stringWidth(jj.getText()),		     m_labelMetrics.getAscent() + 4);	  add(jj);	  jj.setLocation(x, y);	  jj.setForeground((Color)m_colorList.			   elementAt(i % m_colorList.size()));	  //gx.drawString(val,x,y);	  //	  x += ((w-(m_HorizontalPad*2)) / (numClasses-numToDo))+3;	  x += sw +2;	} else {	  //this is the full string	  NomLabel jj;	  if (m_colourUsingPreds) {	    jj = new NomLabel(String.valueOf(i), i);	  }	  else {	    jj = new NomLabel(m_Instances.attribute(m_cIndex).value(i), i);	  }	  jj.setFont(gx.getFont());	  //jj.setBackground(Color.black);	  jj.setSize(m_labelMetrics.stringWidth(jj.getText()),		     m_labelMetrics.getAscent() + 4);	  add(jj);	  jj.setLocation(x, y);	  jj.setForeground((Color)m_colorList.			   elementAt(i % m_colorList.size()));	  //  gx.drawString(m_Instances.attribute(m_cIndex).value(i),x,y);	  x += ((w - (m_HorizontalPad*2)) / (numClasses-numToDo));	}	        }    }