edu.ohiou.cs456_badabing.sceneapi.exec
Class ViewPanel

java.lang.Object
  extended by GLJPanel
      extended by edu.ohiou.cs456_badabing.sceneapi.exec.ViewPanel
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.lang.Runnable, java.util.EventListener

public class ViewPanel
extends GLJPanel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.lang.Runnable, java.awt.event.KeyListener, java.awt.event.MouseWheelListener

OpenGL accelerated panel that renders 3D visualization data.

Description: extends GLJPanel and renders Map. Responds to user interaction.

Copyright: Copyright (c) 2008, Lev A Neiman

Company: Ohio University EECS


Nested Class Summary
private  class ViewPanel.zoomerInner
          inner class to handle zooming in stuff.
 
Field Summary
(package private)  java.util.HashMap<java.awt.Color,java.lang.String> color2name
          mapping of RGB color to county name.
 GLContext context
          GLContext of this panel.
private  int cur_m_button
          mouse button that was pressed.
private  boolean enable_transperency
          if this is false then transperency is disabled.
private  boolean enable_transperency_p
          previouis value for enable_transperency.
 int frames
          frame counter.
private  LightNode light
          handle to light source.
private  MainUIPanel main_panel
          handle to MainUIPanel
 Map map
          handle to Map
private static double max_radius
          the radius of the Sphere representing the county with largest deer harvest.
(package private)  java.lang.Thread measure_fps
          handle to thread that measures and prints out FPS info.
private static double min_radius
          the radius of the Sphere representing the county with smallest deer harvest.
private  int mX
          x position of last mouse move.
private  int mY
          y position of the last mouse move.
(package private)  java.util.HashMap<java.lang.String,java.awt.Color> name2color
          mapping of county name to RGB color
private  int num_inits
          how many times has this panel been re-initialized.
 java.lang.Thread render_thread
          handle to thread that calls display() continuously.
 boolean should_display
           
private  boolean should_update
          if this is switched to true, ViewPanel will attempt to read DataBaseModel from MainUIPanel and update Spheres and PieCharts accordingly.
private static double xdisp
          x position of camera.
private static double xtilt
          xtilt of the camera.
private static double ydisp
          y position of camera.
private static double ytilt
          ytilt of the camera.
private static double zdisp
          z position of camera (how close is it to the map?).
private  ViewPanel.zoomerInner zooming
          handle to the zoomerInner object.
 
Constructor Summary
ViewPanel(MainUIPanel main_panel)
          default constructor.
 
Method Summary
private  void addSM(java.lang.String name, java.awt.Color color)
          add county name to RGB color mapping.
 void changeTransperency(int transperency)
          set a new Transperency.
 void display(GLAutoDrawable gLDrawable)
          render ViewPanel.
 void displayChanged(GLAutoDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)
           
private  java.awt.Color getColor(int x, int y)
          return the color at x, y position on the screen.
 Map getMap()
          return handle to Map object.
 void init(GLAutoDrawable gLDrawable)
          Set up our scene.
 double interpolate(double y1, double y2, double t1, double t2, long ti)
          Interpolation function between (t1, y1) and (t2, y2).
private  void jbInit()
          adds some event listeners.
 void keyPressed(java.awt.event.KeyEvent k)
           
 void keyReleased(java.awt.event.KeyEvent k)
           
 void keyTyped(java.awt.event.KeyEvent k)
           
 void mouseClicked(java.awt.event.MouseEvent e)
          on mouse Clicked event.
 void mouseDragged(java.awt.event.MouseEvent e)
          on mouse dragged.
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
          on mouse moved.
 void mousePressed(java.awt.event.MouseEvent e)
          on mouse pressed.
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
          handle mouse wheel events.
 void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height)
          calls when ViewPanel is being reshaped.
 void run()
          run method for rendering thread.
private  java.lang.String selectCounty()
          method to select county based on the color that is at mX, mY position.
 void setTransperency(boolean transp)
          set whether transperency should be used or not.
 boolean takeScreenshot(java.io.File file, java.lang.String format)
          saves the screen shot of the color buffer into file in some format.
 void triggerUpdate()
          triggers ViewPanel to update sizes of Spheres and PieCharts
private  void update()
          Updates all objects in map to reflect information from DataBaseModel and current year.
 void updateDeerTuple(DeerTuple info)
          take a deer Tuple
 void zoomDefault()
          zoom in to default view.
 void zoomIn()
          zoom in a little bit.
 void zoomIn(java.lang.String county_name)
          causes ViewPanel to zoom in on selected county.
 void zoomOut()
          zoom out a little bit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

zooming

private ViewPanel.zoomerInner zooming
handle to the zoomerInner object. When it is not null the display method calls its step() method and checks whether it is done or not.
If it is null then display method doesnt call it.


measure_fps

java.lang.Thread measure_fps
handle to thread that measures and prints out FPS info.


frames

public int frames
frame counter.


main_panel

private MainUIPanel main_panel
handle to MainUIPanel


map

public Map map
handle to Map


light

private LightNode light
handle to light source.


mX

private int mX
x position of last mouse move.


mY

private int mY
y position of the last mouse move.


