Simon Van Mierlo 8 lat temu
commit
9379056835
100 zmienionych plików z 4041 dodań i 0 usunięć
  1. 7 0
      traffic_light/.classpath
  2. 17 0
      traffic_light/.project
  3. 11 0
      traffic_light/.settings/org.eclipse.jdt.core.prefs
  4. BIN
      traffic_light/bin/traffic/light/ButtonPanel.class
  5. BIN
      traffic_light/bin/traffic/light/CrossWalkPanel.class
  6. BIN
      traffic_light/bin/traffic/light/CrossingPanel.class
  7. BIN
      traffic_light/bin/traffic/light/IStatemachine.class
  8. BIN
      traffic_light/bin/traffic/light/ITimer.class
  9. BIN
      traffic_light/bin/traffic/light/ITimerCallback.class
  10. BIN
      traffic_light/bin/traffic/light/PedestrianLight$Alignment.class
  11. BIN
      traffic_light/bin/traffic/light/PedestrianLight.class
  12. BIN
      traffic_light/bin/traffic/light/RuntimeService$StatemachineTimerTask.class
  13. BIN
      traffic_light/bin/traffic/light/RuntimeService.class
  14. BIN
      traffic_light/bin/traffic/light/TimerService$TimeEventTask.class
  15. BIN
      traffic_light/bin/traffic/light/TimerService.class
  16. BIN
      traffic_light/bin/traffic/light/TrafficLight$Alignment.class
  17. BIN
      traffic_light/bin/traffic/light/TrafficLight.class
  18. BIN
      traffic_light/bin/traffic/light/TrafficlightDemo$1.class
  19. BIN
      traffic_light/bin/traffic/light/TrafficlightDemo.class
  20. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine$SCIPedestrian.class
  21. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine$SCITrafficLight.class
  22. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine$SCInterface.class
  23. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine$SCInterfaceOperationCallback.class
  24. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine.class
  25. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine$1.class
  26. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine$SynchronizedSCIPedestrian.class
  27. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine$SynchronizedSCITrafficLight.class
  28. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine$SynchronizedSCInterface.class
  29. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine.class
  30. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine$SCIPedestrianImpl.class
  31. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine$SCITrafficLightImpl.class
  32. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine$SCInterfaceImpl.class
  33. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine$State.class
  34. BIN
      traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine.class
  35. 48 0
      traffic_light/src-gen/traffic/light/IStatemachine.java
  36. 47 0
      traffic_light/src-gen/traffic/light/ITimer.java
  37. 24 0
      traffic_light/src-gen/traffic/light/ITimerCallback.java
  38. 216 0
      traffic_light/src-gen/traffic/light/RuntimeService.java
  39. 124 0
      traffic_light/src-gen/traffic/light/TimerService.java
  40. 71 0
      traffic_light/src-gen/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine.java
  41. 279 0
      traffic_light/src-gen/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine.java
  42. 1356 0
      traffic_light/src-gen/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine.java
  43. 51 0
      traffic_light/src/traffic/light/ButtonPanel.java
  44. 96 0
      traffic_light/src/traffic/light/CrossWalkPanel.java
  45. 125 0
      traffic_light/src/traffic/light/CrossingPanel.java
  46. 123 0
      traffic_light/src/traffic/light/PedestrianLight.java
  47. 123 0
      traffic_light/src/traffic/light/TrafficLight.java
  48. 96 0
      traffic_light/src/traffic/light/TrafficlightDemo.java
  49. 8 0
      traffic_light_basic/.classpath
  50. 2 0
      traffic_light_basic/.gitignore
  51. 29 0
      traffic_light_basic/.project
  52. 3 0
      traffic_light_basic/.settings/org.eclipse.core.resources.prefs
  53. 2 0
      traffic_light_basic/.settings/org.eclipse.core.runtime.prefs
  54. 12 0
      traffic_light_basic/.settings/org.eclipse.jdt.core.prefs
  55. 17 0
      traffic_light_basic/README.TXT
  56. BIN
      traffic_light_basic/images/TrafficLightCtrl.png
  57. 33 0
      traffic_light_basic/index.html
  58. 12 0
      traffic_light_basic/metadata.json
  59. 143 0
      traffic_light_basic/model/TrafficLightCtrl.sct
  60. 25 0
      traffic_light_basic/model/TrafficLightCtrl.sgen
  61. 39 0
      traffic_light_basic/src-gen/traffic/light/IStatemachine.java
  62. 38 0
      traffic_light_basic/src-gen/traffic/light/ITimer.java
  63. 15 0
      traffic_light_basic/src-gen/traffic/light/ITimerCallback.java
  64. 115 0
      traffic_light_basic/src-gen/traffic/light/TimerService.java
  65. 29 0
      traffic_light_basic/src-gen/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine.java
  66. 65 0
      traffic_light_basic/src-gen/traffic/light/trafficlightctrl/RunnableTrafficLightCtrlStatemachineWrapper.java
  67. 176 0
      traffic_light_basic/src-gen/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine.java
  68. 381 0
      traffic_light_basic/src-gen/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine.java
  69. 48 0
      traffic_light_basic/src/traffic/light/TrafficlightDemo.java
  70. 7 0
      traffic_light_generated/.classpath
  71. 17 0
      traffic_light_generated/.project
  72. 11 0
      traffic_light_generated/.settings/org.eclipse.jdt.core.prefs
  73. BIN
      traffic_light_generated/bin/traffic/light/ButtonPanel.class
  74. BIN
      traffic_light_generated/bin/traffic/light/CrossWalkPanel.class
  75. BIN
      traffic_light_generated/bin/traffic/light/IStatemachine.class
  76. BIN
      traffic_light_generated/bin/traffic/light/ITimer.class
  77. BIN
      traffic_light_generated/bin/traffic/light/ITimerCallback.class
  78. BIN
      traffic_light_generated/bin/traffic/light/RuntimeService$StatemachineTimerTask.class
  79. BIN
      traffic_light_generated/bin/traffic/light/RuntimeService.class
  80. BIN
      traffic_light_generated/bin/traffic/light/TimerService$TimeEventTask.class
  81. BIN
      traffic_light_generated/bin/traffic/light/TimerService.class
  82. BIN
      traffic_light_generated/bin/traffic/light/TrafficLight$Alignment.class
  83. BIN
      traffic_light_generated/bin/traffic/light/TrafficLight.class
  84. BIN
      traffic_light_generated/bin/traffic/light/TrafficlightDemo$1.class
  85. BIN
      traffic_light_generated/bin/traffic/light/TrafficlightDemo.class
  86. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/ITrafficLightCtrl_GeneratorAcceptorStatemachine$SCITrafficLight.class
  87. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/ITrafficLightCtrl_GeneratorAcceptorStatemachine$SCInterface.class
  88. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/ITrafficLightCtrl_GeneratorAcceptorStatemachine$SCInterfaceOperationCallback.class
  89. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/ITrafficLightCtrl_GeneratorAcceptorStatemachine.class
  90. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/SynchronizedTrafficLightCtrl_GeneratorAcceptorStatemachine$1.class
  91. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/SynchronizedTrafficLightCtrl_GeneratorAcceptorStatemachine$SynchronizedSCITrafficLight.class
  92. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/SynchronizedTrafficLightCtrl_GeneratorAcceptorStatemachine$SynchronizedSCInterface.class
  93. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/SynchronizedTrafficLightCtrl_GeneratorAcceptorStatemachine.class
  94. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/TrafficLightCtrl_GeneratorAcceptorStatemachine$SCITrafficLightImpl.class
  95. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/TrafficLightCtrl_GeneratorAcceptorStatemachine$SCInterfaceImpl.class
  96. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/TrafficLightCtrl_GeneratorAcceptorStatemachine$State.class
  97. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/TrafficLightCtrl_GeneratorAcceptorStatemachine.class
  98. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor2/ITrafficLightCtrl_GeneratorAcceptor2Statemachine$SCITrafficLight.class
  99. BIN
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor2/ITrafficLightCtrl_GeneratorAcceptor2Statemachine$SCInterface.class
  100. 0 0
      traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor2/ITrafficLightCtrl_GeneratorAcceptor2Statemachine$SCInterfaceOperationCallback.class

+ 7 - 0
traffic_light/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="src-gen"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
traffic_light/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>traffic_light</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 11 - 0
traffic_light/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8

BIN
traffic_light/bin/traffic/light/ButtonPanel.class


BIN
traffic_light/bin/traffic/light/CrossWalkPanel.class


BIN
traffic_light/bin/traffic/light/CrossingPanel.class


BIN
traffic_light/bin/traffic/light/IStatemachine.class


BIN
traffic_light/bin/traffic/light/ITimer.class


BIN
traffic_light/bin/traffic/light/ITimerCallback.class


BIN
traffic_light/bin/traffic/light/PedestrianLight$Alignment.class


BIN
traffic_light/bin/traffic/light/PedestrianLight.class


BIN
traffic_light/bin/traffic/light/RuntimeService$StatemachineTimerTask.class


BIN
traffic_light/bin/traffic/light/RuntimeService.class


BIN
traffic_light/bin/traffic/light/TimerService$TimeEventTask.class


BIN
traffic_light/bin/traffic/light/TimerService.class


BIN
traffic_light/bin/traffic/light/TrafficLight$Alignment.class


BIN
traffic_light/bin/traffic/light/TrafficLight.class


BIN
traffic_light/bin/traffic/light/TrafficlightDemo$1.class


BIN
traffic_light/bin/traffic/light/TrafficlightDemo.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine$SCIPedestrian.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine$SCITrafficLight.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine$SCInterface.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine$SCInterfaceOperationCallback.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine$1.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine$SynchronizedSCIPedestrian.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine$SynchronizedSCITrafficLight.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine$SynchronizedSCInterface.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine$SCIPedestrianImpl.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine$SCITrafficLightImpl.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine$SCInterfaceImpl.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine$State.class


BIN
traffic_light/bin/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine.class


+ 48 - 0
traffic_light/src-gen/traffic/light/IStatemachine.java

@@ -0,0 +1,48 @@
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+    committers of YAKINDU - initial API and implementation
+� */
+package traffic.light;
+
+/**
+ * Basic interface for state machines.
+ */
+public interface IStatemachine {
+
+	/**
+	 * Initializes the state machine. Used to initialize internal variables etc.
+	 */
+	public void init();
+
+	/**
+	 * Enters the state machine. Sets the state machine into a defined state.
+	 */
+	public void enter();
+
+	/**
+	 * Exits the state machine. Leaves the state machine with a defined state.
+	 */
+	public void exit();
+
+	/**
+	 * Checks whether the state machine is active. 
+	 * A state machine is active if it has been entered. It is inactive if it has not been entered at all or if it has been exited.
+	 */
+	public boolean isActive();
+
+	/**
+	 * Checks whether all active states are final. 
+	 * If there are no active states then the state machine is considered being incative. In this case this method returns <code>false</code>.
+	 */
+	public boolean isFinal();
+
+	/**
+	* Start a run-to-completion cycle.
+	*/
+	public void runCycle();
+}

+ 47 - 0
traffic_light/src-gen/traffic/light/ITimer.java

@@ -0,0 +1,47 @@
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+    committers of YAKINDU - initial API and implementation
+� */
+package traffic.light;
+
+/**
+ * Interface a timer has to implement. Use to implement your own timer
+ * service.
+ * 
+ */
+public interface ITimer {
+
+	/**
+	 * Starts the timing for a given time event id.
+	 * 
+	 * @param callback
+	 * 			  : The target callback where the time event has to be raised.
+	 * 
+	 * @param eventID
+	 *            : The eventID the timer should use if timed out.
+	 *            
+	 * @param time
+	 *            : Time in milliseconds after the given time event should be
+	 *            triggered
+	 *            
+	 * @param isPeriodic
+	 * 			  : Set to true if the time event should be triggered periodically
+	 */
+	public void setTimer(ITimerCallback callback, int eventID, long time, boolean isPeriodic);
+
+	/**
+	 * Unset a time event.
+	 * 
+	 * @param callback
+	 * 			: The target callback for which the time event has to be unset.
+	 * 
+	 * @param eventID
+	 * 			: The time event id.
+	 */
+	public void unsetTimer(ITimerCallback callback, int eventID);
+}

