javax.swing
Class SystemEventQueueUtilities.RunnableCanvas

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended byjavax.swing.SystemEventQueueUtilities.RunnableCanvas
All Implemented Interfaces:
javax.accessibility.Accessible, ImageObserver, MenuContainer, Serializable
Enclosing class:
SystemEventQueueUtilities

private static class SystemEventQueueUtilities.RunnableCanvas
extends Canvas

Applets don't have direct access to the AWT SystemEvent queue. To work around this we call RunnableCanvas.repaint() on a per applet instance of this class. The AWT deals with this by queuing a java.awt.PaintEvent for the event dispatching thread which is dispatched (Component.dispatchEvent()) the usual way. Component.dispatchEvent() handles PaintEvents by calling our update() method (on the event dispatching thread) which processes the RunnableEvents stashed in the runnableEvents vector.


Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  boolean isRegistered
           
private static Graphics nullGraphics
           
private static Hashtable runnableCanvasTable
           
private  Vector runnableEvents
           
 
Fields inherited from class java.awt.Canvas
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
(package private) SystemEventQueueUtilities.RunnableCanvas(JRootPane rootPane)
           
 
Method Summary
(package private)  void addRunnableEvent(SystemEventQueueUtilities.RunnableEvent e)
          Add a RunnableEvent to the queue that will be dispatched when this component is repainted.
 Graphics getGraphics()
          Reduce the cost of repainting (since we're not going to draw anything) by returning a constant no-op graphics object.
 Dimension getPreferredSize()
          Testing purposes only.
private  SystemEventQueueUtilities.RunnableEvent[] getRunnableCanvasEvents()
          Return an (array) copy of the runnableEvents vector or null if the vector is empty.
 boolean isShowing()
          If there are events to be processed then we're showing.
(package private) static SystemEventQueueUtilities.RunnableCanvas lookup(SystemEventQueueUtilities.RunnableEvent e)
          If we're running on the event dispatching thread then lookup the canvas with the current thread itself, otherwise use the current threads thread group.
private  void maybeRegisterEventDispatchThread()
          If called on an event dispatching thread that we haven't seen before then make two hashtable entries in the runnableCanvasTable: current thread => this RunnableCanvas current thread group => this RunnableCanvas
 void paint(Graphics g)
          Paints this canvas.
(package private) static void postRunnableEventToAll(SystemEventQueueUtilities.RunnableEvent e)
          Adds the event to all the RunnableCanvases.
(package private) static void remove(JRootPane rootPane)
          Remove the RunnableCanvas associated with this applet from the applets Layered pane and clear all of the runnableCanvasTable entries that point at it.
 void update(Graphics g)
          Process all of the RunnableEvents that have accumulated since RunnableCanvas.repaint() was called.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nullGraphics

private static final Graphics nullGraphics

runnableCanvasTable

private static Hashtable runnableCanvasTable

runnableEvents

private Vector runnableEvents

isRegistered

private boolean isRegistered
Constructor Detail

SystemEventQueueUtilities.RunnableCanvas

SystemEventQueueUtilities.RunnableCanvas(JRootPane rootPane)
Method Detail

maybeRegisterEventDispatchThread

private void maybeRegisterEventDispatchThread()
If called on an event dispatching thread that we haven't seen before then make two hashtable entries in the runnableCanvasTable:
   current thread => this RunnableCanvas
   current thread group => this RunnableCanvas
 

See Also:
lookup(javax.swing.SystemEventQueueUtilities.RunnableEvent)

lookup

static SystemEventQueueUtilities.RunnableCanvas lookup(SystemEventQueueUtilities.RunnableEvent e)
If we're running on the event dispatching thread then lookup the canvas with the current thread itself, otherwise use the current threads thread group. If there is no match for the ThreadGroup, the first visible RunnableCanvas is returned.


postRunnableEventToAll

static void postRunnableEventToAll(SystemEventQueueUtilities.RunnableEvent e)
Adds the event to all the RunnableCanvases.

See Also:
SystemEventQueueUtilities.restartTimerQueueThread()

remove

static void remove(JRootPane rootPane)
Remove the RunnableCanvas associated with this applet from the applets Layered pane and clear all of the runnableCanvasTable entries that point at it.


isShowing

public boolean isShowing()
If there are events to be processed then we're showing. Note that the AWT code that dispatches paint events short circuits (does nothing) if isShowing() returns false.

Overrides:
isShowing in class Component
Returns:
true if the component is showing, false otherwise
See Also:
Component.setVisible(boolean)

getGraphics

public Graphics getGraphics()
Reduce the cost of repainting (since we're not going to draw anything) by returning a constant no-op graphics object.

Overrides:
getGraphics in class Component
Returns:
a graphics context for this component, or null if it has none
See Also:
Component.paint(java.awt.Graphics)

getPreferredSize

public Dimension getPreferredSize()
Testing purposes only. This method shouldn't be called; the parent of this component should have a null layout manager.

Overrides:
getPreferredSize in class Component
Returns:
a dimension object indicating this component's preferred size
See Also:
Component.getMinimumSize(), LayoutManager

addRunnableEvent

void addRunnableEvent(SystemEventQueueUtilities.RunnableEvent e)
Add a RunnableEvent to the queue that will be dispatched when this component is repainted.

See Also:
update(java.awt.Graphics)

getRunnableCanvasEvents

private SystemEventQueueUtilities.RunnableEvent[] getRunnableCanvasEvents()
Return an (array) copy of the runnableEvents vector or null if the vector is empty. The update method processes a copy of the vector so that we don't have to hold the synchronized lock while calling processRunnableEvent().

See Also:
update(java.awt.Graphics)

paint

public void paint(Graphics g)
Description copied from class: Canvas
Paints this canvas.

Most applications that subclass Canvas should override this method in order to perform some useful operation (typically, custom painting of the canvas). The default operation is simply to clear the canvas. Applications that override this method need not call super.paint(g).

Overrides:
paint in class Canvas
Parameters:
g - the specified Graphics context
See Also:
Canvas.update(Graphics), Component.paint(Graphics)

update

public void update(Graphics g)
Process all of the RunnableEvents that have accumulated since RunnableCanvas.repaint() was called.

Overrides:
update in class Canvas
Parameters:
g - the specified Graphics context
See Also:
Canvas.paint(Graphics), Component.update(Graphics)