source: src/main/java/weka/gui/beans/AbstractTrainingSetProducer.java @ 24

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

Import di weka.

File size: 5.0 KB
RevLine 
[4]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 *    AbstractTrainingSetProducer.java
19 *    Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.beans;
24
25import java.awt.BorderLayout;
26import java.beans.EventSetDescriptor;
27import java.io.Serializable;
28import java.util.Vector;
29
30import javax.swing.JPanel;
31
32/**
33 * Abstract class for TrainingSetProducers that contains default
34 * implementations of add/remove listener methods and default
35 * visual representation
36 *
37 * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
38 * @version $Revision: 1.7 $
39 * @since 1.0
40 * @see TrainingSetProducer
41 */
42public abstract class AbstractTrainingSetProducer
43  extends JPanel
44  implements TrainingSetProducer, Visible, 
45             BeanCommon, Serializable {
46
47  /** for serialization */
48  private static final long serialVersionUID = -7842746199524591125L;
49
50  /**
51   * Objects listening for training set events
52   */
53  protected Vector m_listeners = new Vector();
54
55  protected BeanVisual m_visual = 
56    new BeanVisual("AbstractTraingSetProducer", 
57                   BeanVisual.ICON_PATH+"DefaultTrainTest.gif",
58                   BeanVisual.ICON_PATH+"DefaultTrainTest_animated.gif");
59
60 
61  /**
62   * non null if this object is a target for any events.
63   */
64  protected Object m_listenee = null;
65
66  protected transient weka.gui.Logger m_logger = null;
67
68  /**
69   * Creates a new <code>AbstractTrainingSetProducer</code> instance.
70   */
71  public AbstractTrainingSetProducer() {
72    setLayout(new BorderLayout());
73    add(m_visual, BorderLayout.CENTER);
74  }
75
76  /**
77   * Add a training set listener
78   *
79   * @param tsl a <code>TrainingSetListener</code> value
80   */
81  public synchronized void addTrainingSetListener(TrainingSetListener tsl) {
82    m_listeners.addElement(tsl);
83  }
84
85  /**
86   * Remove a training set listener
87   *
88   * @param tsl a <code>TrainingSetListener</code> value
89   */
90  public synchronized void removeTrainingSetListener(TrainingSetListener tsl) {
91    m_listeners.removeElement(tsl);
92  }
93
94  /**
95   * Set the visual for this bean
96   *
97   * @param newVisual a <code>BeanVisual</code> value
98   */
99  public void setVisual(BeanVisual newVisual) {
100    m_visual = newVisual;
101  }
102
103  /**
104   * Get the visual for this bean
105   *
106   * @return a <code>BeanVisual</code> value
107   */
108  public BeanVisual getVisual() {
109    return m_visual;
110  }
111 
112  /**
113   * Use the default visual for this bean
114   */
115  public void useDefaultVisual() {
116    m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultTrainTest.gif",
117                       BeanVisual.ICON_PATH+"DefaultTrainTest_animated.gif");
118  }
119 
120  /**
121   * Returns true if, at this time,
122   * the object will accept a connection according to the supplied
123   * event name
124   *
125   * @param eventName the event
126   * @return true if the object will accept a connection
127   */
128  public boolean connectionAllowed(String eventName) {
129    return (m_listenee == null);
130  }
131
132  /**
133   * Returns true if, at this time,
134   * the object will accept a connection according to the supplied
135   * EventSetDescriptor
136   *
137   * @param esd the EventSetDescriptor
138   * @return true if the object will accept a connection
139   */
140  public boolean connectionAllowed(EventSetDescriptor esd) {
141    return connectionAllowed(esd.getName());
142  }
143
144  /**
145   * Notify this object that it has been registered as a listener with
146   * a source with respect to the supplied event name
147   *
148   * @param eventName
149   * @param source the source with which this object has been registered as
150   * a listener
151   */
152  public synchronized void connectionNotification(String eventName,
153                                                  Object source) {
154    if (connectionAllowed(eventName)) {
155      m_listenee = source;
156    }
157  }
158
159  /**
160   * Notify this object that it has been deregistered as a listener with
161   * a source with respect to the supplied event name
162   *
163   * @param eventName the event name
164   * @param source the source with which this object has been registered as
165   * a listener
166   */
167  public synchronized void disconnectionNotification(String eventName,
168                                                     Object source) {
169    if (m_listenee == source) {
170      m_listenee = null;
171    }
172  }
173
174  /**
175   * Set a logger
176   *
177   * @param logger a <code>weka.gui.Logger</code> value
178   */
179  public void setLog(weka.gui.Logger logger) {
180    m_logger = logger;
181  }
182
183  /**
184   * Stop any processing that the bean might be doing.
185   * Subclass must implement
186   */
187  public abstract void stop();
188
189}
190
191
192
Note: See TracBrowser for help on using the repository browser.