+ 24 - 0
traffic_light/src-gen/traffic/light/ITimerCallback.java

@@ -0,0 +1,24 @@
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+    committers of YAKINDU - initial API and implementation
+� */
+package traffic.light;
+
+/**
+* Interface for state machines which use timed event triggers.
+*/
+public interface ITimerCallback {
+	
+	/**
+	* Callback method if a time event occurred.
+	* 
+	* @param eventID
+	* 			:The id of the occurred event.
+	*/
+	public void timeElapsed(int eventID);
+}

+ 216 - 0
traffic_light/src-gen/traffic/light/RuntimeService.java

@@ -0,0 +1,216 @@
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+    committers of YAKINDU - initial API and implementation
+� */
+package traffic.light;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Runtime service for state machines to execute a run to completion step
+ * periodically.
+ * 
+ */
+public class RuntimeService {
+
+	private static RuntimeService runtimeService;
+
+	private Timer timer = null;
+
+	private Map<Long, StatemachineTimerTask> timerTasks = new HashMap<Long, StatemachineTimerTask>();
+
+	private class StatemachineTimerTask extends TimerTask {
+
+		private List<IStatemachine> statemachineList = new LinkedList<IStatemachine>();
+
+		private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+		private boolean isPaused = false;
+
+		@Override
+		public void run() {
+			lock.readLock().lock();
+			if (!isPaused) {
+				for (IStatemachine statemachine : statemachineList) {
+					statemachine.runCycle();
+				}
+			}
+			lock.readLock().unlock();
+		}
+
+		/**
+		 * Adds the given state machine to the TimerTask.
+		 *
+		 * @param statemachine
+		 * @return {@code true} if state machine is added properly.
+		 */
+		public boolean addStatemachine(IStatemachine statemachine) {
+			lock.writeLock().lock();
+			boolean ret = statemachineList.add(statemachine);
+			lock.writeLock().unlock();
+			return ret;
+		}
+
+		/**
+		 * Removes the given state machine from the TimerTask.
+		 *
+		 * @param statemachine
+		 * @return {@code true} if state machine is removed properly.
+		 */
+		public boolean removeStatemachine(IStatemachine statemachine) {
+			lock.writeLock().lock();
+			boolean ret = statemachineList.remove(statemachine);
+			lock.writeLock().unlock();
+			return ret;
+		}
+
+		public void pause() {
+			isPaused = true;
+		}
+
+		public void resume() {
+			isPaused = false;
+		}
+	}
+
+	private RuntimeService() {
+		// Not intended to be instantiated.
+	}
+
+	/**
+	 * Returns the {@code RuntimeService} instance as singleton.
+	 *
+	 * @return The singleton {@code RuntimeService} instance
+	 */
+	public static RuntimeService getInstance() {
+		if (runtimeService == null) {
+			runtimeService = new RuntimeService();
+		}
+		return runtimeService;
+	}
+
+	/**
+	 * Registers an {@link IStatemachine} for scheduled fixed rate execution
+	 *
+	 * @param statemachine
+	 *            - The state machine to execute
+	 * @param cyclePeriod
+	 *            - the fixed rate cycle period for scheduling
+	 * @return {@code true} if state machine is added properly.
+	 */
+	public boolean registerStatemachine(IStatemachine statemachine,
+			long cyclePeriod) {
+
+		if (timerTasks.containsKey(cyclePeriod)) {
+			// TimerTask for cycle time already existing -> add state machine
+			return timerTasks.get(cyclePeriod).addStatemachine(statemachine);
+		} else {
+			// Create new TimerTask for cycle period and add state machine
+			StatemachineTimerTask timerTask = new StatemachineTimerTask();
+			timerTasks.put(cyclePeriod, timerTask);
+			boolean ret = timerTask.addStatemachine(statemachine);
+			// Create a new Timer instance if runtime service was cancelled
+			// before
+			if (timer == null) {
+				timer = new Timer();
+			}
+			timer.scheduleAtFixedRate(timerTask, 0, cyclePeriod);
+			return ret;
+		}
+	}
+
+	/**
+	 * Removes the given state machine from runtime service.
+	 *
+	 * @param statemachine
+	 *            - the state machine to be removed
+	 * @param cyclePeriod
+	 *            - the scheduling cycle period of the state machine
+	 * @return {@code true} if state machine is removed properly.
+	 */
+	public boolean unregisterStatemachine(IStatemachine statemachine,
+			long cyclePeriod) {
+		if (timerTasks.containsKey(cyclePeriod)) {
+			boolean ret = timerTasks.get(cyclePeriod).removeStatemachine(
+					statemachine);
+
+			return ret;
+		}
+		return false;
+	}
+
+	/**
+	 * Cancels the execution of state machines for the given cycle period. This
+	 * stops the execution of state machines which are registered for the given
+	 * cycle period and cancels the executing {@link TimerTask}.
+	 *
+	 * @return {@code true} if poperly cancelled
+	 */
+	public boolean cancelAll(long cyclePeriod) {
+		if (timer != null && timerTasks.containsKey(cyclePeriod)) {
+			TimerTask task = timerTasks.get(cyclePeriod);
+			task.cancel();
+			timer.purge();
+			timerTasks.remove(cyclePeriod);
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Pauses the execution of all state machines which are registered for the
+	 * given cyclePeriod.
+	 *
+	 * @param cyclePeriod
+	 * @return {@code true} if properly paused
+	 *
+	 */
+	public boolean pauseAll(long cyclePeriod) {
+		if (timerTasks.containsKey(cyclePeriod)) {
+			timerTasks.get(cyclePeriod).pause();
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Resumes the execution of all state machines which are registered for the
+	 * given cyclePeriod.
+	 *
+	 * @param cyclePeriod
+	 * @return {@code true} if properly resumed
+	 *
+	 */
+	public boolean resumeAll(long cyclePeriod) {
+		if (timerTasks.containsKey(cyclePeriod)) {
+			timerTasks.get(cyclePeriod).resume();
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * Cancels the execution of all registered state machines. This cancels the
+	 * executing {@link Timer} freeing all allocated resources and terminates
+	 * all existing execution threads.
+	 */
+	public void cancelTimer() {
+		if (timer != null) {
+			timer.cancel();
+			timer.purge();
+			timerTasks.clear();
+			timer = null;
+		}
+	}
+}

+ 124 - 0
traffic_light/src-gen/traffic/light/TimerService.java

@@ -0,0 +1,124 @@
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+    committers of YAKINDU - initial API and implementation
+� */
+package traffic.light;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Default timer service implementation.
+ *
+ */
+public class TimerService implements ITimer {
+
+	private final Timer timer = new Timer();
+	
+	private final List<TimeEventTask> timerTaskList = new ArrayList<TimeEventTask>();
+	
+	private final Lock lock = new ReentrantLock();
+	
+	/**
+	 * Timer task that reflects a time event. It's internally used by
+	 * {@link TimerService}.
+	 *
+	 */
+	private class TimeEventTask extends TimerTask {
+	
+		private ITimerCallback callback;
+	
+		int eventID;
+	
+		/**
+		 * Constructor for a time event.
+		 *
+		 * @param callback
+		 *            : Object that implements ITimerCallback, is called
+		 *            when the timer expires.
+		 *
+		 * @param eventID
+		 *            : Index position within the state machine's timeEvent
+		 *            array.
+		 */
+		public TimeEventTask(ITimerCallback callback, int eventID) {
+			this.callback = callback;
+			this.eventID = eventID;
+		}
+	
+		public void run() {
+			callback.timeElapsed(eventID);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+			if (obj instanceof TimeEventTask) {
+				return ((TimeEventTask) obj).callback.equals(callback)
+						&& ((TimeEventTask) obj).eventID == eventID;
+			}
+			return super.equals(obj);
+		}
+		
+		@Override
+		public int hashCode() {
+			int prime = 37;
+			int result = 1;
+			
+			int c = (int) this.eventID;
+			result = prime * result + c;
+			c = this.callback.hashCode();
+			result = prime * result + c;
+			return result;
+		}
+		
+	}
+	
+	public void setTimer(final ITimerCallback callback, final int eventID,
+			long time, boolean isPeriodic) {
+	
+		// Create a new TimerTask for given event and store it.
+		TimeEventTask timerTask = new TimeEventTask(callback, eventID);
+		lock.lock();
+		timerTaskList.add(timerTask);
+	
+		// start scheduling the timer
+		if (isPeriodic) {
+			timer.scheduleAtFixedRate(timerTask, time, time);
+		} else {
+			timer.schedule(timerTask, time);
+		}
+		lock.unlock();
+	}
+	
+	public void unsetTimer(ITimerCallback callback, int eventID) {
+		lock.lock();
+		int index = timerTaskList.indexOf(new TimeEventTask(callback, eventID));
+		if (index != -1) {
+			timerTaskList.get(index).cancel();
+			timer.purge();
+			timerTaskList.remove(index);
+		}
+		lock.unlock();
+	}
+	
+	/**
+	 * Cancel timer service. Use this to end possible timing threads and free
+	 * memory resources.
+	 */
+	public void cancel() {
+		lock.lock();
+		timer.cancel();
+		timer.purge();
+		lock.unlock();
+	}
+}
+

+ 71 - 0
traffic_light/src-gen/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine.java

@@ -0,0 +1,71 @@
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+    committers of YAKINDU - initial API and implementation
+� */
+package traffic.light.trafficlightctrl;
+
+import traffic.light.IStatemachine;
+import traffic.light.ITimerCallback;
+
+public interface ITrafficLightCtrlStatemachine extends ITimerCallback,IStatemachine {
+
+	public interface SCITrafficLight {
+	
+		public boolean getRed();
+		
+		public void setRed(boolean value);
+		
+		public boolean getYellow();
+		
+		public void setYellow(boolean value);
+		
+		public boolean getGreen();
+		
+		public void setGreen(boolean value);
+		
+	}
+	
+	public SCITrafficLight getSCITrafficLight();
+	
+	public interface SCIPedestrian {
+	
+		public boolean getRequest();
+		
+		public void setRequest(boolean value);
+		
+		public boolean getRed();
+		
+		public void setRed(boolean value);
+		
+		public boolean getGreen();
+		
+		public void setGreen(boolean value);
+		
+	}
+	
+	public SCIPedestrian getSCIPedestrian();
+	
+	public interface SCInterface {
+	
+		public void raisePedestrianRequest();
+		
+		public void raiseOnOff();
+		
+		public void setSCInterfaceOperationCallback(SCInterfaceOperationCallback operationCallback);
+	
+	}
+	
+	public interface SCInterfaceOperationCallback {
+	
+		public void synchronize();
+		
+	}
+	
+	public SCInterface getSCInterface();
+	
+}

+ 279 - 0
traffic_light/src-gen/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine.java

@@ -0,0 +1,279 @@
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+    committers of YAKINDU - initial API and implementation
+� */
+package traffic.light.trafficlightctrl;
+import traffic.light.ITimer;
+import traffic.light.ITimerCallback;
+import traffic.light.trafficlightctrl.TrafficLightCtrlStatemachine.State;
+
+/**
+ * Runnable wrapper of TrafficLightCtrlStatemachine. This wrapper provides a thread-safe
+ * instance of the state machine.
+ * 
+ * Please report bugs and issues...
+ */
+
+public class SynchronizedTrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachine {
+	
+	/**
+	 * The core state machine is simply wrapped and the event processing will be
+	 * delegated to that state machine instance. This instance will be created
+	 * implicitly.
+	 */
+	protected TrafficLightCtrlStatemachine statemachine = new TrafficLightCtrlStatemachine();
+	
+	/**
+	 * Interface object for SCITrafficLight
+	 */		
+	protected class SynchronizedSCITrafficLight implements SCITrafficLight {
+		
+		public boolean getRed() {
+			synchronized(statemachine) {
+				return statemachine.getSCITrafficLight().getRed();
+			}
+		}
+		
+		public void setRed(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCITrafficLight().setRed(value);
+			}
+		}
+		
+		public boolean getYellow() {
+			synchronized(statemachine) {
+				return statemachine.getSCITrafficLight().getYellow();
+			}
+		}
+		
+		public void setYellow(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCITrafficLight().setYellow(value);
+			}
+		}
+		
+		public boolean getGreen() {
+			synchronized(statemachine) {
+				return statemachine.getSCITrafficLight().getGreen();
+			}
+		}
+		
+		public void setGreen(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCITrafficLight().setGreen(value);
+			}
+		}
+		
+	};
+	
+	protected SCITrafficLight sCITrafficLight;
+	
+	/**
+	 * Interface object for SCIPedestrian
+	 */		
+	protected class SynchronizedSCIPedestrian implements SCIPedestrian {
+		
+		public boolean getRequest() {
+			synchronized(statemachine) {
+				return statemachine.getSCIPedestrian().getRequest();
+			}
+		}
+		
+		public void setRequest(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCIPedestrian().setRequest(value);
+			}
+		}
+		
+		public boolean getRed() {
+			synchronized(statemachine) {
+				return statemachine.getSCIPedestrian().getRed();
+			}
+		}
+		
+		public void setRed(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCIPedestrian().setRed(value);
+			}
+		}
+		
+		public boolean getGreen() {
+			synchronized(statemachine) {
+				return statemachine.getSCIPedestrian().getGreen();
+			}
+		}
+		
+		public void setGreen(final boolean value) {
+			synchronized(statemachine) {
+				statemachine.getSCIPedestrian().setGreen(value);
+			}
+		}
+		
+	};
+	
+	protected SCIPedestrian sCIPedestrian;
+	
+	/**
+	 * Interface object for SCInterface
+	 */		
+	protected class SynchronizedSCInterface implements SCInterface {
+		
+		public void setSCInterfaceOperationCallback(SCInterfaceOperationCallback operationCallback) {
+			synchronized(statemachine) {
+				statemachine.getSCInterface().setSCInterfaceOperationCallback(operationCallback);
+			}
+		}
+		
+		public void raisePedestrianRequest() {
+			
+			synchronized (statemachine) {
+				statemachine.getSCInterface().raisePedestrianRequest();
+				statemachine.runCycle();
+			}
+		}
+		
+		public void raiseOnOff() {
+			
+			synchronized (statemachine) {
+				statemachine.getSCInterface().raiseOnOff();
+				statemachine.runCycle();
+			}
+		}
+		
+	};
+	
+	protected SCInterface sCInterface;
+	
+	public SynchronizedTrafficLightCtrlStatemachine() {
+		sCITrafficLight = new SynchronizedSCITrafficLight();
+		sCIPedestrian = new SynchronizedSCIPedestrian();
+		sCInterface = new SynchronizedSCInterface();
+	}
+	
+	public synchronized SCITrafficLight getSCITrafficLight() {
+		return sCITrafficLight;
+	}
+	public synchronized SCIPedestrian getSCIPedestrian() {
+		return sCIPedestrian;
+	}
+	public synchronized SCInterface getSCInterface() {
+		return sCInterface;
+	}
+	/*================ TIME EVENT HANDLING ================
+	
+	/** An external timer instance is required. */
+	protected ITimer externalTimer;
+	
+	/** Internally we use a timer proxy that queues time events together with other input events. */
+	protected ITimer timerProxy = new ITimer() {
+		/** Simply delegate to external timer with a modified callback. */
+		@Override
+		public void setTimer(ITimerCallback callback, int eventID, long time,
+				boolean isPeriodic) {
+			externalTimer.setTimer(SynchronizedTrafficLightCtrlStatemachine.this, eventID, time, isPeriodic);
+		}
+		
+		@Override
+		public void unsetTimer(ITimerCallback callback, int eventID) {
+			externalTimer.unsetTimer(SynchronizedTrafficLightCtrlStatemachine.this, eventID);
+		}
+	};
+	
+	/**
+	 * Set the {@link ITimer} for the state machine. It must be set externally
+	 * on a timed state machine before a run cycle can be correct executed.
+	 * 
+	 * @param timer
+	 */
+	public void setTimer(ITimer timer) {
+		synchronized(statemachine) {
+			this.externalTimer = timer;
+			/* the wrapped state machine uses timer proxy as timer */
+			statemachine.setTimer(timerProxy);
+		}
+	}
+	
+	/**
+	* Returns the currently used timer.
+	* 
+	* @return {@link ITimer}
+	*/
+	public ITimer getTimer() {
+		return externalTimer;
+	}
+	
+	public void timeElapsed(int eventID) {
+		synchronized (statemachine) {
+			statemachine.timeElapsed(eventID);
+		}
+	}
+	
+	/**
+	 * init() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void init() {
+		synchronized(statemachine) {
+			statemachine.init();
+		}
+	}
+	
+	/**
+	 * enter() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void enter() {
+		synchronized(statemachine) {
+			statemachine.enter();
+		}
+	}
+	
+	/**
+	 * exit() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void exit() {
+		synchronized(statemachine) {
+			statemachine.exit();
+		}
+	}
+	
+	/**
+	 * isActive() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isActive() {
+		synchronized(statemachine) {
+			return statemachine.isActive();
+		}
+	}
+	
+	/**
+	 * isFinal() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isFinal() {
+		synchronized(statemachine) {
+			return statemachine.isFinal();
+		}
+	}
+	
+	/**
+	 * isStateActive() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isStateActive(State state) {
+		synchronized(statemachine) {
+			return statemachine.isStateActive(state);
+		}
+	}
+	
+	/**
+	 * runCycle() will be delegated thread-safely to the wrapped state machine.
+	 */ 
+	@Override
+	public void runCycle() {
+		synchronized (statemachine) {
+			statemachine.runCycle();
+		}
+	}
+}

Plik diff jest za duży
+ 1356 - 0
traffic_light/src-gen/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine.java


+ 51 - 0
traffic_light/src/traffic/light/ButtonPanel.java

@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) 2016 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package traffic.light;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+/**
+ * 
+ * @author Tesch
+ *
+ */
+
+public class ButtonPanel extends JPanel {
+
+	private static final long serialVersionUID = 1L;
+	private JButton pedestrianRequest;
+	private JButton onOff;
+
+	public ButtonPanel() {
+		createContents();
+	}
+
+	private void createContents() {
+		pedestrianRequest = new JButton();
+		pedestrianRequest.setText("pedestrain request");
+		add(BorderLayout.SOUTH, pedestrianRequest);
+		onOff = new JButton();
+		onOff.setText("on / off");
+		add(BorderLayout.SOUTH, onOff);
+	}
+
+	public JButton getPedestrianRequest() {
+		return pedestrianRequest;
+	}
+
+	public JButton getOnOff() {
+		return onOff;
+	}
+
+}

