com.threerings.opengl
Class DisplayCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.threerings.opengl.DisplayCanvas
All Implemented Interfaces:
GlCanvas, ImageObserver, KeyEventDispatcher, MenuContainer, Serializable, Accessible

public class DisplayCanvas
extends JPanel
implements GlCanvas, KeyEventDispatcher

A canvas that uses Display.

See Also:
Serialized Form

Nested Class Summary
protected  class DisplayCanvas.ButtonRecord
          Contains the state of a single mouse button.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  DisplayCanvas.ButtonRecord[] _buttons
          The states of the mouse buttons.
protected  Canvas _canvas
          The contained canvas.
protected  boolean _entered
          Whether or not the mouse is over the component.
protected  boolean _initialized
          Set on initialization.
protected  int _lclicks
          The number of wheel clicks recorded.
protected  int _lx
          The last position we reported.
protected  int _ly
          The last position we reported.
protected  int _modifiers
          The current set of modifiers.
protected  HashIntSet _pressedKeys
          The set of currently pressed keys.
protected  Runnable _updater
          The runnable that updates the frame.
protected static int ANY_BUTTONS_DOWN_MASK
          A mask for checking whether any mouse buttons are down.
protected static long CLICK_CHAIN_INTERVAL
          Clicks this close to one another are chained together for counting purposes.
protected static long CLICK_INTERVAL
          Mouse buttons released within this interval after being pressed are counted as clicks.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
DisplayCanvas()
          Creates a new canvas.
 
Method Summary
 void addNotify()
           
protected  boolean anyButtonsDown()
          Determines whether the current set of modifiers contains any pressed buttons.
protected  void checkButtonState(long now, int x, int y, int button, boolean pressed)
          Checks for button press/release.
protected  void checkEntered(long now, int x, int y)
          Determines whether the mouse has entered the component, dispatching an event if so.
protected  void checkExited(long now, int x, int y)
          Determines whether the mouse has exited the component, dispatching an event if so.
protected  void checkMoved(long now, int x, int y)
          Determines whether the mouse has moved, dispatching an event if so.
protected  void didInit()
          Override to perform custom initialization.
 boolean dispatchKeyEvent(KeyEvent event)
           
protected  void generateEvents()
          Generates AWT input events from the LWJGL devices.
protected static int getAWTButton(int button)
          Returns the AWT button corresponding to the specified LWJGL button.
protected static int getAWTCode(int key)
          Returns the AWT key code corresponding to the specified key.
protected static int getAWTLocation(int key)
          Returns the AWT location corresponding to the specified key.
 Drawable getDrawable()
          Returns the canvas drawable.
protected static int getLWJGLButton(int button)
          Returns the LWJGL button corresponding to the specified AWT button.
 Point getMousePosition()
           
protected  Point getRelativeMouseLocation()
          Returns the location of the mouse pointer relative to this component, regardless of whether or not it's actually hovering over the component.
protected  void init(PixelFormat pformat)
          Attempts to create the display with this canvas as its parent.
 void makeCurrent()
          Makes the canvas context current.
 void removeNotify()
           
protected  void renderView()
          Override to render the contents of the canvas.
 void setVSyncEnabled(boolean vsync)
          Enables or disables vsync.
 void shutdown()
          Shuts down the canvas.
protected  void startUpdating()
          Starts calling updateFrame() regularly.
protected  void stopUpdating()
          Stops calling updateFrame().
protected  void updateButtonModifier(int button, boolean pressed)
          Updates the modifier for the specified button.
protected  void updateFrame()
          Updates and, if the canvas is showing, renders the scene and swaps the buffers.
protected  void updateView()
          Override to perform any updates that are required even if not rendering.
protected  boolean windowIsFocused()
          Checks whether the window that contains this canvas (if any) is focused.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_canvas

protected Canvas _canvas
The contained canvas.


_initialized

protected boolean _initialized
Set on initialization.


_updater

protected Runnable _updater
The runnable that updates the frame.


_entered

protected boolean _entered
Whether or not the mouse is over the component.


_lx

protected int _lx
The last position we reported.


_ly

protected int _ly
The last position we reported.


_buttons

protected DisplayCanvas.ButtonRecord[] _buttons
The states of the mouse buttons.


