📄 consolewindow.java
字号:
// ConsoleWindow.java// Copyright (c) 1998, Regents of the University of California// $Id: ConsoleWindow.java,v 1.2 1999/06/27 00:17:37 marcel Exp $import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.lang.*;import java.io.*;/* * window with console output */public class ConsoleWindow extends JInternalFrame{int numRows; // # of recorded rowsJDesktopPane desktop;JTextArea consoleText; // output text areaFont cmdFont, infoFont;int[] rowLengths; // circular array, containing current row lengthsint topRow; // index of first row of JTextArea// create console window with capacity for specified # of rowspublic ConsoleWindow(int rows, JDesktopPane desktop){ super("Console", true, false, true, true); numRows = rows; this.desktop = desktop; rowLengths = new int[rows]; topRow = 0; getContentPane().setLayout(new BorderLayout()); //setTitle("Console"); setBounds(20, 20, 300, 200); JPanel areaPanel = new JPanel(new BorderLayout()); areaPanel.setAlignmentX(LEFT_ALIGNMENT); getContentPane().add(areaPanel, BorderLayout.CENTER); consoleText = new JTextArea(""); JScrollPane scroller = new JScrollPane() { // do I really need these redefined? public Dimension getPreferredSize() { return new Dimension(10,10); } public float getAlignmentX() { return LEFT_ALIGNMENT; } }; scroller.getViewport().add(consoleText); consoleText.setFont(new Font("Dialog", Font.PLAIN, 10)); areaPanel.add(scroller, BorderLayout.CENTER); // create fonts //cmdFont = new Font("Dialog", Font.BOLD, 10); //infoFont = new Font("Dialog", Font.PLAIN, 10);}public voidsetTree(String name){ setTitle("Console: " + name);}// fill lower part of desktoppublic voidtile(){ Rectangle bounds = desktop.getBounds(); bounds.x = 0; bounds.y = bounds.height - 190; bounds.height = 150; setBounds(bounds);}private voidreplaceRow(String newRow){ if (rowLengths[topRow] != 0) { // remove that row from the display consoleText.replaceRange("", 0, rowLengths[topRow]); } rowLengths[topRow] = newRow.length(); topRow = (topRow + 1) % numRows;}///////////////////////////////////////////////////////////////////////////////// echoCmd - echo one command line (including \n) at bottom of console window//// Description://// Exceptions://// Return Values:///////////////////////////////////////////////////////////////////////////////public voidechoCmd(String line){ String out = ">" + line + "\n"; replaceRow(out); consoleText.setCaretPosition(consoleText.getText().length()); consoleText.append(out);}///////////////////////////////////////////////////////////////////////////////// echoInfo - echo one message line (including \n) at bottom of console window//// Description://// Exceptions://// Return Values:///////////////////////////////////////////////////////////////////////////////public voidechoInfo(String line){ String out = line + "\n"; replaceRow(out); consoleText.setCaretPosition(consoleText.getText().length()); consoleText.append(out);}///////////////////////////////////////////////////////////////////////////////// echoTuple - echo one returned tuple (including \n) at bottom of window//// Description://// Exceptions://// Return Values:///////////////////////////////////////////////////////////////////////////////public voidechoTuple(String line){ String out = "-> " + line + "\n"; replaceRow(out); consoleText.setCaretPosition(consoleText.getText().length()); consoleText.append(out);}// change the # of recorded rows;// if the number is decreased, delete the excess number of rows from the top of// the JTextArea;// if the number is increased, insert them at the bottompublic voidsetRows(int rows){ if (rows < numRows) { // throw away excess rows for (int i = 0; i < numRows - rows; i++) { replaceRow(""); } } int[] tmpLengths = rowLengths; int[] rowLengths = new int[rows]; // copy row lengths over int min = (rows < numRows ? rows : numRows); for (int i = 0; i < min; i++) { rowLengths[i] = tmpLengths[topRow + i]; } numRows = rows; topRow = 0;}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -