package com.its.vms.ui;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.its.vms.domain.NET;
import com.its.vms.dto.TbVmsCtlrDto;
import com.its.vms.entity.TbVmsCtlrStts;
import com.its.vms.xnettcp.vms.process.TcpServerSendData;
import com.its.vms.xnettcp.vms.protocol.enums.eVmsOpCode;
import com.its.vms.xnettcp.vms.protocol.impl.VmsReqStatusControl;
import com.sun.management.OperatingSystemMXBean;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.StyleContext;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@Slf4j
@Getter
public abstract class SubUI {
    OperatingSystemMXBean osBean = null;
    private TbVmsCtlrDto selObj = null;

    private JPanel rootPanel;
    private JPanel pnlCtlr;
    private JTextArea taLog;
    private JPanel pnlControl;
    private JButton btnReqFan;
    private JButton btnReqHeater;
    private JButton btnSignBoardOn;
    private JButton btnSignBoardOff;
    private JTextField txtName;
    private JTextField txtNmbr;
    private JTextField txtPort;
    private JTextField txtIpAddr;
    private JTextField txtDoor;
    private JTextField txtFan;
    private JTextField txtHeater;
    private JTextField txtTemp;
    private JTextField txtState;
    private JButton btnLogClear;
    private JTextField txtCtlrId;
    private JButton btnReqStatus;
    private JButton btnReqParam;
    private JButton btnScnDnld;
    private JButton btnTimeSync;
    private JComboBox cboControl;
    private JSpinner spControl;
    private JButton btnSymbDnld;
    private JButton btnReserved;

    protected abstract void actionButtonClicked();

