cz.cuni.pogamut.server
Class MapVisualizationPanel

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 cz.cuni.pogamut.server.MapVisualizationPanel
All Implemented Interfaces:
RcvMsgListener, UTServerConnectionInterface, FlagListener<UTServerState>, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class MapVisualizationPanel
extends javax.swing.JPanel
implements UTServerConnectionInterface, RcvMsgListener, FlagListener<UTServerState>

Component for visualization of the map for UT2004. It needs UTWorld instance for getting the information and after that it is handled autonomously ... It will draw only bots that are connected through the UTWorld instance.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  UTServerConnection connection
           
private  GameInfo gameInfo
           
private  UTServerInfoSnapshot info
           
private  boolean initialized
           
private  java.util.logging.Logger log
           
private  double[] mapExtens
          Contains minX, minY, maxX, maxY of the navpoints coords.
private  boolean mapsExtensCounted
          Flag whether mapExtens have been counted.
private static int MAX_X
           
private static int MAX_Y
           
private static int MAX_Z
           
private static int MIN_X
           
private static int MIN_Y
           
private static int MIN_Z
           
private  java.util.List<NavPoint> navPoints
           
private  java.util.Map<java.lang.String,NavPoint> navPointsMap
           
private  java.util.Map<java.lang.String,Player> players
           
private  java.util.logging.Logger rawGBLog
           
private  Flag<UTServerState> serverState
           
private  boolean serverUp
          Flag whether server is up.
private  java.net.URI serverURI
           
private  UTWorld ut
           
private  java.util.concurrent.CountDownLatch waitNavPoints
           
private  int xBorder
          Border for drawing.
private  double xLength
          mapExtens[MAX_X] - mapExtens[MIN_X]
private  double xScale
          Scale x-double from UT2004 to pixel on the map.
private  int xSize
          X-size of the map on the panel int pixels.
private  int yBorder
          Border for drawing.
private  double yLength
          mapExtens[MAX_Y] - mapExtens[MIN_Y]
private  double yScale
          Scale y-double from UT2004 to pixel on the map.
private  int ySize
          Y-size of the map on the panel int pixels.
private  double zLength
          mapExtens[MAX_Z] - mapExtens[MIN_Z]
private  double zScale
          Scale y-double from UT2004 to pixel on the map.
private  int zSize
          Y-size of the map on the panel int pixels.
 
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
MapVisualizationPanel(java.net.URI serverURI)
           
 
Method Summary
private  void addPlayer(PlayerJoinsGame p)
           
private  void clearMapInfo()
           
private  void countMapExtens(java.util.List<NavPoint> navPoints)
           
 void flagChanged(UTServerState changedValue, int listenerParam)
          When registering the flag you may additionally specify listener parameter, if you do so - your listener will be called with that parameter.
 int getAutoReconnectMillis()
           
 MessageType getExpectedWelcomeMessage()
          Which message we should expect as the greeting from GameBots?
 java.net.URI getGamebotsControlConnectionURI()
           
 GameInfo getGameInfo()
           
 UTServerInfoSnapshot getInfo()
          Must NOT return null !!!
 java.util.logging.Logger getLog()
           
 java.util.List<NavPoint> getNavPointsBlocking()
           
private  int[] getPoint(double[] xyz)
          Input is the point from the real data from the server, then it is scaled down to the xSize,ySize of the map in pixels according xLength and yLength
 int getPongTimeoutMillis()
           
 java.util.logging.Logger getRawGBLog()
          Which log should be used to dump raw GB data.
 UTServerState getServerState()
           
 Flag<UTServerState> getServerStateFlag()
           
 java.util.concurrent.CountDownLatch getWaitInventoryLatch()
           
 java.util.concurrent.CountDownLatch getWaitItemsLatch()
           
 java.util.concurrent.CountDownLatch getWaitMapsLatch()
           
 java.util.concurrent.CountDownLatch getWaitNavPointsLatch()
           
 java.util.concurrent.CountDownLatch getWaitRefreshInfoLatch()
           
private  double[] getXYZ_UT(Triple location)
           
private  void init()
          Method called for the initialization of the map.
 boolean isAutomaticallyReconnect()
          Whether we should automaticly try to reconnect.
 boolean isPingPong()
          Whether we should check whether the connection is active.
static void main(java.lang.String[] args)
           
protected  void paintComponent(java.awt.Graphics g)
           
private  void paintDebug(java.awt.Graphics g)
           
private  void paintNavPoints(java.awt.Graphics g)
           
private  void paintPlayer(java.awt.Graphics g, Player pl)
           
