Package bluej.extensions.editor

Provides proxy objects through which extensions can communicate with the BlueJ editor used for creating and modifying classes.

See:
          Description

Class Summary
Editor Proxy object that allows interaction with the BlueJ Editor for a particular class.
TextLocation A TextLocation object groups two pieces of information: a line number and a column number.
 

Package bluej.extensions.editor Description

Provides proxy objects through which extensions can communicate with the BlueJ editor used for creating and modifying classes.

A proxy for a particular class's editor can be obtained from the getEditor() method of BClass.

This proxy can be used to retrieve the text currently associated with the class, to determine the user's current cursor position and text selection, and to modify the text being edited. A simple example of how to use these facilities is given below.

Extension authors who need more sophisticated interaction between their own, modified, version of the BlueJ editor and their extension can use the set/getProperty() mechanism in the Editor class.

Note that there is no way to determine whether the BlueJ user has an existing open editor for a class. Partly this is because there is no way (in general) to tell whether an editor is being actively used: it may be iconised, or obscured by other windows on the users screen, or otherwise not the focus of their attention. It is also because BlueJ does not guarantee to release the resources of editors which have been closed by the user: an editor may be present for a particular class, even if there is no window representing it.

A Simple example

import bluej.extensions.*;
import bluej.extensions.editor.*;

// A method to add a comment at the end of the current class, using the Editor API
private void addComment(BClass curClass) {
    Editor classEditor = null;
    try {
        classEditor = curClass.getEditor();
    } catch (Exception e) { }
    if(classEditor == null) {
        System.out.println("Can't create Editor for " + curClass);
        return;
    }
    
    classEditor.setReadOnly(true);  // Stop the user changing the text
    int textLen = classEditor.getTextLength();
    TextLocation lastLine = classEditor.getTextLocationFromOffset(textLen);
    lastLine.setColumn(0);
    // The TextLocation now points before the first character of the last line of the current text
    // which we'll assume contains the closing } bracket for the class
    classEditor.setText(lastLine, lastLine, "// Comment added by SimpleExtension\n");
    classEditor.setReadOnly(false);
}



BlueJ homepage