/** * 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 JComboBox waypoints; // reference for this checkbox group private movmap mm; // object reference to the main applet private msgpanel mp; // object reference to message panel 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 private boolean WptsInstd = false; // waypoints not yet installed private String WptNames[]; // upto 1000 waypoints provided for 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, add it to the applet's content pane, then set its position and size. */ waypoints = new JComboBox(); cp.add(waypoints); waypoints.setBounds(Wx,Wy,Ww,Wh); // 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;} void clearWaypoints(int x) { /* x is the number of waypoints in the selected route */ WptNames = new String[x]; /* create a string array to hold the waypoint names */ wn = 0; // set its access index to point to the first name } void addWaypoint(String s) { WptNames[wn++] = s; } // copy route names from array RouteNames[] to Choice Menu void installWaypoints() { WptsInstd = false; try { SwingUtilities.invokeLater( new Runnable() { public void run() { install(); } } ); } catch (Exception e) { } } // this has to be done on the event dispatching thread private void install() { waypoints.removeAllItems(); for(int i = 0; i < wn; i++) waypoints.addItem(WptNames[i]); waypoints.setSelectedIndex(0); WptsInstd = true; } void waypointSelect() { // A ROUTE HAS JUST BEEN SELECTED /* NOTE: the following two boolean conditions are set on different threads. That's why both are necessary. */ if(ld.DefaultsLoaded() && WptsInstd) { 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) { // Execute the method in the above applet case WAYPOINT: ws.waypointSelect(); break; } } }