m_StorePredictionsBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_StorePredictionsBut.isSelected()) { if (m_CurrentVis != null) { m_VisualizeBut.setEnabled(true); } }
m_History.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (m_History.getSelectedObject() != null) { m_VisualizeBut.setEnabled(true); } else { m_VisualizeBut.setEnabled(false);
  public ClassifierPanel() {    // Connect / configure the components    m_OutText.setEditable(false);    m_OutText.setFont(new Font("Dialoginput", Font.PLAIN, 10));    m_OutText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    m_OutText.addMouseListener(new MouseAdapter() {      public void mouseClicked(MouseEvent e) {	if ((e.getModifiers() & InputEvent.BUTTON1_MASK)	    != InputEvent.BUTTON1_MASK) {	  m_OutText.selectAll();	}      }    });    m_History.setBorder(BorderFactory.createTitledBorder("Result list"));    m_ClassifierEditor.setClassType(Classifier.class);    m_ClassifierEditor.setValue(new weka.classifiers.ZeroR());    m_ClassifierEditor.addPropertyChangeListener(new PropertyChangeListener() {      public void propertyChange(PropertyChangeEvent e) {	repaint();      }    });    m_VisualizeBut.setToolTipText("Visualize the current classifier");    m_ClassCombo.setToolTipText("Select the attribute to use as the class");    m_TrainBut.setToolTipText("Test on the same set that the classifier"			      + " is trained on");    m_CVBut.setToolTipText("Perform a n-fold cross-validation");    m_PercentBut.setToolTipText("Train on a percentage of the data and"				+ " test on the remainder");    m_TestSplitBut.setToolTipText("Test on a user-specified dataset");    m_StartBut.setToolTipText("Starts the classification");    m_StopBut.setToolTipText("Stops a running classification");    m_StorePredictionsBut.      setToolTipText("Store predictions in the result list for later "		     +"visualization");    m_OutputModelBut      .setToolTipText("Output the model obtained from the full training set");    m_OutputTFPosBut.setToolTipText("Output the true positives and false"				    + " positives for each class");    m_OutputConfusionBut      .setToolTipText("Output the matrix displaying class confusions");    m_StorePredictionsBut.setSelected(true);    m_OutputModelBut.setSelected(true);    m_OutputTFPosBut.setSelected(true);    m_OutputConfusionBut.setSelected(true);    m_ClassCombo.setEnabled(false);    m_CVBut.setSelected(true);    updateRadioLinks();    ButtonGroup bg = new ButtonGroup();    bg.add(m_TrainBut);    bg.add(m_CVBut);    bg.add(m_PercentBut);    bg.add(m_TestSplitBut);    m_TrainBut.addActionListener(m_RadioListener);    m_CVBut.addActionListener(m_RadioListener);    m_PercentBut.addActionListener(m_RadioListener);    m_TestSplitBut.addActionListener(m_RadioListener);    m_SetTestBut.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	setTestSet();      }    });    m_VisualizeBut.setEnabled(false);    m_StartBut.setEnabled(false);    m_StopBut.setEnabled(false);    m_StartBut.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	startClassifier();      }    });    m_StopBut.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	stopClassifier();      }    });    m_VisualizeBut.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	if (!m_StorePredictionsBut.isSelected()) {	  m_VisualizeBut.setEnabled(false);	}	visualizeClassifier();      }    });    m_ClassCombo.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	int selected = m_ClassCombo.getSelectedIndex();	if (selected != -1) {	  boolean isNominal = m_Instances.attribute(selected).isNominal();	  m_OutputTFPosBut.setEnabled(isNominal);	  m_OutputConfusionBut.setEnabled(isNominal);		}      }    });    m_StorePredictionsBut.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  if (m_StorePredictionsBut.isSelected()) {	    if (m_CurrentVis != null) {	      m_VisualizeBut.setEnabled(true);	    }	  }	}      });    m_MoreOptions.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	m_MoreOptions.setEnabled(false);	JPanel moreOptionsPanel = new JPanel();	moreOptionsPanel.setBorder(BorderFactory.createCompoundBorder(			BorderFactory.createTitledBorder("Output Options"),			BorderFactory.createEmptyBorder(0, 5, 5, 5)			       				      ));	moreOptionsPanel.setLayout(new GridLayout(5, 1));	moreOptionsPanel.add(m_OutputModelBut);	moreOptionsPanel.add(m_OutputTFPosBut);	  	moreOptionsPanel.add(m_OutputConfusionBut);	  	moreOptionsPanel.add(m_StorePredictionsBut);	JPanel all = new JPanel();	all.setLayout(new BorderLayout());		JButton oK = new JButton("OK");	JPanel okP = new JPanel();	okP.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));	okP.setLayout(new GridLayout(1,1,5,5));	okP.add(oK);	all.add(moreOptionsPanel,BorderLayout.CENTER);	all.add(okP,BorderLayout.SOUTH);		final javax.swing.JFrame jf = 	  new javax.swing.JFrame("Classifier ouptut options");	jf.getContentPane().setLayout(new BorderLayout());	jf.getContentPane().add(all, BorderLayout.CENTER);	jf.addWindowListener(new java.awt.event.WindowAdapter() {	  public void windowClosing(java.awt.event.WindowEvent e) {	    jf.dispose();	    m_MoreOptions.setEnabled(true);	  }	});	oK.addActionListener(new ActionListener() {	  public void actionPerformed(ActionEvent e) {	    m_MoreOptions.setEnabled(true);	    jf.dispose();	  }	});	jf.pack();	jf.setSize(370,200);	jf.setVisible(true);      }    });    // Layout the GUI    JPanel p1 = new JPanel();    p1.setBorder(BorderFactory.createCompoundBorder(		 BorderFactory.createTitledBorder("Classifier"),		 BorderFactory.createEmptyBorder(0, 5, 5, 5)		 ));    p1.setLayout(new BorderLayout());    p1.add(m_CEPanel, BorderLayout.NORTH);    JPanel p2 = new JPanel();    GridBagLayout gbL = new GridBagLayout();    p2.setLayout(gbL);    p2.setBorder(BorderFactory.createCompoundBorder(		 BorderFactory.createTitledBorder("Test options"),		 BorderFactory.createEmptyBorder(0, 5, 5, 5)		 ));    GridBagConstraints gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.WEST;    gbC.gridy = 0;     gbC.gridx = 0;    gbL.setConstraints(m_TrainBut, gbC);    p2.add(m_TrainBut);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.WEST;    gbC.gridy = 1;     gbC.gridx = 0;    gbL.setConstraints(m_TestSplitBut, gbC);    p2.add(m_TestSplitBut);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 1;     gbC.gridx = 1;    gbC.gridwidth = 2;    gbC.insets = new Insets(2, 10, 2, 0);    gbL.setConstraints(m_SetTestBut, gbC);    p2.add(m_SetTestBut);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.WEST;    gbC.gridy = 2;     gbC.gridx = 0;    gbL.setConstraints(m_CVBut, gbC);    p2.add(m_CVBut);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 2;     gbC.gridx = 1;    gbC.insets = new Insets(2, 10, 2, 10);    gbL.setConstraints(m_CVLab, gbC);    p2.add(m_CVLab);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 2;     gbC.gridx = 2;  gbC.weightx = 100;    gbC.ipadx = 20;    gbL.setConstraints(m_CVText, gbC);    p2.add(m_CVText);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.WEST;    gbC.gridy = 3;     gbC.gridx = 0;    gbL.setConstraints(m_PercentBut, gbC);    p2.add(m_PercentBut);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 3;     gbC.gridx = 1;    gbC.insets = new Insets(2, 10, 2, 10);    gbL.setConstraints(m_PercentLab, gbC);    p2.add(m_PercentLab);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.EAST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 3;     gbC.gridx = 2;  gbC.weightx = 100;    gbC.ipadx = 20;    gbL.setConstraints(m_PercentText, gbC);    p2.add(m_PercentText);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.WEST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 4;     gbC.gridx = 0;  gbC.weightx = 100;    gbC.gridwidth = 3;    //gbC.ipadx = 20;    gbC.insets = new Insets(3, 0, 1, 0);    gbL.setConstraints(m_MoreOptions, gbC);    p2.add(m_MoreOptions);    JPanel buttons = new JPanel();    buttons.setLayout(new GridLayout(3, 2));    buttons.add(m_ClassCombo);    m_ClassCombo.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    JPanel ssButs = new JPanel();    ssButs.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    ssButs.setLayout(new GridLayout(1, 2, 5, 5));    ssButs.add(m_StartBut);    ssButs.add(m_StopBut);    buttons.add(ssButs);    JPanel vPl = new JPanel();    vPl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    vPl.setLayout(new GridLayout(1,1,5,5));    vPl.add(m_VisualizeBut);    buttons.add(vPl);        JPanel p3 = new JPanel();    p3.setBorder(BorderFactory.createTitledBorder("Classifier output"));    p3.setLayout(new BorderLayout());    final JScrollPane js = new JScrollPane(m_OutText);    p3.add(js, BorderLayout.CENTER);    js.getViewport().addChangeListener(new ChangeListener() {      private int lastHeight;      public void stateChanged(ChangeEvent e) {	JViewport vp = (JViewport)e.getSource();	int h = vp.getViewSize().height; 	if (h != lastHeight) { // i.e. an addition not just a user scrolling	  lastHeight = h;	  int x = h - vp.getExtentSize().height;	  vp.setViewPosition(new Point(0, x));	}      }    });        JPanel mondo = new JPanel();    gbL = new GridBagLayout();    mondo.setLayout(gbL);    gbC = new GridBagConstraints();    //    gbC.anchor = GridBagConstraints.WEST;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 0;     gbC.gridx = 0;    gbL.setConstraints(p2, gbC);    mondo.add(p2);    gbC = new GridBagConstraints();    gbC.anchor = GridBagConstraints.NORTH;    gbC.fill = GridBagConstraints.HORIZONTAL;    gbC.gridy = 1;     gbC.gridx = 0;    gbL.setConstraints(buttons, gbC);    mondo.add(buttons);    gbC = new GridBagConstraints();    //gbC.anchor = GridBagConstraints.NORTH;    gbC.fill = GridBagConstraints.BOTH;    gbC.gridy = 2;     gbC.gridx = 0; gbC.weightx = 0;    gbL.setConstraints(m_History, gbC);    mondo.add(m_History);    gbC = new GridBagConstraints();    gbC.fill = GridBagConstraints.BOTH;    gbC.gridy = 0;     gbC.gridx = 1;    gbC.gridheight = 3;    gbC.weightx = 100; gbC.weighty = 100;    gbL.setConstraints(p3, gbC);    mondo.add(p3);    setLayout(new BorderLayout());    add(p1, BorderLayout.NORTH);    add(mondo, BorderLayout.CENTER);  }