Package bluej.extensions2.editor
Class JavaEditor
- java.lang.Object
-
- bluej.extensions2.editor.JavaEditor
-
public class JavaEditor extends java.lang.ObjectProxy object that allows interaction with the BlueJ Editor for a particular Java class.- Author:
- Damiano Bolla, University of Kent at Canterbury, 2004
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJavaEditor.LocationDetailsDetails of a text location.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BClassgetBClass()Gets the class that this editor is editing.TextLocationgetCaretLocation()Returns the current caret location (the position of the user's cursor) within the edited text.doublegetFontSizeInPixels()Gets the height of the editor font, in pixels.intgetLineCount()Returns the total number of lines in the currently edited text.intgetLineLength(int line)Returns the length of the line indicated in the edited text.JavaEditor.LocationDetailsgetLocationFromScreenPos(int screenX, int screenY)Gets the closest text location for the given position on the screen, or null if there is no code at that point on the screen.intgetOffsetFromTextLocation(TextLocation location)Translates a text location into an offset into the text held by this editor.java.lang.ObjectgetProperty(java.lang.String propertyKey)Returns a property of the current editor.javafx.geometry.Rectangle2DgetScreenBounds()Gets the screen bounds of the window that this editor is contained in, if and only if this is the selected tab in its editor window and the window is showing and the window is not minimised.TextLocationgetSelectionBegin()Returns the location at which current selection begins.TextLocationgetSelectionEnd()Returns the location at which the current selection ends.java.lang.StringgetText(TextLocation begin, TextLocation end)Returns the text which lies between the two TextLocations.intgetTextLength()Returns the length of the currently edited text.TextLocationgetTextLocationFromOffset(int offset)Translates an offset in the text held by this editor into a TextLocation.booleanisReadOnly()Returns the readonly status of this.booleanisVisible()Returns the visibility status of this editor.voidloadFile()Requests the editor to load the file currently opened.voidsaveFile()Requests the editor to save the file currently opened.voidsetCaretLocation(TextLocation location)Sets the current caret location within the edited text.voidsetProperty(java.lang.String propertyKey, java.lang.Object value)Sets a property for the current editor.voidsetReadOnly(boolean readOnly)Requests the editor to permit or deny editor content modification (via the editor GUI).voidsetSelection(TextLocation begin, TextLocation end)Requests the editor to mark the text between begin and end as selected.voidsetText(TextLocation begin, TextLocation end, java.lang.String newText)Requests 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.voidsetVisible(boolean visible)Shows or hides this editor.voidshowMessage(java.lang.String message)Requests the editor to display the given message in the editor message area.
-
-
-
Method Detail
-
getBClass
public BClass getBClass()
Gets the class that this editor is editing. Does not change over the course of the object's lifetime, and will not be null.- Returns:
- The class that this Java editor is editing.
- Since:
- Extension API 3.2 (BlueJ 5.0.2)
-
saveFile
public void saveFile()
Requests the editor to save the file currently opened.
-
loadFile
public void loadFile()
Requests the editor to load the file currently opened.
-
setVisible
public void setVisible(boolean visible)
Shows or hides this editor.- Parameters:
visible- a boolean value indicating whether to show (true) the editor or hide it (false).
-
isVisible
public boolean isVisible()
Returns the visibility status of this editor.- Returns:
- A boolean value indicating whether this editor is visible (
true) or not (false).
-
getCaretLocation
public TextLocation getCaretLocation()
Returns the current caret location (the position of the user's cursor) within the edited text.- Returns:
- A
TextLocationobject representing the current caret location of this editor.
-
setCaretLocation
public void setCaretLocation(TextLocation location)
Sets the current caret location within the edited text.- Parameters:
location- aTextLocationobject representing 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)
Requests 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:
- A
TextLocationobject representing the current beginning location of the selection in this editor,nullif no text is selected.
-
getSelectionEnd
public TextLocation getSelectionEnd()
Returns the location at which the current selection ends.- Returns:
- A
TextLocationobject representing the current end location of the selection in this editor,nullif 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- aTextLocationobject representing the beginning location of the text to get.end- aTextLocationobject representing the end location 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)
Requests 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- aTextLocationobject representing the beginning location of the text to replace.end- aTextLocationobject representing the end location of the text to replace.newText- aStringobject containing the new text.- 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)
Requests the editor to mark the text between begin and end as selected.- Parameters:
begin- aTextLocationobject representing the beginning location of the selection to make.end- aTextLocationobject representing the end location of the selection to make.- 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)
Requests the editor to permit or deny editor content modification (via the editor GUI). Extensions should set it totruetrue before changing the editor content programmatically.- Parameters:
readOnly- a boolean indicating whether the user cannot change the editor content using the GUI (true), (false) otherwise.
-
isReadOnly
public boolean isReadOnly()
Returns the readonly status of this.- Returns:
- A boolean indicating whether the user cannot change the editor content using the GUI (
true), (false) otherwise.
-
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 property key of the property to retrieve.- Returns:
- An
Objectobject representing the property value ornullif it is not found.
-
setProperty
public void setProperty(java.lang.String propertyKey, java.lang.Object value)Sets a property for the current editor. Any existing property with this key will be overwritten.- Parameters:
propertyKey- the property key of the property to set.value- AnObjectobject to assign to the new property value.
-
getOffsetFromTextLocation
public int getOffsetFromTextLocation(TextLocation location)
Translates a text location into an offset into the text held by this editor.- Parameters:
location- aTextLocationobject representing the location where to apply the translation on.- Returns:
- an integer representing 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)
Translates an offset in the text held by this editor into a TextLocation.- Parameters:
offset- an integer representing the offset to translate.- Returns:
- A
TextLocationobject representing the text of this offset,nullif the offset is invalid
-
getLineLength
public int getLineLength(int line)
Returns the length of the line indicated in the edited text.- Parameters:
line- an integer representing the line number in the text for which the length should be calculated, starting from zero.- Returns:
- An integer representing the length of the line,
-1if line is invalid.
-
getLineCount
public int getLineCount()
Returns the total number of lines in the currently edited text.- Returns:
- An integer representing the number of lines in the text.
-
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 theTextEditor.getLineColumnFromOffset(int)method withgetTextLength()as argument.- Returns:
- An integer representing the length of the text.
-
getScreenBounds
public javafx.geometry.Rectangle2D getScreenBounds()
Gets the screen bounds of the window that this editor is contained in, if and only if this is the selected tab in its editor window and the window is showing and the window is not minimised. Returns null otherwise.- Since:
- Extension API 3.2 (BlueJ 5.0.2)
-
getLocationFromScreenPos
public JavaEditor.LocationDetails getLocationFromScreenPos(int screenX, int screenY)
Gets the closest text location for the given position on the screen, or null if there is no code at that point on the screen.- Parameters:
screenX- The X coordinate in pixels, relative to the screenscreenY- The Y coordinate in pixels, relative to the screen- Returns:
- The closest text location, if appropriate, or null if there is no code near this point.
- Since:
- Extension API 3.2 (BlueJ 5.0.2)
-
getFontSizeInPixels
public double getFontSizeInPixels()
Gets the height of the editor font, in pixels. This will currently be the same size across all Java editors because it is a shared preference. The actual font size is specified in points, so the pixel height may be a fractional value.- Returns:
- The font size, in pixels.
- Since:
- Extension API 3.2 (BlueJ 5.0.2)
-
-