
package josx.vision;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.media.Control;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

// Referenced classes of package josx.vision:
//            ColorEffect

public class ColorDetectionControl
    implements Control, ActionListener, ChangeListener
{

    public ColorDetectionControl(ColorEffect coloreffect)
    {
        effect = coloreffect;
    }

    public Component getControlComponent()
    {
        if(component == null)
        {
            label = new JLabel("Set Pixel difference threshold:");
            proportionLabel = new JLabel("Set Proportion threshold:");
            button = new JButton("Color Debug");
            button.addActionListener(this);
            button.setToolTipText("Click to turn debugging mode on/off");
            ColorDetectionControl _tmp = this;
            ColorDetectionControl _tmp1 = this;
            threshold = new JSlider(0, 0, 40 / 4, ColorEffect.pixelThreshold / 4);
            threshold.setMajorTickSpacing(1);
            threshold.setPaintLabels(true);
            threshold.addChangeListener(this);
            ColorDetectionControl _tmp2 = this;
            ColorDetectionControl _tmp3 = this;
            proportionThreshold = new JSlider(0, 0, (int)(0.5F / 0.05F), (int)(ColorEffect.requiredProportion / 0.05F));
            proportionThreshold.setMajorTickSpacing(1);
            proportionThreshold.setPaintLabels(true);
            proportionThreshold.addChangeListener(this);
            Box box = Box.createVerticalBox();
            box.add(label);
            box.add(threshold);
            box.add(proportionLabel);
            box.add(proportionThreshold);
            box.invalidate();
            component = box;
        }
        return component;
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        Object obj = actionevent.getSource();
        if(obj == button)
            debug = !debug;
    }

    public void stateChanged(ChangeEvent changeevent)
    {
        Object obj = changeevent.getSource();
        if(obj == threshold)
        {
            ColorDetectionControl _tmp = this;
            ColorEffect.pixelThreshold = threshold.getValue() * 4;
        }
        if(obj == proportionThreshold)
        {
            ColorDetectionControl _tmp1 = this;
            ColorEffect.requiredProportion = (float)proportionThreshold.getValue() * 0.05F;
        }
    }

    private Component component;
    private JButton button;
    private JSlider threshold;
    private JSlider proportionThreshold;
    private JLabel label;
    private JLabel proportionLabel;
    private ColorEffect effect;
    private boolean debug;
    private int thresholdValue;
}