/** * Map Scale Selection Panel for Rob's 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 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 { private static final long serialVersionUID = 12L; // what the hell this is for, I don't know! private static selmap sm; // reference to current object private airmap am; // reference to the air map object private ButtonGroup G; // reference for this JRadioButton group private int I = 3; // number of buttons 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 private movmap mm; // object reference to the main applet private Color bg; // background colour for buttons private JRadioButton a, b, // references to individual JRadioButtones within it c; selmap(movmap mm) { // construct the radio button panel this.bg = bg; // background colour for selector buttons this.mm = mm; // local variable for object reference to main applet sm = this; // reference to sel map object setOpaque(false); setLayout(new GridLayout(I,1)); // to make the buttons lie // in a single column G = new ButtonGroup(); // incorporate them into a // mutually-exclusive group /* Add radio buttons to this panel, create Item Listeners for then, add them to event handler list. */ a = new JRadioButton("",false); G.add(a); add(a); a.addItemListener(new mapbut(0,this)); a.setOpaque(false); b = new JRadioButton("",true); G.add(b); add(b); b.addItemListener(new mapbut(1,this)); b.setOpaque(false); c = new JRadioButton("",false); G.add(c); add(c); 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] = pi / 120; // does 120 dots round the guide circle A[1] = pi / 80; // does 80 dots round the guide circle A[0] = 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]; // set the appropriate scaling factor da = A[i]; // set angular increment for drawing guide circle dots am.atualizar(); // update the air map } double getScale() {return Scale;} // access 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); } } }