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.synthesis;
10 import java.awt.Component;
11 import java.util.Enumeration;
12 import java.util.List;
14 import javax.speech.Central;
15 import javax.speech.EngineList;
16 import javax.speech.synthesis.SynthesizerModeDesc;
17 import javax.swing.JOptionPane;
20 * GUI that displays a list of <code>Synthesizer</code> names in a
21 * dialog box. When the user makes a selection, the selected
22 * <code>SynthesizerModeDesc</code> is returned to the caller.
24 public class SynthesizerSelector {
26 * Asks <code>Central</code> for a list of available synthesizers.
27 * If there are none, returns <code>null</code>. If there is only
28 * one, returns it. Otherwise, pops up an input dialog that gives
31 * @param component the component for JOptionPane.showInputDialog
32 * @param appName the title for the input dialog
34 * @return a <code>SynthesizerModeDesc</code> representing the
37 static public SynthesizerModeDesc getSynthesizerModeDesc(
40 List synths = new java.util.ArrayList();
41 List synthNames = new java.util.ArrayList();
42 EngineList list = Central.availableSynthesizers(null);
43 Enumeration e = list.elements();
44 while (e.hasMoreElements()) {
45 synths.add(((SynthesizerModeDesc) e.nextElement()));
47 ((SynthesizerModeDesc)
48 synths.get(synths.size() - 1)).getEngineName());
50 Object[] synthNamesArray = synthNames.toArray();
52 if (synths.size() == 0) {
54 } else if (synths.size() == 1) {
55 return (SynthesizerModeDesc) synths.get(0);
58 String synthName = (String)JOptionPane.showInputDialog(
60 "Select the Synthesizer to use:",
61 appName + ": Select Synthesizer",
62 JOptionPane.QUESTION_MESSAGE,
67 int index = synthNames.indexOf(synthName);
71 return (SynthesizerModeDesc) synths.get(index);