/** * Scan Mode Selector for CtrlPanl.class re DifEqnAp.class * @author Robert J Morton * @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 private int ls = 0; // language switch: 0=English 1=Portuguese private String s; // for multi-language selscan(timegr tg, setbutt sb, Color pc, int ls) { this.tg = tg; // copy instance ref. of time-graph to local variable this.sb = sb; // copy instance ref. of setbutt panel to local variable this.ls = ls; // language switch setBackground(pc); // set panel colour setLayout(new GridLayout(3,0)); // lay out items in a single column of 3 s = "Scan Mode"; if(ls != 0) s = "Varredura"; // English/Portuguese L = new JLabel(s,Label.LEFT); // create title label for selscan panel add(L); // add the title label to selscan panel s = "Single-scan"; if(ls != 0) s = "Uma vez só"; // English/Portuguese G = new ButtonGroup(); // create a button group container a = new JRadioButton(s,false); // create the 'single-scan' radio button G.add(a); // add radio-button to the button-group add(a); // add radio-button to selscan panel a.addItemListener( new scanbut(0,this) // create an event listener for it ); s = "Continuous"; if(ls != 0) s = "Contínuo"; //English/Portuguese b = new JRadioButton(s,true); // create the 'continuous' radio button G.add(b); // add radio-button to the button-group add(b); // add radio-button to selscan panel b.addItemListener( new scanbut(1,this) // create an event listener for it ); } void setST(selplot st) {this.st = st;} // set instance reference 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 public scanbut(int id, selscan ss) { this.id = id; // set id number pertaining to this instance this.ss = ss; // set the reference to the instance of the above class } // from which it came. (there will only be one instance) // a checkbox event has occurred from checkbox 'id' public void itemStateChanged(ItemEvent e) { switch(id) { case 0: ss.selectScanMode(0); break; // continuous mode was selected case 1: ss.selectScanMode(1); // single-shot mode was selected } } }