Package breadboards
Class GCompound
- java.lang.Object
-
- breadboards.GObject
-
- breadboards.GCompound
-
- All Implemented Interfaces:
Drawable
,GObjectParent
- Direct Known Subclasses:
GSpaceship
,GTurtle
public class GCompound extends GObject implements GObjectParent
Subclass of GObject suitable for displaying a collection of other GObjects, treated as a single entity- Author:
- paul oser
-
-
Constructor Summary
Constructors Constructor Description GCompound()
constructs a new (empty) GCompound
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(GObject gObject)
adds a GObject to this GCompoundvoid
add(GObject gObject, double x, double y)
adds a GObject to this GCompound at the specified locationvoid
add(GObject gObject, GPoint pt)
adds a GObject to this GCompound at the specified pointboolean
contains(double x, double y)
returns true if the point (x,y) is contained in one of the elements of the GCompoundvoid
draw(java.awt.Graphics g)
draws the GCompound (generally not called directly)GRectangle
getBounds()
returns the bounding box for the union of all elements in this GCompoundGPoint
getCanvasPoint(double x, double y)
converts local coordinates associated with the GCompound to coordinates associated with the parent objectGObject
getElement(int i)
returns the ith element by z-order in this GCompoundGObject
getElementAt(double x, double y)
returns the top-most element of the GCompound at the specified location (x,y)GObject
getElementAt(GPoint pt)
returns the top-most element of the GCompound at the specified pointint
getElementCount()
returns the number of elements that make up the GCompounddouble
getHeight()
returns height of GCompoundGPoint
getLocalPoint(double x, double y)
converts coordinates associated with the parent object to local coordinates associated with the GCompounddouble
getWidth()
void
remove(GObject gObject)
removes the specified GObject from the GCompoundvoid
removeAll()
removes all GObjects from this GCompoundvoid
sendBackward(GObject gObj)
Swaps the z-orders of the specified GObject and the object immediately "below" it.void
sendForward(GObject gObj)
Swaps the z-orders of the specified GObject and the object immediately "above" it.void
sendToBack(GObject gObj)
Moves the specified object "below" all other GObjects on the breadboardvoid
sendToFront(GObject gObj)
Moves the specified object "on top" of all other GObjects on the breadboardvoid
updateDisplay()
updates the display of this GCompound and all of its parents on the breadboard drawing area-
Methods inherited from class breadboards.GObject
addMouseListener, addMouseMotionListener, getBreadboard, getLocation, getMouseListeners, getMouseMotionListeners, getParent, getX, getY, isVisible, move, movePolar, removeMouseListener, removeMouseMotionListener, sendBackward, sendForward, sendToBack, sendToFront, setLocation, setParent, setVisible, setX, setY, updateBreadboard
-
-
-
-
Method Detail
-
getElement
public GObject getElement(int i)
returns the ith element by z-order in this GCompound- Parameters:
i
- the z-order index- Returns:
- the ith element by z-order in this GCompound
-
getElementCount
public int getElementCount()
returns the number of elements that make up the GCompound- Returns:
- the number of elements that make up the GCompound
-
getElementAt
public GObject getElementAt(double x, double y)
returns the top-most element of the GCompound at the specified location (x,y)- Parameters:
x
- the x-coordinate of the specified locationy
- the y-coordinate of the specified location- Returns:
- the top-most element of the GCompound at the specified location (x,y)
-
getElementAt
public GObject getElementAt(GPoint pt)
returns the top-most element of the GCompound at the specified point- Parameters:
pt
- the specified point- Returns:
- the top-most element of the GCompound at the specified point
-
getCanvasPoint
public GPoint getCanvasPoint(double x, double y)
converts local coordinates associated with the GCompound to coordinates associated with the parent object- Parameters:
x
- the local x-coordinatey
- the local y-coordinate- Returns:
- coordinates in GCompound's parent object
-
getLocalPoint
public GPoint getLocalPoint(double x, double y)
converts coordinates associated with the parent object to local coordinates associated with the GCompound- Parameters:
x
- the x-coordinate associated with the parent objecty
- the y-coordinate associated with the parent object- Returns:
- the local coordinates
-
add
public void add(GObject gObject)
adds a GObject to this GCompound- Parameters:
gObject
- the GObject to be added
-
add
public void add(GObject gObject, double x, double y)
adds a GObject to this GCompound at the specified location- Parameters:
gObject
- the GObject to be addedx
- the x-coordinate of the specified locationy
- the y-coordiante of the specified location
-
add
public void add(GObject gObject, GPoint pt)
adds a GObject to this GCompound at the specified point- Parameters:
gObject
- the GObject to be addedpt
- the specified point
-
remove
public void remove(GObject gObject)
removes the specified GObject from the GCompound- Parameters:
gObject
- the specified GObject to be removed
-
removeAll
public void removeAll()
removes all GObjects from this GCompound
-
draw
public void draw(java.awt.Graphics g)
draws the GCompound (generally not called directly)
-
contains
public boolean contains(double x, double y)
returns true if the point (x,y) is contained in one of the elements of the GCompound
-
getBounds
public GRectangle getBounds()
returns the bounding box for the union of all elements in this GCompound
-
sendForward
public void sendForward(GObject gObj)
Swaps the z-orders of the specified GObject and the object immediately "above" it.- Specified by:
sendForward
in interfaceGObjectParent
- Parameters:
gObj
- the specified GObject
-
sendBackward
public void sendBackward(GObject gObj)
Swaps the z-orders of the specified GObject and the object immediately "below" it.- Specified by:
sendBackward
in interfaceGObjectParent
- Parameters:
gObj
- the specified GObject
-
sendToFront
public void sendToFront(GObject gObj)
Moves the specified object "on top" of all other GObjects on the breadboard- Specified by:
sendToFront
in interfaceGObjectParent
- Parameters:
gObj
- the specified GObject
-
sendToBack
public void sendToBack(GObject gObj)
Moves the specified object "below" all other GObjects on the breadboard- Specified by:
sendToBack
in interfaceGObjectParent
- Parameters:
gObj
- the specified GObject
-
updateDisplay
public void updateDisplay()
updates the display of this GCompound and all of its parents on the breadboard drawing area- Specified by:
updateDisplay
in interfaceGObjectParent
-
getHeight
public double getHeight()
returns height of GCompound- Returns:
- the height of GCompound
-
getWidth
public double getWidth()
-
-