File: BaseEngineProperties.java

package info (click to toggle)
freetts 1.2.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 65,244 kB
  • sloc: java: 21,305; xml: 1,340; sh: 969; lisp: 587; ansic: 241; makefile: 25; awk: 11
file content (226 lines) | stat: -rw-r--r-- 8,116 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/**
 * Copyright 1998-2001 Sun Microsystems, Inc.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 */
package com.sun.speech.engine;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.EventObject;
import java.util.Iterator;

import javax.speech.EngineProperties;
import javax.speech.SpeechError;
import javax.speech.SpeechEvent;

/**
 * Supports the JSAPI 1.0 <code>EngineProperties</code>
 * interface.
 */
public abstract class BaseEngineProperties
    implements EngineProperties, SpeechEventDispatcher {
    
    /**
     * List of <code>PropertyChangeListeners</code> registered for
     * <code>PropertyChangeEvents</code> on this object.
     */
    protected Collection propertyChangeListeners;

    /**
     * Class constructor.
     */
    protected BaseEngineProperties() {
        propertyChangeListeners = new java.util.ArrayList();
    }

    /**
     * Obtains the AWT <code>Component</code> that provides the
     * default user interface 
     * for setting the properties of the <code>Engine</code>
     * associated with this object.
     *
     * @return an AWT <code>Component</code> to manipulate this object
     */
    public java.awt.Component getControlComponent() {
        return null;
    }

    /**
     * Returns all properties to reasonable defaults
     * for the <code>Engine</code>.  A
     * <code>PropertyChangeEvent</code> is issued
     * for each property that changes as the reset takes effect.
     */
    public abstract void reset();
    
    /**
     * Adds a <code>PropertyChangeListener</code> to the listener list.
     *
     * @param listener the <code>PropertyChangeListener</code> to add
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        if (!propertyChangeListeners.contains(listener)) {
            propertyChangeListeners.add(listener);
        }
    }

    /**
     * Removes a <code>PropertyChangeListener</code> from the listener
     * list.
     * 
     * @param listener the <code>PropertyChangeListener</code> to remove
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeListeners.remove(listener);
    }

    /**
     * Generates a
     * <code>PropertyChangeEvent</code> for an <code>Object</code> value
     * and posts it to the event queue.  Eventually
     * <code>firePropertyChangeEvent</code> will be called by
     * <code>dispatchSpeechEvent</code> as a result of this action.
     *
     * @param propName the name of the property
     * @param oldValue the old value
     * @param newValue the new value
     *
     * @see #firePropertyChangeEvent
     * @see #dispatchSpeechEvent
     */
    protected void postPropertyChangeEvent(String propName,
                                           Object oldValue,
                                           Object newValue) {
        EventObject e = new PropertyChangeEvent(this,
                                                propName,
                                                oldValue,
                                                newValue);
        SpeechEvent se = new SpeechEventWrapper(e);
        SpeechEventUtilities.postSpeechEvent(this, se);
    }

    /**
     * Generates a
     * <code>PropertyChangeEvent</code> for a <code>float</code> value
     * and posts it to the event queue.  Eventually
     * <code>firePropertyChangeEvent</code> will be called by
     * <code>dispatchSpeechEvent</code> as a result of this action.
     *
     * @param propName the name of the property
     * @param oldValue the old value
     * @param newValue the new value
     *
     * @see #firePropertyChangeEvent
     * @see #dispatchSpeechEvent
     */
    protected void postPropertyChangeEvent(String propName,
                                           float oldValue,
                                           float newValue) {
        EventObject e = new PropertyChangeEvent(this,
                                                propName, 
                                                new Float(oldValue), 
                                                new Float(newValue));
        SpeechEvent se = new SpeechEventWrapper(e);
        SpeechEventUtilities.postSpeechEvent(this, se);
    }

    /**
     * Generates a
     * <code>PropertyChangeEvent</code> for a <code>int</code> value
     * and posts it to the event queue.  Eventually
     * <code>firePropertyChangeEvent</code> will be called by
     * <code>dispatchSpeechEvent</code> as a result of this action.
     *
     * @param propName the name of the property
     * @param oldValue the old value
     * @param newValue the new value
     *
     * @see #firePropertyChangeEvent
     * @see #dispatchSpeechEvent
     */
    protected void postPropertyChangeEvent(String propName,
                                           int oldValue,
                                           int newValue) {
        EventObject e = new PropertyChangeEvent(this,
                                                propName, 
                                                new Integer(oldValue), 
                                                new Integer(newValue));
        SpeechEvent se = new SpeechEventWrapper(e);
        SpeechEventUtilities.postSpeechEvent(this, se);
    }

    /**
     * Generates a
     * <code>PropertyChangeEvent</code> for a <code>boolean</code> value
     * and posts it to the event queue.  Eventually
     * <code>firePropertyChangeEvent</code> will be called by
     * <code>dispatchSpeechEvent</code> as a result of this action.
     *
     * @param propName the name of the property
     * @param oldValue the old value
     * @param newValue the new value
     *
     * @see #firePropertyChangeEvent
     * @see #dispatchSpeechEvent
     */
    protected void postPropertyChangeEvent(String propName,
                                           boolean oldValue,
                                           boolean newValue) {
        EventObject e = new PropertyChangeEvent(this,
                                                propName, 
                                                new Boolean(oldValue), 
                                                new Boolean(newValue));
        SpeechEvent se = new SpeechEventWrapper(e);
        SpeechEventUtilities.postSpeechEvent(this, se);
    }
    
    /**
     * Sends a <code>PropertyChangeEvent</code>
     * to all <code>PropertyChangeListeners</code> registered with
     * this object.  Called by <code>dispatchSpeechEvent</code>.
     *
     * @param event the <code>PropertyChangeEvent</code> to send
     *
     * @see #firePropertyChangeEvent
     * @see #dispatchSpeechEvent
     */
    public void firePropertyChangeEvent(PropertyChangeEvent event) {
        if (propertyChangeListeners == null) {
            return;
        }
        Iterator iterator = propertyChangeListeners.iterator();
        while (iterator.hasNext()) {
            PropertyChangeListener pl =
                (PropertyChangeListener) iterator.next();
            pl.propertyChange(event);
        }
    }

    /**
     * Dispatches a <code>PropertyChangeEvent</code>.
     * The dispatcher should notify all <code>PropertyChangeListeners</code>
     * from this method.  The <code>SpeechEvent</code> was added
     * via the various post methods of this class.
     *
     * @param event the <code>SpeechEvent</code> containing a
     *   <code>PropertyChangeEvent</code>
     *
     * @see #postPropertyChangeEvent
     */
    public void dispatchSpeechEvent(SpeechEvent event) {
        if (event instanceof SpeechEventWrapper) {
            SpeechEventWrapper se = (SpeechEventWrapper)event;
            PropertyChangeEvent pe =
                (PropertyChangeEvent)(se.getEventObject());
            firePropertyChangeEvent(pe);
        }
        else {
            throw new SpeechError(
                "BaseEngineProperties: speech event type error");
        }
    }
}