From 073554de5692b23d21a597a580a95726cc2fa890 Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Wed, 5 Feb 2014 01:47:19 +0100 Subject: [PATCH] RemoteAgents: SWT GUI --- .../main/webapp/WEB-INF/spring-mainapp-servlet.xml | 5 ++ .../remote/agents/clients/app/ClientsMainTest.java | 66 +++++++++++++++++----- .../agents/clients/app/RemoteGUIExample.java | 55 ++++++++++++++++++ .../resources/clients-remote-agents-spring.xml | 5 ++ .../agents/services/CurrentDateServiceImpl.java | 19 +++++++ .../src/main/resources/service-spring.xml | 3 + .../remote/agents/services/CurrentDateService.java | 7 +++ 7 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/RemoteGUIExample.java create mode 100644 RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/CurrentDateServiceImpl.java create mode 100644 RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/CurrentDateService.java diff --git a/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml index b24b1b5..980e6c6 100644 --- a/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml +++ b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml @@ -17,5 +17,10 @@ + + + + + diff --git a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java index 983958c..3bbaff9 100644 --- a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java +++ b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java @@ -1,27 +1,25 @@ package de.remote.agents.clients.app; -import java.net.URL; +import java.util.Timer; +import java.util.TimerTask; import org.apache.log4j.Logger; -import com.googlecode.jsonrpc4j.JsonRpcHttpClient; - -import de.remote.agents.SnakeEyes; -import de.remote.agents.SnakeEyesImpl; +import de.remote.agents.services.CurrentDateService; public class ClientsMainTest { private static final Logger logger = Logger.getLogger(ClientsMainTest.class); public static void main(final String[] args) throws Throwable { - final JsonRpcHttpClient client = new JsonRpcHttpClient(new URL( - "http://127.0.0.1:8080/spring-mainapp/UserService.json")); - - final SnakeEyes user = client.invoke("createUser", new Object[] { - "Shana M. O'Hara", "Snake Eyes" }, SnakeEyesImpl.class); - - logger.info("Canon: " + user.getCanon()); - logger.info("Name: " + user.getName()); + // final JsonRpcHttpClient client = new JsonRpcHttpClient(new URL( + // "http://127.0.0.1:8080/spring-mainapp/UserService.json")); + // + // final SnakeEyes user = client.invoke("createUser", new Object[] { + // "Shana M. O'Hara", "Snake Eyes" }, SnakeEyesImpl.class); + // + // logger.info("Canon: " + user.getCanon()); + // logger.info("Name: " + user.getName()); // I need a way to set the return type parameter, otherwise I am not @@ -39,6 +37,48 @@ public class ClientsMainTest { // logger.info("Canon: " + snakeEyes.getCanon()); // logger.info("Name: " + snakeEyes.getName()); + // I need a way to set the return type parameter, otherwise I am not + // going to be able to use this JSON-RPC plugin :( + + logger.info("Starting application"); + SpringContextLocator.getInstance(); + + final CurrentDateService remoteCurrentDate = (CurrentDateService) SpringContextLocator + .getInstance().getBean("remoteCurrentDateService"); + + + final RemoteGUIExample window = new RemoteGUIExample(); + final Runnable task = new Runnable() { + + @Override + public void run() { + window.open(); + } + + }; + + final Thread GUIThread = new Thread(task, "GUI-Thread"); + // GUIThread.setUncaughtExceptionHandler(new DriverHWUncaughtExceptionHandler()); + GUIThread.start(); + + final Timer t = new Timer("Timer-Thread", false); + t.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + final String remoteDate = remoteCurrentDate.getCurrentDate(); + window.updateTextBox(remoteDate); + } + }, 1000, 1000); + } + // private class DriverHWUncaughtExceptionHandler implements UncaughtExceptionHandler { + // + // @Override + // public void uncaughtException(final Thread t, final Throwable e) { + // logger.warn( + // "Exception not expected while running thread " + t.getName(), e); + // } + // } + } diff --git a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/RemoteGUIExample.java b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/RemoteGUIExample.java new file mode 100644 index 0000000..a413a3b --- /dev/null +++ b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/RemoteGUIExample.java @@ -0,0 +1,55 @@ +package de.remote.agents.clients.app; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class RemoteGUIExample { + + private Shell shell; + private Text textBox; + private Display display; + + + /** + * @wbp.parser.entryPoint + */ + public void open() { + this.display = Display.getDefault(); + this.createContents(); + this.shell.open(); + this.shell.layout(); + while (!this.shell.isDisposed()) { + if (!this.display.readAndDispatch()) { + this.display.sleep(); + } + } + } + + public void updateTextBox(final String text) { + this.display.asyncExec(new Runnable() { + @Override + public void run() { + if (!RemoteGUIExample.this.textBox.isDisposed()) + RemoteGUIExample.this.textBox.setText(text); + } + }); + } + + + private void createContents() { + this.shell = new Shell(); + this.shell.setSize(450, 300); + this.shell.setText("Remote GUI"); + + this.textBox = new Text(this.shell, SWT.BORDER); + this.textBox.setBounds(111, 95, 181, 58); + + final Label lblRemoteDate = new Label(this.shell, SWT.NONE); + lblRemoteDate.setBounds(111, 63, 113, 26); + lblRemoteDate.setText("Remote Date:"); + } + +} diff --git a/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml b/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml index b917a91..502b166 100644 --- a/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml +++ b/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml @@ -9,5 +9,10 @@ + + + + + diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/CurrentDateServiceImpl.java b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/CurrentDateServiceImpl.java new file mode 100644 index 0000000..64391a6 --- /dev/null +++ b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/CurrentDateServiceImpl.java @@ -0,0 +1,19 @@ +package de.remote.agents.services; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class CurrentDateServiceImpl implements CurrentDateService { + + @Override + public String getCurrentDate() { + final DateFormat dateFormat = new SimpleDateFormat( + "yyyy/MM/dd HH:mm:ss"); + + final Date date = new Date(); + + return dateFormat.format(date); + } + +} diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml b/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml index 5d57305..67b2ed4 100644 --- a/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml +++ b/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml @@ -10,5 +10,8 @@ + + + diff --git a/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/CurrentDateService.java b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/CurrentDateService.java new file mode 100644 index 0000000..0bb11c5 --- /dev/null +++ b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/CurrentDateService.java @@ -0,0 +1,7 @@ +package de.remote.agents.services; + +public interface CurrentDateService { + + String getCurrentDate(); + +} -- 2.1.4