Class JavaEditor


  • public class JavaEditor
    extends java.lang.Object
    Proxy 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 class  JavaEditor.LocationDetails
      Details of a text location.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      BClass getBClass()
      Gets the class that this editor is editing.
      TextLocation getCaretLocation()
      Returns the current caret location (the position of the user's cursor) within the edited text.
      double getFontSizeInPixels()
      Gets the height of the editor font, in pixels.
      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.
      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.
      int getOffsetFromTextLocation​(TextLocation location)
      Translates a text location into an offset into the text held by this editor.
      java.lang.Object getProperty​(java.lang.String propertyKey)
      Returns a property of the current editor.
      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.
      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)
      Translates an offset in the text held by this editor into a TextLocation.
      boolean isReadOnly()
      Returns the readonly status of this.
      boolean isVisible()
      Returns the visibility status of this editor.
      void loadFile()
      Requests the editor to load the file currently opened.
      void saveFile()
      Requests 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)
      Sets a property for the current editor.
      void setReadOnly​(boolean readOnly)
      Requests the editor to permit or deny editor content modification (via the editor GUI).
      void setSelection​(TextLocation begin, TextLocation end)
      Requests the editor to mark the text between begin and end as selected.
      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.
      void setVisible​(boolean visible)
      Shows or hides this editor.
      void showMessage​(java.lang.String message)
      Requests 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

      • 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 TextLocation object 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 - a TextLocation object 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 TextLocation object representing the current beginning location of the selection in this editor, null if no text is selected.
      • getSelectionEnd

        public TextLocation getSelectionEnd()
        Returns the location at which the current selection ends.
        Returns:
        A TextLocation object representing the current end location of the selection in this editor, 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 - a TextLocation object representing the beginning location of the text to get.
        end - a TextLocation object 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 - a TextLocation object representing the beginning location of the text to replace.
        end - a TextLocation object representing the end location of the text to replace.
        newText - a String object 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 - a TextLocation object representing the beginning location of the selection to make.
        end - a TextLocation object 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 to truetrue 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 Object object representing the property value or null if 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 - An Object object 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 - a TextLocation object 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 TextLocation object representing the text of this offset, 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 - 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, -1 if 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 the TextEditor.getLineColumnFromOffset(int) method with getTextLength() 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 screen
        screenY - 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)