public abstract class AbstractGUIMap extends AbstractGUIElement
GUIElements
that display map
views.javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
private boolean |
avoidCopyArea
Whether map scrolling is done by copying pixel areas.
|
private java.awt.image.BufferedImage |
bufferedImage
An
BufferedImage having the size of this component. |
private java.lang.Object |
bufferedImageSync
|
private boolean |
clearMapPending
Whether the map area should be blanked.
|
private DarknessColors |
darknessColors
The
DarknessColors instance for converting darkness values into
colors. |
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 MapUpdaterState |
mapUpdaterState
The
MapUpdaterState 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 java.util.Deque<java.lang.Long> |
scrollMapPending
Pending map scrolls.
|
private static long |
serialVersionUID
The serial version UID.
|
private SmoothingRenderer |
smoothingRenderer
The
SmoothingRenderer to use or null to not draw smoothed
faces. |
private int |
tileSize
The size of one tile.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Modifier | Constructor and Description |
---|---|
protected |
AbstractGUIMap(boolean avoidCopyArea,
TooltipManager tooltipManager,
GUIElementListener elementListener,
java.lang.String name,
MapUpdaterState mapUpdaterState,
FacesProvider facesProvider,
SmoothingRenderer smoothingRenderer,
DarknessColors darknessColors)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
private void |
clearMap(java.awt.Graphics2D g)
Blanks the map display.
|
private java.awt.Graphics2D |
createBufferGraphics(CfMap map)
Returns a
Graphics instance for painting into bufferedImage . |
void |
dispose()
Releases all allocated resources.
|
protected int |
getMapHeight()
Returns the map height in squares.
|
protected int |
getMapWidth()
Returns the map width in squares.
|
java.awt.Dimension |
getMinimumSize() |
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 . |
void |
paintComponent(java.awt.Graphics g) |
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,
CfMap map,
int x,
int y)
Redraws one square.
|
private void |
redrawSquare(java.awt.Graphics g,
int x,
int y,
CfMapSquare mapSquare,
CfMap map)
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.
|
void |
setBounds(int x,
int y,
int width,
int height) |
private void |
setMapSize(int mapWidth,
int mapHeight)
Sets the map size.
|
private void |
updateScrolledMap(java.awt.Graphics g,
CfMap map,
int dx,
int dy)
Updates the map display after the map contents have scrolled.
|
getName, hasTooltipText, isDefault, isIgnore, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, setChanged, setChangedListener, setDefault, setIgnore, setTooltipText, setTooltipText, toString
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, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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
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
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, getAccessibleContext, 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, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
private final boolean avoidCopyArea
@Nullable private transient java.awt.image.BufferedImage bufferedImage
BufferedImage
having the size of this component. It contains
the rendered map contents.@NotNull private final java.lang.Object bufferedImageSync
private boolean clearMapPending
@NotNull private final DarknessColors darknessColors
DarknessColors
instance for converting darkness values into
colors.private int displayMaxOffsetX
0<=displayMaxOffsetX<tileSize
.private int displayMaxOffsetY
0<=displayMaxOffsetY<tileSize
.private int displayMaxX
mapWidth
if the map view is larger than the gui's area.private int displayMaxY
mapWidth
if the map view is larger than the gui's area.private int displayMinOffsetX
-tileSize<displayMinOffsetX<=0
.private int displayMinOffsetY
-tileSize<displayMinOffsetX<=0
.private int displayMinX
private int displayMinY
@NotNull private final FacesProvider facesProvider
FacesProvider
for looking up faces.@NotNull private final java.util.Map<java.awt.Color,java.awt.Image> images
Color
to an image filled with this color with a size of one
square.private int mapHeight
@NotNull private final MapListener mapListener
MapListener
registered to receive map updates.@NotNull private final MapScrollListener mapscrollListener
MapScrollListener
registered to receive map_scroll commands.@NotNull private final MapSizeListener mapSizeListener
MapSizeListener
registered to detect map size changes.@NotNull private final MapUpdaterState mapUpdaterState
MapUpdaterState
instance to display.private int mapWidth
@NotNull private final NewmapListener newmapListener
NewmapListener
registered to receive newmap commands.private int offsetX
private int offsetY
private int playerX
private int playerY
@NotNull private final java.util.Deque<java.lang.Long> scrollMapPending
private static final long serialVersionUID
@Nullable private final SmoothingRenderer smoothingRenderer
SmoothingRenderer
to use or null
to not draw smoothed
faces.private final int tileSize
protected AbstractGUIMap(boolean avoidCopyArea, @NotNull TooltipManager tooltipManager, @NotNull GUIElementListener elementListener, @NotNull java.lang.String name, @NotNull MapUpdaterState mapUpdaterState, @NotNull FacesProvider facesProvider, @Nullable SmoothingRenderer smoothingRenderer, @NotNull DarknessColors darknessColors)
avoidCopyArea
- whether map scrolling is done by copying pixel
areas; if unset, always repaint all map squarestooltipManager
- the tooltip manager to updateelementListener
- the element listener to notifyname
- the name of this elementmapUpdaterState
- the map updater state instance to usefacesProvider
- the faces provider for looking up facessmoothingRenderer
- the smoothing renderer to use or null
to
not draw smoothed facesdarknessColors
- the darkness colors instance for converting
darkness values into colorsprivate void clearMap(@NotNull java.awt.Graphics2D g)
g
- the graphics to paint to@NotNull private java.awt.Graphics2D createBufferGraphics(@NotNull CfMap map)
Graphics
instance for painting into bufferedImage
. The returned value must be freed by calling Graphics.dispose()
on the returned instance.map
- the map instance that is painted; must hold the lockpublic void dispose()
dispose
in interface GUIElement
dispose
in class AbstractGUIElement
protected int getMapHeight()
protected int getMapWidth()
@Nullable public java.awt.Dimension getMinimumSize()
getMinimumSize
in class javax.swing.JComponent
public int getOffsetX()
public int getOffsetY()
public int getPlayerX()
public int getPlayerY()
protected abstract void markPlayer(@NotNull java.awt.Graphics g, int dx, int dy)
g
- the graphics to paint todx
- the x distance to map has just scrolleddy
- the y distance to map has just scrolledprotected void paintColoredSquare(@NotNull java.awt.Graphics g, @NotNull java.awt.Color color, int x, int y)
Color
.g
- the graphics to paint intocolor
- the colorx
- the x-coordinatey
- the y-coordinatepublic void paintComponent(@NotNull java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
private void paintImage(@NotNull java.awt.Graphics g, @NotNull Face face, int px, int py, int offsetX, int offsetY)
g
- the graphics to draw intoface
- the face to drawpx
- the x coordinate of the square to redrawpy
- the y coordinate of the square to redrawoffsetX
- the x-offset for shifting the original faceoffsetY
- the y-offset for shifting the original faceprotected abstract void paintSquareBackground(@NotNull java.awt.Graphics g, int px, int py, boolean hasImage, @NotNull CfMapSquare mapSquare)
g
- the graphics to paint intopx
- the x-offset for paintingpy
- the y-offset for paintinghasImage
- whether the square contains at least one imagemapSquare
- the map squareprivate void redrawAll()
private void redrawAllUnlessDirty(@NotNull java.awt.Graphics g, @NotNull CfMap map)
g
- the graphics to draw intomap
- the mapprotected void redrawSquare(@NotNull java.awt.Graphics g, @NotNull CfMapSquare mapSquare, @NotNull CfMap map, int x, int y)
g
- the graphics to draw intomapSquare
- the map square to drawmap
- the mapx
- the x-coordinate of the map tile to redrawy
- the y-coordinate of the map tile to redrawprivate void redrawSquare(@NotNull java.awt.Graphics g, int x, int y, @NotNull CfMapSquare mapSquare, @NotNull CfMap map)
g
- the graphics to draw intox
- the x coordinate of the square to redrawy
- the y coordinate of the square to redrawmapSquare
- the map squaremap
- the mapprivate void redrawSquareUnlessDirty(@NotNull java.awt.Graphics g, @NotNull CfMap map, int x, int y)
g
- the graphics to draw intomap
- the map to drawx
- the x-coordinate of the square to cleary
- the y-coordinate of the square to clearprivate void redrawTiles(@NotNull java.awt.Graphics g, @NotNull CfMap map, int x0, int y0, int x1, int y1)
g
- the graphics to draw intomap
- the map to drawx0
- 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)private void redrawTilesUnlessDirty(@NotNull java.awt.Graphics g, @NotNull CfMap map, int x0, int y0, int x1, int y1)
g
- the graphics to draw intomap
- the map to drawx0
- 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)public void setBounds(int x, int y, int width, int height)
setBounds
in class java.awt.Component
private void setMapSize(int mapWidth, int mapHeight)
mapWidth
- the map width in squaresmapHeight
- the map height in squaresprivate void updateScrolledMap(@NotNull java.awt.Graphics g, @NotNull CfMap map, int dx, int dy)
g
- the graphics to updatemap
- the map to scroll; must hold the lockdx
- the x-distancedy
- the y-distance