source: branches/MetisMQI/src/main/java/weka/gui/beans/TrainingSetMaker.java @ 29

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

Taggata versione per la demo e aggiunto branch.

File size: 4.6 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 *    TrainingSetMaker.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 a data sets and produces a training set
30 *
31 * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
32 * @version $Revision: 4999 $
33 */
34public class TrainingSetMaker 
35  extends AbstractTrainingSetProducer
36  implements DataSourceListener, EventConstraints, Serializable {
37
38  /** for serialization */
39  private static final long serialVersionUID = -6152577265471535786L;
40
41  protected boolean m_receivedStopNotification = false;
42
43  public TrainingSetMaker() {
44    m_visual.loadIcons(BeanVisual.ICON_PATH
45                       +"TrainingSetMaker.gif",
46                       BeanVisual.ICON_PATH
47                       +"TrainingSetMaker_animated.gif");
48    m_visual.setText("TrainingSetMaker");
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 training set.";
76  }
77
78  /**
79   * Accept a data set
80   *
81   * @param e a <code>DataSetEvent</code> value
82   */
83  public void acceptDataSet(DataSetEvent e) {
84    m_receivedStopNotification = false;
85    System.err.println("In accept data set");
86    TrainingSetEvent tse = new TrainingSetEvent(this, e.getDataSet());
87    tse.m_setNumber = 1;
88    tse.m_maxSetNumber = 1;
89    notifyTrainingSetProduced(tse);
90  }
91
92  /**
93   * Inform training set listeners that a training set is available
94   *
95   * @param tse a <code>TrainingSetEvent</code> value
96   */
97  protected void notifyTrainingSetProduced(TrainingSetEvent tse) {
98    Vector l;
99    synchronized (this) {
100      l = (Vector)m_listeners.clone();
101    }
102    if (l.size() > 0) {
103      for(int i = 0; i < l.size(); i++) {
104        if (m_receivedStopNotification) {
105          if (m_logger != null) {
106            m_logger.logMessage("T[rainingSetMaker] "
107                +statusMessagePrefix() + " stopping.");
108            m_logger.statusMessage(statusMessagePrefix()
109                + "INTERRUPTED");
110          }
111          m_receivedStopNotification = false;
112          break;
113        }
114        System.err.println("Notifying listeners (training set maker)");
115        ((TrainingSetListener)l.elementAt(i)).acceptTrainingSet(tse);
116      }
117    }
118  }
119
120  /**
121   * Stop any action
122   */
123  public void stop() {
124    m_receivedStopNotification = true;
125
126    // tell the listenee (upstream bean) to stop
127    if (m_listenee instanceof BeanCommon) {
128      //      System.err.println("Listener is BeanCommon");
129      ((BeanCommon)m_listenee).stop();
130    }
131  }
132 
133  /**
134   * Returns true if. at this time, the bean is busy with some
135   * (i.e. perhaps a worker thread is performing some calculation).
136   *
137   * @return true if the bean is busy.
138   */
139  public boolean isBusy() {
140    return false;
141  }
142
143  /**
144   * Returns true, if at the current time, the named event could
145   * be generated. Assumes that supplied event names are names of
146   * events that could be generated by this bean.
147   *
148   * @param eventName the name of the event in question
149   * @return true if the named event could be generated at this point in
150   * time
151   */
152  public boolean eventGeneratable(String eventName) {
153    if (m_listenee == null) {
154      return false;
155    }
156
157    if (m_listenee instanceof EventConstraints) {
158      if (!((EventConstraints)m_listenee).eventGeneratable("dataSet")) {
159        return false;
160      }
161    }
162    return true;
163  }
164 
165  private String statusMessagePrefix() {
166    return getCustomName() + "$" + hashCode() + "|";
167  }
168}
169
Note: See TracBrowser for help on using the repository browser.