The Groovy Swing Console allows a user to enter and run Groovy scripts. This page documents the features of this user interface.
The Groovy Console:
- The Console has an input area and an output area.
- You type a Groovy script in the input area.
- When you select "Run" from the "Actions" menu, the console compiles the script and runs it.
- Anything that would normally be printed on System.out is printed in the output area.
- If the script returns a non-null result, that result is printed.
Handy tips for running scripts:
- Ctrl+Enter and Ctrl+R are both shortcut keys for "Run Script".
- If you highight just part of the text in the input area, then Groovy runs just that text.
- The result of a script is the the value of the last expression executed.
- You can turn the System.out capture on and off by selecting "Capture System.out" from the "Actions" menu
You can open any text file, edit it, run it (as a Groovy Script) and then save it again when you are finished.
- Select File -> Open (shortcut key ctrl+O) to open a file
- Select File -> Save (shortcut key ctrl+S) to save a file
- Select File -> New File (shortcut key ctrl+Q) to start again with a blank
History and results
- You can pop-up a gui inspector on the last (non-null) result by selecting "Inspect Last" from the "Actions" menu. The inspector is a convenient way to view lists and maps.
- The console remembers the last ten script runs. You can scroll back and forth through the history by selecting "Next" and "Previous" from the "Edit" menu. Ctrl-N and ctrl-P are convenient shortcut keys.
- The last (non-null) result is bound to a variable named '
_' (an underscore).
- The last result (null and non-null) for every run in the history is bound into a list variable named '
__' (two underscores). The result of the last run is
__[-1], the result of the second to last run is
__[-2]and so forth.
- You can attempt to interrupt a long running task by clicking the "interrupt" button on the small dialog box that pops up when a script is executing.
- You can change the font size by selecting "Smaller Font" or "Larger Font" from the "Actions menu"
Embedding the Console
To embed a Swing console in your application, simply create the Console object,
load some variables, and then launch it. The console can be embedded in either Java or Groovy code.
The Java code for this is:
Once the console is launched, you can use the variable values in Groovy code.