vanetsim.gui
Class DrawingArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by vanetsim.gui.DrawingArea
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseWheelListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener

public final class DrawingArea
extends javax.swing.JComponent
implements java.awt.event.MouseWheelListener, java.awt.event.KeyListener, java.awt.event.MouseListener

This class represents a JComponent on which all map elements are painted. It just creates the basic system which is needed, rendering itself is delegated to the Renderer-class!

See Also:
Renderer, 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.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
DrawingArea(boolean useDoubleBuffer, boolean drawManualBuffered)
          Constructor.
 
Method Summary
 void keyPressed(java.awt.event.KeyEvent e)
          Allows panning through pressing the keyboard arrows.
 void keyReleased(java.awt.event.KeyEvent e)
          Does nothing.
 void keyTyped(java.awt.event.KeyEvent e)
          Does nothing.
 void mouseClicked(java.awt.event.MouseEvent e)
          Does nothing.
 void mouseEntered(java.awt.event.MouseEvent e)
          Notifies the MouseDragManager that mouse entered this area.
 void mouseExited(java.awt.event.MouseEvent e)
          Notifies the MouseDragManager that mouse left this area.
 void mousePressed(java.awt.event.MouseEvent e)
          Tracks clicks in order to get focus and allow to get information about points on the map or edit something on the map.
 void mouseReleased(java.awt.event.MouseEvent e)
          Used for panning through mousedragging through the MousedragManager.
 void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
          Listener for mouse scrolls.
 void paintComponent(java.awt.Graphics g)
          This method gets automatically called on a repaint().
 void paintImmediately(int x, int y, int width, int height)
          Setting the RepaintManager like seen on the official examples for Java2D (link last time checked on 12.08.2008).
 void prepareBufferedImages()
          Prepares all BufferedImages and notifies the Renderer of a new drawing area size.
 void revalidate()
          This function gets called when a property value changes such that size, location or internal layout of change.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DrawingArea

public DrawingArea(boolean useDoubleBuffer,
                   boolean drawManualBuffered)
Constructor.

Parameters:
useDoubleBuffer - true to set DoubleBuffering on, false to set it off
drawManualBuffered - set to true to use a BufferdImage for drawing (manual DoubleBuffering)
Method Detail

paintComponent

public void paintComponent(java.awt.Graphics g)
This method gets automatically called on a repaint(). Therefore, rendering is delegated from here to the renderer.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the Graphics object to paint on

prepareBufferedImages

public void prepareBufferedImages()
Prepares all BufferedImages and notifies the Renderer of a new drawing area size.


revalidate

public void revalidate()
This function gets called when a property value changes such that size, location or internal layout of change. We then need to check if our BufferdImages still have the correct size and create new ones if needed!

Overrides:
revalidate in class javax.swing.JComponent

paintImmediately

public void paintImmediately(int x,
                             int y,
                             int width,
                             int height)
Setting the RepaintManager like seen on the official examples for Java2D (link last time checked on 12.08.2008).
This imitates the "On Screen" method used there and in some cases drastically improves performance (even when DoubleBuffering of this JComponent is off the DoubleBuffering might still be on because the DoubleBuffering is inherited from the main JFrame!).

Overrides:
paintImmediately in class javax.swing.JComponent
Parameters:
x - the x coordinate for the bounding box to repaint
y - the y coordinate for the bounding box to repaint
width - the width
height - the height

mouseWheelMoved

public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
Listener for mouse scrolls.

Specified by:
mouseWheelMoved in interface java.awt.event.MouseWheelListener
Parameters:
e - the MouseWheelEvent
See Also:
MouseWheelListener.mouseWheelMoved(java.awt.event.MouseWheelEvent)

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Does nothing. Just necessary to implement the KeyListener.

Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
e - the KeyEvent
See Also:
KeyListener.keyTyped(java.awt.event.KeyEvent)

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Allows panning through pressing the keyboard arrows.

Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
e - the KeyEvent
See Also:
KeyListener.keyPressed(java.awt.event.KeyEvent)

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Tracks clicks in order to get focus and allow to get information about points on the map or edit something on the map. The work itself is done in the MousedragManager.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the MouseEvent
See Also:
MouseListener.mousePressed(java.awt.event.MouseEvent)

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Used for panning through mousedragging through the MousedragManager.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the MouseEvent
See Also:
MouseListener.mouseReleased(java.awt.event.MouseEvent)

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Does nothing. Just necessary to implement the KeyListener.

Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
e - the KeyEvent
See Also:
KeyListener.keyReleased(java.awt.event.KeyEvent)

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Does nothing. Just necessary to implement the MouseListener.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the MouseEvent
See Also:
MouseListener.mouseClicked(java.awt.event.MouseEvent)

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Notifies the MouseDragManager that mouse entered this area.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the MouseEvent
See Also:
MouseListener.mouseEntered(java.awt.event.MouseEvent)

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Notifies the MouseDragManager that mouse left this area.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the MouseEvent
See Also:
MouseListener.mouseExited(java.awt.event.MouseEvent)