// created: 29.12.00
// modified:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class AttributeSwitch extends JPanel implements ItemListener
 {

 JLabel theLabel;
 JCheckBox theSwitch; 

 WeightChanger wgtChanger;
 FunctionChanger funcChanger;

 AttributeSwitch(String label, WeightChanger wgt, FunctionChanger func)
  {
  wgtChanger = wgt;
  funcChanger = func;  

  theLabel = new JLabel(label);
  theSwitch = new JCheckBox("on/off");
  theSwitch.setSelected(true);

  theSwitch.addItemListener(this);

  setLayout(new GridLayout(1,2));
  setPreferredSize(new Dimension(165,20));
  theLabel.setPreferredSize(new Dimension(100,20));
  theSwitch.setPreferredSize(new Dimension(65,20));

  add(theLabel);
  add(theSwitch);
  }

 public void setEnabled(boolean bool)
  {
  super.setEnabled(bool);
  theLabel.setEnabled(bool);
  theSwitch.setEnabled(bool);  
  }

 /***************************/
 /* method itemStateChanged */
 /***************************/

 public void itemStateChanged(ItemEvent e) 
  {
  if (e.getStateChange() == ItemEvent.DESELECTED)
   {
   wgtChanger.setEnabled(false);
   wgtChanger.theField.setText("0");
   funcChanger.setEnabled(false);
   } 
  else
   {
   wgtChanger.theField.setText(String.valueOf(wgtChanger.theSlider.getValue()));
   wgtChanger.setEnabled(true);
   funcChanger.setEnabled(true);
   }
  }

}