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.
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.
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.
18
* InstanceCounter.java
19
* Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
23
package weka.gui.streams;
25
import weka.core.Instance;
26
import weka.core.Instances;
28
import java.awt.Color;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
34
* A bean that counts instances streamed to it.
36
* @author Len Trigg (trigg@cs.waikato.ac.nz)
37
* @version $Revision: 1.5 $
39
public class InstanceCounter
41
implements InstanceListener {
43
/** for serialization */
44
private static final long serialVersionUID = -6084967152645935934L;
46
private JLabel m_Count_Lab;
48
private boolean m_Debug;
50
public void input(Instance instance) throws Exception {
53
System.err.println("InstanceCounter::input(" + instance +")");
56
m_Count_Lab.setText(""+m_Count+" instances");
60
public void inputFormat(Instances instanceInfo) {
63
System.err.println("InstanceCounter::inputFormat()");
65
Instances inputInstances = new Instances(instanceInfo,0);
67
m_Count_Lab.setText(""+m_Count+" instances");
70
public void setDebug(boolean debug) {
75
public boolean getDebug() {
80
public InstanceCounter() {
83
m_Count_Lab = new JLabel("no instances");
86
setBackground(Color.lightGray);
89
public void instanceProduced(InstanceEvent e) {
91
Object source = e.getSource();
92
if (source instanceof InstanceProducer) {
94
InstanceProducer a = (InstanceProducer) source;
96
case InstanceEvent.FORMAT_AVAILABLE:
97
inputFormat(a.outputFormat());
99
case InstanceEvent.INSTANCE_AVAILABLE:
100
input(a.outputPeek());
102
case InstanceEvent.BATCH_FINISHED:
104
System.err.println("InstanceCounter::instanceProduced() - End of instance batch");
107
System.err.println("InstanceCounter::instanceProduced() - unknown event type");
110
} catch (Exception ex) {
111
System.err.println(ex.getMessage());
114
System.err.println("InstanceCounter::instanceProduced() - Unknown source object type");