/** * Plot 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 plot the time graph as a series of lines joining con- secutive plots, or, simply mark successive spot values of x by short horizontal lines each of which is equal in lenght to the inter-iteration period as plotted on the Time Graph. */ 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 selplot extends JPanel { private JLabel L; // to hold reference to panel's 'heading' private ButtonGroup G; // to hold reference to the JRadioButton group private JRadioButton a, b; // and references to individual JRadioButtones private setbutt sb; // instance reference of the setbutt panel private selscan ss; // instance reference of the selscan panel private timegr tg; // instance reference of the time-graph private boolean Flags[] = {false, true}, // plot mode options PlotMode = false; /* true: 'spot values' is selected false: 'lines joining values' is selected */ selplot(setbutt sb, selscan ss, timegr tg, Color pc) { this.sb = sb; // setbutt's instance reference this.ss = ss; // selscan's instance reference this.tg = tg; // timegr's instance reference // set out objects as a vertical column of 3 setLayout(new GridLayout(3, 0)); setBackground(pc); // set panel colour //create title label for this panel and add it to this panel L = new JLabel("Plot Mode:", Label.LEFT); add(L); /* Create a container group for radio-buttons then create two buttons and add each to both the group and this panel. */ G = new ButtonGroup(); a = new JRadioButton("Line Graph", true); G.add(a); add(a); b = new JRadioButton("Spot Value", false); G.add(b); add(b); // Create a listener for each button. a.addItemListener(new plotbut(0, this)); b.addItemListener(new plotbut(1, this)); } void resetPlotMode() { // called only by selscan PlotMode = false; // set the plot-mode flag to 'line-graph' a.setSelected(true); // tick the 'line-graph' button tg.setPM(PlotMode); // transfer PlotMode state to the time graph panel } void selectPlotMode(int i) { // called only from the listener class below sb.reset(); // hit the 'Reset' button PlotMode = Flags[i]; // set the new state of the plot-mode selector if(PlotMode) // if in single plot mode ss.setSM(false); // force Scan Mode to Single Scan tg.setPM(PlotMode); // transfer PlotMode state to the time graph panel } } // LISTENS FOR EVENTS FROM PLOT MODE SELECTION BUTTONS class plotbut implements ItemListener { int id; // one of the above events selplot st; // the application that called: always the above class /* Constructor for a new JRadioButton 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 plotbut(int id, selplot st) { this.id = id; this.st = st; } // a JRadioButton event has occurred from JRadioButton 'id' public void itemStateChanged(ItemEvent e) { switch(id) { // Selected mode: case 0: st.selectPlotMode(0); break; // line-graph case 1: st.selectPlotMode(1); break; // single-shot } } }