/* Copyright 1996 Matthew Freedman and University of Washington mattf@cac.washington.edu This program may be freely used, modified, or redistributed for any non-commercial purpose as long as credit is given. This file contains the LineControllers class. */ import java.awt.*; /* This class provides and applet for holding the controller devices for Number of Lines, A Pulse, and B Pulse. Public methods are: setParams(NinaParams p): Set the interface components to match the parameter values. getParams(NinaParams p): Set the parameter values to macth the interface components. */ public class LineControllers extends GenericController { CountSMController num_lines_ctrl; CountController a_pulse_ctrl, b_pulse_ctrl; public void init() { String[] line_max_choices = {"100", "500", "1000", "2000", "5000", "10000"}; if (this.size().height > this.size().width) setLayout(new GridLayout(3, 1, 0, 25)); else setLayout(new GridLayout(1, 3, 20, 0)); /* Create the controllers */ add(num_lines_ctrl = new CountSMController(this, "Number of Lines", line_max_choices, "00000")); add(a_pulse_ctrl = new CountController(this, "A Pulse", "00000")); add(b_pulse_ctrl = new CountController(this, "B Pulse", "00000")); /* Give controllers their proper initial values */ validate(); initted = true; /* If somebody tried to setParams() during initialization, we have to re-do now */ if (params != null) setParams(null); } /* Accept a class full of set line parameters, and make the interface match it */ public void setParams(NinaParams p) { boolean force; /* Use values from p unconditionally? */ force = super.preSetParams(p); /* If we have not finished initializing, don't want to do anything */ if (!initted) return; /* Tell the controllers to set themselves to match */ num_lines_ctrl.setValues(force, params.num_lines, params.ran_lines, params.max_lines); a_pulse_ctrl.setValues(force, params.a_pulse, params.ran_a_pulse, params.num_lines - 1); b_pulse_ctrl.setValues(force, params.b_pulse, params.ran_b_pulse, params.num_lines - 1); } /* Fill in the p structure with our current params */ public void getParams(NinaParams p) { /* Go through our components, and record values into params*/ params.num_lines = num_lines_ctrl.value(); params.ran_lines = num_lines_ctrl.is_ran(); params.max_lines = num_lines_ctrl.max(); /* A-pulse controller */ params.a_pulse = a_pulse_ctrl.value(); params.ran_a_pulse = a_pulse_ctrl.is_ran(); /* B-pulse controller */ params.b_pulse = b_pulse_ctrl.value(); params.ran_b_pulse = b_pulse_ctrl.is_ran(); } /* Called back by the controllers when a signficant change to the user-interface state has been made. Whether we care and what we do is all special-case, depending on which controller is reporting */ void interfaceChanged(Controller ctrl) { if (ctrl == num_lines_ctrl) { /* If the main value of num_lines changed, we have to make sure a and b pulse stay lower than it */ a_pulse_ctrl.setValues(false, a_pulse_ctrl.value(), a_pulse_ctrl.is_ran(), num_lines_ctrl.value()-1); b_pulse_ctrl.setValues(false, b_pulse_ctrl.value(), b_pulse_ctrl.is_ran(), num_lines_ctrl.value()-1); } } public Insets insets() { if (this.size().height > this.size().width) return new Insets(20, 5, 20, 5); else return new Insets(0, 5, 0, 5); } }