Showing the changes to java/pkg/com/sun/tools/example/debug/gui/TypeScript.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,123 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.tools.example.debug.gui; | |
| 27 | + | |
| 28 | +import java.awt.*; | |
| 29 | +import java.awt.event.*; | |
| 30 | +import javax.swing.*; | |
| 31 | + | |
| 32 | +public class TypeScript extends JPanel { | |
| 33 | + | |
| 34 | + private static final long serialVersionUID = -983704841363534885L; | |
| 35 | + private JTextArea history; | |
| 36 | + private JTextField entry; | |
| 37 | + | |
| 38 | + private JLabel promptLabel; | |
| 39 | + | |
| 40 | + private JScrollBar historyVScrollBar; | |
| 41 | + private JScrollBar historyHScrollBar; | |
| 42 | + | |
| 43 | + private boolean echoInput = false; | |
| 44 | + | |
| 45 | + private static String newline = System.getProperty("line.separator"); | |
| 46 | + | |
| 47 | + public TypeScript(String prompt) { | |
| 48 | + this(prompt, true); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public TypeScript(String prompt, boolean echoInput) { | |
| 52 | + this.echoInput = echoInput; | |
| 53 | + | |
| 54 | + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); | |
| 55 | + //setBorder(new EmptyBorder(5, 5, 5, 5)); | |
| 56 | + | |
| 57 | + history = new JTextArea(0, 0); | |
| 58 | + history.setEditable(false); | |
| 59 | + JScrollPane scroller = new JScrollPane(history); | |
| 60 | + historyVScrollBar = scroller.getVerticalScrollBar(); | |
| 61 | + historyHScrollBar = scroller.getHorizontalScrollBar(); | |
| 62 | + | |
| 63 | + add(scroller); | |
| 64 | + | |
| 65 | + JPanel cmdLine = new JPanel(); | |
| 66 | + cmdLine.setLayout(new BoxLayout(cmdLine, BoxLayout.X_AXIS)); | |
| 67 | + //cmdLine.setBorder(new EmptyBorder(5, 5, 0, 0)); | |
| 68 | + | |
| 69 | + promptLabel = new JLabel(prompt + " "); | |
| 70 | + cmdLine.add(promptLabel); | |
| 71 | + entry = new JTextField(); | |
| 72 | +//### Swing bug workaround. | |
| 73 | +entry.setMaximumSize(new Dimension(1000, 20)); | |
| 74 | + cmdLine.add(entry); | |
| 75 | + add(cmdLine); | |
| 76 | + } | |
| 77 | + | |
| 78 | + /****** | |
| 79 | + public void setFont(Font f) { | |
| 80 | + entry.setFont(f); | |
| 81 | + history.setFont(f); | |
| 82 | + } | |
| 83 | + ******/ | |
| 84 | + | |
| 85 | + public void setPrompt(String prompt) { | |
| 86 | + promptLabel.setText(prompt + " "); | |
| 87 | + } | |
| 88 | + | |
| 89 | + public void append(String text) { | |
| 90 | + history.append(text); | |
| 91 | + historyVScrollBar.setValue(historyVScrollBar.getMaximum()); | |
| 92 | + historyHScrollBar.setValue(historyHScrollBar.getMinimum()); | |
| 93 | + } | |
| 94 | + | |
| 95 | + public void newline() { | |
| 96 | + history.append(newline); | |
| 97 | + historyVScrollBar.setValue(historyVScrollBar.getMaximum()); | |
| 98 | + historyHScrollBar.setValue(historyHScrollBar.getMinimum()); | |
| 99 | + } | |
| 100 | + | |
| 101 | + public void flush() {} | |
| 102 | + | |
| 103 | + public void addActionListener(ActionListener a) { | |
| 104 | + entry.addActionListener(a); | |
| 105 | + } | |
| 106 | + | |
| 107 | + public void removeActionListener(ActionListener a) { | |
| 108 | + entry.removeActionListener(a); | |
| 109 | + } | |
| 110 | + | |
| 111 | + public String readln() { | |
| 112 | + String text = entry.getText(); | |
| 113 | + entry.setText(""); | |
| 114 | + if (echoInput) { | |
| 115 | + history.append(">>>"); | |
| 116 | + history.append(text); | |
| 117 | + history.append(newline); | |
| 118 | + historyVScrollBar.setValue(historyVScrollBar.getMaximum()); | |
| 119 | + historyHScrollBar.setValue(historyHScrollBar.getMinimum()); | |
| 120 | + } | |
| 121 | + return text; | |
| 122 | + } | |
| 123 | +} | |