⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.ui.swing;

import jmathlib.core.interfaces.MathLibOutput;
import javax.swing.*;
import javax.swing.text.*;


/**
 * Main input text area class.
 */
public class Console extends JTextArea implements MathLibOutput
{
    public static Console runningReference = null;

    public String prompt = "> ";

    public KeyHandler keyHandler = new KeyHandler(this);


    /**
     * 
     */
    public Console()
    {
        if (runningReference == null)
        {
            runningReference = this;
        }
        this.addKeyListener(keyHandler);
        this.setText(prompt);
        //this.setCaretPosition(2);

        this.addMouseListener(new ConsoleContextMenu());
    }


    /**
     * Display some text on a new line
     * @param text The response string.
     */
    public void displayText(String text)
    {
        this.append('\n' + text);
    }


    /**
     * Returns the current command line.
     *
     * The prompt is also included.
     * @return The last line.
     */
    public String getCurrentCommand()
    {
        String s = getText();
        int i = s.lastIndexOf(""+'\n') + prompt.length()+1;
        int j = s.length();
        s = s.substring(i, j);
        //this.setAutoscrolls(true);
        return s;
    }


    /**
     * Returns the word located down the cursor.
     * @return The string without delimiters.
     */
    public String getcurrentWord()
    {
        int i = this.getCaretPosition();
        String s = this.getText();
        int j = i;
        // Workaround. See DN0016.
        while (j < s.length() &&
               s.charAt(j) != ' ' && s.charAt(j) != '.' &&
               s.charAt(j) != '(' && s.charAt(j) != ')' &&
               s.charAt(j) != '[' && s.charAt(j) != ']' &&
               s.charAt(j) != '{' && s.charAt(j) != '}' &&
               s.charAt(j) != '+' && s.charAt(j) != '-' &&
               s.charAt(j) != '*' && s.charAt(j) != '/' &&
               s.charAt(j) != '\\' && s.charAt(j) != '"' &&
               s.charAt(j) != '=' && s.charAt(j) != ',' &&
               s.charAt(j) != '$' && s.charAt(j) != '%' &&
               s.charAt(j) != '\n' && s.charAt(j) != '\t')
        {
            j++;
        }
        do
        {
            i--;
        }
        while (i > 0 &&
               s.charAt(i) != ' ' && s.charAt(i) != '.' &&
               s.charAt(i) != '(' && s.charAt(i) != ')' &&
               s.charAt(i) != '[' && s.charAt(i) != ']' &&
               s.charAt(i) != '{' && s.charAt(i) != '}' &&
               s.charAt(i) != '+' && s.charAt(i) != '-' &&
               s.charAt(i) != '*' && s.charAt(i) != '/' &&
               s.charAt(i) != '\\' && s.charAt(i) != '"' &&
               s.charAt(i) != '=' && s.charAt(i) != ',' &&
               s.charAt(i) != '$' && s.charAt(i) != '%' &&
               s.charAt(i) != '\n' && s.charAt(i) != '\t');
        try
        {
            s = this.getText(i+1, j-i-1);
        }
        catch (BadLocationException ble)
        {
            s = "";
        }
        return s;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -