package Windows;

import CalculationAndLampsSets.LampsSets;
import CommunicationAndSaving.propertiesFile;
import CommunicationAndSaving.serialCommunication;
import measurementThread.ArduinoAnswear;
import measurementThread.ThreadM;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;

public class Window extends JFrame {

    private propertiesFile properties;
    private ThreadM mThread;
    private serialCommunication serial;
    private ArduinoAnswear answear;

    private boolean measurementProcessOnQuestion = false;
    private JPanel measurementInfo;
    private JPanel generalInfo;
    private JPanel luminaire;
    private JPanel lamps;
    private JPanel utilFactor;
    private JPanel subpanelButtons;
    private JFileChooser jFileChooser;
    private JMenuBar menuBar;
    private JMenu toolsMenu;
    private JMenu propertiesMenu;
    private JMenu saveMenu;
    private JMenu infoMenu;
    private ImageIcon startImageIcon;
    private ImageIcon saveImageIcon;
    private ImageIcon stopImageIcon;
    private ImageIcon exitImageIcon;
    private ImageIcon restoreImageIcon;
    private ImageIcon infoInfoImageIcon;
    private ImageIcon saveSaveImageIcon;
    private ImageIcon refreshItemsImageIcon;
    private JMenuItem startMenuItem;
    private JMenuItem saveMenuItem;
    private JMenuItem stopMenuItem;
    private JMenuItem exitMenuItem;
    private JMenuItem refreshMenuItem;
    private JMenuItem restoreMenuItem;
    private JMenuItem infoInfoMenuItem;
    private JMenuItem savePathMenuItem;
    private final String startToolsIcon = "Icons\\startToolsIcon.png";
    private final String savePropertiesIcon = "Icons\\saveToolsIcon.png";
    private final String stopToolsIcon = "Icons\\stopToolsIcon.png";
    private final String exitToolsIcon = "Icons\\exitToolsIcon.png";
    private final String restorePropertiesIcon = "Icons\\restoreToolsIcon.png";
    private final String infoInfoIcon = "Icons\\infoIcon.png";
    private final String saveSaveIcon = "Icons\\saveIcon.png";
    private final String refreshItemsIcon = "Icons\\refresh.png";

    private JButton graphButton;
    private JButton tableButton;
    private JButton startButton;
    private JButton stopButton;
    private JButton saveButton;
    private JButton restoreButton;
    private JButton exitButton;
    private JButton addLampSet;
    private JButton deleteLampSet;
    private JButton deleteAll;
    private JTextArea measurementScreenArea;
    private ArrayList<String> USBports;
    private JList<String> UsbList;
    private DefaultListModel<String> UsbElements;
    private JLabel distanceText;
    private JCheckBox IlumQuestion;
    private JCheckBox IluminationForLDT;
    private JCheckBox CalculateFlux;
    private JTextField distance;

    private JTextField ID1_manufacturer;            //názov výrobcu svietidla
    private JComboBox ID2_type;                     //parameter - typ svietidla
    private JComboBox ID3_symmetry;                 //parameter symetrie
    private JTextField ID4_Mc;                      //počet C rovín
    private JTextField ID5_Dc;                      //krok medzi C rovinami ... uhol C-motor
    private JTextField ID6_Ng;                      //počet hodnôt svietivosti
    private JTextField ID7_Dg;                      //krok medzi hodnotami svietivosti ... uhol Gamma
    private JTextField ID8_measurementNumber;       //číslo merania
    private JTextField ID9_luminaireName;           //názov svietidla
    private JTextField ID10_luminaireNumber;        //číslo svietidla
    private JTextField ID11_fileName;               //názov súboru
    private JTextField ID12_dateName;               //dátom/meno osoby, ktorá meranie vykonala
    private JTextField ID13_luminaireLength;
    private JTextField ID14_luminaireWidth;
    private JTextField ID15_luminaireHeight;
    private JTextField ID16_luminaireArea;
    private JTextField ID17_widthLuminaireArea;
    private JTextField ID18_heightLiminaireAreaC0;
    private JTextField ID19_heightLiminaireAreaC90;
    private JTextField ID20_heightLiminaireAreaC180;
    private JTextField ID21_heightLiminaireAreaC270;
    private JTextField ID22_DFF;
    private JTextField ID23_LORL;
    private JTextField ID24_conversionFactor;
    private JTextField ID25_tiltLuinaire;
    private static ArrayList<LampsSets> ID26_lamps = new ArrayList<>();
    private JTextField ID27_DR_k060;
    private JTextField ID27_DR_k080;
    private JTextField ID27_DR_k100;
    private JTextField ID27_DR_k125;
    private JTextField ID27_DR_k150;
    private JTextField ID27_DR_k200;
    private JTextField ID27_DR_k250;
    private JTextField ID27_DR_k300;
    private JTextField ID27_DR_k400;
    private JTextField ID27_DR_k500;
    private JTextField ID26a_numberOfLamp;
    private JTextField ID26b_typeOfLamp;
    private JTextField ID26c_fluxOfLamp;
    private JTextField ID26d_ColorTemperatureOfLamp;
    private JTextField ID26e_colorRenderingIndex;
    private JTextField ID26f_allPowerSupply;

    public static Integer factor;
    public static Integer gammaFactor;

    /*
    Konštruktor triedy "Window" ... vykresľuje okno používateľskeho rozhrania,
    inicializuje a rozmiesťňuje základné prvky, a nastavuje parametre
    okna používateľského rozhrania ...
     */
    public Window(serialCommunication serial, propertiesFile properties, ArduinoAnswear answear) throws IOException, IOException {

        this.serial = serial;
        this.properties = properties;
        this.answear = answear;

        setBounds(200, 170, 740, 485);
        addWindowListener(new closeProgram());
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        getContentPane().setLayout(null);
        setResizable(false);
        setVisible(true);
        setTitle("Goniofotometer");

        menuBar = new JMenuBar();
        toolsMenu = new JMenu("Tools");
        propertiesMenu = new JMenu("Properties");
        saveMenu = new JMenu("Save");
        infoMenu = new JMenu("Info");

        startImageIcon = new ImageIcon(startToolsIcon);
        saveImageIcon = new ImageIcon(savePropertiesIcon);
        stopImageIcon = new ImageIcon(stopToolsIcon);
        exitImageIcon = new ImageIcon(exitToolsIcon);
        restoreImageIcon = new ImageIcon(restorePropertiesIcon);
        infoInfoImageIcon = new ImageIcon(infoInfoIcon);
        saveSaveImageIcon = new ImageIcon(saveSaveIcon);
        refreshItemsImageIcon = new ImageIcon(refreshItemsIcon);

        startMenuItem = new JMenuItem("Start", startImageIcon);
        saveMenuItem = new JMenuItem("Save", saveImageIcon);
        stopMenuItem = new JMenuItem("Stop", stopImageIcon);
        exitMenuItem = new JMenuItem("Exit", exitImageIcon);
        restoreMenuItem = new JMenuItem("Restore", restoreImageIcon);
        infoInfoMenuItem = new JMenuItem("Info Dialog", infoInfoImageIcon);
        savePathMenuItem = new JMenuItem("Save Path", saveSaveImageIcon);
        refreshMenuItem = new JMenuItem("Refresh Items", refreshItemsImageIcon);

        setJMenuBar(menuBar);
        menuBar.add(toolsMenu);
        menuBar.add(propertiesMenu);
        menuBar.add(saveMenu);
        menuBar.add(infoMenu);
        toolsMenu.add(startMenuItem);
        toolsMenu.add(stopMenuItem);
        toolsMenu.add(exitMenuItem);
        toolsMenu.add(refreshMenuItem);
        propertiesMenu.add(saveMenuItem);
        propertiesMenu.add(restoreMenuItem);
        infoMenu.add(infoInfoMenuItem);
        saveMenu.add(savePathMenuItem);

        startMenuItem.addActionListener(new startListener());
        stopMenuItem.addActionListener(new stopListener());
        saveMenuItem.addActionListener(new saveListener());
        infoInfoMenuItem.addActionListener(new infoListener());
        exitMenuItem.addActionListener(new closeListener());
        restoreMenuItem.addActionListener(new restoreListener());
        savePathMenuItem.addActionListener(new pathMenuItem());
        refreshMenuItem.addActionListener(new refreshMenuItem());

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        tabbedPane.setBounds(10, 11, 705, 405);
        getContentPane().add(tabbedPane);

        measurementInfo = new JPanel();
        tabbedPane.addTab("Measurement", null, measurementInfo, null);
        measurementInfo.setLayout(null);

        generalInfo = new JPanel();
        tabbedPane.addTab("General", null, generalInfo, null);
        generalInfo.setLayout(null);

        luminaire = new JPanel();
        tabbedPane.addTab("Luminaire", null, luminaire, null);
        luminaire.setLayout(null);

        lamps = new JPanel();
        tabbedPane.addTab("Lamps", null, lamps, null);
        lamps.setLayout(null);

        utilFactor = new JPanel();
        tabbedPane.addTab("Utilization Factor", null, utilFactor, null);
        utilFactor.setLayout(null);

        addMeasurementPart();
        addGeneralPart();
        addLuminairePart();
        addLampsPart();
        addUtilizationFactor();
    }

