File: EngineEventPanel.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 (95 lines) | stat: -rw-r--r-- 2,281 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
/**
 * 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.awt.BorderLayout;
import java.awt.Point;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JButton;

/**
 * Simple GUI for monitoring events of an <code>Engine</code>.  Used
 * for debugging and testing purposes.
 */
public class EngineEventPanel extends JPanel {
    /**
     * The area where engine events are posted.
     */
    protected JTextArea textArea;

    /**
     * The scroll pane containing the <code>textArea</code>.
     *
     * @see #textArea
     */
    protected JScrollPane scroller;

    /**
     * The button for clearing the <code>textArea</code>.
     *
     * @see #textArea
     */
    protected JButton clearButton;

    /**
     * Class constructor.
     */
    public EngineEventPanel() {
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createTitledBorder("Events:"));
        
	clearButton = new JButton("Clear");
	clearButton.setMnemonic('C');
	clearButton.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent evt) {
                clearText();
	    }
	});
        
        textArea = new JTextArea();
        scroller = new JScrollPane(textArea);
        
        add(scroller,BorderLayout.CENTER);
        add(clearButton,BorderLayout.SOUTH);
    }

    /**
     * Clears the text in the text area.
     */
    public void clearText() {
        textArea.setText("");
    }

    /**
     * Sets the text in the text area.
     *
     * @param s the new text
     */
    public void setText(String s) {
        textArea.setText(s);
    }

    /**
     * Appends text to the text area and scrolls the text area so the
     * new text is visible.
     *
     * @param s the text to append
     */
    public void addText(String s) {
        textArea.append(s);
        Point pt = new Point(0, textArea.getHeight() - 1);
        scroller.getViewport().setViewPosition(pt);        
    }
}