2 * Copyright 1998-2001 Sun Microsystems, Inc.
4 * See the file "license.terms" for information on usage and
5 * redistribution of this file, and for a DISCLAIMER OF ALL
8 package com.sun.speech.engine;
10 import java.beans.PropertyChangeEvent;
11 import java.beans.PropertyChangeListener;
12 import java.util.Collection;
13 import java.util.EventObject;
14 import java.util.Iterator;
16 import javax.speech.EngineProperties;
17 import javax.speech.SpeechError;
18 import javax.speech.SpeechEvent;
21 * Supports the JSAPI 1.0 <code>EngineProperties</code>
24 public abstract class BaseEngineProperties
25 implements EngineProperties, SpeechEventDispatcher {
28 * List of <code>PropertyChangeListeners</code> registered for
29 * <code>PropertyChangeEvents</code> on this object.
31 protected Collection propertyChangeListeners;
36 protected BaseEngineProperties() {
37 propertyChangeListeners = new java.util.ArrayList();
41 * Obtains the AWT <code>Component</code> that provides the
42 * default user interface
43 * for setting the properties of the <code>Engine</code>
44 * associated with this object.
46 * @return an AWT <code>Component</code> to manipulate this object
48 public java.awt.Component getControlComponent() {
53 * Returns all properties to reasonable defaults
54 * for the <code>Engine</code>. A
55 * <code>PropertyChangeEvent</code> is issued
56 * for each property that changes as the reset takes effect.
58 public abstract void reset();
61 * Adds a <code>PropertyChangeListener</code> to the listener list.
63 * @param listener the <code>PropertyChangeListener</code> to add
65 public void addPropertyChangeListener(PropertyChangeListener listener) {
66 if (!propertyChangeListeners.contains(listener)) {
67 propertyChangeListeners.add(listener);
72 * Removes a <code>PropertyChangeListener</code> from the listener
75 * @param listener the <code>PropertyChangeListener</code> to remove
77 public void removePropertyChangeListener(PropertyChangeListener listener) {
78 propertyChangeListeners.remove(listener);
83 * <code>PropertyChangeEvent</code> for an <code>Object</code> value
84 * and posts it to the event queue. Eventually
85 * <code>firePropertyChangeEvent</code> will be called by
86 * <code>dispatchSpeechEvent</code> as a result of this action.
88 * @param propName the name of the property
89 * @param oldValue the old value
90 * @param newValue the new value
92 * @see #firePropertyChangeEvent
93 * @see #dispatchSpeechEvent
95 protected void postPropertyChangeEvent(String propName,
98 EventObject e = new PropertyChangeEvent(this,
102 SpeechEvent se = new SpeechEventWrapper(e);
103 SpeechEventUtilities.postSpeechEvent(this, se);
108 * <code>PropertyChangeEvent</code> for a <code>float</code> value
109 * and posts it to the event queue. Eventually
110 * <code>firePropertyChangeEvent</code> will be called by
111 * <code>dispatchSpeechEvent</code> as a result of this action.
113 * @param propName the name of the property
114 * @param oldValue the old value
115 * @param newValue the new value
117 * @see #firePropertyChangeEvent
118 * @see #dispatchSpeechEvent
120 protected void postPropertyChangeEvent(String propName,
123 EventObject e = new PropertyChangeEvent(this,
126 new Float(newValue));
127 SpeechEvent se = new SpeechEventWrapper(e);
128 SpeechEventUtilities.postSpeechEvent(this, se);
133 * <code>PropertyChangeEvent</code> for a <code>int</code> value
134 * and posts it to the event queue. Eventually
135 * <code>firePropertyChangeEvent</code> will be called by
136 * <code>dispatchSpeechEvent</code> as a result of this action.
138 * @param propName the name of the property
139 * @param oldValue the old value
140 * @param newValue the new value
142 * @see #firePropertyChangeEvent
143 * @see #dispatchSpeechEvent
145 protected void postPropertyChangeEvent(String propName,
148 EventObject e = new PropertyChangeEvent(this,
150 new Integer(oldValue),
151 new Integer(newValue));
152 SpeechEvent se = new SpeechEventWrapper(e);
153 SpeechEventUtilities.postSpeechEvent(this, se);
158 * <code>PropertyChangeEvent</code> for a <code>boolean</code> value
159 * and posts it to the event queue. Eventually
160 * <code>firePropertyChangeEvent</code> will be called by
161 * <code>dispatchSpeechEvent</code> as a result of this action.
163 * @param propName the name of the property
164 * @param oldValue the old value
165 * @param newValue the new value
167 * @see #firePropertyChangeEvent
168 * @see #dispatchSpeechEvent
170 protected void postPropertyChangeEvent(String propName,
173 EventObject e = new PropertyChangeEvent(this,
175 new Boolean(oldValue),
176 new Boolean(newValue));
177 SpeechEvent se = new SpeechEventWrapper(e);
178 SpeechEventUtilities.postSpeechEvent(this, se);
182 * Sends a <code>PropertyChangeEvent</code>
183 * to all <code>PropertyChangeListeners</code> registered with
184 * this object. Called by <code>dispatchSpeechEvent</code>.
186 * @param event the <code>PropertyChangeEvent</code> to send
188 * @see #firePropertyChangeEvent
189 * @see #dispatchSpeechEvent
191 public void firePropertyChangeEvent(PropertyChangeEvent event) {
192 if (propertyChangeListeners == null) {
195 Iterator iterator = propertyChangeListeners.iterator();
196 while (iterator.hasNext()) {
197 PropertyChangeListener pl =
198 (PropertyChangeListener) iterator.next();
199 pl.propertyChange(event);
204 * Dispatches a <code>PropertyChangeEvent</code>.
205 * The dispatcher should notify all <code>PropertyChangeListeners</code>
206 * from this method. The <code>SpeechEvent</code> was added
207 * via the various post methods of this class.
209 * @param event the <code>SpeechEvent</code> containing a
210 * <code>PropertyChangeEvent</code>
212 * @see #postPropertyChangeEvent
214 public void dispatchSpeechEvent(SpeechEvent event) {
215 if (event instanceof SpeechEventWrapper) {
216 SpeechEventWrapper se = (SpeechEventWrapper)event;
217 PropertyChangeEvent pe =
218 (PropertyChangeEvent)(se.getEventObject());
219 firePropertyChangeEvent(pe);
222 throw new SpeechError(
223 "BaseEngineProperties: speech event type error");