TU Berlin

jterm

JTerm is a swing component that roughly has the look and feel of a Unix shell window: You can type text to some prompt and after hitting Return the text is evaluated. You are shown the result and you are presented with the next prompt. There is no mouse cursor but a caret at the text insertion point. The cursor keys can be used to move the caret (left and right) or to navigate in the command history (up and down).

In accordance with the way swing proposes to handle text, JTerm is implemented by defining a subclass Session of Document. A single JTerm window could handle multiple sessions (just call setDocument).

The main application is interaction with Java interpreters: to provide a shell window where you can interact with Java objects. The "interpreter" can however be anything that implements a very simple interface called StringEvaluator. This contains only one method evaluate that given a string returns a result string together with a boolean telling whether the result string is a regular result or in fact an error message (has influence on the color of the result string).

Getting started

To see what JTerm does, try

java de.jtem.jterm.Test

This is a terminal for a dummy interpreter that "evaluates" command strings by converting them to lower case.

For a really useful example put bsh-*.jar from the lib directory ( or download from the BeanShell web page www.beanshell.org) into your class path. Then you can try

java de.jtem.jterm.BshTerm

More information on the BeanShell syntax may be found at www.beanshell.org.

Usage

The Enter key will trigger evaluation of the current command (the text portion after the last prompt). You can insert line breaks using Shift-Enter.

Text is always inserted at the caret position. You can move the caret within the part after the last prompt using the left and right arrow keys.

The up and down arrow keys allow navigation in the command history.

The Tab key asks for suggestions for completing the current command. Only the BshTerm example supports this feature.

You can use dragging with the left mouse button for selecting portions of the text, which will copy the selection to your window systems clipboard.

Pressing the middle mouse button anywhere in the window will paste the window system's clipboard to the caret position (independent of the mouse position).

Zusatzinformationen / Extras

Links

Downloads

(release 2014-05-27_rev1801 )