AbstractEvaluator.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 4k
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.  *    AbstractEvaluator.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. import weka.gui.Logger;
  32. /**
  33.  * Abstract class for objects that can provide some kind of evaluation for
  34.  * classifier, clusterers etc.
  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 JPanel
  40.  * @see Visible
  41.  * @see Serializable
  42.  */
  43. public abstract class AbstractEvaluator extends JPanel
  44.   implements Visible, BeanCommon, Serializable {
  45.   
  46.   /**
  47.    * Default visual for evaluators
  48.    */
  49.   protected BeanVisual m_visual = 
  50.     new BeanVisual("AbstractEvaluator", 
  51.    BeanVisual.ICON_PATH+"DefaultEvaluator.gif",
  52.    BeanVisual.ICON_PATH+"DefaultEvaluator_animated.gif");
  53.   protected Object m_listenee = null;
  54.   protected transient Logger m_logger = null;
  55.   /**
  56.    * Constructor
  57.    */
  58.   public AbstractEvaluator() {
  59.     setLayout(new BorderLayout());
  60.     add(m_visual, BorderLayout.CENTER);
  61.   }
  62.   /**
  63.    * Set the visual
  64.    *
  65.    * @param newVisual a <code>BeanVisual</code> value
  66.    */
  67.   public void setVisual(BeanVisual newVisual) {
  68.     m_visual = newVisual;
  69.   }
  70.   /**
  71.    * Get the visual
  72.    *
  73.    * @return a <code>BeanVisual</code> value
  74.    */
  75.   public BeanVisual getVisual() {
  76.     return m_visual;
  77.   }
  78.   
  79.   /**
  80.    * Use the default images for an evaluator
  81.    */
  82.   public void useDefaultVisual() {
  83.     m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultEvaluator.gif",
  84.        BeanVisual.ICON_PATH+"DefaultEvaluator_animated.gif");
  85.   }
  86.   /**
  87.    * Returns true if, at this time, 
  88.    * the object will accept a connection according to the supplied
  89.    * event name
  90.    *
  91.    * @param eventName the event name
  92.    * @return true if the object will accept a connection
  93.    */
  94.   public boolean connectionAllowed(String eventName) {
  95.     return (m_listenee == null);
  96.   }
  97.   /**
  98.    * Notify this object that it has been registered as a listener with
  99.    * a source with respect to the supplied event name
  100.    *
  101.    * @param eventName the event name
  102.    * @param source the source with which this object has been registered as
  103.    * a listener
  104.    */
  105.   public synchronized void connectionNotification(String eventName,
  106.   Object source) {
  107.     if (connectionAllowed(eventName)) {
  108.       m_listenee = source;
  109.     }
  110.   }
  111.   /**
  112.    * Notify this object that it has been deregistered as a listener with
  113.    * a source with respect to the supplied event named
  114.    *
  115.    * @param eventName the event name
  116.    * @param source the source with which this object has been registered as
  117.    * a listener
  118.    */
  119.   public synchronized void disconnectionNotification(String eventName,
  120.      Object source) {
  121.     if (m_listenee == source) {
  122.       m_listenee = null;
  123.     }
  124.   }
  125.   
  126.   /**
  127.    * Set a logger
  128.    *
  129.    * @param logger a <code>weka.gui.Logger</code> value
  130.    */
  131.   public void setLog(weka.gui.Logger logger) {
  132.     m_logger = logger;
  133.   }
  134.   /**
  135.    * Stop any processing that the bean might be doing.
  136.    * Subclass must implement
  137.    */
  138.   public abstract void stop();
  139. }