private  void paintPlayers(java.awt.Graphics g)
           
private  void paintServerDown(java.awt.Graphics g)
           
private  void paintServerUp(java.awt.Graphics g)
           
private  void processNavPoints(java.util.List<NavPoint> navPoints)
           
 void receiveMessage(RcvMsgEvent e)
           
private  void recountScales()
           
private  void removePlayer(PlayerLeft p)
           
private  void requestNavPoints()
           
 void setGameInfo(GameInfo info)
           
 void setMapSize(int x, int y)
           
 void terminate()
          Will stop the communication with the server.
 void tryToRefresh()
           
private  void updatePlayer(Player p)
           
 boolean waitForNFOMessageInHandshake()
          Whether we should wait for NFO message after READY is sent.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, 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, paintImmediately, paintImmediately, 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
 
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

MIN_X

private static final int MIN_X
See Also:
Constant Field Values

MAX_X

private static final int MAX_X
See Also:
Constant Field Values

MIN_Y

private static final int MIN_Y
See Also:
Constant Field Values

MAX_Y

private static final int MAX_Y
See Also:
Constant Field Values

MIN_Z

private static final int MIN_Z
See Also:
Constant Field Values

MAX_Z

private static final int MAX_Z
See Also:
Constant Field Values

ut

private UTWorld ut

log

private java.util.logging.Logger log

rawGBLog

private java.util.logging.Logger rawGBLog

initialized

private boolean initialized

serverURI

private java.net.URI serverURI

connection

private UTServerConnection connection

info

private UTServerInfoSnapshot info

gameInfo

private GameInfo gameInfo

serverState

private Flag<UTServerState> serverState

players

private java.util.Map<java.lang.String,Player> players

navPoints

private java.util.List<NavPoint> navPoints

navPointsMap

private java.util.Map<java.lang.String,NavPoint> navPointsMap

waitNavPoints

private java.util.concurrent.CountDownLatch waitNavPoints

mapExtens

private double[] mapExtens
Contains minX, minY, maxX, maxY of the navpoints coords.


xLength

private double xLength
mapExtens[MAX_X] - mapExtens[MIN_X]


yLength

private double yLength
mapExtens[MAX_Y] - mapExtens[MIN_Y]


zLength

private double zLength
mapExtens[MAX_Z] - mapExtens[MIN_Z]


xScale

private double xScale
Scale x-double from UT2004 to pixel on the map.


yScale

private double yScale
Scale y-double from UT2004 to pixel on the map.


zScale

private double zScale
Scale y-double from UT2004 to pixel on the map.


xSize

private int xSize
X-size of the map on the panel int pixels.


ySize

private int ySize
Y-size of the map on the panel int pixels.


zSize

private int zSize
Y-size of the map on the panel int pixels. Maximal radius of the navpoint.


xBorder

private int xBorder
Border for drawing.


yBorder

private int yBorder
Border for drawing.


mapsExtensCounted

private boolean mapsExtensCounted
Flag whether mapExtens have been counted.


serverUp

private boolean serverUp
Flag whether server is up.

Constructor Detail

MapVisualizationPanel

public MapVisualizationPanel(java.net.URI serverURI)
Method Detail

init

private void init()
Method called for the initialization of the map.


processNavPoints

private void processNavPoints(java.util.List<NavPoint> navPoints)

requestNavPoints

private void requestNavPoints()

terminate

public void terminate()
Will stop the communication with the server.


getAutoReconnectMillis

public int getAutoReconnectMillis()
Specified by:
getAutoReconnectMillis in interface UTServerConnectionInterface

waitForNFOMessageInHandshake

public boolean waitForNFOMessageInHandshake()
Description copied from interface: UTServerConnectionInterface
Whether we should wait for NFO message after READY is sent.

Specified by:
waitForNFOMessageInHandshake in interface UTServerConnectionInterface
Returns:

getExpectedWelcomeMessage

public MessageType getExpectedWelcomeMessage()
Description copied from interface: UTServerConnectionInterface
Which message we should expect as the greeting from GameBots?

Specified by:
getExpectedWelcomeMessage in interface UTServerConnectionInterface

getGameInfo

public GameInfo getGameInfo()
Specified by:
getGameInfo in interface UTServerConnectionInterface

getInfo

public UTServerInfoSnapshot getInfo()
Description copied from interface: UTServerConnectionInterface
Must NOT return null !!! We're synchronizing access to info through this object.

Specified by:
getInfo in interface UTServerConnectionInterface
Returns:

getLog

