/** * 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 { private static final long serialVersionUID = 11L; // what the hell this is for, I don't know! 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 Bs = 76, // distance between left sides of adjacent buttons By = 430, // y-position of top of buttons area on applet panel Bw = 72, // width of each button Bh = 35, // height of each button L = 0, // language switch Bax = 305, // x-position of left side of Start button on applet panel Bbx = Bax + 76, // ditto for Reset button Bcx = Bbx + 76, // ditto for Next button Bdx = Bcx + 76, // ditto for Prev button thisButton = 0; // indicates which button has just been hit private String S[][] = { {"Start","Reset","Next","Prev","Stop"}, {"Iniciar","Restab.","Próximo","Anterior","Pare"} }, F[][] = { {"Flight in progress...","Flight paused.","Ready to begin flight."}, {"Vôo em andamento...","Voo pausado.","Pronto para começar o vôo."} }; private Font font; // font for button lettering private movmap mm; // object reference to the main applet private msgpanel mp; // object reference to message panel // Construct the 4 buttons butpanel(movmap mm, Container cp, msgpanel mp, int L) { 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 this.L = L; /* Create buttons, add them to applet's content pane, create and register event listeners for them. */ a = new JButton(S[L][0]); 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(S[L][1]); 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(S[L][2]); 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(S[L][3]); 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;} // IF THE START/STOP BUTTON HAS BEEN PRESSED void pressStartBut() { Relabel(RunFlag = !RunFlag); // [re]start aircraft along current route if(RunFlag) { // if the run flag is set, ac.start(); // start the aircraft. mp.showMsg(F[L][0],true,false); // "Flight in progress..." } else mp.showMsg(F[L][1],true,false); // "Flight paused." } // IF THE RESET BUTTON HAS BEEN PRESSED void pressResetBut() { 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(F[L][2]); // "Ready to begin flight." } /* If the next button has been pressed, advance to next waypoint in current route. */ void pressNextBut() { Relabel(RunFlag = false); route.getCurrent().setNext(); atualizar(F[L][1]); // "Flight paused." } /* If the prev button has been pressed, back-up to previous waypoint in current route. */ void pressPrevBut() { Relabel(RunFlag = false); route.getCurrent().setPrev(); atualizar(F[L][1]); // "Flight paused." } // Update the air map and nav panel private void atualizar(String s) { am.atualizar(); np.atualizar(); mp.showMsg(s, true, false); } /* Used by the main applet when end of route reached: stop the program from running and terminate flight (set speed to zero).*/ void stop() { Relabel(RunFlag = false); ac.stop(); } /* Label the button 'STOP' or 'START' as required: set font for writing on the button; if the run flag is set, re-label the button 'Stop' and [re] start the aircraft, else re-label the button 'Start'. */ void Relabel(boolean Flag) { setFont(font); if(Flag) { a.setText(S[L][4]); ac.start(); } else a.setText(S[L][0]); } 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(S[L][0]); b.setText(S[L][1]); c.setText(S[L][2]); d.setText(S[L][3]); } 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 RESET = 1, // 'Pull button pressed' event NEXT = 2, // 'C/R from centre freq entry field' event PREV = 3; // 'Up button pressed' event int id; // one of the above butpanel ap; // the application that called: always the above class public bl(int id, butpanel ap) { // constructor for a new command this.id = id; this.ap = ap; } public void actionPerformed(ActionEvent e) { // a button has been clicked 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 } } }