public class GCanvas extends java.awt.Container implements GContainer
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.BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BACK_TO_FRONT, FRONT_TO_BACK
Constructor and Description |
---|
GCanvas()
Creates a new
GCanvas that contains no objects. |
Modifier and Type | Method and Description |
---|---|
java.awt.Component |
add(java.awt.Component comp)
Adds the component to this canvas without changing its location.
|
void |
add(java.awt.Component comp,
double x,
double y)
Adds the component to this canvas and sets its location
to the point (
x , y ). |
void |
add(java.awt.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.
|
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 auto-repaint flag as described in
setNativeArcFlag . |
int |
getWidth()
Returns the width of this canvas in pixels.
|
boolean |
isOpaque()
Returns a boolean value indicating whether this canvas is opaque.
|
java.util.Iterator |
iterator()
Returns an
Iterator that cycles through the elements within
this container in the default direction, which is from back to front. |
java.util.Iterator |
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(java.awt.Graphics g)
Paints the canvas.
|
void |
remove(java.awt.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 . |
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(java.awt.Graphics g)
Updates the canvas.
|
add, add, add, add, addContainerListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, isValidateRoot, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, validate
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public void add(GObject gobj)
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 pointpublic void remove(GObject gobj)
GCanvas
.remove
in interface GContainer
gobj
- The graphical object to removepublic void removeAll()
GCanvas
.removeAll
in interface GContainer
removeAll
in class java.awt.Container
public java.awt.Component add(java.awt.Component comp)
Component
to match the method in
the Container
class, but the result is typically
ignored.add
in class java.awt.Container
comp
- The component to addpublic final void add(java.awt.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 objectpublic final void add(java.awt.Component comp, GPoint pt)
comp
- The component to addpt
- A GPoint
object giving the coordinates of the pointpublic void remove(java.awt.Component comp)
remove
in class java.awt.Container
comp
- The component to removepublic int getElementCount()
GCanvas
.getElementCount
in interface GContainer
GCanvas
public GObject getElement(int index)
getElement
in interface GContainer
index
- The index of the component to returnpublic GObject getElementAt(double x, double y)
x
, y
), or null
if no such
object exists.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 GObject getElementAt(GPoint pt)
null
if no such object exists.getElementAt
in interface GContainer
pt
- The coordinates being testednull
if no such object existspublic java.util.Iterator 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.
Applets that want to run in browsers, however, should avoid using
this method, because Iterator
is not supported on 1.1 browsers.
For maximum portability, you should rely instead on the
getElementCount
and getElement
methods,
which provide the same functionality in a browser-compatible way.
Iterator
ranging over the elements of the
container from back to frontpublic java.util.Iterator 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 i = gc.iterator(direction); i.hasNext(); )
Applets that want to run in browsers, however, should avoid using
this method, because Iterator
is not supported on 1.1 browsers.
For maximum portability, you should rely instead on the
getElementCount
and getElement
methods,
which provide the same functionality in a browser-compatible way.
Iterator
ranging over the elements of the
container in the specified directionpublic 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 boolean isOpaque()
isOpaque
in class java.awt.Component
true
if this canvas is opaque, and false
if it is transparentpublic int getWidth()
getWidth
in class java.awt.Component
public int getHeight()
getHeight
in class java.awt.Component
public void paint(java.awt.Graphics g)
paint
in class java.awt.Container
g
- The graphics context into which the canvas is paintedpublic void update(java.awt.Graphics g)
update
in class java.awt.Container
g
- The graphics context into which the canvas is paintedpublic 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 boolean getAutoRepaintFlag()
setAutoRepaintFlag
.true
if auto-repaint mode is enabled, and false
otherwisepublic 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 boolean getNativeArcFlag()
setNativeArcFlag
.true
if native arcs are enabled, and false
otherwise