_lclicks

protected int _lclicks
The number of wheel clicks recorded.


_modifiers

protected int _modifiers
The current set of modifiers.


_pressedKeys

protected HashIntSet _pressedKeys
The set of currently pressed keys.


ANY_BUTTONS_DOWN_MASK

protected static final int ANY_BUTTONS_DOWN_MASK
A mask for checking whether any mouse buttons are down.

See Also:
Constant Field Values

CLICK_INTERVAL

protected static final long CLICK_INTERVAL
Mouse buttons released within this interval after being pressed are counted as clicks.

See Also:
Constant Field Values

CLICK_CHAIN_INTERVAL

protected static final long CLICK_CHAIN_INTERVAL
Clicks this close to one another are chained together for counting purposes.

See Also:
Constant Field Values
Constructor Detail

DisplayCanvas

public DisplayCanvas()
Creates a new canvas.

Method Detail

getDrawable

public Drawable getDrawable()
Description copied from interface: GlCanvas
Returns the canvas drawable.

Specified by:
getDrawable in interface GlCanvas

setVSyncEnabled

public void setVSyncEnabled(boolean vsync)
Description copied from interface: GlCanvas
Enables or disables vsync.

Specified by:
setVSyncEnabled in interface GlCanvas

makeCurrent

public void makeCurrent()
Description copied from interface: GlCanvas
Makes the canvas context current.

Specified by:
makeCurrent in interface GlCanvas

shutdown

public void shutdown()
Description copied from interface: GlCanvas
Shuts down the canvas.

Specified by:
shutdown in interface GlCanvas

dispatchKeyEvent

public boolean dispatchKeyEvent(KeyEvent event)
Specified by:
dispatchKeyEvent in interface KeyEventDispatcher

addNotify

public void addNotify()
Overrides:
addNotify in class JComponent

removeNotify

public void removeNotify()
Overrides:
removeNotify in class JComponent

getMousePosition

public Point getMousePosition()
Overrides:
getMousePosition in class Component

init

protected void init(PixelFormat pformat)
             throws LWJGLException
Attempts to create the display with this canvas as its parent.

Throws:
LWJGLException

didInit

protected void didInit()
Override to perform custom initialization.


startUpdating

protected void startUpdating()
Starts calling updateFrame() regularly.


stopUpdating

protected void stopUpdating()
Stops calling updateFrame().


updateFrame

protected void updateFrame()
Updates and, if the canvas is showing, renders the scene and swaps the buffers.


generateEvents

protected void generateEvents()
Generates AWT input events from the LWJGL devices.


checkEntered

protected void checkEntered(long now,
                            int x,
                            int y)
Determines whether the mouse has entered the component, dispatching an event if so.


checkExited

protected void checkExited(long now,
                           int x,
                           int y)
Determines whether the mouse has exited the component, dispatching an event if so.


windowIsFocused

protected boolean windowIsFocused()
Checks whether the window that contains this canvas (if any) is focused.


checkMoved

protected void checkMoved(long now,
                          int x,
                          int y)
Determines whether the mouse has moved, dispatching an event if so.


checkButtonState

protected void checkButtonState(long now,
                                int x,
                                int y,
                                int button,
                                boolean pressed)
Checks for button press/release.


updateButtonModifier

protected void updateButtonModifier(int button,
                                    boolean pressed)
Updates the modifier for the specified button.


updateView

protected void updateView()
Override to perform any updates that are required even if not rendering.


renderView

protected void renderView()
Override to render the contents of the canvas.


getRelativeMouseLocation

protected Point getRelativeMouseLocation()
Returns the location of the mouse pointer relative to this component, regardless of whether or not it's actually hovering over the component.


anyButtonsDown

protected boolean anyButtonsDown()
Determines whether the current set of modifiers contains any pressed buttons.


getAWTCode

protected static int getAWTCode(int key)
Returns the AWT key code corresponding to the specified key.


getAWTLocation

protected static int getAWTLocation(int key)
Returns the AWT location corresponding to the specified key.


getAWTButton

protected static int getAWTButton(int button)
Returns the AWT button corresponding to the specified LWJGL button.


getLWJGLButton

protected static int getLWJGLButton(int button)
Returns the LWJGL button corresponding to the specified AWT button.