/** * Geoid Selector Class for Rob's Moving Map Navigator * @author Robert J Morton * @version 16 April 2010 */ /* This class contains a drop-down menu object for choosing which of the geodic ellipsoids is to be used for the Vincenty distance and bearing computations. */ import javax.swing.*; // Java Swing GUI utilities import java.awt.*; // Java Abstract Windowing Toolkit import java.awt.event.*; // for the new-fangled event handling public class selgeoid { // to allow manual selection of the geoid private static final double A[] = { // SEMI-MAJOR AXES OF AVAILABLE GEOIDS 6378137.000, // 0 GRS80 / WGS84 (NAD83) * 6378206.400, // 1 Clark 1866 (NAD27) 6377563.396, // 2 Airy 1858 6377340.189, // 3 Airy Modified 6378160.000, // 4 Australian National 6377397.155, // 5 Bessel 1841 6378249.145, // 6 Clark 1880 6377276.345, // 7 Everest 1830 6377304.063, // 8 Everest Modified 6378166.000, // 9 Fisher 1960 6378150.000, // 10 Fisher 1968 6378270.000, // 11 Hough 1956 6378388.000, // 12 International (Hayford) 6378245.000, // 13 Krassovsky 1938 6378145.000, // 14 NWL-9D (WGS 66) 6378160.000, // 15 South American 1969 6378136.000, // 16 Soviet Geod. System 1985 6378135.000, // 17 WGS 72 }, F[] = { // FLATTENING FACTORS OF GEOIDS 0.00335281068118366789616980869833, // 0 GRS80 / WGS84 (NAD83) * 0.00339007530392991937343144432063, // 1 Clark 1866 (NAD27) 0.00334085064149707745426055919427, // 2 Airy 1858 0.00334085064149707745426055919427, // 3 Airy Modified 0.00335289186923721709974853310981, // 4 Australian National 0.00334277318217480587901060845382, // 5 Bessel 1841 0.00340756137869933382175046428024, // 6 Clark 1880 0.00332444929666288455151682985834, // 7 Everest 1830 0.00332444929666288455151682985834, // 8 Everest Modified 0.00335232986925913509889373114314, // 9 Fisher 1960 0.00335232986925913509889373114314, // 10 Fisher 1968 0.00336700336700336700336700336700, // 11 Hough 1956 0.00336700336700336700336700336700, // 12 International (Hayford) 0.00335232986925913509889373114314, // 13 Krassovsky 1938 0.00335289186923721709974853310981, // 14 NWL-9D (WGS 66) 0.00335289186923721709974853310981, // 15 South American 1969 0.00335281317789691440603238146967, // 16 Soviet Geod. System 1985 0.00335277945416750486153020854288, // 17 WGS 72 }; private static final String N[] = { // NAMES OF THE OF AVAILABLE GEOIDS "GRS80 / WGS84 (NAD83)", // 00 "Clark 1866 (NAD27)", // 01 "Airy 1858", // 02 "Airy Modified", // 03 "Australian National", // 04 "Bessel 1841", // 05 "Clark 1880", // 06 "Everest 1830", // 07 "Everest Modified", // 08 "Fisher 1960", // 09 "Fisher 1968", // 10 "Hough 1956", // 11 "International (Hayford)", // 12 "Krassovsky 1938", // 13 "NWL-9D (WGS 66)", // 14 "South American 1969", // 15 "Soviet Geod. System 1985", // 16 "WGS 72" // 17 }; private static selgeoid gsel; // reference to geoid selector object private int n, // number of currently selected geoid /* Position on the applet panel of the top left corner of geoid selector plus the width and height of geoid selector. */ Gx = 425, Gy = 480, Gw = 180, Gh = 35; private double a, f; // major axis and flattening factor for the above private JComboBox gcm; // reference for geoid choice menu private movmap mm; // object reference to the main applet private dandb db; // object reference to the vincenty class // construct instance of geoid selector menu selgeoid(movmap mm, Container cp) { this.mm = mm; // local variable for reference to main applet gsel = this; // set reference to geoid selector object n = 0; // set default ellipsiod GRS80 / WGS84 (NAD83) a = A[n]; // semi-major axis of default geoid (metres) f = F[n]; // flattening factor of default geoid db = new dandb(a,f); // create a new instance of distance and bearing /* create an instance of goeoid selector, add it to the applet's content pane then set its size and position on the pane. */ gcm = new JComboBox(); cp.add(gcm); gcm.setBounds(Gx,Gy,Gw,Gh); // Add each of the listed geoid names to the goid choice menu. for(int i = 0; i < N.length; i++) gcm.addItem(N[i]); gcm.setSelectedIndex(n); // show the default geoid as selected // create and register an event listener for this choice menu gcm.addItemListener(new glistener(glistener.E,this)); } void select() { // A NEW GEOID HAS JUST BEEN SELECTED // get the menu item number of the currently selected geoid n = gcm.getSelectedIndex(); a = A[n]; // semi-major axis of default geoid (metres) f = F[n]; // flattening factor of default geoid db.setaf(a, f); // set new values of semi-major axis and flattening gcm.getItemAt(n); // show name of currently selected geoid } dandb getDandB() { return db; } } // LISTENS FOR EVENTS FROM THE GEOID CHOICE MENU class glistener implements ItemListener { static final int E = 0; // an event from the 'geoids' Choice Menu int id; // one of the above events selgeoid gsel; // calling application: always the above applet // constructor for a new Choice selection listener public glistener(int id, selgeoid gsel) { this.id = id; // set the id number for this instance of 'selgeoid' this.gsel = gsel; // set the reference to this instance of 'selgeoid' } // from which it came. (only one instance). // a Choice selection event from checkbox 'id' public void itemStateChanged(ItemEvent e) { // Execute the appropriate method in the above applet. switch(id) { case E: gsel.select(); break; } } }