com.threerings.puzzle.client
Class PuzzleBoardView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.threerings.media.MediaPanel
                  extended by com.threerings.media.VirtualMediaPanel
                      extended by com.threerings.puzzle.client.PuzzleBoardView
All Implemented Interfaces:
com.threerings.media.FrameParticipant, com.threerings.media.MediaConstants, com.threerings.media.MediaHost, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
DropBoardView

public abstract class PuzzleBoardView
extends com.threerings.media.VirtualMediaPanel

The puzzle board view displays a view of a puzzle game.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.media.MediaPanel
com.threerings.media.MediaPanel.ActionSpriteHandler, com.threerings.media.MediaPanel.Obscurer
 
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  com.threerings.media.animation.AnimationAdapter _actionAnimObs
          Listens to our action animations and clears them when they're done.
protected  List<com.threerings.media.animation.Animation> _actionAnims
          The action animations on the board.
protected  List<com.threerings.media.sprite.Sprite> _actionSprites
          The action sprites on the board.
protected  com.threerings.media.animation.AnimationArranger _avoidArranger
          Prevents certain animations from overlapping others.
protected  com.threerings.media.image.Mirage _background
          Our background image.
protected  Board _board
          The board data to be displayed.
protected  Rectangle _bounds
          The board's bounding rectangle.
protected  PuzzleContext _ctx
          Our client context.
protected  Label _pauseLabel
          A label to show when the puzzle is paused.
protected  PuzzleController _pctrl
          Our puzzle controller.
protected  int _scoreDist
          The distance in pixels that score animations float.
protected static int ACTION_CLEARED
           
protected static int ACTION_GOING
           
protected static int CLEAR_PENDING
           
protected static boolean DEBUG_ACTION
          Temporary action debugging.
protected static int DEFAULT_SCORE_DISTANCE
          The default vertical distance to float score animations.
 
Fields inherited from class com.threerings.media.VirtualMediaPanel
_abounds, _dx, _dy, _fmode, _fpath, _nx, _ny, _trackers, _vbounds, CENTER_ON_PATHABLE, ENCLOSE_PATHABLE, TRACK_PATHABLE
 
Fields inherited from class com.threerings.media.MediaPanel
_actionHandler, _actionSpriteCount, _animmgr, _metamgr, _obscurerList, _remgr, _spritemgr, _tickPaintPending
 
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 com.threerings.media.MediaConstants
ALL, BACK, FRONT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PuzzleBoardView(PuzzleContext ctx)
          Constructs a puzzle board view.
 
Method Summary
 void abortAnimation(com.threerings.media.animation.Animation anim)
           
 void addActionAnimation(com.threerings.media.animation.Animation anim)
          Adds the given animation to the set of animations currently present on the board.
 void addActionSprite(com.threerings.media.sprite.Sprite sprite)
          Adds the given sprite to the set of sprites currently present on the board.
protected  void animationFinished(com.threerings.media.animation.Animation anim)
          Called when a potential action animation is finished.
 void clearAnimations()
           
 void clearSprites()
           
protected  ScoreAnimation createScoreAnimation(Label label, int x, int y)
          Creates a score animation, allowing derived classes to use custom animations that are customized following a call to createScoreAnimation(String,Color,Font,int,int).
 ScoreAnimation createScoreAnimation(String score, Color color, Font font, int x, int y)
          Creates and returns an animation displaying the given string with the specified parameters, floating it a short distance up the view.
 void dumpActors()
          Dumps to the logs, a list of interesting sprites and animations currently active on the puzzle board.
 int getActionAnimationCount()
          Returns the number of action animations on the board.
 int getActionCount()
          Returns the count of action sprites and animations on the board.
 int getActionSpriteCount()
          Returns the number of action sprites on the board.
 void init(GameConfig config)
          Initializes the board with the board dimensions.
protected  void maybeFireCleared()
          Fires a ACTION_CLEARED command if we have no remaining interesting sprites or animations.
 void paintBehind(Graphics2D gfx, Rectangle dirty)
           
 void paintBetween(Graphics2D gfx, Rectangle dirty)
           
