📄 groundcontrolhelpergui.java.svn-base
字号:
package gui;
/**
* Class: GroundControlHelperGUI
*
* @author Niels-David Yogi
* v1.0
*/
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.*;
import world.*;
import base.*;
import interfaces.*;
public class GroundControlHelperGUI extends WorldObject implements GroundControllerInterface{
// Instance Variables (General)
private Tower tTower;
private GroundControlGUI gGUI;
private List <Runway> alRunways;
private List <Taxiway> alTaxiways;
// Instance Variables for Arrival
private HashMap <String, GroundHelperArriv> alAirplaneInfoArriv;
private List <Taxiway> colTaxiwaysArriv;
// Instance Variables for Departure
private HashMap <String, GroundHelperDep> alAirplaneInfoDep;
private List <Taxiway> colTaxiwaysDep;
Animation animation = new Animation();
/**
* Overloaded Constructor
*
* @param name String for name of Ground Controller
* @param t a Tower object
*/
public GroundControlHelperGUI(String name, Tower t){
super(name);
this.tTower = t;
tTower.ctrlAssumeGroundControllerRole(this);
gGUI = new GroundControlGUI();
initializeCollections();
setupRunTaxiways();
setupListeners();
}
/**
* Overloaded Constructor2
*
* @param name String for name of Ground Controller
* @param t a Tower object
* @param objectState a WorldObjectState object
*/
public GroundControlHelperGUI(String name, Tower t, WorldObjectState objectState) {
super(name, objectState);
this.tTower = t;
tTower.ctrlAssumeGroundControllerRole(this);
gGUI = new GroundControlGUI();
initializeCollections();
setupRunTaxiways();
setupListeners();
}
/**
* Overloaded Constructor3
*
* @param name String for name of Ground Controller
* @param t a Tower object
* @param objectState a WorldObjectState object
* @param guiObject a GuiObjectInterface object
*/
public GroundControlHelperGUI(String name, Tower t, WorldObjectState objectState, GuiObjectInterface guiObject) {
super(name, objectState, guiObject);
this.tTower = t;
tTower.ctrlAssumeGroundControllerRole(this);
gGUI = new GroundControlGUI();
initializeCollections();
setupRunTaxiways();
setupListeners();
}
/**
* Overloaded Constructor4
*
* @param name String for name of Ground Controller
* @param t a Tower object
* @param objectState a WorldObjectState object
* @param guiObject a GuiObjectInterface object
* @param animation an Animation object
*/
public GroundControlHelperGUI(String name, Tower t, WorldObjectState objectState, GuiObjectInterface guiObject, Animation animation) {
super(name, objectState, guiObject);
this.animation = animation;
this.tTower = t;
tTower.ctrlAssumeGroundControllerRole(this);
gGUI = new GroundControlGUI();
initializeCollections();
setupRunTaxiways();
setupListeners();
}
/**
* Messages - Received
* These methods are called by other classes sending messages to them.
* This class utilizes the information being sent and updates the stored panel
*/
//** Arrival **\\
/**
* Tells this panel that a plane is leaving a runway
*
* @param callNumber plane number
* @param lastPath the runway plane is using
* @param gate the gate the plane is entering
* @return void
*/
public void msgLeavingRunway (String callNumber, Runway lastPath, Gate gate)
{
logMessage("msgLeavingRunway", callNumber, lastPath, gate);
if (alAirplaneInfoArriv.get(callNumber)== null)
{
alAirplaneInfoArriv.put(callNumber, new GroundHelperArriv(callNumber,lastPath,gate));
gGUI.cbCallNumArriv.addItem(callNumber);
}
else
{
alAirplaneInfoArriv.get(callNumber).getSStrip().gate = gate;
alAirplaneInfoArriv.get(callNumber).getSStrip().runway = lastPath;
}
//alAirplaneInfoArriv.put(callNumber, new GroundHelperArriv(callNumber, lastPath, gate));
// gGUI.cbCallNumArriv.addItem(callNumber);
// updateImagesArriv(callNumber);
}
/**
* Tells this panel the taxiway path is valid
*
* @param callNumber plane number
* @param taxiInstructions a collection of taxiways used to guide the plane
* @return void
*/
public void msgConfirmTaxiLandingPath (String callNumber, List<Taxiway> taxiInstructions)
{
logMessage("msgConfirmTaxiLandingPath", callNumber, taxiInstructions);
if (alAirplaneInfoArriv.get(callNumber) == null)
{
System.out.println("EMPTY PLANE");
System.out.println(callNumber);
}
if (taxiInstructions != null && !taxiInstructions.isEmpty())
{
alAirplaneInfoArriv.get(callNumber).setAlTaxiways(taxiInstructions);
}
alAirplaneInfoArriv.get(callNumber).setBPath(true);
updateImagesArriv(callNumber);
removeArriv(callNumber);
}
/**
* Tells this panel to build a newstrip for the plane
*
* @param newArrival a Strip object
* @return void
*/
public void msgNewArrivalStrip (Strip newArrival)
{
logMessage("msgNewArrivalStrip", newArrival);
GroundHelperArriv insert = new GroundHelperArriv();
insert.setSStrip(newArrival);
alAirplaneInfoArriv.put(newArrival.callNum, insert);
gGUI.cbCallNumArriv.addItem(newArrival.callNum);
//updateImagesArriv(newArrival.callNum);
}
//** Departure **\\
/**
* Tells this panel to add a new plane into sytem that is leaving a gate
*
* @param callNumber plane number
* @param gate a gate object plane is leaving
* @return void
*/
public void msgRequestPushBack (String callNumber, Gate gate)
{
logMessage("msgRequestPushBack", callNumber, gate);
alAirplaneInfoDep.get(callNumber).getSStrip().gate = gate;
}
/**
* Tells this panel confirm information
*
* @param callNumber plane number
* @param takeoffRunway runway object plane is leaving/using
* @param gate a gate object plane is leaving
* @return void
*/
public void msgConfirmPushBack (String callNumber, Runway takeoffRunway, Gate gate)
{
logMessage("msgConfirmPushBack", callNumber, takeoffRunway, gate);
alAirplaneInfoDep.get(callNumber).getSStrip().runway = takeoffRunway;
alAirplaneInfoDep.get(callNumber).setBPush(true);
updateImagesDep(callNumber);
}
/**
* Tells this panel that the taxiway it is giong to use is ready
*
* @param callNumber plane number
* @param currentPosition current taxiway position
* @return void
*/
public void msgReadyForTaxi (String callNumber, Taxiway currentPosition)
{
logMessage("msgReadyForTaxi", callNumber, currentPosition);
alAirplaneInfoDep.get(callNumber).setBTaxiReady(true);
alAirplaneInfoDep.get(callNumber).setTTaxiCurrent(currentPosition);
updateImagesDep(callNumber);
}
/**
* Tells this panel the taxipath takeoff
*
* @param callNumber plane number
* @param path Taxiway path needed for the plane
* @param lc LocalController object
* @return void
*/
public void msgConfirmTaxiTakeoffPath (String callNumber, List<Taxiway> path, LocalControllerInterface lc)
{
logMessage("msgConfirmTaxiTakeoffPath", callNumber, path, lc);
if (path != null && !path.isEmpty())
alAirplaneInfoDep.get(callNumber).setAlTaxiways(path);
alAirplaneInfoDep.get(callNumber).setBTaxiConfirm(true);
updateImagesDep(callNumber);
removeDep(callNumber);
}
/**
* Tells this panel to build a newstrip for the plane
*
* @param newDeparture a Strip object
* @return void
*/
public void msgNewDepartureStrip (Strip newDeparture)
{
logMessage("msgNewDepartureStrip", newDeparture);
System.out.println("got new departure strip: " + newDeparture.toString());
GroundHelperDep insert = new GroundHelperDep();
insert.setSStrip(newDeparture);
alAirplaneInfoDep.put(newDeparture.callNum, insert);
gGUI.cbCallNum.addItem(newDeparture.callNum);
//updateImagesDep(newDeparture.callNum);
}
/**
* Messages - Sent
* These methods are called by this class through buttons being pressed and such.
*/
//** Arrival **\\
/**
* Gives the information of the taxipath to the pilot
*
* @param callNumber plane number
* @return void
*/
public void GiveTaxiLandingPathToPilot(String callNumber){
tTower.getPlane(callNumber).radio().msgTaxiLandingPath(getTaxiwaysArriv());
}
//** Departure **\\
/**
* Gives the information to the pilot that the runway and gate are confirmed
*
* @param callNumber plane number
* @return void
*/
public void GivePushBackToPilot(String callNumber){
try
{
tTower.getPlane(callNumber).radio().msgGivePushBack(alAirplaneInfoDep.get(callNumber).getSStrip().runway, alAirplaneInfoDep.get(callNumber).getSStrip().gate);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
/**
* Gives the information to the pilot of the taxiways that need to be utilized
*
* @param callNumber plane number
* @return void
*/
public void GiveTaxiTakeoffPathToPilot(String callNumber){
tTower.getPlane(callNumber).radio().msgTaxiTakeoffPath(getPathDep(), tTower.localController);
tTower.localController.msgNewDepartureStrip(alAirplaneInfoDep.get(callNumber).getSStrip());
}
/**
* General Methods [Updating, Button Status Check, etc.]
*/
//** General Methods **\\
/**
* Initializes General variables
*
* @return void
*/
private void initializeCollections()
{
alRunways = new ArrayList<Runway>();
alTaxiways = new ArrayList<Taxiway>();
//** Arrival **\\
alAirplaneInfoArriv = new HashMap <String , GroundHelperArriv>();
colTaxiwaysArriv = new ArrayList<Taxiway>();
//** Departure **\\
alAirplaneInfoDep = new HashMap <String, GroundHelperDep>();
colTaxiwaysDep = new ArrayList<Taxiway>();
}
/**
* Sets up listeners for buttons and comboboxes
*
* @return void
*/
private void setupListeners()
{
//** Arrival **\\
gGUI.cbCallNumArriv.addActionListener(new ComboArriv());
gGUI.bTaxiwayArriv.addActionListener(new ComboArriv());
gGUI.bTaxiwaySubmitArriv.addActionListener(new ComboArriv());
//** Departure **\\
gGUI.cbCallNum.addActionListener(new ComboDep());
gGUI.bPush.addActionListener(new ComboDep());
gGUI.bTaxiway.addActionListener(new ComboDep());
gGUI.bTaxiwaySubmit.addActionListener(new ComboDep());
}
/**
* Sets up the runways and taxiways for both panels
*
* @return void
*/
private void setupRunTaxiways()
{
addRunways((ArrayList)this.tTower.airport.runways);
addTaxiways((ArrayList)this.tTower.airport.taxiways);
}
/**
* Adds runways to alRunways
*
* @param runways list of runways
* @return void
*/
public void addRunways(ArrayList <Runway> runways)
{
alRunways = runways;
for (int i = 0; i<alRunways.size(); i++)
{
gGUI.cbRunway.addItem(runways.get(i).toString());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -