source: src/main/java/weka/gui/beans/TestSetMaker.java @ 18

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

Import di weka.

File size: 4.4 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 *    TestSetMaker.java
19 *    Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.beans;
24
25import java.io.Serializable;
26import java.util.Vector;
27
28/**
29 * Bean that accepts data sets and produces test sets
30 *
31 * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
32 * @version $Revision: 5097 $
33 */
34public class TestSetMaker
35  extends AbstractTestSetProducer
36  implements DataSourceListener, EventConstraints, Serializable {
37
38  /** for serialization */
39  private static final long serialVersionUID = -8473882857628061841L;
40
41  protected boolean m_receivedStopNotification = false;
42
43  public TestSetMaker() {
44     m_visual.loadIcons(BeanVisual.ICON_PATH
45                       +"TestSetMaker.gif",
46                       BeanVisual.ICON_PATH
47                       +"TestSetMaker_animated.gif");
48    m_visual.setText("TestSetMaker");
49  }
50
51  /**
52   * Set a custom (descriptive) name for this bean
53   *
54   * @param name the name to use
55   */
56  public void setCustomName(String name) {
57    m_visual.setText(name);
58  }
59
60  /**
61   * Get the custom (descriptive) name for this bean (if one has been set)
62   *
63   * @return the custom name (or the default name)
64   */
65  public String getCustomName() {
66    return m_visual.getText();
67  }
68
69  /**
70   * Global info for this bean
71   *
72   * @return a <code>String</code> value
73   */
74  public String globalInfo() {
75    return "Designate an incoming data set as a test set.";
76  }
77
78  /**
79   * Accepts and processes a data set event
80   *
81   * @param e a <code>DataSetEvent</code> value
82   */
83  public void acceptDataSet(DataSetEvent e) {
84    m_receivedStopNotification = false;
85    TestSetEvent tse = new TestSetEvent(this, e.getDataSet());
86    tse.m_setNumber = 1;
87    tse.m_maxSetNumber = 1;
88    notifyTestSetProduced(tse);
89  }
90
91  /**
92   * Tells all listeners that a test set is available
93   *
94   * @param tse a <code>TestSetEvent</code> value
95   */
96  protected void notifyTestSetProduced(TestSetEvent tse) {
97    Vector l;
98    synchronized (this) {
99      l = (Vector)m_listeners.clone();
100    }
101    if (l.size() > 0) {
102      for(int i = 0; i < l.size(); i++) {
103        if (m_receivedStopNotification) {
104          if (m_logger != null) {
105            m_logger.logMessage("[TestSetMaker] "
106                + statusMessagePrefix() + " stopping.");
107            m_logger.statusMessage(statusMessagePrefix()
108                + "INTERRUPTED");
109          }
110          m_receivedStopNotification = false;
111          break;
112        }
113        ((TestSetListener)l.elementAt(i)).acceptTestSet(tse);
114      }
115    }
116  }
117
118  public void stop() {
119    // do something
120    m_receivedStopNotification = true;
121
122    // tell the listenee (upstream bean) to stop
123    if (m_listenee instanceof BeanCommon) {
124      ((BeanCommon)m_listenee).stop();
125    }
126  }
127 
128  /**
129   * Returns true if. at this time, the bean is busy with some
130   * (i.e. perhaps a worker thread is performing some calculation).
131   *
132   * @return true if the bean is busy.
133   */
134  public boolean isBusy() {
135    return false;
136  }
137
138  /**
139   * Returns true, if at the current time, the named event could
140   * be generated. Assumes that supplied event names are names of
141   * events that could be generated by this bean.
142   *
143   * @param eventName the name of the event in question
144   * @return true if the named event could be generated at this point in
145   * time
146   */
147  public boolean eventGeneratable(String eventName) {
148    if (m_listenee == null) {
149      return false;
150    }
151
152    if (m_listenee instanceof EventConstraints) {
153      if (!((EventConstraints)m_listenee).eventGeneratable("dataSet")) {
154        return false;
155      }
156    }
157    return true;
158  }
159 
160  private String statusMessagePrefix() {
161    return getCustomName() + "$" + hashCode() + "|";
162  }
163}
Note: See TracBrowser for help on using the repository browser.