package com.its.vds.ui;

import com.its.vds.dto.TbVdsCtlrDto;
import org.springframework.core.io.ClassPathResource;

import javax.swing.*;
import java.io.IOException;
import java.net.URL;

public class SubUIController extends JFrame {
    private SubUI view;
    private JFrame caller;

    public SubUIController(JFrame jFrame) {
        super("VDS 제어");
        try {
            ClassPathResource file = new ClassPathResource("static/image/application.png");
            URL imgURL = file.getURL();
            setIconImage(new ImageIcon(imgURL).getImage());
        } catch (IOException e) {
        }

        this.caller = jFrame;
        this.view = new SubUI() {
            @Override
            protected void actionButtonClicked() {
                doAction();
            }
        };
        //this.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        this.setResizable(false);
        this.setLocationRelativeTo(this.caller);
        this.setLocationByPlatform(true);
        this.setContentPane(view.$$$getRootComponent$$$());
        this.setAlwaysOnTop(true);
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);

        this.setUndecorated(true);
        //this.setDefaultLookAndFeelDecorated(true);
        this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        //this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        this.pack();
    }

    private void doAction() {
        this.view.updateInfo(null);
        this.setVisible(false);
        caller.validate();
    }

    public void updateInfo(TbVdsCtlrDto selObj) {
        this.view.updateInfo(selObj);
    }
}
