/** * Bandscope Receiver Applet 1.0.0 [CENTRE-FREQUENCY ENTRY FIELD] * @author Robert J Morton * @version 13 March 2002, 20 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 centrefreq { private static final int bandCentres[][] = { // band centre frequencies for: {250,1000,2400,3300,3950,4900,6100,7200,9700, // broadcast bands 11800,13700,15550,17700,21650,25850,93000,103000}, {1850,3650,7050,10150,14200,18100,21200,24900, // amateur bands 29000,51000,70250,145000,435000,1245000}, {550,3000,3450,4700,5600,6600,8900,10050,11300, // aircraft bands 13300,15050,17950,21950,23250,123000,133000}, {2500,6350,8500,12800,18850,19750,22600,25300, // marine bands 160000} }, Y = 220, // y-coordinate of Centre-Frequency components H = 30; // height of text field private JTextField FrqFld; // centre frequency entry field private JButton EntBut; // button to enter the centre frequency private JLabel CFlab; // annotation in front of text field private boolean CFvalid = false; // centre frequency valid flag private int CF = 186000; // entered centre frequency in half-kHz private ar86000 rx; // reference to the ar86000-specific class private freqfigs ff; // reference to the frequency scale panel class private listeningon lo; // ref to "listening on" frequency display panel private scope sc; // reference to the "scope" display panel private msgpanel mp; // reference to the message panel instance private bands bd; // reference to the bands class instance private freqspan sp; // reference to the freqspan class instance centrefreq(bs cp, int X, Color bg, Font font, msgpanel mp, freqspan sp) { this.sp = sp; this.mp = mp; CFlab = new JLabel( // create annotation label "Centre Frequency MHz:" // for centre-frequency text field ); cp.add(CFlab); // add it to the applet's content pane CFlab.setBounds(10,Y,200,30); // set its position and size FrqFld = new JTextField("93.000"); // set up centre frequency entry field cp.add(FrqFld); // add it to the applet's content pane FrqFld.setBackground(bg); // set its background colour FrqFld.setBounds(X+55,Y,90,H); // set its position and size on app panel FrqFld.setFont(font); FrqFld.addActionListener( // set up action listener to listen for new cfbl(cfbl.FRQFLD,this) // carriage-return events from text field ); EntBut = new JButton("Enter"); //set up the Enter button cp.add(EntBut); //add it to the applet's content pane EntBut.setBounds(X+155,Y,80,H); //set its position and size EntBut.addActionListener( //set up action listener to listen for new cfbl(cfbl.ENTBUT, this) //the "Enter" button being pressed ); } // set reference to the ar86000-specific class void setAR86000(ar86000 rx) {this.rx = rx;} // set reference to the frequency scale panel class void setFreqFigs(freqfigs ff) {this.ff = ff;} // set reference to the "listening on" frequency display panel void setLo(listeningon lo) {this.lo = lo;} // set reference to the "listening on" frequency display panel void setScope(scope sc) {this.sc = sc;} // set reference to the "listening on" frequency display panel void setBands(bands bd) {this.bd = bd;} void pressFrqFld() { // DO WHEN C/R RECEIVED FROM CENTRE FREQUENCY FIELD bd.setSelectedType(0); // set selected band type to "None" bd.setSelectedBand(0); // set selected band to null pressFrqFld2(); // do when C/R received from centre frequency field if(CFvalid) { // if the current centre-frequency is a valid value sc.killPlots(); // erase all scan information ff.atualizar(); // so frequency scale will be re-drawn sc.atualizar(); // update the bandscope graph mp.showMsg("Please update bandscope data.", false); } } // DO WHEN C/R RECEIVED FROM CENTRE FREQUENCY FIELD private void pressFrqFld2() { lo.setReceiving(false); // stop receiving on last selected frequency // get the text present in the centre-frequency text field String s = FrqFld.getText(); int x = s.indexOf("."); // try to locate a decimal point within it if(x == -1) { // if text does not contain a decimal point s += ".0"; // append a decimal point with a trailing zero x = s.indexOf("."); // find index of inserted point FrqFld.setText(s); // redisplay amended text in centre-frequency } // field String k = s.substring(x,s.length()); // isolate decimal point + digits s = s.substring(0,x); // isolate the integral MHz int l = k.length(); // length of decimal (point+digits) part if(l > 1) { // if more than just the decimal point on its own if(l > 3) l = 3; // limit to 2 decimal places of MHz k = k.substring(1,l); // isolate the decimal digits while(k.length() < 2) // pad out with zeros to 3 digits k += "0"; } else k = "00"; // no decimal places, so add 3 zeros s += k; // s now contains integral 10 kHz CFvalid = false; // initially, show centre-frequency is not valid try { // try to x = Integer.parseInt(s + "0"); // parse string as an integer /* if the frequency is within range of receiver scanner, set new valid centre frequency (in integral half-kHz) and trigger a repaint(). */ if(x < 2040000 && x > 100) { CF = x << 1; CFvalid = true; /* else it is out of range of the scanner, so show error message in scope area. */ } else mp.showMsg("Frequency out of range!", true); /* if what was entered cannot be parsed into an integer, show appropriate error message in scope area. */ } catch(NumberFormatException e) { mp.showMsg("Invalid centre frequency!", true); } } // ALLOWS BANDS CLASS TO SET CENTRE FREQUENCY FOR NEW BAND void setCF(int sbt, int sb) { CF = (bandCentres[sbt][sb]) << 1; // get centre frequency for this band FrqFld.setText( // set the centre frequency CF convert.toMHz(CF, 4) // converted from integer to String ); // set it in the CF text entry field pressFrqFld2(); // enter the centre frequency } int getCF() {return CF;} // return centre frequency of current scan band // TO ENABLE freqfigs TO SET THE CORRECTED CENTRE-FREQUENCY void setCF2(int CF, int d) { this.CF = CF; FrqFld.setText(convert.toMHz(CF, d)); } } class cfbl implements ActionListener { static final int ENTBUT = 0; // Enter button pressed event static final int FRQFLD = 1; // C/R from centre frequency entry field event int id; // one of the above centrefreq ap; // the application that called: always the above app public cfbl(int id, centrefreq ap) { // constructor for a new command 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, which was either: case ENTBUT: ap.pressFrqFld(); break; // 'Enter' button case FRQFLD: ap.pressFrqFld(); // 'C/R' } } }