xdisp

private static double xdisp
x position of camera.


ydisp

private static double ydisp
y position of camera.


zdisp

private static double zdisp
z position of camera (how close is it to the map?).


xtilt

private static double xtilt
xtilt of the camera.


ytilt

private static double ytilt
ytilt of the camera.


cur_m_button

private int cur_m_button
mouse button that was pressed.


render_thread

public java.lang.Thread render_thread
handle to thread that calls display() continuously.


context

public GLContext context
GLContext of this panel.


num_inits

private int num_inits
how many times has this panel been re-initialized.


name2color

java.util.HashMap<java.lang.String,java.awt.Color> name2color
mapping of county name to RGB color


color2name

java.util.HashMap<java.awt.Color,java.lang.String> color2name
mapping of RGB color to county name.


should_update

private boolean should_update
if this is switched to true, ViewPanel will attempt to read DataBaseModel from MainUIPanel and update Spheres and PieCharts accordingly.


enable_transperency_p

private boolean enable_transperency_p
previouis value for enable_transperency.


enable_transperency

private boolean enable_transperency
if this is false then transperency is disabled. otherwise it is enabled.


min_radius

private static final double min_radius
the radius of the Sphere representing the county with smallest deer harvest.

See Also:
Constant Field Values

max_radius

private static final double max_radius
the radius of the Sphere representing the county with largest deer harvest.

See Also:
Constant Field Values

should_display

public boolean should_display
Constructor Detail

ViewPanel

public ViewPanel(MainUIPanel main_panel)
default constructor.

Parameters:
main_panel - MainUIPanel
Method Detail

interpolate

public double interpolate(double y1,
                          double y2,
                          double t1,
                          double t2,
                          long ti)
Interpolation function between (t1, y1) and (t2, y2). takes those input plus ti and reterns yi.

Parameters:
y1 - double
y2 - double
t1 - double
t2 - double
ti - long
Returns:
double

setTransperency

public void setTransperency(boolean transp)
set whether transperency should be used or not.

Parameters:
transp - boolean

addSM

private void addSM(java.lang.String name,
                   java.awt.Color color)
add county name to RGB color mapping.

Parameters:
name - String
color - Color

triggerUpdate

public void triggerUpdate()
triggers ViewPanel to update sizes of Spheres and PieCharts


updateDeerTuple

public void updateDeerTuple(DeerTuple info)
take a deer Tuple


update

private void update()
Updates all objects in map to reflect information from DataBaseModel and current year.


getMap

public Map getMap()
return handle to Map object.

Returns:
Map

zoomIn

public void zoomIn()
zoom in a little bit.


zoomOut

public void zoomOut()
zoom out a little bit.


display

public void display(GLAutoDrawable gLDrawable)
render ViewPanel.

Parameters:
gLDrawable - GLAutoDrawable

displayChanged

public void displayChanged(GLAutoDrawable gLDrawable,
                           boolean modeChanged,
                           boolean deviceChanged)

init

public void init(GLAutoDrawable gLDrawable)
Set up our scene.

Parameters:
gLDrawable - GLAutoDrawable

reshape

public void reshape(GLAutoDrawable gLDrawable,
                    int x,
                    int y,
                    int width,
                    int height)
calls when ViewPanel is being reshaped.

Parameters:
gLDrawable - GLAutoDrawable
x - int
y - int
width - int
height - int

changeTransperency

public void changeTransperency(int transperency)
set a new Transperency.

Parameters:
transperency - int

jbInit

private void jbInit()
             throws java.lang.Exception
adds some event listeners.

Throws:
java.lang.Exception

mouseExited

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

mouseEntered

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

mouseReleased

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

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
on mouse pressed.

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

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
on mouse Clicked event. Does the zoom in, zoom out stuff.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - MouseEvent

zoomIn

public void zoomIn(java.lang.String county_name)
causes ViewPanel to zoom in on selected county.

Parameters:
county_name - String

zoomDefault

public void zoomDefault()
zoom in to default view.


getColor

private java.awt.Color getColor(int x,
                                int y)
return the color at x, y position on the screen. this is used for selection.

Parameters:
x - int
y - int
Returns:
Color

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
on mouse moved. update mX and mY, and do selectCounty().

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - MouseEvent

selectCounty

private java.lang.String selectCounty()
method to select county based on the color that is at mX, mY position. Get that color and then return its mapping to county name.

Returns:
String

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
on mouse dragged. moves the map on left mouse button, and rotates it on right mouse button.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - MouseEvent

mouseWheelMoved

public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
handle mouse wheel events.

Specified by:
mouseWheelMoved in interface java.awt.event.MouseWheelListener
Parameters:
e - MouseWheelEvent

keyReleased

public void keyReleased(java.awt.event.KeyEvent k)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent k)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent k)
Specified by:
keyTyped in interface java.awt.event.KeyListener

run

public void run()
run method for rendering thread.

Specified by:
run in interface java.lang.Runnable

takeScreenshot

public boolean takeScreenshot(java.io.File file,
                              java.lang.String format)
saves the screen shot of the color buffer into file in some format.

Parameters:
file - File
format - String
Returns:
boolean