// **********************************************************************
//
//
* This class needs the RecordSet to be called with the following
* query:
* select CITY (string), STATE (string), GRAPHIC (string, url or
* graphic name), LATITUDE (float), LONGITUDE (float) from
* LOCATION_TABLE (tablename where data is stored)
* The class is expecting the results in this order.
*/
public class UnitData
extends LocationDataRecordImpl
{
public static String ATTRNAME_LAT = "Lattitude";
public static String ATTRNAME_LON = "Longitude";
/* variables that would hold current values of record set */
protected float speed, alt, heading;
protected String status, event, logtype;
protected java.sql.Timestamp fix_Time;
protected String fixtimestr, location;
protected int fixage;
public UnitData() {}
// ----------------------------------------------------------------
public static String[] getLatLonNameArr()
{
String[] retVal = new String[2];
if(retVal != null)
{
retVal[LocationDataFactory.IDX_LATNAME] = ATTRNAME_LAT;
retVal[LocationDataFactory.IDX_LONNAME] = ATTRNAME_LON;
}
return retVal;
}
// ----------------------------------------------------------------
public boolean load(RecordSet drs, LocationColorFormatter colfmt) throws SQLException
{
ResultSet rset = drs.getResultSet();
setRecID(rset.getInt("RecKey"));
StringBuffer tmpstrb = new StringBuffer();
String tmpstr = null;
try
{
tmpstrb.append(rset.getString("Name"));
} // try
catch (SQLException sqlE)
{
tmpstr = rset.getString("Radio_Number");
if(tmpstr != null)
{ tmpstrb.append(tmpstrb); }
tmpstr = rset.getString("Machine_Name");
if(tmpstr != null)
{ tmpstrb.append("[");
tmpstrb.append(tmpstr);
tmpstrb.append("]");
}
}
setDisplayName(tmpstrb.toString());
setLatitude(rset.getFloat(ATTRNAME_LAT));
setLongitude(rset.getFloat(ATTRNAME_LON));
//
status = rset.getString("Status");
event = rset.getString("Event");
speed= rset.getFloat("Speed");
alt= rset.getFloat("Altitude");
heading= rset.getFloat("Heading");
fix_Time = rset.getTimestamp("Fix_Time");
if(!rset.wasNull())
{ fixtimestr = fix_Time.toString();}
try
{
fixage = rset.getInt("Fix_Age");
if(!rset.wasNull())
{
if(fixtimestr != null && fixage < 24 * 60)
{ fixtimestr = fixtimestr.substring(11, 19); }
}
logtype = rset.getString("TZ");
if(!rset.wasNull())
{ fixtimestr += " "+logtype;}
logtype = rset.getString("Type");
location = rset.getString("Location");
} // try
catch (SQLException sqlE)
{ }
if(colfmt != null)
{ setLocationColors(colfmt, status); }
return true;
}
// ----------------------------------------------------------------
public String getStatus()
{
String retVal = status;
/* if(fix_Time != null)
{
fix_Time
}
*/ return retVal;
}
public char getUnitTypeCharacter()
{
char retVal = ' ';
if(logtype != null)
{ retVal = logtype.charAt(0); }
return retVal;
}
// ----------------------------------------------------------------
/**
* Description string
* @return String
*/
public String getDetails()
{
StringBuffer s = new StringBuffer();
if(location != null)
{s.append(" ").append(location);}
s.append(" @ "+fixtimestr +"( " + latitude + "," + longitude + ")");
s.append(" Head: " + getHeadingString(heading) + " @ " + speed +"Mph");
return s.toString();
}
// ----------------------------------------------------------------
/**
* Default output string
* @return String
*/
public String toString() {
return getDetails();
}
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// ----------------------------------------------------------------
/**
* Get the color used for the location graphic.
*/
public Color getLocationColor(Color defcolor)
{
LocationColorFormatter.LocColorEntry e = getColorFormatter();
Color retVal = defcolor;
if(e != null)
{ retVal = e.getColor(); }
if(retVal == null)
{retVal = defcolor;}
return retVal;
}
// ----------------------------------------------------------------
/**
* Get the color used for the label.
*/
public Color getLabelColor(Color defcolor)
{
LocationColorFormatter.LocColorEntry e = getColorFormatter();
Color retVal = defcolor;
if(e != null)
{ retVal = e.getColor(1); }
if(retVal == null)
{retVal = defcolor;}
return retVal;
}
// ----------------------------------------------------------------
public Image getLocationImage()
{
Image retVal = null;
LocationColorFormatter.LocColorEntry e = getColorFormatter();
if(e != null)
{
retVal = IconFactory.getImage(16, e.getColorName(0), e.getColor(0), getUnitTypeCharacter(), false);
}
return retVal;
}
////////////////////////////////////////////////////////////
public static void main(String args[])
{
Image ii = IconFactory.getImage(16, "Cyan", Color.CYAN, 'C');
// for(int i = 0; i < 361; i += 12)
// { System.out.println(i+" Degrees =>" + getHeadingString((float) i));}
}
////////////////////////////////////////////////////////////////////
/**
* Method: getHeadingString
* This method does...
* @param heading
* @param param2
* @return String
* @
*/
public static String getHeadingString(float heading)
{
String retVal = null;
int multiples = (int)(heading / 11.25);
float remainder = (float)(heading % 11.25);
switch(multiples)
{
case 31: // <348.75 Degrees
retVal = "NNW";
break;
case 32: // <360.0 Degrees
case 0: // <0.0 Degrees
retVal = "N";
break;
case 1: // <11.25 Degrees
case 2: // <22.5 Degrees
retVal = "NNE";
break;
case 3: // <33.75 Degrees
case 4: // <45.0 Degrees
retVal = "NE";
break;
case 5: // <56.25 Degrees
case 6: // <67.5 Degrees
retVal = "ENE";
break;
case 7: // <78.75 Degrees
case 8: // <90.0 Degrees
retVal = "E";
break;
case 9: // <101.25 Degrees
case 10: // <112.5 Degrees
retVal = "ESE";
break;
case 11: // <123.75 Degrees
case 12: // <135.0 Degrees
retVal = "SE";
break;
case 13: // <146.25 Degrees
case 14: // <157.5 Degrees
retVal = "SSE";
break;
case 15: // <168.75 Degrees
case 16: // <180.0 Degrees
retVal = "S";
break;
case 17: // <191.25 Degrees
case 18: // <202.5 Degrees
retVal = "SSW";
break;
case 19: // <213.75 Degrees
case 20: // <225.0 Degrees
retVal = "SW";
break;
case 21: // <236.25 Degrees
case 22: // <247.5 Degrees
retVal = "WSW";
break;
case 23: // <258.75 Degrees
case 24: // <270.0 Degrees
retVal = "W";
break;
case 25: // <281.25 Degrees
case 26: // <292.5 Degrees
retVal = "WNW";
break;
case 27: // <303.75 Degrees
case 28: // <315.0 Degrees
retVal = "NW";
break;
case 29: // <326.25 Degrees
case 30: // <337.5 Degrees
retVal = "NNW";
break;
}
return retVal;
}// Method: getHeadingString
}