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.
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.BorderLayout;
30
import javax.swing.JPanel;
31
import javax.swing.JScrollPane;
32
import javax.swing.JTextArea;
35
* This is a very simple instance viewer - just displays the dataset as
36
* text output as it would be written to a file. A more complex viewer
37
* might be more spreadsheet-like
39
* @author Len Trigg (trigg@cs.waikato.ac.nz)
40
* @version $Revision: 1.5 $
42
public class InstanceViewer
44
implements InstanceListener {
46
/** for serialization */
47
private static final long serialVersionUID = -4925729441294121772L;
49
private JTextArea m_OutputTex;
50
private boolean m_Debug;
51
private boolean m_Clear;
52
private String m_UpdateString;
54
private void updateOutput() {
56
m_OutputTex.append(m_UpdateString);
60
private void clearOutput() {
63
m_OutputTex.setText("");
66
public void inputFormat(Instances instanceInfo) {
69
System.err.println("InstanceViewer::inputFormat()\n"
70
+ instanceInfo.toString());
75
m_UpdateString += instanceInfo.toString();
79
public void input(Instance instance) throws Exception {
82
System.err.println("InstanceViewer::input(" + instance +")");
84
m_UpdateString += instance.toString() + "\n";
88
public void batchFinished() {
92
System.err.println("InstanceViewer::batchFinished()");
96
public InstanceViewer() {
98
setLayout(new BorderLayout());
100
setClearEachDataset(true);
101
m_OutputTex = new JTextArea(10,20);
102
m_OutputTex.setEditable(false);
103
add("Center", new JScrollPane(m_OutputTex));
106
public void setClearEachDataset(boolean clear) {
111
public boolean getClearEachDataset() {
116
public void setDebug(boolean debug) {
121
public boolean getDebug() {
126
public void instanceProduced(InstanceEvent e) {
128
Object source = e.getSource();
129
if (source instanceof InstanceProducer) {
131
InstanceProducer a = (InstanceProducer) source;
133
case InstanceEvent.FORMAT_AVAILABLE:
134
inputFormat(a.outputFormat());
136
case InstanceEvent.INSTANCE_AVAILABLE:
137
input(a.outputPeek());
139
case InstanceEvent.BATCH_FINISHED:
143
System.err.println("InstanceViewer::instanceProduced()"
144
+ " - unknown event type");
147
} catch (Exception ex) {
148
System.err.println(ex.getMessage());
151
System.err.println("InstanceViewer::instanceProduced()"
152
+ " - Unknown source object type");