    /*
    Vykresľuje čast okna používateľskeho rozhrania, - vykresľuje
    časť "Utilization Factor" ...
    Podobne, ako to bolo u konštruktora okna, sa tu nastavujú
    a inicializujú objekty okna ...
     */
    private void addUtilizationFactor() throws IOException {
        JPanel factorsPanel = new JPanel();
        factorsPanel.setBackground(new Color(192, 192, 192));
        factorsPanel.setBounds(10, 11, 100, 360);
        factorsPanel.setLayout(null);
        utilFactor.add(factorsPanel);
        JLabel textUtilFactor = new JLabel("Direct ratios: ");
        textUtilFactor.setBounds(13, 10, 100, 14);
        factorsPanel.add(textUtilFactor);

        JLabel k060 = new JLabel("k = 0.60: ");
        k060.setBounds(20, 32, 70, 14);
        factorsPanel.add(k060);

        JLabel k080 = new JLabel("k = 0.80: ");
        k080.setBounds(20, 52, 70, 14);
        factorsPanel.add(k080);

        JLabel k100 = new JLabel("k = 1.00: ");
        k100.setBounds(20, 72, 70, 14);
        factorsPanel.add(k100);

        JLabel k125 = new JLabel("k = 1.25: ");
        k125.setBounds(20, 92, 70, 14);
        factorsPanel.add(k125);

        JLabel k150 = new JLabel("k = 1.50: ");
        k150.setBounds(20, 112, 70, 14);
        factorsPanel.add(k150);

        JLabel k200 = new JLabel("k = 2.00: ");
        k200.setBounds(20, 132, 70, 14);
        factorsPanel.add(k200);

        JLabel k250 = new JLabel("k = 2.50: ");
        k250.setBounds(20, 152, 70, 14);
        factorsPanel.add(k250);

        JLabel k300 = new JLabel("k = 3.00: ");
        k300.setBounds(20, 172, 70, 14);
        factorsPanel.add(k300);

        JLabel k400 = new JLabel("k = 4.00: ");
        k400.setBounds(20, 192, 70, 14);
        factorsPanel.add(k400);

        JLabel k500 = new JLabel("k = 5.00: ");
        k500.setBounds(20, 212, 70, 14);
        factorsPanel.add(k500);

        ID27_DR_k060 = new JTextField(properties.get_Property("ID27_DR_k060"));
        ID27_DR_k060.setBounds(120, 40, 570, 20);
        utilFactor.add(ID27_DR_k060);

        ID27_DR_k080 = new JTextField(properties.get_Property("ID27_DR_k080"));
        ID27_DR_k080.setBounds(120, 60, 570, 20);
        utilFactor.add(ID27_DR_k080);

        ID27_DR_k100 = new JTextField(properties.get_Property("ID27_DR_k100"));
        ID27_DR_k100.setBounds(120, 80, 570, 20);
        utilFactor.add(ID27_DR_k100);

        ID27_DR_k125 = new JTextField(properties.get_Property("ID27_DR_k125"));
        ID27_DR_k125.setBounds(120, 100, 570, 20);
        utilFactor.add(ID27_DR_k125);

        ID27_DR_k150 = new JTextField(properties.get_Property("ID27_DR_k150"));
        ID27_DR_k150.setBounds(120, 120, 570, 20);
        utilFactor.add(ID27_DR_k150);

        ID27_DR_k200 = new JTextField(properties.get_Property("ID27_DR_k200"));
        ID27_DR_k200.setBounds(120, 140, 570, 20);
        utilFactor.add(ID27_DR_k200);

        ID27_DR_k250 = new JTextField(properties.get_Property("ID27_DR_k250"));
        ID27_DR_k250.setBounds(120, 160, 570, 20);
        utilFactor.add(ID27_DR_k250);

        ID27_DR_k300 = new JTextField(properties.get_Property("ID27_DR_k300"));
        ID27_DR_k300.setBounds(120, 180, 570, 20);
        utilFactor.add(ID27_DR_k300);

        ID27_DR_k400 = new JTextField(properties.get_Property("ID27_DR_k400"));
        ID27_DR_k400.setBounds(120, 200, 570, 20);
        utilFactor.add(ID27_DR_k400);

        ID27_DR_k500 = new JTextField(properties.get_Property("ID27_DR_k500"));
        ID27_DR_k500.setBounds(120, 220, 570, 20);
        utilFactor.add(ID27_DR_k500);
    }

