KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > gui > TypeScript


1 /*
2  * @(#)TypeScript.java 1.9 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.gui;
36
37 import java.awt.*;
38 import java.awt.event.*;
39 import javax.swing.*;
40 import javax.swing.border.*;
41
42 public class TypeScript extends JPanel {
43
44     private JTextArea history;
45     private JTextField entry;
46     
47     private JLabel promptLabel;
48
49     private JScrollBar historyVScrollBar;
50     private JScrollBar historyHScrollBar;
51
52     private boolean echoInput = false;
53     private boolean nlPending = false;
54
55     private static String JavaDoc newline = System.getProperty("line.separator");
56
57     public TypeScript(String JavaDoc prompt) {
58     this(prompt, true);
59     }
60     
61     public TypeScript(String JavaDoc prompt, boolean echoInput) {
62     this.echoInput = echoInput;
63
64     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
65     //setBorder(new EmptyBorder(5, 5, 5, 5));
66

67     history = new JTextArea(0, 0);
68     history.setEditable(false);
69     JScrollPane scroller = new JScrollPane(history);
70     historyVScrollBar = scroller.getVerticalScrollBar();
71     historyHScrollBar = scroller.getHorizontalScrollBar();
72
73     add(scroller);
74
75     JPanel cmdLine = new JPanel();
76     cmdLine.setLayout(new BoxLayout(cmdLine, BoxLayout.X_AXIS));
77     //cmdLine.setBorder(new EmptyBorder(5, 5, 0, 0));
78

79     promptLabel = new JLabel(prompt + " ");
80     cmdLine.add(promptLabel);
81     entry = new JTextField();
82 //### Swing bug workaround.
83
entry.setMaximumSize(new Dimension(1000, 20));
84     cmdLine.add(entry);
85     add(cmdLine);
86     }
87
88     /******
89     public void setFont(Font f) {
90     entry.setFont(f);
91     history.setFont(f);
92     }
93     ******/

94
95     public void setPrompt(String JavaDoc prompt) {
96     promptLabel.setText(prompt + " ");
97     }
98
99     public void append(String JavaDoc text) {
100     history.append(text);
101     historyVScrollBar.setValue(historyVScrollBar.getMaximum());
102     historyHScrollBar.setValue(historyHScrollBar.getMinimum());
103     }
104
105     public void newline() {
106     history.append(newline);
107     historyVScrollBar.setValue(historyVScrollBar.getMaximum());
108     historyHScrollBar.setValue(historyHScrollBar.getMinimum());
109     }
110
111     public void flush() {}
112
113     public void addActionListener(ActionListener a) {
114     entry.addActionListener(a);
115     }
116
117     public void removeActionListener(ActionListener a) {
118     entry.removeActionListener(a);
119     }
120
121     public String JavaDoc readln() {
122     String JavaDoc text = entry.getText();
123     entry.setText("");
124     if (echoInput) {
125         history.append(">>>");
126         history.append(text);
127         history.append(newline);
128         historyVScrollBar.setValue(historyVScrollBar.getMaximum());
129         historyHScrollBar.setValue(historyHScrollBar.getMinimum());
130     }
131     return text;
132     }
133 }
134
Popular Tags