package de.newsarea.homecockpit.fsuipc.example;

import de.newsarea.homecockpit.connector.Connector;
import de.newsarea.homecockpit.connector.facade.ConnectorFacade;
import de.newsarea.homecockpit.connector.facade.DefaultConnectorFacade;
import de.newsarea.homecockpit.connector.facade.registration.XmlEventHandlerRegistrationService;
import de.newsarea.homecockpit.connector.fsuipc.FSUIPCConnector;
import de.newsarea.homecockpit.connector.fsuipc.FSUIPCGeneralConnector;
import de.newsarea.homecockpit.connector.net.NetGeneralConnector;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.ConnectException;

public class Application {

    public static void main(String[] args) throws InterruptedException, ConnectException {
        FSUIPCConnector fsuipcConnector = new FSUIPCGeneralConnector(new NetGeneralConnector("drevil", 4020));
        // ~
        Application app = new Application();
        app.run(fsuipcConnector);
    }

    public void run(final Connector connector) throws ConnectException {
        connector.open();
        // ~
        ConnectorFacade connectorFacade = new DefaultConnectorFacade();
        // ~
        XmlEventHandlerRegistrationService xmlEventHandlerRegistrationService = new XmlEventHandlerRegistrationService(connectorFacade);
        xmlEventHandlerRegistrationService.registerEventHandler(connector, "/de/newsarea/homecockpit/connector/fsuipc/general.xml");
        // ~
        FSUIPCSwingUI fsuipSwingUI = new FSUIPCSwingUI(connectorFacade);
        fsuipSwingUI.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                connector.close();
            }
        });
        fsuipSwingUI.initialize();
        // show frame
        fsuipSwingUI.setVisible(true);
    }

}

@@ -530,16 +530,89 @@
 nnector;
+%0Aimport de.newsarea.homecockpit.connector.util.ConnectorConnectionHelper;
 %0A%0Aimport
@@ -740,16 +740,156 @@
 tion %7B%0A%0A
+    private Connector connector;%0A    private ConnectorConnectionHelper connectorConnectionHelper;%0A    private FSUIPCSwingUI fsuipcSwingUI;%0A%0A
     publ
@@ -1205,14 +1205,8 @@
 run(
-final 
 Conn
@@ -1203,33 +1203,38 @@
 d run(Connector 
-c
+inputC
 onnector) throws
@@ -1270,16 +1270,159 @@
 onnector
+ = inputConnector;%0A        // ~%0A        connectorConnectionHelper = new ConnectorConnectionHelper(connector);%0A        connectorConnectionHelper
 .open();
@@ -1811,35 +1811,22 @@
         
-FSUIPCSwingUI 
 fsuip
+c
 SwingUI 
@@ -1868,32 +1868,33 @@
 );%0A        fsuip
+c
 SwingUI.addWindo
@@ -2068,32 +2068,33 @@
 );%0A        fsuip
+c
 SwingUI.initiali
@@ -2134,16 +2134,17 @@
    fsuip
+c
 SwingUI.
@@ -2168,10 +2168,130 @@
 %0A    %7D%0A%0A
+    public void shutdown() %7B%0A        fsuipcSwingUI.setVisible(false);%0A        connectorConnectionHelper.close();%0A    %7D%0A%0A
 %7D%0A

optimize example shutdown