plotTrainingData();
  public BoundaryVisualizer() {        setLayout(new BorderLayout());    m_classAttBox.setMinimumSize(COMBO_SIZE);    m_classAttBox.setPreferredSize(COMBO_SIZE);    m_classAttBox.setMaximumSize(COMBO_SIZE);    m_classAttBox.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        if (m_classAttBox.getItemCount() != 0)	{		try { 			m_classPanel.setCindex(m_classAttBox.getSelectedIndex());			plotTrainingData();		} catch (Exception ex) {}				//set up the add points selector combo box. -jimmy		setUpClassValueSelectorCB();	}      }      });	        m_xAttBox.setMinimumSize(COMBO_SIZE);    m_xAttBox.setPreferredSize(COMBO_SIZE);    m_xAttBox.setMaximumSize(COMBO_SIZE);    m_yAttBox.setMinimumSize(COMBO_SIZE);    m_yAttBox.setPreferredSize(COMBO_SIZE);    m_yAttBox.setMaximumSize(COMBO_SIZE);    m_classPanel.setMinimumSize(new       Dimension((int)COMBO_SIZE.getWidth()*2, 		(int)COMBO_SIZE.getHeight()*2));    m_classPanel.setPreferredSize(new       Dimension((int)COMBO_SIZE.getWidth()*2, 		(int)COMBO_SIZE.getHeight()*2));    m_controlPanel = new JPanel();    m_controlPanel.setLayout(new BorderLayout());        //jimmy    JPanel dataChooseHolder = new JPanel(new BorderLayout());    dataChooseHolder.setBorder(BorderFactory.createTitledBorder("Dataset"));    dataChooseHolder.add(dataFileLabel, BorderLayout.WEST);        m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);    m_FileChooser.addChoosableFileFilter(m_arffFileFilter);    chooseButton.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        try {		setInstancesFromFileQ();		int classIndex = m_classAttBox.getSelectedIndex();		if (m_trainingInstances != null && m_classifier != null && (m_trainingInstances.attribute(classIndex).isNominal())) {			m_startBut.setEnabled(true);		}				plotTrainingData();	} catch (Exception ex) {		ex.printStackTrace(System.out);		System.err.println("exception");	}	      }    });    dataChooseHolder.add(chooseButton, BorderLayout.EAST);        JPanel classifierHolder = new JPanel();    classifierHolder.setBorder(BorderFactory.createTitledBorder("Classifier"));    classifierHolder.setLayout(new BorderLayout());    m_classifierEditor.setClassType(weka.classifiers.Classifier.class);        m_classifierEditor.addPropertyChangeListener(new PropertyChangeListener() {    	public void propertyChange(PropertyChangeEvent evt) {		m_classifier = (Classifier)m_classifierEditor.getValue();		try {			int classIndex = m_classAttBox.getSelectedIndex();			if (m_trainingInstances != null && m_classifier != null && (m_trainingInstances.attribute(classIndex).isNominal())) {				m_startBut.setEnabled(true);			}		} catch (Exception ex) {};	}    });    classifierHolder.add(m_ClassifierPanel, BorderLayout.CENTER);                JPanel cHolder = new JPanel();    cHolder.setBorder(BorderFactory.createTitledBorder("Class Attribute"));    cHolder.add(m_classAttBox);    JPanel vAttHolder = new JPanel();    vAttHolder.setLayout(new GridLayout(2,1));    vAttHolder.setBorder(BorderFactory.			 createTitledBorder("Visualization Attributes"));    vAttHolder.add(m_xAttBox);    vAttHolder.add(m_yAttBox);    JPanel colOne = new JPanel();    colOne.setLayout(new BorderLayout());    colOne.add(dataChooseHolder, BorderLayout.NORTH); //jimmy    colOne.add(cHolder, BorderLayout.CENTER);    //colOne.add(vAttHolder, BorderLayout.SOUTH);    JPanel tempPanel = new JPanel();    tempPanel.setBorder(BorderFactory.			createTitledBorder("Sampling control"));    tempPanel.setLayout(new GridLayout(3,1));    JPanel colTwo = new JPanel();    colTwo.setLayout(new BorderLayout());    JPanel gsP = new JPanel(); gsP.setLayout(new BorderLayout());    gsP.add(new JLabel(" Base for sampling (r)"), BorderLayout.CENTER);    gsP.add(m_generatorSamplesText, BorderLayout.WEST);    tempPanel.add(gsP);    JPanel rsP = new JPanel(); rsP.setLayout(new BorderLayout());    rsP.add(new JLabel(" Num. locations per pixel"), BorderLayout.CENTER);    rsP.add(m_regionSamplesText, BorderLayout.WEST);    tempPanel.add(rsP);    JPanel ksP = new JPanel(); ksP.setLayout(new BorderLayout());    ksP.add(new JLabel(" Kernel bandwidth (k)"), BorderLayout.CENTER);    ksP.add(m_kernelBandwidthText, BorderLayout.WEST);    tempPanel.add(ksP);        colTwo.add(classifierHolder,BorderLayout.NORTH);//jimmy    //colTwo.add(tempPanel, BorderLayout.CENTER);    colTwo.add(vAttHolder, BorderLayout.CENTER);    JPanel startPanel = new JPanel();    startPanel.setBorder(BorderFactory.			 createTitledBorder("Plotting"));    startPanel.setLayout(new BorderLayout());    startPanel.add(m_startBut, BorderLayout.CENTER);    startPanel.add(m_plotTrainingData, BorderLayout.WEST);    //colTwo.add(startPanel, BorderLayout.SOUTH);    m_controlPanel.add(colOne, BorderLayout.WEST);    m_controlPanel.add(colTwo, BorderLayout.CENTER);    JPanel classHolder = new JPanel();    classHolder.setLayout(new BorderLayout()); //jimmy    classHolder.setBorder(BorderFactory.createTitledBorder("Class color"));    classHolder.add(m_classPanel, BorderLayout.CENTER);    m_controlPanel.add(classHolder, BorderLayout.SOUTH);    add(m_controlPanel, BorderLayout.NORTH);        //classHolder.add(newWindowButton, BorderLayout.EAST);       // set up the add-remove points widgets    m_addRemovePointsPanel.setBorder(BorderFactory.createTitledBorder("Add / remove data points"));    m_addRemovePointsPanel.setLayout(new GridBagLayout());    GridBagConstraints constraints = new GridBagConstraints();    constraints.weightx = 1.0;    constraints.weighty = 1.0;    constraints.gridx = 0;    constraints.gridy = 0;    constraints.fill = GridBagConstraints.BOTH;    m_addRemovePointsPanel.add(m_addPointsButton);    constraints.gridx = 1;    m_addRemovePointsPanel.add(new JLabel("Add points"), constraints);    constraints.gridx = 2;    m_addRemovePointsPanel.add(classValueSelector);    constraints.gridx = 0;    constraints.gridy = 1;    m_addRemovePointsPanel.add(m_removePointsButton, constraints);    constraints.gridx = 1;    m_addRemovePointsPanel.add(new JLabel("Remove points"),constraints);            	removeAllButton.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {			if (m_trainingInstances != null)			{				if (m_startBut.getText().equals("Stop")) //we are plotting					return;				m_boundaryPanel.removeAllInstances();				computeBounds();				m_xAxisPanel.repaint(0,0,0,m_xAxisPanel.getWidth(), m_xAxisPanel.getHeight());				m_yAxisPanel.repaint(0,0,0,m_yAxisPanel.getWidth(), m_yAxisPanel.getHeight());					try {m_boundaryPanel.plotTrainingData(); } catch (Exception ex) {}			}		}		});    constraints.gridx = 2;    m_addRemovePointsPanel.add(removeAllButton, constraints);    //     m_addRemovePointsPanel.add(addPointsFrame, BorderLayout.NORTH);//     m_addRemovePointsPanel.add(removePointsFrame, BorderLayout.CENTER);    //m_addRemovePointsPanel.add(removeAllButton, BorderLayout.SOUTH);            m_addRemovePointsButtonGroup.add(m_addPointsButton);    m_addRemovePointsButtonGroup.add(m_removePointsButton);    m_addPointsButton.setSelected(true);            //classHolder.add(m_addRemovePointsPanel, BorderLayout.SOUTH);        m_boundaryPanel = new BoundaryPanel(m_plotAreaWidth, m_plotAreaHeight);    m_numberOfSamplesFromEachRegion = m_boundaryPanel.getNumSamplesPerRegion();    m_regionSamplesText.setText(""+m_numberOfSamplesFromEachRegion+"  ");    m_generatorSamplesBase = (int)m_boundaryPanel.getGeneratorSamplesBase();    m_generatorSamplesText.setText(""+m_generatorSamplesBase+"  ");    m_dataGenerator = new KDDataGenerator();    m_kernelBandwidth = m_dataGenerator.getKernelBandwidth();    m_kernelBandwidthText.setText(""+m_kernelBandwidth+"  ");    m_boundaryPanel.setDataGenerator(m_dataGenerator);             JPanel gfxPanel = new JPanel();    gfxPanel.setLayout(new BorderLayout());    gfxPanel.setBorder(BorderFactory.createEtchedBorder());    //add(gfxPanel, BorderLayout.CENTER);           // gfxPanel.add(m_addRemovePointsPanel, BorderLayout.NORTH);    gfxPanel.add(m_boundaryPanel, BorderLayout.CENTER);    m_xAxisPanel = new AxisPanel(false);    gfxPanel.add(m_xAxisPanel, BorderLayout.SOUTH);    m_yAxisPanel = new AxisPanel(true);    gfxPanel.add(m_yAxisPanel, BorderLayout.WEST);        JPanel containerPanel = new JPanel();    containerPanel.setLayout(new BorderLayout());    containerPanel.add(gfxPanel, BorderLayout.CENTER);    add(containerPanel, BorderLayout.CENTER);        JPanel rightHandToolsPanel = new JPanel(); //this panel contains the widgets to the right of the BoundaryPanel.    rightHandToolsPanel.setLayout(new BoxLayout(rightHandToolsPanel, BoxLayout.PAGE_AXIS));    rightHandToolsPanel.add(m_addRemovePointsPanel);        JButton newWindowButton = new JButton("Open a new window"); //the button for spawning a new window for the program.    //newWindowButton.setMaximumSize(new Dimension(100, 100));    //newWindowButton.setPreferredSize(new Dimension(120, m_addRemovePointsPanel.getHeight()));    newWindowButton.addActionListener(new ActionListener() {    	public void actionPerformed(ActionEvent e) {		try {			Instances newTrainingData = null;			Classifier newClassifier = null;			if (m_trainingInstances != null)				newTrainingData = new Instances(m_trainingInstances);			if (m_classifier != null)				newClassifier = Classifier.makeCopy(m_classifier);			createNewVisualizerWindow(newClassifier, newTrainingData);		} catch (Exception ex) {  ex.printStackTrace();}	}    });    JPanel newWindowHolder = new JPanel();    newWindowHolder.add(newWindowButton);    rightHandToolsPanel.add(newWindowHolder);    rightHandToolsPanel.add(tempPanel);    rightHandToolsPanel.add(startPanel);        containerPanel.add(rightHandToolsPanel, BorderLayout.EAST);            /*add(m_boundaryPanel, BorderLayout.CENTER);    m_xAxisPanel = new AxisPanel(false);    add(m_xAxisPanel, BorderLayout.SOUTH);    m_yAxisPanel = new AxisPanel(true);    add(m_yAxisPanel, BorderLayout.WEST);*/    m_startBut.setEnabled(false);    m_startBut.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  if (m_startBut.getText().equals("Start")) {	    if (m_trainingInstances != null && m_classifier != null) {		try {						int BPSuccessCode = setUpBoundaryPanel(); //set up the boundary panel, find out if it was successful or not.						if (BPSuccessCode == 1)				JOptionPane.showMessageDialog(null,"Error: Kernel Bandwidth can't be less than zero!");			else if (BPSuccessCode == 2) {				JOptionPane.showMessageDialog(null,"Error: Kernel Bandwidth must be less than the number of training instances!");			} else {				m_boundaryPanel.start();				m_startBut.setText("Stop");				setControlEnabledStatus(false);			}		} catch (Exception ex) {			ex.printStackTrace();		}	    }	  } else {	    m_boundaryPanel.stopPlotting();	    m_startBut.setText("Start");	    setControlEnabledStatus(true);	  }	}      });    m_boundaryPanel.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  m_startBut.setText("Start");	  setControlEnabledStatus(true);	}      });    m_classPanel.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  try {	    // save color vector to a file	    FastVector colors = m_boundaryPanel.getColors();	    FileOutputStream fos = new FileOutputStream("colors.ser");	    ObjectOutputStream oos = new ObjectOutputStream(fos);	    oos.writeObject(colors);	    oos.flush();	    oos.close();	  } catch (Exception ex) {}	  m_boundaryPanel.replot();	  	}      });          //set up a mouse listener for the boundary panel.    m_boundaryPanel.addMouseListener(new MouseAdapter() {    	public void mouseClicked(MouseEvent e) {// 		System.err.println("boundary panel mouseClick " + e.getX() + " " + e.getY());		if (m_trainingInstances != null) {			if (m_startBut.getText().equals("Stop")) //we are plotting				return;					if (m_addPointsButton.isSelected()) {//we are in add mode				double classVal = 0;				boolean validInput = true;				if (m_trainingInstances.attribute(m_classAttBox.getSelectedIndex()).isNominal()) //class is nominal					classVal = (double)classValueSelector.getSelectedIndex();				else {					String indexStr = "";					try {											indexStr = (String)classValueSelector.getSelectedItem();						classVal = Double.parseDouble(indexStr);					} catch (Exception ex) {						if (indexStr == null) indexStr = "";						JOptionPane.showMessageDialog(null,"Error adding a point: \"" + indexStr + "\""							+ " is not a valid class value.");						validInput = false;					}				}				//System.err.println("classVal is " + classVal);				if (validInput)					m_boundaryPanel.addTrainingInstanceFromMouseLocation(e.getX(), e.getY(), m_classAttBox.getSelectedIndex(), classVal);			}			else { //remove mode				m_boundaryPanel.removeTrainingInstanceFromMouseLocation(e.getX(), e.getY());			}			try{ plotTrainingData(); } catch (Exception ex) {} //jimmy			m_xAxisPanel.repaint(0,0,0,m_xAxisPanel.getWidth(), m_xAxisPanel.getHeight());    			m_yAxisPanel.repaint(0,0,0,m_yAxisPanel.getWidth(), m_yAxisPanel.getHeight());		}	}    });  }