protected  void paintInFront(Graphics2D gfx, Rectangle dirty)
           
 void removeSprite(com.threerings.media.sprite.Sprite sprite)
           
protected  void renderBackground(Graphics2D gfx, Rectangle dirty)
          Fills the background of the board with the background color.
protected abstract  void renderBoard(Graphics2D gfx, Rectangle dirty)
          Renders the board contents to the given graphics context.
 void setBackgroundImage(com.threerings.media.image.Mirage image)
          Sets the background image displayed by the board view.
 void setBoard(Board board)
          Sets the board to be displayed.
 void setController(PuzzleController pctrl)
          Provides the board view with a reference to its controller so that it may communicate directly rather than by posting actions up the interface hierarchy which sometimes fails if the puzzle board view is hidden before we get a chance to post our actions.
 void setPaused(boolean paused)
          Set whether this puzzle is paused or not.
 void trackAvoidAnimation(com.threerings.media.animation.Animation anim)
          Positions the supplied animation so as to avoid any active animations previously registered with this method, and adds the animation to the list of animations to be avoided by any future avoid animations.
 
Methods inherited from class com.threerings.media.VirtualMediaPanel
addObscurerDirtyRegion, addViewTracker, adjustBoundsCenter, clearPathable, constrainToBounds, didTick, dirtyScreenRect, doLayout, findRootBounds, getViewBounds, paint, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeViewTracker, setBackground, setBounds, setFollowsPathable, setViewLocation, trackPathable, viewLocationDidChange
 
Methods inherited from class com.threerings.media.MediaPanel
addAnimation, addObscurer, addObscurerDirtyRegions, addSprite, clipToDirtyRegion, createActionSpriteHandler, createGraphics, getAnimationManager, getComponent, getRegionManager, getSpriteManager, getTimeStamp, isManaged, isManaged, needsPaint, paint, paintBits, paintDirtyRect, removeObscurer, repaint, setOpaque, tick, willTick
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, 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, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, getMousePosition, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, 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

_ctx

protected PuzzleContext _ctx
Our client context.


_pctrl

protected PuzzleController _pctrl
Our puzzle controller.


_board

protected Board _board
The board data to be displayed.


_bounds

protected Rectangle _bounds
The board's bounding rectangle.


_actionAnims

protected List<com.threerings.media.animation.Animation> _actionAnims
The action animations on the board.


_actionSprites

protected List<com.threerings.media.sprite.Sprite> _actionSprites
The action sprites on the board.


_avoidArranger

protected com.threerings.media.animation.AnimationArranger _avoidArranger
Prevents certain animations from overlapping others.


_background

protected com.threerings.media.image.Mirage _background
Our background image.


_pauseLabel

protected Label _pauseLabel
A label to show when the puzzle is paused.


_scoreDist

protected int _scoreDist
The distance in pixels that score animations float.


_actionAnimObs

protected com.threerings.media.animation.AnimationAdapter _actionAnimObs
Listens to our action animations and clears them when they're done.


DEBUG_ACTION

protected static boolean DEBUG_ACTION
Temporary action debugging.


ACTION_GOING

protected static final int ACTION_GOING
See Also:
Constant Field Values

CLEAR_PENDING

protected static final int CLEAR_PENDING
See Also:
Constant Field Values

ACTION_CLEARED

protected static final int ACTION_CLEARED
See Also:
Constant Field Values

DEFAULT_SCORE_DISTANCE

protected static final int DEFAULT_SCORE_DISTANCE
The default vertical distance to float score animations.

See Also:
Constant Field Values
Constructor Detail

PuzzleBoardView

public PuzzleBoardView(PuzzleContext ctx)
Constructs a puzzle board view.

Method Detail

init

public void init(GameConfig config)
Initializes the board with the board dimensions.


setBoard

public void setBoard(Board board)
Sets the board to be displayed.


setController

public void setController(PuzzleController pctrl)
Provides the board view with a reference to its controller so that it may communicate directly rather than by posting actions up the interface hierarchy which sometimes fails if the puzzle board view is hidden before we get a chance to post our actions.


