The Map Scale Selector Class

This class creates and processes events relating to the 3 radio buttons on the right of the applet's control panel. They allow the user to select the scale or area of coverage of the map. The scale can be changed at any time - whether or not the aircraft is currently in flight.

/** 
  * Map Scale Selection Panel for my Moving Map package
  * @author Robert J Morton
  * @version 27 November 1997
*/
/*  This class contains a group of 3 radio buttons for choosing
    which of the three map scales is to be used. */

import java.awt.*;

public class selmap extends Panel implements navconst {
   private static selmap sm;                //reference to current object
   private Label L;                         //reference to the label
   private CheckboxGroup G;                 //reference for this checkbox group
   private Checkbox a, b, c;                //references to individual checkboxes within it
   private int I = 3;                       //number of buttons
   private Checkbox B[];                    //array to hold the check box references
   private double Scale;                    //scaling factor of currently-selected map size
   private double S[];                      //array for the 3 possible scaling factors
   private double da;                       //angular increment for drawing guide circle dots
   private double A[];                      //array of the above for each of the 3 map sizes

   selmap(Font f) {                                //construct the radio button panel
      setFont(f);                                  //set font for label and annotations
      sm = this;                                   //reference to sel map object
      B = new Checkbox[I];                         //create the array of checkbox references
      setLayout(new GridLayout(I + 1, 0));         //to make the buttons lie in a single column
      L = new Label("Map Size (km)", Label.LEFT);  //heading label for the three buttons
      G = new CheckboxGroup();                     //incorporate the buttons into a mutually-exclusive group
      a = new Checkbox("300 x 300", G, false);     //annotate the 3 radio buttons
      b = new Checkbox("200 x 200", G, true);
      c = new Checkbox("100 x 100", G, false);
      add(L);                                      //add the title label to this panel
      B[0] = (Checkbox)add(a);                     //add the radio buttons to this panel
      B[1] = (Checkbox)add(b);
      B[2] = (Checkbox)add(c);
      S = new double[3];                           //create the array for the scaling factors
      S[0] = 1;                                    //scaling factor for 300 by 300 map
      S[1] = 1.5;                                  //scaling factor for 200 by 200 map
      S[2] = 3;                                    //scaling factor for 100 by 100 map
      Scale = S[1];                                //preselect 200 by 200 as default scale
      A = new double[3];                           //create array for map sizes
      A[2] = Math.PI / 120;                        //does 120 dots round the guide circle
      A[1] = Math.PI / 80;                         //does 80 dots round the guide circle
      A[0] = Math.PI / 40;                         //does 40 dots round the guide circle
      da = A[1];                                   //circle incrementer for drawing guide circles
   }

   boolean action(Event e) {                //HANDLES EVENTS FROM THIS CHECKBOX
      Checkbox cb = G.getCurrent();         //checkbox group's currently selected button
      int i;                                //selection index 0, 1, 2
      if(e.target == cb) {                  //if the event came from this checkbox group
         for(i = 0 ; i < I; i++)            //find the corresponding scale
            if(cb == B[i]) break;
         Scale = S[i];                      //set the appropriate scaling factor
         da = A[i];                         //set angular increment for drawing guide circle dots
         return true;                       //This presented checkbox event has
      }                                     // been successfully dealt with.
      return false;                         //this checkbox event was not for us
   }

   double getScale() {return Scale;}        //access the currently selected map scale
   double getMapSize() {return da;}         //return map size selection range 1 to 3
   static selmap getCurrent() {return sm;}  //return reference to current object
}

/*  Robert J Morton, the author of this program, 
    is a poor but Right Honourable Member of the
    Ancient and Noble Order of the Long-term Unemployed.

    Offers of work please to: robmorton@clara.net  */