jfreerails.client.view
Class MapViewJComponentConcrete

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 jfreerails.client.view.MapViewJComponent
                      extended by jfreerails.client.view.MapViewJComponentConcrete
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable, ModelRootListener, MapLayerRenderer, MapRenderer

public final class MapViewJComponentConcrete
extends MapViewJComponent
implements ModelRootListener

Displays the map, the cursor, and user messages (which are stored on the ModelRoot under the keys QUICK_MESSAGE and PERMANENT_MESSAGE).

Author:
Luke Lindsay
See Also:
Serialized Form

Nested Class Summary
private  class MapViewJComponentConcrete.MapViewJComponentMouseAdapter
          Implements a MouseListener for FreerailsCursor-movement (left mouse button) and a MouseMotionListener for map-scrolling (right mouse button).
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  long displayMessageUntil
          Time at which to stop displaying the current user message.
private  int GRANULARITY
          Affects the granularity of the map scrolling (the map is scrolled in tileSize/GRANULARITY intervals).
private static java.awt.Font LARGE_MESSAGE_FONT
           
private  int LINEAR_ACCEL
          Affects scroll direction and scroll speed relative to the cursor.
private  FreerailsCursor mapCursor
           
private  java.lang.String message
          Message that will appear in the middle of the screen in LARGE_MESSAGE_FONT.
private static java.awt.Robot robot
          A Robot to compensate mouse cursor movement.
private static long serialVersionUID
           
private static java.awt.Font USER_MESSAGE_FONT
           
private  java.lang.String[] userMessage
          The length of the array is the number of lines.
 
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
MapViewJComponentConcrete()
           
 
Method Summary
 FreerailsCursor getMapCursor()
           
protected  void paintComponent(java.awt.Graphics g)
           
 void paintRect(java.awt.Graphics g, java.awt.Rectangle visibleRect)
           
 void paintTile(java.awt.Graphics g, int tileX, int tileY)
           
private  void println(java.lang.String s)
           
 void propertyChange(ModelRoot.Property p, java.lang.Object before, java.lang.Object after)
          Checks what triggered the specfied PropertyChangeEvent and reacts as follows.
private  void react2curorMove(ImPoint newPoint, ImPoint oldPoint)
           
 void refreshAll()
           
 void refreshTile(int x, int y)
           
 void setup(MapRenderer mv)
           
 void setup(MapRenderer mv, ModelRootImpl mr, RenderersRoot rr)
           
 
Methods inherited from class jfreerails.client.view.MapViewJComponent
centerOnTile, getMapSizeInPixels, getMapView, getPreferredScrollableViewportSize, getPreferredSize, getScale, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, setMapView
 
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, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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, transferFocusBackward, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

USER_MESSAGE_FONT

private static final java.awt.Font USER_MESSAGE_FONT

LARGE_MESSAGE_FONT

private static final java.awt.Font LARGE_MESSAGE_FONT

userMessage

private java.lang.String[] userMessage
The length of the array is the number of lines. This is necessary since Graphics.drawString(..) doesn't know about newline characters


message

private java.lang.String message
Message that will appear in the middle of the screen in LARGE_MESSAGE_FONT.


displayMessageUntil

private long displayMessageUntil
Time at which to stop displaying the current user message.


mapCursor

private FreerailsCursor mapCursor

LINEAR_ACCEL

private final int LINEAR_ACCEL
Affects scroll direction and scroll speed relative to the cursor. Examples:

1 := grab map, move 1:1

-2 := invert mouse, scroll twice as fast

See Also:
Constant Field Values

GRANULARITY

private final int GRANULARITY
Affects the granularity of the map scrolling (the map is scrolled in tileSize/GRANULARITY intervals). Multiply this value with LINEAR_ACCEL to be independent of acceleration.

See Also:
Constant Field Values

robot

private static java.awt.Robot robot
A Robot to compensate mouse cursor movement.

Constructor Detail

MapViewJComponentConcrete

public MapViewJComponentConcrete()
Method Detail

paintComponent

protected void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class MapViewJComponent

setup

public void setup(MapRenderer mv,
                  ModelRootImpl mr,
                  RenderersRoot rr)
           throws java.io.IOException
Throws:
java.io.IOException

setup

public void setup(MapRenderer mv)

react2curorMove

private void react2curorMove(ImPoint newPoint,
                             ImPoint oldPoint)

paintTile

public void paintTile(java.awt.Graphics g,
                      int tileX,
                      int tileY)
Specified by:
paintTile in interface MapLayerRenderer

refreshTile

public void refreshTile(int x,
                        int y)
Specified by:
refreshTile in interface MapLayerRenderer

refreshAll

public void refreshAll()
Specified by:
refreshAll in interface MapLayerRenderer

paintRect

public void paintRect(java.awt.Graphics g,
                      java.awt.Rectangle visibleRect)
Specified by:
paintRect in interface MapLayerRenderer

getMapCursor

public FreerailsCursor getMapCursor()

println

private void println(java.lang.String s)

propertyChange

public void propertyChange(ModelRoot.Property p,
                           java.lang.Object before,
                           java.lang.Object after)
Checks what triggered the specfied PropertyChangeEvent and reacts as follows.

(1) If it was ModelRoot.CURSOR_POSITION, scrolls the map if necessary.

(2) If it was ModelRoot.QUICK_MESSAGE, display or hide the message as appropriate.

(3) If it was ModelRoot.PERMANENT_MESSAGE, display or hide the message as appropriate.

Specified by:
propertyChange in interface ModelRootListener