+ 96 - 0
traffic_light/src/traffic/light/CrossWalkPanel.java

@@ -0,0 +1,96 @@
+package traffic.light;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Point;
+
+import javax.swing.JPanel;
+
+import traffic.light.TrafficLight.Alignment;
+
+public class CrossWalkPanel extends JPanel {
+
+	private static final long serialVersionUID = -7137708533029709629L;
+	protected TrafficLight trafficLight;
+	protected PedestrianLight pedLight;
+
+	
+	public CrossWalkPanel() {
+		super();
+		trafficLight = new TrafficLight(Alignment.HORIZONTAL);
+		pedLight = new PedestrianLight(PedestrianLight.Alignment.VERTICAL);
+	}
+	
+	public TrafficLight getTrafficLight() {
+		return trafficLight;
+	}
+
+	public PedestrianLight getPedLight() {
+		return pedLight;
+	}
+
+	public void paint(Graphics g) {
+		paintCrossing(g);
+		paintTrafficLights(g);
+		paintPedestrainLights(g);
+		g.dispose();
+	}
+
+	protected void paintPedestrainLights(Graphics g) {
+		pedLight.updatePosition(new Point(210, 80));
+		pedLight.paint(g);
+	}
+
+	protected void paintTrafficLights(Graphics g) {
+		trafficLight.updatePosition(new Point(170, 280));
+		trafficLight.paint(g);
+	}
+
+	protected void paintCrossing(Graphics g) {
+	
+		int width = getSize().width;
+
+		int streetYOffset = 150;
+		int streetWidth = 100;
+		
+		Dimension streetEastWest = new Dimension(width, streetWidth);
+		g.setColor(Color.darkGray);
+		paint(streetEastWest, 0, streetYOffset, true, g);
+
+		
+		g.setColor(Color.white);
+
+		Dimension laneSeparator = new Dimension(20, 4);
+		for (int i=0; i<4; i++) {
+			paint(laneSeparator, i * 2 * laneSeparator.width , streetYOffset -2 + streetWidth / 2, true, g);			
+		}
+
+		Dimension stopLine = new Dimension(10, streetWidth/2 +2);
+		paint(stopLine, 7 * laneSeparator.width , streetYOffset -2 + streetWidth / 2, true, g);			
+		
+		Dimension zebraStripe = new Dimension(80, 10);
+		
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 5, true, g);			
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 25 , true, g);			
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 45 , true, g);			
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 65 , true, g);			
+		paint(zebraStripe, 9 * laneSeparator.width , streetYOffset + 85 , true, g);		
+		
+		
+		paint(stopLine, 11 * laneSeparator.width + zebraStripe.width - stopLine.width, streetYOffset, true, g);			
+
+		for (int i=0; i<4; i++) {
+			paint(laneSeparator, (i * 2 + 11) * laneSeparator.width + zebraStripe.width, streetYOffset -2 + streetWidth / 2, true, g);			
+		}	
+	
+	}
+
+	
+	protected void paint(Dimension area, int x, int y, boolean horizontally, Graphics g) {
+		g.fillRect(x, y, 
+				horizontally ? area.width : area.height, 
+				horizontally ? area.height : area.width);
+
+	}
+}

+ 125 - 0
traffic_light/src/traffic/light/CrossingPanel.java

