/** * Bandscope Receiver Applet 1.0.0 [SPECIAL FORMATS CONVERTER] * @author Robert J Morton * @version 13 March 2002, 20 March 2012 * @copyright Robert J Morton (all rights reserved) */ import java.awt.*; // for graphics operations (GUI) class convert { // DRAW A STRING CENTRED AT A HORIZONTAL POSITION x static void centreString(Graphics g, String s, int x, int y) { // dimensions of characters for current font FontMetrics fm = g.getFontMetrics(); // half the width of the string to be displayed int b = (fm.stringWidth(s)) >> 1; g.drawString(s, x - b,y); // display the string } // DRAW A RIGHT-JUSTIFIED STRING static void rightString(Graphics g, String s, int x, int y) { // dimensions of characters for current font FontMetrics fm = g.getFontMetrics(); g.drawString(s, x - fm.stringWidth(s),y); // display the string } // INTEGRAL HALF-kHz to DECIMAL MHz STRING static String toMHz( int x, // frequency in integral half-kHz int d // number of decimal places of MHz required ) { int D[] = {5,3,2,1,0}; // to convert decimal places to string chop String s = "0"; if((x & 0x1) > 0) // if there is an odd half-kHz s = "5"; // set 4th decimal place of MHz to '5' s = "" + (x >> 1) + s; // string of rF in form GL.XXXX MHz int l = s.length(); // insert the decimal point if(l < 5) return "?????"; // safety net x = l - 4; // to give MHz to 4 decimal places // insert the decimal point s = s.substring(0,x) + "." + s.substring(x,l); // chop to required number of decimal places return s.substring(0,s.length() - D[d]); } }