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 voidadd(GObject gObject)adds a GObject to this GCompoundvoidadd(GObject gObject, double x, double y)adds a GObject to this GCompound at the specified locationvoidadd(GObject gObject, GPoint pt)adds a GObject to this GCompound at the specified pointbooleancontains(double x, double y)returns true if the point (x,y) is contained in one of the elements of the GCompoundvoiddraw(java.awt.Graphics g)draws the GCompound (generally not called directly)GRectanglegetBounds()returns the bounding box for the union of all elements in this GCompoundGPointgetCanvasPoint(double x, double y)converts local coordinates associated with the GCompound to coordinates associated with the parent objectGObjectgetElement(int i)returns the ith element by z-order in this GCompoundGObjectgetElementAt(double x, double y)returns the top-most element of the GCompound at the specified location (x,y)GObjectgetElementAt(GPoint pt)returns the top-most element of the GCompound at the specified pointintgetElementCount()returns the number of elements that make up the GCompounddoublegetHeight()returns height of GCompoundGPointgetLocalPoint(double x, double y)converts coordinates associated with the parent object to local coordinates associated with the GCompounddoublegetWidth()voidremove(GObject gObject)removes the specified GObject from the GCompoundvoidremoveAll()removes all GObjects from this GCompoundvoidsendBackward(GObject gObj)Swaps the z-orders of the specified GObject and the object immediately "below" it.voidsendForward(GObject gObj)Swaps the z-orders of the specified GObject and the object immediately "above" it.voidsendToBack(GObject gObj)Moves the specified object "below" all other GObjects on the breadboardvoidsendToFront(GObject gObj)Moves the specified object "on top" of all other GObjects on the breadboardvoidupdateDisplay()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:
sendForwardin 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:
sendBackwardin 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:
sendToFrontin 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:
sendToBackin 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:
updateDisplayin interfaceGObjectParent
-
getHeight
public double getHeight()
returns height of GCompound- Returns:
- the height of GCompound
-
getWidth
public double getWidth()
-
-