TrainingSetMaker.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 3k
Category:

Windows Develop

Development Platform:

Java

  1. /*
  2.  *    This program is free software; you can redistribute it and/or modify
  3.  *    it under the terms of the GNU General Public License as published by
  4.  *    the Free Software Foundation; either version 2 of the License, or
  5.  *    (at your option) any later version.
  6.  *
  7.  *    This program is distributed in the hope that it will be useful,
  8.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  *    GNU General Public License for more details.
  11.  *
  12.  *    You should have received a copy of the GNU General Public License
  13.  *    along with this program; if not, write to the Free Software
  14.  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.  */
  16. /*
  17.  *    TrainingSetMaker.java
  18.  *    Copyright (C) 2002 Mark Hall
  19.  *
  20.  */
  21. package weka.gui.beans;
  22. import java.io.Serializable;
  23. import java.util.Vector;
  24. import javax.swing.JPanel;
  25. import javax.swing.JLabel;
  26. import javax.swing.JTextField;
  27. import java.awt.BorderLayout;
  28. import javax.swing.ImageIcon;
  29. import javax.swing.SwingConstants;
  30. import java.awt.*;
  31. /**
  32.  * Bean that accepts a data sets and produces a training set
  33.  *
  34.  * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
  35.  * @version $Revision: 1.1 $
  36.  */
  37. public class TrainingSetMaker 
  38.   extends AbstractTrainingSetProducer 
  39.   implements DataSourceListener, EventConstraints, Serializable {
  40.   public TrainingSetMaker() {
  41.     super();
  42.     m_visual.setText("TrainingSetMaker");
  43.   }
  44.   /**
  45.    * Accept a data set
  46.    *
  47.    * @param e a <code>DataSetEvent</code> value
  48.    */
  49.   public void acceptDataSet(DataSetEvent e) {
  50.     System.err.println("In accept data set");
  51.     TrainingSetEvent tse = new TrainingSetEvent(this, e.getDataSet());
  52.     tse.m_setNumber = 1;
  53.     tse.m_maxSetNumber = 1;
  54.     notifyTrainingSetProduced(tse);
  55.   }
  56.   /**
  57.    * Inform training set listeners that a training set is availabel
  58.    *
  59.    * @param tse a <code>TrainingSetEvent</code> value
  60.    */
  61.   protected void notifyTrainingSetProduced(TrainingSetEvent tse) {
  62.     Vector l;
  63.     synchronized (this) {
  64.       l = (Vector)m_listeners.clone();
  65.     }
  66.     if (l.size() > 0) {
  67.       for(int i = 0; i < l.size(); i++) {
  68. System.err.println("Notifying listeners (training set maker)");
  69. ((TrainingSetListener)l.elementAt(i)).acceptTrainingSet(tse);
  70.       }
  71.     }
  72.   }
  73.   /**
  74.    * Stop any action
  75.    */
  76.   public void stop() {
  77.     // do something
  78.   }
  79.   /**
  80.    * Returns true, if at the current time, the named event could
  81.    * be generated. Assumes that supplied event names are names of
  82.    * events that could be generated by this bean.
  83.    *
  84.    * @param eventName the name of the event in question
  85.    * @return true if the named event could be generated at this point in
  86.    * time
  87.    */
  88.   public boolean eventGeneratable(String eventName) {
  89.     if (m_listenee == null) {
  90.       return false;
  91.     }
  92.     if (m_listenee instanceof EventConstraints) {
  93.       if (!((EventConstraints)m_listenee).eventGeneratable("dataSet")) {
  94. return false;
  95.       }
  96.     }
  97.     return true;
  98.   }
  99. }