@@ -0,0 +1,125 @@
+/**
+ * Copyright (c) 2016 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package traffic.light;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+
+import traffic.light.TrafficLight.Alignment;
+
+/**
+ * 
+ * @author Tesch
+ *
+ */
+
+public class CrossingPanel extends CrossWalkPanel {
+
+	private static final long serialVersionUID = 2709756259645789247L;
+	
+	protected TrafficLight trafficLightWest;
+	protected TrafficLight trafficLightNorth;
+	protected TrafficLight trafficLightSouth;
+	protected PedestrianLight pedlightNorth;
+	
+	public CrossingPanel() {
+		super();
+		
+		trafficLightWest = new TrafficLight(Alignment.HORIZONTAL);
+		trafficLightNorth = new TrafficLight(Alignment.VERTICAL);
+		trafficLightSouth = new TrafficLight(Alignment.VERTICAL);
+		pedlightNorth = new PedestrianLight(PedestrianLight.Alignment.HORIZONTAL);
+	}
+
+	@Override
+	protected void paintTrafficLights(Graphics g) {
+		super.paintTrafficLights(g);
+		
+		trafficLightWest.updatePosition(new Point(25, 150));
+		trafficLightWest.paint(g);
+
+		trafficLightNorth.updatePosition(new Point(350, 25));
+		trafficLightNorth.paint(g);
+
+		trafficLightSouth.updatePosition(new Point(150, 425));
+		trafficLightSouth.paint(g);
+	}
+
+	@Override
+	protected void paintPedestrainLights(Graphics g) {
+		super.paintPedestrainLights(g);
+		
+		pedlightNorth.updatePosition(new Point(175, 25));
+		pedlightNorth.paint(g);
+	}
+	
+	@Override
+	protected void paintCrossing(Graphics g) {
+		
+		int breite = getSize().width;
+		int hoehe = getSize().height;
+	
+		g.setColor(Color.darkGray);
+		g.fillRect(225, 0, 100, hoehe);
+	
+		g.setColor(Color.darkGray);
+		g.fillRect(0, 225, breite, 100);
+	
+		g.setColor(Color.white);
+		g.fillRect(270, 0, 10, hoehe);
+	
+		g.setColor(Color.white);
+		g.fillRect(0, 270, breite, 10);
+	
+		g.setColor(Color.darkGray);
+		g.fillRect(225, 225, 100, 100);
+	
+		g.setColor(Color.white);
+		g.fillRect(225, 225, 100, 100);
+	
+		g.setColor(Color.darkGray);
+		g.fillRect(235, 235, 80, 80);
+	
+		g.setColor(Color.white);
+	
+		g.fillRect(230, 30, 10, 50);
+		g.fillRect(230 + 20, 30, 10, 50);
+		g.fillRect(230 + 40, 30, 10, 50);
+		g.fillRect(230 + 60, 30, 10, 50);
+		g.fillRect(230 + 80, 30, 10, 50);
+	
+		g.setColor(Color.white);
+		g.fillRect(475, 230, 50, 10);
+		g.fillRect(475, 230 + 20, 50, 10);
+		g.fillRect(475, 230 + 40, 50, 10);
+		g.fillRect(475, 230 + 60, 50, 10);
+		g.fillRect(475, 230 + 80, 50, 10);
+	
+	}
+
+
+	public TrafficLight getTrafficLightWest() {
+		return trafficLightWest;
+	}
+
+	public TrafficLight getTrafficLightNorth() {
+		return trafficLightNorth;
+	}
+
+	public TrafficLight getTrafficLightSouth() {
+		return trafficLightSouth;
+	}
+
+	public PedestrianLight getPedLightNorth() {
+		return pedlightNorth;
+	}
+}

+ 123 - 0
traffic_light/src/traffic/light/PedestrianLight.java

@@ -0,0 +1,123 @@
+/**
+ * Copyright (c) 2016 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package traffic.light;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.Rectangle;
+
+import javax.swing.JPanel;
+
+/**
+ * 
+ * @author Tesch
+ *
+ */
+
+public class PedestrianLight extends JPanel {
+
+	private static final long serialVersionUID = 1L;
+
+	boolean white = false;
+	boolean red = false;
+	boolean green = false;
+	private Alignment alignment;
+
+	public enum Alignment {
+		HORIZONTAL(50, 25), VERTICAL(25, 50);
+
+		private int width;
+		private int height;
+
+		Alignment(int width, int height) {
+			this.width = width;
+			this.height = height;
+		}
+
+		public int getWidth() {
+			return width;
+		}
+
+		public int getHeight() {
+			return height;
+		}
+
+	}
+
+	public PedestrianLight(Alignment alignment) {
+		this.alignment = alignment;
+	}
+
+	public boolean isWhite() {
+		return white;
+	}
+
+	public void setWhite(boolean white) {
+		this.white = white;
+	}
+
+	public boolean isRed() {
+		return red;
+	}
+
+	public void setRed(boolean red) {
+		this.red = red;
+	}
+
+	public boolean isGreen() {
+		return green;
+	}
+
+	public void setGreen(boolean green) {
+		this.green = green;
+	}
+
+	public void updatePosition(Point position) {
+		setBounds(new Rectangle(position.x, position.y, alignment.getWidth(), alignment.getHeight()));
+	}
+
+	@Override
+	public void paint(Graphics graphics) {
+		Rectangle bounds = getBounds();
+		graphics.setColor(Color.black);
+		graphics.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
+
+		if (alignment == Alignment.HORIZONTAL) {
+
+			graphics.setColor(white ? Color.white : Color.black);
+			graphics.fillRect(bounds.x + ((bounds.width - (3 * (bounds.height / 3))) / 4),
+					bounds.y + ((bounds.width - (3 * (bounds.height / 3))) / 4), bounds.width / 4, bounds.width / 4);
+
+			graphics.setColor(red ? Color.red : Color.black);
+			graphics.fillOval(bounds.x + (2 * ((bounds.width - (3 * (bounds.height / 3))) / 4)) + (bounds.height / 3),
+					bounds.y + ((bounds.width - (3 * (bounds.height / 3))) / 4), bounds.width / 4, bounds.width / 4);
+
+			graphics.setColor(green ? Color.green : Color.black);
+			graphics.fillOval(
+					bounds.x + (3 * ((bounds.width - (3 * (bounds.height / 3))) / 4)) + (2 * (bounds.height / 3)),
+					bounds.y + ((bounds.width - (3 * (bounds.height / 3))) / 4), bounds.width / 4, bounds.width / 4);
+
+		} else if (alignment == Alignment.VERTICAL) {
+
+			graphics.setColor(white ? Color.white : Color.black);
+			graphics.fillRect(bounds.x + 7, bounds.y + 2, bounds.height / 4, bounds.height / 4);
+
+			graphics.setColor(red ? Color.red : Color.black);
+			graphics.fillOval(bounds.x + 7, bounds.y + 2 * bounds.height / 5, bounds.height / 4, bounds.height / 4);
+
+			graphics.setColor(green ? Color.green : Color.black);
+			graphics.fillOval((bounds.x + (bounds.width / 2) - ((bounds.height / 5) / 2)),
+					bounds.y + bounds.height - (bounds.height / 5) - 5, bounds.height / 4, bounds.height / 4);
+		}
+	}
+
+}

+ 123 - 0
traffic_light/src/traffic/light/TrafficLight.java

@@ -0,0 +1,123 @@
+/**
+ * Copyright (c) 2016 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package traffic.light;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.Rectangle;
+
+import javax.swing.JPanel;
+
+/**
+ * 
+ * @author Tesch
+ *
+ */
+
+public class TrafficLight extends JPanel {
+
+	private boolean red = false;
+	private boolean yellow = false;
+	private boolean green = false;
+	private Alignment alignment;
+
+	public enum Alignment {
+		HORIZONTAL(100, 50), VERTICAL(50, 100);
+
+		private int width;
+		private int height;
+
+		Alignment(int width, int height) {
+			this.width = width;
+			this.height = height;
+		}
+
+		public int getWidth() {
+			return width;
+		}
+
+		public int getHeight() {
+			return height;
+		}
+
+	}
+
+	public TrafficLight(Alignment alignment) {
+		this.alignment = alignment;
+	}
+
+	public boolean isRed() {
+		return red;
+	}
+
+	public void setRed(boolean red) {
+		this.red = red;
+	}
+
+	public boolean isYellow() {
+		return yellow;
+	}
+
+	public void setYellow(boolean yellow) {
+		this.yellow = yellow;
+	}
+
+	public boolean isGreen() {
+		return green;
+	}
+
+	public void setGreen(boolean green) {
+		this.green = green;
+	}
+
+	private static final long serialVersionUID = 1L;
+
+	public void updatePosition(Point position) {
+		setBounds(new Rectangle(position.x, position.y, alignment.getWidth(), alignment.getHeight()));
+	}
+
+	@Override
+	public void paint(Graphics graphics) {
+		Rectangle bounds = getBounds();
+		graphics.setColor(Color.black);
+		graphics.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
+		
+		if (alignment == Alignment.VERTICAL) {
+
+			graphics.setColor(red ? Color.red : Color.black);
+			graphics.fillOval(bounds.x + 15, bounds.y + 5, bounds.height / 5, bounds.height / 5);
+
+			graphics.setColor(yellow ? Color.yellow : Color.black);
+			graphics.fillOval(bounds.x + 15, bounds.y + 2 * bounds.height / 5, bounds.height / 5, bounds.height / 5);
+
+			graphics.setColor(green ? Color.green : Color.black);
+			graphics.fillOval(bounds.x + (bounds.width / 2) - ((bounds.height / 5) / 2),
+					bounds.y + bounds.height - (bounds.height / 5) - 5, bounds.height / 5, bounds.height / 5);
+
+		} else if (alignment == Alignment.HORIZONTAL) {
+
+			graphics.setColor(red ? Color.red : Color.black);
+			graphics.fillOval(bounds.x + ((bounds.width - (3 * (bounds.height / 3))) / 4),
+					bounds.y + ((bounds.width - (3 * (bounds.height / 3))) / 4), bounds.width / 5, bounds.width / 5);
+
+			graphics.setColor(yellow ? Color.yellow : Color.black);
+			graphics.fillOval(bounds.x + (2 * ((bounds.width - (3 * (bounds.height / 3))) / 4)) + (bounds.height / 3),
+					bounds.y + ((bounds.width - (3 * (bounds.height / 3))) / 4), bounds.width / 5, bounds.width / 5);
+
+			graphics.setColor(green ? Color.green : Color.black);
+			graphics.fillOval(bounds.x + (3 * ((bounds.width - (3 * (bounds.height / 3))) / 4)) + (2 * (bounds.height / 3)),
+					bounds.y + ((bounds.width - (3 * (bounds.height / 3))) / 4), bounds.width / 5, bounds.width / 5);
+
+		}
+	}
+
+}

+ 96 - 0
traffic_light/src/traffic/light/TrafficlightDemo.java

@@ -0,0 +1,96 @@
+/**
+ * Copyright (c) 2016 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package traffic.light;
+
+import java.awt.BorderLayout;
+import java.awt.Graphics;
+
+import javax.swing.JFrame;
+
+import traffic.light.trafficlightctrl.*;
+
+/**
+ * 
+ * @author Tesch
+ *
+ */
+
+public class TrafficlightDemo extends JFrame {
+
+	private static final long serialVersionUID = -8909693541678814631L;
+
+	protected SynchronizedTrafficLightCtrlStatemachine statemachine;
+
+	protected TimerService timer;
+
+	private CrossWalkPanel crossing;
+
+	private ButtonPanel buttonPanel;
+
+	public static void main(String[] args) {
+		TrafficlightDemo application = new TrafficlightDemo();
+		application.createContents();
+		application.setupStatemachine();
+		application.run();
+	}
+
+	protected void run() {
+		statemachine.enter();
+		RuntimeService.getInstance().registerStatemachine(statemachine, 100);
+	}
+
+	protected void createContents() {
+		setLayout(new BorderLayout());
+		setTitle("Crosswalk traffic light");
+		crossing = new CrossWalkPanel();
+		add(BorderLayout.CENTER, crossing);
+		buttonPanel = new ButtonPanel();
+		add(BorderLayout.SOUTH, buttonPanel);
+		setSize(440, 440);
+		setVisible(true);
+	}
+
+	@Override
+	public void paint(Graphics g) {
+		super.paint(g);
+	}
+
+	protected void setupStatemachine() {
+		statemachine = new SynchronizedTrafficLightCtrlStatemachine();
+		timer = new TimerService();
+		statemachine.setTimer(timer);
+		statemachine.getSCInterface().setSCInterfaceOperationCallback(new ITrafficLightCtrlStatemachine.SCInterfaceOperationCallback() {
+			@Override
+			public void synchronize() {
+				checkTrafficLightStates();
+				repaint();
+			}
+		});
+		
+		statemachine.init();
+
+		buttonPanel.getPedestrianRequest()
+				.addActionListener(e -> statemachine.getSCInterface().raisePedestrianRequest());
+		buttonPanel.getOnOff().addActionListener(e -> statemachine.getSCInterface().raiseOnOff());
+	}
+
+	
+	protected void checkTrafficLightStates() {
+
+		crossing.getTrafficLight().setRed(statemachine.getSCITrafficLight().getRed());
+		crossing.getTrafficLight().setYellow(statemachine.getSCITrafficLight().getYellow());
+		crossing.getTrafficLight().setGreen(statemachine.getSCITrafficLight().getGreen());
+
+		crossing.getPedLight().setRed(statemachine.getSCIPedestrian().getRed());
+		crossing.getPedLight().setGreen(statemachine.getSCIPedestrian().getGreen());
+		crossing.getPedLight().setWhite(statemachine.getSCIPedestrian().getRequest());
+	}
+}

