📄 clearancedeliveryhelper.java.svn-base
字号:
package gui;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import javax.swing.*;
import world.*;
import agents.*;
import base.*;
import gui.GroundControlHelperGUI.ComboArriv;
import gui.GroundControlHelperGUI.ComboDep;
import interfaces.*;
public class ClearanceDeliveryHelper extends WorldObject implements ClearanceDeliveryInterface, ActionListener{
protected World myWorld;
protected Tower myTower;
protected ClearanceDeliveryPanel cdPanel;
protected PilotInterface myPilot;
private Animation animation;
private Airport airport;
protected Map<String, MyFlight> flights = new HashMap<String, MyFlight>();
protected enum FlightState {CLEARANCE_REQUESTED, CLEARANCE_GRANTED, CLEARANCE_DENIED, CONFIRM_CLEARANCE, GIVEN_CONDITIONS, NO_ACTION}
protected class MyFlight{
public String callNumber;
public Gate gate;
public FlightState state;
public Runway runway;
public String destination;
public PilotInterface pilot;
public PlaneInterface plane;
public MyFlight(String callNum, Runway runway, Gate gate, String destination, PilotInterface pilot){
this.callNumber = callNum;
this.gate = gate;
this.runway = runway;
this.destination = destination;
this.pilot = pilot;
//this.state = FlightState.CLEARANCE_REQUESTED;
}
}
/**constructors**/
public ClearanceDeliveryHelper(String name, Airport airport){
super(name);
this.myTower = airport.towers.get(0);
this.airport = airport;
myTower.ctrlAssumeClearanceDeliveryRole(this);
cdPanel = new ClearanceDeliveryPanel();
initializeCollections();
setupListeners();
}
public ClearanceDeliveryHelper(String name, Airport airport, WorldObjectState objectState) {
super(name, objectState);
this.myTower = airport.towers.get(0);
this.airport = airport;
myTower.ctrlAssumeClearanceDeliveryRole(this);
cdPanel = new ClearanceDeliveryPanel();
initializeCollections();
setupListeners();
}
public ClearanceDeliveryHelper(String name, Airport airport, WorldObjectState objectState, GuiObjectInterface guiObject) {
super(name, objectState, guiObject);
this.myTower = airport.towers.get(0);
this.airport = airport;
myTower.ctrlAssumeClearanceDeliveryRole(this);
cdPanel = new ClearanceDeliveryPanel();
initializeCollections();
setupListeners();
}
public ClearanceDeliveryHelper(String name, Airport airport, WorldObjectState objectState, GuiObjectInterface guiObject, Animation animation) {
super(name, objectState, guiObject);
this.animation = animation;
this.myTower = airport.towers.get(0);
this.airport = airport;
myTower.ctrlAssumeClearanceDeliveryRole(this);
cdPanel = new ClearanceDeliveryPanel();
initializeCollections();
setupListeners();
}
/**messages**/
//receive
public void msgNewDepartingFlight(Plane plane, String callNumber,
Runway runway, Gate gate, String destination, PilotInterface p) {
MyFlight f = new MyFlight(callNumber, runway, gate, destination, p);
flights.put(callNumber, f);
}
public void msgRequestingClearance(String callNumber, Gate gate){
MyFlight f = flights.get(callNumber);
f.state = FlightState.CLEARANCE_REQUESTED;
logMessage("msgRequestingClearance", callNumber, gate);
cdPanel.listFlight.addElement(callNumber);
cdPanel.listGate.addElement(gate);
}
public void msgConfirmClearance(String callNumber, GroundControllerInterface groundController){
MyFlight f = flights.get(callNumber);
f.state = FlightState.CONFIRM_CLEARANCE;
logMessage("msgConfirmClearance", callNumber, groundController);
}
public void msgConfirmWeather(String callNumber){
MyFlight f = flights.get(callNumber);
f.state = FlightState.GIVEN_CONDITIONS;
logMessage("msgConfirmWeather", callNumber);
Weather report = new Weather();
// getPilot(callNumber).msgSendWeather(report);
}
public PilotInterface getPilot(String callNumber) {
PlaneInterface plane = myTower.getPlane(callNumber);
return plane.msgPilot();
}
//sent
void actGrantClearance(MyFlight f){
List<Waypoint> procedure = new LinkedList<Waypoint>();
getPilot(f.callNumber).msgClearanceGranted(procedure, myTower.groundController);
f.state = FlightState.CLEARANCE_GRANTED;
}
void sendNewDepartureStrip(MyFlight f) {
Strip s = new Strip(f.callNumber);
s.runway = f.runway;
s.gate = f.gate;
myTower.groundController.msgNewDepartureStrip(s);
}
void actSendWeather(MyFlight f){
Weather report = new Weather();
getPilot(f.callNumber).msgSendWeather(report);
f.state = FlightState.NO_ACTION;
}
/**other**/
public JPanel getClearancePanel() {
return cdPanel;
}
public void setDestinations(String[] destinations) {
cdPanel.setDestinations(destinations);
}
/**initialization**/
private void initializeCollections()
{
}
private void setupListeners()
{
cdPanel.buttonApprove.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == cdPanel.buttonApprove) {
sendNewDepartureStrip(flights.get(cdPanel.listFlight.getElementAt(cdPanel.flight.getSelectedIndex())));
actGrantClearance(flights.get(cdPanel.listFlight.getElementAt(cdPanel.indexFlight)));
actSendWeather(flights.get(cdPanel.listFlight.getElementAt(cdPanel.flight.getSelectedIndex())));
cdPanel.listFlight.removeElement(cdPanel.listFlight.getElementAt(cdPanel.flight.getSelectedIndex()));
}
}
/**message logger**/
protected void logMessage(String msg, Object ... objects) {
String from = Thread.currentThread().getName();
String str = timeStamp() + from + " -> " + name + " . " + msg + "()\n";
System.out.print(str + "\n \n");
animation.logMessage(from, name, str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -