/** * 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 int wn = 0, // waypoint number Wx = 305, Wy = 380, // top left corner of waypoint selector Ww = 300, Wh = 35; // width and height of waypoint selector // reference for this checkbox group private JComboBox waypoints; private boolean WaypointsInstalled = false; private String WaypointNames[]; // provides for upto 1000 waypoints // 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, add it to the applet's content pane, 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;} /* 'x' is the number of waypoints in the selected route. Create a string array to hold the waypoint names then set its access index to point to the first name. */ void clearWaypoints(int x) { WaypointNames = new String[x]; wn = 0; } 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) { } } // This has to be done on the event dispatching thread invoked above. 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 if(ld.DefaultsLoaded() // These two boolean conditions are set on diff- && WaypointsInstalled) { // erent threads. That's why both are necessary. 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 information 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 class from } // which it came. (there will only be one instance). // a Choice selection event has occurred from checkbox 'id' public void itemStateChanged(ItemEvent e) { // Execute the method in the above applet switch(id) { case WAYPOINT: ws.waypointSelect(); } } }