AbstractTrainingSetProducer.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 5k
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.  *    AbstractTrainingSetProducer.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.SwingConstants;
  29. import java.awt.*;
  30. import java.beans.EventSetDescriptor;
  31. /**
  32.  * Abstract class for TrainingSetProducers that contains default
  33.  * implementations of add/remove listener methods and default
  34.  * visual representation
  35.  *
  36.  * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
  37.  * @version $Revision: 1.2 $
  38.  * @since 1.0
  39.  * @see TrainingSetProducer
  40.  * @see DataSetListener
  41.  */
  42. public abstract class AbstractTrainingSetProducer extends JPanel
  43.   implements TrainingSetProducer, Visible, 
  44.      BeanCommon, Serializable {
  45.   /**
  46.    * Objects listening for training set events
  47.    */
  48.   protected Vector m_listeners = new Vector();
  49.   protected BeanVisual m_visual = 
  50.     new BeanVisual("AbstractTraingSetProducer", 
  51.    BeanVisual.ICON_PATH+"DefaultTrainTest.gif",
  52.    BeanVisual.ICON_PATH+"DefaultTrainTest_animated.gif");
  53.   
  54.   /**
  55.    * non null if this object is a target for any events.
  56.    */
  57.   protected Object m_listenee = null;
  58.   private transient weka.gui.Logger m_logger = null;
  59.   /**
  60.    * Creates a new <code>AbstractTrainingSetProducer</code> instance.
  61.    */
  62.   public AbstractTrainingSetProducer() {
  63.     setLayout(new BorderLayout());
  64.     add(m_visual, BorderLayout.CENTER);
  65.   }
  66.   /**
  67.    * Add a training set listener
  68.    *
  69.    * @param tsl a <code>TrainingSetListener</code> value
  70.    */
  71.   public synchronized void addTrainingSetListener(TrainingSetListener tsl) {
  72.     m_listeners.addElement(tsl);
  73.   }
  74.   /**
  75.    * Remove a training set listener
  76.    *
  77.    * @param tsl a <code>TrainingSetListener</code> value
  78.    */
  79.   public synchronized void removeTrainingSetListener(TrainingSetListener tsl) {
  80.     m_listeners.removeElement(tsl);
  81.   }
  82.   /**
  83.    * Set the visual for this bean
  84.    *
  85.    * @param newVisual a <code>BeanVisual</code> value
  86.    */
  87.   public void setVisual(BeanVisual newVisual) {
  88.     m_visual = newVisual;
  89.   }
  90.   /**
  91.    * Get the visual for this bean
  92.    *
  93.    * @return a <code>BeanVisual</code> value
  94.    */
  95.   public BeanVisual getVisual() {
  96.     return m_visual;
  97.   }
  98.   
  99.   /**
  100.    * Use the default visual for this bean
  101.    */
  102.   public void useDefaultVisual() {
  103.     m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultTrainTest.gif",
  104.        BeanVisual.ICON_PATH+"DefaultTrainTest_animated.gif");
  105.   }
  106.   
  107.   /**
  108.    * Returns true if, at this time, 
  109.    * the object will accept a connection according to the supplied
  110.    * event name
  111.    *
  112.    * @param eventName the event
  113.    * @return true if the object will accept a connection
  114.    */
  115.   public boolean connectionAllowed(String eventName) {
  116.     return (m_listenee == null);
  117.   }
  118.   /**
  119.    * Notify this object that it has been registered as a listener with
  120.    * a source with respect to the supplied event name
  121.    *
  122.    * @param eventName
  123.    * @param source the source with which this object has been registered as
  124.    * a listener
  125.    */
  126.   public synchronized void connectionNotification(String eventName,
  127.   Object source) {
  128.     if (connectionAllowed(eventName)) {
  129.       m_listenee = source;
  130.     }
  131.   }
  132.   /**
  133.    * Notify this object that it has been deregistered as a listener with
  134.    * a source with respect to the supplied event name
  135.    *
  136.    * @param eventName the event name
  137.    * @param source the source with which this object has been registered as
  138.    * a listener
  139.    */
  140.   public synchronized void disconnectionNotification(String eventName,
  141.      Object source) {
  142.     if (m_listenee == source) {
  143.       m_listenee = null;
  144.     }
  145.   }
  146.   /**
  147.    * Set a logger
  148.    *
  149.    * @param logger a <code>weka.gui.Logger</code> value
  150.    */
  151.   public void setLog(weka.gui.Logger logger) {
  152.     m_logger = logger;
  153.   }
  154.   /**
  155.    * Stop any processing that the bean might be doing.
  156.    * Subclass must implement
  157.    */
  158.   public abstract void stop();
  159. }