net.sf.freecol.client.gui.panel
Class MiniMap

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 net.sf.freecol.client.gui.panel.MiniMap
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.MouseInputListener

public final class MiniMap
extends javax.swing.JPanel
implements javax.swing.event.MouseInputListener

This component draws a small version of the map. It allows us to see a larger part of the map and to relocate the viewport by clicking on it.

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  int adjustX
          Used for adjusting the position of the mapboard image.
private  int adjustY
          Used for adjusting the position of the mapboard image.
private  java.awt.Image back
           
private  java.awt.Color backgroundColor
           
private  int firstColumn
          The top left tile on the mini map represents the tile.
private  int firstRow
          The top left tile on the mini map represents the tile.
private  FreeColClient freeColClient
           
private static int GAP
           
private  GUI gui
           
private  int lastColumn
          The top left tile on the mini map represents the tile.
private  int lastRow
          The top left tile on the mini map represents the tile.
private static java.util.logging.Logger logger
           
private static int MAP_HEIGHT
           
private static int MAP_WIDTH
           
private  java.awt.Rectangle mapWindow
          The part of the panel that is used for the map.
static int MAX_TILE_SIZE
           
static int MIN_TILE_SIZE
           
private  javax.swing.JButton miniMapZoomInButton
           
private  javax.swing.JButton miniMapZoomOutButton
           
private  java.awt.Color newBackground
           
static int SCALE_STEP
           
private  java.awt.Image skin
           
private  int tileSize
           
private  boolean useSkin
           
 
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
MiniMap(FreeColClient freeColClient, GUI gui)
          The constructor that will initialize this component.
MiniMap(FreeColClient freeColClient, GUI gui, boolean useSkin)
          The constructor that will initialize this component.
 
Method Summary
 boolean canZoomIn()
          Return true if tile size can be decreased.
 boolean canZoomOut()
          Return true if tile size can be increased.
private  void focus(int x, int y)
           
private  void focus(java.awt.event.MouseEvent e)
           
 java.awt.Color getBackgroundColor()
           
private  java.awt.Color getMinimapColor(TileType type)
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
          If the user clicks on the mini map, refocus the map to center on the tile that he clicked on
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void paintComponent(java.awt.Graphics graphics)
          Paints this component.
 void paintMap(java.awt.Graphics graphics, int width, int height)
          Paints a representation of the mapboard onto this component.
 void setBackgroundColor(java.awt.Color backgroundColor)
           
 void setTileSize(int size)
          Set tile size to the given value, or the minimum or maximum bound of the tile size.
private  void setZoomOption(int tileSize)
           
 void zoomIn()
          Zooms in the mini map.
 void zoomOut()
          Zooms out the mini map.
 
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, 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
 
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, getName, 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, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

MAX_TILE_SIZE

public static final int MAX_TILE_SIZE
See Also:
Constant Field Values

MIN_TILE_SIZE

public static final int MIN_TILE_SIZE
See Also:
Constant Field Values

SCALE_STEP

public static final int SCALE_STEP
See Also:
Constant Field Values

MAP_WIDTH

private static final int MAP_WIDTH
See Also:
Constant Field Values

MAP_HEIGHT

private static final int MAP_HEIGHT
See Also:
Constant Field Values

GAP

private static final int GAP
See Also:
Constant Field Values

mapWindow

private final java.awt.Rectangle mapWindow
The part of the panel that is used for the map. If a skin is used, this is smaller than the whole panel.


freeColClient

private FreeColClient freeColClient

miniMapZoomOutButton

private final javax.swing.JButton miniMapZoomOutButton

miniMapZoomInButton

private final javax.swing.JButton miniMapZoomInButton

backgroundColor

private java.awt.Color backgroundColor

back

private java.awt.Image back

skin

private java.awt.Image skin

newBackground

private java.awt.Color newBackground

useSkin

private boolean useSkin

tileSize

private int tileSize

firstColumn

private int firstColumn
The top left tile on the mini map represents the tile. (firstColumn, firstRow) in the world map


firstRow

private int firstRow
The top left tile on the mini map represents the tile. (firstColumn, firstRow) in the world map


lastColumn

private int lastColumn
The top left tile on the mini map represents the tile. (firstColumn, firstRow) in the world map


lastRow

private int lastRow
The top left tile on the mini map represents the tile. (firstColumn, firstRow) in the world map


adjustX

private int adjustX
Used for adjusting the position of the mapboard image.

See Also:
paintMap(java.awt.Graphics, int, int)

adjustY

private int adjustY
Used for adjusting the position of the mapboard image.

See Also:
paintMap(java.awt.Graphics, int, int)

gui

private GUI gui
Constructor Detail

MiniMap

public MiniMap(FreeColClient freeColClient,
               GUI gui)
The constructor that will initialize this component.

Parameters:
freeColClient - The main controller object for the client
gui - a GUI value

MiniMap

public MiniMap(FreeColClient freeColClient,
               GUI gui,
               boolean useSkin)
The constructor that will initialize this component.

Parameters:
freeColClient - The main controller object for the client
gui - a GUI value
Method Detail

zoomIn

public void zoomIn()
Zooms in the mini map.


zoomOut

public void zoomOut()
Zooms out the mini map.


setTileSize

public void setTileSize(int size)
Set tile size to the given value, or the minimum or maximum bound of the tile size.

Parameters:
size - an int value

canZoomIn

public boolean canZoomIn()
Return true if tile size can be decreased.

Returns:
a boolean value

canZoomOut

public boolean canZoomOut()
Return true if tile size can be increased.

Returns:
a boolean value

setZoomOption

private void setZoomOption(int tileSize)

paintComponent

public void paintComponent(java.awt.Graphics graphics)
Paints this component.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
graphics - The Graphics context in which to draw this component.

getMinimapColor

private java.awt.Color getMinimapColor(TileType type)

paintMap

public void paintMap(java.awt.Graphics graphics,
                     int width,
                     int height)
Paints a representation of the mapboard onto this component.

Parameters:
graphics - The Graphics context in which to draw this component.
width - The width of the map.
height - The height of the map.

focus

private void focus(int x,
                   int y)

focus

private void focus(java.awt.event.MouseEvent e)

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
If the user clicks on the mini map, refocus the map to center on the tile that he clicked on

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - a MouseEvent value

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

getBackgroundColor

public java.awt.Color getBackgroundColor()

setBackgroundColor

public void setBackgroundColor(java.awt.Color backgroundColor)