graphics
Class GraphicsEngine

java.lang.Object
  extended by graphics.GraphicsEngine

public class GraphicsEngine
extends java.lang.Object

GraphicsEngine class is responsible for rendering graphics viewed on screen. Class gets all information about program's state from DataColletion -class and it renders weather, planes and routes into one bufferedImage. GraphicsEngine uses Java 2D and buffered offScreen-images. Next frame will be rendered when buildNextFrame() -method is called. There are some tricks we have used when generating graphics. First of all, we render the main background image just when weather changes. Background image contains weather map, airport and arrival tree. When weather stays same, we just render airplanes and airplane paths on the top of old background. At the beginning we show the Chopper -logo. GraphicsEngine also takes care of loading public graphics from hard disk. This feature is rather used by window and JPanels.

Version:
1
Author:
Potkuri-group

Field Summary
private  java.awt.BasicStroke arcPoints
          Java 2D style for arc points.
private  java.awt.BasicStroke arrivalTree
          Java 2D style for arrival tree.
private  java.awt.Color colorArcPoints
          Render color for arc points.
private  java.awt.Color colorArrivalTree
          Render color for arrival tree.
private  DataCollection dataCollection
          Current instance of DataCollection- class.
private  java.awt.image.BufferedImage[] graphicsData
          Graphics which is used in window and JPanels.
private  double mountedLat
          Map latitude and longitude.
private  double mountedLon
          Map latitude and longitude.
private  java.awt.image.BufferedImage nextBufferedImage
          Rendered offScreen image.
private  java.awt.image.BufferedImage offScreenImage
          Working space for Java 2D.
private  java.awt.Image offScreenImage2
          Working space for Java 2D.
private  Parameters parameters
          Current instance of Parameters- class.
private  java.awt.BasicStroke planes
          Java 2D style for planes.
private  double relativeCornerPoint
          Relative point of corner.
private  boolean renderAirspace
          Shall we render airspace.
private  boolean renderArcPoints
          Shall we render arc points.
private  boolean renderArrivalTree
          Shall we render arc arrival tree.
private  boolean renderDebug
          Shall we render debug information.
private  boolean renderDebug2
          Shall we render debug information 2.
private  int renderMapHeight
          Render map height.
private  int renderMapWidth
          Render map width.
private  boolean renderPlaneAsTriangle
          Shall we render plane as triangle.
private  boolean renderPlanePath
          Shall we render plane path.
private  boolean renderWeatherMap
          Shall we render weather map.
private  double scale
          Scale is used to scout out different object to offScreen space.
private  boolean status
          Status is false until first offScreen image is ready.
 
Constructor Summary
GraphicsEngine(DataCollection dCollection)
          Construct new instance of GraphicsEngine-class.
 
Method Summary
 boolean buildNextFrame()
          Render next offScreen image into buffered offScreen -image.
private  void debugDrawGraph(java.awt.Graphics2D g2)
          This method is for debugging.
private  java.lang.String[] getDebugData()
          This method is for debugging.
 java.awt.image.BufferedImage getFrame()
          Returns next frame in bufferedImage.
 java.awt.image.BufferedImage getGraphics(int index)
          Returns asked graphics -object (bufferedImage).
 boolean getStatus()
          Returns current status of this instance.
private  void graphicsRenderAirport(java.awt.Graphics2D g2, Vertex root)
          Draw airport to offScreen image.
private  boolean graphicsRenderAirspace(java.awt.Graphics2D g2, java.util.ArrayList<Plane> planes)
          Render planes and plane paths to OffScreen- image.
private  void graphicsRenderArcPoints(java.awt.Graphics2D g2)
          Render arcPoints to OffScreen -image.
private  void graphicsRenderArrivalTree(java.awt.Graphics2D g2, TreeNode node)
          Method uses pre-order traversal to draw arrival tree into offScreen -image.
private  void graphicsRenderPlaneAsTriangle(java.awt.Graphics2D g2, int x, int y, double direction)
          Render a plane as a triangle.
private  void graphicsRenderRealArcPoints(java.awt.Graphics2D g2, java.util.ArrayList<Vertex>[] arcPoints)
          This method is for debugging.
private  void graphicsRenderStuff(java.awt.Graphics2D g2)
          This method is for debugging.
private  boolean loadCommonGraphics()
          Load media and graphics from hard disk.
private  java.awt.image.BufferedImage loadImage(java.lang.String filename)
          Returns BufferedImage or null if file doesn't exists.
 void setDebugMode(boolean mode)
          Set demo mode.
 void setDebugMode2()
          Set demo 2 mode.
 void takeSnapshot()
          Take snapshot and store it into media -directory defined in parameter class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

arcPoints

private java.awt.BasicStroke arcPoints
Java 2D style for arc points.


arrivalTree

private java.awt.BasicStroke arrivalTree
Java 2D style for arrival tree.


colorArcPoints

private java.awt.Color colorArcPoints
Render color for arc points.


colorArrivalTree

private java.awt.Color colorArrivalTree
Render color for arrival tree.


dataCollection

private DataCollection dataCollection
Current instance of DataCollection- class.


graphicsData

private java.awt.image.BufferedImage[] graphicsData
Graphics which is used in window and JPanels.


mountedLat

private double mountedLat
Map latitude and longitude.


mountedLon

private double mountedLon
Map latitude and longitude.


nextBufferedImage

