Class ClassEvent

  • All Implemented Interfaces:
    ExtensionEvent

    public class ClassEvent
    extends java.lang.Object
    implements ExtensionEvent
    This class encapsulates events which occur on BlueJ classes.

    The following events can occur:
    STATE_CHANGED - the compile state changed (either from uncompiled to compiled, or from compiled to uncompiled)
    CHANGED_NAME - the class has changed name.
    REMOVED - the class has been removed.

    In the case of STATE_CHANGED there are three possible sitations:
    • isClassCompiled() returns true: the class has been compiled successfully. Editing the class will switch to one of the next two states.
    • isClassCompiled() returns false and hasError() returns true: the class has been compiled and was found to have an error. If the user edits the class, it will either switch directly to the first state (if they fix it and the compile occurs quickly) or the next state (if we are awaiting the compile).
    • isClassCompiled() returns false, and hasError() returns false: the class has been edited and is awaiting the next compile. When the next compile occurs, the state will be changed to one of the above two states.
    Author:
    Davin McCall
    • Constructor Detail

      • ClassEvent

        public ClassEvent​(bluej.pkgmgr.Package bluejPackage,
                          BClass bClass,
                          boolean isCompiled,
                          boolean hasError)
        Constructs a new ClassEvent object for a ClassEvent.EventType.STATE_CHANGED event.
        Parameters:
        bluejPackage - a Package object that contains the compiled class.
        bClass - a BClass object wrapping the compiled class.
        isCompiled - boolean indicating whether the class is compiled (true) or not.
        hasError - boolean indicating whether the last compilation gave an error and the class not has been edited since (true).
      • ClassEvent

        public ClassEvent​(bluej.pkgmgr.Package bluejPackage,
                          BClass bClass,
                          java.lang.String oldName)
        Constructs a new ClassEvent object for a ClassEvent.EventType.CHANGED_NAME event.
        Parameters:
        bluejPackage - a Package object that contains the renamed class.
        bClass - a BClass object wrapping the class which was renamed (refers to the new name).
      • ClassEvent

        public ClassEvent​(bluej.pkgmgr.Package bluejPackage,
                          BClass bClass)
        Constructs a new ClassEvent object for a ClassEvent.EventType.REMOVED event.
        Parameters:
        bluejPackage - a Package object that contained the removed class.
        bClass - a BClass object wrapping the class which was removed.
    • Method Detail

      • isClassCompiled

        public boolean isClassCompiled()
        Checks whether the class for which the event occurred is compiled. Valid for ClassEvent.EventType.STATE_CHANGED event.
        Returns:
        True if the class is compiled, false otherwise.
      • hasError

        public boolean hasError()
        Checks whether the class for which the event occurred has compilation errors. Valid for ClassEvent.EventType.STATE_CHANGED event if isClassCompiled() returns false.
        Returns:
        True if the class has compilation errors, false otherwise.
      • getPackage

        public BPackage getPackage()
        Returns the package to which the class that caused this event belongs.
        Returns:
        A BPackage object wrapping the package to which the class that caused this event belongs.
      • getBClass

        public BClass getBClass()
        Gets the class on which the event occurred.
        Returns:
        A BClass object wrapping the class on which this event occurred.