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.accessibleContext, 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.
|
protected void |
conditionalRepaint()
Repaints the canvas if auto-repaint is in effect.
|
protected void |
dispatchMouseEvent(java.awt.event.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.
|
java.util.Iterator<GObject> |
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<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(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 . |
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(java.awt.Graphics g)
Updates the canvas.
|
protected void |
updateEnabledList()
Reconstructs the enabledList list in the correct order.
|
add, add, add, add, addContainerListener, addImpl, 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, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, 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<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 java.util.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 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
otherwiseprotected 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.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 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 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 dispatchMouseEvent(java.awt.event.MouseEvent e)
e
- The event that triggered this responseprotected void initOffscreenImage()
protected void conditionalRepaint()
repaint
method in
GObject
and is not accessible outside the package.protected void updateEnabledList()