bluej.extensions.editor
Class Editor

java.lang.Object
  extended by bluej.extensions.editor.Editor

public class Editor
extends java.lang.Object

Proxy object that allows interaction with the BlueJ Editor for a particular class. Except as marked, methods of this class must be called from a swing compatible thread.

Version:
$Id: Editor.java 7337 2010-04-14 14:52:24Z nccb $
Author:
Damiano Bolla, University of Kent at Canterbury, 2004

Method Summary
 TextLocation getCaretLocation()
          Returns the current caret location (the position of the user's cursor) within the edited text.
 int getLineCount()
          Returns the total number of lines in the currently edited text.
 int getLineLength(int line)
          Returns the length of the line indicated in the edited text.
 int getOffsetFromTextLocation(TextLocation location)
          Translates a text location into an offset into the text held by the editor.
 java.lang.Object getProperty(java.lang.String propertyKey)
          Returns a property of the current editor.
 TextLocation getSelectionBegin()
          Returns the location at which current selection begins.
 TextLocation getSelectionEnd()
          Returns the location at which the current selection ends.
 java.lang.String getText(TextLocation begin, TextLocation end)
          Returns the text which lies between the two TextLocations.
 int getTextLength()
          Returns the length of the currently edited text.
 TextLocation getTextLocationFromOffset(int offset)
          Translate an offset in the text held by the editor into a TextLocation.
 boolean isReadOnly()
          Is the editor currently set to readOnly?.
 boolean isVisible()
          Is this Editor currently visible?
 void loadFile()
          Request the editor to load the file currently opened.
 void saveFile()
          Request the editor to save the file currently opened.
 void setCaretLocation(TextLocation location)
          Sets the current caret location within the edited text.
 void setProperty(java.lang.String propertyKey, java.lang.Object value)
          Set a property for the current editor.
 void setReadOnly(boolean readOnly)
          Request the editor to permit or deny editor content modification (via the editor GUI).
 void setSelection(TextLocation begin, TextLocation end)
          Request the editor to mark the text between begin and end as selected.
 void setText(TextLocation begin, TextLocation end, java.lang.String newText)
          Request the editor to replace the text between beginning and end with the given newText If begin and end refer to the same location, the text is inserted.
 void setVisible(boolean visible)
          Show or hide this Editor.
 void showMessage(java.lang.String message)
          Request the editor to display the given message in the editor message area.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

saveFile

public void saveFile()
Request the editor to save the file currently opened.


loadFile

public void loadFile()
Request the editor to load the file currently opened.


setVisible

public void setVisible(boolean visible)
Show or hide this Editor.

Parameters:
visible - If true, make this editor visible

isVisible

public boolean isVisible()
Is this Editor currently visible?

Returns:
true if the Editor is visible, false otherwise.

getCaretLocation

public TextLocation getCaretLocation()
Returns the current caret location (the position of the user's cursor) within the edited text.

Returns:
the textLocation.

setCaretLocation

public void setCaretLocation(TextLocation location)
Sets the current caret location within the edited text.

Parameters:
location - The location in the text to set the Caret to.
Throws:
java.lang.IllegalArgumentException - if the specified TextLocation represents a position which does not exist in the text.

showMessage

public void showMessage(java.lang.String message)
Request the editor to display the given message in the editor message area. The message will be cleared using BlueJ's usual rules.

Parameters:
message - The message to display.

getSelectionBegin

public TextLocation getSelectionBegin()
Returns the location at which current selection begins.

Returns:
the current beginning of the selection or null if no text is selected.

getSelectionEnd

public TextLocation getSelectionEnd()
Returns the location at which the current selection ends.

Returns:
the current end of the selection or null if no text is selected

getText

public java.lang.String getText(TextLocation begin,
                                TextLocation end)
Returns the text which lies between the two TextLocations.

Parameters:
begin - The beginning of the text to get
end - The end of the text to get
Returns:
The text value
Throws:
java.lang.IllegalArgumentException - if either of the specified TextLocations represent a position which does not exist in the text.

setText

public void setText(TextLocation begin,
                    TextLocation end,
                    java.lang.String newText)
Request the editor to replace the text between beginning and end with the given newText If begin and end refer to the same location, the text is inserted.

Parameters:
begin - where to start to replace
end - where to end to replace
newText - The new text value
Throws:
java.lang.IllegalArgumentException - if either of the specified TextLocations represent a position which does not exist in the text.

setSelection

public void setSelection(TextLocation begin,
                         TextLocation end)
Request the editor to mark the text between begin and end as selected.

Parameters:
begin - where to start the selection
end - where to end the selection
Throws:
java.lang.IllegalArgumentException - if either of the specified TextLocations represent a position which does not exist in the text.

setReadOnly

public void setReadOnly(boolean readOnly)
Request the editor to permit or deny editor content modification (via the editor GUI). Extensions should set readOnly to true before changing the editor content programmatically.

Parameters:
readOnly - If true user cannot change the editor content using the GUI, false allows user interaction.

isReadOnly

public boolean isReadOnly()
Is the editor currently set to readOnly?.

Returns:
true if the user cannot change the text using the GUI, false othervise

getProperty

public java.lang.Object getProperty(java.lang.String propertyKey)
Returns a property of the current editor. This allows custom versions of the editor to communicate with extensions.

Parameters:
propertyKey - The propertyKey of the property to retrieve.
Returns:
the property value or null if it is not found

setProperty

public void setProperty(java.lang.String propertyKey,
                        java.lang.Object value)
Set a property for the current editor. Any existing property with this key will be overwritten.

Parameters:
propertyKey - The property key of the new property
value - The new property value

getOffsetFromTextLocation

public int getOffsetFromTextLocation(TextLocation location)
Translates a text location into an offset into the text held by the editor.

Parameters:
location - position to be translated
Returns:
the offset into the text of this location
Throws:
java.lang.IllegalArgumentException - if the specified TextLocation represent a position which does not exist in the text.

getTextLocationFromOffset

public TextLocation getTextLocationFromOffset(int offset)
Translate an offset in the text held by the editor into a TextLocation.

Parameters:
offset - location to be translated
Returns:
the TextLocation in the text of this offset or null if the offset is invalid

getLineLength

public int getLineLength(int line)
Returns the length of the line indicated in the edited text.

Parameters:
line - the line in the text for which the length should be calculated, starting from zero.
Returns:
the length of the line, -1 if line is invalid

getLineCount

public int getLineCount()
Returns the total number of lines in the currently edited text.

Returns:
The number of lines in the text >= 0

getTextLength

public int getTextLength()
Returns the length of the currently edited text. This is the number of characters of content that represents the user's data. The line number and column of the last character of text can be obtained by using the getLineColumnFromOffset(getTextLength()) method.

Returns:
the length >= 0


BlueJ homepage