CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-codehaus-groovy--groovy-console

A Swing-based interactive console for evaluating Groovy expressions and scripts with syntax highlighting, code completion, and an integrated AST browser.

Pending
Overview
Eval results
Files

text-editing.mddocs/

Text Editing

The Groovy Console provides advanced text editing capabilities with Groovy-specific syntax highlighting, auto-completion, smart indentation, and comprehensive editing features.

Main Text Editor

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)
}

Parameters

setShowLineNumbers():

  • showLineNumbers (boolean): Whether to display line numbers in the editor

setEditable():

  • editable (boolean): Whether the editor content can be modified

enableHighLighter():

  • clazz (Class): Highlighter class to enable for syntax highlighting

Returns

  • getTextEditor(): TextEditor - The underlying text editor component
  • clipBoardAvailable(): boolean - True if clipboard operations are available
  • getUndoAction(): Action - Swing Action for undo operation
  • getRedoAction(): Action - Swing Action for redo operation
  • getPrintAction(): Action - Swing Action for print operation

Base Text Editor

class 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.

Syntax Highlighting and Filtering

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
}

Text Editor Features

Undo/Redo Management

class TextUndoManager extends UndoManager {
    // Enhanced undo manager for text operations
}

Bracket Matching

class MatchingHighlighter implements CaretListener {
    // Highlights matching brackets, braces, and parentheses
}

Find and Replace

class FindReplaceUtility {
    // Find and replace functionality for the text editor
}

Auto-Indentation

class AutoIndentAction extends AbstractAction {
    // Automatic indentation for Groovy code
}

Usage Examples

Basic Text Editor Setup

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)

Accessing Underlying Editor

def consoleEditor = new groovy.console.ui.ConsoleTextEditor()
def baseEditor = consoleEditor.getTextEditor()

// Configure the base editor
baseEditor.setFont(new Font("Consolas", Font.PLAIN, 14))

Action Integration

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)

Clipboard Operations

def textEditor = new groovy.console.ui.ConsoleTextEditor()

// Check clipboard availability before operations
if (textEditor.clipBoardAvailable()) {
    // Perform clipboard operations
    textEditor.getTextEditor().copy()
    textEditor.getTextEditor().paste()
}

Syntax Highlighting Configuration

The text editor supports multiple levels of syntax highlighting:

Groovy-Specific Highlighting

// Enable Groovy syntax highlighting
textEditor.enableHighLighter(groovy.console.ui.text.GroovyFilter.class)

Smart Document Features

The SmartDocumentFilter provides:

  • Automatic bracket completion
  • Smart indentation based on Groovy syntax
  • Context-aware code formatting
  • Real-time syntax validation

Structured Syntax Handling

class StructuredSyntaxHandler extends DefaultHandler {
    // XML/structured content syntax handling
}

class StructuredSyntaxDocumentFilter extends DocumentFilter {
    // Base structured syntax filtering
}

Legacy API

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
// ... etc

Integration with Console

The text editor integrates seamlessly with the main Console:

  • Automatic syntax highlighting for Groovy code
  • Real-time error highlighting during compilation
  • Context-sensitive auto-completion
  • Integration with AST browser for code analysis
  • Find/replace across console history

Install with Tessl CLI

npx tessl i tessl/maven-org-codehaus-groovy--groovy-console

docs

ast-browser.md

console-application.md

index.md

object-inspector.md

system-integration.md

text-editing.md

tile.json