soc.client
Class SOCFaceButton

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by soc.client.SOCFaceButton
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class SOCFaceButton
extends java.awt.Canvas

This is a component that can display a face. When you click on the face, it changes to another face.

There are two modes: Standard (with associated player ID) for use in HandPanel; and Bordered (with associated FaceChooserFrame) for choosing a new face icon. The two constructors correspond to the two modes.

Author:
Robert S. Thomas
See Also:
FaceChooserFrame, Serialized Form

Nested Class Summary
protected static class SOCFaceButton.FaceButtonPopupMenu
          Menu for right-click on face icon to choose a new face (Player's hand only).
private  class SOCFaceButton.MyMouseAdapter
          Handle Events
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  java.awt.Image buffer
          offscreen buffer
private  int currentImageNum
          Human face images are positive numbers, 1-based (range 1 to NUM_FACES).
static int DEFAULT_FACE
           
static int FACE_BORDER_WIDTH_PX
          width of border (per side), used in FACE_WIDTH_BORDERED_PX
static int FACE_WIDTH_BORDERED_PX
          width,height of button with border around the face icon (bordered mode)
static int FACE_WIDTH_PX
          width,height of button showing only the face icon (standard mode)
private  FaceChooserFrame faceChooser
          Null unless being used in the face chooser
private  SOCGame game
           
private  java.awt.Color hilightBorderColor
          Color for selection border; ignored if faceChooser == null.
private  boolean hilightBorderShown
          Hilight selection border? always false if faceChooser == null.
private  boolean hilightBorderWasShown
          Recently shown hilight selection border? (Used in paint method to clear it away) Always false if faceChooser == null.
private static java.lang.String IMAGEDIR
           
private static java.awt.Image[] images
          Shared images
static int NUM_FACES
          number of /numbered/ face images, /plus 1/ for indexing.
static int NUM_ROBOT_FACES
          number of robot faces, which are separately numbered.
protected  java.awt.Dimension ourSize
          size
private  int panelx
           
private  int panely
           
private  SOCPlayerInterface pi
           
private  int pNumber
          player number
protected static int POPUP_MENU_IGNORE_MS
          For popup-menu, length of time after popup to ignore further mouse-clicks.
private  SOCFaceButton.FaceButtonPopupMenu popupMenu
          Context menu for face icon chooser
private  long popupMenuSystime
          Tracks last popup-menu time.
private static java.awt.Image[] robotImages
           
private static java.awt.MediaTracker tracker
          For status in drawFace
 
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
  SOCFaceButton(SOCPlayerInterface pi, FaceChooserFrame fcf, int faceId)
          create a new SOCFaceButton, for the FaceChooserFrame (bordered mode)
  SOCFaceButton(SOCPlayerInterface pi, int pn)
          create a new SOCFaceButton, for a player's handpanel (standard mode).
protected SOCFaceButton(SOCPlayerInterface pi, int pn, java.awt.Color bgColor, int width)
          implement creation of a new SOCFaceButton (common to both modes)
 
Method Summary
 void addFacePopupMenu()
          Designate player as client (can click and right-click to choose face icon).
 void clearFacePopupPreviousChooser()
          The previous face-chooser window (from the face-popup menu) has been disposed.
private  void drawFace(java.awt.Graphics g)
          draw the face
 int getFace()
           
 java.awt.Dimension getMinimumSize()
          DOCUMENT ME!
 java.awt.Dimension getPreferedSize()
          DOCUMENT ME!
 java.awt.Dimension getSize()
           
private static void loadImages(java.awt.Component c)
           
 void paint(java.awt.Graphics g)
          Redraw the facebutton using double buffering.
private  void paintBorder(java.awt.Graphics g, boolean showNotClear)
          Paint or clear the hilight border
 void removeFacePopupMenu()
          If we have a popup menu, remove it.
 void setDefaultFace()
          Reset to the default face.
 void setFace(int id)
          set which image is shown
 void setHilightBorder(boolean wantBorder)
          Set or clear the hilight border flag.
 void update(java.awt.Graphics g)
          Overriden so the peer isn't painted, which clears background.
 
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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, 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, setMaximumSize, setMinimumSize, setName, setPreferredSize, 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

DEFAULT_FACE

public static final int DEFAULT_FACE
See Also:
Constant Field Values

IMAGEDIR

private static final java.lang.String IMAGEDIR
See Also:
Constant Field Values

NUM_FACES

public static final int NUM_FACES
number of /numbered/ face images, /plus 1/ for indexing. If NUM_FACES is 74, there will be no face74.gif (but will be face73.gif).

See Also:
Constant Field Values

NUM_ROBOT_FACES

public static final int NUM_ROBOT_FACES
number of robot faces, which are separately numbered. Robot face 0 is just robot.gif, otherwise robot1.gif, robot2.gif, etc. Internally, robot faces are negative faceIds.

See Also:
Constant Field Values

FACE_WIDTH_PX

public static final int FACE_WIDTH_PX
width,height of button showing only the face icon (standard mode)

See Also:
Constant Field Values

FACE_BORDER_WIDTH_PX

public static final int FACE_BORDER_WIDTH_PX
width of border (per side), used in FACE_WIDTH_BORDERED_PX

See Also:
Constant Field Values

FACE_WIDTH_BORDERED_PX

public static final int FACE_WIDTH_BORDERED_PX
width,height of button with border around the face icon (bordered mode)

See Also:
Constant Field Values

images

private static java.awt.Image[] images
Shared images


robotImages

private static java.awt.Image[] robotImages

tracker

private static java.awt.MediaTracker tracker
For status in drawFace


currentImageNum

private int currentImageNum
Human face images are positive numbers, 1-based (range 1 to NUM_FACES). Robot face images are negative, 0-based (range -(NUM_ROBOT_FACES-1) to 0).


panelx

private int panelx

panely

private int panely

pNumber

private int pNumber
player number


game

private SOCGame game

pi

private SOCPlayerInterface pi

faceChooser

private FaceChooserFrame faceChooser
Null unless being used in the face chooser


hilightBorderShown

private boolean hilightBorderShown
Hilight selection border? always false if faceChooser == null.


hilightBorderWasShown

private boolean hilightBorderWasShown
Recently shown hilight selection border? (Used in paint method to clear it away) Always false if faceChooser == null.


hilightBorderColor

private java.awt.Color hilightBorderColor
Color for selection border; ignored if faceChooser == null.

See Also:
SOCPlayerInterface.makeGhostColor(Color)

popupMenu

private SOCFaceButton.FaceButtonPopupMenu popupMenu
Context menu for face icon chooser


popupMenuSystime

private long popupMenuSystime
Tracks last popup-menu time. Avoids misinterpretation of popup-click with placement-click during initial placement: On Windows, popup-click must be caught in mouseReleased, but mousePressed is called immediately afterwards.


POPUP_MENU_IGNORE_MS

protected static int POPUP_MENU_IGNORE_MS
For popup-menu, length of time after popup to ignore further mouse-clicks. Avoids Windows accidental left-click by popup-click. (150 ms)


buffer

private java.awt.Image buffer
offscreen buffer


ourSize

protected java.awt.Dimension ourSize
size

Constructor Detail

SOCFaceButton

public SOCFaceButton(SOCPlayerInterface pi,
                     int pn)
              throws java.lang.IllegalArgumentException
create a new SOCFaceButton, for a player's handpanel (standard mode). Face id DEFAULT_FACE.

Parameters:
pi - the interface that this button is attached to
pn - the number of the player that owns this button. Must be in range 0 to (SOCGame.maxPlayers - 1).
Throws:
java.lang.IllegalArgumentException - if pn is < -1 or >= SOCGame.MAXPLAYERS.

SOCFaceButton

public SOCFaceButton(SOCPlayerInterface pi,
                     FaceChooserFrame fcf,
                     int faceId)
create a new SOCFaceButton, for the FaceChooserFrame (bordered mode)

Parameters:
pi - Player interface (for stack-print callback ONLY)
fcf - Face chooser frame for callback
faceId - Face ID to show; same range as setFace(int)

SOCFaceButton

protected SOCFaceButton(SOCPlayerInterface pi,
                        int pn,
                        java.awt.Color bgColor,
                        int width)
                 throws java.lang.IllegalArgumentException
implement creation of a new SOCFaceButton (common to both modes)

Parameters:
pi - the interface that this button is attached to
pn - the number of the player that owns this button, or -1 if none; if pn >= 0, pi.getGame() must not be null.
bgColor - background color to use
width - width,height in pixels; FACE_WIDTH_PX or FACE_WIDTH_BORDERED_PX
Throws:
java.lang.IllegalArgumentException - if pn is < -1 or >= SOCGame.maxPlayers, or if pi.getGame() is null.
Method Detail

loadImages

private static void loadImages(java.awt.Component c)

getFace

public int getFace()
Returns:
which image id is shown

setFace

public void setFace(int id)
set which image is shown

Parameters:
id - the id for the image. Range is within -NUM_ROBOT_FACES to +NUM_FACES. Human id's out of range (>= NUM_FACES) get id DEFAULT_FACE. Robot id's out of range (<= -NUM_ROBOT_FACES) get id 0.

setDefaultFace

public void setDefaultFace()
Reset to the default face.


addFacePopupMenu

public void addFacePopupMenu()
                      throws java.lang.IllegalStateException
Designate player as client (can click and right-click to choose face icon). If we don't have a popup menu, and player is client, add it. If we already have one, nothing happens.

Throws:
java.lang.IllegalStateException - if player isn't client (checks getName vs client.getNickname)

removeFacePopupMenu

public void removeFacePopupMenu()
If we have a popup menu, remove it. All clicks will be ignored, and won't change the face id shown.


clearFacePopupPreviousChooser

public void clearFacePopupPreviousChooser()
The previous face-chooser window (from the face-popup menu) has been disposed. If menu item is chosen again, don't show the previous one, create a new face-chooser window.

See Also:
addFacePopupMenu()

setHilightBorder

public void setHilightBorder(boolean wantBorder)
                      throws java.lang.IllegalStateException
Set or clear the hilight border flag. Repaints if needed.

Parameters:
wantBorder - Show the hilight border?
Throws:
java.lang.IllegalStateException - If this FaceButton wasn't created for a face chooser.

getPreferedSize

public java.awt.Dimension getPreferedSize()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getMinimumSize

public java.awt.Dimension getMinimumSize()
DOCUMENT ME!

Overrides:
getMinimumSize in class java.awt.Component
Returns:
DOCUMENT ME!

getSize

public java.awt.Dimension getSize()
Overrides:
getSize in class java.awt.Component
Returns:
Size of this square facebutton

paint

public void paint(java.awt.Graphics g)
Redraw the facebutton using double buffering. Don't call this directly, use Component.repaint() instead.

Overrides:
paint in class java.awt.Canvas

update

public void update(java.awt.Graphics g)
Overriden so the peer isn't painted, which clears background. Don't call this directly, use Component.repaint() instead.

Overrides:
update in class java.awt.Canvas

drawFace

private void drawFace(java.awt.Graphics g)
draw the face


paintBorder

private void paintBorder(java.awt.Graphics g,
                         boolean showNotClear)
Paint or clear the hilight border