/** * Map Scale Selection Panel for Rob's Moving Map package * @author Robert J Morton YE572246C * @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 javax.swing.*; // Java Swing GUI utilities import java.awt.*; // Java Abstract Windowing Toolkit import java.awt.event.*; // for the new-fangled 1.1 event handling public class selmap extends JPanel implements navconst { // what the hell this is for, I don't know! private static final long serialVersionUID = 2011L; private static selmap sm; // reference to current object private airmap am; // reference to the air map object private movmap mm; // object reference to the main applet private Color bg; // background colour for buttons private int I = 3; // number of buttons private ButtonGroup G; // reference for a JRadioButton group // references to the individual JRadioButtones within the Group private JRadioButton a, b, c; private double Scale, // scaling factor of currently-selected map size S[], // array for the 3 possible scaling factors da, // angular increment for drawing guide circle dots A[]; // array of the above for each of the 3 map sizes selmap(movmap mm) { // construct the radio button panel sm = this; // reference to sel map object this.bg = bg; // background colour for selector buttons this.mm = mm; // local variable for object reference to main applet setOpaque(false); // to make the buttons lie in a single column setLayout(new GridLayout(I,1 )); G = new ButtonGroup(); // Create a Group for the following buttons // Create and add the radio buttons to the Group and to this panel. a = new JRadioButton("", false); G.add(a); add(a); b = new JRadioButton("", true); G.add(b); add(b); c = new JRadioButton("", false); G.add(c); add(c); // Create Item Listeners for them and set them transparent. a.addItemListener(new mapbut(0, this)); a.setOpaque(false); b.addItemListener(new mapbut(1, this)); b.setOpaque(false); c.addItemListener(new mapbut(2, this)); c.setOpaque(false); S = new double[3]; // create the array for the scaling factors S[0] = KPR; // scaling factor for 300 by 300 map S[1] = KPR * 3 / 2; // scaling factor for 200 by 200 map S[2] = KPR * 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 } void setAirmap(airmap am) {this.am = am;} void selectMap(int i) { // MAP SCALE i HAS JUST BEEN SELECTED Scale = S[i]; // so set the appropriate scaling factor da = A[i]; // set angular increment for drawing guide am.atualizar(); // circle dots then update the air map. } double getScale(){return Scale;} // access the currently selected map scale double getMapSize(){return da;} // return map size selection range 1 to 3 } // LISTENS FOR EVENTS FROM THE MAP SCALE SELECTION BUTTONS class mapbut implements ItemListener { int id; // one of the above events selmap ap; // the application that called: always the above applet! // constructor for a new JRadioButton event public mapbut(int id, selmap ap) { this.id = id; // set id number pertaining to this instance of 'mapbut' this.ap = ap; // set the reference to the instance of the applet } // from which it came. (there will only be one instance) // a JRadioButton event has occurred from JRadioButton 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: ap.selectMap(0); break; case 1: ap.selectMap(1); break; case 2: ap.selectMap(2); } } }