/** * Plot 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 plot the time graph as a series of lines joining consecutive 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 int ls = 0; // language switch: 0=English 1=Portuguese private String s; // for multi-language 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, int ls) { this.sb = sb; // copy setbutt's instance reference to the local variable this.ss = ss; // copy selscan's instance reference to the local variable this.tg = tg; // copy timegr's instance reference to the local variable this.ls = ls; // language switch setLayout(new GridLayout(3,0)); // set objects in vertical column of 3 setBackground(pc); // set panel colour /* Get annotation in the selected language [English or Portuguese], create a label to write it on and add the label to this panel. */ s = "Plot Mode"; if(ls != 0) s = "Modo de Traçar"; L = new JLabel(s,Label.LEFT); add(L); // Create a group container for the following radio-buttons G = new ButtonGroup(); /* Get annotation for the 'line-graph' radio button in the selected language [English or Portuguese], create the radio button with the annotation written on it, add the radio button to the button group and to this panel then create and add an event listener for it. */ s = "Line Graph"; if(ls != 0) s = "Em Linhas"; a = new JRadioButton(s,true); G.add(a); add(a); a.addItemListener(new plotbut(0,this)); /* Get annotation for the 'spot-value' radio button in the selected language [English or Portuguese], create the radio button with the annotation written on it, add the radio button to the button group and to this panel then create and add an event listener for it. */ s = "Spot Value"; if(ls != 0) s = "Em Pontos"; b = new JRadioButton(s,false); G.add(b); add(b); 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 time graph panel } // called only from the listener class below void selectPlotMode(int i) { 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 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 public plotbut(int id, selplot st) { this.id = id; // set id number pertaining to this instance this.st = st; // set the reference to the instance of the above class } // 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: st.selectPlotMode(0); break; // line-graph mode was selected case 1: st.selectPlotMode(1); // single-shot mode was selected } } }