public class GCompound extends GObject implements GContainer, GScalable, Iterable<GObject>
BACK_TO_FRONT, FRONT_TO_BACK
Constructor and Description |
---|
GCompound()
Creates a new
GCompound object with no internal components. |
Modifier and Type | Method and Description |
---|---|
void |
add(GObject gobj)
Adds a new graphical object to this
GCompound . |
void |
add(GObject gobj,
double x,
double y)
Adds the graphical object to this canvas and sets its location
to the point (
x , y ). |
void |
add(GObject gobj,
GPoint pt)
Adds the graphical object to this canvas and sets its location to the specified point.
|
protected boolean |
areMouseListenersEnabled()
Returns
true if mouse listeners have ever been assigned to
this object or to any of the contained objects. |
boolean |
contains(double x,
double y)
Checks to see whether a point is "inside" the compound, which means that it is
inside one of the components.
|
protected void |
fireMouseListeners(MouseEvent e)
Dispatches a mouse event to the topmost child that covers the location
in the event
e . |
GRectangle |
getBounds()
Returns the bounding rectangle for this compound object, which consists of
the union of the bounding rectangles for each of the components.
|
GPoint |
getCanvasPoint(double x,
double y)
Converts the location of the specified point in this compound to
the corresponding point in the enclosing canvas.
|
GPoint |
getCanvasPoint(GPoint localPoint)
Converts the location of the specified point in this compound to
the corresponding point in the enclosing canvas.
|
<T extends GObject> |
getElement(int index)
Returns the graphical object at the specified index, numbering from back
to front in the the z dimension.
|
<T extends GObject> |
getElementAt(double x,
double y)
Returns the topmost graphical object that contains the point
(
x , y ), or null if no such
object exists. |
<T extends GObject> |
getElementAt(GPoint pt)
Returns the topmost graphical object that contains the specified point,
or
null if no such object exists. |
int |
getElementCount()
Returns the number of graphical objects stored in this container.
|
GPoint |
getLocalPoint(double x,
double y)
Converts the specified point on the enclosing canvas to the
corresponding point in the space of this compound.
|
GPoint |
getLocalPoint(GPoint canvasPoint)
Converts the location of the specified point on the enclosing canvas
to the corresponding point in the space of this compound.
|
Iterator<GObject> |
iterator()
Returns an
Iterator that cycles through the elements within
this container in the default direction, which is from back to front. |
Iterator<GObject> |
iterator(int direction)
Returns an
Iterator that cycles through the elements
within this container in the specified direction, which must be one
of the constants GContainer.FRONT_TO_BACK
or GContainer.BACK_TO_FRONT . |
void |
markAsComplete()
Calling this method makes it illegal to add or remove elements from the
compound object.
|
protected void |
paint2d(Graphics2D g)
Implements the
paint2d operation for this graphical object. |
void |
remove(GObject gobj)
Removes a graphical object from this
GCompound . |
void |
removeAll()
Removes all graphical objects from this
GCompound . |
void |
scale(double sx,
double sy)
Scales every object contained in this compound by the scale factors
sx and sy . |
protected void |
sendBackward(GObject gobj)
Implements the
sendBackward function from the GContainer
interface. |
protected void |
sendForward(GObject gobj)
Implements the
sendForward function from the GContainer
interface. |
protected void |
sendToBack(GObject gobj)
Implements the
sendToBack function from the GContainer
interface. |
protected void |
sendToFront(GObject gobj)
Implements the
sendToFront function from the GContainer
interface. |
addActionListener, addMouseListener, addMouseMotionListener, clone, colorName, colorName, colorNameFriendly, contains, createTransformedGraphics, fireActionEvent, fireActionEvent, getBottomY, getCenterLocation, getCenterX, getCenterY, getColor, getComponent, getHeight, getLineWidth, getLocation, getMatrix, getObjectColor, getParent, getRightX, getSize, getWidth, getX, getY, intersects, isAntiAliasing, isVisible, move, movePolar, paint, paramString, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, rotate, scale, sendBackward, sendForward, sendToBack, sendToFront, setAntiAliasing, setBottomY, setCenterLocation, setCenterLocation, setCenterX, setCenterY, setColor, setLineWidth, setLocation, setLocation, setParent, setRightX, setVisible, setX, setY, start, start, toString, updateEnabledList
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public GCompound()
GCompound
object with no internal components.public void add(GObject gobj)
GCompound
.add
in interface GContainer
gobj
- The graphical object to addpublic final void add(GObject gobj, double x, double y)
x
, y
).add
in interface GContainer
gobj
- The graphical object to addx
- The new x-coordinate for the objecty
- The new y-coordinate for the objectpublic final void add(GObject gobj, GPoint pt)
add
in interface GContainer
gobj
- The graphical object to addpt
- A GPoint
object giving the coordinates of the pointprotected boolean areMouseListenersEnabled()
true
if mouse listeners have ever been assigned to
this object or to any of the contained objects.areMouseListenersEnabled
in class GObject
true
if mouse listeners have been enabled in this objectpublic boolean contains(double x, double y)
protected void fireMouseListeners(MouseEvent e)
e
.fireMouseListeners
in class GObject
e
- The MouseEvent
that triggered this responsepublic GRectangle getBounds()
public final GPoint getCanvasPoint(GPoint localPoint)
localPoint
- The coordinates in the space of the compoundGCanvas
public GPoint getCanvasPoint(double x, double y)
x
- The x coordinate in the space of the compoundy
- The y coordinate in the space of the compoundGCanvas
public <T extends GObject> T getElement(int index)
getElement
in interface GContainer
index
- The index of the component to returnpublic <T extends GObject> T getElementAt(double x, double y)
x
, y
), or null
if no such
object exists. Note that these coordinates are relative to the
location of the compound object and not to the canvas in which
it is displayed.getElementAt
in interface GContainer
x
- The x-coordinate of the point being testedy
- The y-coordinate of the point being testednull
if no such object existspublic final <T extends GObject> T getElementAt(GPoint pt)
null
if no such object exists.getElementAt
in interface GContainer
pt
- The coordinates being testednull
if no such object existspublic int getElementCount()
getElementCount
in interface GContainer
public GPoint getLocalPoint(double x, double y)
x
- The x coordinate in the space of the space of the enclosing GCanvas
y
- The y coordinate in the space of the space of the enclosing GCanvas
public final GPoint getLocalPoint(GPoint canvasPoint)
canvasPoint
- The coordinates in the space of the enclosing GCanvas
public Iterator<GObject> iterator()
Iterator
that cycles through the elements within
this container in the default direction, which is from back to front.
You can also run the iterator in the opposite direction by using the
iterator
(
direction)
form of this method.public Iterator<GObject> iterator(int direction)
Iterator
that cycles through the elements
within this container in the specified direction, which must be one
of the constants GContainer.FRONT_TO_BACK
or GContainer.BACK_TO_FRONT
.
for (Iterator<GObject> i = gc.iterator(direction); i.hasNext(); )
Iterator
ranging over the elements of the
container in the specified directionpublic void markAsComplete()
protected void paint2d(Graphics2D g)
paint2d
operation for this graphical object. This method
is not called directly by clients.public void remove(GObject gobj)
GCompound
.remove
in interface GContainer
gobj
- The graphical object to removepublic void removeAll()
GCompound
.removeAll
in interface GContainer
public void scale(double sx, double sy)
sx
and sy
. Automatic repaint is turned off
during the scaling operation so that at most one repaint is performed.protected void sendBackward(GObject gobj)
sendBackward
function from the GContainer
interface. Clients should not be calling this method, but the semantics of
interfaces forces it to be exported.protected void sendForward(GObject gobj)
sendForward
function from the GContainer
interface. Clients should not be calling this method, but the semantics of
interfaces forces it to be exported.protected void sendToBack(GObject gobj)
sendToBack
function from the GContainer
interface. Clients should not be calling this method, but the semantics of
interfaces forces it to be exported.protected void sendToFront(GObject gobj)
sendToFront
function from the GContainer
interface. Clients should not be calling this method, but the semantics of
interfaces forces it to be exported.