setBackgroundImage

public void setBackgroundImage(com.threerings.media.image.Mirage image)
Sets the background image displayed by the board view.


setPaused

public void setPaused(boolean paused)
Set whether this puzzle is paused or not. If paused, a label will be displayed with the component's font, which may be set with setFont().

Overrides:
setPaused in class com.threerings.media.MediaPanel

addActionAnimation

public void addActionAnimation(com.threerings.media.animation.Animation anim)
Adds the given animation to the set of animations currently present on the board. The animation will be added to a list of action animations whose count can be queried with getActionAnimationCount(). The animation will automatically be removed from the action list when it completes.


abortAnimation

public void abortAnimation(com.threerings.media.animation.Animation anim)
Overrides:
abortAnimation in class com.threerings.media.MediaPanel

animationFinished

protected void animationFinished(com.threerings.media.animation.Animation anim)
Called when a potential action animation is finished.


addActionSprite

public void addActionSprite(com.threerings.media.sprite.Sprite sprite)
Adds the given sprite to the set of sprites currently present on the board. The sprite will be added to a list of action sprites whose count can be queried with getActionSpriteCount(). Callers should be sure to remove the sprite when their work with it is done via removeSprite(com.threerings.media.sprite.Sprite).


removeSprite

public void removeSprite(com.threerings.media.sprite.Sprite sprite)
Overrides:
removeSprite in class com.threerings.media.MediaPanel

clearSprites

public void clearSprites()
Overrides:
clearSprites in class com.threerings.media.MediaPanel

clearAnimations

public void clearAnimations()
Overrides:
clearAnimations in class com.threerings.media.MediaPanel

getActionAnimationCount

public int getActionAnimationCount()
Returns the number of action animations on the board.


getActionSpriteCount

public int getActionSpriteCount()
Returns the number of action sprites on the board.


getActionCount

public int getActionCount()
Returns the count of action sprites and animations on the board.


dumpActors

public void dumpActors()
Dumps to the logs, a list of interesting sprites and animations currently active on the puzzle board.


createScoreAnimation

public ScoreAnimation createScoreAnimation(String score,
                                           Color color,
                                           Font font,
                                           int x,
                                           int y)
Creates and returns an animation displaying the given string with the specified parameters, floating it a short distance up the view.

Parameters:
score - the score text to display.
color - the color of the text.
font - the font with which to create the score animation.
x - the x-position at which the score is to be placed.
y - the y-position at which the score is to be placed.

createScoreAnimation

protected ScoreAnimation createScoreAnimation(Label label,
                                              int x,
                                              int y)
Creates a score animation, allowing derived classes to use custom animations that are customized following a call to createScoreAnimation(String,Color,Font,int,int).


trackAvoidAnimation

public void trackAvoidAnimation(com.threerings.media.animation.Animation anim)
Positions the supplied animation so as to avoid any active animations previously registered with this method, and adds the animation to the list of animations to be avoided by any future avoid animations.


paintBehind

public void paintBehind(Graphics2D gfx,
                        Rectangle dirty)
Overrides:
paintBehind in class com.threerings.media.VirtualMediaPanel

renderBackground

protected void renderBackground(Graphics2D gfx,
                                Rectangle dirty)
Fills the background of the board with the background color.


paintBetween

public void paintBetween(Graphics2D gfx,
                         Rectangle dirty)
Overrides:
paintBetween in class com.threerings.media.MediaPanel

paintInFront

protected void paintInFront(Graphics2D gfx,
                            Rectangle dirty)
Overrides:
paintInFront in class com.threerings.media.MediaPanel

maybeFireCleared

protected void maybeFireCleared()
Fires a ACTION_CLEARED command if we have no remaining interesting sprites or animations.


renderBoard

protected abstract void renderBoard(Graphics2D gfx,
                                    Rectangle dirty)
Renders the board contents to the given graphics context. Sub-classes should implement this method to draw all of their game-specific business.