com.realtime.crossfire.jxclient.gui.map
Class AbstractGUIMap

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.realtime.crossfire.jxclient.gui.gui.GUIElement
                  extended by com.realtime.crossfire.jxclient.gui.map.AbstractGUIMap
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
GUIMap, GUIMiniMap

public abstract class AbstractGUIMap
extends GUIElement

Abstract base class for GUIElements that display map views.

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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  int displayMaxOffsetX
          The number of pixels that are visible in the rightmost visible tile.
private  int displayMaxOffsetY
          The number of pixels that are visible in the bottommost visible tile.
private  int displayMaxX
          The tile x coordinate where map drawing ends.
private  int displayMaxY
          The tile y coordinate where map drawing ends.
private  int displayMinOffsetX
          The distance the leftmost visible tile reaches outside the map window.
private  int displayMinOffsetY
          The distance the topmost visible tile reaches outside the map window.
private  int displayMinX
          The tile x coordinate where map drawing starts.
private  int displayMinY
          The tile y coordinate where map drawing starts.
private  FacesProvider facesProvider
          The FacesProvider for looking up faces.
private  java.util.Map<java.awt.Color,java.awt.Image> images
          Maps Color to an image filled with this color with a size of one square.
private  int mapHeight
          The map height in squares.
private  MapListener mapListener
          The MapListener registered to receive map updates.
private  MapScrollListener mapscrollListener
          The MapScrollListener registered to receive map_scroll commands.
private  MapSizeListener mapSizeListener
          The MapSizeListener registered to detect map size changes.
private  CfMapUpdater mapUpdater
          The CfMapUpdater instance to display.
private  int mapWidth
          The map width in squares.
private  NewmapListener newmapListener
          The NewmapListener registered to receive newmap commands.
private  int offsetX
          The x offset for drawing the square at coordinate 0 of the map.
private  int offsetY
          The y offset for drawing the square at coordinate 0 of the map.
private  int playerX
          The x offset of the tile representing the player.
private  int playerY
          The y offset of the tile representing the player.
private static long serialVersionUID
          The serial version UID.
private  int tileSize
          The size of one tile.
 
Fields inherited from class com.realtime.crossfire.jxclient.gui.gui.GUIElement
bufferedImageSync
 
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
protected AbstractGUIMap(TooltipManager tooltipManager, GUIElementListener elementListener, java.lang.String name, Extent extent, CfMapUpdater mapUpdater, FacesProvider facesProvider)
          Creates a new instance.
 
Method Summary
 void dispose()
          Releases all allocated resources.
protected  int getMapHeight()
          Returns the map height in squares.
protected  int getMapWidth()
          Returns the map width in squares.
 int getOffsetX()
          Returns the x offset for drawing the square at coordinate 0 of the map.
 int getOffsetY()
          Returns the y offset for drawing the square at coordinate 0 of the map.
 int getPlayerX()
          Returns the x offset of the tile representing the player.
 int getPlayerY()
          Returns the y offset of the tile representing the player.
protected abstract  void markPlayer(java.awt.Graphics g, int dx, int dy)
          Paints the player location.
protected  void paintColoredSquare(java.awt.Graphics g, java.awt.Color color, int x, int y)
          Fills a square with one Color.
private  void paintImage(java.awt.Graphics g, Face face, int px, int py, int offsetX, int offsetY)
          Paints a face into a tile.
protected abstract  void paintSquareBackground(java.awt.Graphics g, int px, int py, boolean hasImage, CfMapSquare mapSquare)
          Paints the background of a map square.
private  void redrawAll()
          Redraws the complete map view.
private  void redrawAllUnlessDirty(java.awt.Graphics g, CfMap map)
          Redraws all non-dirty tiles.
protected  void redrawSquare(java.awt.Graphics g, CfMapSquare mapSquare, int x, int y)
          Redraws one square.
private  void redrawSquare(java.awt.Graphics g, int x, int y, CfMapSquare mapSquare)
          Redraws one layer of a square.
private  void redrawSquareUnlessDirty(java.awt.Graphics g, CfMap map, int x, int y)
          Redraws one square if it is not dirty.
private  void redrawTiles(java.awt.Graphics g, CfMap map, int x0, int y0, int x1, int y1)
          Redraws a rectangular area of tiles.
private  void redrawTilesUnlessDirty(java.awt.Graphics g, CfMap map, int x0, int y0, int x1, int y1)
          Redraws a rectangular area of non-dirty tiles.
protected  void render(java.awt.Graphics2D g2)
          Paints the element's contents into the passed graphics.
private  void setMapSize(int mapWidth, int mapHeight)
          Sets the map size.
 void updateResolution(int screenWidth, int screenHeight)
          Updates the location and size to a new screen resolution.
