/** * Route selector for Rob's Moving Map package * @author Robert J Morton * @version 27 November 1997 */ /* This class contains a drop-down menu object for choosing which of the three routes is to be flown. */ import javax.swing.*; // Java Swing GUI utilities import java.awt.*; // Java Abstract Windowing Toolkit import java.awt.event.*; // for the new-fangled 1.1 event handling public class selwp { private static selwp ws; // reference to waypoint selector object private butpanel bp; // reference to button panel object private airmap am; // reference to air map object private navpanel np; // reference to nav panel object private loader ld; // reference to the loader object private movmap mm; // object reference to the main applet private msgpanel mp; // object reference to message panel private JComboBox waypoints; // reference for this checkbox group private String WaypointNames[]; // up to 1000 waypoints provided for private boolean WaypointsInstalled = false; private int wn = 0, // waypoint number Wx = 305, // x-coord of top left corner of waypoint selector Wy = 380, // y-coord of top left corner of waypoint selector Ww = 300, // width of waypoint selector Wh = 35; // height of waypoint selector // construct the radio button panel selwp(movmap mm, Container cp, msgpanel mp, butpanel bp) { this.mm = mm; // local variable for object reference to main applet this.mp = mp; // message panel reference this.bp = bp; // reference to the button panel object ws = this; // set reference to route selector object // create waypoint selector choice menu waypoints = new JComboBox(); cp.add(waypoints); // add it to the applet's content pane waypoints.setBounds(Wx,Wy,Ww,Wh); // set its position and size //create and register an event listener for this choice menu waypoints.addItemListener(new wslisten(wslisten.WAYPOINT, this)); } void setAirmap(airmap am) {this.am = am;} void setNavpanel(navpanel np) {this.np = np;} void setLoader(loader ld) {this.ld = ld;} // x is the number of waypoints in the selected route void clearWaypoints(int x) { // create a string array to hold the waypoint names WaypointNames = new String[x]; wn = 0; // set its access index to point to the first name } void addWaypoint(String s) {WaypointNames[wn++] = s;} // copy route names from array RouteNames[] to Choice Menu void installWaypoints() { WaypointsInstalled = false; try { SwingUtilities.invokeLater( new Runnable() { public void run() { install(); } } ); } catch (Exception e) { } } // copy route names from array RouteNames[] to Choice Menu private void install() { waypoints.removeAllItems(); for(int i = 0; i < wn; i++) waypoints.addItem(WaypointNames[i]); waypoints.setSelectedIndex(0); WaypointsInstalled = true; } void waypointSelect() { // A ROUTE HAS JUST BEEN SELECTED /* NOTE: these two boolean conditions are set on different threads. That's why both are necessary. */ if(ld.DefaultsLoaded() && WaypointsInstalled) { bp.pause(); // pause flight by killing RunFlag in butpanel bp.Relabel(false); // set label of start button mp.showMsg("Flight paused.",true,false); route.getCurrent().setThis(waypoints.getSelectedIndex()); am.atualizar(); // update the air map np.atualizar(); // update the nav info panel } } } // LISTENS FOR EVENTS FROM THE CHOICE MENU SELECTORS class wslisten implements ItemListener { static final int WAYPOINT = 0; // an event from the 'Stations' Choice Menu int id; // one of the above events selwp ws; // the application that called: always the above applet! // constructor for a new Choice selection event public wslisten(int id, selwp ws) { this.id = id; // set the id number for this instance of 'rslisten' this.ws = ws; // set the reference to the instance of the 'hfbrx' applet } // from which it came. (there will only be one instance). // a Choice selection event has occurred from checkbox 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case WAYPOINT: ws.waypointSelect(); // Execute this method in the above applet } } }