/** * Bandscope Receiver Applet 1.0.0 [UPDATE FREQUENCY SELECTOR AND UPDATE BUTTON] * @author Robert J Morton * @version 13 March 2002, 22 March 2012 * @copyright Robert J Morton (all rights reserved) */ import javax.swing.*; // swing widgets import java.awt.*; // for graphics operations (GUI) import java.awt.event.*; // for the new-fangled 1.1 event handling class update { private static final int X = 395, // x-coordinate of hold button on applet panel Y = 183, // y-coordinate of hold button on applet panel W = 140, // width of peak hold button H = 30, // height of peak hold button h = 15; // label height private String Age = ""; // age of latest scan data for selected band private JLabel AgeLabel; // label on which the above is displayed private msgpanel mp; // instance reference of the message panel object private loader ld; // instance reference of the loader object update(bs cp, msgpanel mp) { this.mp = mp; // instance reference of message panel object int y = Y; /* set the y-coordinate to where the top of the first Swing widget should be placed. */ JLabel UpdtLab = // create an "Update Trace" label new JLabel("Update trace..."); cp.add(UpdtLab); // add it to the applet's content pane UpdtLab.setBounds(X, y, W, h); // set its position and size y += 18; /* advance the y-coordinate to where the top of the next Swing widget should be placed. */ JComboBox Update = // create update frequency choice menu new JComboBox(); Update.addItem("on demand"); // enter its fixed text values Update.addItem("continuous"); Update.addItem("every minute"); Update.addItem("every 5 mins"); Update.addItem("every 10 mins"); Update.addItem("every 15 mins"); Update.addItem("every 20 mins"); Update.addItem("every 30 mins"); Update.addItem("every hour"); cp.add(Update); // add it to the applet's content pane Update.setBounds(X,y,W,H); // set its position and size // create a listener for this choice menu Update.addItemListener(new udchl(udchl.UPDATE, this)); y += 39; /* advance the y-coordinate to where the top of the next Swing widget should be lpaced. */ // create a blank label in which to show the age of the scan data AgeLabel = new JLabel(""); cp.add(AgeLabel); // add it to the main JPanel AgeLabel.setBounds(X, y, W, h); // set its position and size y += 18; /* advance the y-coordinate to where the top of the next Swing widget should be lpaced. */ // create the Pull button JButton PulBut = new JButton("Update Now"); cp.add(PulBut); // add it to the main JPanel PulBut.setBounds(X,y,W,H); // set its position and size // create a listener for this button PulBut.addActionListener(new updatebl(updatebl.PULBUT, this)); } // set the reference to the loader class instance void setLd(loader ld) {this.ld = ld;} // action to be taken when update choice made void selUpdate() {mp.showMsg("new update frequency selected", false);} // action to be taken when Pull button is pressed void pressPulBut() { if(false) { // replace with server ack signal ld.post(); // send POST command to server to invoke a re-scan } else { mp.showMsg("RX port server currently unavailable.", true); ld.reload(); // trigger a delayed reload of current data } } // !!! THIS MUST BE DONE ON THE EVENT-DESPATCHING THREAD !!! void setAgeLabel(String Age) {AgeLabel.setText(Age);} } // LISTENS FOR EVENTS FROM THE BUTTONS class updatebl implements ActionListener { static final int PULBUT = 0; // 'Pull button pressed' event int id; // one of the above update ap; // the application that called public updatebl(int id, update ap){ // constructor for a new command this.id = id; this.ap = ap; } public void actionPerformed(ActionEvent e){ switch(id) {case PULBUT: ap.pressPulBut(); break;} } // entered when PULL button has been pressed } /* LISTENS FOR EVENTS FROM THE CHOICE MENU SELECTORS: In this case, an event from the 'update frequency selector' choice menu. */ class udchl implements ItemListener { static final int UPDATE = 0; int id; // one of the above events update ap; // the app that called: always the above app /* Constructor for a new Choice selection event. Sets the id number pertaining to this instance of 'cl' and then the reference to the instance of the 'bs' app from which it came. (there will only be one instance anyway). */ public udchl(int id, update ap) { this.id = id; this.ap = ap; } // a Choice selection event has occurred from checkbox 'id' public void itemStateChanged(ItemEvent e) { switch(id) {case UPDATE: ap.selUpdate(); break;} } // Execute the method in the above applet which deals with this choice }