private  void updateScrolledMap(java.awt.Graphics g, int dx, int dy)
          Updates the map display after the map contents have scrolled.
 
Methods inherited from class com.realtime.crossfire.jxclient.gui.gui.GUIElement
createBufferGraphics, getElementX, getElementY, getGui, getName, getTooltipText, hasBufferedImage, isChanged, isDefault, isElementAtPoint, isElementVisible, isIgnore, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, paintComponent, resetChanged, setChanged, setChangedListener, setChangedNoListeners, setDefault, setElementLocation, setElementSize, setElementVisible, setGui, setIgnore, setTooltipText, setTooltipText, toString, updateResolutionConstant
 
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, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, 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, 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, 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, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

displayMaxOffsetX

private int displayMaxOffsetX
The number of pixels that are visible in the rightmost visible tile. 0<=displayMaxOffsetX<tileSize.


displayMaxOffsetY

private int displayMaxOffsetY
The number of pixels that are visible in the bottommost visible tile. 0<=displayMaxOffsetY<tileSize.


displayMaxX

private int displayMaxX
The tile x coordinate where map drawing ends. May be less than mapWidth if the map view is larger than the gui's area.


displayMaxY

private int displayMaxY
The tile y coordinate where map drawing ends. May be less than mapWidth if the map view is larger than the gui's area.


displayMinOffsetX

private int displayMinOffsetX
The distance the leftmost visible tile reaches outside the map window. -tileSize.


displayMinOffsetY

private int displayMinOffsetY
The distance the topmost visible tile reaches outside the map window. -tileSize.


displayMinX

private int displayMinX
The tile x coordinate where map drawing starts. May be positive if the map view is larger than the gui's area.


displayMinY

private int displayMinY
The tile y coordinate where map drawing starts. May be positive if the map view is larger than the gui's area.


facesProvider

@NotNull
private final FacesProvider facesProvider
The FacesProvider for looking up faces.


images

@NotNull
private final java.util.Map<java.awt.Color,java.awt.Image> images
Maps Color to an image filled with this color with a size of one square.


mapHeight

private int mapHeight
The map height in squares.


mapListener

@NotNull
private final MapListener mapListener
The MapListener registered to receive map updates.


mapscrollListener

@NotNull
private final MapScrollListener mapscrollListener
The MapScrollListener registered to receive map_scroll commands.


mapSizeListener

@NotNull
private final MapSizeListener mapSizeListener
The MapSizeListener registered to detect map size changes.


mapUpdater

@NotNull
private final CfMapUpdater mapUpdater
The CfMapUpdater instance to display.


mapWidth

private int mapWidth
The map width in squares.


newmapListener

@NotNull
private final NewmapListener newmapListener
The NewmapListener registered to receive newmap commands.


offsetX

private int offsetX
The x offset for drawing the square at coordinate 0 of the map.


offsetY

private int offsetY
The y offset for drawing the square at coordinate 0 of the map.


playerX

private int playerX
The x offset of the tile representing the player.


playerY

private int playerY
The y offset of the tile representing the player.


serialVersionUID

private static final long serialVersionUID
The serial version UID.

See Also:
Constant Field Values

tileSize

private final int tileSize
The size of one tile.

Constructor Detail

AbstractGUIMap

protected AbstractGUIMap(@NotNull
                         TooltipManager tooltipManager,
                         @NotNull
                         GUIElementListener elementListener,
                         @NotNull
                         java.lang.String name,
                         @NotNull
                         Extent extent,
                         @NotNull
                         CfMapUpdater mapUpdater,
                         @NotNull
                         FacesProvider facesProvider)
Creates a new instance.

Parameters:
tooltipManager - the tooltip manager to update
elementListener - the element listener to notify
name - the name of this element
extent - the extent of this element
mapUpdater - the map updater instance to use
facesProvider - the faces provider for looking up faces
Method Detail

dispose

public void dispose()
Releases all allocated resources.

Overrides:
dispose in class GUIElement

getMapHeight

protected int getMapHeight()
Returns the map height in squares.

Returns:
the map height

getMapWidth

protected int getMapWidth()
Returns the map width in squares.

Returns:
the map width

getOffsetX

public int getOffsetX()
Returns the x offset for drawing the square at coordinate 0 of the map.

Returns:
the x offset

getOffsetY

public int getOffsetY()
Returns the y offset for drawing the square at coordinate 0 of the map.

Returns:
the y offset

getPlayerX

public int getPlayerX()
Returns the x offset of the tile representing the player.

Returns:
the x offset

getPlayerY

public int getPlayerY()
Returns the y offset of the tile representing the player.

Returns:
the y offset

markPlayer

protected abstract void markPlayer(@NotNull
                                   java.awt.Graphics g,
                                   int dx,
                                   int dy)
Paints the player location.

Parameters:
g - the graphics to paint to
dx - the x distance to map has just scrolled
dy - the y distance to map has just scrolled

