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