+ 8 - 0
traffic_light_basic/.classpath

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src-gen"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 2 - 0
traffic_light_basic/.gitignore

@@ -0,0 +1,2 @@
+/bin/
+/target/

+ 29 - 0
traffic_light_basic/.project

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>traffic_light_basic</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.yakindu.sct.builder.SCTBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.yakindu.sct.builder.SCTNature</nature>
+		<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+	</natures>
+</projectDescription>

+ 3 - 0
traffic_light_basic/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+encoding//model/TrafficLightCtrl.sct=UTF-8
+encoding/<project>=UTF-8

+ 2 - 0
traffic_light_basic/.settings/org.eclipse.core.runtime.prefs

@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+line.separator=\n

+ 12 - 0
traffic_light_basic/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8

+ 17 - 0
traffic_light_basic/README.TXT

@@ -0,0 +1,17 @@
+The traffic light example project is based on Java and contains a small GUI 
+that demonstrate the state machine behaviour in /model/TrafficLightWaiting.sct. 
+This example combines generated java code with manual Java implementations (the GUI). 
+To start the application run src/trafficlight_example/TrafficlightDemo.java. 
+In Eclipse select the project in the project explorer and right-click to open the 
+context menu. Select 'Run As > Java Application'. The application will start and 
+everything else should be self explaining
+
+ATTENTION:
+
+1! The example REQUIRES a JAVA 8 JDK. 
+
+2! When you installed the example then Eclipse may show errors on the project. This 
+is likely due to a missing configuration of the JDK. In this case select 'Properties'
+from the context menu on the project and set the correct JDK in 'Java Build Path'. You 
+will find further help in the 'Java development user guide' section of the Eclipse help.
+

BIN
traffic_light_basic/images/TrafficLightCtrl.png


+ 33 - 0
traffic_light_basic/index.html

@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="UTF-8">
+<title>Traffic Light (Java)</title>
+<link href="../css/style.css" rel="stylesheet">
+</head>
+<body class="body-container">
+
+  <h1>Traffic Light (Java)</h1>
+
+  <p>This example demonstrates how to to generate Javacode from a statechart. The procedure is explained in the documentation, chapter "Java code generator". </p>
+
+  <p>
+    <img class="standard-image" alt="The statechart"
+      src="images/TrafficLightCtrl.png" />
+  </p>
+
+  <p>In summary, there are two traffic lights: one for the traffic on the street, and
+    one for pedestrians who want to cross the street. They can push a button to
+    request their traffic light to turn green, which activates a blinking
+    wait-light first. The street's traffic light then goes through the standard
+    procedure, turning on the yellow light, followed by the red light, allowing
+    the pedestrians to cross safely. After some time, the pedestrians' traffic
+    light turns red again, and the cars are allowed to pass until the next
+    request is made by a pedestrian.</p>
+
+  <p>Additionally, the traffic light can be switched off completely. This
+    turns the yellow lights into a blinking mode, signaling that the traffic
+    light is indeed switched off and that the street should be crossed in a
+    careful manner.</p>
+</body>
+</html>

+ 12 - 0
traffic_light_basic/metadata.json

@@ -0,0 +1,12 @@
+{
+	"id": "org.yakindu.sct.examples.traffic_light_java",
+	"title": "Traffic Light (Java)",
+	"category": [
+		"open source",
+		"java",
+		"basic",
+		"interface",
+		"composite state",
+		"timer service"
+	]
+}

+ 143 - 0
traffic_light_basic/model/TrafficLightCtrl.sct

@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:sgraph="http://www.yakindu.org/sct/sgraph/2.0.0">
+  <sgraph:Statechart xmi:id="_Kl0RwBYbEeee7sC6Py90Ig" specification="interface:&#xA;  out event displayRed&#xA;  out event displayGreen&#xA;  out event displayYellow" name="TrafficLightCtrl">
+    <regions xmi:id="_KmaHoBYbEeee7sC6Py90Ig" name="main region">
+      <vertices xsi:type="sgraph:State" xmi:id="_P8Pj4BYbEeee7sC6Py90Ig" specification="entry / raise displayYellow" name="Yellow" incomingTransitions="_P8XfxBYbEeee7sC6Py90Ig">
+        <outgoingTransitions xmi:id="_P8RZJBYbEeee7sC6Py90Ig" specification="after 2s" target="_P8bxIBYbEeee7sC6Py90Ig"/>
+      </vertices>
+      <vertices xsi:type="sgraph:State" xmi:id="_P8WRkBYbEeee7sC6Py90Ig" specification="entry / raise displayGreen" name="Green" incomingTransitions="_P8c_VBYbEeee7sC6Py90Ig">
+        <outgoingTransitions xmi:id="_P8XfxBYbEeee7sC6Py90Ig" specification="after 3s" target="_P8Pj4BYbEeee7sC6Py90Ig"/>
+      </vertices>
+      <vertices xsi:type="sgraph:Entry" xmi:id="_P8bKEBYbEeee7sC6Py90Ig">
+        <outgoingTransitions xmi:id="_P8bKERYbEeee7sC6Py90Ig" target="_P8bxIBYbEeee7sC6Py90Ig"/>
+      </vertices>
+      <vertices xsi:type="sgraph:State" xmi:id="_P8bxIBYbEeee7sC6Py90Ig" specification="entry / raise displayRed" name="Red" incomingTransitions="_P8bKERYbEeee7sC6Py90Ig _P8RZJBYbEeee7sC6Py90Ig">
+        <outgoingTransitions xmi:id="_P8c_VBYbEeee7sC6Py90Ig" specification="after 5s" target="_P8WRkBYbEeee7sC6Py90Ig"/>
+      </vertices>
+    </regions>
+  </sgraph:Statechart>
+  <notation:Diagram xmi:id="_KmZgkBYbEeee7sC6Py90Ig" type="org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor" element="_Kl0RwBYbEeee7sC6Py90Ig" measurementUnit="Pixel">
+    <children xmi:id="_KmbVwBYbEeee7sC6Py90Ig" type="Region" element="_KmaHoBYbEeee7sC6Py90Ig">
+      <children xsi:type="notation:DecorationNode" xmi:id="_KmdyABYbEeee7sC6Py90Ig" type="RegionName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_KmdyARYbEeee7sC6Py90Ig"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_KmdyAhYbEeee7sC6Py90Ig"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_KmeZEBYbEeee7sC6Py90Ig" type="RegionCompartment" fontName="Verdana" lineColor="4210752">
+        <children xmi:id="_P8NusBYbEeee7sC6Py90Ig" type="State" element="_P8Pj4BYbEeee7sC6Py90Ig">
+          <children xsi:type="notation:DecorationNode" xmi:id="_P8NusRYbEeee7sC6Py90Ig" type="StateName">
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_P8NushYbEeee7sC6Py90Ig"/>
+            <layoutConstraint xsi:type="notation:Location" xmi:id="_P8NusxYbEeee7sC6Py90Ig"/>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_P8NutBYbEeee7sC6Py90Ig" type="StateTextCompartment">
+            <children xsi:type="notation:Shape" xmi:id="_P8NutRYbEeee7sC6Py90Ig" type="StateTextCompartmentExpression" fontName="Verdana" lineColor="4210752">
+              <layoutConstraint xsi:type="notation:Bounds" xmi:id="_P8NuthYbEeee7sC6Py90Ig"/>
+            </children>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_P8NutxYbEeee7sC6Py90Ig" type="StateFigureCompartment"/>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_P8NuuBYbEeee7sC6Py90Ig" fontName="Verdana" fillColor="15981773" lineColor="12632256"/>
+          <styles xsi:type="notation:FontStyle" xmi:id="_P8NuuRYbEeee7sC6Py90Ig"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_P8NuuhYbEeee7sC6Py90Ig" x="34" y="195" width="229" height="54"/>
+        </children>
+        <children xmi:id="_P8O80BYbEeee7sC6Py90Ig" type="State" element="_P8WRkBYbEeee7sC6Py90Ig">
+          <children xsi:type="notation:DecorationNode" xmi:id="_P8O80RYbEeee7sC6Py90Ig" type="StateName">
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_P8O80hYbEeee7sC6Py90Ig"/>
+            <layoutConstraint xsi:type="notation:Location" xmi:id="_P8O80xYbEeee7sC6Py90Ig"/>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_P8O81BYbEeee7sC6Py90Ig" type="StateTextCompartment">
+            <children xsi:type="notation:Shape" xmi:id="_P8O81RYbEeee7sC6Py90Ig" type="StateTextCompartmentExpression" fontName="Verdana" lineColor="4210752">
+              <layoutConstraint xsi:type="notation:Bounds" xmi:id="_P8O81hYbEeee7sC6Py90Ig"/>
+            </children>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_P8O81xYbEeee7sC6Py90Ig" type="StateFigureCompartment"/>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_P8O82BYbEeee7sC6Py90Ig" fontName="Verdana" fillColor="15981773" lineColor="12632256"/>
+          <styles xsi:type="notation:FontStyle" xmi:id="_P8O82RYbEeee7sC6Py90Ig"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_P8O82hYbEeee7sC6Py90Ig" x="33" y="111" width="230" height="53"/>
+        </children>
+        <children xmi:id="_P8O82xYbEeee7sC6Py90Ig" type="Entry" element="_P8bKEBYbEeee7sC6Py90Ig">
+          <children xmi:id="_P8O83BYbEeee7sC6Py90Ig" type="BorderItemLabelContainer">
+            <children xsi:type="notation:DecorationNode" xmi:id="_P8O83RYbEeee7sC6Py90Ig" type="BorderItemLabel">
+              <styles xsi:type="notation:ShapeStyle" xmi:id="_P8O83hYbEeee7sC6Py90Ig"/>
+              <layoutConstraint xsi:type="notation:Location" xmi:id="_P8O83xYbEeee7sC6Py90Ig"/>
+            </children>
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_P8O84BYbEeee7sC6Py90Ig" fontName="Verdana" lineColor="4210752"/>
+            <layoutConstraint xsi:type="notation:Bounds" xmi:id="_P8O84RYbEeee7sC6Py90Ig"/>
+          </children>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_P8O84hYbEeee7sC6Py90Ig" fontName="Verdana" lineColor="4210752"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_P8O84xYbEeee7sC6Py90Ig" x="151" y="-7" width="15" height="15"/>
+        </children>
+        <children xmi:id="_P8O85BYbEeee7sC6Py90Ig" type="State" element="_P8bxIBYbEeee7sC6Py90Ig">
+          <children xsi:type="notation:DecorationNode" xmi:id="_P8O85RYbEeee7sC6Py90Ig" type="StateName">
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_P8O85hYbEeee7sC6Py90Ig"/>
+            <layoutConstraint xsi:type="notation:Location" xmi:id="_P8O85xYbEeee7sC6Py90Ig"/>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_P8O86BYbEeee7sC6Py90Ig" type="StateTextCompartment">
+            <children xsi:type="notation:Shape" xmi:id="_P8O86RYbEeee7sC6Py90Ig" type="StateTextCompartmentExpression" fontName="Verdana" lineColor="4210752">
+              <layoutConstraint xsi:type="notation:Bounds" xmi:id="_P8O86hYbEeee7sC6Py90Ig"/>
+            </children>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_P8O86xYbEeee7sC6Py90Ig" type="StateFigureCompartment"/>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_P8O87BYbEeee7sC6Py90Ig" fontName="Verdana" fillColor="15981773" lineColor="12632256"/>
+          <styles xsi:type="notation:FontStyle" xmi:id="_P8O87RYbEeee7sC6Py90Ig"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_P8O87hYbEeee7sC6Py90Ig" x="31" y="24" width="234" height="57"/>
+        </children>
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_KmeZERYbEeee7sC6Py90Ig"/>
+      </children>
+      <styles xsi:type="notation:ShapeStyle" xmi:id="_KmbVwRYbEeee7sC6Py90Ig" fontName="Verdana" fillColor="15790320" lineColor="12632256"/>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_KmfnMBYbEeee7sC6Py90Ig" x="216" y="10" width="400" height="363"/>
+    </children>
+    <children xsi:type="notation:Shape" xmi:id="_Kmws8BYbEeee7sC6Py90Ig" type="StatechartText" fontName="Verdana" lineColor="4210752">
+      <children xsi:type="notation:DecorationNode" xmi:id="_KmxUABYbEeee7sC6Py90Ig" type="StatechartName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_KmxUARYbEeee7sC6Py90Ig"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_KmxUAhYbEeee7sC6Py90Ig"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_KmxUAxYbEeee7sC6Py90Ig" type="StatechartTextExpression" fontName="Verdana" lineColor="4210752">
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_KmxUBBYbEeee7sC6Py90Ig"/>
+      </children>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_Kmx7EBYbEeee7sC6Py90Ig" x="10" y="10" width="200" height="363"/>
+    </children>
+    <styles xsi:type="notation:DiagramStyle" xmi:id="_KmZgkRYbEeee7sC6Py90Ig"/>
+    <edges xmi:id="_P8gpoBYbEeee7sC6Py90Ig" type="Transition" element="_P8bKERYbEeee7sC6Py90Ig" source="_P8O82xYbEeee7sC6Py90Ig" target="_P8O85BYbEeee7sC6Py90Ig">
+      <children xsi:type="notation:DecorationNode" xmi:id="_P8gpoRYbEeee7sC6Py90Ig" type="TransitionExpression">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_P8gpohYbEeee7sC6Py90Ig"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_P8gpoxYbEeee7sC6Py90Ig" y="40"/>
+      </children>
+      <styles xsi:type="notation:ConnectorStyle" xmi:id="_P8gppBYbEeee7sC6Py90Ig" lineColor="4210752"/>
+      <styles xsi:type="notation:FontStyle" xmi:id="_P8gppRYbEeee7sC6Py90Ig" fontName="Verdana"/>
+      <bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_P8gpphYbEeee7sC6Py90Ig" points="[7, 0, -124, -1]$[127, 0, -4, -1]"/>
+      <targetAnchor xsi:type="notation:IdentityAnchor" xmi:id="_P8gppxYbEeee7sC6Py90Ig" id="(0.5854700854700855,0.0)"/>
+    </edges>
+    <edges xmi:id="_P8hQsBYbEeee7sC6Py90Ig" type="Transition" element="_P8c_VBYbEeee7sC6Py90Ig" source="_P8O85BYbEeee7sC6Py90Ig" target="_P8O80BYbEeee7sC6Py90Ig">
+      <children xsi:type="notation:DecorationNode" xmi:id="_P8hQsRYbEeee7sC6Py90Ig" type="TransitionExpression">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_P8hQshYbEeee7sC6Py90Ig"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_P8hQsxYbEeee7sC6Py90Ig" x="4" y="-40"/>
+      </children>
+      <styles xsi:type="notation:ConnectorStyle" xmi:id="_P8hQtBYbEeee7sC6Py90Ig" lineColor="4210752"/>
+      <styles xsi:type="notation:FontStyle" xmi:id="_P8hQtRYbEeee7sC6Py90Ig" fontName="Verdana"/>
+      <bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_P8hQthYbEeee7sC6Py90Ig" points="[5, 6, -3, -50]$[5, 27, -3, -29]$[5, 50, -3, -6]$[4, 51, -4, -5]$[4, 52, -4, -4]"/>
+      <sourceAnchor xsi:type="notation:IdentityAnchor" xmi:id="_P8hQtxYbEeee7sC6Py90Ig" id="(0.452991452991453,0.9478260869565217)"/>
+      <targetAnchor xsi:type="notation:IdentityAnchor" xmi:id="_P8hQuBYbEeee7sC6Py90Ig" id="(0.48484848484848486,0.0684931506849315)"/>
+    </edges>
+    <edges xmi:id="_P8hQuRYbEeee7sC6Py90Ig" type="Transition" element="_P8XfxBYbEeee7sC6Py90Ig" source="_P8O80BYbEeee7sC6Py90Ig" target="_P8NusBYbEeee7sC6Py90Ig">
+      <children xsi:type="notation:DecorationNode" xmi:id="_P8hQuhYbEeee7sC6Py90Ig" type="TransitionExpression">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_P8hQuxYbEeee7sC6Py90Ig"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_P8hQvBYbEeee7sC6Py90Ig" y="10"/>
+      </children>
+      <styles xsi:type="notation:ConnectorStyle" xmi:id="_P8hQvRYbEeee7sC6Py90Ig" routing="Rectilinear" lineColor="4210752"/>
+      <styles xsi:type="notation:FontStyle" xmi:id="_P8hQvhYbEeee7sC6Py90Ig" fontName="Verdana"/>
+      <bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_P8hQvxYbEeee7sC6Py90Ig" points="[72, 68, 62, -65]$[72, 132, 62, -1]"/>
+      <sourceAnchor xsi:type="notation:IdentityAnchor" xmi:id="_P8hQwBYbEeee7sC6Py90Ig" id="(0.15151515151515152,0.0)"/>
+      <targetAnchor xsi:type="notation:IdentityAnchor" xmi:id="_P8hQwRYbEeee7sC6Py90Ig" id="(0.19213973799126638,0.03389830508474576)"/>
+    </edges>
+    <edges xmi:id="_P8hQwhYbEeee7sC6Py90Ig" type="Transition" element="_P8RZJBYbEeee7sC6Py90Ig" source="_P8NusBYbEeee7sC6Py90Ig" target="_P8O85BYbEeee7sC6Py90Ig">
+      <children xsi:type="notation:DecorationNode" xmi:id="_P8hQwxYbEeee7sC6Py90Ig" type="TransitionExpression">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_P8hQxBYbEeee7sC6Py90Ig"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_P8hQxRYbEeee7sC6Py90Ig" y="10"/>
+      </children>
+      <styles xsi:type="notation:ConnectorStyle" xmi:id="_P8hQxhYbEeee7sC6Py90Ig" routing="Rectilinear" lineColor="4210752"/>
+      <styles xsi:type="notation:FontStyle" xmi:id="_P8hQxxYbEeee7sC6Py90Ig" fontName="Verdana"/>
+      <bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_P8hQyBYbEeee7sC6Py90Ig" points="[3, 13, 4, 190]$[58, 13, 59, 190]$[58, -182, 59, -5]$[5, -182, 6, -5]"/>
+      <sourceAnchor xsi:type="notation:IdentityAnchor" xmi:id="_P8hQyRYbEeee7sC6Py90Ig" id="(0.9868995633187773,0.48148148148148145)"/>
+      <targetAnchor xsi:type="notation:IdentityAnchor" xmi:id="_P8hQyhYbEeee7sC6Py90Ig" id="(0.9743589743589743,0.3391304347826087)"/>
+    </edges>
+  </notation:Diagram>
+</xmi:XMI>

