/** * 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 six 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; private String RouteNames[]; // names of routes to be installed in // the route selector private int rn = 0, // route number Rx = 15, Ry = 15, // top left corner of route selector Rw = 275, Rh = 35; // width and height of route selector 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 routes = new JComboBox(); // create route selector choice menu cp.add(routes); // add it to the applet content pane routes.setBounds(Rx,Ry,Rw,Rh); // set its position and size // 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) { // x is the number of available routes RouteNames = new String[x]; // string array to hold the route names rn = 0; // set its access index to point to the first name } void addRoute(String s) {RouteNames[rn++] = s;} // copy route names from array RouteNames[] to 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 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 /* NOTE: these two boolean conditions are set on diff- erent threads. That's why both are necessary. If they are both true, initiate loading of the selected route's features and set the button annotations to grey. */ if(ld.DefaultsLoaded() && RoutesInstalled) { ld.loadRoute(routes.getSelectedIndex()); bp.setGrey(); } } // 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 next route name. 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 'Stations' 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' so execute the method in the above applet. */ public void itemStateChanged(ItemEvent e) { switch(id) { case ROUTE: rs.routeSelect(); break; } } }