com.ibexconsulting.demonstration
Class SunCalculation

java.lang.Object
  |
  +--com.ibexconsulting.demonstration.SunCalculation

public class SunCalculation
extends java.lang.Object

This class is used to calculate the sunrise, sunset, and day length for a given latitude. If told to support a graph it will generate these facts for the entire year at one time and store the values in an array of sun facts. This allows the graph to be painted more efficiently when requested. The class is designed so it can be used independently of the SunStuff applet sample. All latitudes are in degrees and converted internally to radians for calculations. Effects related to longitude, time zone, and daylight savings time are ignored as well as marginal effects related to the year not being exactly 365 days long.


Constructor Summary
SunCalculation()
          Creates a new sun calculation class.
SunCalculation(double TrialLatitude)
          Creates a new sun calculation class.
SunCalculation(double TrialLatitude, boolean SupportsGraph)
          Creates a new sun calculation class.
 
Method Summary
 java.util.Calendar getCalendarInstance()
           
 java.lang.String getDate()
           
 java.lang.String getDayLength()
           
 int getDayofYear()
           
 int getDayofYearMaximum()
           
 java.awt.Image getGraphImage(javax.swing.JComponent Component)
          Paints a graph of the total hours of sunlight for the entire year onto a swing component.
 double getLatitude()
           
 java.lang.String getSunRise()
           
 java.lang.String getSunSet()
           
 void setDate(java.util.Date TrialDate)
          Sets the trial date.
 void setDate(int DayofYear)
          Sets the trial date.
 void setLatitude(double TrialLatitude)
          Sets the trial latitude.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SunCalculation

public SunCalculation()
Creates a new sun calculation class. The latitude is defaulted to 49.1 and there is no graph support.

SunCalculation

public SunCalculation(double TrialLatitude)
Creates a new sun calculation class. There is no graph support.
Parameters:
TrialLatitude - The initial latitude in degrees.

SunCalculation

public SunCalculation(double TrialLatitude,
                      boolean SupportsGraph)
Creates a new sun calculation class.
Parameters:
TrialLatitude - The initial latitude in degrees.
SupportsGraph - Defines whether the class can be used to draw a graph inside a swing component. If true is selected, the sunrise, sunset, and hours in the day are calculated for the entire year whenever the latitude is changed. If false is selected than the getGraphImage will return a null every call.
See Also:
getGraphImage(JComponent Component)
Method Detail

getCalendarInstance

public java.util.Calendar getCalendarInstance()
Returns:
Clone of the current Calendar used inside the class.

getDate

public java.lang.String getDate()
Returns:
The current trial date in the format of 'MMM d'

getDayLength

public java.lang.String getDayLength()
Returns:
The length of the trial date in the format of 'HH:mm'

getDayofYear

public int getDayofYear()
Returns:
The day number of the current year represented by the current trial date.

getDayofYearMaximum

public int getDayofYearMaximum()
Returns:
The total number of days in the current year.

getLatitude

public double getLatitude()
Returns:
The current trial latitude in degrees

getGraphImage

public java.awt.Image getGraphImage(javax.swing.JComponent Component)
Paints a graph of the total hours of sunlight for the entire year onto a swing component. This function should be called within the paint method of that component. Will support a component of any size. If the SunCalculation object was constructed without graph support than this method will always return a null for the image.
Parameters:
The - swing JComponent object
Returns:
The graph image
See Also:
SunCalculation(double TrialLatitude, boolean SupportsGraph)

getSunRise

public java.lang.String getSunRise()
Returns:
The time of the sun rise on the trial date in the format of 'h:mm a'. If the sun does not rise the value of 'n/a' will be returned.

getSunSet

public java.lang.String getSunSet()
Returns:
The time of the sun set on the trial date in the format of 'h:mm a'. If the sun does not rise the value of 'n/a' will be returned.

setDate

public void setDate(int DayofYear)
Sets the trial date.
Parameters:
The - day number of the current year.

setDate

public void setDate(java.util.Date TrialDate)
Sets the trial date.
Parameters:
Date - object.

setLatitude

public void setLatitude(double TrialLatitude)
                 throws java.lang.Exception
Sets the trial latitude.
Parameters:
Latitude - in degrees
Throws:
java.lang.Exception - if TrialLatitude is not in the range of -90 to +90 degrees.