/** * Bandscope Receiver Applet 1.0.0 [FREQUENCY ANNOTATION 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 freqfigs extends JPanel { private static final long serialVersionUID = 213L; // what the hell this is for, I don't know! private static final int // minimum centre frequency (in half-kHz) MC[] = {12000,6000,3000,1200,600,220,120}, // number of required decimal places (including decimal point) DP[] = {0,0,1,1,2,2,2}, // frequency to subtract to get first annotation (in half-kHz) FS[] = {10000,4000,2000,1000,400,200,100}, // starting bias in pixels SB[] = {0,20,0,0,20,0,0}, // number of annotated graduations NG[] = {6,5,3,3,5,3,3}, // half-kHz/annotated graduation on frequency scale for each span choice FG[] = { 4000,2000,2000,1000,200,200,100}, // pixels to jump between successive annotations FJ[] = {40,40,100,100,40,100,100}, I = 5; // text inset from beginning of text area private static final Font // for Choice menus and buttons font = new Font("Serif",Font.PLAIN,12); private int W = 240, // width of frequency scale panel H = 20, // height of frequency scale text area t, // distance from top of panel to baseling for the text CF, // entered centre frequency in half-kHz fs, // selected frequency span number 0 = 10MHz ... 6 = 100kHz f, // frequency of first annotation (in half-kHz) w, // pixels from start of frequency scale of first annotation dp; // number of decimal places needed for frequency annotations private String mFs; // current mouse frequency private Image img; // reference to background image for this panel private centrefreq cf; // reference to centre-frequency class private freqspan sp; freqfigs(Image i, centrefreq cf, int W, int H, freqspan sp) { img = i; // reference to main app class this.cf = cf; // reference to centre-frequency class this.W = W; // width of frequency-figures panel this.H = H; // height of frequency-figures panel this.sp = sp; // reference to frequency span selector instance // compute distance from top of panel to baseling for the text FontMetrics fm = getFontMetrics(font); t = fm.getAscent() + (H - fm.getHeight()) /2; } void atualizar() { int fs = sp.getFreqSpan(); CF = cf.getCF(); // entre frequency of currently selected band if(CF < MC[fs]) // make sure that the Centre Frequency CF is not less CF = MC[fs]; // than the minimum centre frequency for this band. f = CF - FS[fs]; // frequency of first annotation (in half-kHz) w = SB[fs]+20; // pixels from start of freq scale of first annotation dp = DP[fs]; // number of decimal places for frequency annotations cf.setCF2(CF,dp); // display corrected CF in the text entry field this.fs = fs; // selected freq span number 0 = 10MHz ... 6 = 100kHz repaint(); // shedule a repaint via the event-despatching thread } public void paint(Graphics g) { // DISPLAY FREQUENCY AT MOUSE POINTER g.drawImage(img, 0, 0, this); // draw background image onto app panel g.setColor(Color.black); // colour for figures g.setFont(font); for(int i=0; i < NG[fs]; i++) { // for each frequency graduation convert.centreString( // frequency annotation g, convert.toMHz(f, dp), w, t // base line for printing text ); f += FG[fs]; // increment to frequency of next annotation w += FJ[fs]; // move to position of next annotation } } }