source: src/main/java/weka/gui/beans/AbstractEvaluator.java @ 9

Last change on this file since 9 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 4.3 KB
Line 
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/*
18 *    AbstractEvaluator.java
19 *    Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.beans;
24
25import weka.gui.Logger;
26
27import java.awt.BorderLayout;
28import java.beans.EventSetDescriptor;
29import java.io.Serializable;
30
31import javax.swing.JPanel;
32
33/**
34 * Abstract class for objects that can provide some kind of evaluation for
35 * classifier, clusterers etc.
36 *
37 * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
38 * @version $Revision: 1.5 $
39 * @since 1.0
40 * @see JPanel
41 * @see Visible
42 * @see Serializable
43 */
44public abstract class AbstractEvaluator
45  extends JPanel
46  implements Visible, BeanCommon, Serializable {
47
48  /** for serialization */
49  private static final long serialVersionUID = 3983303541814121632L;
50 
51  /**
52   * Default visual for evaluators
53   */
54  protected BeanVisual m_visual = 
55    new BeanVisual("AbstractEvaluator", 
56                   BeanVisual.ICON_PATH+"DefaultEvaluator.gif",
57                   BeanVisual.ICON_PATH+"DefaultEvaluator_animated.gif");
58
59  protected Object m_listenee = null;
60
61  protected transient Logger m_logger = null;
62
63  /**
64   * Constructor
65   */
66  public AbstractEvaluator() {
67    setLayout(new BorderLayout());
68    add(m_visual, BorderLayout.CENTER);
69  }
70
71  /**
72   * Set the visual
73   *
74   * @param newVisual a <code>BeanVisual</code> value
75   */
76  public void setVisual(BeanVisual newVisual) {
77    m_visual = newVisual;
78  }
79
80  /**
81   * Get the visual
82   *
83   * @return a <code>BeanVisual</code> value
84   */
85  public BeanVisual getVisual() {
86    return m_visual;
87  }
88 
89  /**
90   * Use the default images for an evaluator
91   */
92  public void useDefaultVisual() {
93    m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultEvaluator.gif",
94                       BeanVisual.ICON_PATH+"DefaultEvaluator_animated.gif");
95  }
96
97  /**
98   * Returns true if, at this time,
99   * the object will accept a connection according to the supplied
100   * event name
101   *
102   * @param eventName the event name
103   * @return true if the object will accept a connection
104   */
105  public boolean connectionAllowed(String eventName) {
106    return (m_listenee == null);
107  }
108
109  /**
110   * Returns true if, at this time,
111   * the object will accept a connection according to the supplied
112   * EventSetDescriptor
113   *
114   * @param esd the EventSetDescriptor
115   * @return true if the object will accept a connection
116   */
117  public boolean connectionAllowed(EventSetDescriptor esd) {
118    return connectionAllowed(esd.getName());
119  }
120
121  /**
122   * Notify this object that it has been registered as a listener with
123   * a source with respect to the supplied event name
124   *
125   * @param eventName the event name
126   * @param source the source with which this object has been registered as
127   * a listener
128   */
129  public synchronized void connectionNotification(String eventName,
130                                                  Object source) {
131    if (connectionAllowed(eventName)) {
132      m_listenee = source;
133    }
134  }
135
136  /**
137   * Notify this object that it has been deregistered as a listener with
138   * a source with respect to the supplied event named
139   *
140   * @param eventName the event name
141   * @param source the source with which this object has been registered as
142   * a listener
143   */
144  public synchronized void disconnectionNotification(String eventName,
145                                                     Object source) {
146    if (m_listenee == source) {
147      m_listenee = null;
148    }
149  }
150 
151  /**
152   * Set a logger
153   *
154   * @param logger a <code>weka.gui.Logger</code> value
155   */
156  public void setLog(weka.gui.Logger logger) {
157    m_logger = logger;
158  }
159
160  /**
161   * Stop any processing that the bean might be doing.
162   * Subclass must implement
163   */
164  public abstract void stop();
165
166}
167
Note: See TracBrowser for help on using the repository browser.