update standards version
[debian/freetts] / demo / JSAPI / Player / Monitor.java
1 /**
2  * Copyright 2001 Sun Microsystems, Inc.
3  * 
4  * See the file "license.terms" for information on usage and
5  * redistribution of this file, and for a DISCLAIMER OF ALL 
6  * WARRANTIES.
7  */
8 import java.awt.Component;
9 import java.awt.Container;
10 import java.awt.BorderLayout;
11 import java.awt.Dimension;
12 import java.awt.GridBagLayout;
13 import java.awt.GridBagConstraints;
14 import java.awt.Insets;
15
16 import java.awt.event.WindowAdapter;
17 import java.awt.event.WindowEvent;
18
19 import javax.speech.synthesis.Synthesizer;
20
21 import javax.swing.JFrame;
22 import javax.swing.JPanel;
23 import javax.swing.LookAndFeel;
24 import javax.swing.SwingUtilities;
25 import javax.swing.UIManager;
26
27 import javax.swing.border.TitledBorder;
28
29 import com.sun.speech.engine.synthesis.SynthesizerMonitor;
30 import com.sun.speech.engine.EngineEventPanel;
31
32 /**
33  * Implements the GUI for a SynthesizerMonitor.
34  */
35 public class Monitor extends JPanel {
36     
37     private SynthesizerMonitor monitor;
38     private Synthesizer synthesizer;
39     private int width = 600;
40     private int height = 300;
41
42
43     /**
44      * Constructs a Monitor for the given synthesizer
45      *
46      * @param synthesizer the synthesizer it monitors
47      * @param synthesizerName name of the synthesizer
48      */
49     public Monitor(Synthesizer synthesizer, String synthesizerName) {
50         TitledBorder titledBorder = new TitledBorder(synthesizerName);
51         setBorder(titledBorder);
52         setPreferredSize(new Dimension(width, height));
53         setSize(width, height);
54         this.synthesizer = synthesizer;
55         this.monitor = new SynthesizerMonitor(synthesizer);
56         createMonitorPanel();
57     }
58
59
60     /**
61      * Populates this Monitor JPanel.
62      */
63     private void createMonitorPanel() {
64         GridBagLayout gridbag = new GridBagLayout();
65         setLayout(gridbag);
66
67         GridBagConstraints c = new GridBagConstraints();
68         c.anchor = GridBagConstraints.WEST;
69         c.insets = new Insets(4,4,4,4);
70         c.gridx = 0;
71         c.gridy = 0;        
72         c.weightx = 1.0;
73         c.fill = GridBagConstraints.BOTH;
74
75         Component sp = monitor.getStatePanel();
76         gridbag.setConstraints(sp, c);
77         add(sp);
78
79         EngineEventPanel eventPanel = 
80             (EngineEventPanel) monitor.getEventPanel();
81
82         c.gridy = 1;
83         c.weighty = 1.0;
84         gridbag.setConstraints(eventPanel, c);
85         add(eventPanel);
86         validate();
87     }
88 }