    /*
    Vykresľuje čast okna používateľskeho rozhrania, - vykresľuje
    časť "Measurement" ...
    Podobne, ako to bolo u konštruktora okna, sa tu nastavujú
    a inicializujú objekty okna ...
     */
    private void addMeasurementPart() throws IOException {
        JPanel panelButtons = new JPanel();
        panelButtons.setBackground(new Color(192, 192, 192));
        panelButtons.setBounds(10, 11, 200, 360);
        measurementInfo.add(panelButtons);
        panelButtons.setLayout(null);

        JPanel panelScreen = new JPanel();
        panelScreen.setBackground(new Color(169, 169, 169));
        panelScreen.setBounds(213, 32, 485, 300);
        measurementInfo.add(panelScreen);
        panelScreen.setLayout(new BorderLayout());

        JPanel panelScreenTextNorth = new JPanel();
        panelScreenTextNorth.setBounds(203, 11, 485, 20);
        panelScreenTextNorth.setLayout(null);
        JLabel measuremantScreen = new JLabel("Measurement State:");
        measuremantScreen.setBounds(200, 3, 149, 14);
        panelScreenTextNorth.add(measuremantScreen);
        measurementInfo.add(panelScreenTextNorth);

        JPanel panelButtonDown = new JPanel();
        panelButtonDown.setBounds(203, 315, 485, 50);
        panelButtonDown.setLayout(null);
        graphButton = new JButton("Results Graphs");
        graphButton.setBounds(10, 15, 230, 30);
        panelButtonDown.add(graphButton);
        graphButton.addActionListener(new resultGraphsListener());
        tableButton = new JButton("Results Table");
        tableButton.setBounds(250, 15, 230, 30);
        panelButtonDown.add(tableButton);
        tableButton.addActionListener(new resultTableListener());
        measurementInfo.add(panelButtonDown);

        measurementScreenArea = new JTextArea();
        measurementScreenArea.setEditable(false);
        measurementScreenArea.setBounds(15, 30, 462, 285);
        measurementScreenArea.setText("Welcome! You can start your measurement");
        JScrollPane screenScrollPane = new JScrollPane(measurementScreenArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        panelScreen.add(screenScrollPane);

        startButton = new JButton("Start");
        startButton.setBounds(8, 8, 90, 40);
        panelButtons.add(startButton);
        startButton.addActionListener(new startListener());

        stopButton = new JButton("Stop");
        stopButton.setBounds(100, 8, 90, 40);
        panelButtons.add(stopButton);
        stopButton.addActionListener(new stopListener());

        saveButton = new JButton("Save");
        saveButton.setBounds(8, 50, 90, 40);
        panelButtons.add(saveButton);
        saveButton.addActionListener(new saveListener());

        restoreButton = new JButton("Restore");
        restoreButton.setBounds(100, 50, 90, 40);
        panelButtons.add(restoreButton);
        restoreButton.addActionListener(new restoreListener());

        exitButton = new JButton("Exit");
        exitButton.setBounds(8, 315, 185, 40);
        panelButtons.add(exitButton);
        exitButton.addActionListener(new closeListener());

        subpanelButtons = new JPanel();
        subpanelButtons.setBounds(8,92, 185, 70 );
        panelButtons.add(subpanelButtons);
        UsbElements = new DefaultListModel<String>();
        UsbList = new JList<String>(UsbElements);
        USBports = serial.usbCommPortDescriptions();
        for (int i = 0; i < USBports.size(); i++) {
            UsbElements.addElement(USBports.get(i));
            if (serial.SelectPort(USBports.get(i))) {
                UsbList.setSelectedIndex(i);
            }
        }
        JScrollPane devicesScrollPane = new JScrollPane(UsbList);
        subpanelButtons.add(devicesScrollPane);

        JLabel multiplicationGammaText = new JLabel("Gamma Step:");
        multiplicationGammaText.setBounds(8, 176, 85, 25);
        panelButtons.add(multiplicationGammaText);
        ID7_Dg = new JTextField(properties.get_Property("ID7_Dg"));
        ID7_Dg.setBounds(100,176, 90, 25);
        panelButtons.add(ID7_Dg);

        JLabel multiplicationCplaneText = new JLabel("Cplane Step:");
        multiplicationCplaneText.setBounds(8, 199, 85, 25);
        panelButtons.add(multiplicationCplaneText);
        ID5_Dc = new JTextField(properties.get_Property("ID5_Dc"));
        ID5_Dc.setBounds(100,199, 90, 25);
        panelButtons.add(ID5_Dc);

        distanceText = new JLabel("Distance:");
        distanceText.setBounds(8, 223, 85, 25);
        panelButtons.add(distanceText);
        distance = new JTextField();
        distance.setBounds(100,223, 90, 25);
        panelButtons.add(distance);

        IlumQuestion = new JCheckBox("Calculate intensity?");
        IlumQuestion.setBounds(8, 252, 170,20);
        panelButtons.add(IlumQuestion);

        IluminationForLDT = new JCheckBox("Luminous intensity/LDT?");
        IluminationForLDT.setBounds(8, 272, 170,20);
        panelButtons.add(IluminationForLDT);

        CalculateFlux = new JCheckBox("Flux/LDT?");
        CalculateFlux.setBounds(8, 292, 170,20);
        panelButtons.add(CalculateFlux);
    }

    /*
    Vykresľuje čast okna používateľskeho rozhrania, - vykresľuje
    časť "General" ...
    Podobne, ako to bolo u konštruktora okna, sa tu nastavujú
    a inicializujú objekty okna ...
     */
    private void addGeneralPart() throws IOException {
        JPanel panelgeneralInfo = new JPanel();
        panelgeneralInfo.setBackground(new Color(192, 192, 192));
        panelgeneralInfo.setBounds(10, 11, 210, 360);
        generalInfo.add(panelgeneralInfo);
        panelgeneralInfo.setLayout(null);

        JLabel manufacturerText = new JLabel("Manufacturer:");
        manufacturerText.setBounds(10, 6, 194, 14);
        panelgeneralInfo.add(manufacturerText);

        JLabel typeIndicatorText = new JLabel("Type Indicator:");
        typeIndicatorText.setBounds(10, 31, 194, 14);
        panelgeneralInfo.add(typeIndicatorText);

        JLabel symetriIndicatorText = new JLabel("Symmetry indicator:");
        symetriIndicatorText.setBounds(10, 56, 194, 14);
        panelgeneralInfo.add(symetriIndicatorText);

        JLabel numbersOfCPlanesText = new JLabel("Numbers of C-planes:");
        numbersOfCPlanesText.setBounds(10, 81, 194, 14);
        panelgeneralInfo.add(numbersOfCPlanesText);

        JLabel numbersGammaAngleText = new JLabel("Numbers of gamma angles:");
        numbersGammaAngleText.setBounds(10, 106, 194, 14);
        panelgeneralInfo.add(numbersGammaAngleText);

        JLabel measurementReportnumberText = new JLabel("Measurement report number: ");
        measurementReportnumberText.setBounds(10, 131, 194, 14);
        panelgeneralInfo.add(measurementReportnumberText);

        JLabel luminaireNameText = new JLabel("Luminaire name: ");
        luminaireNameText.setBounds(10, 156, 194, 14);
        panelgeneralInfo.add(luminaireNameText);

        JLabel luminaireNumberText = new JLabel("Luminaire number:");
        luminaireNumberText.setBounds(10, 181, 194, 14);
        panelgeneralInfo.add(luminaireNumberText);

        JLabel fileNameText = new JLabel("File name:");
        fileNameText.setBounds(10, 206, 194, 14);
        panelgeneralInfo.add(fileNameText);

        JLabel datePersonText = new JLabel("Date/Person:");
        datePersonText.setBounds(10, 231, 194, 14);
        panelgeneralInfo.add(datePersonText);

        ID1_manufacturer = new JTextField(properties.get_Property("ID1_manufacturer"));
        ID1_manufacturer.setBounds(225, 12, 468, 20);
        generalInfo.add(ID1_manufacturer);

        ID2_type = new JComboBox();
        ID2_type.addItem("Point Source");
        ID2_type.addItem("Linear Luminaire");
        ID2_type.addItem("Another symetry");
        ID2_type.setBounds(225, 36, 468, 22);
        generalInfo.add(ID2_type);
        ID2_type.setSelectedItem(properties.get_Property("ID2_type"));

        ID3_symmetry = new JComboBox();
        ID3_symmetry.addItem("Without Symetry");
        ID3_symmetry.addItem("Vertical Symetry");
        ID3_symmetry.addItem("C0-C180 Symetry");
        ID3_symmetry.addItem("C90-C270 Symetry");
        ID3_symmetry.addItem("C0-C180 and C90-C270 Symetry");
        ID3_symmetry.setBounds(225, 61, 468, 22);
        generalInfo.add(ID3_symmetry);
        ID3_symmetry.setSelectedItem(properties.get_Property("ID3_symmetry"));

        ID4_Mc = new JTextField();
        ID4_Mc.setColumns(10);
        ID4_Mc.setBounds(225, 86, 468, 20);
        generalInfo.add(ID4_Mc);
        ID4_Mc.setEditable(false);

        ID6_Ng = new JTextField();
        ID6_Ng.setColumns(10);
        ID6_Ng.setBounds(225, 111, 468, 20);
        generalInfo.add(ID6_Ng);
        ID6_Ng.setEditable(false);

        ID8_measurementNumber = new JTextField(properties.get_Property("ID8_measurementNumber"));
        ID8_measurementNumber.setColumns(10);
        ID8_measurementNumber.setBounds(225, 136, 468, 20);
        generalInfo.add(ID8_measurementNumber);

        ID9_luminaireName = new JTextField(properties.get_Property("ID9_luminaireName"));
        ID9_luminaireName.setColumns(10);
        ID9_luminaireName.setBounds(225, 161, 468, 20);
        generalInfo.add(ID9_luminaireName);

        ID10_luminaireNumber = new JTextField(properties.get_Property("ID10_luminaireNumber"));
        ID10_luminaireNumber.setColumns(10);
        ID10_luminaireNumber.setBounds(225, 186, 468, 20);
        generalInfo.add(ID10_luminaireNumber);

        ID11_fileName = new JTextField(properties.get_Property("ID11_fileName"));
        ID11_fileName.setColumns(10);
        ID11_fileName.setBounds(225, 211, 468, 20);
        generalInfo.add(ID11_fileName);

        ID12_dateName = new JTextField(properties.get_Property("ID12_dateName"));
        ID12_dateName.setColumns(10);
        ID12_dateName.setBounds(225, 236, 468, 20);
        generalInfo.add(ID12_dateName);
    }

    /*
    Vykresľuje čast okna používateľskeho rozhrania, - vykresľuje
    časť "Luminaire" ...
    Podobne, ako to bolo u konštruktora okna, sa tu nastavujú
    a inicializujú objekty okna ...
     */
    private void addLuminairePart() throws IOException {
        JPanel panelLuminaire = new JPanel();
        panelLuminaire.setBackground(new Color(192, 192, 192));
        panelLuminaire.setBounds(7, 6, 254, 360);
        luminaire.add(panelLuminaire);
        panelLuminaire.setLayout(null);

        JLabel distanceOfLuminareText = new JLabel("Distance of luminare:");
        distanceOfLuminareText.setBounds(10, 8, 194, 14);
        panelLuminaire.add(distanceOfLuminareText);

        JLabel widthOfLuminareText = new JLabel("Width of luminare: ");
        widthOfLuminareText.setBounds(10, 33, 194, 14);
        panelLuminaire.add(widthOfLuminareText);

        JLabel heightOfLuminareText = new JLabel("Height of luminare:");
        heightOfLuminareText.setBounds(10, 58, 194, 14);
        panelLuminaire.add(heightOfLuminareText);

        JLabel diameterOfLuminousAreaText = new JLabel("Diameter of luminous area:");
        diameterOfLuminousAreaText.setBounds(10, 83, 194, 14);
        panelLuminaire.add(diameterOfLuminousAreaText);

        JLabel widthOfLuminousAreaText = new JLabel("Width of luminous area:");
        widthOfLuminousAreaText.setBounds(10, 108, 194, 14);
        panelLuminaire.add(widthOfLuminousAreaText);

        JLabel heightOfLuminousAreaC0 = new JLabel("Height of luminous area C0-plane:");
        heightOfLuminousAreaC0.setBounds(10, 133, 194, 14);
        panelLuminaire.add(heightOfLuminousAreaC0);

        JLabel heightOfLuminousAreaC90 = new JLabel("Height of luminous area C90-plane:");
        heightOfLuminousAreaC90.setBounds(10, 158, 194, 14);
        panelLuminaire.add(heightOfLuminousAreaC90);

        JLabel heightOfLuminousAreaC180 = new JLabel("Height of luminous area C180-plane:");
        heightOfLuminousAreaC180.setBounds(10, 183, 194, 14);
        panelLuminaire.add(heightOfLuminousAreaC180);

        JLabel heightOfLuminousAreaC270 = new JLabel("Height of luminous area C270-plane:");
        heightOfLuminousAreaC270.setBounds(10, 208, 194, 14);
        panelLuminaire.add(heightOfLuminousAreaC270);

        JLabel DFFtext = new JLabel("Downward flux fraction (DFF): ");
        DFFtext.setBounds(10, 233, 194, 14);
        panelLuminaire.add(DFFtext);

        JLabel outputRatioText = new JLabel("Light output ratio of luminaire:");
        outputRatioText.setBounds(10, 258, 220, 14);
        panelLuminaire.add(outputRatioText);

        JLabel conversionFactorText = new JLabel("Conversion factor for luminous intensities: ");
        conversionFactorText.setBounds(10, 283, 260, 14);
        panelLuminaire.add(conversionFactorText);

        JLabel titlLuminaireText = new JLabel("Tilt of luminaire during measurement:");
        titlLuminaireText.setBounds(10, 308, 220, 14);
        panelLuminaire.add(titlLuminaireText);

        ID13_luminaireLength = new JTextField(properties.get_Property("ID13_luminaireLength"));
        ID13_luminaireLength.setBounds(270, 10, 420, 20);
        luminaire.add(ID13_luminaireLength);

        ID14_luminaireWidth = new JTextField(properties.get_Property("ID14_luminaireWidth"));
        ID14_luminaireWidth.setBounds(270, 35, 420, 20);
        luminaire.add(ID14_luminaireWidth);

        ID15_luminaireHeight = new JTextField(properties.get_Property("ID15_luminaireHeight"));
        ID15_luminaireHeight.setBounds(270, 60, 420, 20);
        luminaire.add(ID15_luminaireHeight);

        ID16_luminaireArea = new JTextField(properties.get_Property("ID16_luminaireArea"));
        ID16_luminaireArea.setBounds(270, 85, 420, 20);
        luminaire.add(ID16_luminaireArea);

        ID17_widthLuminaireArea = new JTextField(properties.get_Property("ID17_widthLuminaireArea"));
        ID17_widthLuminaireArea.setBounds(270, 110, 420, 20);
        luminaire.add(ID17_widthLuminaireArea);

        ID18_heightLiminaireAreaC0 = new JTextField(properties.get_Property("ID18_heightLiminaireAreaC0"));
        ID18_heightLiminaireAreaC0.setBounds(270, 135, 420, 20);
        luminaire.add(ID18_heightLiminaireAreaC0);

        ID19_heightLiminaireAreaC90 = new JTextField(properties.get_Property("ID19_heightLiminaireAreaC90"));
        ID19_heightLiminaireAreaC90.setBounds(270, 160, 420, 20);
        luminaire.add(ID19_heightLiminaireAreaC90);

        ID20_heightLiminaireAreaC180 = new JTextField(properties.get_Property("ID20_heightLiminaireAreaC180"));
        ID20_heightLiminaireAreaC180.setBounds(270, 185, 420, 20);
        luminaire.add(ID20_heightLiminaireAreaC180);

        ID21_heightLiminaireAreaC270 = new JTextField(properties.get_Property("ID21_heightLiminaireAreaC270"));
        ID21_heightLiminaireAreaC270.setBounds(270, 210, 420, 20);
        luminaire.add(ID21_heightLiminaireAreaC270);

        ID22_DFF = new JTextField(properties.get_Property("ID22_DFF"));
        ID22_DFF.setBounds(270, 235, 420, 20);
        luminaire.add(ID22_DFF);

        ID23_LORL = new JTextField(properties.get_Property("ID23_LORL"));
        ID23_LORL.setBounds(270, 260, 420, 20);
        luminaire.add(ID23_LORL);

        ID24_conversionFactor = new JTextField(properties.get_Property("ID24_conversionFactor"));
        ID24_conversionFactor.setBounds(270, 285, 420, 20);
        luminaire.add(ID24_conversionFactor);

        ID25_tiltLuinaire = new JTextField(properties.get_Property("ID25_tiltLuinaire"));
        ID25_tiltLuinaire.setBounds(270, 310, 420, 20);
        luminaire.add(ID25_tiltLuinaire);
    }

    /*
    Vykresľuje čast okna používateľskeho rozhrania, - vykresľuje
    časť "Lamps" ...
    Podobne, ako to bolo u konštruktora okna, sa tu nastavujú
    a inicializujú objekty okna ...
     */
    private void addLampsPart() throws IOException {
        JPanel panelLamps = new JPanel();
        panelLamps.setBackground(new Color(192, 192, 192));
        panelLamps.setBounds(10, 11, 200, 360);
        lamps.add(panelLamps);
        panelLamps.setLayout(null);

        JLabel numberLampsText = new JLabel("Number of sources:");
        numberLampsText.setBounds(10, 20, 194, 14);
        panelLamps.add(numberLampsText);

        JLabel typeOfLampText = new JLabel("Type of lamps: ");
        typeOfLampText.setBounds(10, 45, 194, 14);
        panelLamps.add(typeOfLampText);

        JLabel totalFluxText = new JLabel("Total luminous flux of lamps:");
        totalFluxText.setBounds(10, 70, 220, 14);
        panelLamps.add(totalFluxText);

        JLabel temperatureLampText = new JLabel("Color temperature of lamps:");
        temperatureLampText.setBounds(10, 95, 194, 14);
        panelLamps.add(temperatureLampText);

        JLabel renderingIndexText = new JLabel("Color rendering index:");
        renderingIndexText.setBounds(10, 120, 194, 14);
        panelLamps.add(renderingIndexText);

        JLabel powerText = new JLabel("Total connected power:");
        powerText.setBounds(10, 145, 194, 14);
        panelLamps.add(powerText);

        ID26a_numberOfLamp = new JTextField(properties.get_Property("ID26a_numberOfLamp"));
        ID26a_numberOfLamp.setBounds(220, 26, 468, 20);
        lamps.add(ID26a_numberOfLamp);

        ID26b_typeOfLamp = new JTextField(properties.get_Property("ID26b_typeOfLamp"));
        ID26b_typeOfLamp.setBounds(220, 51, 468, 20);
        lamps.add(ID26b_typeOfLamp);

        ID26c_fluxOfLamp = new JTextField(properties.get_Property("ID26c_fluxOfLamp"));
        ID26c_fluxOfLamp.setBounds(220, 76, 468, 20);
        lamps.add(ID26c_fluxOfLamp);

        ID26d_ColorTemperatureOfLamp = new JTextField(properties.get_Property("ID26d_ColorTemperatureOfLamp"));
        ID26d_ColorTemperatureOfLamp.setColumns(10);
        ID26d_ColorTemperatureOfLamp.setBounds(220, 101, 468, 20);
        lamps.add(ID26d_ColorTemperatureOfLamp);

        ID26e_colorRenderingIndex = new JTextField(properties.get_Property("ID26e_colorRenderingIndex"));
        ID26e_colorRenderingIndex.setBounds(220, 126, 468, 20);
        lamps.add(ID26e_colorRenderingIndex);

        ID26f_allPowerSupply = new JTextField(properties.get_Property("ID26f_allPowerSupply"));
        ID26f_allPowerSupply.setBounds(220, 151, 468, 20);
        lamps.add(ID26f_allPowerSupply);

        addLampSet = new JButton("Add Lamp Set");
        addLampSet.setBounds(220, 180, 140, 20);
        addLampSet.addActionListener(new addSet());
        lamps.add(addLampSet);

        deleteLampSet = new JButton("Delete Lamp Set");
        deleteLampSet.setBounds(373, 180, 140, 20);
        deleteLampSet.addActionListener(new deleteSet());
        lamps.add(deleteLampSet);

        deleteAll = new JButton("Delete All Sets");
        deleteAll.setBounds(526, 180, 140, 20);
        deleteAll.addActionListener(new deleteAll());
        lamps.add(deleteAll);

    }

    /*
    Funkcia, ktorá sprístupňuje funkčnosť vybraných objektov okna rozhrania,
    v závislosti na parametry, tejto funkcie, je možné objekty okna zneprístupniť (false),
    alebo naopak sprístupniť (true) ...
     */
    public void clickEnableFunction(boolean b) {

        JButton[] jButtons = {startButton, saveButton, restoreButton, exitButton, tableButton, graphButton, stopButton, addLampSet,
                deleteLampSet, deleteAll};
        JMenuItem[] jMenuItems = {startMenuItem, exitMenuItem, saveMenuItem, restoreMenuItem, savePathMenuItem, stopMenuItem, refreshMenuItem};
        JTextField[] jTextFields = {ID1_manufacturer, ID5_Dc, ID7_Dg, ID8_measurementNumber, ID9_luminaireName, ID10_luminaireNumber,
                ID11_fileName, ID12_dateName, ID13_luminaireLength, ID14_luminaireWidth, ID15_luminaireHeight, ID17_widthLuminaireArea,
                ID18_heightLiminaireAreaC0, ID19_heightLiminaireAreaC90, ID20_heightLiminaireAreaC180, ID21_heightLiminaireAreaC270,
                ID22_DFF, ID23_LORL, ID24_conversionFactor, ID25_tiltLuinaire, ID26a_numberOfLamp, ID26b_typeOfLamp, ID26c_fluxOfLamp,
                ID26d_ColorTemperatureOfLamp, ID26e_colorRenderingIndex, ID26f_allPowerSupply, ID16_luminaireArea, distance, ID27_DR_k060,
                ID27_DR_k080, ID27_DR_k100, ID27_DR_k125, ID27_DR_k150, ID27_DR_k200, ID27_DR_k250, ID27_DR_k300, ID27_DR_k400, ID27_DR_k500};
        JComboBox[] jComboBoxes = {ID2_type, ID3_symmetry};

        for (JButton jButton : jButtons) {
            if(jButton == stopButton){
                jButton.setEnabled(!b);
            }else{
                jButton.setEnabled(b);
            }
        }

        for (JMenuItem items : jMenuItems) {
            if(items == stopMenuItem){
                items.setEnabled(!b);
            }else{
                items.setEnabled(b);
            }
        }

        for (JTextField field : jTextFields) {
            field.setEditable(b);
        }

        for (JComboBox jComboBox : jComboBoxes) {
            jComboBox.setEnabled(b);
        }

        IlumQuestion.setEnabled(b);
        IluminationForLDT.setEnabled(b);
        CalculateFlux.setEnabled(b);
    }

    /*
    Funkcie "show(String s)" a "clean()" slúžia na vypísanie/vymazanie
    textových údajov, ktoré sa zobrazujú na panely "screen" (JTextArea) ...
     */
    public void show(String s) {
        measurementScreenArea.append(s);
    }

    public void clean() {
        measurementScreenArea.append("");
    }

    /*
    "Gettery" - umožňujú vytiahnuť informácie, ktoré je následne nutné
    použiť v ďalších častiach programu, či už sa jedná o bežné
    vypisovanie textu, z textových polí alebo povolenia (boolean),
    pre ďalšie kroky v programe (procese merania) ...
     */
    public boolean getIlumQuestion(){
        return IlumQuestion.isSelected();
    }

    public boolean getIluminationForLDT(){
        return IluminationForLDT.isSelected();
    }

    public boolean getCalculateFlux(){
        return CalculateFlux.isSelected();
    }

    public String getID1_manufacturer(){
        return ID1_manufacturer.getText();
    }

    public String getID2_type(){
        return String.valueOf(ID2_type.getSelectedIndex() + 1);
    }

    public String getID3_symmetry(){
        return String.valueOf(ID3_symmetry.getSelectedIndex());
    }

    public String getID5_Dc(){
        return ID5_Dc.getText();
    }

    public String getID7_Dg(){
        return ID7_Dg.getText();
    }

    public String getID8_measurementNumber(){
        return ID8_measurementNumber.getText();
    }

    public String getID9_luminaireName(){
        return ID9_luminaireName.getText();
    }

    public String getID10_luminaireNumber(){
        return ID10_luminaireNumber.getText();
    }

    public String getID11_fileName(){
        return ID11_fileName.getText();
    }

    public String getID12_dateName(){
        return ID12_dateName.getText();
    }

    public String getID13_luminaireLength(){
        return ID13_luminaireLength.getText();
    }

    public String getID14_luminaireWidth(){
        return ID14_luminaireWidth.getText();
    }

    public String getID15_luminaireHeight(){
        return ID15_luminaireHeight.getText();
    }

    public String getID16_luminaireArea(){
        return ID16_luminaireArea.getText();
    }

    public String getID17_widthLuminaireArea(){
        return ID17_widthLuminaireArea.getText();
    }

    public String getID18_heightLiminaireAreaC0(){
        return ID18_heightLiminaireAreaC0.getText();
    }

    public String getID19_heightLiminaireAreaC90(){
        return ID19_heightLiminaireAreaC90.getText();
    }

    public String getID20_heightLiminaireAreaC180(){
        return ID20_heightLiminaireAreaC180.getText();
    }

    public String getID21_heightLiminaireAreaC270(){
        return ID21_heightLiminaireAreaC270.getText();
    }

    public String getID22_DFF(){
        return ID22_DFF.getText();
    }

    public String getID23_LORL(){
        return ID23_LORL.getText();
    }

    public String getID24_conversionFactor(){
        return ID24_conversionFactor.getText();
    }

    public String getID25_tiltLuinaire(){
        return ID25_tiltLuinaire.getText();
    }

    public static ArrayList<LampsSets> getID26_lamps(){
        return ID26_lamps;
    }

    public String getDistanceValue(){
        return distance.getText();
    }

    public String getID27_DR_k060(){
        return ID27_DR_k060.getText();
    }

    public String getID27_DR_k080(){
        return ID27_DR_k080.getText();
    }

    public String getID27_DR_k100(){
        return ID27_DR_k100.getText();
    }

    public String getID27_DR_k125(){
        return ID27_DR_k125.getText();
    }

    public String getID27_DR_k150(){
        return ID27_DR_k150.getText();
    }

    public String getID27_DR_k200(){
        return ID27_DR_k200.getText();
    }

    public String getID27_DR_k250(){
        return ID27_DR_k250.getText();
    }

    public String getID27_DR_k300(){
        return ID27_DR_k300.getText();
    }

    public String getID27_DR_k400(){
        return ID27_DR_k400.getText();
    }

    public String getID27_DR_k500(){
        return ID27_DR_k500.getText();
    }


    /*
    Trieda umožňujúca vypnutie programu ... zobrazuje dialógové okno, ktoré
    dá používateľovi možnosti "YES", "NO" ... v prípade možnosti "YES" sa
    program používateľského rozhrania vypne ...
     */
    private class closeProgram implements WindowListener, ActionListener {
        @Override
        public void windowOpened(WindowEvent e) {

        }

        @Override
        public void windowClosing(WindowEvent e) {
            String[] options = {"YES", "NO"};

            int choice = JOptionPane.showOptionDialog(Window.this, "Are you sure you want to quit GUI program?", "Attention", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if(choice == JOptionPane.YES_OPTION){
                if(measurementProcessOnQuestion){
                    mThread.stopMeasurementThread();
                    try {
                        mThread.join();
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                    System.exit(0);
                }else {
                    System.exit(0);
                }
            }
        }

        @Override
        public void windowClosed(WindowEvent e) {

        }

        @Override
        public void windowIconified(WindowEvent e) {

        }

        @Override
        public void windowDeiconified(WindowEvent e) {

        }

        @Override
        public void windowActivated(WindowEvent e) {

        }

        @Override
        public void windowDeactivated(WindowEvent e) {

        }

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    }

    /*
    Trieda, ktorá za určitých podmienok, vytvorí objekt triedy "ThreadM" a
    spustí meranie ...
    Meranie sa sputí v prípade, ak je správne nastavená cesta, do existujúcej
    zložky v systéme, a v prípade dodržania postupu merania, čo v praxi
    znamená ... nastavenie napr. prepočtu na svietivosť (v tomto prípade
    je nutné uviesť, do vyhradeného textového poľa hodnotu vzdialenosti
    senzora v metroch! ... inak meranie nemôže byť spustené ... )
     */
    private class startListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {

            if (ID26_lamps.size()<1){
                LampsSets lampsSet = null;
                try {
                    lampsSet = new LampsSets(properties.get_Property("ID26a_numberOfLamp"), properties.get_Property("ID26b_typeOfLamp"), properties.get_Property("ID26c_fluxOfLamp"),
                            properties.get_Property("ID26d_ColorTemperatureOfLamp"), properties.get_Property("ID26e_colorRenderingIndex"), properties.get_Property("ID26f_allPowerSupply"));
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                ID26_lamps.add(lampsSet);
            }

            try {
                if (Files.exists(Paths.get(properties.get_Property("File Path")))) {
                    if (IlumQuestion.isSelected() && !distance.getText().equalsIgnoreCase("")){
                        try {
                            if (serial.SelectPort(UsbList.getSelectedValue())) {
                                mThread = new ThreadM(Window.this, answear, serial, properties);
                                mThread.startThread();
                                measurementProcessOnQuestion = true;
                            }else{
                                show("\nCan not START the Thread due to incorrect USB connection");
                            }
                        } catch (Exception e1) {
                            JOptionPane.showMessageDialog(Window.this, "Can not start the measurement process");
                        }
                    }else if(!IlumQuestion.isSelected()){
                        try {
                            if (serial.SelectPort(UsbList.getSelectedValue())) {
                                mThread = new ThreadM(Window.this, answear, serial, properties);
                                mThread.startThread();
                                measurementProcessOnQuestion = true;
                            }else{
                                show("\nCan not START the Thread due to incorrect USB connection");
                            }
                        } catch (Exception e1) {
                            JOptionPane.showMessageDialog(Window.this, "Can not start the measurement process");
                        }
                    }else{
                        JOptionPane.showMessageDialog(Window.this, "Add the Distance value, or unselect the Luminance box");
                    }


                    {
                        try {
                            factor = Integer.valueOf((ID5_Dc.getText()));
                            gammaFactor = Integer.valueOf(ID7_Dg.getText());
                        } catch (Exception e2) {
                            e2.printStackTrace();
                        }
                    }
                }
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(null, "ERROR");
            }
        }
    }

    /*
    Trieda umožňujúca vypnutie Threadu merania ...po stlačení tlačidla
    je v prípade, ak existuje objekt mThread, aktivovaná funkcia
    "stopMeasurementThread()", ktorá spôsobí ukončenie meracieho
    procesu, zároveň sa na JTextScreen (obrazovke), vypíše správa
    pre užívateľa, ktorá ho informuje, o ukončení merania ...
     */
    private class stopListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (mThread != null){
                mThread.stopMeasurementThread();
                show("\nMeasuremant will be STOP!");
            }
            measurementProcessOnQuestion = false;
        }
    }

    /*
    Trieda po stlačení tlačidla ukladá hodnoty jednotlivých
    parametrov, a zapisuje do nich hodnoty v podobe reťazcov
    vpísaných do textových polí používateľského rozhrania ...
     */
    private class saveListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                properties.set_Property("ID1_manufacturer", ID1_manufacturer.getText());
                properties.set_Property("ID2_type", String.valueOf(ID2_type.getSelectedIndex()));
                properties.set_Property("ID3_symmetry", String.valueOf(ID3_symmetry.getSelectedIndex()));
                properties.set_Property("ID5_Dc", String.valueOf(ID5_Dc.getText()));
                properties.set_Property("ID7_Dg", String.valueOf(ID7_Dg.getText()));
                properties.set_Property("ID8_measurementNumber", String.valueOf(ID8_measurementNumber.getText()));
                properties.set_Property("ID9_luminaireName", ID9_luminaireName.getText());
                properties.set_Property("ID10_luminaireNumber", ID10_luminaireNumber.getText());
                properties.set_Property("ID11_fileName", ID11_fileName.getText());
                properties.set_Property("ID12_dateName", ID12_dateName.getText());
                properties.set_Property("ID13_luminaireLength", ID13_luminaireLength.getText());
                properties.set_Property("ID14_luminaireWidth", ID14_luminaireWidth.getText());
                properties.set_Property("ID15_luminaireHeight", ID15_luminaireHeight.getText());
                properties.set_Property("ID16_luminaireArea", ID16_luminaireArea.getText());
                properties.set_Property("ID17_widthLuminaireArea", ID17_widthLuminaireArea.getText());
                properties.set_Property("ID18_heightLiminaireAreaC0", ID18_heightLiminaireAreaC0.getText());
                properties.set_Property("ID19_heightLiminaireAreaC90", ID19_heightLiminaireAreaC90.getText());
                properties.set_Property("ID20_heightLiminaireAreaC180", ID20_heightLiminaireAreaC180.getText());
                properties.set_Property("ID21_heightLiminaireAreaC270", ID21_heightLiminaireAreaC270.getText());
                properties.set_Property("ID22_DFF", ID22_DFF.getText());
                properties.set_Property("ID23_LORL", ID23_LORL.getText());
                properties.set_Property("ID24_conversionFactor", ID24_conversionFactor.getText());
                properties.set_Property("ID25_tiltLuinaire", ID25_tiltLuinaire.getText());
                properties.set_Property("ID26a_numberOfLamp", ID26a_numberOfLamp.getText());
                properties.set_Property("ID26b_typeOfLamp", ID26b_typeOfLamp.getText());
                properties.set_Property("ID26c_fluxOfLamp", ID26c_fluxOfLamp.getText());
                properties.set_Property("ID26d_ColorTemperatureOfLamp", ID26d_ColorTemperatureOfLamp.getText());
                properties.set_Property("ID26e_colorRenderingIndex", ID26e_colorRenderingIndex.getText());
                properties.set_Property("ID26f_allPowerSupply", ID26f_allPowerSupply.getText());
                properties.set_Property("ID27_DR_k060", ID27_DR_k060.getText());
                properties.set_Property("ID27_DR_k080", ID27_DR_k080.getText());
                properties.set_Property("ID27_DR_k100", ID27_DR_k100.getText());
                properties.set_Property("ID27_DR_k125", ID27_DR_k125.getText());
                properties.set_Property("ID27_DR_k150", ID27_DR_k150.getText());
                properties.set_Property("ID27_DR_k200", ID27_DR_k200.getText());
                properties.set_Property("ID27_DR_k125", ID27_DR_k250.getText());
                properties.set_Property("ID27_DR_k150", ID27_DR_k300.getText());
                properties.set_Property("ID27_DR_k200", ID27_DR_k400.getText());
                properties.set_Property("ID27_DR_k200", ID27_DR_k500.getText());
                if (!UsbElements.isEmpty()){
                    properties.set_Property("USBport", UsbElements.getElementAt(0));
                }else{
                    show("\nCan not store the USB ... probably it is not connected");
                }
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(Window.this, "Can not save the values to Property file!\n");
            }
        }
    }

    /*
    Trieda, ktorá prostredníctvom "showMessageDialog" zobrazuje správu pre
    používateľa ... aktivuje sa v prípade stlačenia "záložky : INFO" (JMenuItem)
     */
    private class infoListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(Window.this, "Dear User, welcome in the User Interface Program (GUI - Goniofotometer).\nThese program was developed as a part of the master thesis, on University of Technology in Brno.\nForm more information please contact the developer Bc. Martin Ivor.");
        }
    }

    /*
    Trieda po stlačení tlačidla preberá hodnoty z uloženého textového
    súboru, a nastavuje hodnoty do prísločných textových polí,
    "key-value" ...
     */
    private class restoreListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                properties.undoProperties();
                ID1_manufacturer.setText(properties.get_Property("ID1_manufacturer"));
                properties.set_Property("ID2_type", "0");
                ID2_type.getItemAt(0);
                properties.set_Property("ID3_symmetry", "0");
                ID3_symmetry.getItemAt(0);
                ID5_Dc.setText(properties.get_Property("ID5_Dc"));
                ID7_Dg.setText(properties.get_Property("ID7_Dg"));
                ID8_measurementNumber.setText(properties.get_Property("ID8_measurementNumber"));
                ID9_luminaireName.setText(properties.get_Property("ID9_luminaireName"));
                ID10_luminaireNumber.setText(properties.get_Property("ID10_luminaireNumber"));
                ID11_fileName.setText(properties.get_Property("ID11_fileName"));
                ID12_dateName.setText(properties.get_Property("ID12_dateName"));
                ID13_luminaireLength.setText(properties.get_Property("ID13_luminaireLength"));
                ID14_luminaireWidth.setText(properties.get_Property("ID14_luminaireWidth"));
                ID15_luminaireHeight.setText(properties.get_Property("ID15_luminaireHeight"));
                ID16_luminaireArea.setText(properties.get_Property("ID16_luminaireArea"));
                ID17_widthLuminaireArea.setText(properties.get_Property("ID17_widthLuminaireArea"));
                ID18_heightLiminaireAreaC0.setText(properties.get_Property("ID18_heightLiminaireAreaC0"));
                ID19_heightLiminaireAreaC90.setText(properties.get_Property("ID19_heightLiminaireAreaC90"));
                ID20_heightLiminaireAreaC180.setText(properties.get_Property("ID20_heightLiminaireAreaC180"));
                ID21_heightLiminaireAreaC270.setText(properties.get_Property("ID21_heightLiminaireAreaC270"));
                ID22_DFF.setText(properties.get_Property("ID22_DFF"));
                ID23_LORL.setText(properties.get_Property("ID23_LORL"));
                ID24_conversionFactor.setText(properties.get_Property("ID24_conversionFactor"));
                ID25_tiltLuinaire.setText(properties.get_Property("ID25_tiltLuinaire"));
                ID27_DR_k060.setText(properties.get_Property("ID27_DR_k060"));
                ID27_DR_k080.setText(properties.get_Property("ID27_DR_k080"));
                ID27_DR_k100.setText(properties.get_Property("ID27_DR_k100"));
                ID27_DR_k125.setText(properties.get_Property("ID27_DR_k125"));
                ID27_DR_k150.setText(properties.get_Property("ID27_DR_k150"));
                ID27_DR_k200.setText(properties.get_Property("ID27_DR_k200"));
                ID27_DR_k250.setText(properties.get_Property("ID27_DR_k250"));
                ID27_DR_k300.setText(properties.get_Property("ID27_DR_k300"));
                ID27_DR_k400.setText(properties.get_Property("ID27_DR_k400"));
                ID27_DR_k500.setText(properties.get_Property("ID27_DR_k500"));
                ID26a_numberOfLamp.setText(properties.get_Property("ID26a_numberOfLamp"));
                ID26b_typeOfLamp.setText(properties.get_Property("ID26b_typeOfLamp"));
                ID26c_fluxOfLamp.setText(properties.get_Property("ID26c_fluxOfLamp"));
                ID26d_ColorTemperatureOfLamp.setText(properties.get_Property("ID26d_ColorTemperatureOfLamp"));
                ID26e_colorRenderingIndex.setText(properties.get_Property("ID26e_colorRenderingIndex"));
                ID26f_allPowerSupply.setText(properties.get_Property("ID26f_allPowerSupply"));

            } catch(IOException ex){
                    JOptionPane.showMessageDialog(Window.this, "Can not restore the values from Property file!\n");
                }
            }
        }

    /*
    Trieda, zakladajúca objekt okna grafov, ktorá vzniká stlačením
    tlačidla "Result Graphs" ... týmto sa aktivuje konštruktor
    danej triedy, čo má za následok zobrazenie okna s výberom
    zachytených grafov ... možnosť stlačenia tlačidla, sa však
    aktivuje až po ukončení merania, pretože je funkčnosť tlačidiel
    v priebehu meracieho procesu obmedzená funkciou "clickEnableFunction(boolean b)"
     */
    private class resultGraphsListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            GraphsWindow graphWindow = null;
            try {
                if(getIluminationForLDT() && getCalculateFlux()){
                    JOptionPane.showMessageDialog(Window.this, "Can not create graph due to incorrect lux selection!");
                }else{
                    graphWindow = new GraphsWindow(Window.this, Window.this);
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            graphWindow.setVisible(true);
        }
    }

    /*
    Trieda, zakladajúca objekt okna s tabuľkou, ktorá vzniká stlačením
    tlačidla "Result Table" ... týmto sa aktivuje konštruktor
    danej triedy, čo má za následok zobrazenie okna s tabuľkou,
    ktorá zaznamenáva hodnoty svietivosti zdroja,... možnosť stlačenia
    tlačidla, sa však aktivuje až po ukončení merania, pretože je
    funkčnosť tlačidiel v priebehu meracieho procesu obmedzená
    funkciou "clickEnableFunction(boolean b)"
     */
    private class resultTableListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            TableWindow tableWindow = null;
            try {
                if(getIluminationForLDT() && getCalculateFlux()){
                    JOptionPane.showMessageDialog(Window.this, "Can not create table due to incorrect lux selection!");
                }else{
                    tableWindow = new TableWindow(Window.this, Window.this);
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            tableWindow.setVisible(true);
        }
    }

    /*
     Trieda umožňujúca vypnutie programu ... zobrazuje dialógové okno, ktoré
     dá používateľovi možnosti "YES", "NO" ... v prípade možnosti "YES" sa
     program používateľského rozhrania vypne ...
      */
    private class closeListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            String[] options = {"YES", "NO"};

            int choice = JOptionPane.showOptionDialog(Window.this, "Are you sure you want to quit GUI program?", "Attention", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if(choice == JOptionPane.YES_OPTION){
                if(measurementProcessOnQuestion){
                    mThread.stopMeasurementThread();
                    show("\nMeasurement will be STOP!");
                    try {
                        mThread.join();
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                    System.exit(0);
                }else{
                        System.exit(0);
                    }
            }
        }
    }

    /*
    Trieda umožňujúca nastavenie cesty do zložky, do ktorej
    sa majú ukladať súbory ...
     */
    private class pathMenuItem implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            jFileChooser = new JFileChooser();
            try {
                jFileChooser.setCurrentDirectory(new File(properties.get_Property("File Path")));
                jFileChooser.setDialogTitle("Choose a Path where you wish to save measure file!");
                jFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                if (jFileChooser.showOpenDialog(Window.this) == JFileChooser.APPROVE_OPTION){
                    File selectedFile = jFileChooser.getSelectedFile();
                    String fileStringPath = selectedFile.getPath();
                    properties.set_Property("File Path", fileStringPath);
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

    /*
    Trieda umožňuje, v prípadestlačenie zodpovedajúceho JMenuItem,
    znovu načitať list s prítonými USB portami ...
     */
    private class refreshMenuItem implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {

            boolean flag = false;
            serial.getPorts();
            USBports = serial.usbCommPortDescriptions();
            if (USBports.size() == 0 || USBports == null){
                UsbElements.clear();
            }else{
                for (int i = 0; i < USBports.size(); i++) {
                    if (!UsbElements.isEmpty()){
                        if(!UsbElements.get(i).equals(USBports.get(i))){
                            flag = true;
                        }
                        if(flag){
                            UsbElements.addElement(USBports.get(i));
                            UsbList.setSelectedIndex(i);
                        }
                    }else{
                        UsbElements.addElement(USBports.get(i));
                        UsbList.setSelectedIndex(i);
                    }
                }
            }
        }
    }

    /*
    Nasledujuce triedy, umožňujú vkladať sety, so zdrojmi,
    a manipulovať s nimi, tak aby bolo možné ich vymazanie atď. ...
     */
    private class addSet implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {

            LampsSets lampsSet = new LampsSets(ID26a_numberOfLamp.getText(), ID26b_typeOfLamp.getText(), ID26c_fluxOfLamp.getText(),
                    ID26d_ColorTemperatureOfLamp.getText(), ID26e_colorRenderingIndex.getText(), ID26f_allPowerSupply.getText());

            ID26_lamps.add(lampsSet);
        }
    }

    private class deleteSet implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            ID26_lamps.remove(ID26_lamps.size() - 1);
        }
    }

    private class deleteAll implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            ID26_lamps.clear();
        }
    }
}

