[29] | 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 | * AbstractDataSink.java |
---|
| 19 | * Copyright (C) 2003 University of Waikato, Hamilton, New Zealand |
---|
| 20 | * |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | package weka.gui.beans; |
---|
| 24 | |
---|
| 25 | import java.awt.BorderLayout; |
---|
| 26 | import java.beans.EventSetDescriptor; |
---|
| 27 | import java.io.Serializable; |
---|
| 28 | |
---|
| 29 | import javax.swing.JPanel; |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * Abstract class for objects that store instances to some destination. |
---|
| 33 | * |
---|
| 34 | * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a> |
---|
| 35 | * @version $Revision: 5753 $ |
---|
| 36 | * @since 1.0 |
---|
| 37 | * @see JPanel |
---|
| 38 | * @see Serializable |
---|
| 39 | */ |
---|
| 40 | |
---|
| 41 | public abstract class AbstractDataSink |
---|
| 42 | extends JPanel |
---|
| 43 | implements DataSink, BeanCommon, Visible, |
---|
| 44 | DataSourceListener, TrainingSetListener, |
---|
| 45 | TestSetListener, InstanceListener, ThresholdDataListener, |
---|
| 46 | Serializable { |
---|
| 47 | |
---|
| 48 | /** for serialization */ |
---|
| 49 | private static final long serialVersionUID = 3956528599473814287L; |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * Default visual for data sources |
---|
| 53 | */ |
---|
| 54 | protected BeanVisual m_visual = |
---|
| 55 | new BeanVisual("AbstractDataSink", |
---|
| 56 | BeanVisual.ICON_PATH+"DefaultDataSink.gif", |
---|
| 57 | BeanVisual.ICON_PATH+"DefaultDataSink_animated.gif"); |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * Non null if this object is a target for any events. |
---|
| 61 | * Provides for the simplest case when only one incomming connection |
---|
| 62 | * is allowed. Subclasses can overide the appropriate BeanCommon methods |
---|
| 63 | * to change this behaviour and allow multiple connections if desired |
---|
| 64 | */ |
---|
| 65 | protected Object m_listenee = null; |
---|
| 66 | |
---|
| 67 | protected transient weka.gui.Logger m_logger = null; |
---|
| 68 | |
---|
| 69 | public AbstractDataSink() { |
---|
| 70 | useDefaultVisual(); |
---|
| 71 | setLayout(new BorderLayout()); |
---|
| 72 | add(m_visual, BorderLayout.CENTER); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * Accept a training set |
---|
| 77 | * |
---|
| 78 | * @param e a <code>TrainingSetEvent</code> value |
---|
| 79 | */ |
---|
| 80 | public abstract void acceptTrainingSet(TrainingSetEvent e); |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * Accept a test set |
---|
| 84 | * |
---|
| 85 | * @param e a <code>TestSetEvent</code> value |
---|
| 86 | */ |
---|
| 87 | public abstract void acceptTestSet(TestSetEvent e); |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * Accept a data set |
---|
| 91 | * |
---|
| 92 | * @param e a <code>DataSetEvent</code> value |
---|
| 93 | */ |
---|
| 94 | public abstract void acceptDataSet(DataSetEvent e); |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | * Accept a threshold data set |
---|
| 98 | * |
---|
| 99 | * @param e a <code>ThresholdDataEvent</code> value |
---|
| 100 | */ |
---|
| 101 | public abstract void acceptDataSet(ThresholdDataEvent e); |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | * Accept an instance |
---|
| 105 | * |
---|
| 106 | * @param e an <code>InstanceEvent</code> value |
---|
| 107 | */ |
---|
| 108 | public abstract void acceptInstance(InstanceEvent e); |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | * Set the visual for this data source |
---|
| 112 | * |
---|
| 113 | * @param newVisual a <code>BeanVisual</code> value |
---|
| 114 | */ |
---|
| 115 | public void setVisual(BeanVisual newVisual) { |
---|
| 116 | m_visual = newVisual; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * Get the visual being used by this data source. |
---|
| 121 | * |
---|
| 122 | */ |
---|
| 123 | public BeanVisual getVisual() { |
---|
| 124 | return m_visual; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | * Use the default images for a data source |
---|
| 129 | * |
---|
| 130 | */ |
---|
| 131 | public void useDefaultVisual() { |
---|
| 132 | m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultDataSink.gif", |
---|
| 133 | BeanVisual.ICON_PATH+"DefaultDataSink_animated.gif"); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | * Returns true if, at this time, |
---|
| 138 | * the object will accept a connection according to the supplied |
---|
| 139 | * EventSetDescriptor |
---|
| 140 | * |
---|
| 141 | * @param esd the EventSetDescriptor |
---|
| 142 | * @return true if the object will accept a connection |
---|
| 143 | */ |
---|
| 144 | public boolean connectionAllowed(EventSetDescriptor esd) { |
---|
| 145 | return connectionAllowed(esd.getName()); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * Returns true if, at this time, |
---|
| 150 | * the object will accept a connection according to the supplied |
---|
| 151 | * event name |
---|
| 152 | * |
---|
| 153 | * @param eventName the event |
---|
| 154 | * @return true if the object will accept a connection |
---|
| 155 | */ |
---|
| 156 | public boolean connectionAllowed(String eventName) { |
---|
| 157 | return (m_listenee == null); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | * Notify this object that it has been registered as a listener with |
---|
| 162 | * a source with respect to the supplied event name |
---|
| 163 | * |
---|
| 164 | * @param eventName the event |
---|
| 165 | * @param source the source with which this object has been registered as |
---|
| 166 | * a listener |
---|
| 167 | */ |
---|
| 168 | public synchronized void connectionNotification(String eventName, |
---|
| 169 | Object source) { |
---|
| 170 | if (connectionAllowed(eventName)) { |
---|
| 171 | m_listenee = source; |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | /** |
---|
| 176 | * Notify this object that it has been deregistered as a listener with |
---|
| 177 | * a source with respect to the supplied event name |
---|
| 178 | * |
---|
| 179 | * @param eventName the event |
---|
| 180 | * @param source the source with which this object has been registered as |
---|
| 181 | * a listener |
---|
| 182 | */ |
---|
| 183 | public synchronized void disconnectionNotification(String eventName, |
---|
| 184 | Object source) { |
---|
| 185 | if (m_listenee == source) { |
---|
| 186 | m_listenee = null; |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | /** |
---|
| 191 | * Set a log for this bean |
---|
| 192 | * |
---|
| 193 | * @param logger a <code>weka.gui.Logger</code> value |
---|
| 194 | */ |
---|
| 195 | public void setLog(weka.gui.Logger logger) { |
---|
| 196 | m_logger = logger; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | /** |
---|
| 200 | * Stop any processing that the bean might be doing. |
---|
| 201 | * Subclass must implement |
---|
| 202 | */ |
---|
| 203 | public abstract void stop(); |
---|
| 204 | } |
---|