/** * Bandscope Receiver Applet 1.0.0 ["LISTENING ON" PANEL] * @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) class listeningon extends JPanel { private static final long serialVersionUID = 211L; // what the hell this is for, I don't know! 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 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 mouse frequency panel object private ar86000 rx; // reference to the receiver object private boolean receiving; /* true when actually listening on a specified frequency. */ 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; } // reference to scope panel class instance void setScope(scope sc) {this.sc = sc;} // reference to receiver class instance void setAR86000(ar86000 rx) {this.rx = rx;} 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 atualizar(); // still within scope area } private void atualizar() { rF = mf.pixTokHz(rX); // convert x-coordinate to half-kHz int q = 3; // use 3 decimal places of MHz, however, if(rF < 200000) // if frequency less than 100MHz q = 4; // use 4 decimal places of MHz // convert to string with 3 or 4 decimal places of MHz rFs = convert.toMHz(rF, q) + " MHz"; // highlight the listening frequency in blue on the scope panel sc.highlightSignal(rX); // indicate that receiver is being tuned to the listening frequency setReceiving(true); repaint(); // shedule a repaint via the event-despatching thread } // DISPLAY FREQUENCY AT AT WHICH MOUSE WAS CLICKED public void paint(Graphics g) { g.setColor(bg); // panel background colour g.fillRect(0,0,W,H); // clear 'Listening on' area // only if actually receiving on a clicked frequency if(receiving) { g.setFont(font); // set the font for this panel g.setColor(Color.black); // print colour // display the "Listening on" label g.drawString("Listening on:",I,tb); // display the string 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(receiving) // if currently receiving (listening-on) rx.tuneTo(rF * 500); // send 'tune to' command to receiver else // otherwise rx.mute(); // mute the receiver } }