/** * 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 /* Create reference variables for this radio button group and for each of the radio buttons in it. */ private ButtonGroup G; private JRadioButton a, b, c; 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 selmap(movmap mm) { this.bg = bg; // background colour for selector buttons this.mm = mm; // local variable for object reference to main applet setOpaque(false); sm = this; // reference to sel map object // make the radio buttons lie in a single column setLayout(new GridLayout(I,1)); /* Creat a group for the radio buttons so that whenever a particular button is selected, all the others automatically become de-selected. */ G = new ButtonGroup(); /* Add each radio button to this panel and to the group, create an Item Listener for it to detect when it has been clicked by the mouse, then add its Item Listener 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] = 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;} // MAP SCALE i HAS JUST BEEN SELECTED void selectMap(int i) { 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 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); } } }