location
Class LocationServer

java.lang.Object
  extended bylocation.LocationServer
All Implemented Interfaces:
java.util.EventListener, GpsInfoListener, LocationListener, java.io.Serializable

public class LocationServer
extends java.lang.Object
implements java.io.Serializable, LocationListener, GpsInfoListener

LocationServer is the singleton that applications implementing the LocationListener interface register on to receive location information. The LocationServer obtains location information from a LocationGenerator. The LocationGenerator used can be specified by the user using the setLocationGenerator(...) method prior to booting the LocationServer. Once the LocationServer has been booted, the LocationGenerator it is using cannot be changed.

Two LocationGenerators are provided within a subpackage called location.generators. They are: FakeGPSMonitor and RealGPSMonitor. The FakeGPSMonitor provides a graphical user interface that allows the user to "move" around. The RealGPSMonitor reads data from a real GPS unit connected to the serial port.

Additional LocationGenerators may be defined by third parties by implementing the LocationGenerator interface.

The LocationServer supports two types of listeners: LocationListener and GpsInfoListener. A LocationListener is informed of location information, while a GpsInfoListener is informed of GPS status such as the number of satellites.

Version:
3.0
Author:
Chien-Liang Fok
See Also:
GpsInfoEvent, LocationEvent, LocationListener, GpsInfoListener, Serialized Form

Field Summary
private  boolean booted
          Keeps track of whether this server has been booted.
private  java.util.Vector gps_listeners
          Holds the listeners that are registered on this server.
private  LocationGenerator lg
          The LocationGenerator that provides the location.
private  java.util.Vector listeners
          Holds the listeners that are registered on this server.
private static LocationServer server
          This is the singleton LocationServer.
 
Constructor Summary
private LocationServer()
          Creates a LocationServer.
 
Method Summary
 void addGpsInfoListener(GpsInfoListener gpsinfo)
          Adds a GpsInfoListener to this server.
 void addLocationListener(LocationListener ll)
          Adds a LocationListener to this server.
 void boot()
          Boots the Location Server.
private  void distributeInfo(GpsInfoEvent gpsinfo)
           
private  void distributeLocation(LocationEvent le)
           
static LocationServer getServer()
          Returns the LocationServer singleton.
 boolean isBooted()
          Returns true if the location server is booted.
 void locationChanged(LocationEvent le)
          This implements the locationlistener interface.
 void newGpsInfo(GpsInfoEvent gpsinfo)
          This implements the GpsInfolistener interface.
 void removeGpsInfoListener(GpsInfoListener gpsinfo)
          Removes a GpsInfoListener from this server.
 void removeLocationListener(LocationListener ll)
          Removes a LocationListener from this server.
 void setLocationGenerator(LocationGenerator lg)
          Sets the location generated used by this LocationServer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lg

private LocationGenerator lg
The LocationGenerator that provides the location.


server

private static final LocationServer server
This is the singleton LocationServer.


booted

private boolean booted
Keeps track of whether this server has been booted.


listeners

private java.util.Vector listeners
Holds the listeners that are registered on this server.


gps_listeners

private java.util.Vector gps_listeners
Holds the listeners that are registered on this server.

Constructor Detail

LocationServer

private LocationServer()
Creates a LocationServer.

Method Detail

setLocationGenerator

public void setLocationGenerator(LocationGenerator lg)
Sets the location generated used by this LocationServer. This should only be called prior to booting the LocationServer.


locationChanged

public void locationChanged(LocationEvent le)
This implements the locationlistener interface. It is called by the location generator whenever the generator has a new location to report.

Specified by:
locationChanged in interface LocationListener
Parameters:
le - the new location event.

distributeLocation

private void distributeLocation(LocationEvent le)

newGpsInfo

public void newGpsInfo(GpsInfoEvent gpsinfo)
This implements the GpsInfolistener interface. It is called by the location generator whenever the generator has new info to report.

Specified by:
newGpsInfo in interface GpsInfoListener
Parameters:
gpsinfo - The new gpsinfoevent.

distributeInfo

private void distributeInfo(GpsInfoEvent gpsinfo)

isBooted

public boolean isBooted()
Returns true if the location server is booted.


boot

public void boot()
Boots the Location Server. Booting the LocationServer starts the distribution of location information.


addLocationListener

public void addLocationListener(LocationListener ll)
Adds a LocationListener to this server. This listener will be notified of the current location whenever the location generator reports a new location.

Parameters:
ll - the LocationListener.

removeLocationListener

public void removeLocationListener(LocationListener ll)
Removes a LocationListener from this server. The LocationListener removed will no longer be notified of the current location.

Parameters:
ll - the LocationListener to be removed.
Returns:
true if the operation was successful;

addGpsInfoListener

public void addGpsInfoListener(GpsInfoListener gpsinfo)
Adds a GpsInfoListener to this server. This listener will be notified of the new informations whenever the location generator reports a new info.

Parameters:
gpsinfo - the GpsInfoListener.

removeGpsInfoListener

public void removeGpsInfoListener(GpsInfoListener gpsinfo)
Removes a GpsInfoListener from this server. The GpsInfoListener removed will no longer be notified of the current location.

Parameters:
gpsinfo - the GpsInfoListener to be removed.
Returns:
true if the operation was successful;

getServer

public static LocationServer getServer()
Returns the LocationServer singleton.

Returns:
the LocationServer singleton.