All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.gui.beans.AbstractDataSink Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This version represents the developer version, the "bleeding edge" of development, you could say. New functionality gets added to this version.

There is a newer version: 3.9.6
Show newest version
/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 *    AbstractDataSink.java
 *    Copyright (C) 2003-2012 University of Waikato, Hamilton, New Zealand
 *
 */

package weka.gui.beans;

import java.awt.BorderLayout;
import java.beans.EventSetDescriptor;
import java.io.Serializable;

import javax.swing.JPanel;

/**
 * Abstract class for objects that store instances to some destination.
 *
 * @author Mark Hall
 * @version $Revision: 8034 $
 * @since 1.0
 * @see JPanel
 * @see Serializable
 */

public abstract class AbstractDataSink
  extends JPanel
  implements DataSink, BeanCommon, Visible, 
	     DataSourceListener, TrainingSetListener,
	     TestSetListener, InstanceListener, ThresholdDataListener,
	     Serializable {

  /** for serialization */
  private static final long serialVersionUID = 3956528599473814287L;

  /**
   * Default visual for data sources
   */
  protected BeanVisual m_visual = 
    new BeanVisual("AbstractDataSink", 
		   BeanVisual.ICON_PATH+"DefaultDataSink.gif",
		   BeanVisual.ICON_PATH+"DefaultDataSink_animated.gif");

  /**
   * Non null if this object is a target for any events.
   * Provides for the simplest case when only one incomming connection
   * is allowed. Subclasses can overide the appropriate BeanCommon methods
   * to change this behaviour and allow multiple connections if desired
   */
  protected Object m_listenee = null;

  protected transient weka.gui.Logger m_logger = null;

  public AbstractDataSink() {
    useDefaultVisual();
    setLayout(new BorderLayout());
    add(m_visual, BorderLayout.CENTER);
  }

  /**
   * Accept a training set
   *
   * @param e a TrainingSetEvent value
   */
  public abstract void acceptTrainingSet(TrainingSetEvent e);

  /**
   * Accept a test set
   *
   * @param e a TestSetEvent value
   */
  public abstract void acceptTestSet(TestSetEvent e);

  /**
   * Accept a data set
   *
   * @param e a DataSetEvent value
   */
  public abstract void acceptDataSet(DataSetEvent e);
  
  /**
   * Accept a threshold data set
   *
   * @param e a ThresholdDataEvent value
   */
  public abstract void acceptDataSet(ThresholdDataEvent e);
  
  /**
   * Accept an instance
   *
   * @param e an InstanceEvent value
   */
  public abstract void acceptInstance(InstanceEvent e);

  /**
   * Set the visual for this data source
   *
   * @param newVisual a BeanVisual value
   */
  public void setVisual(BeanVisual newVisual) {
    m_visual = newVisual;
  }

  /**
   * Get the visual being used by this data source.
   *
   */
  public BeanVisual getVisual() {
    return m_visual;
  }

  /**
   * Use the default images for a data source
   *
   */
  public void useDefaultVisual() {
    m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultDataSink.gif",
		       BeanVisual.ICON_PATH+"DefaultDataSink_animated.gif");
  }

  /**
   * Returns true if, at this time, 
   * the object will accept a connection according to the supplied
   * EventSetDescriptor
   *
   * @param esd the EventSetDescriptor
   * @return true if the object will accept a connection
   */
  public boolean connectionAllowed(EventSetDescriptor esd) {
    return connectionAllowed(esd.getName());
  }

  /**
   * Returns true if, at this time, 
   * the object will accept a connection according to the supplied
   * event name
   *
   * @param eventName the event
   * @return true if the object will accept a connection
   */
  public boolean connectionAllowed(String eventName) {
    return (m_listenee == null);
  }

  /**
   * Notify this object that it has been registered as a listener with
   * a source with respect to the supplied event name
   *
   * @param eventName the event
   * @param source the source with which this object has been registered as
   * a listener
   */
  public synchronized void connectionNotification(String eventName,
						  Object source) {
    if (connectionAllowed(eventName)) {
      m_listenee = source;
    }
  }

  /**
   * Notify this object that it has been deregistered as a listener with
   * a source with respect to the supplied event name
   *
   * @param eventName the event
   * @param source the source with which this object has been registered as
   * a listener
   */
  public synchronized void disconnectionNotification(String eventName,
						     Object source) {
    if (m_listenee == source) {
      m_listenee = null;
    }
  }
  
  /**
   * Set a log for this bean
   *
   * @param logger a weka.gui.Logger value
   */
  public void setLog(weka.gui.Logger logger) {
    m_logger = logger;
  }

  /**
   * Stop any processing that the bean might be doing.
   * Subclass must implement
   */
  public abstract void stop();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy