edu.trinity.cs.gamecore
Class MainDisplay<B extends Block<B,E>,E extends GameEntity<B,E>>

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 edu.trinity.cs.gamecore.MainDisplay<B,E>
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
EditorDisplay

public class MainDisplay<B extends Block<B,E>,E extends GameEntity<B,E>>
extends javax.swing.JPanel

This class is the panel on which the action part of the game is rendered. At each tick, this panel is repainted with the contents of the screen that is in the location for the local player as returned by GameSetup.getLocalPlayer. This uses the scrolling and optimize options specified by GameSetup. The only method that should really be used from the outside is getClickLocation. You could also call setForceDraw, but that can also be achieved by turning the draw optimization off for one tick in the GameSetup.

This class is a generic that takes the general block type and the general entity type for each game.

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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  Screen<B,E> lastScreen
           
protected  int sizex
           
protected  int sizey
           
 
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 MainDisplay(GameSetup<B,E> gs)
           
  MainDisplay(MainFrame<B,E> mf)
          This mainly figures out what size this panel should "prefer" to be.
 
Method Summary
 void draw(Player<B,E> player)
          Draw the display assuming the player passed in.
 Location<B,E> getClickLocation(int x, int y)
          This function does a conversion from display coordinates to the locations coordinates in the screen that it is displaying.
 int getDrawX(Location<B,E> loc)
          This function tells you the physical display x for a given location on the screen.
 int getDrawY(Location<B,E> loc)
          This function tells you the physical display y for a given location on the screen.
 java.awt.Dimension getPreferredSize()
          Returns the size that this display would be without any scaling for the drawing options it was first set up to use.
 void paintComponent(java.awt.Graphics g)
          Renders the image drawn by the draw method to the provided Graphics object.
 void setForceDraw()
          Tell the display that at the next draw call (typically the next tick) that it must redraw all of the blocks for the background and can't use a buffered image.
 
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

lastScreen

protected Screen<B extends Block<B,E>,E extends GameEntity<B,E>> lastScreen

sizex

protected int sizex

sizey

protected int sizey
Constructor Detail

MainDisplay

public MainDisplay(MainFrame<B,E> mf)
This mainly figures out what size this panel should "prefer" to be.


MainDisplay

protected MainDisplay(GameSetup<B,E> gs)
Method Detail

draw

public void draw(Player<B,E> player)
Draw the display assuming the player passed in.

Parameters:
player - This is the player whose location is used for the drawing.

paintComponent

public void paintComponent(java.awt.Graphics g)
Renders the image drawn by the draw method to the provided Graphics object. This is automatically called by the GUI framework and should generally not be called by user code.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - The graphics object to render to.

setForceDraw

public void setForceDraw()
Tell the display that at the next draw call (typically the next tick) that it must redraw all of the blocks for the background and can't use a buffered image.


getClickLocation

public Location<B,E> getClickLocation(int x,
                                      int y)
This function does a conversion from display coordinates to the locations coordinates in the screen that it is displaying. When you get a MouseEvent you can pass the getX() and getY() values from it into this and it will return the Location of the click.

Parameters:
x - The physical display x location.
y - The physical display y location.
Returns:
The location that corresponds to the physical location that was passed in.

getDrawX

public int getDrawX(Location<B,E> loc)
This function tells you the physical display x for a given location on the screen. This is used for drawing and shouldn't need to be called from external code.

Parameters:
loc - The Location you are interested in.
Returns:
The x physical display position for that location.

getDrawY

public int getDrawY(Location<B,E> loc)
This function tells you the physical display y for a given location on the screen. This is used for drawing and shouldn't need to be called from external code.

Parameters:
loc - The Location you are interested in.
Returns:
The y physical display position for that location.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the size that this display would be without any scaling for the drawing options it was first set up to use. This is used by the GUI.

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
The size that this "wants" to be so there isn't scaling.