/** * Route selector for Rob's Moving Map package * @author Robert J Morton YE572246C * @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 routesel { private static routesel rs; // reference to route selector object private loader ld; // reference to the loader object private JComboBox routes; // reference for this checkbox group private movmap mm; // object reference to the main applet private butpanel bp; // reference to button panel object private boolean RoutesInstalled = false; // The names of the routes to be installed in the route selector. private String RouteNames[]; private int rn = 0, // route number /* Position on applet panel of top left corner of route selector, plus width and height of the route selector. */ Rx = 15, Ry = 15, Rw = 275, Rh = 35; // construct the radio button panel routesel(movmap mm, Container cp, butpanel bp) { this.mm = mm; // local variable for object reference to main applet this.bp = bp; // reference to the button panel object rs = this; // set reference to route selector object /* Create the Route Selector choice menu, add it to the applet pane and set its position and size. */ routes = new JComboBox(); cp.add(routes); routes.setBounds(Rx,Ry,Rw,Rh); //create and register an event listener for the above choice menu routes.addItemListener(new rslisten(rslisten.ROUTE,this)); } void setLoader(loader ld) {this.ld = ld;} void clearRoutes(int x) { // Create a string array of 'x' elements RouteNames = new String[x]; // to hold all route names and set its rn = 0; // access index to point to the first name. } void addRoute(String s) { RouteNames[rn++] = s; } // Copy the route names from the array RouteNames[] to the Choice Menu void installRoutes() { RoutesInstalled = 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() { routes.removeAllItems(); for(int i = 0; i < rn; i++) routes.addItem(RouteNames[i]); routes.setSelectedIndex(0); RoutesInstalled = true; } void routeSelect() { // A NEW ROUTE HAS JUST BEEN SELECTED if(ld.DefaultsLoaded() // These two boolean conditions are set on diff- && RoutesInstalled) { // erent threads. That's why both are necessary. // Initiate loading of the selected route's geographic features. ld.loadRoute(routes.getSelectedIndex()); bp.setGrey(); // set the button annotations to grey } } // Select the route name within the routes Choice menu. void selectRouteName(int i) { routes.setSelectedIndex(i); } // Return the total number of available routes. int getTotalRoutes() { return routes.getItemCount(); } // Get the name of the next route. String getRouteName(int i) { String s = routes.getItemAt(i); return s.toLowerCase(); } } // LISTENS FOR EVENTS FROM THE CHOICE MENU SELECTORS class rslisten implements ItemListener { static final int ROUTE = 0; // an event from the 'Routes' Choice Menu int id; // one of the above events routesel rs; // the application that called: always the above applet! // constructor for a new Choice selection event public rslisten(int id, routesel rs) { this.id = id; // set the id number for this instance of 'rslisten' this.rs = rs; // 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) { // Execute the appropriate method in the above applet switch(id) { case ROUTE: rs.routeSelect(); break; } } }