    public SubUI() {
        System.setProperty("awt.useSystemAAFontSettings", "false"); // AntiAliasing false

        osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
        try {
            Font font = Font.createFont(Font.TRUETYPE_FONT, new File("fonts/D2Coding.ttc"));
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            ge.registerFont(font);
        } catch (FontFormatException | IOException e) {
        }

        Font d2font = new Font("D2Coding", Font.PLAIN, 12);
        taLog.setFont(d2font);

        txtPort.setVisible(false);
        btnReserved.setVisible(false);
        SpinnerModel value = new SpinnerNumberModel(0, 0, 100, 1);
        spControl.setModel(value);

        btnLogClear.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                taLog.setText(null);
            }
        });
        btnReqStatus.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusControl(1);   // 상태정보요청
            }
        });
        btnReqParam.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusControl(2);   // 파라미터정보요청
            }
        });
        btnScnDnld.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusControl(3);   // 시나리오 다운로드
            }
        });
        btnTimeSync.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusControl(4);   // 시간설정
            }
        });
        btnSignBoardOff.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusControl(5);   // 전광판 OFF
            }
        });
        btnSignBoardOn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusControl(6);   // 전광판 ON
            }
        });
        btnReqFan.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusControl(7);   // FAN 제어
            }
        });
        btnReqHeater.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                statusControl(8);   // HEATER 제어
            }
        });
        btnSymbDnld.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selObj == null) {
                    return;
                }
                String message = "심벌라이브러리 다운로드를 요청하시겠습니까?\n\r시스템에 영향을 줄 수 있습니다.";
                String title = "심벌라이브러리 다운로드";
                if (JOptionPane.showConfirmDialog(getRootPanel(), message, title, JOptionPane.YES_NO_OPTION) != 0) {
                    return;
                }
                selObj.getDnldSymbMap().clear();
                message = "심벌라이브러리 다운로드를 요청하였습니다.\n\r시스템 운영에 따라 심벌라이브러리를 다운로드 합니다.";
                JOptionPane.showMessageDialog(getRootPanel(), message, title, JOptionPane.YES_OPTION);
            }
        });
    }

    public void statusControl(int controlType) {
        if (this.selObj == null) {
            JOptionPane.showMessageDialog(getRootPanel(), "제어기가 선택되지 않았습니다. 목록을 더블클릭하여 제어기를 선택하세요.", "제어기 선택", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (this.selObj.getNetState() == NET.CLOSED) {
            JOptionPane.showMessageDialog(getRootPanel(), "제어기가 현재 연결이 되어 있지 않습니다.", "제어기 연결 상태", JOptionPane.ERROR_MESSAGE);
            return;
        }

        String message = "";
        String title = "제어기 상태 제어";
        switch (controlType) {
            case 1:
                message = "제어기의 상태정보를 요청 하시겠습니까?";
                break;
            case 2:
                message = "제어기의 파라미터정보를 요청 하시겠습니까?";
                break;
            case 3:
                message = "제어기의 표출 시나리오를 다운로드 하시겠습니까?";
                break;
            case 4:
                message = "제어기의 시간 정보를 설정 하시겠습니까?";
                break;
            case 5:
                message = "제어기의 전광판 전원을 OFF 하시겠습니까?";
                break;
            case 6:
                message = "제어기의 전광판 전원을 ON 하시겠습니까?";
                break;
            case 7:
                message = "제어기의 FAN 을 제어 하시겠습니까?";
                break;
            case 8:
                message = "제어기의 HEATER 를 제어 하시겠습니까?";
                break;
            default:
                return;
        }
        if (JOptionPane.showConfirmDialog(getRootPanel(), message, title, JOptionPane.YES_NO_OPTION) != 0) {
            return;
        }

        VmsReqStatusControl statusControl = new VmsReqStatusControl(this.selObj);
        switch (controlType) {
            case 1:
                this.selObj.addRequestData(new TcpServerSendData(eVmsOpCode.OP_VMS_STATUS_REQ, null));
                return;
            case 2:
                this.selObj.addRequestData(new TcpServerSendData(eVmsOpCode.OP_VMS_PARAMETER_REQ, null));
                return;
            case 3:
                this.selObj.downloadForm();
                return;
            case 4:
                statusControl.controlSystemTime();
                break;
            case 5:
                statusControl.controlSignboardPower((byte) 0x00);
                break;
            case 6:
                statusControl.controlSignboardPower((byte) 0x01);
                break;
            case 7:
                statusControl.controlFan((byte) (cboControl.getSelectedIndex() & 0xff), (byte) ((Integer) spControl.getValue() & 0xFF));
                break;
            case 8:
                statusControl.controlHeater((byte) (cboControl.getSelectedIndex() & 0xff), (byte) ((Integer) spControl.getValue() & 0xFF));
                break;
        }
        this.selObj.addRequestData(new TcpServerSendData(eVmsOpCode.OP_VMS_STATUS_CONTROL, statusControl));
    }

    public void logging(String txt) {
        Date now = new Date();
        SimpleDateFormat sFormat = new SimpleDateFormat("[MM/dd HH:mm:ss] ");
        String newLog = sFormat.format(now);
        taLog.append("\n" + newLog + txt);
        taLog.setCaretPosition(taLog.getDocument().getLength());
    }

    public void updateInfo(TbVmsCtlrDto selObj) {
        this.selObj = selObj;
        taLog.setText(null);
        txtNmbr.setText("");
        txtCtlrId.setText("");
        txtName.setText("");
        txtState.setText("");
        txtIpAddr.setText("");
        txtPort.setText("");
        txtDoor.setText("");
        txtFan.setText("");
        txtHeater.setText("");
        txtTemp.setText("");
        if (selObj != null) {
            txtNmbr.setText(String.valueOf(selObj.getVmsCtlrNmbr()));
            txtCtlrId.setText(selObj.getCtlrId());
            txtName.setText(selObj.getName());
            txtIpAddr.setText(selObj.getCtlrIp());
            txtPort.setText(String.valueOf(selObj.getCtlrPort()));
            txtState.setText(CtlrSttsTableModel.netStateStr[selObj.getNetState()]);

            TbVmsCtlrStts stts = selObj.getStts();
            String door = "-";
            String fan = "-";
            String heater = "-";
            String temper = "-";
            if ("CMS0".equals(stts.getCmncSttsCd())) {
                if (stts.getCboxDoorSttsCd().equals("CDS0")) {
                    door = "닫힘";
                } else if (stts.getCboxDoorSttsCd().equals("CDS1")) {
                    door = "열림";
                } else {
                    door = "-?-";
                }
                if (stts.getFanSttsCd().equals("PAS0")) {
                    fan = "중지";
                } else if (stts.getFanSttsCd().equals("PAS1")) {
                    fan = "가동";
                }
                else {
                    fan = "-?-";
                }
                if (stts.getHetrSttsCd().equals("HTS0")) {
                    heater = "중지";
                } else if (stts.getHetrSttsCd().equals("HTS1")) {
                    heater = "가동";
                }
                else {
                    heater = "-?-";
                }
                temper = String.valueOf(stts.getCboxTmpr());
            }
            txtDoor.setText(door);
            txtFan.setText(fan);
            txtHeater.setText(heater);
            txtTemp.setText(temper);
        }
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        rootPanel = new JPanel();
        rootPanel.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
        pnlCtlr = new JPanel();
        pnlCtlr.setLayout(new GridLayoutManager(2, 1, new Insets(0, 4, 0, 4), -1, -1));
        rootPanel.add(pnlCtlr, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        pnlControl = new JPanel();
        pnlControl.setLayout(new GridLayoutManager(5, 1, new Insets(0, 0, 0, 2), 1, 1));
        pnlCtlr.add(pnlControl, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new GridLayoutManager(5, 11, new Insets(0, 0, 0, 0), -1, -1));
        pnlControl.add(panel1, new GridConstraints(0, 0, 5, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        txtName = new JTextField();
        txtName.setEditable(false);
        Font txtNameFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtName.getFont());
        if (txtNameFont != null) txtName.setFont(txtNameFont);
        txtName.setHorizontalAlignment(2);
        txtName.setText("제어기 명칭");
        panel1.add(txtName, new GridConstraints(1, 4, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(200, -1), null, 0, false));
        final JLabel label1 = new JLabel();
        Font label1Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label1.getFont());
        if (label1Font != null) label1.setFont(label1Font);
        label1.setText("ㅣ명칭");
        panel1.add(label1, new GridConstraints(1, 0, 1, 4, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label2 = new JLabel();
        Font label2Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label2.getFont());
        if (label2Font != null) label2.setFont(label2Font);
        label2.setText("ㅣIP / Port   ");
        panel1.add(label2, new GridConstraints(2, 0, 1, 3, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label3 = new JLabel();
        Font label3Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label3.getFont());
        if (label3Font != null) label3.setFont(label3Font);
        label3.setText("ㅣ도어");
        panel1.add(label3, new GridConstraints(3, 0, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        txtDoor = new JTextField();
        txtDoor.setEditable(false);
        Font txtDoorFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtDoor.getFont());
        if (txtDoorFont != null) txtDoor.setFont(txtDoorFont);
        txtDoor.setHorizontalAlignment(0);
        txtDoor.setText("열림/닫힘");
        panel1.add(txtDoor, new GridConstraints(3, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(100, -1), new Dimension(100, -1), new Dimension(100, -1), 0, false));
        txtCtlrId = new JTextField();
        txtCtlrId.setEditable(false);
        Font txtCtlrIdFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtCtlrId.getFont());
        if (txtCtlrIdFont != null) txtCtlrId.setFont(txtCtlrIdFont);
        txtCtlrId.setHorizontalAlignment(0);
        txtCtlrId.setText("제어기 ID");
        panel1.add(txtCtlrId, new GridConstraints(0, 5, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
        txtNmbr = new JTextField();
        txtNmbr.setEditable(false);
        Font txtNmbrFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtNmbr.getFont());
        if (txtNmbrFont != null) txtNmbr.setFont(txtNmbrFont);
        txtNmbr.setHorizontalAlignment(0);
        txtNmbr.setText("관리번호");
        panel1.add(txtNmbr, new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label4 = new JLabel();
        Font label4Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label4.getFont());
        if (label4Font != null) label4.setFont(label4Font);
        label4.setText("ㅣVMS");
        panel1.add(label4, new GridConstraints(0, 0, 1, 4, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        txtFan = new JTextField();
        txtFan.setEditable(false);
        Font txtFanFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtFan.getFont());
        if (txtFanFont != null) txtFan.setFont(txtFanFont);
        txtFan.setHorizontalAlignment(0);
        txtFan.setText("가동/중지");
        panel1.add(txtFan, new GridConstraints(3, 6, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(100, -1), new Dimension(100, -1), new Dimension(100, -1), 0, false));
        txtPort = new JTextField();
        txtPort.setEditable(false);
        Font txtPortFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtPort.getFont());
        if (txtPortFont != null) txtPort.setFont(txtPortFont);
        txtPort.setHorizontalAlignment(0);
        txtPort.setText("3001");
        panel1.add(txtPort, new GridConstraints(2, 6, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(100, -1), new Dimension(100, -1), new Dimension(100, -1), 0, false));
        final JLabel label5 = new JLabel();
        Font label5Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label5.getFont());
        if (label5Font != null) label5.setFont(label5Font);
        label5.setText("ㅣ함체온도");
        panel1.add(label5, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label6 = new JLabel();
        Font label6Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label6.getFont());
        if (label6Font != null) label6.setFont(label6Font);
        label6.setText("ㅣ히터");
        panel1.add(label6, new GridConstraints(4, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        txtTemp = new JTextField();
        txtTemp.setEditable(false);
        Font txtTempFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtTemp.getFont());
        if (txtTempFont != null) txtTemp.setFont(txtTempFont);
        txtTemp.setHorizontalAlignment(0);
        txtTemp.setText("34");
        panel1.add(txtTemp, new GridConstraints(4, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(100, -1), new Dimension(100, -1), new Dimension(100, -1), 0, false));
        txtHeater = new JTextField();
        txtHeater.setEditable(false);
        Font txtHeaterFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtHeater.getFont());
        if (txtHeaterFont != null) txtHeater.setFont(txtHeaterFont);
        txtHeater.setHorizontalAlignment(0);
        txtHeater.setText("가동/중지");
        panel1.add(txtHeater, new GridConstraints(4, 6, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(100, -1), new Dimension(100, -1), new Dimension(100, -1), 0, false));
        txtIpAddr = new JTextField();
        txtIpAddr.setEditable(false);
        Font txtIpAddrFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtIpAddr.getFont());
        if (txtIpAddrFont != null) txtIpAddr.setFont(txtIpAddrFont);
        txtIpAddr.setHorizontalAlignment(0);
        txtIpAddr.setText("192.168.113.112");
        panel1.add(txtIpAddr, new GridConstraints(2, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnReqStatus = new JButton();
        Font btnReqStatusFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnReqStatus.getFont());
        if (btnReqStatusFont != null) btnReqStatus.setFont(btnReqStatusFont);
        btnReqStatus.setText("상태정보요청");
        panel1.add(btnReqStatus, new GridConstraints(1, 8, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnReqParam = new JButton();
        Font btnReqParamFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnReqParam.getFont());
        if (btnReqParamFont != null) btnReqParam.setFont(btnReqParamFont);
        btnReqParam.setText("파라미터 요청");
        panel1.add(btnReqParam, new GridConstraints(2, 8, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnScnDnld = new JButton();
        Font btnScnDnldFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnScnDnld.getFont());
        if (btnScnDnldFont != null) btnScnDnld.setFont(btnScnDnldFont);
        btnScnDnld.setText("시나리오 다운로드");
        panel1.add(btnScnDnld, new GridConstraints(3, 8, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnTimeSync = new JButton();
        Font btnTimeSyncFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnTimeSync.getFont());
        if (btnTimeSyncFont != null) btnTimeSync.setFont(btnTimeSyncFont);
        btnTimeSync.setText("시간 설정");
        panel1.add(btnTimeSync, new GridConstraints(4, 8, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnSignBoardOff = new JButton();
        Font btnSignBoardOffFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnSignBoardOff.getFont());
        if (btnSignBoardOffFont != null) btnSignBoardOff.setFont(btnSignBoardOffFont);
        btnSignBoardOff.setText("전광판 전원 OFF");
        btnSignBoardOff.setToolTipText("");
        panel1.add(btnSignBoardOff, new GridConstraints(1, 9, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnSignBoardOn = new JButton();
        Font btnSignBoardOnFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnSignBoardOn.getFont());
        if (btnSignBoardOnFont != null) btnSignBoardOn.setFont(btnSignBoardOnFont);
        btnSignBoardOn.setText("전광판 전원 ON");
        btnSignBoardOn.setToolTipText("");
        panel1.add(btnSignBoardOn, new GridConstraints(1, 10, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnReqFan = new JButton();
        Font btnReqFanFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnReqFan.getFont());
        if (btnReqFanFont != null) btnReqFan.setFont(btnReqFanFont);
        btnReqFan.setText("Fan 제어");
        btnReqFan.setToolTipText("");
        panel1.add(btnReqFan, new GridConstraints(4, 9, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnReqHeater = new JButton();
        Font btnReqHeaterFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnReqHeater.getFont());
        if (btnReqHeaterFont != null) btnReqHeater.setFont(btnReqHeaterFont);
        btnReqHeater.setText("Heater 제어");
        btnReqHeater.setToolTipText("");
        panel1.add(btnReqHeater, new GridConstraints(4, 10, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        cboControl = new JComboBox();
        Font cboControlFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, cboControl.getFont());
        if (cboControlFont != null) cboControl.setFont(cboControlFont);
        final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel();
        defaultComboBoxModel1.addElement("0x00: 꺼짐");
        defaultComboBoxModel1.addElement("0x01: 켜짐");
        defaultComboBoxModel1.addElement("0x02: 자동");
        cboControl.setModel(defaultComboBoxModel1);
        panel1.add(cboControl, new GridConstraints(3, 9, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label7 = new JLabel();
        Font label7Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label7.getFont());
        if (label7Font != null) label7.setFont(label7Font);
        label7.setText("ㅣ팬");
        panel1.add(label7, new GridConstraints(3, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label8 = new JLabel();
        Font label8Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label8.getFont());
        if (label8Font != null) label8.setFont(label8Font);
        label8.setText("ㅣ팬/히터 제어 구분");
        panel1.add(label8, new GridConstraints(2, 9, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JLabel label9 = new JLabel();
        Font label9Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label9.getFont());
        if (label9Font != null) label9.setFont(label9Font);
        label9.setText("ㅣ팬/히터 제어 값");
        panel1.add(label9, new GridConstraints(2, 10, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel1.add(panel2, new GridConstraints(3, 10, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        spControl = new JSpinner();
        panel2.add(spControl, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnSymbDnld = new JButton();
        Font btnSymbDnldFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnSymbDnld.getFont());
        if (btnSymbDnldFont != null) btnSymbDnld.setFont(btnSymbDnldFont);
        btnSymbDnld.setText("심벌라이브러리");
        panel1.add(btnSymbDnld, new GridConstraints(0, 10, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        txtState = new JTextField();
        txtState.setEditable(false);
        Font txtStateFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, txtState.getFont());
        if (txtStateFont != null) txtState.setFont(txtStateFont);
        txtState.setHorizontalAlignment(0);
        txtState.setText("통신");
        panel1.add(txtState, new GridConstraints(0, 8, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(100, -1), new Dimension(100, -1), new Dimension(100, -1), 0, false));
        btnReserved = new JButton();
        Font btnReservedFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnReserved.getFont());
        if (btnReservedFont != null) btnReserved.setFont(btnReservedFont);
        btnReserved.setText("Button");
        panel1.add(btnReserved, new GridConstraints(0, 9, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JPanel panel3 = new JPanel();
        panel3.setLayout(new GridLayoutManager(2, 1, new Insets(0, 4, 0, 4), -1, -1));
        rootPanel.add(panel3, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, new Dimension(-1, 200), null, null, 0, false));
        final JPanel panel4 = new JPanel();
        panel4.setLayout(new GridLayoutManager(1, 3, new Insets(2, 0, 0, 2), -1, -1));
        panel3.add(panel4, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JLabel label10 = new JLabel();
        Font label10Font = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, label10.getFont());
        if (label10Font != null) label10.setFont(label10Font);
        label10.setHorizontalAlignment(2);
        label10.setIcon(new ImageIcon(getClass().getResource("/static/image/logging.png")));
        label10.setText("제어 로그");
        panel4.add(label10, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        btnLogClear = new JButton();
        Font btnLogClearFont = this.$$$getFont$$$("Malgun Gothic", Font.PLAIN, 12, btnLogClear.getFont());
        if (btnLogClearFont != null) btnLogClear.setFont(btnLogClearFont);
        btnLogClear.setHorizontalTextPosition(0);
        btnLogClear.setText("지우기");
        panel4.add(btnLogClear, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final Spacer spacer1 = new Spacer();
        panel4.add(spacer1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
        final JScrollPane scrollPane1 = new JScrollPane();
        panel3.add(scrollPane1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        taLog = new JTextArea();
        taLog.setBackground(new Color(-16777216));
        taLog.setCaretColor(new Color(-1));
        taLog.setEditable(false);
        Font taLogFont = this.$$$getFont$$$("D2Coding", Font.PLAIN, 14, taLog.getFont());
        if (taLogFont != null) taLog.setFont(taLogFont);
        taLog.setForeground(new Color(-1));
        taLog.setMargin(new Insets(4, 4, 4, 4));
        taLog.setText("제어로그");
        scrollPane1.setViewportView(taLog);
    }

    /**
     * @noinspection ALL
     */
    private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
        if (currentFont == null) return null;
        String resultName;
        if (fontName == null) {
            resultName = currentFont.getName();
        } else {
            Font testFont = new Font(fontName, Font.PLAIN, 10);
            if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
                resultName = fontName;
            } else {
                resultName = currentFont.getName();
            }
        }
        Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
        boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac");
        Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize());
        return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return rootPanel;
    }

}
