Package breadboards

Class GObject

  • All Implemented Interfaces:
    Drawable
    Direct Known Subclasses:
    GCompound, GImage, GLabel, GLine, GOval, GRect

    public abstract class GObject
    extends java.lang.Object
    implements Drawable
    Abstract class suitable for graphics objects that can be added to a Breadboard object
    Author:
    paul oser
    • Constructor Summary

      Constructors 
      Constructor Description
      GObject()
      (only called through constructor chaining)
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addMouseListener​(java.awt.event.MouseListener mouseListener)
      adds a specified MouseListener to this GObject
      void addMouseMotionListener​(java.awt.event.MouseMotionListener mouseMotionListener)
      adds a specified mouseMotionListener to this GObject
      abstract boolean contains​(double x, double y)
      required of subclasses to determine if the point (x,y) is contained in/on the GObject in question
      abstract GRectangle getBounds()
      required of subclasses to determine the bounding rectangle of the GObject in question
      Breadboard getBreadboard()
      returns the breadboard associated with this GObject -- or null if there is no such breadboard
      GPoint getLocation()
      returns the location of the GObject as a GPoint
      java.lang.Iterable<java.awt.event.MouseListener> getMouseListeners()
      gets an iterable collection of all MouseListeners associated with this GObject
      java.lang.Iterable<java.awt.event.MouseMotionListener> getMouseMotionListeners()
      gets an iterable collection of all MouseMotionListeners associated with this GObject
      GObjectParent getParent()
      returns the parent of the GObject - typically a GCompound or a Breadboard object
      double getX()
      returns the x-coordinate of the GObject
      double getY()
      returns the y-coordinate of the GObject
      boolean isVisible()
      returns whether or not this GObject is visible
      void move​(double dx, double dy)
      moves this GObject dx units horizontally and dy units vertically
      void movePolar​(double r, double theta)
      moves this GObject in a polar manner, r units from its current position in the theta direction
      void removeMouseListener​(java.awt.event.MouseListener mouseListener)
      removes a specified MouseListener from this GObject
      void removeMouseMotionListener​(java.awt.event.MouseMotionListener mouseMotionListener)
      removes a specified MouseMotionListener from this GObject
      void sendBackward()
      Swaps the z-orders of this GObject and the object immediately "below" it on this GObject's parent object
      void sendForward()
      Swaps the z-orders of this GObject and the object immediately "above" it on this GObject's parent object
      void sendToBack()
      Moves this GObject "below" all other GObjects on this GObject's parent object
      void sendToFront()
      Moves this GObject "on top" of all other GObjects on this GObject's parent object
      void setLocation​(double x, double y)
      sets the location of this GObject to (x,y)
      void setParent​(GObjectParent parent)
      sets the parent for this object to be the specified parent - note: it does not tell the parent of this child
      void setVisible​(boolean isVisible)
      sets whether this GObject is visible or not
      void setX​(double x)
      sets the x-coordinate for this GObject to the specified x-coordinate
      void setY​(double y)
      sets the y-coordinate for this GObject to the specified y-coordinate
      void updateBreadboard()
      updates display of containing breadboard (should be called when the GObject changes state)
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GObject

        public GObject()
        (only called through constructor chaining)
    • Method Detail

      • contains

        public abstract boolean contains​(double x,
                                         double y)
        required of subclasses to determine if the point (x,y) is contained in/on the GObject in question
        Parameters:
        x - x-coordinate of the point in question
        y - y-coordinate of the point in question
        Returns:
        true if the point is contained in the GObject, false otherwise
      • getBounds

        public abstract GRectangle getBounds()
        required of subclasses to determine the bounding rectangle of the GObject in question
        Returns:
        the bounding rectangle of the GObject
      • getX

        public double getX()
        returns the x-coordinate of the GObject
        Returns:
        the x-coordinate of the GObject
      • getY

        public double getY()
        returns the y-coordinate of the GObject
        Returns:
        the y-coordinate of the GObject
      • getLocation

        public GPoint getLocation()
        returns the location of the GObject as a GPoint
        Returns:
        the location of the GObject
      • getParent

        public GObjectParent getParent()
        returns the parent of the GObject - typically a GCompound or a Breadboard object
        Returns:
        the parent of the GObject
      • getBreadboard

        public Breadboard getBreadboard()
        returns the breadboard associated with this GObject -- or null if there is no such breadboard
        Returns:
        the breadboard associated with this GObject -- or null if there is no such breadboard
      • isVisible

        public boolean isVisible()
        returns whether or not this GObject is visible
        Returns:
        true if the GObject is visible, false otherwise
      • setParent

        public void setParent​(GObjectParent parent)
        sets the parent for this object to be the specified parent - note: it does not tell the parent of this child
        Parameters:
        parent - the specified parent
      • setX

        public void setX​(double x)
        sets the x-coordinate for this GObject to the specified x-coordinate
        Parameters:
        x - the specified x-coordinate
      • setY

        public void setY​(double y)
        sets the y-coordinate for this GObject to the specified y-coordinate
        Parameters:
        y - the specified y-coordinate
      • setLocation

        public void setLocation​(double x,
                                double y)
        sets the location of this GObject to (x,y)
        Parameters:
        x - the new x-coordinate for this GObject
        y - the new y-coordinate for this GObject
      • setVisible

        public void setVisible​(boolean isVisible)
        sets whether this GObject is visible or not
        Parameters:
        isVisible - true if the object is visible, false otherwise
      • sendForward

        public void sendForward()
        Swaps the z-orders of this GObject and the object immediately "above" it on this GObject's parent object
      • sendBackward

        public void sendBackward()
        Swaps the z-orders of this GObject and the object immediately "below" it on this GObject's parent object
      • sendToFront

        public void sendToFront()
        Moves this GObject "on top" of all other GObjects on this GObject's parent object
      • sendToBack

        public void sendToBack()
        Moves this GObject "below" all other GObjects on this GObject's parent object
      • addMouseListener

        public void addMouseListener​(java.awt.event.MouseListener mouseListener)
        adds a specified MouseListener to this GObject
        Parameters:
        mouseListener - the MouseListener specified
      • addMouseMotionListener

        public void addMouseMotionListener​(java.awt.event.MouseMotionListener mouseMotionListener)
        adds a specified mouseMotionListener to this GObject
        Parameters:
        mouseMotionListener - the MouseMotionListener specified
      • removeMouseListener

        public void removeMouseListener​(java.awt.event.MouseListener mouseListener)
        removes a specified MouseListener from this GObject
        Parameters:
        mouseListener - the specified MouseListener
      • removeMouseMotionListener

        public void removeMouseMotionListener​(java.awt.event.MouseMotionListener mouseMotionListener)
        removes a specified MouseMotionListener from this GObject
        Parameters:
        mouseMotionListener - the specified MouseMotionListener
      • getMouseListeners

        public java.lang.Iterable<java.awt.event.MouseListener> getMouseListeners()
        gets an iterable collection of all MouseListeners associated with this GObject
        Returns:
        an iterable collection of all MouseListeners associated with this GObject
      • getMouseMotionListeners

        public java.lang.Iterable<java.awt.event.MouseMotionListener> getMouseMotionListeners()
        gets an iterable collection of all MouseMotionListeners associated with this GObject
        Returns:
        an iterable collection of all MouseMotionListeners associated with this GObject
      • move

        public void move​(double dx,
                         double dy)
        moves this GObject dx units horizontally and dy units vertically
        Parameters:
        dx - how much to move this GObject horizontally (positive is to the right, negative to the left)
        dy - how much to move this GObject vertically (positive is down, negative is up)
      • movePolar

        public void movePolar​(double r,
                              double theta)
        moves this GObject in a polar manner, r units from its current position in the theta direction
        Parameters:
        r - how far to move from the current position
        theta - the direction in which this GObject is moved (expressed in radians)
      • updateBreadboard

        public void updateBreadboard()
        updates display of containing breadboard (should be called when the GObject changes state)