paintColoredSquare

protected void paintColoredSquare(@NotNull
                                  java.awt.Graphics g,
                                  @NotNull
                                  java.awt.Color color,
                                  int x,
                                  int y)
Fills a square with one Color.

Parameters:
g - the graphics to paint into
color - the color
x - the x-coordinate
y - the y-coordinate

paintImage

private void paintImage(@NotNull
                        java.awt.Graphics g,
                        @NotNull
                        Face face,
                        int px,
                        int py,
                        int offsetX,
                        int offsetY)
Paints a face into a tile.

Parameters:
g - the graphics to draw into
face - the face to draw
px - the x coordinate of the square to redraw
py - the y coordinate of the square to redraw
offsetX - the x-offset for shifting the original face
offsetY - the y-offset for shifting the original face

paintSquareBackground

protected abstract void paintSquareBackground(@NotNull
                                              java.awt.Graphics g,
                                              int px,
                                              int py,
                                              boolean hasImage,
                                              @NotNull
                                              CfMapSquare mapSquare)
Paints the background of a map square.

Parameters:
g - the graphics to paint into
px - the x-offset for painting
py - the y-offset for painting
hasImage - whether the square contains at least one image
mapSquare - the map square

redrawAll

private void redrawAll()
Redraws the complete map view.


redrawAllUnlessDirty

private void redrawAllUnlessDirty(@NotNull
                                  java.awt.Graphics g,
                                  @NotNull
                                  CfMap map)
Redraws all non-dirty tiles.

Parameters:
g - the graphics to draw into
map - the map

redrawSquare

protected void redrawSquare(@NotNull
                            java.awt.Graphics g,
                            @NotNull
                            CfMapSquare mapSquare,
                            int x,
                            int y)
Redraws one square.

Parameters:
g - the graphics to draw into
mapSquare - the map square to draw
x - the x-coordinate of the map tile to redraw
y - the y-coordinate of the map tile to redraw

redrawSquare

private void redrawSquare(@NotNull
                          java.awt.Graphics g,
                          int x,
                          int y,
                          @NotNull
                          CfMapSquare mapSquare)
Redraws one layer of a square.

Parameters:
g - the graphics to draw into
x - the x coordinate of the square to redraw
y - the y coordinate of the square to redraw
mapSquare - the map square

redrawSquareUnlessDirty

private void redrawSquareUnlessDirty(@NotNull
                                     java.awt.Graphics g,
                                     @NotNull
                                     CfMap map,
                                     int x,
                                     int y)
Redraws one square if it is not dirty. This function is called for tiles that need to be repainted due to scrolling. Skipping dirty squares prevents multiple repainting.

Parameters:
g - the graphics to draw into
map - the map to draw
x - the x-coordinate of the square to clear
y - the y-coordinate of the square to clear

redrawTiles

private void redrawTiles(@NotNull
                         java.awt.Graphics g,
                         @NotNull
                         CfMap map,
                         int x0,
                         int y0,
                         int x1,
                         int y1)
Redraws a rectangular area of tiles.

Parameters:
g - the graphics to draw into
map - the map to draw
x0 - the left edge to redraw (inclusive)
y0 - the top edge to redraw (inclusive)
x1 - the right edge to redraw (exclusive)
y1 - the bottom edge to redraw (exclusive)

redrawTilesUnlessDirty

private void redrawTilesUnlessDirty(@NotNull
                                    java.awt.Graphics g,
                                    @NotNull
                                    CfMap map,
                                    int x0,
                                    int y0,
                                    int x1,
                                    int y1)
Redraws a rectangular area of non-dirty tiles.

Parameters:
g - the graphics to draw into
map - the map to draw
x0 - the left edge to redraw (inclusive)
y0 - the top edge to redraw (inclusive)
x1 - the right edge to redraw (exclusive)
y1 - the bottom edge to redraw (exclusive)

render

protected void render(@NotNull
                      java.awt.Graphics2D g2)
Paints the element's contents into the passed graphics.

Specified by:
render in class GUIElement
Parameters:
g2 - the graphics to paint to

setMapSize

private void setMapSize(int mapWidth,
                        int mapHeight)
Sets the map size.

Parameters:
mapWidth - the map width in squares
mapHeight - the map height in squares

updateResolution

public void updateResolution(int screenWidth,
                             int screenHeight)
Updates the location and size to a new screen resolution.

Overrides:
updateResolution in class GUIElement
Parameters:
screenWidth - the new screen width
screenHeight - the new screen height

updateScrolledMap

private void updateScrolledMap(@NotNull
                               java.awt.Graphics g,
                               int dx,
                               int dy)
Updates the map display after the map contents have scrolled.

Parameters:
g - the graphics to update
dx - the x-distance
dy - the y-distance