/** * Control buttone for Rob's Moving Map package * @author Robert J Morton * @version 19 November 1997 */ /* This Panel class contains 4 buttons: Stop/Start, Reset, Next and Prev to control the operation of the Moving Map applet */ 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 butpanel extends JPanel { // what the hell this is for, I don't know! private static final long serialVersionUID = 2010L; private static butpanel bp; // object reference variable private aircraft ac; // reference to aircraft object private airmap am; // reference to airmap object private navpanel np; // reference to navigation panel object private JButton a, b, c, d; // references for the 4 buttons private boolean RunFlag = false, // start off with the program running ResetFlag = false; // initial reset is done in MovMap.init() private int thisButton = 0, // indicates which button has just been hit Bs = 76, // distance between left sides of adjacent buttons /* x-positions of left sides of Start, Reset, Next and Prev buttons on the applet panel */ Bax = 305, Bbx = Bax + 76, Bcx = Bbx + 76, Bdx = Bcx + 76, /* y-position of top of the buttons area on the applet panel, plus the width and height of each button. */ By = 430, Bw = 72, Bh = 35; private Font font; // font for button lettering private movmap mm; // object reference to the main applet private msgpanel mp; // object reference to message panel butpanel(movmap mm, Container cp, msgpanel mp) { // construct the 4 buttons this.mm = mm; // local variable for object reference to main applet this.mp = mp; // reference to message panel bp = this; // reference to button panel object /* Creat buttons, add them to applet's content pane, then create and register event listeners for them. */ a = new JButton("Start"); cp.add(a); a.setBounds(Bax,By,Bw,Bh); a.setMargin(new Insets(3,3,3,3)); a.addActionListener(new bl(bl.START,this)); b = new JButton("Reset"); cp.add(b); b.setBounds(Bbx,By,Bw,Bh); b.setMargin(new Insets(3,3,3,3)); b.addActionListener(new bl(bl.RESET,this)); c = new JButton("Next"); cp.add(c); c.setBounds(Bcx,By,Bw,Bh); c.setMargin(new Insets(3,3,3,3)); c.addActionListener(new bl(bl.NEXT,this)); d = new JButton("Prev"); cp.add(d); d.setBounds(Bdx,By,Bw,Bh); d.setMargin(new Insets(3,3,3,3)); d.addActionListener(new bl(bl.PREV,this)); setGrey(); // set all buttons to have grey lettering } void setAircraft(aircraft ac) {this.ac = ac;} void setAirmap(airmap am) {this.am = am;} void setNavpanel(navpanel np) {this.np = np;} void pressStartBut() { // IF THE START/STOP BUTTON HAS BEEN PRESSED Relabel(RunFlag = !RunFlag); // [re]start aircraft along current route /* If the 'run' flag is set, start the aircraft and show the 'Flight in progress' maeeage; else show the 'Flight paused' message.*/ if(RunFlag) { ac.start(); mp.showMsg("Flight in progress...",true,false); } else mp.showMsg("Flight paused.",true,false); } void pressResetBut() { // IF THE RESET BUTTON HAS BEEN PRESSED route.getCurrent().reset(); // reset aircraft to start of current route Relabel(RunFlag = false); // stop the flight ResetFlag = true; // set the reset request flag for applet atualizar("Ready to begin flight."); } void pressNextBut() { // IF THE NEXT BUTTON HAS BEEN PRESSED Relabel(RunFlag = false); route.getCurrent().setNext(); // advance to next waypoint in current route atualizar("Flight paused."); } void pressPrevBut() { // IF THE PREV BUTTON HAS BEEN PRESSED Relabel(RunFlag = false); route.getCurrent().setPrev(); // back up to prev waypoint in current route atualizar("Flight paused."); } private void atualizar(String s) { am.atualizar(); // update the air map np.atualizar(); // update the nav info panel mp.showMsg(s, true, false); } void stop() { // used by the main applet when end of route reached Relabel(RunFlag = false); // stop the program from running ac.stop(); // terminate flight (set speed to zero) } // LABEL THE BUTTON 'STOP' OR 'START' AS REQUIRED void Relabel(boolean Flag) { setFont(font); // set font for writing on the button if(Flag) { // If the 'run' flag is set a.setText("Stop"); // re-label the button 'Stop' ac.start(); // and [re]start the aircraft } else // otherwise a.setText("Start"); // re-label the button 'Start' } void setGrey() { a.setForeground(Color.lightGray); b.setForeground(Color.lightGray); c.setForeground(Color.lightGray); d.setForeground(Color.lightGray); setButtonText(); } void setBlack() { a.setForeground(Color.black); b.setForeground(Color.black); c.setForeground(Color.black); d.setForeground(Color.black); setButtonText(); } private void setButtonText() { a.setText("Start"); b.setText("Reset"); c.setText("Next"); d.setText("Prev"); } boolean inFlight() {return RunFlag;} // returns in-flight status to MovMap void pause() {RunFlag = false;} // called from waypoint selector selwp() } class bl implements ActionListener { // LISTENS FOR BUTTON EVENTS static final int START = 0; // 'Enter button pressed' event static final int RESET = 1; // 'Pull button pressed' event static final int NEXT = 2; // 'C/R from centre frequency entry field' event static final int PREV = 3; // 'Up button pressed' event int id; // one of the above butpanel ap; // the application that called: always the above class // constructor for a new command public bl(int id, butpanel ap) { this.id = id; this.ap = ap; } // one of the buttons has been clicked public void actionPerformed(ActionEvent e) { switch(id) { // id of this instance of ActionEvent case START: ap.pressStartBut(); break; // it was the 'Start' button case RESET: ap.pressResetBut(); break; // it was the 'Reset' button case NEXT: ap.pressNextBut(); break; // it was the 'Next' button case PREV: ap.pressPrevBut(); break; // it was the 'Prev' button } } }