source: src/main/java/weka/gui/beans/AbstractDataSource.java @ 14

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

Import di weka.

File size: 5.7 KB
RevLine 
[4]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 *    AbstractDataSource.java
19 *    Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.beans;
24
25import java.awt.BorderLayout;
26import java.beans.PropertyChangeListener;
27import java.beans.VetoableChangeListener;
28import java.beans.beancontext.BeanContext;
29import java.beans.beancontext.BeanContextChild;
30import java.beans.beancontext.BeanContextChildSupport;
31import java.io.Serializable;
32import java.util.Vector;
33
34import javax.swing.JPanel;
35
36/**
37 * Abstract class for objects that can provide instances from some source
38 *
39 * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
40 * @version $Revision: 1.4 $
41 * @since 1.0
42 * @see JPanel
43 * @see DataSource
44 * @see Serializable
45 */
46public abstract class AbstractDataSource
47  extends JPanel
48  implements DataSource, Visible, Serializable, BeanContextChild {
49
50  /** for serialization */
51  private static final long serialVersionUID = -4127257701890044793L;
52
53  /**
54   * True if this bean's appearance is the design mode appearance
55   */
56  protected boolean m_design;
57 
58  /**
59   * BeanContex that this bean might be contained within
60   */
61  protected transient BeanContext m_beanContext = null;
62
63  /**
64   * BeanContextChild support
65   */
66  protected BeanContextChildSupport m_bcSupport = 
67    new BeanContextChildSupport(this);
68
69  /**
70   * Default visual for data sources
71   */
72  protected BeanVisual m_visual = 
73    new BeanVisual("AbstractDataSource", 
74                   BeanVisual.ICON_PATH+"DefaultDataSource.gif",
75                   BeanVisual.ICON_PATH+"DefaultDataSource_animated.gif");
76 
77  /**
78   * Objects listening for events from data sources
79   */
80  protected Vector m_listeners;
81
82  /**
83   * Creates a new <code>AbstractDataSource</code> instance.
84   *
85   */
86  public AbstractDataSource() {   
87    useDefaultVisual();
88    setLayout(new BorderLayout());
89    add(m_visual, BorderLayout.CENTER);
90    m_listeners = new Vector();
91  }
92
93  /**
94   * Add a listener
95   *
96   * @param dsl a <code>DataSourceListener</code> value
97   */
98  public synchronized void addDataSourceListener(DataSourceListener dsl) {
99    m_listeners.addElement(dsl);
100  }
101 
102  /**
103   * Remove a listener
104   *
105   * @param dsl a <code>DataSourceListener</code> value
106   */
107  public synchronized void removeDataSourceListener(DataSourceListener dsl) {
108    m_listeners.remove(dsl);
109  }
110
111  /**
112   * Add an instance listener
113   *
114   * @param dsl a <code>InstanceListener</code> value
115   */
116  public synchronized void addInstanceListener(InstanceListener dsl) {
117    m_listeners.addElement(dsl);
118  }
119 
120  /**
121   * Remove an instance listener
122   *
123   * @param dsl a <code>InstanceListener</code> value
124   */
125  public synchronized void removeInstanceListener(InstanceListener dsl) {
126    m_listeners.remove(dsl);
127  }
128
129  /**
130   * Set the visual for this data source
131   *
132   * @param newVisual a <code>BeanVisual</code> value
133   */
134  public void setVisual(BeanVisual newVisual) {
135    m_visual = newVisual;
136  }
137
138  /**
139   * Get the visual being used by this data source.
140   *
141   */
142  public BeanVisual getVisual() {
143    return m_visual;
144  }
145
146  /**
147   * Use the default images for a data source
148   *
149   */
150  public void useDefaultVisual() {
151    m_visual.loadIcons(BeanVisual.ICON_PATH+"DefaultDataSource.gif",
152                       BeanVisual.ICON_PATH+"DefaultDataSource_animated.gif");
153  }
154
155  /**
156   * Set a bean context for this bean
157   *
158   * @param bc a <code>BeanContext</code> value
159   */
160  public void setBeanContext(BeanContext bc) {
161    m_beanContext = bc;
162    m_design = m_beanContext.isDesignTime();
163  }
164
165  /**
166   * Return the bean context (if any) that this bean is embedded in
167   *
168   * @return a <code>BeanContext</code> value
169   */
170  public BeanContext getBeanContext() {
171    return m_beanContext;
172  }
173
174  /**
175   * Add a property change listener to this bean
176   *
177   * @param name the name of the property of interest
178   * @param pcl a <code>PropertyChangeListener</code> value
179   */
180  public void addPropertyChangeListener(String name,
181                                        PropertyChangeListener pcl) {
182    m_bcSupport.addPropertyChangeListener(name, pcl);
183  }
184
185  /**
186   * Remove a property change listener from this bean
187   *
188   * @param name the name of the property of interest
189   * @param pcl a <code>PropertyChangeListener</code> value
190   */
191  public void removePropertyChangeListener(String name,
192                                           PropertyChangeListener pcl) {
193    m_bcSupport.removePropertyChangeListener(name, pcl);
194  }
195
196  /**
197   * Add a vetoable change listener to this bean
198   *
199   * @param name the name of the property of interest
200   * @param vcl a <code>VetoableChangeListener</code> value
201   */
202  public void addVetoableChangeListener(String name,
203                                       VetoableChangeListener vcl) {
204    m_bcSupport.addVetoableChangeListener(name, vcl);
205  }
206 
207  /**
208   * Remove a vetoable change listener from this bean
209   *
210   * @param name the name of the property of interest
211   * @param vcl a <code>VetoableChangeListener</code> value
212   */
213  public void removeVetoableChangeListener(String name,
214                                           VetoableChangeListener vcl) {
215    m_bcSupport.removeVetoableChangeListener(name, vcl);
216  }
217}
218
219
220
221
222
223
224
Note: See TracBrowser for help on using the repository browser.