/** * Bandscope Receiver Applet 1.0.0 ["LISTENING ON" PANEL] * @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) class listeningon extends JPanel { private int W, // width of the "listening on" panel H, // Height of "listening on" frequency panel I = 5; // text inset from beginning of text area private int J, // end position for right-justified text tb, // text base line for panel of height H rF, // receiving frequency in integral half-kHz rX; // x-coordinate of the "listening on" line on the scope graph private String rFs; // receiving frequency rF in String form private boolean receiving; // true = listening on a specified frequency private Color bg; // panel background colour private Font font; // font used in this panel private FontMetrics fm; // font metrics of the current font private scope sc; // reference to the scope object private mousefreq mf; // reference to the mouse frequency panel object private ar86000 rx; // reference to the receiver object listeningon(Color bg, Font font, mousefreq mf, int W, int H) { this.bg = bg; // set panel colour this.mf = mf; // reference to mouse frequency panel class instance this.W = W; // width of listening-on panel class instance this.H = H; // width of listening-on panel class instance J = W - I; this.font = font; fm = getFontMetrics(font); // get dimensions of current type face // y-coordinate for lettering within a field of depth H tb = fm.getAscent() + (H - fm.getHeight()) / 2; } void setScope(scope sc) { // Enables an external class to set ref- this.sc = sc; // erence to scope panel class instance. } void setAR86000(ar86000 rx) { // Enables an external class to set ref- this.rx = rx; // erence to receiver class instance. } void click(int x) { // MOUSE CLICK EVENT HANDLER rX = x; // x-coordinate of mouse within scope area atualizar(); // (0 = left edge of scope) } void inchFreq(int δx) { // INCHING EVENT FROM THE UP/DOWN BUTTONS rX += δx; // add + or - 1 to current x-coordinate of highlighted bar if(sc.withinScopeWidth(rX)) { // provided inched x-coordinate is still atualizar(); } // within scope area, update it. } private void atualizar() { rF = mf.pixTokHz(rX); // convert x-coordinate to half-kHz /* Use 3 decimal places of MHz, however, if frequency is less tha 100MHz, use 4 decimal places of MHz. */ int q = 3; if(rF < 200000) q = 4; // convert to a string of 3 or 4 decimal places of MHz rFs = convert.toMHz(rF, q) + " MHz"; sc.highlightSignal(rX); // highlight the listening frequency // in blue on the scope panel setReceiving(true); // indicate that receiver is being // tuned to the listening frequency repaint(); // shedule a repaint via the event-despatching thread } // DISPLAY THE FREQUENCY AT WHICH THE MOUSE WAS CLICKED public void paint(Graphics g) { // clear 'Listening on' area to the panel background colour g.setColor(bg); g.fillRect(0, 0, W, H); /* Probided we are actually listening on the clicked frequency, set the font to print in black then display the "Listening on" label and the frequency on which we are listening. */ if(receiving) { g.setFont(font); g.setColor(Color.black); g.drawString("Listening on:", I, tb); g.drawString(rFs, J - fm.stringWidth(rFs), tb); } } boolean getReceiving() {return receiving;} // CALLED ONLY BY "SCOPE" // CALLED BY "BANDS", "CENTREFREQ" AND "FREQSPAN" void setReceiving(boolean b) { receiving = b; // set the "receiving or not" state /* If currently receiving (listening-on), send 'tune to' command to the receiver; otherwise, mute the receiver. */ if(receiving) rx.tuneTo(rF * 500); else rx.mute(); } }