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.awt.BorderLayout;
11 import java.awt.Point;
13 import java.awt.event.ActionListener;
14 import java.awt.event.ActionEvent;
16 import javax.swing.BorderFactory;
17 import javax.swing.JPanel;
18 import javax.swing.JTextArea;
19 import javax.swing.JScrollPane;
20 import javax.swing.JButton;
23 * Simple GUI for monitoring events of an <code>Engine</code>. Used
24 * for debugging and testing purposes.
26 public class EngineEventPanel extends JPanel {
28 * The area where engine events are posted.
30 protected JTextArea textArea;
33 * The scroll pane containing the <code>textArea</code>.
37 protected JScrollPane scroller;
40 * The button for clearing the <code>textArea</code>.
44 protected JButton clearButton;
49 public EngineEventPanel() {
50 setLayout(new BorderLayout());
51 setBorder(BorderFactory.createTitledBorder("Events:"));
53 clearButton = new JButton("Clear");
54 clearButton.setMnemonic('C');
55 clearButton.addActionListener(new ActionListener() {
56 public void actionPerformed(ActionEvent evt) {
61 textArea = new JTextArea();
62 scroller = new JScrollPane(textArea);
64 add(scroller,BorderLayout.CENTER);
65 add(clearButton,BorderLayout.SOUTH);
69 * Clears the text in the text area.
71 public void clearText() {
76 * Sets the text in the text area.
78 * @param s the new text
80 public void setText(String s) {
85 * Appends text to the text area and scrolls the text area so the
86 * new text is visible.
88 * @param s the text to append
90 public void addText(String s) {
92 Point pt = new Point(0, textArea.getHeight() - 1);
93 scroller.getViewport().setViewPosition(pt);