+ 25 - 0
traffic_light_basic/model/TrafficLightCtrl.sgen

@@ -0,0 +1,25 @@
+GeneratorModel for yakindu::java {
+
+	statechart TrafficLightCtrl {
+	 	
+		feature Outlet {
+			targetProject = "traffic_light_basic"
+			targetFolder = "src-gen"
+		}
+
+		feature Naming {
+			basePackage = "traffic.light"
+			implementationSuffix = ""
+		}
+
+		feature GeneralFeatures {
+			TimerService = true
+			InterfaceObserverSupport = true
+		}
+		
+		feature RunnableWrapper {
+		    namePrefix = "Runnable"
+		    nameSuffix = "Wrapper"
+		}
+	}
+}

+ 39 - 0
traffic_light_basic/src-gen/traffic/light/IStatemachine.java

@@ -0,0 +1,39 @@
+package traffic.light;
+
+/**
+ * Basic interface for state machines.
+ */
+public interface IStatemachine {
+
+	/**
+	 * Initializes the state machine. Used to initialize internal variables etc.
+	 */
+	public void init();
+
+	/**
+	 * Enters the state machine. Sets the state machine into a defined state.
+	 */
+	public void enter();
+
+	/**
+	 * Exits the state machine. Leaves the state machine with a defined state.
+	 */
+	public void exit();
+
+	/**
+	 * Checks whether the state machine is active. 
+	 * A state machine is active if it has been entered. It is inactive if it has not been entered at all or if it has been exited.
+	 */
+	public boolean isActive();
+
+	/**
+	 * Checks whether all active states are final. 
+	 * If there are no active states then the state machine is considered being incative. In this case this method returns <code>false</code>.
+	 */
+	public boolean isFinal();
+
+	/**
+	* Start a run-to-completion cycle.
+	*/
+	public void runCycle();
+}

+ 38 - 0
traffic_light_basic/src-gen/traffic/light/ITimer.java

@@ -0,0 +1,38 @@
+package traffic.light;
+
+/**
+ * Interface a timer has to implement. Use to implement your own timer
+ * service.
+ * 
+ */
+public interface ITimer {
+
+	/**
+	 * Starts the timing for a given time event id.
+	 * 
+	 * @param callback
+	 * 			  : The target callback where the time event has to be raised.
+	 * 
+	 * @param eventID
+	 *            : The eventID the timer should use if timed out.
+	 *            
+	 * @param time
+	 *            : Time in milliseconds after the given time event should be
+	 *            triggered
+	 *            
+	 * @param isPeriodic
+	 * 			  : Set to true if the time event should be triggered periodically
+	 */
+	public void setTimer(ITimerCallback callback, int eventID, long time, boolean isPeriodic);
+
+	/**
+	 * Unset a time event.
+	 * 
+	 * @param callback
+	 * 			: The target callback for which the time event has to be unset.
+	 * 
+	 * @param eventID
+	 * 			: The time event id.
+	 */
+	public void unsetTimer(ITimerCallback callback, int eventID);
+}

+ 15 - 0
traffic_light_basic/src-gen/traffic/light/ITimerCallback.java

@@ -0,0 +1,15 @@
+package traffic.light;
+
+/**
+* Interface for state machines which use timed event triggers.
+*/
+public interface ITimerCallback {
+	
+	/**
+	* Callback method if a time event occurred.
+	* 
+	* @param eventID
+	* 			:The id of the occurred event.
+	*/
+	public void timeElapsed(int eventID);
+}

+ 115 - 0
traffic_light_basic/src-gen/traffic/light/TimerService.java

@@ -0,0 +1,115 @@
+package traffic.light;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Default timer service implementation.
+ *
+ */
+public class TimerService implements ITimer {
+
+	private final Timer timer = new Timer();
+	
+	private final List<TimeEventTask> timerTaskList = new ArrayList<TimeEventTask>();
+	
+	private final Lock lock = new ReentrantLock();
+	
+	/**
+	 * Timer task that reflects a time event. It's internally used by
+	 * {@link TimerService}.
+	 *
+	 */
+	private class TimeEventTask extends TimerTask {
+	
+		private ITimerCallback callback;
+	
+		int eventID;
+	
+		/**
+		 * Constructor for a time event.
+		 *
+		 * @param callback
+		 *            : Object that implements ITimerCallback, is called
+		 *            when the timer expires.
+		 *
+		 * @param eventID
+		 *            : Index position within the state machine's timeEvent
+		 *            array.
+		 */
+		public TimeEventTask(ITimerCallback callback, int eventID) {
+			this.callback = callback;
+			this.eventID = eventID;
+		}
+	
+		public void run() {
+			callback.timeElapsed(eventID);
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+			if (obj instanceof TimeEventTask) {
+				return ((TimeEventTask) obj).callback.equals(callback)
+						&& ((TimeEventTask) obj).eventID == eventID;
+			}
+			return super.equals(obj);
+		}
+		
+		@Override
+		public int hashCode() {
+			int prime = 37;
+			int result = 1;
+			
+			int c = (int) this.eventID;
+			result = prime * result + c;
+			c = this.callback.hashCode();
+			result = prime * result + c;
+			return result;
+		}
+		
+	}
+	
+	public void setTimer(final ITimerCallback callback, final int eventID,
+			long time, boolean isPeriodic) {
+	
+		// Create a new TimerTask for given event and store it.
+		TimeEventTask timerTask = new TimeEventTask(callback, eventID);
+		lock.lock();
+		timerTaskList.add(timerTask);
+	
+		// start scheduling the timer
+		if (isPeriodic) {
+			timer.scheduleAtFixedRate(timerTask, time, time);
+		} else {
+			timer.schedule(timerTask, time);
+		}
+		lock.unlock();
+	}
+	
+	public void unsetTimer(ITimerCallback callback, int eventID) {
+		lock.lock();
+		int index = timerTaskList.indexOf(new TimeEventTask(callback, eventID));
+		if (index != -1) {
+			timerTaskList.get(index).cancel();
+			timer.purge();
+			timerTaskList.remove(index);
+		}
+		lock.unlock();
+	}
+	
+	/**
+	 * Cancel timer service. Use this to end possible timing threads and free
+	 * memory resources.
+	 */
+	public void cancel() {
+		lock.lock();
+		timer.cancel();
+		timer.purge();
+		lock.unlock();
+	}
+}
+

