/** * Bandscope Receiver Applet 1.0.0 [FREQUENCY ANNOTATION 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 freqfigs extends JPanel { /* MC[]: minimum centre frequency (in half-kHz) DP[]: number of required decimal places (including decimal point) FS[]: frequency to subtract to get first annotation (in half-kHz) SB[]: starting bias in pixels NG[]: number of annotated graduations FG[]: half-kHz per graduation of frequency scale for each span choice FJ[]: pixels to jump between successive annotations */ private static final int MC[] = {12000, 6000, 3000, 1200, 600, 220, 120 }, DP[] = { 0, 0, 1, 1, 2, 2, 2 }, FS[] = {10000, 4000, 2000, 1000, 400, 200, 100 }, SB[] = { 0, 20, 0, 0, 20, 0, 0 }, NG[] = { 6, 5, 3, 3, 5, 3, 3 }, FG[] = { 4000, 2000, 2000, 1000, 200, 200, 100 }, FJ[] = { 40, 40, 100, 100, 40, 100, 100 }, I = 5; // text inset from beginning of text area // Font for Choice Menus and buttons. private static final Font 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 required 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 applet 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 instance of frequency span selector // compute distance from top of panel to baseling for the text FontMetrics fm = getFontMetrics(font); t = fm.getAscent() + (H - fm.getHeight()) / 2; } void atualizar() { /* Get the frequency span and centre frequency of the currently selected band and ensure that the Centre Frequency CF is not less than the minimum centre frequency for this band. */ int x = MC[fs], fs = sp.getFreqSpan(); if((CF = cf.getCF()) < x) CF = x; f = CF - FS[fs]; // frequency of first annotation (in half-kHz) // pixels from start of frequency scale of first annotation w = SB[fs] + 20; // number of decimal places required for frequency annotations dp = DP[fs]; cf.setCF2(CF, dp); // display corrected CF in the text entry field this.fs = fs; // selected frequency span number 0 = 10MHz to 6 = 100kHz repaint(); // shedule a repaint via the event-despatching thread } public void paint(Graphics g) { // DISPLAY FREQUENCY AT MOUSE POINTER // draw the background image onto the applet canvas g.drawImage(img, 0, 0, this); // colour and font for figures g.setColor(Color.black); g.setFont(font); /* For each frequency graduation, get the frequency annotation base line for printing text, then afterwards increment to the frequency of, and move to position of, the next annotation. */ for(int i = 0; i < NG[fs]; i++) { convert.centreString(g, convert.toMHz(f, dp), w, t); f += FG[fs]; w += FJ[fs]; } } }