repaint();
PlotPanel.this.repaint();
    public PlotPanel() {      setBackground(Color.black);      m_InstanceInfoText.setFont(new Font("Monospaced", Font.PLAIN,12));      m_InstanceInfoText.setEditable(false);      m_createShape = false;              m_shapes = null;////      m_shapePoints = null;      m_newMousePos = new Dimension();      m_drawnPoints = new int[getWidth()][getHeight()];      addMouseListener(new MouseAdapter() {	  ///////      	  public void mousePressed(MouseEvent e) {	    if ((e.getModifiers() & e.BUTTON1_MASK) == e.BUTTON1_MASK) {	      //	      if (m_sIndex == 0) {		//do nothing it will get dealt to in the clicked method	      }	      else if (m_sIndex == 1) {		m_createShape = true;		m_shapePoints = new FastVector(5);		m_shapePoints.addElement(new Double(m_sIndex));		m_shapePoints.addElement(new Double(e.getX()));		m_shapePoints.addElement(new Double(e.getY()));		m_shapePoints.addElement(new Double(e.getX()));		m_shapePoints.addElement(new Double(e.getY()));		Graphics g = getGraphics();		g.setColor(Color.black);		g.setXORMode(Color.white);		g.drawRect(((Double)m_shapePoints.elementAt(1)).intValue(),			   ((Double)m_shapePoints.elementAt(2)).intValue(),			   ((Double)m_shapePoints.elementAt(3)).intValue() -			   ((Double)m_shapePoints.elementAt(1)).intValue(), 			   ((Double)m_shapePoints.elementAt(4)).intValue() -			   ((Double)m_shapePoints.elementAt(2)).intValue());		g.dispose();	      }	      //System.out.println("clicked");	    }	    //System.out.println("clicked");	  }	  //////	  public void mouseClicked(MouseEvent e) {	    	    if ((m_sIndex == 2 || m_sIndex == 3) && 		(m_createShape || 		 (e.getModifiers() & e.BUTTON1_MASK) == e.BUTTON1_MASK)) {	      if (m_createShape) {		//then it has been started already.		Graphics g = getGraphics();		g.setColor(Color.black);		g.setXORMode(Color.white);		if ((e.getModifiers() & e.BUTTON1_MASK) == e.BUTTON1_MASK) {		  m_shapePoints.addElement(new 		    Double(convertToAttribX(e.getX())));		  		  m_shapePoints.addElement(new 		    Double(convertToAttribY(e.getY())));		  		  m_newMousePos.width = e.getX();		  m_newMousePos.height = e.getY();		  g.drawLine((int)Math.ceil			     (convertToPanelX			      (((Double)m_shapePoints.				elementAt(m_shapePoints.size() - 2)).			       doubleValue())),			     			     (int)Math.ceil			     (convertToPanelY			      (((Double)m_shapePoints.				elementAt(m_shapePoints.size() - 1)).			       doubleValue())),			     m_newMousePos.width, m_newMousePos.height);		  		}		else if (m_sIndex == 3) {		  //then extend the lines to infinity 		  //(100000 or so should be enough).		  //the area is selected by where the user right clicks 		  //the mouse button		  		  m_createShape = false;		  if (m_shapePoints.size() >= 5) {		    double cx = Math.ceil		      (convertToPanelX		       (((Double)m_shapePoints.elementAt			 (m_shapePoints.size() - 4)).doubleValue()));		    		    double cx2 = Math.ceil		      (convertToPanelX		       (((Double)m_shapePoints.elementAt			 (m_shapePoints.size() - 2)).doubleValue())) - 		      cx;		    		    cx2 *= 50000;		    		    double cy = Math.ceil		      (convertToPanelY(((Double)m_shapePoints.elementAt					(m_shapePoints.size() - 3)).				       doubleValue()));		    double cy2 = Math.ceil		      (convertToPanelY(((Double)m_shapePoints.elementAt					(m_shapePoints.size() - 1)).				       doubleValue())) - cy;		    cy2 *= 50000;			    		    		    double cxa = Math.ceil(convertToPanelX					   (((Double)m_shapePoints.					     elementAt(3)).					    doubleValue()));		    double cxa2 = Math.ceil(convertToPanelX					    (((Double)m_shapePoints.					      elementAt(1)).					     doubleValue())) - cxa;		    cxa2 *= 50000;		    		    		    double cya = Math.ceil		      (convertToPanelY		       (((Double)m_shapePoints.elementAt(4)).			doubleValue()));		    double cya2 = Math.ceil		      (convertToPanelY		       (((Double)m_shapePoints.elementAt(2)).			doubleValue())) - cya;		    		    cya2 *= 50000;		    		    m_shapePoints.setElementAt		      (new Double(convertToAttribX(cxa2 + cxa)), 1);		    		    m_shapePoints.setElementAt		      (new Double(convertToAttribY(cy2 + cy)), 		       m_shapePoints.size() - 1);		    		    m_shapePoints.setElementAt		      (new Double(convertToAttribX(cx2 + cx)), 		       m_shapePoints.size() - 2);		    		    m_shapePoints.setElementAt		      (new Double(convertToAttribY(cya2 + cya)), 2);		    		    		    //determine how infinity line should be built		    		    cy = Double.POSITIVE_INFINITY;		    cy2 = Double.NEGATIVE_INFINITY;		    if (((Double)m_shapePoints.elementAt(1)).			doubleValue() > 			((Double)m_shapePoints.elementAt(3)).			doubleValue()) {		      if (((Double)m_shapePoints.elementAt(2)).			  doubleValue() == 			  ((Double)m_shapePoints.elementAt(4)).			  doubleValue()) {			cy = ((Double)m_shapePoints.elementAt(2)).			  doubleValue();		      }		    }		    if (((Double)m_shapePoints.elementAt			 (m_shapePoints.size() - 2)).doubleValue() > 			((Double)m_shapePoints.elementAt			 (m_shapePoints.size() - 4)).doubleValue()) {		      if (((Double)m_shapePoints.elementAt			   (m_shapePoints.size() - 3)).			  doubleValue() == 			  ((Double)m_shapePoints.elementAt			   (m_shapePoints.size() - 1)).doubleValue()) {			cy2 = ((Double)m_shapePoints.lastElement()).			  doubleValue();		      }		    }		    m_shapePoints.addElement(new Double(cy));		    m_shapePoints.addElement(new Double(cy2));		    		    if (!inPolyline(m_shapePoints, convertToAttribX				    (e.getX()), 				    convertToAttribY(e.getY()))) {		      Double tmp = (Double)m_shapePoints.			elementAt(m_shapePoints.size() - 2);		      m_shapePoints.setElementAt			(m_shapePoints.lastElement(), 			 m_shapePoints.size() - 2);		      m_shapePoints.setElementAt			(tmp, m_shapePoints.size() - 1);		    }		    		    if (m_shapes == null) {		      m_shapes = new FastVector(4);		    }		    m_shapes.addElement(m_shapePoints);		    m_submit.setText("Submit");		    m_submit.setActionCommand("Submit");		    		    m_submit.setEnabled(true);		  }		  		  m_shapePoints = null;		  repaint();		  		}		else {		  //then close the shape		  m_createShape = false;		  if (m_shapePoints.size() >= 7) {		    m_shapePoints.addElement(m_shapePoints.elementAt(1));		    m_shapePoints.addElement(m_shapePoints.elementAt(2));		    if (m_shapes == null) {		      m_shapes = new FastVector(4);		    }		    m_shapes.addElement(m_shapePoints);			   		    m_submit.setText("Submit");		    m_submit.setActionCommand("Submit");		    		    m_submit.setEnabled(true);		  }		  m_shapePoints = null;		  repaint();		}		g.dispose();		//repaint();	      }	      else if ((e.getModifiers() & e.BUTTON1_MASK) == e.BUTTON1_MASK) {		//then this is the first point		m_createShape = true;		m_shapePoints = new FastVector(17);		m_shapePoints.addElement(new Double(m_sIndex));		m_shapePoints.addElement(new 		  Double(convertToAttribX(e.getX())));      //the new point		m_shapePoints.addElement(new 		  Double(convertToAttribY(e.getY())));		m_newMousePos.width = e.getX();      //the temp mouse point		m_newMousePos.height = e.getY();		Graphics g = getGraphics();		g.setColor(Color.black);		g.setXORMode(Color.white);		g.drawLine((int)Math.ceil			   (convertToPanelX(((Double)m_shapePoints.					     elementAt(1)).doubleValue())),			   (int)Math.ceil			   (convertToPanelY(((Double)m_shapePoints.					     elementAt(2)).doubleValue())),			   m_newMousePos.width, m_newMousePos.height);		g.dispose();	      }	    }	    else {	      if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == 		  InputEvent.BUTTON1_MASK) {				searchPoints(e.getX(),e.getY(), false);	      } else {		searchPoints(e.getX(), e.getY(), true);	      }	    }	  }	  	  /////////             	  public void mouseReleased(MouseEvent e) {	    //System.out.println("rel");	    if (m_createShape) {	      if (((Double)m_shapePoints.elementAt(0)).intValue() == 1) {		m_createShape = false;		Graphics g = getGraphics();		g.setColor(Color.black);		g.setXORMode(Color.white);		g.drawRect(((Double)m_shapePoints.elementAt(1)).			   intValue(), 			   ((Double)m_shapePoints.elementAt(2)).intValue(),			   ((Double)m_shapePoints.elementAt(3)).intValue() -			   ((Double)m_shapePoints.elementAt(1)).intValue(), 			   ((Double)m_shapePoints.elementAt(4)).intValue() -			   ((Double)m_shapePoints.elementAt(2)).intValue());				g.dispose();		if (checkPoints(((Double)m_shapePoints.elementAt(1)).				doubleValue(), 				((Double)m_shapePoints.elementAt(2)).				doubleValue()) &&		    checkPoints(((Double)m_shapePoints.elementAt(3)).				doubleValue(), 				((Double)m_shapePoints.elementAt(4)).				doubleValue())) {		  //then the points all land on the screen		  //now do special check for the rectangle		  if (((Double)m_shapePoints.elementAt(1)).doubleValue() <		      ((Double)m_shapePoints.elementAt(3)).doubleValue() 		      &&		      ((Double)m_shapePoints.elementAt(2)).doubleValue() <		      ((Double)m_shapePoints.elementAt(4)).doubleValue()) {		    //then the rectangle is valid		    if (m_shapes == null) {		      m_shapes = new FastVector(2);		    }		    m_shapePoints.setElementAt(new 		      Double(convertToAttribX(((Double)m_shapePoints.					       elementAt(1)).					      doubleValue())), 1);		    m_shapePoints.setElementAt(new 		      Double(convertToAttribY(((Double)m_shapePoints.					       elementAt(2)).					      doubleValue())), 2);		    m_shapePoints.setElementAt(new 		      Double(convertToAttribX(((Double)m_shapePoints.					       elementAt(3)).					      doubleValue())), 3);		    m_shapePoints.setElementAt(new 		      Double(convertToAttribY(((Double)m_shapePoints.					       elementAt(4)).					      doubleValue())), 4);		    		    m_shapes.addElement(m_shapePoints);		    		    m_submit.setText("Submit");		    m_submit.setActionCommand("Submit");		    		    m_submit.setEnabled(true);		    repaint();		  }		}		m_shapePoints = null;	      }	    }	  }	});            addMouseMotionListener(new MouseMotionAdapter() {	  public void mouseDragged(MouseEvent e) {	    //check if the user is dragging a box	    if (m_createShape) {	      if (((Double)m_shapePoints.elementAt(0)).intValue() == 1) {		Graphics g = getGraphics();		g.setColor(Color.black);		g.setXORMode(Color.white);		g.drawRect(((Double)m_shapePoints.elementAt(1)).intValue(), 			   ((Double)m_shapePoints.elementAt(2)).intValue(),			   ((Double)m_shapePoints.elementAt(3)).intValue() -			   ((Double)m_shapePoints.elementAt(1)).intValue(), 			   ((Double)m_shapePoints.elementAt(4)).intValue() -			   ((Double)m_shapePoints.elementAt(2)).intValue());				m_shapePoints.setElementAt(new Double(e.getX()), 3);		m_shapePoints.setElementAt(new Double(e.getY()), 4);				g.drawRect(((Double)m_shapePoints.elementAt(1)).intValue(), 			   ((Double)m_shapePoints.elementAt(2)).intValue(),			   ((Double)m_shapePoints.elementAt(3)).intValue() -			   ((Double)m_shapePoints.elementAt(1)).intValue(), 			   ((Double)m_shapePoints.elementAt(4)).intValue() -			   ((Double)m_shapePoints.elementAt(2)).intValue());		g.dispose();	      }	    }	  }	  	  public void mouseMoved(MouseEvent e) {	    if (m_createShape) {	      if (((Double)m_shapePoints.elementAt(0)).intValue() == 2 || 		  ((Double)m_shapePoints.elementAt(0)).intValue() == 3) {		Graphics g = getGraphics();		g.setColor(Color.black);		g.setXORMode(Color.white);		g.drawLine((int)Math.ceil(convertToPanelX					  (((Double)m_shapePoints.elementAt					    (m_shapePoints.size() - 2)).					   doubleValue())),			   (int)Math.ceil(convertToPanelY					  (((Double)m_shapePoints.elementAt					    (m_shapePoints.size() - 1)).					   doubleValue())),			   m_newMousePos.width, m_newMousePos.height);				m_newMousePos.width = e.getX();		m_newMousePos.height = e.getY();				g.drawLine((int)Math.ceil(convertToPanelX					  (((Double)m_shapePoints.elementAt					    (m_shapePoints.size() - 2)).					   doubleValue())),			   (int)Math.ceil(convertToPanelY					  (((Double)m_shapePoints.elementAt					    (m_shapePoints.size() - 1)).					   doubleValue())),			   m_newMousePos.width, m_newMousePos.height);		g.dispose();	      }	    }	  }	});            m_submit.addActionListener(new ActionListener() {	  public void actionPerformed(ActionEvent e) {	 	    if (e.getActionCommand().equals("Submit")) {	      if (m_splitListener != null && m_shapes != null) {		//then send the split to the listener		Instances sub_set1 = new Instances(m_plotInstances, 500);		Instances sub_set2 = new Instances(m_plotInstances, 500);				if (m_plotInstances != null) {		  		  for (int noa = 0 ; noa < m_plotInstances.numInstances(); 		       noa++) {		    if (!m_plotInstances.instance(noa).isMissing(m_xIndex)			&& !m_plotInstances.instance(noa).isMissing(m_yIndex)){		      		      if (inSplit(m_plotInstances.instance(noa))) {			sub_set1.add(m_plotInstances.instance(noa));		      }		      else {			sub_set2.add(m_plotInstances.instance(noa));		      }		    }		  }		  FastVector tmp = m_shapes;		  cancelShapes();		  m_splitListener.userDataEvent(new 		    VisualizePanelEvent(tmp, sub_set1, sub_set2, m_xIndex, 					m_yIndex));		}	      }	      else if (m_shapes != null && m_plotInstances != null) { 		Instances sub_set1 = new Instances(m_plotInstances, 500);		int count = 0;		for (int noa = 0 ; noa < m_plotInstances.numInstances(); 		     noa++) {		  if (inSplit(m_plotInstances.instance(noa))) {		    sub_set1.add(m_plotInstances.instance(noa));		      count++;		  }				}   		double [] nPreds = null;		int x = m_xIndex;		int y = m_yIndex;		//boolean p = m_predsNumeric;		if (m_origInstances == null) {		    //this sets these instances as the instances 		    //to go back to.		    m_origInstances = m_plotInstances;		  }		if (m_origPreds == null && m_preds != null) {		  m_origPreds = m_preds;		}		if (m_preds != null && count > 0) {		  nPreds = new double[m_origInstances.numInstances()];		  count = 0;		  for (int noa = 0; noa < m_plotInstances.numInstances(); 		       noa++) {		    if (inSplit(m_plotInstances.instance(noa))) {		      //System.out.println(m_preds[noa]);		      nPreds[count] = m_preds[noa];		      count++;		    }		  }		}		cancelShapes();		VisualizePanel.this.setInstances(sub_set1);		if (m_preds != null) {		  VisualizePanel.this.setPredictions(nPreds);		  //VisualizePanel.this.setPredictionsNumeric(p);		}		try {		  VisualizePanel.this.setXIndex(x);		  VisualizePanel.this.setYIndex(y);		} catch(Exception er) {		  System.out.println("Error : " + er);		  //  System.out.println("Part of user input so had to" +		  //		 " catch here");		}	      }	    }	    else if (e.getActionCommand().equals("Reset")) {	      int x = m_xIndex;	      int y = m_yIndex;	      //boolean p = m_predsNumeric;	      VisualizePanel.this.setInstances(m_origInstances);	      if (m_origPreds != null) {		VisualizePanel.this.setPredictions(m_origPreds);		//VisualizePanel.this.setPredictionsNumeric(p);	      }	      try {		VisualizePanel.this.setXIndex(x);		VisualizePanel.this.setYIndex(y);	      } catch(Exception er) {		System.out.println("Error : " + er);	      }	    }	  }  	});      m_cancel.addActionListener(new ActionListener() {	  public void actionPerformed(ActionEvent e) {	    cancelShapes();	    repaint();	  }	});      ////////////    }