/*
 * Created by JFormDesigner on Mon Oct 17 17:19:48 CST 2022
 */

package com.uhf.form;

import com.uhf.UHFMainForm;

import java.awt.*;
import java.awt.event.*;
import javax.accessibility.AccessibleContext;
import javax.swing.*;
import javax.swing.plaf.PanelUI;

/**
 * @author zp
 */
public class UHFInfoForm extends JPanel {
    public UHFInfoForm() {
        initComponents();
    }

    @Override
    public void setVisible(boolean aFlag) {
        super.setVisible(aFlag);
        if (aFlag) {
            String uhfVersion = UHFMainForm.ur4.getVersion();
            // System.out.println(uhfVersion);
            if (uhfVersion == null) {
                UHFVersion.setText("failed！");
            } else if (uhfVersion.equals("")) {
                UHFVersion.setText("empty！");
            } else {
                UHFVersion.setText(uhfVersion);
            }

            String tcpVersion = UHFMainForm.ur4.getTcpServiceVersion();
            // System.out.println(uhfVersion);
            if (tcpVersion == null) {
                TCPVersion.setText("failed！");
            } else if (tcpVersion.equals("")) {
                TCPVersion.setText("empty！");
            } else {
                TCPVersion.setText(tcpVersion);
            }
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        UHFVersion = new JLabel();
        label1 = new JLabel();
        TCPVersion = new JLabel();
        label2 = new JLabel();

        //======== this ========
        setLayout(null);

        //---- UHFVersion ----
        UHFVersion.setFont(UHFVersion.getFont().deriveFont(UHFVersion.getFont().getSize() + 5f));
        add(UHFVersion);
        UHFVersion.setBounds(162, 40, 208, 25);

        //---- label1 ----
        label1.setText("UHF Version:");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 5f));
        add(label1);
        label1.setBounds(new Rectangle(new Point(40, 40), label1.getPreferredSize()));

        //---- TCPVersion ----
        TCPVersion.setFont(TCPVersion.getFont().deriveFont(TCPVersion.getFont().getSize() + 5f));
        add(TCPVersion);
        TCPVersion.setBounds(162, 75, 208, 25);

        //---- label2 ----
        label2.setText("TCP Version:");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 5f));
        add(label2);
        label2.setBounds(new Rectangle(new Point(40, 75), label2.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < getComponentCount(); i++) {
                Rectangle bounds = getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            setMinimumSize(preferredSize);
            setPreferredSize(preferredSize);
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel UHFVersion;
    private JLabel label1;
    private JLabel TCPVersion;
    private JLabel label2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