+ 29 - 0
traffic_light_basic/src-gen/traffic/light/trafficlightctrl/ITrafficLightCtrlStatemachine.java

@@ -0,0 +1,29 @@
+package traffic.light.trafficlightctrl;
+
+import java.util.List;
+import traffic.light.IStatemachine;
+import traffic.light.ITimerCallback;
+
+public interface ITrafficLightCtrlStatemachine extends ITimerCallback,IStatemachine {
+
+	public interface SCInterface {
+	
+		public boolean isRaisedDisplayRed();
+		
+		public boolean isRaisedDisplayGreen();
+		
+		public boolean isRaisedDisplayYellow();
+		
+	public List<SCInterfaceListener> getListeners();
+	}
+	
+	public interface SCInterfaceListener {
+	
+		public void onDisplayRedRaised();
+		public void onDisplayGreenRaised();
+		public void onDisplayYellowRaised();
+		}
+	
+	public SCInterface getSCInterface();
+	
+}

+ 65 - 0
traffic_light_basic/src-gen/traffic/light/trafficlightctrl/RunnableTrafficLightCtrlStatemachineWrapper.java

@@ -0,0 +1,65 @@
+package traffic.light.trafficlightctrl;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Runnable wrapper of TrafficLightCtrlStatemachine. This wrapper provides a
+ * thread-safe, runnable instance of the state machine. The wrapper implements
+ * the {@link Runnable} interface and can be started in a thread by the client
+ * code. The run method then starts the main event processing loop for this
+ * state machine.
+ *
+ * Please report bugs and issues...
+ */
+
+public class RunnableTrafficLightCtrlStatemachineWrapper extends SynchronizedTrafficLightCtrlStatemachine implements Runnable {
+	
+	/**
+	 * The events are queued using a blocking queue without capacity
+	 * restriction. This queue holds Runnable instances that process the events.
+	 */
+	protected BlockingQueue<Runnable> eventQueue = new LinkedBlockingQueue<Runnable>();
+	
+	/**
+	 * Interface object for SCInterface
+	 */		
+	protected SCInterface sCInterface = new SynchronizedSCInterface() {
+	};
+	
+	public void timeElapsed(final int eventID) {
+		eventQueue.add(new Runnable() {
+	
+			@Override
+			public void run() {
+				synchronized (statemachine) {
+					statemachine.timeElapsed(eventID);
+					statemachine.runCycle();
+				}
+			}
+		});
+	}
+	
+	/**
+	 * This method will start the main execution loop for the state machine.
+	 * First it will init and enter the state machine implicitly and then will
+	 * start processing events from the event queue until the thread is
+	 * interrupted.
+	 */
+	@Override
+	public void run() {
+	
+		boolean terminate = false;
+		
+		while(!(terminate || Thread.currentThread().isInterrupted())) {
+	
+			try {
+				
+				Runnable eventProcessor = eventQueue.take();
+				eventProcessor.run();
+				
+			} catch (InterruptedException e) {
+				terminate = true;
+			}
+		}
+	}
+}

+ 176 - 0
traffic_light_basic/src-gen/traffic/light/trafficlightctrl/SynchronizedTrafficLightCtrlStatemachine.java

@@ -0,0 +1,176 @@
+package traffic.light.trafficlightctrl;
+import java.util.List;
+
+import traffic.light.ITimer;
+import traffic.light.ITimerCallback;
+import traffic.light.trafficlightctrl.TrafficLightCtrlStatemachine.State;
+
+/**
+ * Runnable wrapper of TrafficLightCtrlStatemachine. This wrapper provides a thread-safe
+ * instance of the state machine.
+ * 
+ * Please report bugs and issues...
+ */
+
+public class SynchronizedTrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachine {
+	
+	/**
+	 * The core state machine is simply wrapped and the event processing will be
+	 * delegated to that state machine instance. This instance will be created
+	 * implicitly.
+	 */
+	protected TrafficLightCtrlStatemachine statemachine = new TrafficLightCtrlStatemachine();
+	
+	/**
+	 * Interface object for SCInterface
+	 */		
+	protected class SynchronizedSCInterface implements SCInterface {
+		
+		public List<SCInterfaceListener> getListeners() {
+			synchronized(statemachine) {
+				return statemachine.getSCInterface().getListeners();
+			}
+		}
+		
+		public boolean isRaisedDisplayRed() {
+			synchronized(statemachine) {
+				return statemachine.getSCInterface().isRaisedDisplayRed();
+			}
+		}
+		
+		public boolean isRaisedDisplayGreen() {
+			synchronized(statemachine) {
+				return statemachine.getSCInterface().isRaisedDisplayGreen();
+			}
+		}
+		
+		public boolean isRaisedDisplayYellow() {
+			synchronized(statemachine) {
+				return statemachine.getSCInterface().isRaisedDisplayYellow();
+			}
+		}
+		
+	};
+	
+	protected SCInterface sCInterface;
+	
+	public SynchronizedTrafficLightCtrlStatemachine() {
+		sCInterface = new SynchronizedSCInterface();
+	}
+	
+	public synchronized SCInterface getSCInterface() {
+		return sCInterface;
+	}
+	/*================ TIME EVENT HANDLING ================
+	
+	/** An external timer instance is required. */
+	protected ITimer externalTimer;
+	
+	/** Internally we use a timer proxy that queues time events together with other input events. */
+	protected ITimer timerProxy = new ITimer() {
+		/** Simply delegate to external timer with a modified callback. */
+		@Override
+		public void setTimer(ITimerCallback callback, int eventID, long time,
+				boolean isPeriodic) {
+			externalTimer.setTimer(SynchronizedTrafficLightCtrlStatemachine.this, eventID, time, isPeriodic);
+		}
+		
+		@Override
+		public void unsetTimer(ITimerCallback callback, int eventID) {
+			externalTimer.unsetTimer(SynchronizedTrafficLightCtrlStatemachine.this, eventID);
+		}
+	};
+	
+	/**
+	 * Set the {@link ITimer} for the state machine. It must be set externally
+	 * on a timed state machine before a run cycle can be correct executed.
+	 * 
+	 * @param timer
+	 */
+	public void setTimer(ITimer timer) {
+		synchronized(statemachine) {
+			this.externalTimer = timer;
+			/* the wrapped state machine uses timer proxy as timer */
+			statemachine.setTimer(timerProxy);
+		}
+	}
+	
+	/**
+	* Returns the currently used timer.
+	* 
+	* @return {@link ITimer}
+	*/
+	public ITimer getTimer() {
+		return externalTimer;
+	}
+	
+	public void timeElapsed(int eventID) {
+		synchronized (statemachine) {
+			statemachine.timeElapsed(eventID);
+		}
+	}
+	
+	/**
+	 * init() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void init() {
+		synchronized(statemachine) {
+			statemachine.init();
+		}
+	}
+	
+	/**
+	 * enter() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void enter() {
+		synchronized(statemachine) {
+			statemachine.enter();
+		}
+	}
+	
+	/**
+	 * exit() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public void exit() {
+		synchronized(statemachine) {
+			statemachine.exit();
+		}
+	}
+	
+	/**
+	 * isActive() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isActive() {
+		synchronized(statemachine) {
+			return statemachine.isActive();
+		}
+	}
+	
+	/**
+	 * isFinal() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isFinal() {
+		synchronized(statemachine) {
+			return statemachine.isFinal();
+		}
+	}
+	
+	/**
+	 * isStateActive() will be delegated thread-safely to the wrapped state machine.
+	 */
+	public boolean isStateActive(State state) {
+		synchronized(statemachine) {
+			return statemachine.isStateActive(state);
+		}
+	}
+	
+	/**
+	 * runCycle() will be delegated thread-safely to the wrapped state machine.
+	 */ 
+	@Override
+	public void runCycle() {
+		synchronized (statemachine) {
+			statemachine.runCycle();
+		}
+	}
+}

+ 381 - 0
traffic_light_basic/src-gen/traffic/light/trafficlightctrl/TrafficLightCtrlStatemachine.java

