/*
* File: Radio.java
*/
/**
* This package contains the files that support the GUI
* assignment for Semester 2 - 2000
*/
package gui2000;
import java.util.*;
/**
* The <code>Radio</code> simulates radio contact with all the aircraft in
* a particular simulated airspace.
*
* @author T Balls
* @version 0.1, 12-12-99
*
* @see gui2000.AirSpace
*/
public class Radio extends java.util.Observable
implements java.util.Observer
{ public Radio( Vector theAircraft )
{ aircraft = theAircraft;
}
/**@shapeType AggregationLink
@associates <b>Aircraft</b>*/
private Vector aircraft = null;
/**
* Called by each <code>Aircraft</code> when there is a message
* to pass to the air traffic controller.
* <P>
* The method prepends the call sign to the message before passing
* it to any Observers registered.
*/
public void update( Observable o, Object message )
{ if( (o instanceof Aircraft) && (message instanceof String) )
{ setChanged();
notifyObservers( ((Aircraft)o).getData().callSign + ": " + message );
}
}
/**
* Send a message to an aircraft
* <P>
* @param callsign - the aircraft's call sign (squawk code)
* @param message the String to be sent to the aircraft
*/
public void broadcast( String callsign, String message )
{ for( int i = 0; i < aircraft.size(); i++ )
{ Aircraft theOne = (Aircraft)(aircraft.elementAt(i));
if( theOne.getData().callSign.equals( callsign ) )
{ theOne.order( message );
return;
}
}
}
}
|