/src/gui/CamOptions.java
Java | 210 lines | 173 code | 33 blank | 4 comment | 44 complexity | 73b48764a272091b5037678e6f0b9d51 MD5 | raw file
- package gui;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import javax.swing.BoxLayout;
- import javax.swing.ButtonGroup;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JRadioButton;
- import javax.swing.JSlider;
- import javax.swing.JTabbedPane;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import cv.Config;
- class MyRadio extends JRadioButton {
- public MyRadio(String name) {
- this(name, false);
- }
- public MyRadio(String name, Boolean selected) {
- super(name, selected);
- setActionCommand(name);
- }
- }
- public class CamOptions extends JFrame implements ItemListener, MouseListener,
- ActionListener {
- public static Boolean laserDetection = false, showHSVValues = false,
- frameDelay = false, calibrationPointsDetection = false,
- threshold = false, dilate = true;
- public static JLabel hsvValues = new JLabel("(-1, -1, -1)");
- public static String whatToThreshold = "TARGET_LASER";
- protected JCheckBox ld, showHSV, fDelay, cpd, thres, dilateErode;
- protected JButton saveBtn;
- protected JTabbedPane tabs;
- protected MySlider cs_hw_factor, laser_area, cs_area;
- protected ButtonGroup radioGroup;
- public CamOptions() {
- super("Cam Options");
- this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.PAGE_AXIS));
- this.setMinimumSize(new Dimension(350, 600));
- this.ld = new JCheckBox("Laser detection");
- this.ld.addItemListener(this);
- this.cpd = new JCheckBox("Calibration points detection");
- this.cpd.addItemListener(this);
- this.showHSV = new JCheckBox("Show HSV Values");
- this.showHSV.addItemListener(this);
- this.fDelay = new JCheckBox("Video frame delay");
- this.fDelay.addItemListener(this);
- this.thres = new JCheckBox("Threshold");
- this.thres.addItemListener(this);
- this.dilateErode = new JCheckBox("Erode & Dilate");
- this.dilateErode.setSelected(true);
- this.dilateErode.addItemListener(this);
- this.saveBtn = new JButton("Save");
- this.saveBtn.addMouseListener(this);
- this.cs_hw_factor = new MySlider("CS width-height factor", 0, 100,
- "MAX_CS_HEIGHT_WIDTH_FACTOR");
- this.laser_area = new MySlider("Min laser area", 0, 300,
- "MIN_LASER_AREA");
- this.cs_area = new MySlider("min CS Area", 0, 8000, "MIN_CS_AREA");
- this.tabs = new JTabbedPane();
- String[] hsvKeys = { "HUE", "SATURATION", "VALUE" };
- String[] ranges = { "MIN", "MAX" };
- String[] items = { "LASER", /*"BOTTOM_RIGHT_CS", "TOP_RIGHT_CS",
- "BOTTOM_LEFT_CS", "TOP_LEFT_CS" */};
- String delimiter = "_";
- this.radioGroup = new ButtonGroup();
- for (String item : items) {
- JPanel panel = new JPanel();
- panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
- MyRadio radio = new MyRadio(item, false);
- radio.addActionListener(this);
- if (radioGroup.getButtonCount() == 0) {
- radio.setSelected(true);
- CamOptions.whatToThreshold = item;
- }
- radioGroup.add(radio);
- panel.add(radio);
- for (String hsvKey : hsvKeys) {
- int min = 0, max = 255;
- if (hsvKey == "HUE") {
- max = 180;
- }
- for (String range : ranges) {
- MySlider slider = new MySlider(range + delimiter + hsvKey,
- min, max, range + delimiter + item + delimiter
- + hsvKey);
- panel.add(slider);
- }
- }
- this.tabs.addTab(item, panel);
- }
- this.add(this.ld);
- this.add(this.cpd);
- this.add(this.thres);
- this.add(this.dilateErode);
- //this.add(this.cs_hw_factor);
- this.add(this.laser_area);
- //this.add(this.cs_area);
- // this.add(CamOptions.hsvValues);
- // this.add(this.fDelay);
- this.add(this.tabs);
- this.add(this.saveBtn);
- }
- @Override
- public void itemStateChanged(ItemEvent e) {
- Object source = e.getItemSelectable();
- if (source == this.ld) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- CamOptions.laserDetection = true;
- } else {
- CamOptions.laserDetection = false;
- }
- } else if (source == this.cpd) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- CamOptions.calibrationPointsDetection = true;
- } else {
- CamOptions.calibrationPointsDetection = false;
- }
- } else if (source == this.showHSV) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- CamOptions.showHSVValues = true;
- } else {
- CamOptions.showHSVValues = false;
- }
- } else if (source == this.fDelay) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- CamOptions.frameDelay = true;
- } else {
- CamOptions.frameDelay = false;
- }
- } else if (source == this.thres) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- CamOptions.threshold = true;
- } else {
- CamOptions.threshold = false;
- }
- } else if (source == this.dilateErode) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- CamOptions.dilate = true;
- } else {
- CamOptions.dilate = false;
- }
- }
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- Object source = e.getSource();
- if (source == this.saveBtn) {
- Config.save();
- }
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- }
- @Override
- public void mousePressed(MouseEvent arg0) {
- }
- @Override
- public void mouseReleased(MouseEvent arg0) {
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- CamOptions.whatToThreshold = e.getActionCommand();
- }
- }