private java.awt.image.BufferedImage nextBufferedImage
Rendered offScreen image.


offScreenImage

private java.awt.image.BufferedImage offScreenImage
Working space for Java 2D.


offScreenImage2

private java.awt.Image offScreenImage2
Working space for Java 2D.


parameters

private Parameters parameters
Current instance of Parameters- class.


planes

private java.awt.BasicStroke planes
Java 2D style for planes.


relativeCornerPoint

private double relativeCornerPoint
Relative point of corner.


renderAirspace

private boolean renderAirspace
Shall we render airspace.


renderArcPoints

private boolean renderArcPoints
Shall we render arc points.


renderArrivalTree

private boolean renderArrivalTree
Shall we render arc arrival tree.


renderDebug

private boolean renderDebug
Shall we render debug information.


renderDebug2

private boolean renderDebug2
Shall we render debug information 2.


renderMapHeight

private int renderMapHeight
Render map height.


renderMapWidth

private int renderMapWidth
Render map width.


renderPlaneAsTriangle

private boolean renderPlaneAsTriangle
Shall we render plane as triangle.


renderPlanePath

private boolean renderPlanePath
Shall we render plane path.


renderWeatherMap

private boolean renderWeatherMap
Shall we render weather map.


scale

private double scale
Scale is used to scout out different object to offScreen space.


status

private boolean status
Status is false until first offScreen image is ready.

Constructor Detail

GraphicsEngine

public GraphicsEngine(DataCollection dCollection)
Construct new instance of GraphicsEngine-class. Most of the render properties will be set from Parameter- class.

Parameters:
dCollection - Current DataCollection class.
Method Detail

buildNextFrame

public boolean buildNextFrame()
Render next offScreen image into buffered offScreen -image.

Returns:
succeed

debugDrawGraph

private void debugDrawGraph(java.awt.Graphics2D g2)
This method is for debugging. Draw vertexes to screen.

Parameters:
g2 - OffScreen space for Java 2D.

getDebugData

private java.lang.String[] getDebugData()
This method is for debugging. Test weather data.

Returns:
debugData

getFrame

public java.awt.image.BufferedImage getFrame()
Returns next frame in bufferedImage.

Returns:
next off-screen frame

getGraphics

public java.awt.image.BufferedImage getGraphics(int index)
Returns asked graphics -object (bufferedImage).

Parameters:
index - Graphics id.
Returns:
asked bufferedImage or null

getStatus

public final boolean getStatus()
Returns current status of this instance.

Returns:
status

graphicsRenderAirport

private void graphicsRenderAirport(java.awt.Graphics2D g2,
                                   Vertex root)
Draw airport to offScreen image.

Parameters:
g2 - Graphics space
root - Root vertex;

graphicsRenderAirspace

private boolean graphicsRenderAirspace(java.awt.Graphics2D g2,
                                       java.util.ArrayList<Plane> planes)
Render planes and plane paths to OffScreen- image. Note that we have to render all paths ready before planes, because otherwise some path could hide the plane by accident.

Parameters:
g2 - OffScreen space for Java 2D.
planes - ArrayList of planes.
Returns:
Render succeed.

graphicsRenderArcPoints

private void graphicsRenderArcPoints(java.awt.Graphics2D g2)
Render arcPoints to OffScreen -image.

Parameters:
g2 - OffScreen space for Java 2D.

graphicsRenderArrivalTree

private void graphicsRenderArrivalTree(java.awt.Graphics2D g2,
                                       TreeNode node)
Method uses pre-order traversal to draw arrival tree into offScreen -image. Method visit each node in a tree by recursively visiting each node in the left and right subtrees of the root.

Parameters:
g2 - OffScreen space for Java 2D.
node - Root node of tree.

graphicsRenderPlaneAsTriangle

private void graphicsRenderPlaneAsTriangle(java.awt.Graphics2D g2,
                                           int x,
                                           int y,
                                           double direction)
Render a plane as a triangle.

Parameters:
g2 - Graphics
x - X- coordinate
y - Y- coordinate
direction - Plane direction

graphicsRenderRealArcPoints

private void graphicsRenderRealArcPoints(java.awt.Graphics2D g2,
                                         java.util.ArrayList<Vertex>[] arcPoints)
This method is for debugging. Draw real arcPoints to OffScreen -image

Parameters:
g2 - OffScreen space for Java 2D.
arcPoints - ArrayList of arcPoints.

graphicsRenderStuff

private void graphicsRenderStuff(java.awt.Graphics2D g2)
This method is for debugging. Draw some information into offScreen-image

Parameters:
g2 - OffScreen space for Java 2D

loadCommonGraphics

private boolean loadCommonGraphics()
Load media and graphics from hard disk. JPanels uses this feature via getGraphics() -method.

Returns:
succeed

loadImage

private java.awt.image.BufferedImage loadImage(java.lang.String filename)
Returns BufferedImage or null if file doesn't exists.

Parameters:
filename - File path and name.
Returns:
BufferedImage

setDebugMode

public final void setDebugMode(boolean mode)
Set demo mode. This is for debugging with JUnit.

Parameters:
mode - Set debug mode.

setDebugMode2

public final void setDebugMode2()
Set demo 2 mode. This is for debugging with JUnit.


takeSnapshot

public void takeSnapshot()
Take snapshot and store it into media -directory defined in parameter class. This property is only for testing.