/** * Scan Mode Selector for CtrlPanl.class re DifEqnAp.class * @author Robert J Morton UK-YE572246C * @version 27 November 1997 modified 07 August 2009, 18 April 2012 */ /* This class contains a pair of radio buttons for choosing whether the program should simply plot to the end of the time graph and then stop (single-scan mode); or whether, upon reaching the end of the time axis, it should fly back to the beginning again and continue plotting, wiping the old trace as it goes (continuous mode). */ import java.awt.*; // for graphics operations (GUI) import java.awt.event.*; // for the new-fangled 1.1 event handling import javax.swing.*; // library for constructing Swing GUI public class selscan extends Panel { private timegr tg; // instance reference of time-graph private setbutt sb; // instance reference of setbutt panel private selplot st; // instance reference of selplot panel private JLabel L; // to hold reference to panel's 'heading' private ButtonGroup G; // to hold reference to the checkbox group private JRadioButton a, b; // and references to individual checkboxes private boolean Flags[] = {false, true}, // the 2 options for the scan-mode flag ScanMode = true; // start in continuous-scan mode selscan(timegr tg, setbutt sb, Color pc) { this.tg = tg; // copy instance ref. of time-graph to local variable this.sb = sb; // copy instance ref. of setbutt panel to local variable setBackground(pc); // set panel colour // lay out items in a single column of 3 setLayout(new GridLayout(3, 0)); // create title label for selscan panel and add it to selscan panel L = new JLabel("Scan Mode:", Label.LEFT); add(L); G = new ButtonGroup(); // create a button group container /* Create the 'single-scan' radio button, add it to the button- group and to the selscan panel then create a istener for it. */ a = new JRadioButton("Single-scan", false); G.add(a); add(a); a.addItemListener(new scanbut(0, this)); /* Create the 'continuous' radio button, add it to the button- group and to the selscan panel then create a istener for it. */ b = new JRadioButton("Continuous", true); G.add(b); add(b); b.addItemListener(new scanbut(1, this)); } void setST(selplot st) {this.st = st;} // set instance ref. of selplot void selectScanMode(int i){ ScanMode = Flags[i]; // set the newly-selected scan mode tg.setSM(ScanMode); // set scan mode flag in the time graph class st.resetPlotMode(); // sets plot mode to false = 'line-graph' sb.reset(); // stop iteration and clear (reset) the graphs } void setSM(boolean Flag) { // used by selplot ScanMode = Flag; // set the scan flag to its appropriate state if(ScanMode) // if it has been set true b.setSelected(true); // tick the 'continuous' button else // if it has been set false a.setSelected(true); // tick the 'single-scan' button sb.reset(); // stop iteration and clear (reset) the graphs } } // LISTENS FOR EVENTS FROM SCAN MODE SELECTION BUTTONS class scanbut implements ItemListener { int id; // one of the above events selscan ss; // the application that called: always the above class /* Constructor for a new checkbox event: sets 'id' number pertaining to this instance and the reference to the instance of the above class from which it came. (there will only be one instance). */ public scanbut(int id, selscan ss) { this.id = id; this.ss = ss; } // a checkbox event has occurred from checkbox 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: ss.selectScanMode(0); break; // continuous mode case 1: ss.selectScanMode(1); break; // single-shot mode } } }