cz.nipax.hippo.pexeso
Class PlaygroundComponent

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by cz.nipax.hippo.pexeso.PlaygroundComponent
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener

public class PlaygroundComponent
extends javax.swing.JComponent
implements java.awt.event.MouseListener

PlaygroundComponent creates playground and gets user input. It requires to have valid Playground in constructor to know what to display. Playground should call repaint if gamestate changes.

If any AI wants to receive input from user, it needs to register. Just call registerAI(cz.nipax.hippo.pexeso.AI). Note that PlaygroundComponent stores only one AI. So if game is with more AIs that want user input, registerAI(cz.nipax.hippo.pexeso.AI) everytime AI on turn is changed. This call is done by Playground.switchplayer(boolean), so AI class doesn't have to do it.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private) static boolean DEBUG
          Enables debug messages.
(package private)  AI m_ai
          Currently active AI.
private  java.awt.Image m_back
           
private  java.awt.image.VolatileImage m_back_vol
          Off screen image of game.
private  Playground m_pg
          Local reference to main Playground
(package private)  PGTheme m_theme
          All graphic and dimensions of graphics
 
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
PlaygroundComponent(Playground pg)
          Perpares whole class for use.
 
Method Summary
 void createback()
           
private  void drawImage_true(java.awt.Graphics g, java.awt.Image img, int x, int y)
          Graphics.drawImage may return false and then no image is drawn.
 java.awt.Dimension getPreferredSize()
          Set default size of playground.
 void mouseClicked(java.awt.event.MouseEvent event)
          Computes field where user has clicked and sends it to m_ai via AI.userinput(int, int).
 void mouseEntered(java.awt.event.MouseEvent event)
          Empty function - just for MouseListener interface.
 void mouseExited(java.awt.event.MouseEvent event)
          Empty function - just for MouseListener interface.
 void mousePressed(java.awt.event.MouseEvent event)
          Empty function - just for MouseListener interface.
 void mouseReleased(java.awt.event.MouseEvent event)
          Empty function - just for MouseListener interface.
 void paint_offscreen(boolean updateonly, java.awt.Graphics gr)
          Paints playground and game statistic.
 void paintComponent(java.awt.Graphics g)
           
 void println(java.lang.String s)
          Inteligent message printing.
 void registerAI(AI ai)
          Set current AI.
 void repaint_later(boolean update_only)
          This should be caled from Playground if repaint is wanted.
 void setTheme(PGTheme theme)
          Chenges current theme.
 
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, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printComponent, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, updateUI
 
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, 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, checkImage, checkImage, 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

DEBUG

static final boolean DEBUG
Enables debug messages.

See Also:
Constant Field Values

m_pg

private Playground m_pg
Local reference to main Playground


m_ai

AI m_ai
Currently active AI. Needed to know where to pass user input. May be null.


m_theme

PGTheme m_theme
All graphic and dimensions of graphics


m_back_vol

private java.awt.image.VolatileImage m_back_vol
Off screen image of game. For better graphic performance


m_back

private java.awt.Image m_back
Constructor Detail

PlaygroundComponent

PlaygroundComponent(Playground pg)
Perpares whole class for use. Loads images of pexesos :-) Also register self into Playground via Playground.setPGC(cz.nipax.hippo.pexeso.PlaygroundComponent).

Parameters:
pg - what playground to display
Method Detail

println

public void println(java.lang.String s)
Inteligent message printing. It is possible to disable all messages in one place - for some kind of final release


registerAI

public void registerAI(AI ai)
Set current AI. Changes m_ai.

Parameters:
ai - the current ai.

setTheme

public void setTheme(PGTheme theme)
Chenges current theme. Owerwrites m_theme.

Parameters:
theme - new theme

createback

public void createback()

getPreferredSize

public java.awt.Dimension getPreferredSize()
Set default size of playground.

Overrides:
getPreferredSize in class javax.swing.JComponent

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

paint_offscreen

public void paint_offscreen(boolean updateonly,
                            java.awt.Graphics gr)
Paints playground and game statistic. Performs full redraw but without clearing backgorund. Uses cliping for better perfomance.


repaint_later

public void repaint_later(boolean update_only)
This should be caled from Playground if repaint is wanted.

Parameters:
update_only - if only few cards chenged visibility - for incremental painting and thus better performance. This is critical for Kaffe if you want to be able to play th egame.

drawImage_true

private void drawImage_true(java.awt.Graphics g,
                            java.awt.Image img,
                            int x,
                            int y)
Graphics.drawImage may return false and then no image is drawn. Usually repeted paint with some delay correct this. The problem was observed with sun java 1.5. classpath worked with no problem. It looks like the picture need some time to get ready before drawing. It happens for one picture only once.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
Computes field where user has clicked and sends it to m_ai via AI.userinput(int, int).

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)
Empty function - just for MouseListener interface.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
Empty function - just for MouseListener interface.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
Empty function - just for MouseListener interface.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
Empty function - just for MouseListener interface.

Specified by:
mouseReleased in interface java.awt.event.MouseListener