@@ -0,0 +1,381 @@
+package traffic.light.trafficlightctrl;
+import java.util.LinkedList;
+import java.util.List;
+import traffic.light.ITimer;
+
+public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachine {
+
+	protected class SCInterfaceImpl implements SCInterface {
+	
+		private List<SCInterfaceListener> listeners = new LinkedList<SCInterfaceListener>();
+		
+		public List<SCInterfaceListener> getListeners() {
+			return listeners;
+		}
+		private boolean displayRed;
+		
+		public boolean isRaisedDisplayRed() {
+			return displayRed;
+		}
+		
+		protected void raiseDisplayRed() {
+			displayRed = true;
+			for (SCInterfaceListener listener : listeners) {
+				listener.onDisplayRedRaised();
+			}
+		}
+		
+		private boolean displayGreen;
+		
+		public boolean isRaisedDisplayGreen() {
+			return displayGreen;
+		}
+		
+		protected void raiseDisplayGreen() {
+			displayGreen = true;
+			for (SCInterfaceListener listener : listeners) {
+				listener.onDisplayGreenRaised();
+			}
+		}
+		
+		private boolean displayYellow;
+		
+		public boolean isRaisedDisplayYellow() {
+			return displayYellow;
+		}
+		
+		protected void raiseDisplayYellow() {
+			displayYellow = true;
+			for (SCInterfaceListener listener : listeners) {
+				listener.onDisplayYellowRaised();
+			}
+		}
+		
+		protected void clearEvents() {
+		}
+		protected void clearOutEvents() {
+		
+		displayRed = false;
+		displayGreen = false;
+		displayYellow = false;
+		}
+		
+	}
+	
+	protected SCInterfaceImpl sCInterface;
+	
+	private boolean initialized = false;
+	
+	public enum State {
+		main_region_Yellow,
+		main_region_Green,
+		main_region_Red,
+		$NullState$
+	};
+	
+	private final State[] stateVector = new State[1];
+	
+	private int nextStateIndex;
+	
+	private ITimer timer;
+	
+	private final boolean[] timeEvents = new boolean[3];
+	public TrafficLightCtrlStatemachine() {
+		sCInterface = new SCInterfaceImpl();
+	}
+	
+	public void init() {
+		this.initialized = true;
+		if (timer == null) {
+			throw new IllegalStateException("timer not set.");
+		}
+		for (int i = 0; i < 1; i++) {
+			stateVector[i] = State.$NullState$;
+		}
+		clearEvents();
+		clearOutEvents();
+	}
+	
+	public void enter() {
+		if (!initialized) {
+			throw new IllegalStateException(
+					"The state machine needs to be initialized first by calling the init() function.");
+		}
+		if (timer == null) {
+			throw new IllegalStateException("timer not set.");
+		}
+		enterSequence_main_region_default();
+	}
+	
+	public void exit() {
+		exitSequence_main_region();
+	}
+	
+	/**
+	 * @see IStatemachine#isActive()
+	 */
+	public boolean isActive() {
+		return stateVector[0] != State.$NullState$;
+	}
+	
+	/** 
+	* Always returns 'false' since this state machine can never become final.
+	*
+	* @see IStatemachine#isFinal()
+	*/
+	public boolean isFinal() {
+		return false;
+	}
+	/**
+	* This method resets the incoming events (time events included).
+	*/
+	protected void clearEvents() {
+		sCInterface.clearEvents();
+		for (int i=0; i<timeEvents.length; i++) {
+			timeEvents[i] = false;
+		}
+	}
+	
+	/**
+	* This method resets the outgoing events.
+	*/
+	protected void clearOutEvents() {
+		sCInterface.clearOutEvents();
+	}
+	
+	/**
+	* Returns true if the given state is currently active otherwise false.
+	*/
+	public boolean isStateActive(State state) {
+	
+		switch (state) {
+		case main_region_Yellow:
+			return stateVector[0] == State.main_region_Yellow;
+		case main_region_Green:
+			return stateVector[0] == State.main_region_Green;
+		case main_region_Red:
+			return stateVector[0] == State.main_region_Red;
+		default:
+			return false;
+		}
+	}
+	
+	/**
+	* Set the {@link ITimer} for the state machine. It must be set
+	* externally on a timed state machine before a run cycle can be correct
+	* executed.
+	* 
+	* @param timer
+	*/
+	public void setTimer(ITimer timer) {
+		this.timer = timer;
+	}
+	
+	/**
+	* Returns the currently used timer.
+	* 
+	* @return {@link ITimer}
+	*/
+	public ITimer getTimer() {
+		return timer;
+	}
+	
+	public void timeElapsed(int eventID) {
+		timeEvents[eventID] = true;
+	}
+	
+	public SCInterface getSCInterface() {
+		return sCInterface;
+	}
+	
+	public boolean isRaisedDisplayRed() {
+		return sCInterface.isRaisedDisplayRed();
+	}
+	
+	public boolean isRaisedDisplayGreen() {
+		return sCInterface.isRaisedDisplayGreen();
+	}
+	
+	public boolean isRaisedDisplayYellow() {
+		return sCInterface.isRaisedDisplayYellow();
+	}
+	
+	private boolean check_main_region_Yellow_tr0_tr0() {
+		return timeEvents[0];
+	}
+	
+	private boolean check_main_region_Green_tr0_tr0() {
+		return timeEvents[1];
+	}
+	
+	private boolean check_main_region_Red_tr0_tr0() {
+		return timeEvents[2];
+	}
+	
+	private void effect_main_region_Yellow_tr0() {
+		exitSequence_main_region_Yellow();
+		enterSequence_main_region_Red_default();
+	}
+	
+	private void effect_main_region_Green_tr0() {
+		exitSequence_main_region_Green();
+		enterSequence_main_region_Yellow_default();
+	}
+	
+	private void effect_main_region_Red_tr0() {
+		exitSequence_main_region_Red();
+		enterSequence_main_region_Green_default();
+	}
+	
+	/* Entry action for state 'Yellow'. */
+	private void entryAction_main_region_Yellow() {
+		timer.setTimer(this, 0, 2 * 1000, false);
+		
+		sCInterface.raiseDisplayYellow();
+	}
+	
+	/* Entry action for state 'Green'. */
+	private void entryAction_main_region_Green() {
+		timer.setTimer(this, 1, 3 * 1000, false);
+		
+		sCInterface.raiseDisplayGreen();
+	}
+	
+	/* Entry action for state 'Red'. */
+	private void entryAction_main_region_Red() {
+		timer.setTimer(this, 2, 5 * 1000, false);
+		
+		sCInterface.raiseDisplayRed();
+	}
+	
+	/* Exit action for state 'Yellow'. */
+	private void exitAction_main_region_Yellow() {
+		timer.unsetTimer(this, 0);
+	}
+	
+	/* Exit action for state 'Green'. */
+	private void exitAction_main_region_Green() {
+		timer.unsetTimer(this, 1);
+	}
+	
+	/* Exit action for state 'Red'. */
+	private void exitAction_main_region_Red() {
+		timer.unsetTimer(this, 2);
+	}
+	
+	/* 'default' enter sequence for state Yellow */
+	private void enterSequence_main_region_Yellow_default() {
+		entryAction_main_region_Yellow();
+		nextStateIndex = 0;
+		stateVector[0] = State.main_region_Yellow;
+	}
+	
+	/* 'default' enter sequence for state Green */
+	private void enterSequence_main_region_Green_default() {
+		entryAction_main_region_Green();
+		nextStateIndex = 0;
+		stateVector[0] = State.main_region_Green;
+	}
+	
+	/* 'default' enter sequence for state Red */
+	private void enterSequence_main_region_Red_default() {
+		entryAction_main_region_Red();
+		nextStateIndex = 0;
+		stateVector[0] = State.main_region_Red;
+	}
+	
+	/* 'default' enter sequence for region main region */
+	private void enterSequence_main_region_default() {
+		react_main_region__entry_Default();
+	}
+	
+	/* Default exit sequence for state Yellow */
+	private void exitSequence_main_region_Yellow() {
+		nextStateIndex = 0;
+		stateVector[0] = State.$NullState$;
+		
+		exitAction_main_region_Yellow();
+	}
+	
+	/* Default exit sequence for state Green */
+	private void exitSequence_main_region_Green() {
+		nextStateIndex = 0;
+		stateVector[0] = State.$NullState$;
+		
+		exitAction_main_region_Green();
+	}
+	
+	/* Default exit sequence for state Red */
+	private void exitSequence_main_region_Red() {
+		nextStateIndex = 0;
+		stateVector[0] = State.$NullState$;
+		
+		exitAction_main_region_Red();
+	}
+	
+	/* Default exit sequence for region main region */
+	private void exitSequence_main_region() {
+		switch (stateVector[0]) {
+		case main_region_Yellow:
+			exitSequence_main_region_Yellow();
+			break;
+		case main_region_Green:
+			exitSequence_main_region_Green();
+			break;
+		case main_region_Red:
+			exitSequence_main_region_Red();
+			break;
+		default:
+			break;
+		}
+	}
+	
+	/* The reactions of state Yellow. */
+	private void react_main_region_Yellow() {
+		if (check_main_region_Yellow_tr0_tr0()) {
+			effect_main_region_Yellow_tr0();
+		}
+	}
+	
+	/* The reactions of state Green. */
+	private void react_main_region_Green() {
+		if (check_main_region_Green_tr0_tr0()) {
+			effect_main_region_Green_tr0();
+		}
+	}
+	
+	/* The reactions of state Red. */
+	private void react_main_region_Red() {
+		if (check_main_region_Red_tr0_tr0()) {
+			effect_main_region_Red_tr0();
+		}
+	}
+	
+	/* Default react sequence for initial entry  */
+	private void react_main_region__entry_Default() {
+		enterSequence_main_region_Red_default();
+	}
+	
+	public void runCycle() {
+		if (!initialized)
+			throw new IllegalStateException(
+					"The state machine needs to be initialized first by calling the init() function.");
+		clearOutEvents();
+		for (nextStateIndex = 0; nextStateIndex < stateVector.length; nextStateIndex++) {
+			switch (stateVector[nextStateIndex]) {
+			case main_region_Yellow:
+				react_main_region_Yellow();
+				break;
+			case main_region_Green:
+				react_main_region_Green();
+				break;
+			case main_region_Red:
+				react_main_region_Red();
+				break;
+			default:
+				// $NullState$
+			}
+		}
+		clearEvents();
+	}
+}

+ 48 - 0
traffic_light_basic/src/traffic/light/TrafficlightDemo.java

@@ -0,0 +1,48 @@
+package traffic.light;
+
+import traffic.light.trafficlightctrl.ITrafficLightCtrlStatemachine;
+import traffic.light.trafficlightctrl.RunnableTrafficLightCtrlStatemachineWrapper;
+
+public class TrafficlightDemo {
+	
+	protected RunnableTrafficLightCtrlStatemachineWrapper statemachine;
+
+	protected TimerService timer;
+
+	public static void main(String[] args) {
+		TrafficlightDemo application = new TrafficlightDemo();
+		application.setupStatemachine();
+		application.run();
+	}
+
+	protected void run() {
+		statemachine.enter();
+		statemachine.run();
+	}
+
+	protected void setupStatemachine() {
+		statemachine = new RunnableTrafficLightCtrlStatemachineWrapper();
+		timer = new TimerService();
+		statemachine.setTimer(timer);
+		
+		statemachine.getSCInterface().getListeners().add(new ITrafficLightCtrlStatemachine.SCInterfaceListener() {
+			
+			@Override
+			public void onDisplayYellowRaised() {
+				System.out.println("Yellow!");
+			}
+			
+			@Override
+			public void onDisplayRedRaised() {
+				System.out.println("Red!");
+			}
+			
+			@Override
+			public void onDisplayGreenRaised() {
+				System.out.println("Green!");
+			}
+		});
+		
+		statemachine.init();
+	}
+}

+ 7 - 0
traffic_light_generated/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="src-gen"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
traffic_light_generated/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>traffic_light_generated</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 11 - 0
traffic_light_generated/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8

BIN
traffic_light_generated/bin/traffic/light/ButtonPanel.class


BIN
traffic_light_generated/bin/traffic/light/CrossWalkPanel.class


BIN
traffic_light_generated/bin/traffic/light/IStatemachine.class


BIN
traffic_light_generated/bin/traffic/light/ITimer.class


BIN
traffic_light_generated/bin/traffic/light/ITimerCallback.class


BIN
traffic_light_generated/bin/traffic/light/RuntimeService$StatemachineTimerTask.class


BIN
traffic_light_generated/bin/traffic/light/RuntimeService.class


BIN
traffic_light_generated/bin/traffic/light/TimerService$TimeEventTask.class


BIN
traffic_light_generated/bin/traffic/light/TimerService.class


BIN
traffic_light_generated/bin/traffic/light/TrafficLight$Alignment.class


BIN
traffic_light_generated/bin/traffic/light/TrafficLight.class


BIN
traffic_light_generated/bin/traffic/light/TrafficlightDemo$1.class


BIN
traffic_light_generated/bin/traffic/light/TrafficlightDemo.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/ITrafficLightCtrl_GeneratorAcceptorStatemachine$SCITrafficLight.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/ITrafficLightCtrl_GeneratorAcceptorStatemachine$SCInterface.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/ITrafficLightCtrl_GeneratorAcceptorStatemachine$SCInterfaceOperationCallback.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/ITrafficLightCtrl_GeneratorAcceptorStatemachine.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/SynchronizedTrafficLightCtrl_GeneratorAcceptorStatemachine$1.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/SynchronizedTrafficLightCtrl_GeneratorAcceptorStatemachine$SynchronizedSCITrafficLight.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/SynchronizedTrafficLightCtrl_GeneratorAcceptorStatemachine$SynchronizedSCInterface.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/SynchronizedTrafficLightCtrl_GeneratorAcceptorStatemachine.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/TrafficLightCtrl_GeneratorAcceptorStatemachine$SCITrafficLightImpl.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/TrafficLightCtrl_GeneratorAcceptorStatemachine$SCInterfaceImpl.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/TrafficLightCtrl_GeneratorAcceptorStatemachine$State.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor/TrafficLightCtrl_GeneratorAcceptorStatemachine.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor2/ITrafficLightCtrl_GeneratorAcceptor2Statemachine$SCITrafficLight.class


BIN
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor2/ITrafficLightCtrl_GeneratorAcceptor2Statemachine$SCInterface.class


+ 0 - 0
traffic_light_generated/bin/traffic/light/trafficlightctrl_generatoracceptor2/ITrafficLightCtrl_GeneratorAcceptor2Statemachine$SCInterfaceOperationCallback.class


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików