|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
acm.graphics.GCanvas
public class GCanvas
The GCanvas class is a lightweight component that also
serves as a container for graphical objects. As such, this class
provides the link between graphical objects and the window system.
Conceptually, the GCanvas provides a background canvas
to which other graphical objects can be added.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface acm.graphics.GContainer |
|---|
BACK_TO_FRONT, FRONT_TO_BACK |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
GCanvas()
Creates a new GCanvas that contains no objects. |
|
| Method Summary | |
|---|---|
Component |
add(Component comp)
Adds the component to this canvas without changing its location. |
void |
add(Component comp,
double x,
double y)
Adds the component to this canvas and sets its location to the point ( x, y). |
void |
add(Component comp,
GPoint pt)
Adds the component to this canvas and sets its location to the specified point. |
void |
add(GObject gobj)
Adds the graphical object to this canvas. |
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 void |
conditionalRepaint()
Repaints the canvas if auto-repaint is in effect. |
protected void |
dispatchMouseEvent(MouseEvent e)
Dispatches this mouse event to the uppermost graphical object for which the active point is within the object bounds. |
boolean |
getAutoRepaintFlag()
Returns the current setting of the auto-repaint flag as described in setAutoRepaintFlag. |
GObject |
getElement(int index)
Returns the graphical object at the specified index, numbering from back to front in the the z dimension. |
GObject |
getElementAt(double x,
double y)
Returns the topmost graphical object that contains the point ( x, y), or null if no such
object exists. |
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 GCanvas. |
int |
getHeight()
Returns the height of this canvas in pixels. |
boolean |
getNativeArcFlag()
Returns the current setting of the native-arc flag as described in setNativeArcFlag. |
int |
getWidth()
Returns the width of this canvas in pixels. |
protected void |
initOffscreenImage()
Initializes the offscreen memory image used for double buffering. |
boolean |
isOpaque()
Returns a boolean value indicating whether this canvas is opaque. |
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 |
paint(Graphics g)
Paints the canvas. |
void |
remove(Component comp)
Removes the component from the canvas. |
void |
remove(GObject gobj)
Removes a graphical object from this GCanvas. |
void |
removeAll()
Removes all graphical objects from this GCanvas. |
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. |
void |
setAutoRepaintFlag(boolean state)
Changes the setting of the auto-repaint flag. |
void |
setNativeArcFlag(boolean state)
Sets whether the redering code for GArc and GOval should use
Java arcs. |
void |
setOpaque(boolean flag)
Sets a flag indicating whether this canvas is opaque, which means that it obscures anything behind it. |
void |
update(Graphics g)
Updates the canvas. |
protected void |
updateEnabledList()
Reconstructs the enabledList list in the correct order. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public GCanvas()
GCanvas that contains no objects.
| Method Detail |
|---|
public Component add(Component comp)
Component to match the method in
the Container class, but the result is typically
ignored.
add in class Containercomp - The component to add
public final void add(Component comp,
double x,
double y)
x, y).
comp - The component to addx - The new x-coordinate for the objecty - The new y-coordinate for the object
public final void add(Component comp,
GPoint pt)
comp - The component to addpt - A GPoint object giving the coordinates of the pointpublic void add(GObject gobj)
add in interface GContainergobj - The graphical object to add
public final void add(GObject gobj,
double x,
double y)
x, y).
add in interface GContainergobj - The graphical object to addx - The new x-coordinate for the objecty - The new y-coordinate for the object
public final void add(GObject gobj,
GPoint pt)
add in interface GContainergobj - The graphical object to addpt - A GPoint object giving the coordinates of the pointprotected void conditionalRepaint()
repaint method in
GObject and is not accessible outside the package.
protected void dispatchMouseEvent(MouseEvent e)
e - The event that triggered this responsepublic boolean getAutoRepaintFlag()
setAutoRepaintFlag.
true if auto-repaint mode is enabled, and false
otherwisepublic GObject getElement(int index)
getElement in interface GContainerindex - The index of the component to return
public GObject getElementAt(double x,
double y)
x, y), or null if no such
object exists.
getElementAt in interface GContainerx - The x-coordinate of the point being testedy - The y-coordinate of the point being tested
null
if no such object existspublic final GObject getElementAt(GPoint pt)
null if no such object exists.
getElementAt in interface GContainerpt - The coordinates being tested
null
if no such object existspublic int getElementCount()
GCanvas.
getElementCount in interface GContainerGCanvaspublic int getHeight()
getHeight in class Componentpublic boolean getNativeArcFlag()
setNativeArcFlag.
true if native arcs are enabled, and false
otherwisepublic int getWidth()
getWidth in class Componentprotected void initOffscreenImage()
public boolean isOpaque()
isOpaque in class Componenttrue if this canvas is opaque, and false
if it is transparentpublic 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.
Iterator ranging over the elements of the
container from back to frontpublic 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 paint(Graphics g)
paint in class Containerg - The graphics context into which the canvas is paintedpublic void remove(Component comp)
remove in class Containercomp - The component to removepublic void remove(GObject gobj)
GCanvas.
remove in interface GContainergobj - The graphical object to removepublic void removeAll()
GCanvas.
removeAll in interface GContainerremoveAll in class Containerprotected 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.
public void setAutoRepaintFlag(boolean state)
setAutoRepaintFlag(false), but you must then make explicit
calls to repaint() whenever you want to update the display.
The advantage of this model is that you can then make many different changes
and have them all appear at once with a single repaint call.
state - true to enable auto-repaint mode, and false
to disable itpublic void setNativeArcFlag(boolean state)
GArc and GOval should use
Java arcs. By default, arcs and ovals are rendered using polygons and polylines
to ensure that the same set of pixels is covered by the fill and frame.
If this value is set to true, the renderers will use the native
arc code, which is more efficient but less accurate.
state - true to enable native arcs, false to use polygonspublic void setOpaque(boolean flag)
false makes
the GCanvas transparent, so that any other lightweight components
behind it show through.
flag - true to make this canvas opaque, and false
to make it transparentpublic void update(Graphics g)
update in class Containerg - The graphics context into which the canvas is paintedprotected void updateEnabledList()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||