public java.util.logging.Logger getLog()
Specified by:
getLog in interface UTServerConnectionInterface

getPongTimeoutMillis

public int getPongTimeoutMillis()
Specified by:
getPongTimeoutMillis in interface UTServerConnectionInterface

getRawGBLog

public java.util.logging.Logger getRawGBLog()
Description copied from interface: UTServerConnectionInterface
Which log should be used to dump raw GB data.

Specified by:
getRawGBLog in interface UTServerConnectionInterface

getServerState

public UTServerState getServerState()
Specified by:
getServerState in interface UTServerConnectionInterface

getServerStateFlag

public Flag<UTServerState> getServerStateFlag()
Specified by:
getServerStateFlag in interface UTServerConnectionInterface

getGamebotsControlConnectionURI

public java.net.URI getGamebotsControlConnectionURI()
Specified by:
getGamebotsControlConnectionURI in interface UTServerConnectionInterface

getWaitInventoryLatch

public java.util.concurrent.CountDownLatch getWaitInventoryLatch()
Specified by:
getWaitInventoryLatch in interface UTServerConnectionInterface

getWaitItemsLatch

public java.util.concurrent.CountDownLatch getWaitItemsLatch()
Specified by:
getWaitItemsLatch in interface UTServerConnectionInterface

getWaitMapsLatch

public java.util.concurrent.CountDownLatch getWaitMapsLatch()
Specified by:
getWaitMapsLatch in interface UTServerConnectionInterface

getWaitNavPointsLatch

public java.util.concurrent.CountDownLatch getWaitNavPointsLatch()
Specified by:
getWaitNavPointsLatch in interface UTServerConnectionInterface

getWaitRefreshInfoLatch

public java.util.concurrent.CountDownLatch getWaitRefreshInfoLatch()
Specified by:
getWaitRefreshInfoLatch in interface UTServerConnectionInterface

isAutomaticallyReconnect

public boolean isAutomaticallyReconnect()
Description copied from interface: UTServerConnectionInterface
Whether we should automaticly try to reconnect.

Specified by:
isAutomaticallyReconnect in interface UTServerConnectionInterface

isPingPong

public boolean isPingPong()
Description copied from interface: UTServerConnectionInterface
Whether we should check whether the connection is active.

Specified by:
isPingPong in interface UTServerConnectionInterface

setGameInfo

public void setGameInfo(GameInfo info)
Specified by:
setGameInfo in interface UTServerConnectionInterface

getNavPointsBlocking

public java.util.List<NavPoint> getNavPointsBlocking()

tryToRefresh

public void tryToRefresh()

receiveMessage

public void receiveMessage(RcvMsgEvent e)
Specified by:
receiveMessage in interface RcvMsgListener

addPlayer

private void addPlayer(PlayerJoinsGame p)

removePlayer

private void removePlayer(PlayerLeft p)

updatePlayer

private void updatePlayer(Player p)

countMapExtens

private void countMapExtens(java.util.List<NavPoint> navPoints)

recountScales

private void recountScales()

setMapSize

public void setMapSize(int x,
                       int y)

getXYZ_UT

private double[] getXYZ_UT(Triple location)

getPoint

private int[] getPoint(double[] xyz)
Input is the point from the real data from the server, then it is scaled down to the xSize,ySize of the map in pixels according xLength and yLength

Parameters:
xyz - ... double[3] ... xyz, xyz[0] == x, xyz[1] == y, xyz[2] == z
Returns:
int[3], x,y,z(radius) of pixels

paintNavPoints

private void paintNavPoints(java.awt.Graphics g)

paintPlayer

private void paintPlayer(java.awt.Graphics g,
                         Player pl)

paintPlayers

private void paintPlayers(java.awt.Graphics g)

paintDebug

private void paintDebug(java.awt.Graphics g)

paintServerUp

private void paintServerUp(java.awt.Graphics g)

paintServerDown

private void paintServerDown(java.awt.Graphics g)

paintComponent

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

clearMapInfo

private void clearMapInfo()

flagChanged

public void flagChanged(UTServerState changedValue,
                        int listenerParam)
Description copied from interface: FlagListener
When registering the flag you may additionally specify listener parameter, if you do so - your listener will be called with that parameter. Note that we purposefully denying OOP paradigm here. 'listenerParam' will allow you to implement this interface only once for more flags at the cost of switch(listenerParam){} ... but imagine that you have 4 objects which all register 4 different flag listeners (it would be a bit messy, wouldn't it).

Specified by:
flagChanged in interface FlagListener<UTServerState>

main

public static void main(java.lang.String[] args)