A Swing-based interactive console for evaluating Groovy expressions and scripts with syntax highlighting, code completion, and an integrated AST browser.
—
The Groovy Console provides advanced text editing capabilities with Groovy-specific syntax highlighting, auto-completion, smart indentation, and comprehensive editing features.
class ConsoleTextEditor extends JScrollPane {
// Constructor
ConsoleTextEditor()
// Core Editor Access
TextEditor getTextEditor()
// Display Configuration
void setShowLineNumbers(boolean showLineNumbers)
void setEditable(boolean editable)
// Clipboard Operations
boolean clipBoardAvailable()
// Actions
Action getUndoAction()
Action getRedoAction()
Action getPrintAction()
// Syntax Highlighting
void enableHighLighter(Class clazz)
}setShowLineNumbers():
showLineNumbers (boolean): Whether to display line numbers in the editorsetEditable():
editable (boolean): Whether the editor content can be modifiedenableHighLighter():
clazz (Class): Highlighter class to enable for syntax highlightingclass TextEditor extends JTextPane implements Pageable, Printable {
// Constructor
TextEditor()
// Implements Pageable and Printable for printing support
}The TextEditor class provides the core text editing functionality and printing capabilities.
class GroovyFilter extends StructuredSyntaxDocumentFilter {
// Groovy-specific syntax filtering and highlighting
}
class StructuredSyntaxDocumentFilter extends DocumentFilter {
// Base class for syntax highlighting document filters
}
class SmartDocumentFilter extends DocumentFilter {
// Smart editing features like auto-indentation and bracket matching
}class TextUndoManager extends UndoManager {
// Enhanced undo manager for text operations
}class MatchingHighlighter implements CaretListener {
// Highlights matching brackets, braces, and parentheses
}class FindReplaceUtility {
// Find and replace functionality for the text editor
}class AutoIndentAction extends AbstractAction {
// Automatic indentation for Groovy code
}def textEditor = new groovy.console.ui.ConsoleTextEditor()
textEditor.setShowLineNumbers(true)
textEditor.setEditable(true)
// Enable Groovy syntax highlighting
textEditor.enableHighLighter(groovy.console.ui.text.GroovyFilter.class)def consoleEditor = new groovy.console.ui.ConsoleTextEditor()
def baseEditor = consoleEditor.getTextEditor()
// Configure the base editor
baseEditor.setFont(new Font("Consolas", Font.PLAIN, 14))def textEditor = new groovy.console.ui.ConsoleTextEditor()
// Get editor actions for toolbar/menu integration
def undoAction = textEditor.getUndoAction()
def redoAction = textEditor.getRedoAction()
def printAction = textEditor.getPrintAction()
// Add actions to a toolbar
toolbar.add(undoAction)
toolbar.add(redoAction)
toolbar.add(printAction)def textEditor = new groovy.console.ui.ConsoleTextEditor()
// Check clipboard availability before operations
if (textEditor.clipBoardAvailable()) {
// Perform clipboard operations
textEditor.getTextEditor().copy()
textEditor.getTextEditor().paste()
}The text editor supports multiple levels of syntax highlighting:
// Enable Groovy syntax highlighting
textEditor.enableHighLighter(groovy.console.ui.text.GroovyFilter.class)The SmartDocumentFilter provides:
class StructuredSyntaxHandler extends DefaultHandler {
// XML/structured content syntax handling
}
class StructuredSyntaxDocumentFilter extends DocumentFilter {
// Base structured syntax filtering
}The same text editing functionality is available in the legacy groovy.ui.text package:
// Legacy imports (same API as groovy.console.ui.text)
import groovy.ui.text.TextEditor
import groovy.ui.text.GroovyFilter
import groovy.ui.text.SmartDocumentFilter
// ... etcThe text editor integrates seamlessly with the main Console:
Install with Tessl CLI
npx tessl i tessl/maven-org-codehaus-groovy--groovy-console