source: branches/MetisMQI/src/main/java/weka/gui/beans/AbstractTestSetProducer.java

Last change on this file was 29, checked in by gnappo, 14 years ago

Taggata versione per la demo e aggiunto branch.

File size: 5.0 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 *    AbstractTestSetProducer.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 TestSetProducers that contains default
34 * implementations of add/remove listener methods and defualt
35 * visual representation.
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 TestSetProducer
41 */
42public abstract class AbstractTestSetProducer
43  extends JPanel
44  implements TestSetProducer, Visible, 
45             BeanCommon, Serializable {
46
47  /** for serialization */
48  private static final long serialVersionUID = -7905764845789349839L;
49
50  /**
51   * Objects listening to us
52   */
53  protected Vector m_listeners = new Vector();
54
55  protected BeanVisual m_visual = 
56    new BeanVisual("AbstractTestSetProducer", 
57                    BeanVisual.ICON_PATH+"DefaultTrainTest.gif",
58                    BeanVisual.ICON_PATH+"DefaultTrainTest_animated.gif");
59
60  /**
61   * non null if this object is a target for any events.
62   */
63  protected Object m_listenee = null;
64
65  /**
66   * Logger
67   */
68  protected transient weka.gui.Logger m_logger = null;
69
70  /**
71   * Creates a new <code>AbstractTestSetProducer</code> instance.
72   */
73  public AbstractTestSetProducer() {
74
75    setLayout(new BorderLayout());
76    add(m_visual, BorderLayout.CENTER);
77  }
78
79  /**
80   * Add a listener for test sets
81   *
82   * @param tsl a <code>TestSetListener</code> value
83   */
84  public synchronized void addTestSetListener(TestSetListener tsl) {
85    m_listeners.addElement(tsl);
86  }
87
88  /**
89   * Remove a listener for test sets
90   *
91   * @param tsl a <code>TestSetListener</code> value
92   */
93  public synchronized void removeTestSetListener(TestSetListener tsl) {
94    m_listeners.removeElement(tsl);
95  }
96
97  /**
98   * Set the visual for this bean
99   *
100   * @param newVisual a <code>BeanVisual</code> value
101   */
102  public void setVisual(BeanVisual newVisual) {
103    m_visual = newVisual;
104  }
105 
106  /**
107   * Get the visual for this bean
108   *
109   * @return a <code>BeanVisual</code> value
110   */
111  public BeanVisual getVisual() {
112    return m_visual;
113  }
114 
115  /**
116   * Use the default visual for this bean
117   */
118  public void useDefaultVisual() {
119    m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultTrainTest.gif",
120                       BeanVisual.ICON_PATH+"DefaultTrainTest_animated.gif");
121  }
122
123  /**
124   * Returns true if, at this time,
125   * the object will accept a connection according to the supplied
126   * event name
127   *
128   * @param eventName the event name
129   * @return true if the object will accept a connection
130   */
131  public boolean connectionAllowed(String eventName) {
132    return (m_listenee == null);
133  }
134
135  /**
136   * Returns true if, at this time,
137   * the object will accept a connection according to the supplied
138   * EventSetDescriptor
139   *
140   * @param esd the EventSetDescriptor
141   * @return true if the object will accept a connection
142   */
143  public boolean connectionAllowed(EventSetDescriptor esd) {
144    return connectionAllowed(esd.getName());
145  }
146
147  /**
148   * Notify this object that it has been registered as a listener with
149   * a source with respect to the supplied event name
150   *
151   * @param eventName the event name
152   * @param source the source with which this object has been registered as
153   * a listener
154   */
155  public synchronized void connectionNotification(String eventName,
156                                                  Object source) {
157    if (connectionAllowed(eventName)) {
158      m_listenee = source;
159    }
160  }
161
162  /**
163   * Notify this object that it has been deregistered as a listener with
164   * a source with respect to the supplied event name
165   *
166   * @param eventName the event name
167   * @param source the source with which this object has been registered as
168   * a listener
169   */
170  public synchronized void disconnectionNotification(String eventName,
171                                                     Object source) {
172    if (m_listenee == source) {
173      m_listenee = null;
174    }
175  }
176     
177  /**
178   * Set a logger
179   *
180   * @param logger a <code>weka.gui.Logger</code> value
181   */
182  public void setLog(weka.gui.Logger logger) {
183    m_logger = logger;
184  }
185
186  /**
187   * Stop any processing that the bean might be doing.
188   * Subclass must implement
189   */
190  public abstract void stop();
191
192}
Note: See TracBrowser for help on using the repository browser.