From a5608245e09cfd68f6173fd37d69c4b868199d33 Mon Sep 17 00:00:00 2001 From: graefjk Date: Wed, 3 Jan 2024 23:18:44 +0100 Subject: [PATCH 1/6] made letters in artifactID lowercase and changed Version to 2.3.8 --- ICGE-Log/pom.xml | 52 +++--- ICGE-ManualStart/pom.xml | 52 +++--- ICGE-Simulation/pom.xml | 76 +++++---- ICGE-Ui/pom.xml | 124 +++++++------- ICGE-archetype-module/pom.xml | 16 +- ICGE-build-tools/pom.xml | 20 ++- pom.xml | 310 ++++++++++++++++++---------------- 7 files changed, 343 insertions(+), 307 deletions(-) diff --git a/ICGE-Log/pom.xml b/ICGE-Log/pom.xml index bcd76515d..61bf72a44 100644 --- a/ICGE-Log/pom.xml +++ b/ICGE-Log/pom.xml @@ -1,27 +1,29 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - ICGE - 2.3.8-Snapshot - - ICGE-Log - ICGE Log - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-log + ICGE Log + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + + + diff --git a/ICGE-ManualStart/pom.xml b/ICGE-ManualStart/pom.xml index f78795535..6499af459 100644 --- a/ICGE-ManualStart/pom.xml +++ b/ICGE-ManualStart/pom.xml @@ -1,25 +1,31 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - ICGE - 2.3.8-Snapshot - - ICGE-ManualStart - ICGE Manual Start - - - de.uni-stuttgart.informatik.fius - ICGE-Simulation - - - - - - net.revelc.code.formatter - formatter-maven-plugin - - - + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-manualstart + ICGE Manual Start + + 2.3.8 + + + + de.uni-stuttgart.informatik.fius + ICGE-Simulation + ${icge.version} + + + + + + net.revelc.code.formatter + formatter-maven-plugin + + + diff --git a/ICGE-Simulation/pom.xml b/ICGE-Simulation/pom.xml index bcd82b3ee..91964317c 100644 --- a/ICGE-Simulation/pom.xml +++ b/ICGE-Simulation/pom.xml @@ -1,37 +1,43 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - ICGE - 2.3.8-Snapshot - - ICGE-Simulation - ICGE Simulation - - - org.junit.jupiter - junit-jupiter-engine - - - de.uni-stuttgart.informatik.fius - ICGE-Ui - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-simulation + ICGE Simulation + + 2.3.8 + + + + org.junit.jupiter + junit-jupiter-engine + + + de.uni-stuttgart.informatik.fius + ICGE-Ui + ${icge.version} + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + + + diff --git a/ICGE-Ui/pom.xml b/ICGE-Ui/pom.xml index e088ce3a7..a3578d2b8 100644 --- a/ICGE-Ui/pom.xml +++ b/ICGE-Ui/pom.xml @@ -1,61 +1,67 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - ICGE - 2.3.8-Snapshot - - ICGE-Ui - ICGE Ui - - - org.junit.jupiter - junit-jupiter-engine - - - de.uni-stuttgart.informatik.fius - ICGE-Log - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - - - - noUiTests - - - noUiTests - true - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*UiTest.java - - - - - - - + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-ui + ICGE Ui + + 2.3.8 + + + + org.junit.jupiter + junit-jupiter-engine + + + de.uni-stuttgart.informatik.fius + ICGE-Log + ${icge.version} + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + + + + + + noUiTests + + + noUiTests + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*UiTest.java + + + + + + + diff --git a/ICGE-archetype-module/pom.xml b/ICGE-archetype-module/pom.xml index 3c2062ac3..03deb0ad9 100644 --- a/ICGE-archetype-module/pom.xml +++ b/ICGE-archetype-module/pom.xml @@ -1,9 +1,11 @@ - - 4.0.0 - de.uni-stuttgart.informatik.fius - ICGE-archetype-module - 1.0.0 - Archetype for FIUS ICGE Modules - http://maven.apache.org + + 4.0.0 + de.uni-stuttgart.informatik.fius + icge-archetype-module + 1.0.0 + Archetype for FIUS ICGE Modules + http://maven.apache.org diff --git a/ICGE-build-tools/pom.xml b/ICGE-build-tools/pom.xml index 8e1344f05..5245e50e4 100644 --- a/ICGE-build-tools/pom.xml +++ b/ICGE-build-tools/pom.xml @@ -1,11 +1,13 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - ICGE - 2.3.8-Snapshot - - ICGE-build-tools - ICGE build tools + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-build-tools + ICGE build tools diff --git a/pom.xml b/pom.xml index ff9a6cdf4..a40f45c2d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,151 +1,163 @@ - - 4.0.0 - de.uni-stuttgart.informatik.fius - ICGE - 2.3.8-Snapshot - Introduction Course Game Engine - The game engine for the java intoduction course of FIUS - https://fius.github.io/ICGE2 - pom - - 11 - 5.3.1 - 1.1.0 - 2.3.8-Snapshot - UTF-8 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - maven-surefire-plugin - 2.19.1 - - - - **/Test*.java - **/*Test.java - **/*Tests.java - **/*TestCase.java - - - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.1.1 - - - attach-javadocs - - jar - - - - - - maven-deploy-plugin - 2.8.2 - - true - - - - org.apache.maven.plugins - maven-source-plugin - 3.1.0 - - - attach-sources - - jar - - - - - - net.revelc.code.formatter - formatter-maven-plugin - 2.10.0 - - LF - build_tools/eclipse/ICGE-Formatter.xml - true - ${java.version} - ${java.version} - ${java.version} - - - - de.uni-stuttgart.informatik.fius - ICGE-build-tools - ${icge.version} - - - - - - - - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - - - de.uni-stuttgart.informatik.fius - ICGE-Ui - ${icge.version} - - - de.uni-stuttgart.informatik.fius - ICGE-Simulation - ${icge.version} - - - de.uni-stuttgart.informatik.fius - ICGE-Log - ${icge.version} - - - - - - c-hack.icge-release - C-Hack ICGE-Release Repo - https://maven.c-hack.de/repository/icge-release/ - - - c-hack.snapshot - C-Hack Repositroy Snapshot - https://maven.c-hack.de/repository/snapshot/ - - - - ICGE-Ui - ICGE-Simulation - ICGE-ManualStart - ICGE-Log - ICGE-build-tools - + + 4.0.0 + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + Introduction Course Game Engine + The game engine for the java intoduction course of FIUS + https://fius.github.io/icge2 + pom + + 11 + 5.3.1 + 1.1.0 + 2.3.8 + UTF-8 + ICGE2 + project.groupId + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + maven-surefire-plugin + 2.19.1 + + + + **/Test*.java + **/*Test.java + **/*Tests.java + **/*TestCase.java + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + attach-javadocs + + jar + + + + + + maven-deploy-plugin + 3.1.1 + + ${project.artifactId} + ${project.groupId} + ${icge.version} + false + + + + deploy-executable + + deploy-file + + + target/*.jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.1.0 + + + attach-sources + + jar + + + + + + net.revelc.code.formatter + formatter-maven-plugin + 2.10.0 + + LF + build_tools/eclipse/icge-Formatter.xml + true + ${java.version} + ${java.version} + ${java.version} + + + + de.uni-stuttgart.informatik.fius + ICGE2-build-tools + ${icge.version} + + + + + + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + de.uni-stuttgart.informatik.fius + ICGE2-Ui + ${icge.version} + + + de.uni-stuttgart.informatik.fius + ICGE2-Simulation + ${icge.version} + + + de.uni-stuttgart.informatik.fius + ICGE2-Log + ${icge.version} + + + + + + github + https://maven.pkg.github.com/graefjk/ICGE2 + + + + ICGE-Ui + ICGE-Simulation + ICGE-ManualStart + ICGE-Log + ICGE-build-tools + From 293a2049da1ca64581ca140db711b00b2b7399fa Mon Sep 17 00:00:00 2001 From: graefjk Date: Thu, 4 Jan 2024 00:10:14 +0100 Subject: [PATCH 2/6] formatting --- ICGE-Log/pom.xml | 52 +++--- ICGE-ManualStart/pom.xml | 56 +++--- ICGE-Simulation/pom.xml | 80 +++++---- ICGE-Ui/pom.xml | 128 +++++++------- ICGE-archetype-module/pom.xml | 16 +- ICGE-build-tools/pom.xml | 20 +-- pom.xml | 318 +++++++++++++++++----------------- 7 files changed, 328 insertions(+), 342 deletions(-) diff --git a/ICGE-Log/pom.xml b/ICGE-Log/pom.xml index 61bf72a44..d1c301871 100644 --- a/ICGE-Log/pom.xml +++ b/ICGE-Log/pom.xml @@ -1,29 +1,27 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - icge - 2.3.8 - - icge-log - ICGE Log - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-log + ICGE Log + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + + + diff --git a/ICGE-ManualStart/pom.xml b/ICGE-ManualStart/pom.xml index 6499af459..ff4de8a94 100644 --- a/ICGE-ManualStart/pom.xml +++ b/ICGE-ManualStart/pom.xml @@ -1,31 +1,29 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - icge - 2.3.8 - - icge-manualstart - ICGE Manual Start - - 2.3.8 - - - - de.uni-stuttgart.informatik.fius - ICGE-Simulation - ${icge.version} - - - - - - net.revelc.code.formatter - formatter-maven-plugin - - - + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-manualstart + ICGE Manual Start + + 2.3.8 + + + + de.uni-stuttgart.informatik.fius + icge-simulation + ${icge.version} + + + + + + net.revelc.code.formatter + formatter-maven-plugin + + + diff --git a/ICGE-Simulation/pom.xml b/ICGE-Simulation/pom.xml index 91964317c..0d106a9b9 100644 --- a/ICGE-Simulation/pom.xml +++ b/ICGE-Simulation/pom.xml @@ -1,43 +1,41 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - icge - 2.3.8 - - icge-simulation - ICGE Simulation - - 2.3.8 - - - - org.junit.jupiter - junit-jupiter-engine - - - de.uni-stuttgart.informatik.fius - ICGE-Ui - ${icge.version} - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-simulation + ICGE Simulation + + 2.3.8 + + + + org.junit.jupiter + junit-jupiter-engine + + + de.uni-stuttgart.informatik.fius + icge-ui + ${icge.version} + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + + + diff --git a/ICGE-Ui/pom.xml b/ICGE-Ui/pom.xml index a3578d2b8..18b9f3f7f 100644 --- a/ICGE-Ui/pom.xml +++ b/ICGE-Ui/pom.xml @@ -1,67 +1,65 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - icge - 2.3.8 - - icge-ui - ICGE Ui - - 2.3.8 - - - - org.junit.jupiter - junit-jupiter-engine - - - de.uni-stuttgart.informatik.fius - ICGE-Log - ${icge.version} - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - net.revelc.code.formatter - formatter-maven-plugin - - - - - - noUiTests - - - noUiTests - true - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*UiTest.java - - - - - - - + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-ui + ICGE Ui + + 2.3.8 + + + + org.junit.jupiter + junit-jupiter-engine + + + de.uni-stuttgart.informatik.fius + icge-log + ${icge.version} + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + net.revelc.code.formatter + formatter-maven-plugin + + + + + + noUiTests + + + noUiTests + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*UiTest.java + + + + + + + diff --git a/ICGE-archetype-module/pom.xml b/ICGE-archetype-module/pom.xml index 03deb0ad9..09657aee4 100644 --- a/ICGE-archetype-module/pom.xml +++ b/ICGE-archetype-module/pom.xml @@ -1,11 +1,9 @@ - - 4.0.0 - de.uni-stuttgart.informatik.fius - icge-archetype-module - 1.0.0 - Archetype for FIUS ICGE Modules - http://maven.apache.org + + 4.0.0 + de.uni-stuttgart.informatik.fius + icge-archetype-module + 1.0.0 + Archetype for FIUS ICGE Modules + http://maven.apache.org diff --git a/ICGE-build-tools/pom.xml b/ICGE-build-tools/pom.xml index 5245e50e4..635c17682 100644 --- a/ICGE-build-tools/pom.xml +++ b/ICGE-build-tools/pom.xml @@ -1,13 +1,11 @@ - - 4.0.0 - - de.uni-stuttgart.informatik.fius - icge - 2.3.8 - - icge-build-tools - ICGE build tools + + 4.0.0 + + de.uni-stuttgart.informatik.fius + icge + 2.3.8 + + icge-build-tools + ICGE build tools diff --git a/pom.xml b/pom.xml index 04897e12e..c0c896f3e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,163 +1,161 @@ - - 4.0.0 - de.uni-stuttgart.informatik.fius - icge - 2.3.8 - Introduction Course Game Engine - The game engine for the java intoduction course of FIUS - https://fius.github.io/icge2 - pom - - 11 - 5.3.1 - 1.1.0 - 2.3.8 - UTF-8 - ICGE2 - project.groupId - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - - - maven-surefire-plugin - 2.19.1 - - - - **/Test*.java - **/*Test.java - **/*Tests.java - **/*TestCase.java - - - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.1.1 - - - attach-javadocs - - jar - - - - - - maven-deploy-plugin - 3.1.1 - - ${project.artifactId} - ${project.groupId} - ${icge.version} - false - - - - deploy-executable - - deploy-file - - - target/*.jar - - - - - - org.apache.maven.plugins - maven-source-plugin - 3.1.0 - - - attach-sources - - jar - - - - - - net.revelc.code.formatter - formatter-maven-plugin - 2.10.0 - - LF - build_tools/eclipse/icge-Formatter.xml - true - ${java.version} - ${java.version} - ${java.version} - - - - de.uni-stuttgart.informatik.fius - ICGE2-build-tools - ${icge.version} - - - - - - - - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - - - de.uni-stuttgart.informatik.fius - ICGE2-Ui - ${icge.version} - - - de.uni-stuttgart.informatik.fius - ICGE2-Simulation - ${icge.version} - - - de.uni-stuttgart.informatik.fius - ICGE2-Log - ${icge.version} - - - - - - github - https://maven.pkg.github.com/FIUS/ICGE2 - - - - ICGE-Ui - ICGE-Simulation - ICGE-ManualStart - ICGE-Log - ICGE-build-tools - + + + **/Test*.java + **/*Test.java + **/*Tests.java + **/*TestCase.java + + + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + attach-javadocs + + jar + + + + + + maven-deploy-plugin + 3.1.1 + + ${project.artifactId} + ${project.groupId} + ${icge.version} + false + + + + deploy-executable + + deploy-file + + + target/*.jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.1.0 + + + attach-sources + + jar + + + + + + net.revelc.code.formatter + formatter-maven-plugin + 2.23.0 + + LF + build_tools/eclipse/ICGE-Formatter.xml + true + ${java.version} + ${java.version} + ${java.version} + + + + de.uni-stuttgart.informatik.fius + icge-build-tools + ${icge.version} + + + + + + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + de.uni-stuttgart.informatik.fius + icge-ui + ${icge.version} + + + de.uni-stuttgart.informatik.fius + icge-simulation + ${icge.version} + + + de.uni-stuttgart.informatik.fius + icge-log + ${icge.version} + + + + + + github + https://maven.pkg.github.com/FIUS/ICGE2 + + + + ICGE-Log + ICGE-Ui + ICGE-Simulation + ICGE-ManualStart + ICGE-build-tools + From e15c38bbaac01ca9cd7099d90c5672fc0c4038f7 Mon Sep 17 00:00:00 2001 From: graefjk Date: Thu, 4 Jan 2024 00:15:22 +0100 Subject: [PATCH 3/6] formatting --- .../informatik/fius/icge/log/Logger.java | 24 +-- .../fius/icge/log/OutputStreamMultiplier.java | 22 +-- ICGE-Log/src/main/java/module-info.java | 4 +- .../fius/icge/manualstart/Coin.java | 10 +- .../manualstart/ManualStartSimulation.java | 16 +- .../fius/icge/manualstart/ManualStartUi.java | 8 +- .../fius/icge/manualstart/TestEntity.java | 10 +- .../fius/icge/manualstart/TestTask.java | 14 +- .../icge/manualstart/TestTaskVerifier.java | 96 +++++----- .../src/main/java/module-info.java | 4 +- .../fius/icge/simulation/Direction.java | 12 +- .../fius/icge/simulation/MultiTypedList.java | 52 +++--- .../fius/icge/simulation/Playfield.java | 54 +++--- .../fius/icge/simulation/Position.java | 28 +-- .../fius/icge/simulation/Simulation.java | 40 ++--- .../icge/simulation/SimulationBuilder.java | 38 ++-- .../fius/icge/simulation/SimulationClock.java | 36 ++-- .../fius/icge/simulation/TaskVerifier.java | 12 +- .../fius/icge/simulation/actions/Action.java | 18 +- .../icge/simulation/actions/ActionLog.java | 32 ++-- .../icge/simulation/actions/EntityAction.java | 14 +- .../actions/EntityCollectAction.java | 24 +-- .../actions/EntityDespawnAction.java | 16 +- .../simulation/actions/EntityDropAction.java | 24 +-- .../simulation/actions/EntityMoveAction.java | 16 +- .../simulation/actions/EntitySpawnAction.java | 18 +- .../simulation/actions/EntityStepAction.java | 12 +- .../actions/EntityTeleportAction.java | 10 +- .../simulation/actions/EntityTurnAction.java | 18 +- .../icge/simulation/entity/BasicEntity.java | 48 ++--- .../simulation/entity/CollectableEntity.java | 8 +- .../fius/icge/simulation/entity/Entity.java | 16 +- .../simulation/entity/EntityCollector.java | 20 +-- .../simulation/entity/EntityTypeRegistry.java | 14 +- .../icge/simulation/entity/GreedyEntity.java | 46 ++--- .../icge/simulation/entity/Inventory.java | 6 +- .../icge/simulation/entity/MovableEntity.java | 62 +++---- .../icge/simulation/entity/SolidEntity.java | 10 +- .../simulation/entity/UntilableDrawable.java | 10 +- .../CannotCollectEntityException.java | 16 +- .../exception/CannotDropEntityException.java | 16 +- .../exception/CannotRunProgramException.java | 16 +- .../exception/ElementExistsException.java | 12 +- .../EntityAlreadyOnFieldExcpetion.java | 12 +- .../exception/EntityNotOnFieldException.java | 12 +- .../EntityOnAnotherFieldException.java | 16 +- .../exception/IllegalMoveException.java | 14 +- .../exception/SimulationExcpetion.java | 18 +- .../exception/TimerAlreadyRunning.java | 6 +- .../UncheckedInterruptedException.java | 16 +- .../inspection/AnnotationReader.java | 22 +-- .../simulation/inspection/ClassFinder.java | 26 +-- .../inspection/InspectionAttribute.java | 8 +- .../simulation/inspection/InspectionData.java | 169 +++++++++-------- .../inspection/InspectionManager.java | 46 ++--- .../inspection/InspectionMethod.java | 6 +- .../internal/StandardSimulation.java | 40 ++--- .../internal/StandardSimulationClock.java | 82 ++++----- .../internal/StandardSimulationProxy.java | 94 +++++----- .../internal/actions/StandardActionLog.java | 26 +-- .../entity/StandardEntityTypeRegistry.java | 31 ++-- .../internal/playfield/PlayfieldCell.java | 12 +- .../internal/playfield/StandardPlayfield.java | 151 ++++++++-------- .../programs/StandardProgramRunner.java | 30 ++-- .../internal/tasks/StandardTaskRunner.java | 22 +-- .../icge/simulation/programs/Program.java | 10 +- .../fius/icge/simulation/tasks/Task.java | 4 +- .../simulation/tools/PlayfieldModifier.java | 22 +-- .../src/main/java/module-info.java | 6 +- .../fius/icge/ui/AnimatedDrawable.java | 58 +++--- .../fius/icge/ui/BasicDrawable.java | 22 +-- .../informatik/fius/icge/ui/Console.java | 6 +- .../informatik/fius/icge/ui/Drawable.java | 24 +-- .../fius/icge/ui/EntityInspectorEntry.java | 32 ++-- .../fius/icge/ui/EntitySidebar.java | 34 ++-- .../informatik/fius/icge/ui/GameWindow.java | 22 +-- .../fius/icge/ui/PlayfieldDrawer.java | 20 +-- .../fius/icge/ui/SimulationProxy.java | 36 ++-- .../fius/icge/ui/SimulationTreeNode.java | 46 ++--- .../fius/icge/ui/TaskInformation.java | 16 +- .../fius/icge/ui/TaskStatusDisplay.java | 8 +- .../fius/icge/ui/TaskVerificationStatus.java | 4 +- .../fius/icge/ui/TextureRegistry.java | 22 +-- .../informatik/fius/icge/ui/Toolbar.java | 38 ++-- .../fius/icge/ui/WindowBuilder.java | 61 +++---- .../icge/ui/exception/LeafNodeException.java | 6 +- .../ui/exception/ListenerSetException.java | 8 +- .../exception/TextureNotFoundException.java | 10 +- .../icge/ui/internal/AnimatedTexture.java | 34 ++-- .../internal/ConsoleBufferedOutputStream.java | 44 ++--- .../fius/icge/ui/internal/OutputStyle.java | 10 +- .../fius/icge/ui/internal/StaticTexture.java | 16 +- .../icge/ui/internal/StaticUiTextures.java | 12 +- .../fius/icge/ui/internal/SwingConsole.java | 20 +-- .../ui/internal/SwingEntityInspector.java | 98 +++++----- .../icge/ui/internal/SwingEntitySidebar.java | 83 ++++----- .../icge/ui/internal/SwingGameWindow.java | 50 +++--- .../ui/internal/SwingPlayfieldDrawer.java | 170 +++++++++--------- .../ui/internal/SwingTaskStatusDisplay.java | 60 +++---- .../ui/internal/SwingTextureRegistry.java | 28 +-- .../fius/icge/ui/internal/SwingToolbar.java | 74 ++++---- .../fius/icge/ui/internal/Texture.java | 22 +-- .../internal/dropdown/DropdownItemEditor.java | 26 +-- .../dropdown/DropdownItemRenderer.java | 22 +-- .../internal/dropdown/DropdownSelector.java | 44 ++--- ICGE-Ui/src/main/java/module-info.java | 6 +- .../fius/icge/ui/SwingGameWindowUiTest.java | 14 +- 107 files changed, 1587 insertions(+), 1602 deletions(-) diff --git a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java index 870a264f0..d9377281d 100644 --- a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java +++ b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -23,28 +23,28 @@ * @version 2.0 */ public abstract class Logger { - + /** The main logger printing to {@link System#out} */ public static PrintStream out; /** The error logger printing to {@link System#err} */ public static PrintStream error; - + private static OutputStreamMultiplier outStream; private static OutputStreamMultiplier errorStream; - + // This block intercepts {@link System.out} and {@link System.err} static { Logger.outStream = new OutputStreamMultiplier(); Logger.outStream.addOutputStream(System.out); Logger.out = new PrintStream(Logger.outStream); System.setOut(Logger.out); - + Logger.errorStream = new OutputStreamMultiplier(); Logger.errorStream.addOutputStream(System.err); Logger.error = new PrintStream(Logger.errorStream); System.setErr(Logger.error); } - + /** * Function to add a {@link OutputStream} to the out logger * @@ -56,7 +56,7 @@ public abstract class Logger { public static boolean addOutOutputStream(final OutputStream stream) { return Logger.outStream.addOutputStream(stream); } - + /** * Function to remove a {@link OutputStream} from the out logger * @@ -68,7 +68,7 @@ public static boolean addOutOutputStream(final OutputStream stream) { public static boolean removeOutOutputStream(final OutputStream stream) { return Logger.outStream.removeOutputStream(stream); } - + /** * Clears the out OutputStreams * @@ -77,7 +77,7 @@ public static boolean removeOutOutputStream(final OutputStream stream) { public static void clearOutOutputStream() { Logger.outStream.clearOutputStreams(); } - + /** * Function to add a {@link OutputStream} to the error logger * @@ -89,7 +89,7 @@ public static void clearOutOutputStream() { public static boolean addErrorOutputStream(final OutputStream stream) { return Logger.errorStream.addOutputStream(stream); } - + /** * Function to remove a {@link OutputStream} from the error logger * @@ -101,7 +101,7 @@ public static boolean addErrorOutputStream(final OutputStream stream) { public static boolean removeErrorOutputStream(final OutputStream stream) { return Logger.errorStream.removeOutputStream(stream); } - + /** * Clears the error OutputStreams * diff --git a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java index 423972451..c7c7dc155 100644 --- a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java +++ b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -21,16 +21,16 @@ * @version 1.0 */ public class OutputStreamMultiplier extends OutputStream { - + private final ArrayList listenerStreams; - + /** * Default Constructor */ public OutputStreamMultiplier() { this.listenerStreams = new ArrayList<>(); } - + /** * Add a output stream to also recieve everything this stream recieves * @@ -41,7 +41,7 @@ public OutputStreamMultiplier() { public boolean addOutputStream(final OutputStream listenerStream) { return this.listenerStreams.add(listenerStream); } - + /** * Remove a output stream from recieving everything this stream recieves * @@ -52,30 +52,30 @@ public boolean addOutputStream(final OutputStream listenerStream) { public boolean removeOutputStream(final OutputStream listenerStream) { return this.listenerStreams.remove(listenerStream); } - + /** * Clears all connected output streams */ public void clearOutputStreams() { this.listenerStreams.clear(); } - + @Override public void flush() throws IOException { super.flush(); - + for (final OutputStream listenerStream : this.listenerStreams) { listenerStream.flush(); } } - + @Override public void write(final int arg0) throws IOException { for (final OutputStream listenerStream : this.listenerStreams) { listenerStream.write(arg0); } } - + @Override public void close() throws IOException { for (final OutputStream listenerStream : this.listenerStreams) { diff --git a/ICGE-Log/src/main/java/module-info.java b/ICGE-Log/src/main/java/module-info.java index 8f9cf7c3c..c1bca88ec 100644 --- a/ICGE-Log/src/main/java/module-info.java +++ b/ICGE-Log/src/main/java/module-info.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java index f4e0920ac..6c6950e44 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -19,17 +19,17 @@ * @author Fabian Bühler */ public class Coin extends BasicEntity implements CollectableEntity { - + /** * The texture handle used for the test entity. */ public static String TEXTURE_HANDLE; - + @Override protected String getTextureHandle() { return TEXTURE_HANDLE; } - + @Override protected int getZPosition() { return 0; diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java index d24202fb8..80d9f4d37 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -22,11 +22,11 @@ * @author Tim Neumann */ public class ManualStartSimulation { - + private static String textureHandleWall; private static String textureHandleCoin; private static String animated; - + /** * @param args * the command line arguments. Not used. @@ -38,21 +38,21 @@ public static void main(final String[] args) { // wb.setDpiScale(1.0); wb.buildWindow(); final GameWindow w = wb.getBuiltWindow(); - + ManualStartSimulation.prepareTextures(w.getTextureRegistry()); TestEntity.TEXTURE_HANDLE = ManualStartSimulation.animated; Coin.TEXTURE_HANDLE = textureHandleCoin; - + final SimulationBuilder sb = new SimulationBuilder(); sb.setTaskVerifier(new TestTaskVerifier()); sb.buildSimulation(); final Simulation sim = sb.getBuiltSimulation(); - + w.start(); sim.attachToWindow(w, true); sim.runTask(new TestTask()); } - + private static void prepareTextures(final TextureRegistry tr) { ManualStartSimulation.textureHandleWall = tr .loadTextureFromResource("textures/wall-default.png", ManualStartSimulation.class::getResourceAsStream); diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java index ccf9a705e..4510360bc 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -19,7 +19,7 @@ * @author Tim Neumann */ public class ManualStartUi { - + /** * Main entry point of the program * @@ -29,7 +29,7 @@ public class ManualStartUi { public static void main(final String[] args) { ManualStartUi.newStyleBuilder(); } - + private static void newStyleBuilder() { final WindowBuilder wb = new WindowBuilder(); wb.setTitle("Window Builder start!"); diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java index eada6e3b4..b5b2ca9c1 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,17 +16,17 @@ * Basic test entity. */ public class TestEntity extends GreedyEntity { - + /** * The texture handle used for the test entity. */ public static String TEXTURE_HANDLE; - + @Override protected String getTextureHandle() { return TestEntity.TEXTURE_HANDLE; } - + @Override protected int getZPosition() { return 0; diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java index 1011705e2..458034ed5 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -20,16 +20,16 @@ * Test task for manual start. */ public class TestTask implements Task { - + @Override public void run(final Simulation sim) { final TestEntity tE = new TestEntity(); - + sim.getPlayfield().addEntity(new Position(3, 4), tE); - + CollectableEntity coin = new Coin(); sim.getPlayfield().addEntity(new Position(3, 4), coin); - + while (true) { tE.collect(coin); tE.drop(coin); @@ -44,7 +44,7 @@ public void run(final Simulation sim) { break; } } - + sim.runProgram(new Program() { @Override public void run(TestEntity entity) { diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java index 4afb333cc..52704a591 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -23,26 +23,26 @@ /** * Example task verifier. - * + * * Verifies that between {@code minStepsToWalk} and {@code maxStepsToWalk} {@code EntityMoveAction} events are in the * log of the simulation. Below the task is UNDECIDED and above the task is FAILED. - * + * * @author Fabian Bühler */ public class TestTaskVerifier implements TaskVerifier, TaskInformation { - + private ActionLog log; private TaskVerificationStatus taskIsValid = TaskVerificationStatus.UNDECIDED; private int minStepsToWalk = 4; private int maxStepsToWalk = 14; private int stepsWalked = 0; - + @Override public void attachToSimulation(Simulation sim) { // get the log to verify if the required events did happen later this.log = sim.getActionLog(); } - + @Override public void verify() { if (this.log == null) { @@ -50,33 +50,33 @@ public void verify() { } // check the number of steps/moves all entity have taken together this.stepsWalked = this.log.getActionsOfType(EntityMoveAction.class, true).size(); - + // as long as task is still achievable use UNDECIDED status if (this.stepsWalked < this.minStepsToWalk) { this.taskIsValid = TaskVerificationStatus.UNDECIDED; return; } - + // if task is failed irreversibly use FAILED status if (this.stepsWalked > this.maxStepsToWalk) { this.taskIsValid = TaskVerificationStatus.FAILED; return; } - + // use SUCCESSFUL status if task is solved correctly this.taskIsValid = TaskVerificationStatus.SUCCESSFUL; } - + @Override public TaskInformation getTaskInformation() { return this; } - + @Override public String getTaskTitle() { return "Test Task"; } - + @Override public String getTaskDescription() { String description = "Just a demo task to test the UI and the Backend.\n"; @@ -88,157 +88,157 @@ public String getTaskDescription() { } return description; } - + @Override public TaskVerificationStatus getTaskStatus() { return this.taskIsValid; } - + @Override public List getChildTasks() { ArrayList subTasks = new ArrayList<>(); - + subTasks.add(new TaskInformation() { - + @Override public String getTaskTitle() { return "a) Successful sub task"; } - + @Override public String getTaskDescription() { return "Super basic sample description"; } - + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.SUCCESSFUL; } - + @Override public List getChildTasks() { return Collections.emptyList(); } }); - + subTasks.add(new TaskInformation() { - + @Override public String getTaskTitle() { return "b) undecided sub task"; } - + @Override public String getTaskDescription() { return "Super basic sample description"; } - + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.UNDECIDED; } - + @Override public List getChildTasks() { ArrayList subTasks = new ArrayList<>(); - + subTasks.add(new TaskInformation() { - + @Override public String getTaskTitle() { return "b.1) Successful sub sub task"; } - + @Override public String getTaskDescription() { return "Super basic sample description"; } - + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.SUCCESSFUL; } - + @Override public List getChildTasks() { return Collections.emptyList(); } }); - + subTasks.add(new TaskInformation() { - + @Override public String getTaskTitle() { return "b.2) undecided sub sub task"; } - + @Override public String getTaskDescription() { return "Super basic sample description"; } - + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.UNDECIDED; } - + @Override public List getChildTasks() { return Collections.emptyList(); } }); - + subTasks.add(new TaskInformation() { - + @Override public String getTaskTitle() { return "b.3) failed sub sub task"; } - + @Override public String getTaskDescription() { return "Super basic sample description"; } - + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.FAILED; } - + @Override public List getChildTasks() { return Collections.emptyList(); } }); - + return subTasks; } }); - + subTasks.add(new TaskInformation() { - + @Override public String getTaskTitle() { return "c) failed sub task"; } - + @Override public String getTaskDescription() { return "Super basic sample description"; } - + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.FAILED; } - + @Override public List getChildTasks() { return Collections.emptyList(); } }); - + return subTasks; } - + } diff --git a/ICGE-ManualStart/src/main/java/module-info.java b/ICGE-ManualStart/src/main/java/module-info.java index f3ca52225..561c8e6eb 100644 --- a/ICGE-ManualStart/src/main/java/module-info.java +++ b/ICGE-ManualStart/src/main/java/module-info.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java index 9d372c2a6..10d657617 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -23,9 +23,9 @@ *

* {@link #WEST} is at the left of the screen ({@link Position#getX()} getting smaller) *

- * + * * @see Position - * + * * @author Tim Neumann */ public enum Direction { @@ -37,10 +37,10 @@ public enum Direction { SOUTH, /** The west direction; at the left of the screen ({@link Position#getX()} getting smaller) */ WEST; - + /** * Get the direction that is next in a clock wise rotation - * + * * @return The next direction */ public Direction clockWiseNext() { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java index 7b1d028c1..d79aff19f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -18,18 +18,18 @@ /** * A list which can contain and return multiple types. - * + * * @author Tim Neumann * @param

* The parent type of all types contained in this list. */ public class MultiTypedList

{ - + private final HashMap, List

> items = new HashMap<>(); - + /** * Get the relevant list for the given type. - * + * * @param type * The type to get the list for * @return an Optional with the list if it exists, otherwise an empty Optional @@ -43,7 +43,7 @@ private Optional> getRelevantListGeneric(final Class) list; return Optional.ofNullable(listOfCorrectType); } - + private Class getClass(final P o) { //Actually a cast should not be necessary here. //Should be totally safe, because o is of type P, so o.getClass() should extend P. @@ -51,10 +51,10 @@ private Class getClass(final P o) { final var type = (Class) o.getClass(); return type; } - + /** * Get the relevant list for the given object. - * + * * @param o * The object to get the list for * @return an Optional with the list if it exists, otherwise an empty Optional @@ -62,10 +62,10 @@ private Class getClass(final P o) { private Optional> getRelevantList(final P o) { return this.getRelevantListGeneric(this.getClass(o)); } - + /** * Get the relevant list for the given entity and create it if it is not there. - * + * * @param o * The object to get the list for * @return The list for the given object @@ -73,25 +73,25 @@ private Optional> getRelevantList(final P o) { private List

getRelevantListAndCreate(final P o) { final var type = this.getClass(o); if (this.items.containsKey(type)) return this.items.get(type); - + final List

list = new ArrayList<>(); this.items.put(type, list); return list; } - + /** * Add the given object to this list. - * + * * @param o * The object to add */ public synchronized void add(final P o) { this.getRelevantListAndCreate(o).add(o); } - + /** * Check whether this list contains the given object. - * + * * @param o * The object to check for * @return Whether this list contains the given object @@ -101,19 +101,19 @@ public synchronized boolean contains(final P o) { if (opt.isEmpty()) return false; return opt.get().contains(o); } - + /** * Return {@code true} iff the list contains no objects. - * + * * @return {@code true} if empty */ public synchronized boolean isEmpty() { return this.items.isEmpty(); } - + /** * Remove the given object from this list. - * + * * @param o * The object to remove * @return Whether this cell contained the given object @@ -123,10 +123,10 @@ public synchronized boolean remove(final P o) { if (opt.isEmpty()) return false; return opt.get().remove(o); } - + /** * Get all objects in this list of the given type. - * + * * @param * The generic type to return the objects as * @param type @@ -137,9 +137,9 @@ public synchronized boolean remove(final P o) { */ public synchronized List get(final Class type, final boolean includeSubclasses) { if (!includeSubclasses) return this.getRelevantListGeneric(type).orElse(List.of()); - + final List result = new ArrayList<>(); - + for (final Class storedType : this.items.keySet()) { if (type.isAssignableFrom(storedType)) { final Class storedTypeAsSubOfRequested = storedType.asSubclass(type); @@ -147,10 +147,10 @@ public synchronized List get(final Class type, fin result.addAll(listForStoredType); } } - + return result; } - + /** * @return a list of stored types. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java index 785bf8d3b..78f3f8279 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -21,26 +21,26 @@ /** * The interface for the playfield of the simulation - * + * * @author Tim Neumann */ public interface Playfield { - + /** * @return the simulation this playfield is part of */ Simulation getSimulation(); - + /** * Get a list of all entities on this playfield. - * + * * @return A list of all entities */ List getAllEntities(); - + /** * Get a list of all entities matching the given type on this playfield. - * + * * @param * The generic type to return the entities as * @param type @@ -52,10 +52,10 @@ public interface Playfield { * if the given type is null */ List getAllEntitiesOfType(Class type, boolean includeSubclasses); - + /** * Get a list of all entities at the given position on this playfield. - * + * * @param pos * The position at which to get the entities; must not be null * @return A list of all entities at that position @@ -63,10 +63,10 @@ public interface Playfield { * if the given pos is null */ List getEntitiesAt(final Position pos); - + /** * Get a list of all entities matching the given type at the given position on this playfield. - * + * * @param * The generic type to return the entities as * @param pos @@ -80,15 +80,15 @@ public interface Playfield { * if the given pos or type is null */ List getEntitiesOfTypeAt(final Position pos, Class type, boolean includeSubclasses); - + /** * Add a given entity to this simulation at a given position on this playfield. - * + * * @param pos * The position to add the entity; must not be null * @param entity * The entity to add; must not be on the field; must not be null - * + * * @throws EntityAlreadyOnFieldExcpetion * if the given entity has been added to this playfield before * @throws EntityOnAnotherFieldException @@ -97,13 +97,13 @@ public interface Playfield { * if the given pos or entity is null */ void addEntity(Position pos, Entity entity); - + /** * Move a entity of this simulation to a given position on this playfield. *

* This causes a {@link EntityTeleportAction}. *

- * + * * @param entity * The entity to move; must be on the field; must not be null * @param pos @@ -114,10 +114,10 @@ public interface Playfield { * if the given pos or entity is null */ void moveEntity(Entity entity, Position pos); - + /** * Move a entity of this simulation to a given position on this playfield. - * + * * @param entity * The entity to move; must be on the field; must not be null * @param pos @@ -132,10 +132,10 @@ public interface Playfield { * if the given action match with the other arguments */ void moveEntity(Entity entity, Position pos, EntityMoveAction action); - + /** * Remove a entity of this simulation from this playfield. - * + * * @param entity * The entity to add; must be on the field; must not be null * @throws EntityNotOnFieldException @@ -144,10 +144,10 @@ public interface Playfield { * if the given entity is null */ void removeEntity(Entity entity); - + /** * Get the position of the specified entity on the playfield. - * + * * @param entity * The entity to get the position of; must be on the field; must not be null * @return The position of the given entity @@ -157,10 +157,10 @@ public interface Playfield { * if the given entity is null */ Position getEntityPosition(Entity entity); - + /** * Check whether the specified entity is on this playfield. - * + * * @param entity * The entity to check; must not be null * @return whether the given entity is on this playfield @@ -168,10 +168,10 @@ public interface Playfield { * if the given entity is null */ boolean containsEntity(Entity entity); - + /** * Check whether a solid entity is at the given position. - * + * * @param pos * The position to check * @return true if and only if a solid entity is at that position diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java index 736da7348..56f61ac3f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -17,7 +17,7 @@ *

* Objects of this class are immutable *

- * + * *

* x is the row; negative towards the top ({@link Direction#NORTH}) and positive towards the bottom * ({@link Direction#SOUTH}) @@ -26,18 +26,18 @@ * y is the column; negative towards the left ({@link Direction#WEST}) and positive towards the right * ({@link Direction#EAST}) *

- * + * * @see Direction - * + * * @author Tim Neumann */ public class Position { private final int x; private final int y; - + /** * Create a new position from the given parameters. - * + * * @param x * The x coordinate for the new position * @param y @@ -47,24 +47,24 @@ public Position(final int x, final int y) { this.x = x; this.y = y; } - + /** * @return the x coordinate of this position */ public int getX() { return this.x; } - + /** * @return the y coordinate of this position */ public int getY() { return this.y; } - + /** * Get the adjacent position in the given direction. - * + * * @param direction * The direction to get the adjacent position in * @return The position adjacent to this in the given direction @@ -83,20 +83,20 @@ public Position adjacentPosition(final Direction direction) { throw new IllegalArgumentException("Unknown direction"); } } - + @Override public boolean equals(final Object o) { if (!(o instanceof Position)) return false; final Position p = (Position) o; return (this.x == p.getX()) && (this.y == p.getY()); } - + @Override public int hashCode() { final int[] numbers = { this.x, this.y }; return Arrays.hashCode(numbers); } - + @Override public String toString() { return "(x=" + this.x + ", y=" + this.y + ")"; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java index 9ebeb8bab..9c6828f9c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -30,80 +30,80 @@ public interface Simulation { * @return The playfield used by this simulation */ Playfield getPlayfield(); - + /** * Get the task verifier set for this simulation. * * @return The task verifier set for this simulation */ TaskVerifier getTaskVerifier(); - + /** * Get the simulation clock for this simulation. * * @return the simulation clock used by this simulation */ SimulationClock getSimulationClock(); - + /** * Get the entity type registry associated with the simulation host. * * @return The entity type registry */ EntityTypeRegistry getEntityTypeRegistry(); - + /** * Get the action log for this simulation. * * @return the action log used by this siumulation */ ActionLog getActionLog(); - + /** * Get the simulation proxy used by the game window to communicate with the simulation. - * + * * @return The simulation proxy for the UI to use */ SimulationProxy getSimulationProxyForWindow(); - + /** * Attach this simulation to the given window. - * + * * @param window * The window to attach to */ void attachToWindow(GameWindow window); - + /** * Attach this simulation to the given window. - * + * * @param window * The window to attach to * @param stopWithWindowClose * If {@code true} the simulation will stop when the attached window is closed */ void attachToWindow(GameWindow window, boolean stopWithWindowClose); - + /** * Irreversibly stop the simulation and all running background tasks and programs. - * + * * Calling this method twice will not throw an exception. */ void stop(); - + /** * Run the given task in the background. - * + * * Only one task can be run for a simulation so calling this twice will throw an exception. - * + * * @param taskToRun * The task to run */ void runTask(Task taskToRun); - + /** * Run the given program for the given Entity in the background. - * + * * @param * The subtype of Entity that the Program accepts * @param @@ -112,7 +112,7 @@ public interface Simulation { * The program to run * @param entity * The Entity to run the program for - * + * */ void runProgram(Program program, S entity); } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java index 4dd0d5f5d..f5fbdf2f2 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -23,11 +23,11 @@ * @author Tim Neumann */ public class SimulationBuilder { - + private TaskVerifier taskVerifier; - + private Simulation simulation; - + /** * Set the task verifier to use with this simulation. * @@ -47,7 +47,7 @@ public void setTaskVerifier(final TaskVerifier taskVerifier) { ); this.taskVerifier = taskVerifier; } - + /** * Actually build the simulation. * @@ -56,32 +56,31 @@ public void setTaskVerifier(final TaskVerifier taskVerifier) { *

*/ public void buildSimulation() { - if ( - this.hasBuiltSimulation() - ) throw new IllegalStateException("The simulation was already built! Use getBuiltSimulation() to acess the built window."); + if (this.hasBuiltSimulation()) + throw new IllegalStateException("The simulation was already built! Use getBuiltSimulation() to acess the built window."); final StandardPlayfield playfield = new StandardPlayfield(); final StandardSimulationClock simulationClock = new StandardSimulationClock(); - + final StandardEntityTypeRegistry entityTypeRegistry = new StandardEntityTypeRegistry(); - + final StandardActionLog actionLog = new StandardActionLog(); - + final InspectionManager inspectionManager = new InspectionManager(); - + this.simulation = new StandardSimulation( playfield, simulationClock, entityTypeRegistry, actionLog, inspectionManager, this.taskVerifier ); } - + /** * Get whether the window has been built. - * + * * @return true if and only if the window has been built */ public boolean hasBuiltSimulation() { return this.simulation != null; } - + /** * Get the simulation that was built. *

@@ -91,10 +90,9 @@ public boolean hasBuiltSimulation() { * @return The created {@link Simulation} */ public Simulation getBuiltSimulation() { - if ( - !this.hasBuiltSimulation() - ) throw new IllegalStateException("The simulation was not yet built! Use buildSimulation() to do that."); - + if (!this.hasBuiltSimulation()) + throw new IllegalStateException("The simulation was not yet built! Use buildSimulation() to do that."); + return this.simulation; } } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java index 1034c8f57..1857b9e1a 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -21,17 +21,17 @@ * @version 1.0 */ public interface SimulationClock { - + /** * The number of render ticks per one simulation tick. */ int RENDER_TICKS_PER_SIMULATION_TICK = 8; - + /** * The render period, that is set by default. */ int DEFAULT_RENDER_TICK_PERIOD = 50; - + /** * Set the period of the render ticks. The game ticks will have this period times * {@value #RENDER_TICKS_PER_SIMULATION_TICK}. @@ -40,33 +40,33 @@ public interface SimulationClock { * The new period in milliseconds. */ void setPeriod(int millis); - + /** * Get the period of the render ticks. * * @return The number of milliseconds per render tick period. */ int getRenderTickPeriod(); - + /** * Get the period of the game ticks. * * @return The number of milliseconds per game tick period. */ int getGameTickPeriod(); - + /** * Query the clock if its running * * @return if the clock is running */ boolean isRunning(); - + /** * Start ticking. */ void start(); - + /** * Stop ticking. *

@@ -74,12 +74,12 @@ public interface SimulationClock { *

*/ void stop(); - + /** * Execute one single tick */ void step(); - + /** * Register a listener for simulation ticks. *

@@ -90,7 +90,7 @@ public interface SimulationClock { * The listener to be called. */ void registerTickListener(Function listener); - + /** * Register a listener for the end of simulation ticks. *

@@ -101,17 +101,17 @@ public interface SimulationClock { * The listener to be called. */ void registerPostTickListener(Function listener); - + /** * @return the number of the last simulation tick */ long getLastTickNumber(); - + /** * @return the number of the last render tick */ long getLastRenderTickNumber(); - + /** * Schedule an operation, to happen during the given tick. This method will block until that tick. Then the tick * processing will halt until the given end of operation is completed. @@ -127,7 +127,7 @@ public interface SimulationClock { * if the end of operation completes exceptionally */ void scheduleOperationAtTick(long tick, CompletableFuture endOfOperation); - + /** * Schedule an operation, to happen during the tick a given number of ticks in the future. This method will block * until that tick. Then the tick processing will halt until the given end of operation is completed. @@ -143,7 +143,7 @@ public interface SimulationClock { * if the end of operation completes exceptionally */ void scheduleOperationInTicks(long ticks, CompletableFuture endOfOperation); - + /** * Schedule an operation, to happen during the next tick. This method will block until that tick. Then the tick * processing will halt until the given end of operation is completed. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java index da571ad7d..7e2bfa00e 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -22,24 +22,24 @@ public interface TaskVerifier { * Attach the verifier to a simulation. *

* Must be called by the simulation or the simulation builder. - * + * * @param sim * the simulation to verify */ void attachToSimulation(Simulation sim); - + /** * Verify if the current state of the simulation matches the requirements for the successful completion of the task. *

* This method should update the task information returned by {@link #getTaskInformation}. */ void verify(); - + /** * Get the current task information. *

* The information returned by this method should not change unless {@link #verify} is called. - * + * * @return the task information */ TaskInformation getTaskInformation(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java index 4f6cf9d34..94f49a22f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,35 +11,35 @@ /** * An action which happens during the execution of a simulation. - * + * * @author Tim Neumann */ public abstract class Action { - + private final long tickNumber; - + /** * Create an action. - * + * * @param tickNumber * the tick the action happened at */ public Action(final long tickNumber) { this.tickNumber = tickNumber; } - + /** * @return the description of this action */ public abstract String getDescription(); - + /** * @return the number of the simulation tick the action happened */ public long getTickNumber() { return this.tickNumber; } - + @Override public String toString() { return this.getDescription(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java index 61f94b5d1..29700b5f7 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,24 +16,24 @@ /** * A log for all {@link Action}s. - * + * * @author Tim Neumann */ public interface ActionLog { - + /** * Get all actions which were logged. *

* Warning: No order is guaranteed. *

- * + * * @return A list of all actions logged */ List getAllActions(); - + /** * Get all actions which were logged of the given type. - * + * * @param * The generic type to return the actions as * @param type @@ -43,19 +43,19 @@ public interface ActionLog { * @return A list of all matching actions */ List getActionsOfType(final Class type, final boolean includeSubclasses); - + /** * Get all actions which were logged and were caused by the given entity. - * + * * @param entity * The entity to get actions for * @return A list of all matching actions */ List getAllActionsOfEntity(Entity entity); - + /** * Get all actions which were logged of the given type and were caused by the given entity. - * + * * @param * The generic type to return the actions as * @param entity @@ -69,15 +69,15 @@ public interface ActionLog { List getActionsOfTypeOfEntity( Entity entity, final Class type, final boolean includeSubclasses ); - + /** * Log an action. - * + * * @param actionToLog * The action to log */ void logAction(Action actionToLog); - + /** * Set ActionLog console output (default: {@code true}) * @@ -85,7 +85,7 @@ List getActionsOfTypeOfEntity( * true: log to console, false: do not log to console */ void setConsoleOutput(boolean enable); - + /** * Get ActionLog console output status. *

@@ -93,5 +93,5 @@ List getActionsOfTypeOfEntity( * logged but not printed to console. */ boolean getConsoleOutput(); - + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java index 7298c965e..a0f45a739 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -14,16 +14,16 @@ /** * An action originating from an entity. - * + * * @author Tim Neumann */ public abstract class EntityAction extends Action { - + private final Entity entity; - + /** * Create an entity action. - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -33,7 +33,7 @@ public EntityAction(final long tickNumber, final Entity entity) { super(tickNumber); this.entity = entity; } - + /** * @return the entity that caused this action. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java index 774464809..97db49de2 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,18 +16,18 @@ /** * An entity action for when an entity collects another entity. - * + * * @author Tim Neumann */ public class EntityCollectAction extends EntityAction { - + private final CollectableEntity collected; private final Position collectorPos; private final Position collectedPos; - + /** * Create an entity collect action. - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -38,7 +38,7 @@ public class EntityCollectAction extends EntityAction { * the position the collector was at while collecting * @param collectedPos * the position the collected entity was at while being collected - * + * */ public EntityCollectAction( final long tickNumber, final Entity entity, final CollectableEntity collected, final Position collectorPos, @@ -49,32 +49,32 @@ public EntityCollectAction( this.collectedPos = collectedPos; this.collectorPos = collectorPos; } - + /** * @return the entity that was collected */ public CollectableEntity getCollectedEntity() { return this.collected; } - + /** * @return the position the collected entity was at while being collected */ public Position getCollectedEntityPosition() { return this.collectedPos; } - + /** * @return the position the collector was at while collecting */ public Position getCollectorPosition() { return this.collectorPos; } - + @Override public String getDescription() { return this.getEntity() + " (at " + this.getCollectorPosition() + ") collected " + this.getCollectedEntity() + " at " + this.getCollectedEntityPosition(); } - + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java index caa3a8da0..38d31591c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,16 +15,16 @@ /** * An entity action for when the entity is removed from a play field - * + * * @author Tim Neumann */ public class EntityDespawnAction extends EntityAction { - + private final Playfield playfield; - + /** * Create an entity despawn action - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -36,14 +36,14 @@ public EntityDespawnAction(final long tickNumber, final Entity entity, final Pla super(tickNumber, entity); this.playfield = playfield; } - + /** * @return the playfield the entity was removed from */ public Playfield getPlayfield() { return this.playfield; } - + @Override public String getDescription() { return this.getEntity() + " despawned from " + this.getPlayfield(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java index 44e39ee2f..50d03beba 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,18 +16,18 @@ /** * An entity action for when an entity drops another entity. - * + * * @author Tim Neumann */ public class EntityDropAction extends EntityAction { - + private final CollectableEntity dropped; private final Position dropperPos; private final Position dropppedPos; - + /** * Create an entity drop action. - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -38,7 +38,7 @@ public class EntityDropAction extends EntityAction { * the position the dropper was at while collecting * @param droppedPos * the position the dropped entity was dropped to - * + * */ public EntityDropAction( final long tickNumber, final Entity entity, final CollectableEntity dropped, final Position dropperPos, @@ -49,32 +49,32 @@ public EntityDropAction( this.dropppedPos = droppedPos; this.dropperPos = dropperPos; } - + /** * @return the entity that was dropped */ public CollectableEntity getDroppedEntity() { return this.dropped; } - + /** * @return the position the dropped entity was dropped to */ public Position getDroppedEntityPosition() { return this.dropppedPos; } - + /** * @return the position the dropper was at while dropping */ public Position getDropperPosition() { return this.dropperPos; } - + @Override public String getDescription() { return this.getEntity() + " (at " + this.getDropperPosition() + ") dropped " + this.getDroppedEntity() + " at " + this.getDroppedEntityPosition(); } - + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java index 71368d8ed..3905273ae 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,19 +15,19 @@ /** * An entity action for when a entity moved. - * + * * @author Tim Neumann * @see EntityStepAction * @see EntityTeleportAction */ public abstract class EntityMoveAction extends EntityAction { - + private final Position from; private final Position to; - + /** * Create an entity move action. - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -42,14 +42,14 @@ public EntityMoveAction(final long tickNumber, final Entity entity, final Positi this.from = from; this.to = to; } - + /** * @return the position the entity was at before the move */ public Position from() { return this.from; } - + /** * @return the position the entity is after the move */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java index 5acd8847f..73e3e0fa6 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,17 +16,17 @@ /** * An entity action for when the entity is added to a play field - * + * * @author Tim Neumann */ public class EntitySpawnAction extends EntityAction { - + private final Playfield playfield; private final Position position; - + /** * Create an entity spawn action. - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -41,21 +41,21 @@ public EntitySpawnAction(final long tickNumber, final Entity entity, final Playf this.playfield = playfield; this.position = position; } - + /** * @return the playfield the entity was added to */ public Playfield getPlayfield() { return this.playfield; } - + /** * @return the position the entity was added at */ public Position getPosition() { return this.position; } - + @Override public String getDescription() { return this.getEntity() + " spawned in " + this.getPlayfield() + " at " + this.getPosition(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java index 8db58f84d..9515ebd9b 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,14 +15,14 @@ /** * An entity action for when the entity took a step - * + * * @author Tim Neumann */ public class EntityStepAction extends EntityMoveAction { - + /** * Create an entity step action. - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -35,7 +35,7 @@ public class EntityStepAction extends EntityMoveAction { public EntityStepAction(final long tickNumber, final Entity entity, final Position from, final Position to) { super(tickNumber, entity, from, to); } - + @Override public String getDescription() { return this.getEntity() + " stepped from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java index ba23e8d9a..f533be88c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,13 +15,13 @@ /** * An entity action for when the entity was just teleported on the playfield - * + * * @author Tim Neumann */ public class EntityTeleportAction extends EntityMoveAction { /** * Create an entity teleport action. - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -34,7 +34,7 @@ public class EntityTeleportAction extends EntityMoveAction { public EntityTeleportAction(final long tickNumber, final Entity entity, final Position from, final Position to) { super(tickNumber, entity, from, to); } - + @Override public String getDescription() { return this.getEntity() + " teleported from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java index 51df05271..5f219c83f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,17 +15,17 @@ /** * An entity action for when the entity turned - * + * * @author Tim Neumann */ public class EntityTurnAction extends EntityAction { - + private final Direction from; private final Direction to; - + /** * Create an entity turn action. - * + * * @param tickNumber * the tick the action happened at * @param entity @@ -40,21 +40,21 @@ public EntityTurnAction(final long tickNumber, final Entity entity, final Direct this.from = from; this.to = to; } - + /** * @return the direction the entity was facing before the turn */ public Direction from() { return this.from; } - + /** * @return the direction the entity is facing after the turn */ public Direction to() { return this.to; } - + @Override public String getDescription() { return this.getEntity() + " turned from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java index f075bfd9c..04de18bbc 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -24,23 +24,23 @@ /** * A basic implementation of {@link Entity} - * + * * @author Tim Neumann */ public abstract class BasicEntity implements Entity { - + /** Lock object to make setting the Playfield threadsafe. */ private Object fieldLock = new Object(); /** The current (weak) reference to the playfield. */ private WeakReference field; - + /** * Lock object to ensure no two long running operations ({@code >= 1} clock tick) are scheduled at the same time. */ private Object operationQueueLock = new Object(); /** The completable future representing the completion of the last enqueued operation. */ protected CompletableFuture endOfLastEnqueuedOperation; - + /** * @throws EntityNotOnFieldException * if this entity is not on a playfield @@ -56,24 +56,24 @@ public Position getPosition() { if (playfield == null) throw new EntityNotOnFieldException("This entity is not on a playfield"); return playfield.getEntityPosition(this); } - + /** * Get the texture handle, with which to get the texture for this entity. - * + * * @return the texture handle for the texture of this entity */ protected abstract String getTextureHandle(); - + /** * Get the z position of this entity. *

* The z position is used to order entities on the same field. *

- * + * * @return the z position of this entity. */ protected abstract int getZPosition(); - + /** * @throws EntityNotOnFieldException * if this entity is not on a playfield @@ -83,7 +83,7 @@ public Drawable getDrawInformation() { final Position pos = this.getPosition(); return new BasicDrawable(pos.getX(), pos.getY(), this.getZPosition(), this.getTextureHandle()); } - + @Override public void initOnPlayfield(final Playfield playfield) { if (playfield == null) throw new IllegalArgumentException("The given playfield is null."); @@ -92,10 +92,10 @@ public void initOnPlayfield(final Playfield playfield) { this.field = new WeakReference<>(playfield); } } - + /** * Check whether this entity is on a playfield - * + * * @return true if and only if this entity is on a playfield */ public boolean isOnPlayfield() { @@ -114,10 +114,10 @@ public boolean isOnPlayfield() { return true; } } - + /** * Get the playfield of this entity. - * + * * @return the playfield * @throws EntityNotOnFieldException * if this entity is not on a playfield @@ -128,10 +128,10 @@ protected Playfield getPlayfield() { return this.field.get(); } } - + /** * Get the simulation of this entity. - * + * * @return the simulation * @throws EntityNotOnFieldException * if this entity is not on a playfield @@ -143,12 +143,12 @@ protected Simulation getSimulation() { return this.getPlayfield().getSimulation(); } } - + /** * Prevent this entity from performing any long running operation for {@code ticks} simulation ticks. *

* Only operations that take {@code >= 1} clock ticks to execute will be affected by this sleep. - * + * * @param ticks * numberof simulation ticks to pause; must be {@code > 0} * @throws IllegalArgumentException @@ -164,7 +164,7 @@ public void sleep(final int ticks) { endOfOperation.complete(null); } } - + /** * Wait for the last enqueued long running operation to finish before allowing the new Operation to perform. *

@@ -181,7 +181,7 @@ public void sleep(final int ticks) { *

* The field {@link #endOfLastEnqueuedOperation} keeps track of the operation that is currently performed by this * entity. - * + * * @param endOfNewOperation * The completable future representing the operation to be performed (must be completed when the operation is * completed) @@ -204,10 +204,10 @@ protected void enqueueToPerformNewOperation(CompletableFuture endOfNewOper endOfLastEnqueuedOperation.join(); } } - + @Override public String toString() { return this.getClass().getSimpleName() + "@" + Integer.toHexString(this.hashCode()); } - + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java index 389145ff8..892ea8f24 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,7 +11,7 @@ /** * An entity, which can be collected by {@link EntityCollector}. - * + * * @author Tim Neumann */ public interface CollectableEntity extends Entity { @@ -20,7 +20,7 @@ public interface CollectableEntity extends Entity { *

* This can be used to make entities, that are not collectable all the time. *

- * + * * @return true if and only if this entity is currently collectable */ default boolean isCurrentlyCollectable() { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java index 1ce9d8a4b..74b3ea471 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -17,7 +17,7 @@ /** * The interface for an entity in the simulation of the ICGE. - * + * * @author Tim Neumann */ public interface Entity { @@ -25,12 +25,12 @@ public interface Entity { * @return the position of this entity */ Position getPosition(); - + /** * @return the information required to draw this entity; must not be null */ Drawable getDrawInformation(); - + /** * Method to initialize this entity after being added to the playfield. *

@@ -39,15 +39,15 @@ public interface Entity { *

* This method needs to be called by the playfield directly before adding the entity to the field. *

- * + * * @param playfield * The playfield this entity was added to; must not be null - * + * * @throws IllegalArgumentException * if the given playfield is null * @throws EntityOnAnotherFieldException * if the entity is already on a field */ void initOnPlayfield(Playfield playfield); - + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java index ba46a13b5..b9752ac75 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,23 +16,23 @@ /** * An entity which can collect {@link CollectableEntity}. - * + * * @author Tim Neumann */ public interface EntityCollector { - + /** * Check if this can collect and drop the given collectable entity type. - * + * * @param type * The type to check; must not be null * @return true if this entity collector can collect or drop the given entity type */ boolean canCarry(Class type); - + /** * Collect the given entity. - * + * * @param entity * The entity to collect; must not be null; must be collectable by this * @throws CannotCollectEntityException @@ -41,10 +41,10 @@ public interface EntityCollector { * if an argument is null */ void collect(CollectableEntity entity); - + /** * Drop the given entity. - * + * * @param entity * The entity to drop;must not be null; must be droppable by this * @param pos @@ -55,5 +55,5 @@ public interface EntityCollector { * if an argument is null */ void drop(CollectableEntity entity, Position pos); - + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java index f3183135e..dd9739d38 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -21,7 +21,7 @@ * @author Fabian Bühler */ public interface EntityTypeRegistry { - + /** * Register a new entity type by name. *

@@ -42,7 +42,7 @@ public interface EntityTypeRegistry { * if the name is already used */ void registerEntityType(final String typeName, final String textureHandle, Class entityType); - + /** * Register a new entity type by name. *

@@ -62,14 +62,14 @@ public interface EntityTypeRegistry { * if the name is already used */ void registerEntityType(final String typeName, final String textureHandle, Supplier entityFactory); - + /** * Get a set of all currently registered entity types. * * @return registered entity types */ Set getRegisteredEntityTypes(); - + /** * Get the texture handle of a registered entity type. * @@ -80,7 +80,7 @@ public interface EntityTypeRegistry { * if an argument is null */ String getTextureHandleOfEntityType(final String typeName); - + /** * Get a new Entity instance of a registered entity type. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java index 9d6a838dd..35c10a440 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -22,31 +22,31 @@ /** * A movable entity collector. - * + * * @author Tim Neumann */ public abstract class GreedyEntity extends MovableEntity implements EntityCollector { - + /** A lock to synchronize all operations involving the entities inventory. */ protected final Object inventoryOperationLock = new Object(); - + private final Inventory inventory = new Inventory(); - + /** * @return the inventory of this greedy entity */ public Inventory getInventory() { return this.inventory; } - + @Override public boolean canCarry(final Class type) { return true; } - + /** * Get all the currently collectable entities of the given type - * + * * @param * The generic type to return the entities as * @param type @@ -58,13 +58,13 @@ public boolean canCarry(final Class type) { public List getCurrentlyCollectableEntities(final Class type, final boolean includeSubclasses) { return this.getPlayfield().getEntitiesOfTypeAt(this.getPosition(), type, includeSubclasses); } - + @Override public void collect(final CollectableEntity entity) { if (entity == null) throw new IllegalArgumentException("An argument is null."); Position myPos; Position otherPos; - + synchronized (this.inventoryOperationLock) { try { myPos = this.getPosition(); @@ -72,22 +72,22 @@ public void collect(final CollectableEntity entity) { } catch (final EntityNotOnFieldException e) { throw new CannotCollectEntityException(e); } - + if (!myPos.equals(otherPos)) throw new CannotCollectEntityException("Not on my field"); - + this.getSimulation().getPlayfield().removeEntity(entity); this.getInventory().add(entity); - + final Action action = new EntityCollectAction( this.getSimulation().getSimulationClock().getLastTickNumber(), this, entity, myPos, otherPos ); this.getSimulation().getActionLog().logAction(action); } } - + /** * Get all the currently droppable entities of the given type - * + * * @param * The generic type to return the entities as * @param type @@ -99,7 +99,7 @@ public void collect(final CollectableEntity entity) { public List getCurrentlyDroppableEntities(final Class type, final boolean includeSubclasses) { return this.getInventory().get(type, includeSubclasses); } - + @Override public void drop(final CollectableEntity entity, final Position pos) { if ((entity == null) || (pos == null)) throw new IllegalArgumentException("An argument is null."); @@ -110,22 +110,22 @@ public void drop(final CollectableEntity entity, final Position pos) { } catch (final EntityNotOnFieldException e) { throw new CannotCollectEntityException(e); } - + if (!myPos.equals(pos)) throw new CannotCollectEntityException("Not on my field"); - + this.getInventory().remove(entity); this.getPlayfield().addEntity(pos, entity); - + final Action action = new EntityDropAction( this.getSimulation().getSimulationClock().getLastTickNumber(), this, entity, myPos, pos ); this.getSimulation().getActionLog().logAction(action); } } - + /** * Drop the given entity at the current position. - * + * * @param entity * The entity to drop;must not be null; must be droppable by this * * @throws CannotDropEntityException @@ -136,5 +136,5 @@ public void drop(final CollectableEntity entity, final Position pos) { public void drop(final CollectableEntity entity) { this.drop(entity, this.getPosition()); } - + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java index f0d4e422e..9698fd6fd 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -14,7 +14,7 @@ /** * An inventory of a entity. - * + * * @author Tim Neumann */ public class Inventory extends MultiTypedList { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java index 1d686d3f5..d54e68555 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -27,17 +27,17 @@ /** * A movable entity - * + * * @author Tim Neumann */ public abstract class MovableEntity extends BasicEntity { - + private Direction lookingDirection = Direction.EAST; - + private AnimatedDrawable movingDrawable = null; - + private Direction directionOfAlmostArrivedMove; - + @Override public Drawable getDrawInformation() { final AnimatedDrawable movingDrawable = this.movingDrawable; @@ -45,7 +45,7 @@ public Drawable getDrawInformation() { final Position pos = this.getPosition(); return new UntilableDrawable(pos.getX(), pos.getY(), this.getZPosition(), this.getTextureHandle()); } - + /** * Turn this entity for 90 degrees in clock wise direction. */ @@ -59,53 +59,53 @@ public void turnClockWise() { endOfOperation.complete(null); } } - + private void turnClockWiseInternal() { final Direction oldLookingDirection = this.lookingDirection; this.lookingDirection = this.lookingDirection.clockWiseNext(); final long tick = this.getSimulation().getSimulationClock().getLastTickNumber(); this.getSimulation().getActionLog().logAction(new EntityTurnAction(tick, this, oldLookingDirection, this.lookingDirection)); } - + @InspectionMethod(name = "turnClockwise") private void turnClockWiseInspector() { this.turnClockWiseInternal(); this.recalculateAnimationAfterInspector(); } - + private void recalculateAnimationAfterInspector() { if (this.movingDrawable != null) { - + final long tickStart = this.movingDrawable.getTickStart(); final long duration = this.movingDrawable.getDuration(); - + Direction movingDir; if (this.directionOfAlmostArrivedMove == null) { movingDir = this.lookingDirection; } else { movingDir = this.directionOfAlmostArrivedMove; } - + final Position currentPos = this.getPosition(); final Position nextPos = currentPos.adjacentPosition(movingDir); - + this.movingDrawable = new AnimatedDrawable( tickStart, currentPos.getX(), currentPos.getY(), duration, nextPos.getX(), nextPos.getY(), this.getZPosition(), this.getTextureHandle() ); } } - + /** * @return the current looking direction of this entity */ public Direction getLookingDirection() { return this.lookingDirection; } - + /** * Set the looking direction - * + * * @param direction * the name of the new direction */ @@ -114,7 +114,7 @@ private void setLookingDirectionByString(final String direction) { this.lookingDirection = Direction.valueOf(direction.toUpperCase()); this.recalculateAnimationAfterInspector(); } - + /** * @return the looking direction as a string */ @@ -122,14 +122,14 @@ private void setLookingDirectionByString(final String direction) { public String getLookingDirectionString() { return this.getLookingDirection().toString(); } - + private boolean isSolidEntityAt(final Position pos) { return this.getPlayfield().isSolidEntityAt(pos); } - + /** * Move this entity forward one field. - * + * * @throws EntityNotOnFieldException * if this entity is not on a playfield * @throws IllegalMoveException @@ -139,7 +139,7 @@ public void move() { // use extra future for whole operation as it is split amongst two futures final CompletableFuture endOfOperation = new CompletableFuture<>(); this.enqueueToPerformNewOperation(endOfOperation); - + // setup move final int duration = 4; final int renderTickDuration = duration * SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; @@ -152,7 +152,7 @@ public void move() { currentTick, currentPos.getX(), currentPos.getY(), renderTickDuration, nextPos.getX(), nextPos.getY(), this.getZPosition(), this.getTextureHandle() ); - + final CompletableFuture endOfOperation1 = new CompletableFuture<>(); try { clock.scheduleOperationInTicks(duration / 2, endOfOperation1); @@ -162,7 +162,7 @@ public void move() { } finally { endOfOperation1.complete(null); } - + final CompletableFuture endOfOperation2 = new CompletableFuture<>(); try { clock.scheduleOperationInTicks(duration / 2, endOfOperation2); @@ -175,16 +175,16 @@ public void move() { this.movingDrawable = null; } } - + @InspectionMethod(name = "move") private void moveInspector() { final Position currentPos = this.getPosition(); final Position nextPos = currentPos.adjacentPosition(this.lookingDirection); - + this.internalMove(currentPos, nextPos); this.recalculateAnimationAfterInspector(); } - + private void internalMove(final Position currentPos, final Position nextPos) { if (this.isSolidEntityAt(nextPos)) throw new IllegalMoveException("Solid Entity in the way"); final EntityMoveAction action = new EntityStepAction( @@ -192,7 +192,7 @@ private void internalMove(final Position currentPos, final Position nextPos) { ); this.getPlayfield().moveEntity(this, nextPos, action); } - + /** * @return whether this entity can move forward one field. */ @@ -200,7 +200,7 @@ public boolean canMove() { final Position nextPos = this.getPosition().adjacentPosition(this.lookingDirection); return this.isOnPlayfield() && !this.isSolidEntityAt(nextPos); } - + /** * Move this entity forward one field if that is possible. */ @@ -208,7 +208,7 @@ public void moveIfPossible() { try { if (this.canMove()) this.move(); } catch (@SuppressWarnings("unused") EntityNotOnFieldException | IllegalMoveException e) { - // do nothing just catch exeptions if move was made illegal by an operation + // do nothing just catch exeptions if move was made illegal by an operation // in another thread } } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java index 045fdf063..227b4bdcb 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,17 +11,17 @@ /** * A solid entity, through which a movable entity cannot move. - * + * * @author Tim Neumann */ public interface SolidEntity extends Entity { - + /** * Get whether this entity is really solid at the moment. *

* This can be used to make entities, that are not solid all the time. *

- * + * * @return true if and only if this entity is currently solid */ default boolean isCurrentlySolid() { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java index 5720e34fb..11dccaa7c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,10 +16,10 @@ * Same as {@link BasicDrawable} but won't tile. */ public class UntilableDrawable extends BasicDrawable { - + /** * Create a new untilable Drawable. - * + * * @param x * @param y * @param z @@ -28,7 +28,7 @@ public class UntilableDrawable extends BasicDrawable { public UntilableDrawable(final double x, final double y, final int z, final String textureHandle) { super(x, y, z, textureHandle); } - + @Override public boolean isTilable() { return false; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java index 05357c463..140d7b2f1 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,16 +11,16 @@ /** * This exception indicates that an entity program cannot be run. - * + * * @author Tim Neumann */ public class CannotCollectEntityException extends SimulationExcpetion { - + /** * generated */ private static final long serialVersionUID = 6758366706458330276L; - + /** * Constructs a new CannotCollectEntityException with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +28,7 @@ public class CannotCollectEntityException extends SimulationExcpetion { public CannotCollectEntityException() { super(); } - + /** * Constructs a new CannotCollectEntityException with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +39,7 @@ public CannotCollectEntityException() { public CannotCollectEntityException(final String message) { super(message); } - + /** * Constructs a new CannotCollectEntityException with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -54,7 +54,7 @@ public CannotCollectEntityException(final String message) { public CannotCollectEntityException(final Throwable cause) { super(cause); } - + /** * Constructs a new CannotCollectEntityException with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java index b111e60ff..cb8687bcc 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,16 +11,16 @@ /** * This exception indicates that an entity program cannot be run. - * + * * @author Tim Neumann */ public class CannotDropEntityException extends SimulationExcpetion { - + /** * generated */ private static final long serialVersionUID = 8237903756645049779L; - + /** * Constructs a new CannotDropEntityException with {@code null} as its detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +28,7 @@ public class CannotDropEntityException extends SimulationExcpetion { public CannotDropEntityException() { super(); } - + /** * Constructs a new CannotDropEntityException with the specified detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +39,7 @@ public CannotDropEntityException() { public CannotDropEntityException(final String message) { super(message); } - + /** * Constructs a new CannotDropEntityException with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -54,7 +54,7 @@ public CannotDropEntityException(final String message) { public CannotDropEntityException(final Throwable cause) { super(cause); } - + /** * Constructs a new CannotDropEntityException with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java index d4202f2c3..82bdd010f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,23 +11,23 @@ /** * This exception indicates that an entity program cannot be run. - * + * * @author Tim Neumann */ public class CannotRunProgramException extends IllegalArgumentException { - + /** * generated */ private static final long serialVersionUID = -5283363131395011240L; - + /** * Constructs an CannotRunProgramException with no detail message. */ public CannotRunProgramException() { super(); } - + /** * Constructs an CannotRunProgramException with the specified detail message. * @@ -37,7 +37,7 @@ public CannotRunProgramException() { public CannotRunProgramException(final String s) { super(s); } - + /** * Constructs a new exception with the specified detail message and cause. * @@ -55,7 +55,7 @@ public CannotRunProgramException(final String s) { public CannotRunProgramException(final String message, final Throwable cause) { super(message, cause); } - + /** * Constructs a new exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java index 5fb8b4554..848418cd3 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,23 +11,23 @@ /** * This exception indicates that the element already exists. - * + * * @author Tim Neumann */ public class ElementExistsException extends IllegalArgumentException { - + /** * generated */ private static final long serialVersionUID = -564159508677510779L; - + /** * Constructs an ElementExistsException with no detail message. */ public ElementExistsException() { super(); } - + /** * Constructs an ElementExistsException with the specified detail message. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java index 475d686fa..1cfcc701c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -12,7 +12,7 @@ /** * This exception indicates that an action is illegal, because the subject entity is already in on the relevant * playfield. - * + * * @author Tim Neumann */ public class EntityAlreadyOnFieldExcpetion extends SimulationExcpetion { @@ -20,7 +20,7 @@ public class EntityAlreadyOnFieldExcpetion extends SimulationExcpetion { * generated */ private static final long serialVersionUID = 3177203739377160043L; - + /** * Constructs a new EntityAlreadyOnFieldExcpetion with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +28,7 @@ public class EntityAlreadyOnFieldExcpetion extends SimulationExcpetion { public EntityAlreadyOnFieldExcpetion() { super(); } - + /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +39,7 @@ public EntityAlreadyOnFieldExcpetion() { public EntityAlreadyOnFieldExcpetion(final String message) { super(message); } - + /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java index 9770a36b2..c36fd3cb6 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,7 +11,7 @@ /** * This exception indicates that an action was illegal, because the subject entity is not the the relevant playfield. - * + * * @author Tim Neumann */ public class EntityNotOnFieldException extends SimulationExcpetion { @@ -19,7 +19,7 @@ public class EntityNotOnFieldException extends SimulationExcpetion { * generated */ private static final long serialVersionUID = -8786124964224174226L; - + /** * Constructs a new EntityAlreadyOnFieldExcpetion with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -27,7 +27,7 @@ public class EntityNotOnFieldException extends SimulationExcpetion { public EntityNotOnFieldException() { super(); } - + /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -38,7 +38,7 @@ public EntityNotOnFieldException() { public EntityNotOnFieldException(final String message) { super(message); } - + /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java index ef97bdd22..6378e6448 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,16 +11,16 @@ /** * This exception indicates that an action is illegal, because the subject entity is already on another playfield. - * + * * @author Tim Neumann */ public class EntityOnAnotherFieldException extends SimulationExcpetion { - + /** * generated */ private static final long serialVersionUID = -2894368466373991151L; - + /** * Constructs a new EntityOnAnotherFieldException with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +28,7 @@ public class EntityOnAnotherFieldException extends SimulationExcpetion { public EntityOnAnotherFieldException() { super(); } - + /** * Constructs a new EntityOnAnotherFieldException with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +39,7 @@ public EntityOnAnotherFieldException() { public EntityOnAnotherFieldException(final String message) { super(message); } - + /** * Constructs a new EntityOnAnotherFieldException with the specified detail message and cause. * @@ -48,7 +48,7 @@ public EntityOnAnotherFieldException(final String message) { * @param cause * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value is * permitted, and indicates that the cause is nonexistent or unknown.) - * + * * @since 1.4 */ public EntityOnAnotherFieldException(final String message, final Throwable cause) { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java index 9efb451c8..7856ef11d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -14,7 +14,7 @@ *

* Possible reasons are: solid entity in the way *

- * + * * @author Tim Neumann */ public class IllegalMoveException extends SimulationExcpetion { @@ -22,7 +22,7 @@ public class IllegalMoveException extends SimulationExcpetion { * generated */ private static final long serialVersionUID = -4781899414191823139L; - + /** * Constructs a new IllegalMoveException with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -30,7 +30,7 @@ public class IllegalMoveException extends SimulationExcpetion { public IllegalMoveException() { super(); } - + /** * Constructs a new IllegalMoveException with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -41,10 +41,10 @@ public IllegalMoveException() { public IllegalMoveException(final String message) { super(message); } - + /** * Constructs a new IllegalMoveException with the specified detail message and cause. * - * + * * @param message * the detail message (which is saved for later retrieval by the {@link #getMessage()} method). * @param cause diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java index 0cad214ff..085bb0fa4 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,16 +11,16 @@ /** * The parent of all exceptions thrown by the simulation. - * + * * @author Tim Neumann */ public class SimulationExcpetion extends RuntimeException { - + /** * generated */ private static final long serialVersionUID = 8969492057602725022L; - + /** * Constructs a new SimulationExcpetion with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +28,7 @@ public class SimulationExcpetion extends RuntimeException { public SimulationExcpetion() { super(); } - + /** * Constructs a new SimulationExcpetion with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +39,7 @@ public SimulationExcpetion() { public SimulationExcpetion(final String message) { super(message); } - + /** * Constructs a new SimulationExcpetion with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -54,10 +54,10 @@ public SimulationExcpetion(final String message) { public SimulationExcpetion(final Throwable cause) { super(cause); } - + /** * Constructs a new SimulationExcpetion with the specified detail message and cause. * - * + * * @param message * the detail message (which is saved for later retrieval by the {@link #getMessage()} method). * @param cause diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java index 6790b3647..c94f941e3 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -20,7 +20,7 @@ */ public class TimerAlreadyRunning extends IllegalStateException { private static final long serialVersionUID = 1715637086603245424L; - + /** * Default constructor */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java index 15b79cd74..18ae81a10 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,23 +11,23 @@ /** * This exception indicates that an entity program cannot be run. - * + * * @author Tim Neumann */ public class UncheckedInterruptedException extends IllegalArgumentException { - + /** * generated */ private static final long serialVersionUID = -8407441370711369840L; - + /** * Constructs an EntityProgramInterruptedException with no detail message. */ public UncheckedInterruptedException() { super(); } - + /** * Constructs an EntityProgramInterruptedException with the specified detail message. * @@ -37,7 +37,7 @@ public UncheckedInterruptedException() { public UncheckedInterruptedException(final String s) { super(s); } - + /** * Constructs a new exception with the specified detail message and cause. * @@ -55,7 +55,7 @@ public UncheckedInterruptedException(final String s) { public UncheckedInterruptedException(final String message, final Throwable cause) { super(message, cause); } - + /** * Constructs a new exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java index 1c78c5930..4e4e5d84e 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -18,17 +18,17 @@ /** * Class responsible for reading annotations. - * + * * @author Tim Neumann */ public class AnnotationReader { private AnnotationReader() { //hide constructor } - + /** * Get all methods with the given annotation in the given class and all parent classes. - * + * * @param cls * The class to get the methods from * @param annotation @@ -38,23 +38,23 @@ private AnnotationReader() { public static List getAllMethodsWithAnnotationRecursively(final Class cls, final Class annotation) { final Method[] methods = cls.getDeclaredMethods(); final List ret = new ArrayList<>(); - + for (final Method m : methods) { if (m.isAnnotationPresent(annotation)) { ret.add(m); } } - + final Class superCls = cls.getSuperclass(); if (superCls != null) { ret.addAll(AnnotationReader.getAllMethodsWithAnnotationRecursively(superCls, annotation)); } return ret; } - + /** * Get all attributes with the given annotation in the given class and all parent classes. - * + * * @param cls * The class to get the attributes from * @param annotation @@ -64,13 +64,13 @@ public static List getAllMethodsWithAnnotationRecursively(final Class public static List getAllAttributesWithAnnotationRecursively(final Class cls, final Class annotation) { final Field[] fields = cls.getDeclaredFields(); final List ret = new ArrayList<>(); - + for (final Field f : fields) { if (f.isAnnotationPresent(annotation)) { ret.add(f); } } - + final Class superCls = cls.getSuperclass(); if (superCls != null) { ret.addAll(AnnotationReader.getAllAttributesWithAnnotationRecursively(superCls, annotation)); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java index e6c406552..e1df282e5 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -23,17 +23,17 @@ /** * A class for finding classes in the class loader - * + * * @author Tim Neumann */ public class ClassFinder { private ClassFinder() { //hide constructor } - + /** * Get all classes in the current context class loader, which match the filter. - * + * * @param filter * The filter to check each class against. * @return A list of classes @@ -43,9 +43,9 @@ private ClassFinder() { public static List> getClassesInClassLoader(final Predicate> filter) throws IOException { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final List urls = Collections.list(loader.getResources("de")); - + final List> classes = new ArrayList<>(); - + for (final URL url : urls) { if (url.getProtocol().equals("jar")) { ClassFinder.loadClassesFromJar(url, filter, classes); @@ -53,10 +53,10 @@ public static List> getClassesInClassLoader(final Predicate> f ClassFinder.loadClassesFromFS(url, filter, classes, loader); } } - + return classes; } - + private static void loadClassesFromJar(final URL url, final Predicate> filter, final List> classes) throws IOException { final String urlS = url.getPath(); @@ -83,7 +83,7 @@ private static void loadClassesFromJar(final URL url, final Predicate> throw new IOException(e2); } } - + private static void loadClassesFromFS( final URL url, final Predicate> filter, final List> classes, final ClassLoader loader ) throws IOException { @@ -94,7 +94,7 @@ private static void loadClassesFromFS( throw new IOException(e); } } - + private static void loadClassInFile( final File file, final List> classes, final ClassLoader loader, final String rootDir, final Predicate> filter ) throws ClassNotFoundException { @@ -116,7 +116,7 @@ private static void loadClassInFile( } } } - + private static String convertPathToClassName(final String path, final String rootDir) { if (!path.startsWith(rootDir)) throw new IllegalStateException("File not starting with root dir!"); final String[] fileSeps = new String[] { System.getProperty("file.separator"), "/" }; @@ -128,6 +128,6 @@ private static String convertPathToClassName(final String path, final String roo relPath = relPath.replace(fileSep, "."); } return relPath; - + } } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java index 945327fb8..6a0703432 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -22,7 +22,7 @@ * A annotation specifying that the annotated element should be displayed as a attribute in the inspector. *

* This can be used for attributes or for getters and setters. - * + * * @author Tim Neumann */ @Documented @@ -31,7 +31,7 @@ public @interface InspectionAttribute { /** @return The optional name of the attribute, to be displayed in the front end. */ String name() default ""; - + /** @return Optional argument setting this attribute to read only. */ boolean readOnly() default false; } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java index c20f43d84..f98a59fa9 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -22,18 +22,18 @@ /** * Represents all data available for the inspection for a class - * + * * @author Tim Neumann */ public class InspectionData { private final Class c; - + private final Map inspectableAttributes; private final Map inspectableMethods; - + /** * Creates a new inspection data object for the given class - * + * * @param cls * The class to create a inspection data object for. */ @@ -44,10 +44,10 @@ public InspectionData(final Class cls) { this.initAttributes(); this.initMethods(); } - + /** * Get the value of the attribute with the given name from the given object. - * + * * @param obj * The object to get the value from * @param name @@ -63,15 +63,15 @@ public Object getAttributeValue(final Object obj, final String name) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { - // InvocationTargetException is suppressed to prevent crashes from methods that throw an exception when the value is null, e.g. getPosition(); + // InvocationTargetException is suppressed to prevent crashes from methods that throw an exception when the value is null, e.g. getPosition(); } } return null; } - + /** * Set's the value of the attribute with the given name for the given object - * + * * @param obj * The object to set the value in. * @param name @@ -92,19 +92,19 @@ public boolean setAttributeValue(final Object obj, final String name, final Obje } return false; } - + /** * Get the attribute names of the class for this inspection data. - * + * * @return A list of attribute names. */ public List getAttributeNames() { return Collections.unmodifiableList(new ArrayList<>(this.inspectableAttributes.keySet())); } - + /** * Get the type of the attribute with the given name. - * + * * @param attributeName * The name of the attribute * @return The type of the attribute. @@ -114,10 +114,10 @@ public Class getAttributeType(final String attributeName) { if (p == null) return null; return p.getType(); } - + /** * Check whether the attribute with the given name is read only. - * + * * @param attributeName * The name of the attribute. * @return Whether the attribute is read only. @@ -127,26 +127,26 @@ public boolean isAttributeReadOnly(final String attributeName) { if (p == null) return true; return p.isReadOnly(); } - + /** * @return Whether this inspection data has any inspectable elements. */ public boolean hasAnyInspectableElements() { return !(this.inspectableAttributes.isEmpty() && this.inspectableMethods.isEmpty()); } - + /** * Get the mathod names of the class for this inspection data. - * + * * @return A list of method names. */ public List getMethodNames() { return Collections.unmodifiableList(new ArrayList<>(this.inspectableMethods.keySet())); } - + /** * Get the method detail for the method with the given name - * + * * @param methodName * The name of the method to get the detail for * @return The method detail. @@ -154,10 +154,10 @@ public List getMethodNames() { public Method getMethodByName(final String methodName) { return this.inspectableMethods.get(methodName); } - + /** * Invoke the method with the given name in the given object, using the given arguments - * + * * @param obj * The object to call the method on * @param methodName @@ -176,38 +176,38 @@ public Object invokeMethod(final Object obj, final String methodName, final Obje throw new IllegalStateException("Invokation didn't work", e); } } - + private void initMethods() { final List methods = AnnotationReader.getAllMethodsWithAnnotationRecursively(this.c, InspectionMethod.class); - + for (final Method m : methods) { m.setAccessible(true); this.inspectableMethods.put(this.getDsiplayNameForInspectionMethod(m), m); } } - + private void initAttributes() { final List fields = AnnotationReader.getAllAttributesWithAnnotationRecursively(this.c, InspectionAttribute.class); final List methods = AnnotationReader.getAllMethodsWithAnnotationRecursively(this.c, InspectionAttribute.class); - + for (final Field f : fields) { f.setAccessible(true); this.inspectableAttributes.put(this.getDisplayNameForField(f), new AttributeInspectionPoint(f)); } - + final Map getters = new HashMap<>(); final Map setters = new HashMap<>(); - + for (int i = 0; i < methods.size(); i++) { final Method m = methods.get(i); - + if (this.isGetter(m)) { getters.put(this.getDisplayNameForMethod(m, "get"), m); } else if (this.isSetter(m)) { setters.put(this.getDisplayNameForMethod(m, "set"), m); } else throw new InspectionPointException("Method is neither a getter nor a setter! : " + m.getName()); } - + for (final Entry entry : getters.entrySet()) { final String name = entry.getKey(); final Method setter = setters.remove(name); @@ -218,61 +218,56 @@ private void initAttributes() { this.validateReadOnlyGetter(getter); getter.setAccessible(true); this.inspectableAttributes.put(name, new AttributeInspectionPoint(getter)); - + } else { this.validateMethodPair(getter, setter); getter.setAccessible(true); setter.setAccessible(true); this.inspectableAttributes.put(name, new AttributeInspectionPoint(getter, setter)); } - + } - + if (setters.size() > 0) throw new InspectionPointException("No getter for setter! : " + setters.values().iterator().next()); - + } - + private boolean isGetter(final Method met) { return (met.getParameterTypes().length == 0) && (met.getReturnType() != Void.TYPE); } - + private boolean isSetter(final Method met) { return (met.getParameterTypes().length == 1) && (met.getReturnType() == Void.TYPE); } - + private void validateMethodPair(final Method getter, final Method setter) { final Class type = getter.getReturnType(); - + if (type.equals(Void.TYPE)) throw new InspectionPointException("Getter should return something! : " + getter.getName()); - - if ( - getter.getParameterTypes().length != 0 - ) throw new InspectionPointException("Getter should not have parameters! : " + getter.getName()); - - if ( - !setter.getReturnType().equals(Void.TYPE) - ) throw new InspectionPointException("Setter should not be return type null. : " + setter.getName()); - + + if (getter.getParameterTypes().length != 0) + throw new InspectionPointException("Getter should not have parameters! : " + getter.getName()); + + if (!setter.getReturnType().equals(Void.TYPE)) + throw new InspectionPointException("Setter should not be return type null. : " + setter.getName()); + final Class[] setterParas = setter.getParameterTypes(); - + if (setterParas.length != 1) throw new InspectionPointException("Setter should have exactly one parameter! : " + setter.getName()); - - if ( - !setterParas[0].equals(type) - ) throw new InspectionPointException("Getter parameter is not the same type as getter return value"); - + + if (!setterParas[0].equals(type)) + throw new InspectionPointException("Getter parameter is not the same type as getter return value"); + } - + private void validateReadOnlyGetter(final Method getter) { - if ( - getter.getReturnType().equals(Void.TYPE) - ) throw new InspectionPointException("Getter should return something! : " + getter.getName()); - - if ( - getter.getParameterTypes().length != 0 - ) throw new InspectionPointException("Getter should not have parameters! : " + getter.getName()); + if (getter.getReturnType().equals(Void.TYPE)) + throw new InspectionPointException("Getter should return something! : " + getter.getName()); + + if (getter.getParameterTypes().length != 0) + throw new InspectionPointException("Getter should not have parameters! : " + getter.getName()); } - + private String getDisplayNameForField(final Field f) { final InspectionAttribute anno = f.getAnnotation(InspectionAttribute.class); if (anno != null) { @@ -281,7 +276,7 @@ private String getDisplayNameForField(final Field f) { } return f.getName(); } - + private String getDsiplayNameForInspectionMethod(final Method m) { final InspectionMethod anno = m.getAnnotation(InspectionMethod.class); if (anno != null) { @@ -290,23 +285,23 @@ private String getDsiplayNameForInspectionMethod(final Method m) { } return m.getName(); } - + private String getDisplayNameForMethod(final Method m, final String possiblePrefixToRemove) { final InspectionAttribute anno = m.getAnnotation(InspectionAttribute.class); if (anno != null) { final String name = anno.name(); if ((name != null) && !name.isEmpty()) return name; } - + String name = m.getName(); - + if (name.toLowerCase().startsWith(possiblePrefixToRemove)) { name = name.substring(3); name = name.substring(0, 1).toLowerCase() + name.substring(1); } return name; } - + private static class AttributeInspectionPoint { private static final Map, Class> primitiveToWrapperMap = new HashMap<>(); static { @@ -326,10 +321,10 @@ private static class AttributeInspectionPoint { private final Method setter; private final Class type; private final boolean readOnly; - + /** * Creates a new attribute inspection point for a field - * + * * @param field * The field for the inspection point. */ @@ -341,7 +336,7 @@ public AttributeInspectionPoint(final Field field) { this.type = this.convertTypeToWrappers(field.getType()); this.readOnly = field.getAnnotation(InspectionAttribute.class).readOnly(); } - + public AttributeInspectionPoint(final Method getter) { this.usesField = false; this.f = null; @@ -350,7 +345,7 @@ public AttributeInspectionPoint(final Method getter) { this.type = this.convertTypeToWrappers(getter.getReturnType()); this.readOnly = true; } - + public AttributeInspectionPoint(final Method getter, final Method setter) { this.usesField = false; this.f = null; @@ -359,17 +354,17 @@ public AttributeInspectionPoint(final Method getter, final Method setter) { this.type = this.convertTypeToWrappers(getter.getReturnType()); this.readOnly = false; } - + private Class convertTypeToWrappers(final Class cls) { if (!cls.isPrimitive()) return cls; return AttributeInspectionPoint.primitiveToWrapperMap.get(cls); } - + public Object getValue(final Object obj) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (this.usesField) return this.f.get(obj); return this.getter.invoke(obj); } - + public void setValue(final Object obj, final Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { if (this.readOnly) throw new InspectionPointException("Attribute is read only."); @@ -380,29 +375,29 @@ public void setValue(final Object obj, final Object value) this.setter.invoke(obj, value); } } - + /** * Get's {@link #type type} - * + * * @return type */ public Class getType() { return this.type; } - + /** * Get's {@link #readOnly readOnly} - * + * * @return readOnly */ public boolean isReadOnly() { return this.readOnly; } } - + /** * A exception that is thrown when an error with a inspection point occurs. - * + * * @author Tim Neumann */ public static class InspectionPointException extends RuntimeException { @@ -410,7 +405,7 @@ public static class InspectionPointException extends RuntimeException { * generated */ private static final long serialVersionUID = 6324656121971704376L; - + /** * Constructs a new runtime exception with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -418,7 +413,7 @@ public static class InspectionPointException extends RuntimeException { public InspectionPointException() { super(); } - + /** * Constructs a new runtime exception with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -429,7 +424,7 @@ public InspectionPointException() { public InspectionPointException(final String message) { super(message); } - + /** * Constructs a new runtime exception with the specified detail message and cause. *

@@ -446,7 +441,7 @@ public InspectionPointException(final String message) { public InspectionPointException(final String message, final Throwable cause) { super(message, cause); } - + /** * Constructs a new runtime exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -461,7 +456,7 @@ public InspectionPointException(final String message, final Throwable cause) { public InspectionPointException(final Throwable cause) { super(cause); } - + /** * Constructs a new runtime exception with the specified detail message, cause, suppression enabled or disabled, * and writable stack trace enabled or disabled. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java index d109efd51..5fe7331e0 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -21,20 +21,20 @@ /** * A class for managing the inspections - * + * * @author Tim Neumann */ public class InspectionManager { - + private final Map, InspectionData> inspectableClasses = new HashMap<>(); - + /** * Create a new inspection manager. */ public InspectionManager() { try { final List> classes = ClassFinder.getClassesInClassLoader(c -> true); - + for (final Class cls : classes) { final InspectionData d = new InspectionData(cls); if (d.hasAnyInspectableElements()) { @@ -45,10 +45,10 @@ public InspectionManager() { e.printStackTrace(); } } - + /** * Get's all attribute names of the given entity. - * + * * @param entity * The entity to get the names for * @return A List of attribute names. @@ -58,10 +58,10 @@ public List getAttributeNamesOfEntity(final Entity entity) { if (d == null) return Collections.emptyList(); return d.getAttributeNames(); } - + /** * Get's all method names of the given entity. - * + * * @param entity * The entity to get the names for * @return A List of method names. @@ -71,10 +71,10 @@ public List getMethodNamesOfEntity(final Entity entity) { if (d == null) return Collections.emptyList(); return d.getMethodNames(); } - + /** * Checks whether the attribute with the given name in the given entity is writable. - * + * * @param entity * The entity. * @param attributeName @@ -86,10 +86,10 @@ public boolean isAttributeEditable(final Entity entity, final String attributeNa if (d == null) return false; return !d.isAttributeReadOnly(attributeName); } - + /** * Get's the type of the attribute with the given name in the given entity. - * + * * @param entity * The entity. * @param attributeName @@ -101,10 +101,10 @@ public Class getAttributeType(final Entity entity, final String attributeName if (d == null) return null; return d.getAttributeType(attributeName); } - + /** * Get the value of the attribute with the given name from the given entity - * + * * @param entity * The entity to get the value from * @param attributeName @@ -116,10 +116,10 @@ public Object getAttributeValue(final Entity entity, final String attributeName) if (d == null) return null; return d.getAttributeValue(entity, attributeName); } - + /** * Set the value of the attribute with the given name in the given entity - * + * * @param entity * The entity to set the value in * @param attributeName @@ -133,10 +133,10 @@ public boolean setAttributeValue(final Entity entity, final String attributeName if (d == null) return false; return d.setAttributeValue(entity, attributeName, value); } - + /** * Get the detail of the method with the given name of the given name. - * + * * @param entity * The entity to get the method of. * @param methodName @@ -148,10 +148,10 @@ public Method getMethodDetail(final Entity entity, final String methodName) { if (d == null) return null; return d.getMethodByName(methodName); } - + /** * Invokes the method with the given name on the given entity. Uses the given arguments. - * + * * @param entity * The entity to invoke the method in. * @param methodName @@ -167,5 +167,5 @@ public Object invokeMethod(final Entity entity, final String methodName, final O if (d == null) throw new IllegalStateException("Not a known inspectable class"); return d.invokeMethod(entity, methodName, args); } - + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java index 24b225972..a8b540048 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -19,7 +19,7 @@ /** * A annotation specifying that the annotated method should be displayed as a method in the inspector. - * + * * @author Tim Neumann */ @Documented diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java index c4e00d026..d023fec70 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -34,17 +34,17 @@ * @author Tim Neumann */ public class StandardSimulation implements Simulation { - + private final StandardPlayfield playfield; private final StandardSimulationClock simulationClock; private final StandardActionLog actionLog; private final StandardEntityTypeRegistry entityTypeRegistry; private final TaskVerifier taskVerifier; private final StandardSimulationProxy simulationProxy; - + private StandardTaskRunner runningTask; private final StandardProgramRunner programRunner; - + /** * Creates a new standard simulation with the given parameters. * @@ -71,60 +71,60 @@ public StandardSimulation( this.actionLog = actionLog; this.entityTypeRegistry = entityTypeRegistry; this.taskVerifier = taskVerifier; - + this.programRunner = new StandardProgramRunner(); - + this.playfield.initialize(this); - + if (taskVerifier != null) { taskVerifier.attachToSimulation(this); } - + this.simulationProxy = new StandardSimulationProxy( this, simulationClock, inspectionManager, entityTypeRegistry, playfield, taskVerifier ); } - + @Override public Playfield getPlayfield() { return this.playfield; } - + @Override public TaskVerifier getTaskVerifier() { return this.taskVerifier; } - + @Override public SimulationClock getSimulationClock() { return this.simulationClock; } - + @Override public ActionLog getActionLog() { return this.actionLog; } - + @Override public EntityTypeRegistry getEntityTypeRegistry() { return this.entityTypeRegistry; } - + @Override public SimulationProxy getSimulationProxyForWindow() { return this.simulationProxy; } - + @Override public void attachToWindow(final GameWindow window) { this.attachToWindow(window, false); } - + @Override public void attachToWindow(final GameWindow window, final boolean stopWithWindowClose) { this.getSimulationProxyForWindow().attachToGameWindow(window, stopWithWindowClose); } - + @Override public void stop() { if (this.runningTask != null) { @@ -134,7 +134,7 @@ public void stop() { this.programRunner.stopAll(); this.simulationClock.shutdown(); // stop the clock for good } - + @Override public void runTask(final Task taskToRun) { if (this.runningTask != null) { @@ -143,7 +143,7 @@ public void runTask(final Task taskToRun) { this.runningTask = new StandardTaskRunner(taskToRun, this); this.runningTask.runTask(); } - + @Override public void runProgram(Program program, S entity) { this.programRunner.run(program, entity); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java index 2b9ef6e1d..6ce7abac6 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -37,20 +37,20 @@ */ public class StandardSimulationClock implements SimulationClock { private final Object tickListenerLock = new Object(); - + private final List> tickListeners; private final List> postTickListeners; - + private final Set> operationBoundaries; - + private Consumer animationTickListener; private StateChangeListener stateChangeListener; - + private TimerTask task; private final Timer timer; - + private volatile long tickCount; - + /** * Setting this to true will signal the clock that it is in shutdown mode. *

@@ -64,9 +64,9 @@ public class StandardSimulationClock implements SimulationClock { * */ private volatile boolean shuttingDown; - + private int period; - + /** * Default constructor */ @@ -79,7 +79,7 @@ public StandardSimulationClock() { this.shuttingDown = false; this.operationBoundaries = Collections.synchronizedSet(new HashSet<>()); } - + /** * This internal start function actually starts the timer but does not notify the simulation proxy. If you don't * know what you do use {@link SimulationClock#start()} @@ -87,9 +87,9 @@ public StandardSimulationClock() { public synchronized void startInternal() { if (this.isRunning()) throw new TimerAlreadyRunning(); if (this.shuttingDown) return; - + this.task = new TimerTask() { - + @Override public void run() { StandardSimulationClock.this.tick(); @@ -97,7 +97,7 @@ public void run() { }; this.timer.schedule(this.task, 0, this.period); } - + /** * This internal stop function actually stops the timer but does not notify the simulation proxy. If you don't know * what you do use {@link SimulationClock#stop()} @@ -108,7 +108,7 @@ public synchronized void stopInternal() { } this.task = null; } - + /** * Shuts down this clock. *

@@ -131,62 +131,62 @@ public synchronized void shutdown() { boundary.cancel(true); } } - + @Override public synchronized void setPeriod(final int millis) { this.period = millis; - + if (this.isRunning()) { this.stop(); this.start(); } } - + @Override public int getRenderTickPeriod() { return this.period; } - + @Override public int getGameTickPeriod() { return this.period * SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; } - + @Override public boolean isRunning() { return this.task != null; } - + @Override public synchronized void start() { if (this.stateChangeListener != null) { this.stateChangeListener.clockStarted(); } - + this.startInternal(); } - + @Override public synchronized void stop() { if (this.stateChangeListener != null) { this.stateChangeListener.clockPaused(); } - + this.stopInternal(); } - + @Override public synchronized void step() { if (this.isRunning()) throw new TimerAlreadyRunning(); if (this.shuttingDown) return; - + new Thread(() -> { StandardSimulationClock.this.tickCount = ((StandardSimulationClock.this.tickCount - (StandardSimulationClock.this.tickCount % 8)) + 7); StandardSimulationClock.this.tick(); }, "single-step").start(); } - + /** * Process a tick */ @@ -205,7 +205,7 @@ private void tick() { } } } - + /** * Process a simulation tick * @@ -220,7 +220,7 @@ private void tickSimulation(final long tickNumber) { this.tickListeners.remove(listener); } } - + for (final var listener : List.copyOf(this.postTickListeners)) { //Don't continue to process tick when shutting down. if (this.shuttingDown) return; @@ -229,7 +229,7 @@ private void tickSimulation(final long tickNumber) { } } } - + /** * Set the animation tick listener, that gets called every animation tick and is responsible for informing the UI. * @@ -243,7 +243,7 @@ public void setAnimationTickListener(final Consumer listener) { this.animationTickListener = listener; } else throw new ListenerSetException(); } - + /** * Set the state change listener, that gets called when the clock get's started or paused through public API and is * responsible for informing the UI. @@ -258,7 +258,7 @@ public void setStateChangeListener(final StateChangeListener listener) { this.stateChangeListener = listener; } else throw new ListenerSetException(); } - + /** * Remove the state change listener, that gets called when the clock get's started or paused through public API and * is responsible for informing the UI. @@ -266,7 +266,7 @@ public void setStateChangeListener(final StateChangeListener listener) { public void removeStateChangeListener() { this.stateChangeListener = null; } - + @Override public void registerTickListener(final Function listener) { if (this.shuttingDown) return; @@ -274,7 +274,7 @@ public void registerTickListener(final Function listener) { this.tickListeners.add(listener); } } - + @Override public void registerPostTickListener(final Function listener) { if (this.shuttingDown) return; @@ -282,18 +282,18 @@ public void registerPostTickListener(final Function listener) { this.postTickListeners.add(listener); } } - + @Override public long getLastTickNumber() { //not rounding is intended here as we'd need floor and casting is the same as floor for positive integers return this.tickCount / SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; } - + @Override public long getLastRenderTickNumber() { return this.tickCount; } - + @Override public void scheduleOperationAtTick(final long tick, final CompletableFuture endOfOperation) { if (this.shuttingDown) return; @@ -328,17 +328,17 @@ public void scheduleOperationAtTick(final long tick, final CompletableFuture endOfOperation) { this.scheduleOperationAtTick(this.getLastTickNumber() + ticks, endOfOperation); } - + @Override public void scheduleOperationAtNextTick(final CompletableFuture endOfOperation) { this.scheduleOperationInTicks(1, endOfOperation); } - + /** * The interface for a listener listening for simulation clock starts and stops. The listener is only informed when * the state change is caused from the public API, not from UI interaction. @@ -348,7 +348,7 @@ public interface StateChangeListener { * The clock was started. */ void clockStarted(); - + /** * The clock was paused/stopped. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java index bdc883a0c..20a493495 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -43,21 +43,21 @@ * @version 1.0 */ public class StandardSimulationProxy implements SimulationProxy { - + /** A lookup table for the simulation times */ public static final int[] SIMULATION_TIMES = { // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 1000, 415, 200, 115, 75, 50, 42, 34, 26, 18, 10 // These values are aproximated by two functions originally by haslersn which where modified by waeltkts }; - + // GAME WINDOW private GameWindow gameWindow; private boolean stopSimulationWithWindowClose = false; - + // MANAGERS private final InspectionManager inspectionManager; - + // CURRENT SIMULATION private final Simulation simulation; private final StandardEntityTypeRegistry entityTypeRegistry; @@ -65,9 +65,9 @@ public class StandardSimulationProxy implements SimulationProxy { private final StandardPlayfield playfield; private final TaskVerifier taskVerifier; private final Map simualtionSidebarMap; - + private Entity entityToInspect; - + /** * Create a new standard simulation proxy * @@ -95,7 +95,7 @@ public StandardSimulationProxy( this.playfield = playfield; this.taskVerifier = taskVerifier; this.simualtionSidebarMap = new ConcurrentHashMap<>(); - + // attach tick listeners to simulation clock // only do this once per SimulationProxy as unsetting these listeners is not possible atm this.simulationClock.setAnimationTickListener(new Consumer() { @@ -106,24 +106,24 @@ public void accept(final Long tickCount) { } } }); - + this.simulationClock.registerPostTickListener(unused -> { updateEntityInspector(); return true; // post tick listener could be removed by returning false here }); } - + @Override public void attachToGameWindow(final GameWindow window) { this.attachToGameWindow(window, false); } - + @Override public void attachToGameWindow(final GameWindow window, final boolean stopWithWindowClose) { if (this.gameWindow != null) throw new IllegalStateException("Already attached to a window!"); this.gameWindow = window; this.stopSimulationWithWindowClose = stopWithWindowClose; - + //Simulation Clock if (this.simulationClock.isRunning()) { this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); @@ -131,21 +131,21 @@ public void attachToGameWindow(final GameWindow window, final boolean stopWithWi this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); } this.simulationSpeedChange(this.gameWindow.getToolbar().getSpeedSliderPosition()); - + this.simulationClock.setStateChangeListener(new StateChangeListener() { @Override public void clockStarted() { StandardSimulationProxy.this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); } - + @Override public void clockPaused() { StandardSimulationProxy.this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); } }); - + //EntityDrawing - + this.playfield.setDrawablesChangedListener(new Consumer>() { @Override public void accept(final List drawables) { @@ -154,10 +154,10 @@ public void accept(final List drawables) { } } }); - + //ControlButtonState this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.VIEW); - + //EntitySelection this.entityTypeRegistry.setEntityRegisteredListener((entityName, textureHandle) -> { if (StandardSimulationProxy.this.gameWindow != null) { @@ -175,7 +175,7 @@ public void accept(final List drawables) { } catch (@SuppressWarnings("unused") final NullPointerException e) { // catching exception instead of checking before allows to avoid synchronization here } - + this.gameWindow.getEntitySidebar().setSimulationTreeRootNode(this.playfield.getSimulationTree()); this.gameWindow.getEntitySidebar().enableSimulationTree(); this.playfield.setSimulationTreeEntityAddedListener((node, entity) -> { @@ -186,19 +186,19 @@ public void accept(final List drawables) { this.simualtionSidebarMap.remove(node); this.gameWindow.getEntitySidebar().updateSimulationTree(); }); - + this.gameWindow.getEntitySidebar().disableEntityInspector(); - + // taskState TaskInformation task = null; if (this.taskVerifier != null) { task = this.taskVerifier.getTaskInformation(); } this.gameWindow.getTaskStatusDisplay().setTaskInformation(task); - + this.gameWindow.setSimulationProxy(this); } - + @Override public void windowClosed() { // clear listeners first @@ -208,16 +208,16 @@ public void windowClosed() { this.playfield.removeSimulationTreeEntityAddedListener(); this.playfield.removeSimulationTreeEntityRemovedListener(); this.entityTypeRegistry.removeEntityRegisteredListener(); - + // remove gameWindow reference this.gameWindow = null; - + // stop simulation if (this.stopSimulationWithWindowClose) { this.simulation.stop(); } } - + @Override public void buttonPressed(final ButtonType type) { switch (type) { @@ -227,7 +227,7 @@ public void buttonPressed(final ButtonType type) { } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); break; - + case STEP: if (!this.simulationClock.isRunning()) { this.simulationClock.step(); @@ -236,48 +236,48 @@ public void buttonPressed(final ButtonType type) { } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); break; - + case PAUSE: if (this.simulationClock.isRunning()) { this.simulationClock.stopInternal(); } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); break; - + case VIEW: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.VIEW); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.VIEW); break; - + case ADD: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.ADD); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.ADD); break; - + case SUB: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.SUB); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.SUB); break; - + default: } } - + @Override public void simulationSpeedChange(final int value) { this.simulationClock.setPeriod(StandardSimulationProxy.SIMULATION_TIMES[value]); } - + @Override public void selectedEntityChanged(final String name) { String textureHandle = null; if ((name != null) && !name.equals("")) { textureHandle = this.entityTypeRegistry.getTextureHandleOfEntityType(name); } - + this.gameWindow.getPlayfieldDrawer().setSelectedEntityType(name, textureHandle); } - + @Override public void refreshTaskInformation() { TaskInformation task = null; @@ -287,7 +287,7 @@ public void refreshTaskInformation() { } this.gameWindow.getTaskStatusDisplay().setTaskInformation(task); } - + @Override public void spawnEntityAt(final String typeName, final int x, final int y) { try { @@ -302,11 +302,11 @@ public void spawnEntityAt(final String typeName, final int x, final int y) { e.printStackTrace(); } } - + @Override public void clearCell(final int x, final int y) { final List toRemove = this.playfield.getEntitiesAt(new Position(x, y)); - + toRemove.forEach(entity -> { try { this.playfield.removeEntity(entity); @@ -315,10 +315,10 @@ public void clearCell(final int x, final int y) { } }); } - + private EntityInspectorEntry[] getEntries(final Entity e) { final List result = new ArrayList<>(); - + for (final String name : this.inspectionManager.getAttributeNamesOfEntity(e)) { String type = "string"; if (!this.inspectionManager.isAttributeEditable(e, name)) { @@ -337,7 +337,7 @@ private EntityInspectorEntry[] getEntries(final Entity e) { this.updateEntityInspector(); })); } - + for (final String name : this.inspectionManager.getMethodNamesOfEntity(e)) { final String type = "function"; result.add(new EntityInspectorEntry(name, type, "", unused -> { @@ -349,13 +349,13 @@ private EntityInspectorEntry[] getEntries(final Entity e) { } return result.toArray(new EntityInspectorEntry[result.size()]); } - + private void updateEntityInspector() { if (this.gameWindow == null) return; if (this.entityToInspect == null) return; this.gameWindow.getEntitySidebar().setEntityInspectorEntries(this.getEntries(this.entityToInspect)); } - + @Override public void selectedSimulationEntityChange(final SimulationTreeNode node) { if (node == null) { @@ -363,7 +363,7 @@ public void selectedSimulationEntityChange(final SimulationTreeNode node) { } else { this.entityToInspect = this.simualtionSidebarMap.get(node); } - + if (this.entityToInspect != null) { this.gameWindow.getEntitySidebar().enableEntityInspector(); this.gameWindow.getEntitySidebar().setEntityInspectorName(this.entityToInspect.toString()); @@ -374,7 +374,7 @@ public void selectedSimulationEntityChange(final SimulationTreeNode node) { this.gameWindow.getEntitySidebar().disableEntityInspector(); } } - + @Override public void entityValueChange(final String name, final String value) { // Intentionally left blank diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java index 2915b9021..5ff023cef 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -27,30 +27,30 @@ * @author Tim Neumann */ public class StandardActionLog implements ActionLog { - + private final Object actionsLock = new Object(); private final Object entityActionsLock = new Object(); - + private final MultiTypedList actions = new MultiTypedList<>(); - + private final Map> entityActions = new HashMap<>(); - + private boolean consoleLog = true; - + @Override public List getAllActions() { synchronized (this.actionsLock) { return this.actions.get(Action.class, true); } } - + @Override public List getActionsOfType(final Class type, final boolean includeSubclasses) { synchronized (this.actionsLock) { return this.actions.get(type, includeSubclasses); } } - + @Override public List getAllActionsOfEntity(final Entity entity) { synchronized (this.entityActionsLock) { @@ -59,7 +59,7 @@ public List getAllActionsOfEntity(final Entity entity) { return list.get(EntityAction.class, true); } } - + @Override public List getActionsOfTypeOfEntity( final Entity entity, final Class type, final boolean includeSubclasses @@ -70,7 +70,7 @@ public List getActionsOfTypeOfEntity( return list.get(type, includeSubclasses); } } - + @Override public void logAction(final Action actionToLog) { if (actionToLog instanceof EntityAction) { @@ -90,12 +90,12 @@ public void logAction(final Action actionToLog) { System.out.println(actionToLog.getDescription()); } } - + @Override public void setConsoleOutput(boolean enable) { this.consoleLog = enable; } - + @Override public boolean getConsoleOutput() { return this.consoleLog; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java index e0a9d6a7a..cb32e5870 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -27,12 +27,12 @@ * @author Fabian Bühler */ public class StandardEntityTypeRegistry implements EntityTypeRegistry { - + private final Map> typeToEntityFactory = new HashMap<>(); private final Map typeToTextureHandle = new HashMap<>(); - + private EntityRegisteredListener entityRegisteredListener; - + @Override public void registerEntityType(final String typeName, final String textureHandle, final Class entityType) { if (entityType == null) throw new IllegalArgumentException("Entity type class object cannot be null!"); @@ -50,37 +50,36 @@ public void registerEntityType(final String typeName, final String textureHandle }; this.registerEntityType(typeName, textureHandle, entityFactory); } - + @Override public synchronized void registerEntityType( final String typeName, final String textureHandle, final Supplier entityFactory ) { if ((typeName == null) || typeName.equals("")) throw new IllegalArgumentException("Type name cannot be null or empty!"); - if ( - (textureHandle == null) || textureHandle.equals("") - ) throw new IllegalArgumentException("Texture handle cannot be null or empty!"); + if ((textureHandle == null) || textureHandle.equals("")) + throw new IllegalArgumentException("Texture handle cannot be null or empty!"); if (entityFactory == null) throw new IllegalArgumentException("Entity factory cannot be null!"); if (entityFactory.get() == null) throw new IllegalArgumentException("Unable to instantiate a new entity!"); if (this.typeToEntityFactory.containsKey(typeName)) throw new ElementExistsException(); this.typeToEntityFactory.put(typeName, entityFactory); this.typeToTextureHandle.put(typeName, textureHandle); - + if (this.entityRegisteredListener != null) { this.entityRegisteredListener.entityWasRegistered(typeName, textureHandle); } } - + @Override public Set getRegisteredEntityTypes() { return this.typeToEntityFactory.keySet(); } - + @Override public String getTextureHandleOfEntityType(final String typeName) { if ((typeName == null) || typeName.equals("")) throw new IllegalArgumentException("Type name cannot be null or empty!"); return this.typeToTextureHandle.get(typeName); } - + @Override public Entity getNewEntity(final String typeName) { if ((typeName == null) || typeName.equals("")) throw new IllegalArgumentException("Type name cannot be null or empty!"); @@ -88,7 +87,7 @@ public Entity getNewEntity(final String typeName) { if (entityFactory == null) return null; return entityFactory.get(); } - + /** * Set an entity selector listener that gets informed about all entity types added. * @@ -107,14 +106,14 @@ public synchronized void setEntityRegisteredListener(final EntityRegisteredListe this.entityRegisteredListener = listener; } else throw new ListenerSetException(); } - + /** * Remove the set entity selector listener that gets informed about all entity types added. */ public synchronized void removeEntityRegisteredListener() { this.entityRegisteredListener = null; } - + /** * The interface for when an entity is registered */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java index 4b8663bb1..a42c37afc 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,15 +16,15 @@ /** * Represents one cell on the playfield. - * + * * @author Tim Neumann */ public class PlayfieldCell extends MultiTypedList { private final Position pos; - + /** * Create a new playfield cell, - * + * * @param pos * The position of the cell */ @@ -32,7 +32,7 @@ public PlayfieldCell(final Position pos) { super(); this.pos = pos; } - + /** * @return the position of this cell */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java index 6846a512a..5aa777a98 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -43,22 +43,22 @@ */ public class StandardPlayfield implements Playfield { private WeakReference sim; - + private final Object playfieldLock = new Object(); - + private final Map cells = new HashMap<>(); private final Map entityPositions = new HashMap<>(); - + private SimulationTreeNode simualtionTreeRootNode; - + private BiConsumer simulationTreeEntityAddedListener; private Consumer simulationTreeEntityRemovedListener; - + private Consumer> drawablesChangedListener; - + private boolean awaitingEntityDraw = false; private long timeBetweenDraws = 32; //the time between draw calls in milliseconds - + /** * Initialize the playfield for the given simulation * @@ -71,19 +71,19 @@ public void initialize(final StandardSimulation simulation) { this.drawEntities(); return true; }); - + this.simualtionTreeRootNode = new SimulationTreeNode("root", "Entities", "", false); - + new Timer().scheduleAtFixedRate(new TimerTask() { - + @Override public void run() { drawEntitiesInternal(); } - + }, 0, this.timeBetweenDraws); } - + /** * @throws IllegalStateException * if this playfield is not part of any simulation @@ -95,7 +95,7 @@ public Simulation getSimulation() { if (simulation == null) throw new IllegalStateException("This playfield is not part of any simulation."); return simulation; } - + /** * Queues a draw update to the playfield drawer. Draw updates are sent to the playfield drawer automatically every * 32ms. @@ -103,7 +103,7 @@ public Simulation getSimulation() { public void drawEntities() { this.awaitingEntityDraw = true; } - + /** * Converts all entities to drawables and sends them to the playfield drawer. */ @@ -127,14 +127,14 @@ private void drawEntitiesInternal() { } catch (@SuppressWarnings("unused") final IllegalStateException e) { //If we are not attached to a simultion we do not need to draw anything } - + } - + @Override public List getAllEntities() { return this.getAllEntitiesOfType(Entity.class, true); } - + @Override public List getAllEntitiesOfType(final Class type, final boolean includeSubclasses) { if (type == null) throw new IllegalArgumentException("The given type is null."); @@ -146,13 +146,13 @@ public List getAllEntitiesOfType(final Class } return result; } - + @Override public List getEntitiesAt(final Position pos) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); return this.getEntitiesOfTypeAt(pos, Entity.class, true); } - + @Override public List getEntitiesOfTypeAt( final Position pos, final Class type, final boolean includeSubclasses @@ -168,7 +168,7 @@ public List getEntitiesOfTypeAt( } return result; } - + private void addEntityToCell(final Position pos, final Entity entity) { synchronized (this.playfieldLock) { PlayfieldCell cell = this.cells.get(pos); @@ -179,7 +179,7 @@ private void addEntityToCell(final Position pos, final Entity entity) { cell.add(entity); } } - + private void removeEntityFromCell(final Position pos, final Entity entity) { synchronized (this.playfieldLock) { final PlayfieldCell cell = this.cells.get(pos); @@ -193,31 +193,30 @@ private void removeEntityFromCell(final Position pos, final Entity entity) { } } } - + @Override public void addEntity(final Position pos, final Entity entity) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); if (entity == null) throw new IllegalArgumentException("The given entity is null."); - + synchronized (this.playfieldLock) { - if ( - this.entityPositions.containsKey(entity) - ) throw new EntityAlreadyOnFieldExcpetion("The given entity" + entity + "is already on this playfield."); - + if (this.entityPositions.containsKey(entity)) + throw new EntityAlreadyOnFieldExcpetion("The given entity" + entity + "is already on this playfield."); + entity.initOnPlayfield(this); - + this.addEntityToCell(pos, entity); - + this.entityPositions.put(entity, pos); - + this.getSimulation().getActionLog() .logAction(new EntitySpawnAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, this, pos)); - + this.addEntityToSimulationTree(entity); } this.drawEntities(); } - + private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean create) { final List> classHiera = new ArrayList<>(); { @@ -228,7 +227,7 @@ private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean } while (Entity.class.isAssignableFrom(clazz)); } SimulationTreeNode node = this.simualtionTreeRootNode; - + hieraLoop: for (final Class clazz : classHiera) { for (final SimulationTreeNode child : node.getChildren()) { if (child.getElementId().equals(clazz.getName())) { @@ -245,65 +244,62 @@ private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean } return node; } - + private void addEntityToSimulationTree(final Entity entity) { final SimulationTreeNode newNode = new SimulationTreeNode( Integer.toHexString(entity.hashCode()), entity.toString(), entity.getDrawInformation().getTextureHandle() ); this.findNodeForEntity(entity, true).appendChild(newNode); - + if (this.simulationTreeEntityAddedListener != null) { // TODO check for bugs with simulation tree when window is reattached or attached late this.simulationTreeEntityAddedListener.accept(newNode, entity); } } - + @Override public void moveEntity(final Entity entity, final Position pos) { this.moveEntity(entity, pos, null); } - + @Override public void moveEntity(final Entity entity, final Position pos, final EntityMoveAction action) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); if (entity == null) throw new IllegalArgumentException("The given entity is null."); - + synchronized (this.playfieldLock) { - if ( - !this.entityPositions.containsKey(entity) - ) throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); - + if (!this.entityPositions.containsKey(entity)) + throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); + EntityMoveAction actionToLog = action; - + final Position oldPos = this.entityPositions.get(entity); - + if (actionToLog == null) { actionToLog = new EntityTeleportAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, oldPos, pos); } else { - if ( - !actionToLog.getEntity().equals(entity) - ) throw new IllegalArgumentException("Given action wasn't caused by given entity."); - if ( - !actionToLog.from().equals(oldPos) - ) throw new IllegalArgumentException("Given action does not start at current position of given entity."); + if (!actionToLog.getEntity().equals(entity)) + throw new IllegalArgumentException("Given action wasn't caused by given entity."); + if (!actionToLog.from().equals(oldPos)) + throw new IllegalArgumentException("Given action does not start at current position of given entity."); if (!actionToLog.to().equals(pos)) throw new IllegalArgumentException("Given action does not end at given pos."); } - + this.removeEntityFromCell(oldPos, entity); this.addEntityToCell(pos, entity); this.entityPositions.put(entity, pos); - + this.getSimulation().getActionLog().logAction(actionToLog); - + } this.drawEntities(); } - + private void removeEntityFromSimulationTree(final Entity entity) { final SimulationTreeNode node = this.findNodeForEntity(entity, false); - + if (node == null) return; - + for (final SimulationTreeNode child : node.getChildren()) { if (child.getElementId().equals(Integer.toHexString(entity.hashCode()))) { node.removeChild(child); @@ -314,29 +310,28 @@ private void removeEntityFromSimulationTree(final Entity entity) { } } } - + @Override public void removeEntity(final Entity entity) { if (entity == null) throw new IllegalArgumentException("The given entity is null."); - + synchronized (this.playfieldLock) { - if ( - !this.entityPositions.containsKey(entity) - ) throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); - + if (!this.entityPositions.containsKey(entity)) + throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); + final Position pos = this.entityPositions.get(entity); this.removeEntityFromCell(pos, entity); this.entityPositions.remove(entity, pos); - + this.getSimulation().getActionLog() .logAction(new EntityDespawnAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, this)); - + this.removeEntityFromSimulationTree(entity); - + } this.drawEntities(); } - + @Override public Position getEntityPosition(final Entity entity) { if (entity == null) throw new IllegalArgumentException("The given entity is null."); @@ -346,7 +341,7 @@ public Position getEntityPosition(final Entity entity) { return pos; } } - + @Override public boolean containsEntity(final Entity entity) { if (entity == null) throw new IllegalArgumentException("The given entity is null."); @@ -354,7 +349,7 @@ public boolean containsEntity(final Entity entity) { return this.entityPositions.containsKey(entity); } } - + @Override public boolean isSolidEntityAt(final Position pos) { final List solidEntitiesAtPos = this.getEntitiesOfTypeAt(pos, SolidEntity.class, true); @@ -363,14 +358,14 @@ public boolean isSolidEntityAt(final Position pos) { } return false; } - + /** * @return the root node of the simulation tree */ public SimulationTreeNode getSimulationTree() { return this.simualtionTreeRootNode; } - + /** * Set the listener for when an entity is added to the simulation tree. * @@ -382,14 +377,14 @@ public void setSimulationTreeEntityAddedListener(final BiConsumer> listener) this.drawablesChangedListener = listener; } else throw new ListenerSetException(); } - + /** * Remove the listener for when the drawables on the playfield changed. This listener is responsible for informing * the UI. @@ -429,7 +424,7 @@ public void setDrawablesChangedListener(final Consumer> listener) public void removeDrawablesChangedListener() { this.drawablesChangedListener = null; } - + @Override public String toString() { return this.getClass().getSimpleName() + "@" + Integer.toHexString(this.hashCode()); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java index 9da1d2d93..55106863d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -29,21 +29,21 @@ * @author Fabian Bühler */ public class StandardProgramRunner { - + private ExecutorService executor; - + private final Map> runningPrograms = new HashMap<>(); - + /** * Standard constructor setting up the executor for the Futures. */ public StandardProgramRunner() { this.executor = this.createExecutor(); } - + /** * Create an executor that uses named threads for a better debugging experience, - * + * * @return the executor service */ private ExecutorService createExecutor() { @@ -53,15 +53,15 @@ private ExecutorService createExecutor() { worker.setDaemon(true); return worker; }; - + return new ForkJoinPool(Runtime.getRuntime().availableProcessors(), factory, null, false); } - + /** * Run a program for the given entity inside a completable future. - * + * * Only one program can bu run for a each entity. - * + * * @param * The subtype of Entity that the Program accepts * @param @@ -79,7 +79,7 @@ public void run(final Program program, final throw new IllegalStateException("Already running a program for entity " + entity.toString() + "!"); } } - + final CompletableFuture future = CompletableFuture.runAsync(() -> { try { program.run(entity); @@ -94,11 +94,11 @@ public void run(final Program program, final System.out.println("----------------------------------------------"); } }, this.executor); - + // set the running program in the entityMap this.runningPrograms.put(entity, future); } - + /** * Get the running program as a CompletableFuture. * @@ -109,7 +109,7 @@ public void run(final Program program, final public CompletableFuture getRunningProgram(Entity entity) { return this.runningPrograms.get(entity); } - + /** * Stop all running programs. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java index 80dbd37c0..9be58f903 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -26,14 +26,14 @@ * @author Tim Neumann */ public class StandardTaskRunner { - + private final ExecutorService executor; - + private final Task taskToRun; private final Simulation sim; - + private CompletableFuture taskResult; - + /** * Create a new task runner. * @@ -50,11 +50,11 @@ public StandardTaskRunner(final Task taskToRun, final Simulation sim) { Thread worker = new Thread(runnable, "TaskThread-" + taskToRun.toString()); return worker; }; - + // only one task can be run per task runner so parallelism of one is ok this.executor = Executors.newSingleThreadExecutor(factory); } - + /** * Run the given task. *

@@ -66,10 +66,10 @@ public StandardTaskRunner(final Task taskToRun, final Simulation sim) { public CompletableFuture runTask() { if (this.taskResult != null) return this.taskResult; this.taskResult = CompletableFuture.supplyAsync(this::executeTask, this.executor); - + return this.taskResult; } - + private boolean executeTask() { try { this.taskToRun.run(this.sim); @@ -95,7 +95,7 @@ private boolean executeTask() { return false; } } - + /** * Cancel the completable future and intterupt the underlying thread. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java index 338c06bbe..49d8580c8 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,16 +15,16 @@ /** * The interface for programs that operate on entities. - * + * * Programs can be run by using {@link Simulation#runProgram}. - * + * * @param * The type of entities this program can operate on. */ public interface Program { /** * The entry method of the program. - * + * * @param entity * The entity this program operates on. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java index a7fb0513e..276a88b7b 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java index 69b91026c..ac0db9320 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -18,25 +18,25 @@ /** * A tool to modify a playfield and place entities on it. - * + * * @author Tim Neumann */ public class PlayfieldModifier { private final Playfield playfield; - + /** * Create a new playfield modifier for the given playfield. - * + * * @param playfield * The playfield to create the modifier for */ public PlayfieldModifier(final Playfield playfield) { this.playfield = playfield; } - + /** * Place the given entity at the given position on the playfield. - * + * * @param entity * The entity to place * @param position @@ -45,10 +45,10 @@ public PlayfieldModifier(final Playfield playfield) { public void placeEntityAt(final Entity entity, final Position position) { this.playfield.addEntity(position, entity); } - + /** * Place the given number of entities supplied by the given factory at the given location. - * + * * @param entityFactory * The factory to get the entities from * @param count @@ -61,10 +61,10 @@ public void placeMultipleEntitiesAt(final Supplier entityFacto placeEntityAt(entityFactory.get(), position); } } - + /** * Place an entity supplied by the given factory at each of the given positions - * + * * @param entityFactory * The factory to get the entities from * @param positions diff --git a/ICGE-Simulation/src/main/java/module-info.java b/ICGE-Simulation/src/main/java/module-info.java index 7b5bc416b..9117dd04f 100644 --- a/ICGE-Simulation/src/main/java/module-info.java +++ b/ICGE-Simulation/src/main/java/module-info.java @@ -1,15 +1,15 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ module de.unistuttgart.informatik.fius.icge.simulation { requires transitive de.unistuttgart.informatik.fius.icge.ui; - + exports de.unistuttgart.informatik.fius.icge.simulation; exports de.unistuttgart.informatik.fius.icge.simulation.entity; exports de.unistuttgart.informatik.fius.icge.simulation.exception; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java index 4425ff478..400dbeec8 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,22 +15,22 @@ * @author Fabian Bühler */ public class AnimatedDrawable implements Drawable { - + private final double xStart; private final double yStart; private final double xEnd; private final double yEnd; - + private final int z; - + private final String textureHandle; - + private final long tickStart; private final long tickEnd; private final long duration; - + private long currentTick = 0; - + /** * Create a new animated Drawable. * @@ -66,12 +66,12 @@ public AnimatedDrawable( this.z = z; this.textureHandle = textureHandle; } - + @Override public void setCurrentTick(final long renderTick) { this.currentTick = renderTick; } - + @Override public double getX() { if (this.currentTick <= this.tickStart) return this.xStart; @@ -79,7 +79,7 @@ public double getX() { final double completion = (this.currentTick - this.tickStart) / (double) this.duration; return ((this.xEnd - this.xStart) * completion) + this.xStart; } - + @Override public double getY() { if (this.currentTick <= this.tickStart) return this.yStart; @@ -87,84 +87,84 @@ public double getY() { final double completion = (this.currentTick - this.tickStart) / (double) this.duration; return ((this.yEnd - this.yStart) * completion) + this.yStart; } - + @Override public int getZ() { return this.z; } - + @Override public String getTextureHandle() { return this.textureHandle; } - + @Override public boolean isTilable() { return false; } - + @Override public boolean isAnimated() { return this.currentTick <= this.tickEnd; } - + /** * Get's {@link #xStart xStart} - * + * * @return xStart */ public double getxStart() { return this.xStart; } - + /** * Get's {@link #yStart yStart} - * + * * @return yStart */ public double getyStart() { return this.yStart; } - + /** * Get's {@link #xEnd xEnd} - * + * * @return xEnd */ public double getxEnd() { return this.xEnd; } - + /** * Get's {@link #yEnd yEnd} - * + * * @return yEnd */ public double getyEnd() { return this.yEnd; } - + /** * Get's {@link #tickStart tickStart} - * + * * @return tickStart */ public long getTickStart() { return this.tickStart; } - + /** * Get's {@link #tickEnd tickEnd} - * + * * @return tickEnd */ public long getTickEnd() { return this.tickEnd; } - + /** * Get's {@link #duration duration} - * + * * @return duration */ public long getDuration() { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java index d9d080243..13766b9ec 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,35 +15,35 @@ * @author Tim Neumann */ public class BasicDrawable implements Drawable { - + /** * The x coordinate of the drawable. * * The coordinate system is based on cells where fractionals denote positions between cells. */ private final double x; - + /** * The y coordinate of the drawable. * * The coordinate system is based on cells where fractionals denote positions between cells. */ private final double y; - + /** * The z value of the drawable. * * The z value is used to decide the drawing order of Drawables in the same cell. */ private final int z; - + /** * The handle of the texture for this drawable. * * The texture must be registered in the TextureRegistry. */ private final String textureHandle; - + /** * Create a new Drawable. * @@ -62,22 +62,22 @@ public BasicDrawable(final double x, final double y, final int z, final String t this.z = z; this.textureHandle = textureHandle; } - + @Override public double getX() { return this.x; } - + @Override public double getY() { return this.y; } - + @Override public int getZ() { return this.z; } - + @Override public String getTextureHandle() { return this.textureHandle; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java index 7ad3d95cd..5c20d0cca 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,7 +16,7 @@ * @version 2.0 */ public interface Console { - + /** * Clears the console in the ui. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java index 89b241fdd..d90d8f088 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -17,7 +17,7 @@ * @version 1.0 */ public interface Drawable extends Comparable { - + /** * Get the x coordinate of the drawable. * @@ -26,7 +26,7 @@ public interface Drawable extends Comparable { * @return returns the X position as a double */ double getX(); - + /** * Get the y coordinate of the drawable. * @@ -35,7 +35,7 @@ public interface Drawable extends Comparable { * @return returns the Y position as a double */ double getY(); - + /** * Get the z value of the drawable. * @@ -44,7 +44,7 @@ public interface Drawable extends Comparable { * @return returns the Z position as a double */ int getZ(); - + /** * Get the handle of the texture for this drawable. * @@ -53,7 +53,7 @@ public interface Drawable extends Comparable { * @return returns the texture handle as a String */ String getTextureHandle(); - + /** * Return wether this Drawable can be drawn tiled if multiple are present in the same cell. * @@ -62,26 +62,26 @@ public interface Drawable extends Comparable { default boolean isTilable() { return true; } - + /** * Return wether the Drawable is animated. - * + * * @return true iff any property (x, y, z) is animated */ default boolean isAnimated() { return false; } - + /** * Set the current render tick for animated drawables. - * + * * @param renderTick * The current render tick */ default void setCurrentTick(final long renderTick) { return; // default to noop } - + @Override default int compareTo(final Drawable o) { double compareResult = 0; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java index a4dd4b6c6..51c9203a2 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,18 +16,18 @@ * EntityInspectorEntry */ public class EntityInspectorEntry { - + private final String name; - + private final String type; - + private final String value; - + private final Consumer callback; - + /** * Default constructor - * + * * @param name * The name of the setting * @param type @@ -43,37 +43,37 @@ public EntityInspectorEntry(final String name, final String type, final String v this.value = value; this.callback = callback; } - + /** * Getter for the name - * + * * @return returns the name */ public String getName() { return this.name; } - + /** * Getter for the type - * + * * @return returns the type */ public String getType() { return this.type; } - + /** * Getter for the value - * + * * @return returns the value */ public String getValue() { return this.value; } - + /** * This function runs the callback of the item - * + * * @param arg * The argument of the callback */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java index 84d0c3e33..1a9d56f32 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,7 +16,7 @@ * @version 1.0 */ public interface EntitySidebar { - + /** * Setter function to attach a SimulationTree to the entity sidebar. * @@ -24,12 +24,12 @@ public interface EntitySidebar { * The root node of the simulation tree. */ void setSimulationTreeRootNode(SimulationTreeNode treeNode); - + /** * This function should be called if the simulation tree changes. */ void updateSimulationTree(); - + /** * This function deletes all currently created ui elements and creates a new inspector * @@ -37,52 +37,52 @@ public interface EntitySidebar { * The entries to create the inspector from */ void setEntityInspectorEntries(EntityInspectorEntry[] entries); - + /** * Get the selected element of the simulation tree. - * + * * @return the currently selected SimulationTreeNode */ SimulationTreeNode getSimulationTreeSelectedElement(); - + /** * Set the selected element of the simulation tree. - * + * * @param node * The SimulationTreeNode to select */ void setSimulationTreeSelectedElement(SimulationTreeNode node); - + /** * Enable the simulation tree. */ void enableSimulationTree(); - + /** * Disable the simulation tree. */ void disbaleSimulationTree(); - + /** * Set the name of the entity inspector. - * + * * @param name * The name to set */ void setEntityInspectorName(String name); - + /** * Get the current name of the entity inspector. - * + * * @return The name */ String getEntityInspectorName(); - + /** * Enable the entity inspector. */ void enableEntityInspector(); - + /** * Disable the entity inspector. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java index 67ddb6e4b..52b7d0f22 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -21,42 +21,42 @@ public interface GameWindow { * @return The texture registry used by this window. */ TextureRegistry getTextureRegistry(); - + /** * Get the drawer responsible for drawing the playfield for this game window. * * @return The playfield drawer used by this window. */ PlayfieldDrawer getPlayfieldDrawer(); - + /** * Get the toolbar for this game window. * * @return The toolbar used by this window. */ Toolbar getToolbar(); - + /** * Get the entity sidebar for this game window * * @return The entity sidebar used by this window */ EntitySidebar getEntitySidebar(); - + /** * Get the console for this game window * * @return The console used by this window */ Console getConsole(); - + /** * Get the task status display for this game window. * * @return The task status display used by this window */ TaskStatusDisplay getTaskStatusDisplay(); - + /** * Set the title of the window, in which the ICGE is displayed. * @@ -64,17 +64,17 @@ public interface GameWindow { * The title to use. */ void setWindowTitle(String title); - + /** * Start and show the game window. */ void start(); - + /** * Stop and close the game window. This action is equivalent with pressing the "X"-button of the window. */ void stop(); - + /** * Set the simulation proxy instance used by multiple UI components to inform the Simulation of user actions. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java index c5ea55708..83ac6e533 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -20,7 +20,7 @@ * @author Tim Neumann */ public interface PlayfieldDrawer { - + /** * Set the current list of Drawables to be rendered onto the playfield. * @@ -30,7 +30,7 @@ public interface PlayfieldDrawer { * the list of Drawables to render */ void setDrawables(List drawables); - + /** * Draws the playfield. * @@ -38,25 +38,25 @@ public interface PlayfieldDrawer { * The number of the current tick */ void draw(long tickCount); - + /** * Reset Zoom and Pan applied by the user to the default values. */ void resetZoomAndPan(); - + /** * @param useDoubleBuffering * true (default) uses doubleBuffering when rendering changes on the playfield. */ void setDoubleBuffering(boolean useDoubleBuffering); - + /** * @param syncToScreen * true (default) actively tries to sync the updated graphics to the screen after rendering changes on the * playfield. */ void setSyncToScreen(boolean syncToScreen); - + /** * Inform the playfield drawer about which tool is selected in the toolbar. This influences what happens when a user * clicks on the playfield. @@ -65,7 +65,7 @@ public interface PlayfieldDrawer { * The currently selected tool */ void setSelectedTool(ControlButtonState selectedTool); - + /** * Inform the playfield drawer about which entity type is selected in the toolbar. This influences what entity is * spawned when a user uses the entity creation tool. @@ -76,5 +76,5 @@ public interface PlayfieldDrawer { * The texture handle for the entity type selected. */ void setSelectedEntityType(String typeName, String textureHandle); - + } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java index 099a50921..3e056494e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -21,7 +21,7 @@ * @version 1.0 */ public interface SimulationProxy { - + /** * Attach this simulation proxy to a specific game window. * @@ -29,7 +29,7 @@ public interface SimulationProxy { * The game window to attach to */ void attachToGameWindow(GameWindow gameWindow); - + /** * Attach this simulation proxy to a specific game window. * @@ -39,16 +39,16 @@ public interface SimulationProxy { * If {@code true} the simulation will stop when the attached window is closed */ void attachToGameWindow(GameWindow gameWindow, boolean stopWithWindowClose); - + /** * Called when the window is closing. */ void windowClosed(); - + // // Toolbar // - + /** * This is to identify the buttons */ @@ -66,7 +66,7 @@ public enum ButtonType { /** The sub button in the toolbar */ SUB } - + /** * This is called when a button is pressed by the user * @@ -74,7 +74,7 @@ public enum ButtonType { * The type of the pressed button */ void buttonPressed(ButtonType type); - + /** * This is called if the speed slider is changed by the user * @@ -82,7 +82,7 @@ public enum ButtonType { * The new selected speed */ void simulationSpeedChange(int value); - + /** * This gets called when the user changes the selected element * @@ -90,18 +90,18 @@ public enum ButtonType { * The name of the selected element */ void selectedEntityChanged(String name); - + /** * This gets called by the user to refresh task status information. *

* Calling this must verify the task. */ void refreshTaskInformation(); - + // // Entity placing // - + /** * Spawn a new entity of the given type at the given position and bind the program to this entity. * @@ -113,7 +113,7 @@ public enum ButtonType { * coordinate */ void spawnEntityAt(String typeName, int x, int y); - + /** * Clear all entities in the given cell. * @@ -123,11 +123,11 @@ public enum ButtonType { * coordinate */ void clearCell(int x, int y); - + // // Sidebar - Simulation Tree // - + /** * This function gets called when the user selects a different node * @@ -135,11 +135,11 @@ public enum ButtonType { * The node with was selected */ void selectedSimulationEntityChange(SimulationTreeNode node); - + // // Entity Inspector // - + /** * This function gets called when a user changes a value or fires a function in the ui * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java index fb6b7028b..bd15e2f9e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -25,14 +25,14 @@ * @version 1.0 */ public class SimulationTreeNode { - + private ArrayList children; - + private final String elementId; private final String displayText; private final String textureId; private final boolean isLeaf; - + /** * Default constructor for leaf nodes * @@ -49,7 +49,7 @@ public SimulationTreeNode(final String elementId, final String displayText, fina this.textureId = textureId; this.isLeaf = true; } - + /** * This constructor can be used to create non leaf nodes as well as leaf nodes. * @@ -66,13 +66,13 @@ public SimulationTreeNode(final String elementId, final String displayText, fina if (!isLeaf) { this.children = new ArrayList<>(); } - + this.elementId = elementId; this.displayText = displayText; this.textureId = textureId; this.isLeaf = isLeaf; } - + /** * Getter for the element id the non visible string to better identify the selected entity. * @@ -81,7 +81,7 @@ public SimulationTreeNode(final String elementId, final String displayText, fina public String getElementId() { return this.elementId; } - + /** * Getter for the display text which is the name of the entity which is displayed to the user. * @@ -90,7 +90,7 @@ public String getElementId() { public String getDisplayText() { return this.displayText; } - + /** * Getter for the texture id the identifier of the texture which is rendered infront of the display text. * @@ -99,7 +99,7 @@ public String getDisplayText() { public String getTextureId() { return this.textureId; } - + /** * This checks if node is a leaf node. * @@ -108,7 +108,7 @@ public String getTextureId() { public boolean isLeaf() { return this.isLeaf; } - + /** * Function to check if the node has children. * @@ -116,10 +116,10 @@ public boolean isLeaf() { */ public boolean hasChildren() { if (this.isLeaf) return false; - + return !this.children.isEmpty(); } - + /** * Appends a child node to this node * @@ -129,10 +129,10 @@ public boolean hasChildren() { */ public boolean appendChild(final SimulationTreeNode node) { if (this.isLeaf) throw new LeafNodeException(); - + return this.children.add(node); } - + /** * Removes a child node from this node * @@ -142,17 +142,17 @@ public boolean appendChild(final SimulationTreeNode node) { */ public boolean removeChild(final SimulationTreeNode node) { if (this.isLeaf) throw new LeafNodeException(); - + return this.children.remove(node); } - + /** * @return a list of all children */ public List getChildren() { return List.copyOf(this.children); } - + /** * Runs a function for each added child node with the child node as a parameter * @@ -161,23 +161,23 @@ public List getChildren() { */ public void forEachChild(final Consumer lamda) { if (this.isLeaf) throw new LeafNodeException(); - + for (final SimulationTreeNode child : this.children) { lamda.accept(child); } } - + @Override public int hashCode() { return this.elementId.hashCode(); } - + @Override public boolean equals(final Object obj) { if (!(obj instanceof SimulationTreeNode)) return false; return Objects.equals(this.elementId, ((SimulationTreeNode) obj).elementId); } - + @Override public String toString() { return this.getDisplayText(); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java index 0808f4e69..86ab147eb 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -19,28 +19,28 @@ * @version 1.0 */ public interface TaskInformation { - + /** * Get the title of the task. - * + * * @return the task title (must not be {@code null}, without trailing newline) */ String getTaskTitle(); - + /** * Get the description of the task. * * @return the task description (can be {@code null}, can contain newlines, without trailing newline) */ String getTaskDescription(); - + /** * Get the verification status of the task. - * + * * @return the task status (must not be {@code null}) */ TaskVerificationStatus getTaskStatus(); - + /** * Get a list of child/sub tasks of this task. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java index a89de65cb..a274b7416 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,10 +16,10 @@ * @version 1.0 */ public interface TaskStatusDisplay { - + /** * Set the task information to be displayed. - * + * * @param task * the information of the current task (and subtasks) */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java index 584c9cfda..fd96eb55c 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java index 7f66bd77c..ee2a1eafe 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -21,7 +21,7 @@ * @author Tim Neumann */ public interface TextureRegistry { - + /** * Load an image from an internal resource as texture and return the handle to the texture. * @@ -42,21 +42,21 @@ public interface TextureRegistry { * the texture could not be loaded from the given resource location */ String loadTextureFromResource(String resourceName, final Function resourceProvider); - + /** * Create a new animated texture with the animation length in render ticks. - * + * * Use {@link #addAnimationFrameToTexture} to add animation frames to the animated texture. - * + * * @param loop * if true the animation will loop after the last frame * @return the handle to retrieve the texture */ String createAnimatedTexture(boolean loop); - + /** * Add a animation frame to an animated texture. - * + * * @param animatedTexture * the animated texture to add the animation frame to * @param frameTexture @@ -65,16 +65,16 @@ public interface TextureRegistry { * the number of frames to show this texture */ void addAnimationFrameToTexture(String animatedTexture, String frameTexture, long frames); - + /** * Check if a texture is animated. - * + * * @param textureHandle * the texture to check * @return true iff the texture is animated */ boolean isTextureAnimated(String textureHandle); - + /** * Load an image from a file path as texture and return the handle to the texture. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java index b45318655..f40679b4e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -20,7 +20,7 @@ * @version 1.0 */ public interface Toolbar { - + /** * The clock button state represents the states of the clock buttons in the ui */ @@ -32,7 +32,7 @@ enum ClockButtonState { /** Indicates an error or unavailable clock or simulation */ BLOCKED } - + /** * The control button state represents the status of the control buttons in the ui */ @@ -46,7 +46,7 @@ enum ControlButtonState { /** Indicates that the user input is blocked or unavailable */ BLOCKED } - + /** * Append the list of entities with the given entry * @@ -57,58 +57,58 @@ enum ControlButtonState { * @see DropdownSelector */ void addEntity(String displayName, String textureID); - + /** * Set the state of the control buttons. - * + * * @param controlButtonState * The new state */ void setControlButtonState(ControlButtonState controlButtonState); - + /** * Set the state of the clock buttons. - * + * * @param clockButtonState * The new state */ void setClockButtonState(ClockButtonState clockButtonState); - + /** * Get the current position of the speed slider. - * + * * @return The position from 0 to 10 (both inclusive) */ int getSpeedSliderPosition(); - + /** * Set the position of the speed slider. - * + * * @param position * The new position; can be from 0 to 10 (both inclusive) */ void setSpeedSliderPosition(int position); - + /** * Get the entity currently selected in the entity selection dropdown. - * + * * @return The name of the currently selected entity */ String getCurrentlySelectedEntity(); - + /** * Set the entity selected in the entity selection dropdown. - * + * * @param entity * The name of the entity to select */ void setCurrentlySelectedEntity(String entity); - + /** * Enable the entity selector */ void enableEntitySelector(); - + /** * Disable the entity selector */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java index 5a423921c..1c1339ec5 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -36,33 +36,33 @@ * @author Tim Neumann */ public class WindowBuilder { - + private static boolean isDefaultLookAndFeelUpdated = false; private static double dpiScale; private static double fontScale; - + private String windowTitle = ""; private boolean useDoubleBuffering; private boolean syncToScreen; private volatile GameWindow window; - + /** * Create a new WindowBuilder. */ public WindowBuilder() { this(WindowBuilder.getDeviceDpiScale()); } - + /** * Create a new WindowBuilder. - * + * * @param dpiScale * the scaling factor for high dpi screens, only effective for the very first WindowBuilder instantiation! */ public WindowBuilder(double dpiScale) { if (dpiScale < 0.5) throw new IllegalArgumentException("A dpi scale < 0.5 is not supported!"); if (dpiScale > 3.0) throw new IllegalArgumentException("A dpi scale > 3.0 is not supported!"); - + if (!WindowBuilder.isDefaultLookAndFeelUpdated) { // only once WindowBuilder.isDefaultLookAndFeelUpdated = true; WindowBuilder.dpiScale = dpiScale; @@ -70,22 +70,22 @@ public WindowBuilder(double dpiScale) { this.setUiDefaults(dpiScale, WindowBuilder.fontScale); } } - + /** * Get the scaling factor from the default display device. - * + * * @return the dpi scale of the default display */ private static double getDeviceDpiScale() { return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform() .getScaleX(); } - + /** * Set the UI Manager defaults forlook and feeel and dpi scaling. *

* This method must only be called once. Calling this twice may have undefined behaviur. - * + * * @param dpiScale * The dpi scaling factor to use to scale all fonts. * @param fontScale @@ -111,7 +111,7 @@ private void setUiDefaults(double dpiScale, double fontScale) { System.err.println("Can't set look and feel because of: " + e.toString()); } } - + /** * Set the title of the new window. * @@ -124,13 +124,12 @@ private void setUiDefaults(double dpiScale, double fontScale) { * The title to set */ public void setTitle(final String title) { - if ( - this.hasBuiltWindow() - ) throw new IllegalStateException("The window was already built! Use the methods of the Window Object to change its properties."); - + if (this.hasBuiltWindow()) + throw new IllegalStateException("The window was already built! Use the methods of the Window Object to change its properties."); + this.windowTitle = title; } - + /** * Set the graphics settings of the playfield drawer. *

@@ -146,14 +145,13 @@ public void setTitle(final String title) { * playfield. */ public void setGraphicsSettings(final boolean useDoubleBuffering, final boolean syncToScreen) { - if ( - this.hasBuiltWindow() - ) throw new IllegalStateException("The window was already built! Use the methods of the Window Object to change its properties."); - + if (this.hasBuiltWindow()) + throw new IllegalStateException("The window was already built! Use the methods of the Window Object to change its properties."); + this.useDoubleBuffering = useDoubleBuffering; this.syncToScreen = syncToScreen; } - + /** * Actually build the window. * @@ -162,9 +160,8 @@ public void setGraphicsSettings(final boolean useDoubleBuffering, final boolean *

*/ public void buildWindow() { - if ( - this.hasBuiltWindow() - ) throw new IllegalStateException("The window was already built! Use getBuiltWindow() to acess the built window."); + if (this.hasBuiltWindow()) + throw new IllegalStateException("The window was already built! Use getBuiltWindow() to acess the built window."); try { SwingUtilities.invokeAndWait(this::buildWindowInternal); } catch (final InterruptedException | InvocationTargetException e) { @@ -172,7 +169,7 @@ public void buildWindow() { System.err.println("Can't build the window because of: " + e.toString()); } } - + /** * Build the window. *

@@ -185,25 +182,25 @@ private void buildWindowInternal() { final SwingEntitySidebar entitySidebar = new SwingEntitySidebar(textureRegistry, WindowBuilder.dpiScale); final SwingConsole console = new SwingConsole(WindowBuilder.fontScale); final SwingTaskStatusDisplay taskStatus = new SwingTaskStatusDisplay(WindowBuilder.fontScale); - + playfieldDrawer.setDoubleBuffering(this.useDoubleBuffering); playfieldDrawer.setSyncToScreen(this.syncToScreen); - + this.window = new SwingGameWindow(textureRegistry, playfieldDrawer, toolbar, entitySidebar, console, taskStatus); if (this.windowTitle != null) { this.window.setWindowTitle(this.windowTitle); } } - + /** * Get whether the window has been built. - * + * * @return true if and only if the window has been built */ public boolean hasBuiltWindow() { return this.window != null; } - + /** * Get the window that was built. *

diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java index 9f68b20a3..144d389c8 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -18,7 +18,7 @@ */ public class LeafNodeException extends UnsupportedOperationException { private static final long serialVersionUID = 2227365905217962083L; - + /** * Default constructor */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java index f15a93580..6a772cf81 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,13 +11,13 @@ /** * The ListenerSetException is thrown if a set listener function in the SimulationProxy fails - * + * * @author Tobias Wältken * @version 1.0 */ public class ListenerSetException extends IllegalArgumentException { private static final long serialVersionUID = -2620520061340158420L; - + /** * Default constructor */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java index e398c0704..84728316f 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -13,12 +13,12 @@ * Exception thrown when a texture file or resource could not be found. */ public class TextureNotFoundException extends RuntimeException { - + /** * generated */ private static final long serialVersionUID = -6554875504029045378L; - + /** * Construct a new {@code TextureNotFoundException} with the given message. * @@ -28,7 +28,7 @@ public class TextureNotFoundException extends RuntimeException { public TextureNotFoundException(final String message) { super(message); } - + /** * Construct a new {@code TextureNotFoundException} with the given message. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java index 4db8ce81c..c75bca1ed 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,19 +16,19 @@ /** * Class containing multiple textures of an animation. - * + * * @author Fabian Bühler */ public class AnimatedTexture implements Texture { - + private final SwingTextureRegistry registry; private final ArrayList animationFrames; private long duration; private final boolean loop; - + /** * Create a new animated Texture. - * + * * @param registry * the texture registry. * @param loop @@ -40,10 +40,10 @@ public AnimatedTexture(final SwingTextureRegistry registry, final boolean loop) this.duration = 0; this.loop = loop; } - + /** * Add a texture at the end of the animation. - * + * * @param frameTexture * the texture handle of the texture to add. * @param frames @@ -57,10 +57,10 @@ public void addAnimationFrame(final String frameTexture, final long frames) { final AnimationFrame frame = new AnimationFrame(last, last + (frames - 1), texture); this.animationFrames.add(frame); } - + /** * Get the texture for the current frame. - * + * * @param frame * the current frame * @return the texture for the frame @@ -68,10 +68,10 @@ public void addAnimationFrame(final String frameTexture, final long frames) { public Texture getTextureForTick(final long frame) { return this.getTextureForTick(frame, 0); } - + /** * Get the texture for the current frame. - * + * * @param frame * the current frame * @param animationStart @@ -80,7 +80,7 @@ public Texture getTextureForTick(final long frame) { */ private Texture getTextureForTick(final long frame, final long animationStart) { if (this.duration == 0) throw new IllegalStateException("AnimatedTexture is empty!"); - + long animationFrame = frame - animationStart; if (this.loop) { animationFrame = animationFrame % this.duration; @@ -98,22 +98,22 @@ private Texture getTextureForTick(final long frame, final long animationStart) { } throw new IllegalStateException("This can only happen if the start and end frames of the animation frames were set wrong!"); } - + @Override public Image getTexture(final long frame) { return this.getTextureForTick(frame).getTexture(); } - + @Override public void drawTexture(final long frame, final Graphics g, final int x, final int y, final int width, final int height) { this.getTextureForTick(frame).drawTexture(frame, g, x, y, width, height); } - + private class AnimationFrame { private final long startFrame; private final long endFrame; private final Texture texture; - + private AnimationFrame(final long startFrame, final long endFrame, final Texture texture) { this.startFrame = startFrame; this.endFrame = endFrame; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java index 4ae62dc38..57f2ff3f7 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -41,18 +41,18 @@ * @version 2.0 */ public class ConsoleBufferedOutputStream extends OutputStream { - + /** The maximum length of the line buffer. */ static final int DEFAULT_MAX_BUFFER_LENGTH = 4096; private final int maxBufferLength; - + private final Timer timer; - + //TODO add actual buffer to avoid overflowing the textarea and cause lag private final JTextPane textPane; private final Style style; private final StringBuilder lineBuffer; - + /** * Default Constructor *

@@ -66,10 +66,10 @@ public class ConsoleBufferedOutputStream extends OutputStream { public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle style) { this(textPane, style, DEFAULT_MAX_BUFFER_LENGTH); } - + /** * Constructor with maxBufferLenght included - * + * * @param textPane * The text pane to place the stream data into * @param style @@ -81,10 +81,10 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle style, int maxBufferLength) { this.maxBufferLength = maxBufferLength; this.lineBuffer = new StringBuilder(maxBufferLength * 2); - + this.textPane = textPane; this.style = this.textPane.addStyle(style.toString(), null); - + switch (style) { case STANDARD: break; @@ -94,7 +94,7 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s default: throw new UnsupportedOperationException("With stye type " + style.toString()); } - + this.timer = new Timer(32, (event) -> { try { // flush the line buffer in regular intervalls @@ -106,44 +106,44 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s this.timer.setCoalesce(true); this.timer.start(); // start timer after everything is initialized } - + @Override public void flush() throws IOException { super.flush(); this.flushLineBufferToTextPane(); } - + @Override public void close() throws IOException { super.close(); this.timer.stop(); } - + @Override public void write(final int character) throws IOException { final char symbol = (char) character; - + synchronized (this.lineBuffer) { this.lineBuffer.append(symbol); } - + if (this.lineBuffer.length() >= this.maxBufferLength) { this.flushLineBufferToTextPane(); } } - + private void flushLineBufferToTextPane() throws IOException { if (this.lineBuffer.length() == 0) { // fast exit as default without costly synchronized return; // nothing to flush in the line buffer } - + String newText; synchronized (this.lineBuffer) { // stringBuilder is not threadsafe // get the current buffer and reset linebuffer newText = this.lineBuffer.toString(); this.lineBuffer.setLength(0); } - + if (newText.length() > 0) { // new null check because previous check may be obsolete now // print line to text pane SwingUtilities.invokeLater(() -> { @@ -158,14 +158,14 @@ private void flushLineBufferToTextPane() throws IOException { }); } } - + /** * Get's {@link #maxBufferLength maxBufferLength} - * + * * @return maxBufferLength */ public int getMaxBufferLength() { return this.maxBufferLength; } - + } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java index e8899560b..da399d887 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,14 +11,14 @@ /** * Enum to identify different standard styles for the ConsoleBufferedOutputStream - * + * * @author David Ruff */ public enum OutputStyle { - + /** Standard Style for text from stdout */ STANDARD, - + /** Style for text from stderr (e.g. errors) */ ERROR } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java index b268e030d..9e99fdfb7 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,28 +15,28 @@ /** * Class containing a texture image and methods to draw this image. - * + * * @author Fabian Bühler */ public class StaticTexture implements Texture { - + private final Image texture; - + /** * Create a new Texture. - * + * * @param texture * the image to use as texture. */ public StaticTexture(final Image texture) { this.texture = texture; } - + @Override public Image getTexture(final long frame) { return this.texture; } - + @Override public void drawTexture(final long frame, final Graphics g, final int x, final int y, final int width, final int height) { g.drawImage(this.texture, x, y, width, height, null); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java index eeaaf0f67..de64140a8 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -19,7 +19,7 @@ * @version 1.0 */ public abstract class StaticUiTextures { - + /** A play icon */ public static String playIcon; /** A step icon */ @@ -29,14 +29,14 @@ public abstract class StaticUiTextures { /** A stop icon */ @Deprecated public static String stopIcon; - + /** A arrow icon */ public static String arrowIcon; /** A add icon */ public static String addIcon; /** A sub icon */ public static String subIcon; - + /** * This function loads all textures into the given texture registry and stores the icon ids * @@ -48,7 +48,7 @@ public static void load(final TextureRegistry registry) { StaticUiTextures.stepIcon = registry.loadTextureFromResource("textures/step.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.pauseIcon = registry.loadTextureFromResource("textures/pause.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.stopIcon = registry.loadTextureFromResource("textures/stop.png", TextureRegistry.class::getResourceAsStream); - + StaticUiTextures.arrowIcon = registry.loadTextureFromResource("textures/arrow.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.addIcon = registry.loadTextureFromResource("textures/add.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.subIcon = registry.loadTextureFromResource("textures/sub.png", TextureRegistry.class::getResourceAsStream); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java index 71fd8abbb..3b588be2a 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -31,40 +31,40 @@ */ public class SwingConsole extends JTextPane implements Console { private static final long serialVersionUID = 5100186594058483257L; - + private ConsoleBufferedOutputStream systemOutputStream; private ConsoleBufferedOutputStream systemErrorStream; - + /** * Default constructor *

* This should only be called from the swing ui thread - * + * * @param fontScale * the scaling value for the fontSize */ public SwingConsole(final double fontScale) { super(new DefaultStyledDocument()); - + final int fontSize = (int) Math.floor(12 * fontScale); final Font standardFont = new Font("monospaced", Font.PLAIN, fontSize); - + this.setEditable(false); this.setFont(standardFont); final DefaultCaret caret = (DefaultCaret) this.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); this.systemOutputStream = new ConsoleBufferedOutputStream(this, OutputStyle.STANDARD); this.systemErrorStream = new ConsoleBufferedOutputStream(this, OutputStyle.ERROR); - + Logger.addOutOutputStream(this.systemOutputStream); Logger.addErrorOutputStream(this.systemErrorStream); } - + @Override public void clearConsole() { SwingUtilities.invokeLater(() -> this.setText("")); } - + /** * Detach the internal output streams from {@code Logger.out} and {@code Logger.error}. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java index 83a25ed31..395bf4dd9 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -36,66 +36,66 @@ */ public class SwingEntityInspector extends JPanel { private static final long serialVersionUID = 1L; - + private final GridBagConstraints gbc; - + /** The name at the top */ private final JLabel title; - + /** The JPanel containing all the ui elements */ private JPanel inspector; - + /** The user warning at the bottom */ private final JLabel warning; - + private Object updateLock = new Object(); private EntityInspectorEntry[] currentEntries; private List> uiValueUpdaters; - + /** * Default constructor *

* This should only be called from the swing ui thread - * + * * @param textureRegistry * The texture registry to get the images from */ public SwingEntityInspector(final SwingTextureRegistry textureRegistry) { this.setLayout(new BorderLayout()); - + this.title = new JLabel("Empty"); this.add(this.title, BorderLayout.PAGE_START); - + this.inspector = new JPanel(); this.inspector.setLayout(new GridBagLayout()); this.add(this.inspector, BorderLayout.CENTER); - + this.warning = new JLabel("Pause the simulation to modify an entity!"); this.warning.setVisible(false); this.add(this.warning, BorderLayout.PAGE_END); - + this.gbc = new GridBagConstraints(); this.gbc.fill = GridBagConstraints.HORIZONTAL; this.gbc.gridx = 0; this.gbc.gridy = 0; - + this.setEnabled(false); this.warning.setVisible(false); } - + /** * Getter for the inspector name wich is displayed at the top - * + * * @return the name */ @Override public String getName() { return this.title.getText(); } - + /** * Setter for the inspector name - * + * * @param name * The new name */ @@ -105,7 +105,7 @@ public void setName(final String name) { this.title.setText(name); return; } - + // cannot call invokeAndWait when already in EventDispatchThread! try { SwingUtilities.invokeAndWait(() -> { @@ -115,7 +115,7 @@ public void setName(final String name) { System.err.println("Failed to set entity inspector name because of: " + e.toString()); } } - + /** * Update the entity inspector to reflect the new Values. * @@ -131,15 +131,15 @@ public void updateEntityInspectorEntries(final EntityInspectorEntry[] entries) { List> valueUpdaters = this.uiValueUpdaters; if (valueUpdaters == null) return; // TODO throw exeptions here? if (valueUpdaters.size() != entries.length) return; - + // update values for (int i = 0; i < entries.length; i++) { valueUpdaters.get(i).accept(entries[i].getValue()); } - + // change to new entries list this.currentEntries = entries; - + // update ui this.revalidate(); this.repaint(); @@ -147,39 +147,39 @@ public void updateEntityInspectorEntries(final EntityInspectorEntry[] entries) { }); return; } - + // completely update the view SwingUtilities.invokeLater(() -> { synchronized (this.updateLock) { // clear old elements first, then update current entries list this.clearUIElements(); - + // change to new entries list this.uiValueUpdaters = null; this.currentEntries = entries; // only do this after clearing old elements - + // add new ui elements List> newUiValueUpdaters = new ArrayList<>(entries.length); for (int i = 0; i < entries.length; i++) { newUiValueUpdaters.add(this.addUIElement(entries[i], i)); } - + // set new value updaters this.uiValueUpdaters = newUiValueUpdaters; - + // update ui this.revalidate(); this.repaint(); } }); } - + /** * Check if the new list of entries matches the current entries structurally. * * @param entries * The ne list of entries to check against currentEntries - * + * * @return true iff only the values need to be updated */ private boolean canUpdateValuesOnly(final EntityInspectorEntry[] entries) { @@ -194,13 +194,13 @@ private boolean canUpdateValuesOnly(final EntityInspectorEntry[] entries) { } return true; } - + /** * Callback to change the value of an entry. - * + * * This indirect callback is used to avoid changing the callback on the ui element when only the values of the * entries have changed. - * + * * @param index * the index of the entry to update * @param name @@ -214,28 +214,28 @@ private void updateValueOnEntity(int index, String name, String value) { if (!entry.getName().equals(name)) return; entry.runCallback(value); } - + /** * Add a entry to the ui editor *

* This should only be run from the swing ui thread - * + * * @param entry * The entry to add a ui element for * @param index * The index of the entry in currentEntries - * + * * @return A consumer that updates the newly added ui element to the given string value */ private Consumer addUIElement(final EntityInspectorEntry entry, final int index) { - + final String name = entry.getName(); this.inspector.add(new JLabel(name + ": "), this.gbc); this.gbc.gridx = 1; - + Consumer updateUiValueCallback = (newValue) -> { /* Default is to update nothing. */}; - + switch (entry.getType()) { case "integer": { final NumberFormatter formatter = new NumberFormatter(NumberFormat.getInstance()); @@ -276,13 +276,13 @@ private Consumer addUIElement(final EntityInspectorEntry entry, final in updateUiValueCallback = (newValue) -> label.setText(newValue); this.inspector.add(label, this.gbc); } - + this.gbc.gridx = 0; this.gbc.gridy += 1; - + return updateUiValueCallback; } - + /** * Clears the entity editor *

@@ -293,23 +293,23 @@ private void clearUIElements() { this.inspector = new JPanel(); this.inspector.setLayout(new GridBagLayout()); this.add(this.inspector, BorderLayout.CENTER); - + this.gbc.gridx = 0; this.gbc.gridy = 0; } - + @Override public void setEnabled(final boolean enabled) { super.setEnabled(enabled); - + this.title.setEnabled(enabled); SwingEntityInspector.setEnabledState(this.inspector, enabled); this.warning.setVisible(!enabled); } - + /** * Recursive method to enable and disable a JPanel and its children - * + * * @param panel * The panel to traverse * @param state @@ -317,7 +317,7 @@ public void setEnabled(final boolean enabled) { */ private static void setEnabledState(final JPanel panel, final boolean state) { panel.setEnabled(state); - + for (final Component component : panel.getComponents()) { if (component instanceof JPanel) { SwingEntityInspector.setEnabledState((JPanel) component, state); @@ -325,7 +325,7 @@ private static void setEnabledState(final JPanel panel, final boolean state) { component.setEnabled(state); } } - + @Override public Dimension getPreferredSize() { return new Dimension(300, 300); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java index 176b1b692..cd9757672 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -36,17 +36,17 @@ * A swing implementation of the EntitySidebar * * @author Tobias Wältken - * + * * @version 1.0 */ public class SwingEntitySidebar extends JPanel implements EntitySidebar { private static final long serialVersionUID = -4409545257025298208L; - + /** The simulation proxy */ private SimulationProxy simulationProxy; /** The texture registry */ private final SwingTextureRegistry textureRegistry; - + /** The root node of the entity list */ private SimulationTreeNode rootNode; /** The hierarchical list of all entities */ @@ -55,7 +55,7 @@ public class SwingEntitySidebar extends JPanel implements EntitySidebar { private DefaultTreeModel entityListModel; /** The entity inspector in the sidebar */ private SwingEntityInspector entityInspector; - + /** * The default constructor *

@@ -69,7 +69,7 @@ public class SwingEntitySidebar extends JPanel implements EntitySidebar { public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final double dpiScale) { // class setup this.textureRegistry = textureRegistry; - + // JTree setup this.entityListModel = new DefaultTreeModel(null, true); this.entityList = new JTree(this.entityListModel); @@ -84,7 +84,7 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub } return; } - + if (SwingEntitySidebar.this.simulationProxy != null) { SwingEntitySidebar.this.simulationProxy.selectedSimulationEntityChange( (SimulationTreeNode) ((DefaultMutableTreeNode) SwingEntitySidebar.this.entityList.getLastSelectedPathComponent()) @@ -92,22 +92,22 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub ); } }); - + // Entity inspector setup this.entityInspector = new SwingEntityInspector(this.textureRegistry); - + // Sidebar layout final JScrollPane pane = new JScrollPane(this.entityList); pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - + final JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pane, this.entityInspector); jsp.setOneTouchExpandable(true); jsp.setResizeWeight(0.4); this.setLayout(new BorderLayout()); this.add(jsp, BorderLayout.CENTER); } - + /** * TODO better doc * @@ -116,10 +116,10 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - + this.simulationProxy = simulationProxy; } - + @Override public void setSimulationTreeRootNode(final SimulationTreeNode treeNode) { SwingUtilities.invokeLater(() -> { @@ -130,7 +130,7 @@ public void setSimulationTreeRootNode(final SimulationTreeNode treeNode) { // The order of execution is still correct, because calls to invokeLater are processes in the order the calls happen. this.updateSimulationTree(); } - + private void getExpandedTreePaths(final List expanded, final TreePath path) { if (path == null) return; for (final Enumeration e = this.entityList.getExpandedDescendants(path); e.hasMoreElements();) { @@ -139,18 +139,18 @@ private void getExpandedTreePaths(final List expanded, final TreePath this.getExpandedTreePaths(expanded, p); } } - + private TreePath getRootPath() { final Object root = this.entityList.getModel().getRoot(); if (root == null) return null; return new TreePath(root); } - + @Override public void updateSimulationTree() { SwingUtilities.invokeLater(this::updateSimulationTreeInternal); } - + /** * Update the simulation tree model. *

@@ -167,30 +167,30 @@ private void updateSimulationTreeInternal() { this.entityList.expandPath(p); } } - + @Override public void setEnabled(final boolean enabled) { super.setEnabled(enabled); this.entityList.setEnabled(enabled); } - + @Override public void setEntityInspectorEntries(final EntityInspectorEntry[] entries) { this.entityInspector.updateEntityInspectorEntries(entries); } - + @Override public Dimension getPreferredSize() { return new Dimension(300, 800); } - + private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { if ((node == null) || !node.getAllowsChildren()) return; final SimulationTreeNode data = (SimulationTreeNode) node.getUserObject(); - + final List toRemove = new ArrayList<>(); final List toAdd = new ArrayList<>(); - + outer: for (final SimulationTreeNode child : data.getChildren()) { for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); @@ -200,7 +200,7 @@ private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { } toAdd.add(child); } - + outer: for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); for (final SimulationTreeNode child : data.getChildren()) { @@ -210,58 +210,59 @@ private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { } toRemove.add(childNode); } - + for (final DefaultMutableTreeNode child : toRemove) { node.remove(child); } - + for (final SimulationTreeNode child : toAdd) { node.add(SwingEntitySidebar.generateDefaultMutableTreeNodeFromSimulationTreeNode(child)); } - + for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); SwingEntitySidebar.updateTreeNodeChildren(childNode); } } - + /** * Recursively generate a {@link DefaultMutableTreeNode} from a {@link SimulationTreeNode} * * @param node * The {@link SimulationTreeNode} the Tree structure is generated from - * + * * @return Returns the corresponding {@link DefaultMutableTreeNode} */ private static DefaultMutableTreeNode generateDefaultMutableTreeNodeFromSimulationTreeNode(final SimulationTreeNode node) { final DefaultMutableTreeNode returnNode = new DefaultMutableTreeNode(node); - + if (node.isLeaf()) { returnNode.setAllowsChildren(false); } else { node.forEachChild( - (final SimulationTreeNode childNode) -> returnNode.add(SwingEntitySidebar.generateDefaultMutableTreeNodeFromSimulationTreeNode(childNode)) + (final SimulationTreeNode childNode) -> returnNode + .add(SwingEntitySidebar.generateDefaultMutableTreeNodeFromSimulationTreeNode(childNode)) ); } - + return returnNode; } - + @Override public SimulationTreeNode getSimulationTreeSelectedElement() { return (SimulationTreeNode) ((DefaultMutableTreeNode) this.entityList.getLastSelectedPathComponent()).getUserObject(); } - + @Override public void setSimulationTreeSelectedElement(final SimulationTreeNode node) { //TODO implement } - + @Override public void enableSimulationTree() { SwingUtilities.invokeLater(() -> this.entityList.setEnabled(true)); } - + @Override public void disbaleSimulationTree() { SwingUtilities.invokeLater(() -> { @@ -269,22 +270,22 @@ public void disbaleSimulationTree() { this.entityListModel.setRoot(null); }); } - + @Override public void setEntityInspectorName(final String name) { SwingUtilities.invokeLater(() -> this.entityInspector.setName(name)); } - + @Override public String getEntityInspectorName() { return this.entityInspector.getName(); } - + @Override public void enableEntityInspector() { SwingUtilities.invokeLater(() -> this.entityInspector.setEnabled(true)); } - + @Override public void disableEntityInspector() { SwingUtilities.invokeLater(() -> SwingEntitySidebar.this.entityInspector.setEnabled(false)); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java index 01bf69421..a43a27610 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -45,16 +45,16 @@ */ public class SwingGameWindow extends JFrame implements GameWindow { private static final long serialVersionUID = -7215617949088643819L; - + private final SwingTextureRegistry textureRegistry; private final SwingPlayfieldDrawer playfieldDrawer; private final SwingToolbar toolbar; private final SwingEntitySidebar entitySidebar; private final SwingConsole console; private final SwingTaskStatusDisplay taskStatus; - + private SimulationProxy simulationProxy; - + /** * Create a new Swing game window using the given submodules. * @@ -83,7 +83,7 @@ public SwingGameWindow( this.taskStatus = taskStatus; SwingUtilities.invokeLater(this::initGameWindow); } - + @Override public void setSimulationProxy(final SimulationProxy simulationProxy) { // contains no direct calls to any swing ui method @@ -93,55 +93,55 @@ public void setSimulationProxy(final SimulationProxy simulationProxy) { this.entitySidebar.setSimulationProxy(simulationProxy); this.taskStatus.setSimulationProxy(simulationProxy); } - + @Override public TextureRegistry getTextureRegistry() { return this.textureRegistry; } - + @Override public PlayfieldDrawer getPlayfieldDrawer() { return this.playfieldDrawer; } - + @Override public Toolbar getToolbar() { return this.toolbar; } - + @Override public EntitySidebar getEntitySidebar() { return this.entitySidebar; } - + @Override public Console getConsole() { return this.console; } - + @Override public TaskStatusDisplay getTaskStatusDisplay() { return this.taskStatus; } - + @Override public void setWindowTitle(final String title) { // UI operations must happen in swing thread! SwingUtilities.invokeLater(() -> this.setTitle(title)); } - + @Override public void start() { // Asynchronously set visible to true SwingUtilities.invokeLater(() -> this.setVisible(true)); } - + @Override public void stop() { // programmatically close the window Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } - + /** * Initialize window listeners and layout all child components. *

@@ -150,7 +150,7 @@ public void stop() { @SuppressWarnings("unused") // Suppress unused warnings on 'ClassCastException e' private void initGameWindow() { // init jFrame - + // // setup window closing // @@ -161,9 +161,9 @@ public void windowClosing(final WindowEvent e) { SwingGameWindow.this.cleanup(); // stop simulation etc. } }); - + this.playfieldDrawer.initialize(); - + // // convert toolbar // @@ -173,7 +173,7 @@ public void windowClosing(final WindowEvent e) { } catch (ClassCastException | NullPointerException e) { toolbarComponent = new JLabel("Toolbar not valid!", UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - + // // convert sidebar // @@ -183,7 +183,7 @@ public void windowClosing(final WindowEvent e) { } catch (ClassCastException | NullPointerException e) { sidebarComponent = new JLabel(UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - + // // convert console // @@ -193,7 +193,7 @@ public void windowClosing(final WindowEvent e) { } catch (NullPointerException e) { consoleComponent = new JLabel("Console not valid!", UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - + // // setup bottom pane layout // @@ -201,7 +201,7 @@ public void windowClosing(final WindowEvent e) { bottomPane.addTab("Console", new JScrollPane(consoleComponent)); bottomPane.addTab("Task Status", this.taskStatus); bottomPane.setPreferredSize(new Dimension(400, 200)); - + // // setup JFrame layout // @@ -212,13 +212,13 @@ public void windowClosing(final WindowEvent e) { final JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jsp1, sidebarComponent); jsp2.setOneTouchExpandable(true); this.getContentPane().add(BorderLayout.CENTER, jsp2); - + // // finalize jFrame // this.pack(); } - + /** * Clean up all resources used by this window and tell the simulation that the window is now closed. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java index 230800db6..03217ab0a 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -36,34 +36,34 @@ * @author Tim Neumann */ public class SwingPlayfieldDrawer extends JPanel implements PlayfieldDrawer { - + /** * generated */ private static final long serialVersionUID = 1800137555269066525L; - + /** Stretch factor for mapping row/column coordinates to screen coordinates. */ private final double CELL_SIZE; - + private final int INFO_BAR_HEIGHT; - + // Colors private static final Color BACKGROUND_COLOR = new Color(255, 255, 255); private static final Color BACKGROUND_COLOR_TRANSPARENT = new Color(255, 255, 255, 230); private static final Color GRID_COLOR = new Color(46, 52, 54); private static final Color OVERLAY_COLOR = new Color(0, 40, 255, 50); - + private static final RenderingHints RENDERING_HINTS = new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON ); - + private final SwingTextureRegistry textureRegistry; - + // current display offset and zoom private double offsetX; private double offsetY; private double scale = 1.0; - + // mouse events private boolean mouseInWindow = false; private int currentMouseX = 0; @@ -71,29 +71,29 @@ public class SwingPlayfieldDrawer extends JPanel implements PlayfieldDrawer { private int mouseStartX = 0; private int mouseStartY = 0; private boolean isDrag = false; - + // current tool state private ControlButtonState activeTool = ControlButtonState.BLOCKED; private String selectedEntityType = null; private String selectedEntityTexture = null; private SimulationProxy simulationProxy; - + private List drawables = List.of(); private List animatedDrawables = List.of(); private boolean fullRepaintNeeded = true; private Rectangle lastRedrawArea = null; private long currentFrame = 0; - + // current graphic settings private final RepaintManager repaintManager; private boolean useDoubleBuffer = true; private boolean syncToscreen = true; - + private double dpiScale; - + private Font scaleFont; private Font font; - + /** * Create a new SwingPlayfieldDrawer. *

@@ -106,22 +106,22 @@ public class SwingPlayfieldDrawer extends JPanel implements PlayfieldDrawer { */ public SwingPlayfieldDrawer(final SwingTextureRegistry textureRegistry, final double dpiScale) { this.textureRegistry = textureRegistry; - + this.setOpaque(true); this.repaintManager = RepaintManager.currentManager(this); - + this.INFO_BAR_HEIGHT = (int) Math.floor(25 * dpiScale); this.CELL_SIZE = (int) Math.floor(32 * dpiScale); this.offsetX = this.CELL_SIZE; this.offsetY = this.CELL_SIZE; this.dpiScale = dpiScale; - + Font font = this.getFont(); final int newFontSize = (int) Math.floor(12 * dpiScale * this.scale); this.font = new Font(font.getFontName(), font.getStyle(), newFontSize); this.setFont(this.font); } - + /** * Set the simulation proxy. TODO better doc * @@ -130,63 +130,63 @@ public SwingPlayfieldDrawer(final SwingTextureRegistry textureRegistry, final do */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - + this.simulationProxy = simulationProxy; } - + /** * Initialize the PlayfieldDrawer. *

* This should only be called from the swing ui thread */ public void initialize() { - + this.addMouseListener(new MouseListener() { - + @Override public void mouseReleased(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { SwingPlayfieldDrawer.this.mouseReleased(e.getX(), e.getY()); } } - + @Override public void mousePressed(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { SwingPlayfieldDrawer.this.mousePressed(e.getX(), e.getY()); } } - + @Override public void mouseExited(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMouseInWindow(false); } - + @Override public void mouseEntered(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMouseInWindow(true); } - + @Override public void mouseClicked(final MouseEvent e) { // ignore this for now } }); - + this.addMouseMotionListener(new MouseMotionListener() { - + @Override public void mouseMoved(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMousePosition(e.getX(), e.getY()); } - + @Override public void mouseDragged(final MouseEvent e) { SwingPlayfieldDrawer.this.updateDrag(e.getX(), e.getY()); SwingPlayfieldDrawer.this.updateMousePosition(e.getX(), e.getY()); } }); - + this.addMouseWheelListener(e -> { final int rot = e.getWheelRotation(); final int x = e.getX(); @@ -194,17 +194,17 @@ public void mouseDragged(final MouseEvent e) { SwingPlayfieldDrawer.this.updateZoom(rot, x, y); }); } - + @Override public void setDrawables(final List drawables) { this.drawables = drawables.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toUnmodifiableList()); - this.animatedDrawables = drawables.stream().filter( - d -> d.isAnimated() || this.textureRegistry.isTextureAnimated(d.getTextureHandle()) - ).collect(Collectors.toUnmodifiableList()); + this.animatedDrawables = drawables.stream() + .filter(d -> d.isAnimated() || this.textureRegistry.isTextureAnimated(d.getTextureHandle())) + .collect(Collectors.toUnmodifiableList()); this.fullRepaintNeeded = true; this.draw(this.currentFrame); } - + @Override public void draw(final long tickCount) { this.currentFrame = tickCount; @@ -212,16 +212,16 @@ public void draw(final long tickCount) { if (this.animatedDrawables.size() > 0) { this.drawables = this.drawables.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toUnmodifiableList()); } - + SwingUtilities.invokeLater(() -> { // synchronize this to fix possible null pointer when setting double buffer setting - + final boolean bufferEnabled = this.repaintManager.isDoubleBufferingEnabled(); if (!this.useDoubleBuffer) { // only change strategy to false since true should already be default this.repaintManager.setDoubleBufferingEnabled(this.useDoubleBuffer); } - + if (this.fullRepaintNeeded) { Rectangle visible = this.getVisibleRect(); if (visible == null) { @@ -234,9 +234,9 @@ public void draw(final long tickCount) { final Rectangle visible = this.getVisibleRect(); final double cellSize = this.CELL_SIZE * this.scale; final int textureSize = Math.toIntExact(Math.round(cellSize)); - final Optional rectToDraw = this.animatedDrawables.stream().map( - d -> this.getScreenPointFromCellCoordinates(d.getX(), d.getY(), cellSize) - ).map(p -> SwingPlayfieldDrawer.getPaintRectFromPoint(p, textureSize)).filter(r -> r.intersects(visible)) + final Optional rectToDraw = this.animatedDrawables.stream() + .map(d -> this.getScreenPointFromCellCoordinates(d.getX(), d.getY(), cellSize)) + .map(p -> SwingPlayfieldDrawer.getPaintRectFromPoint(p, textureSize)).filter(r -> r.intersects(visible)) .reduce((final Rectangle r1, final Rectangle r2) -> { r1.add(r2); return r1; @@ -269,11 +269,11 @@ public void draw(final long tickCount) { } }); // filter out finished animations - this.animatedDrawables = this.drawables.stream().filter( - d -> d.isAnimated() || this.textureRegistry.isTextureAnimated(d.getTextureHandle()) - ).collect(Collectors.toUnmodifiableList()); + this.animatedDrawables = this.drawables.stream() + .filter(d -> d.isAnimated() || this.textureRegistry.isTextureAnimated(d.getTextureHandle())) + .collect(Collectors.toUnmodifiableList()); } - + @Override public void resetZoomAndPan() { this.scale = 1.0; @@ -283,42 +283,42 @@ public void resetZoomAndPan() { final int newFontSize = (int) Math.floor(12 * this.dpiScale * this.scale); this.scaleFont = new Font(font.getFontName(), font.getStyle(), newFontSize); } - + @Override public void setDoubleBuffering(final boolean useDoubleBuffering) { this.useDoubleBuffer = useDoubleBuffering; } - + @Override public void setSyncToScreen(final boolean syncToScreen) { this.syncToscreen = syncToScreen; } - + @Override public Dimension getPreferredSize() { return new Dimension(800, 600); } - + private int getColumnCoordinateFromScreenCoordinate(final int screenX) { final double cellSize = this.CELL_SIZE * this.scale; return (int) Math.floor((screenX - this.offsetX) / cellSize); } - + private int getRowCoordinateFromScreenCoordinate(final int screenY) { final double cellSize = this.CELL_SIZE * this.scale; return (int) Math.floor((screenY - this.offsetY) / cellSize); } - + private Point getScreenPointFromCellCoordinates(final double x, final double y, final double cellSize) { final int screenX = Math.toIntExact(Math.round((x * cellSize) + this.offsetX)); final int screenY = Math.toIntExact(Math.round((y * cellSize) + this.offsetY)); return new Point(screenX, screenY); } - + private static Rectangle getPaintRectFromPoint(final Point upperLeftCorner, final int cellSize) { return new Rectangle(upperLeftCorner.x, upperLeftCorner.y, cellSize, cellSize); } - + @Override public void paintComponent(final Graphics g) { if (g instanceof Graphics2D) { @@ -330,7 +330,7 @@ public void paintComponent(final Graphics g) { this.paintDrawableList(g, this.drawables); this.paintOverlay(g); } - + private void paintGrid(final Graphics g) { final Rectangle clipBounds = g.getClipBounds(); // cell size on screen (with zoom) @@ -339,7 +339,7 @@ private void paintGrid(final Graphics g) { // to the top left corner of e cell on screen) final double firstX = (Math.IEEEremainder(this.offsetX - clipBounds.x, cellSize) + clipBounds.x) - cellSize; final double firstY = (Math.IEEEremainder(this.offsetY - clipBounds.y, cellSize) + clipBounds.y) - cellSize; - + final int width = this.getWidth(); final int height = this.getHeight(); g.setColor(SwingPlayfieldDrawer.GRID_COLOR); @@ -354,7 +354,7 @@ private void paintGrid(final Graphics g) { g.drawLine(0, iy, width, iy); } } - + /** * Compare two drawables and checks if they can be grouped together. * @@ -375,14 +375,14 @@ private static boolean canGroupDrawables(final Drawable a, final Drawable b) { if (Math.abs(a.getY() - b.getY()) > 0.001) return false; return true; } - + private void paintDrawableList(final Graphics g, final List drawablesList) { if (drawablesList.size() <= 0) return; final Iterator iter = drawablesList.iterator(); Drawable last = null; int currentCount = 0; boolean isTilable = true; - + // group and count drawables while (iter.hasNext()) { final Drawable next = iter.next(); @@ -402,7 +402,7 @@ private void paintDrawableList(final Graphics g, final List drawablesL this.paintDrawable(g, last, currentCount + 1, isTilable); } } - + private void paintDrawable(final Graphics g, final Drawable drawable, final int count, final boolean isTilable) { final double cellSize = this.CELL_SIZE * this.scale; final int x = Math.toIntExact(Math.round((drawable.getX() * cellSize) + this.offsetX)); @@ -429,7 +429,7 @@ private void paintDrawable(final Graphics g, final Drawable drawable, final int final Double scaleAdjust = third; this.paintMultiCountDrawable(g, drawable, count, xOffsets, yOffsets, scaleAdjust); } - + private void paintMultiCountDrawable( final Graphics g, final Drawable drawable, final int count, final Double[] xOffsets, final Double[] yOffsets, final Double scaleAdjust @@ -456,7 +456,7 @@ private void paintMultiCountDrawable( } } } - + private void drawNumber(int count, Graphics g, int x, int y) { final double cellSize = this.CELL_SIZE * this.scale; g.setFont(this.scaleFont); @@ -475,19 +475,19 @@ private void drawNumber(int count, Graphics g, int x, int y) { g.drawString("" + count, x + xOffset, y + yOffset); g.setFont(this.font); } - + private void paintOverlay(final Graphics g) { final int width = this.getWidth(); final int height = this.getHeight(); - + final int currentCellX = this.getColumnCoordinateFromScreenCoordinate(this.currentMouseX); final int currentCellY = this.getRowCoordinateFromScreenCoordinate(this.currentMouseY); - + final double cellSize = this.CELL_SIZE * this.scale; final int roundedCellSize = Math.toIntExact(Math.round(cellSize)); final int screenX = Math.toIntExact(Math.round(this.offsetX + (currentCellX * cellSize))); final int screenY = Math.toIntExact(Math.round(this.offsetY + (currentCellY * cellSize))); - + // draw cell highlight if (this.mouseInWindow && g.hitClip(screenX, screenY, roundedCellSize, roundedCellSize)) { // draw current tool texture @@ -508,44 +508,44 @@ private void paintOverlay(final Graphics g) { g.setColor(SwingPlayfieldDrawer.OVERLAY_COLOR); g.fillRect(screenX, screenY, roundedCellSize, roundedCellSize); } - + // draw info bar if (this.mouseInWindow && g.hitClip(0, height - this.INFO_BAR_HEIGHT, width, this.INFO_BAR_HEIGHT)) { - + g.setColor(SwingPlayfieldDrawer.BACKGROUND_COLOR); g.fillRect(0, height - this.INFO_BAR_HEIGHT, width, this.INFO_BAR_HEIGHT); g.setColor(SwingPlayfieldDrawer.GRID_COLOR); - + // calculate baseline final FontMetrics font = g.getFontMetrics(); final int heightAboveBaseline = font.getAscent(); final int heightBelowBaseline = font.getMaxDescent(); final int baselineCentered = Math.toIntExact(Math.round((this.INFO_BAR_HEIGHT / 2.0) - (heightAboveBaseline / 2.0))); final int baseline = height - Math.max(baselineCentered, heightBelowBaseline); - + // build string final String infoText = "Cell (x=" + currentCellX + ", y=" + currentCellY + ")"; g.drawString(infoText, 5, baseline); - + } } - + private void mousePressed(final int screenX, final int screenY) { this.mouseStartX = screenX; this.mouseStartY = screenY; this.isDrag = false; } - + private void mouseReleased(final int screenX, final int screenY) { if (!this.isDrag) { this.mouseClick(this.mouseStartX, this.mouseStartY); } } - + private void mouseClick(final int screenX, final int screenY) { final int x = this.getColumnCoordinateFromScreenCoordinate(screenX); final int y = this.getRowCoordinateFromScreenCoordinate(screenY); - + if (this.activeTool == ControlButtonState.ADD) { final String type = this.selectedEntityType; if ((type == null) || type.equals("")) { @@ -569,12 +569,12 @@ private void mouseClick(final int screenX, final int screenY) { } this.repaint(); } - + private void updateMouseInWindow(final boolean mouseInWindow) { this.mouseInWindow = mouseInWindow; this.repaintMouseOverlay(); } - + private void updateMousePosition(final int x, final int y) { final int oldX = this.currentMouseX; final int oldY = this.currentMouseY; @@ -583,18 +583,18 @@ private void updateMousePosition(final int x, final int y) { this.repaintCellHighlight(oldX, oldY); this.repaintMouseOverlay(); } - + private void repaintMouseOverlay() { this.repaintCellHighlight(this.currentMouseX, this.currentMouseY); this.repaint(0, this.getHeight() - this.INFO_BAR_HEIGHT, this.getWidth(), this.INFO_BAR_HEIGHT); } - + private void repaintCellHighlight(final int x, final int y) { final double cellSize = this.CELL_SIZE * this.scale; final int roundedCellSize = Math.toIntExact(Math.round(cellSize)); this.repaint(x - roundedCellSize, y - roundedCellSize, 2 * roundedCellSize, 2 * roundedCellSize); } - + private void updateDrag(final int x, final int y) { this.isDrag = true; // TODO change this later to support different tools... @@ -604,7 +604,7 @@ private void updateDrag(final int x, final int y) { this.mouseStartY = y; this.repaint(); } - + private void updateZoom(final int amount, final int x, final int y) { final double zoomScaling = 0.1 * Math.ceil(this.scale); double newScale = this.scale + (zoomScaling * -amount); @@ -622,18 +622,18 @@ private void updateZoom(final int amount, final int x, final int y) { this.scale = newScale; this.offsetX += dx; this.offsetY += dy; - + Font font = this.getFont(); final int newFontSize = (int) Math.floor(12 * this.dpiScale * this.scale); this.scaleFont = new Font(font.getFontName(), font.getStyle(), newFontSize); this.repaint(); } - + @Override public void setSelectedTool(final ControlButtonState selectedTool) { this.activeTool = selectedTool; } - + @Override public void setSelectedEntityType(final String typeName, final String textureHandle) { this.selectedEntityType = typeName; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java index 263add095..be56839c3 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -37,49 +37,49 @@ * @version 1.0 */ public class SwingTaskStatusDisplay extends JPanel implements TaskStatusDisplay { - + private static final long serialVersionUID = -2711911902591163118L; - + private final JTextPane textPane; - + private final Style textStyle; private final Style taskTitle; private final Style taskSuccess; private final Style taskFail; - + private SimulationProxy simulationProxy; - + /** * Default constructor. *

* This should only be called from the swing ui thread - * + * * @param fontScale * the scaling value for the fontSize */ public SwingTaskStatusDisplay(final double fontScale) { super(new BorderLayout()); - + // setup text pane this.textPane = new JTextPane(new DefaultStyledDocument()); this.textPane.setEditable(false); ((DefaultCaret) this.textPane.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE); - + // setup text styles final int fontSize = (int) Math.floor(12 * fontScale); this.textStyle = this.textPane.addStyle("Text", null); StyleConstants.setFontFamily(this.textStyle, "serif"); StyleConstants.setFontSize(this.textStyle, fontSize); - + this.taskTitle = this.textPane.addStyle("TaskTitle", this.textStyle); StyleConstants.setBold(this.taskTitle, true); - + this.taskSuccess = this.textPane.addStyle("TaskSuccess", this.taskTitle); this.taskFail = this.textPane.addStyle("TaskFail", this.taskTitle); - + StyleConstants.setForeground(this.taskSuccess, Color.GREEN); StyleConstants.setForeground(this.taskFail, Color.RED); - + // setup refresh button final JButton refreshButton = new JButton("Refresh"); refreshButton.addActionListener(ae -> { @@ -87,12 +87,12 @@ public SwingTaskStatusDisplay(final double fontScale) { this.simulationProxy.refreshTaskInformation(); } }); - + // pack component this.add(new JScrollPane(this.textPane), BorderLayout.CENTER); this.add(refreshButton, BorderLayout.LINE_END); } - + /** * Set the simulation proxy. TODO better doc * @@ -101,10 +101,10 @@ public SwingTaskStatusDisplay(final double fontScale) { */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - + this.simulationProxy = simulationProxy; } - + @Override public void setTaskInformation(final TaskInformation task) { // invoke later to break out of event thread of the refresh button press handler @@ -119,10 +119,10 @@ public void setTaskInformation(final TaskInformation task) { } }); } - + /** * Appends the task information of the task and all subtasks to the styled document. - * + * * @param task * the task information to add * @param document @@ -131,14 +131,14 @@ public void setTaskInformation(final TaskInformation task) { * the current task depth (starts with 0, may be used to indent subtasks later) */ private void appendTaskInformation(final TaskInformation task, final StyledDocument document, final int depth) { - + // append title String title = task.getTaskTitle(); if (title == null || title.length() == 0) { title = "Unnamed Task"; } this.appendText(document, indentText(title, depth), this.taskTitle); - + // append task status switch (task.getTaskStatus()) { case SUCCESSFUL: @@ -151,13 +151,13 @@ private void appendTaskInformation(final TaskInformation task, final StyledDocum default: this.appendText(document, " (pending)\n", this.taskTitle); } - + // append description final String description = task.getTaskDescription(); if (description != null && description.length() > 0) { this.appendText(document, indentText(description + '\n', depth + 2), this.textStyle); } - + // handle subtasks final List childTasks = task.getChildTasks(); if (childTasks != null) { @@ -167,7 +167,7 @@ private void appendTaskInformation(final TaskInformation task, final StyledDocum } } } - + /** * Appends text to a styled document while silently dismissing {@link BadLocationException}. * @@ -185,7 +185,7 @@ private void appendText(final StyledDocument document, final String text, final e.printStackTrace(); } } - + /** * This function appends indentation spaces to a string * @@ -197,21 +197,21 @@ private void appendText(final StyledDocument document, final String text, final */ private static String indentText(final String text, final int depth) { if (depth == 0) return text; - + StringBuilder returnString = new StringBuilder(); String indention = "\u2003".repeat(depth); - + for (String s : text.split("\n")) { returnString.append(indention); returnString.append(s); returnString.append('\n'); } - + // Delete the final new line character if needed to prevent additional unwanted newlines in the result string if (!text.endsWith("\n")) { returnString.deleteCharAt(returnString.length() - 1); } - + return returnString.toString(); } } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java index a503e6f7a..b77ee3c9d 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -40,23 +40,23 @@ public class SwingTextureRegistry implements TextureRegistry { private final Map pathToHandle = new HashMap<>(); private final Set animatedTextures = new HashSet<>(); private final Map handleToTexture = new HashMap<>(); - + /** * Default constructor */ public SwingTextureRegistry() { StaticUiTextures.load(this); } - + /** * Generate a new unique texture handle. - * + * * @return uuid texture handle */ private static String generateNewTextureHandle() { return UUID.randomUUID().toString(); } - + /** * Load a texture from a local (ui module) resource. * @@ -68,7 +68,7 @@ private static String generateNewTextureHandle() { public String loadTextureFromResource(final String resourceName) { return this.loadTextureFromResource(resourceName, SwingTextureRegistry.class::getResourceAsStream); } - + @Override public String loadTextureFromResource(final String resourceName, final Function resourceProvider) { if (this.resourceToHandle.containsKey(resourceName)) return this.resourceToHandle.get(resourceName); @@ -82,7 +82,7 @@ public String loadTextureFromResource(final String resourceName, final Function< throw new TextureNotFoundException("The requested Resource could not be loaded!", e); } } - + @Override public String loadTextureFromFile(final String filePath) { final Path resolvedPath = Path.of(filePath).toAbsolutePath(); @@ -99,18 +99,18 @@ public String loadTextureFromFile(final String filePath) { } return textureHandle; } - + @Override public String createAnimatedTexture(final boolean loop) { final String textureHandle = SwingTextureRegistry.generateNewTextureHandle(); - + final AnimatedTexture animTexture = new AnimatedTexture(this, loop); this.handleToTexture.put(textureHandle, animTexture); this.animatedTextures.add(textureHandle); - + return textureHandle; } - + @Override public void addAnimationFrameToTexture(final String animatedTexture, final String frameTexture, final long frames) { try { @@ -120,12 +120,12 @@ public void addAnimationFrameToTexture(final String animatedTexture, final Strin throw new IllegalArgumentException("Texture handle was not a handle for an animated texture!", e); } } - + @Override public boolean isTextureAnimated(final String textureHandle) { return this.animatedTextures.contains(textureHandle); } - + /** * Get the texture for the given texture handle. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java index 1e531617e..453fd6bd8 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -39,32 +39,32 @@ */ public class SwingToolbar extends JToolBar implements Toolbar { private static final long serialVersionUID = -2525998620577603876L; - + /** The simulation proxy */ private SimulationProxy simulationProxy; /** The texture registry */ private final SwingTextureRegistry textureRegistry; - + /** The play button in the toolbar */ private JButton play; /** The step button in the toolbar */ private JButton step; /** The pause button in the toolbar */ private JButton pause; - + /** A slider to set the simulation time */ private JSlider simulationTime; - + /** The button to change to view mode */ private JToggleButton view; /** The button to change to add mode */ private JToggleButton add; /** The button to change to sub mode */ private JToggleButton sub; - + /** The selector which selects the entity for the user to place */ private DropdownSelector entitySelect; - + /** * The constructor of the toolbar *

@@ -80,12 +80,12 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi // class setup // this.textureRegistry = textureRegistry; - + // // toolbar setup // this.setFloatable(false); - + // // play button setup // @@ -97,7 +97,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.play.setEnabled(false); this.add(this.play); - + // // step button setup // @@ -109,7 +109,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.step.setEnabled(false); this.add(this.step); - + // // pause button setup // @@ -121,7 +121,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.pause.setEnabled(false); this.add(this.pause); - + // // simulation time slider setup // @@ -142,7 +142,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi // setup change listener this.simulationTime.addChangeListener(event -> { final JSlider source = (JSlider) event.getSource(); - + if (!source.getValueIsAdjusting()) { if (this.simulationProxy != null) { this.simulationProxy.simulationSpeedChange(source.getValue()); @@ -152,12 +152,12 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi this.simulationTime.setEnabled(false); this.add(this.simulationTime); this.addSeparator(); - + // // add visual separator // this.add(new JSeparator(SwingConstants.VERTICAL)); - + // // view button setup // @@ -169,7 +169,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.view.setEnabled(false); this.add(this.view); - + // // add button setup // @@ -181,7 +181,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.add.setEnabled(false); this.add(this.add); - + // // sub button setup // @@ -193,7 +193,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.sub.setEnabled(false); this.add(this.sub); - + // // entity selector setup // @@ -209,7 +209,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi this.entitySelect.setEnabled(false); this.add(this.entitySelect); } - + /** * * @param simulationProxy @@ -217,17 +217,17 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - + this.simulationProxy = simulationProxy; } - + @Override public void addEntity(final String displayName, final String textureID) { SwingUtilities.invokeLater(() -> { this.entitySelect.addEntry(this.entitySelect.new DropdownEntry(displayName, textureID)); }); } - + private void setControlButtonStateInternal(final ControlButtonState controlButtonState) { switch (controlButtonState) { case VIEW: @@ -235,34 +235,34 @@ private void setControlButtonStateInternal(final ControlButtonState controlButto this.add.setEnabled(true); this.sub.setEnabled(true); break; - + case ADD: this.view.setEnabled(true); this.add.setEnabled(false); this.sub.setEnabled(true); break; - + case SUB: this.view.setEnabled(true); this.add.setEnabled(true); this.sub.setEnabled(false); break; - + case BLOCKED: this.view.setEnabled(false); this.add.setEnabled(false); this.sub.setEnabled(false); break; - + default: } } - + @Override public void setControlButtonState(final ControlButtonState controlButtonState) { SwingUtilities.invokeLater(() -> this.setControlButtonStateInternal(controlButtonState)); } - + private void setClockButtonStateInternal(final ClockButtonState clockButtonState) { switch (clockButtonState) { case PLAYING: @@ -286,17 +286,17 @@ private void setClockButtonStateInternal(final ClockButtonState clockButtonState default: } } - + @Override public void setClockButtonState(final ClockButtonState clockButtonState) { SwingUtilities.invokeLater(() -> this.setClockButtonStateInternal(clockButtonState)); } - + @Override public int getSpeedSliderPosition() { return this.simulationTime.getValue(); } - + @Override public void setSpeedSliderPosition(final int position) { if ( @@ -306,28 +306,28 @@ public void setSpeedSliderPosition(final int position) { ); SwingUtilities.invokeLater(() -> this.simulationTime.setValue(position)); } - + @Override public String getCurrentlySelectedEntity() { final DropdownEntry currentEntry = this.entitySelect.getCurrentEntry(); if (currentEntry == null) return ""; return currentEntry.displayName; } - + @Override public void setCurrentlySelectedEntity(final String entity) { SwingUtilities.invokeLater(() -> { this.entitySelect.setCurrentEntry(this.entitySelect.new DropdownEntry(entity)); }); } - + @Override public void enableEntitySelector() { SwingUtilities.invokeLater(() -> { this.entitySelect.setEnabled(true); }); } - + @Override public void disableEntitySelector() { SwingUtilities.invokeLater(() -> { @@ -335,5 +335,5 @@ public void disableEntitySelector() { this.entitySelect.setEnabled(false); }); } - + } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java index 36a0c3083..73e5cc517 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,34 +15,34 @@ /** * Class containing a texture image and methods to draw this image. - * + * * @author Fabian Bühler */ public interface Texture { - + /** * Get the texture image. - * + * * @return the image */ default Image getTexture() { return this.getTexture(0); } - + /** * Get the texture image. - * + * * @param frame * the current frame number * @return the image */ Image getTexture(long frame); - + /** * Draw the texture onto the screen. *

* This method should only be called from the swing ui thread. - * + * * @param frame * the current frame number * @param g @@ -57,12 +57,12 @@ default Image getTexture() { default void drawTexture(final long frame, final Graphics g, final int x, final int y, final int size) { this.drawTexture(frame, g, x, y, size, size); } - + /** * Draw the texture onto the screen. *

* This method should only be called from the swing ui thread. - * + * * @param frame * the current frame number * @param g diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java index 361a68762..93cc766c2 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -32,14 +32,14 @@ * @version 1.0 */ class DropdownItemEditor extends BasicComboBoxEditor { - + /** The texture registry */ private final SwingTextureRegistry textureRegistry; - + private final JPanel panel; private final JLabel labelItem; private DropdownEntry selectedValue; - + /** * Constructor for the DropdownItemEditor *

@@ -50,7 +50,7 @@ class DropdownItemEditor extends BasicComboBoxEditor { */ public DropdownItemEditor(final SwingTextureRegistry textureRegistry) { this.textureRegistry = textureRegistry; - + this.panel = new JPanel(); this.panel.setBackground(Color.BLUE); this.panel.setLayout(new GridBagLayout()); @@ -58,32 +58,32 @@ public DropdownItemEditor(final SwingTextureRegistry textureRegistry) { constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; constraints.insets = new Insets(2, 5, 2, 2); - + this.labelItem = new JLabel(); this.labelItem.setOpaque(false); this.labelItem.setHorizontalAlignment(SwingConstants.LEFT); this.labelItem.setForeground(Color.WHITE); - + this.panel.add(this.labelItem, constraints); } - + @Override public Component getEditorComponent() { return this.panel; } - + @Override public Object getItem() { return this.selectedValue; } - + @Override public void setItem(final Object item) { if (item == null) return; - + this.selectedValue = (DropdownEntry) item; this.labelItem.setText(this.selectedValue.displayName); - + if (!this.selectedValue.textureID.equals("")) { this.labelItem.setIcon(new ImageIcon(this.textureRegistry.getTextureForHandle(this.selectedValue.textureID).getTexture())); } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java index d289f5b08..2a085d0a5 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -34,12 +34,12 @@ */ class DropdownItemRenderer extends JPanel implements ListCellRenderer { private static final long serialVersionUID = 2930839533138981414L; - + /** The texture registry */ private final SwingTextureRegistry textureRegistry; - + private final JLabel labelItem; - + /** * Constructor for the DropdownItemRenderer *

@@ -50,21 +50,21 @@ class DropdownItemRenderer extends JPanel implements ListCellRenderer list, final DropdownEntry value, final int index, final boolean isSelected, @@ -74,12 +74,12 @@ public Component getListCellRendererComponent( this.labelItem.setText("∅"); } else { this.labelItem.setText(value.displayName); - + if (!value.textureID.equals("")) { this.labelItem.setIcon(new ImageIcon(this.textureRegistry.getTextureForHandle(value.textureID).getTexture())); } } - + return this; } } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownSelector.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownSelector.java index 6a2183e3f..1d1f49312 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownSelector.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownSelector.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -28,7 +28,7 @@ */ public class DropdownSelector extends JPanel { private static final long serialVersionUID = -3898035206502504991L; - + /** * This class represents a single entry of the selector * @@ -40,7 +40,7 @@ public class DropdownEntry { public String displayName; /** The texture id of the icon which is rendert infront of the display name */ public String textureID; - + /** * The empty constructor */ @@ -48,7 +48,7 @@ public DropdownEntry() { this.displayName = ""; this.textureID = ""; } - + /** * This constructor is used for text only entries * @@ -59,7 +59,7 @@ public DropdownEntry(final String name) { this.displayName = name; this.textureID = ""; } - + /** * The default constructor * @@ -73,16 +73,16 @@ public DropdownEntry(final String name, final String texture) { this.textureID = texture; } } - + /** The texture registry */ private final SwingTextureRegistry textureRegistry; - + private final JLabel label; private final JComboBox comboBox; - + /** The data model of the DropdownSelector */ private final DefaultComboBoxModel model; - + /** * Constructor of the DropdownSelector *

@@ -95,20 +95,20 @@ public DropdownEntry(final String name, final String texture) { */ public DropdownSelector(final SwingTextureRegistry textureRegistry, final String header) { this.textureRegistry = textureRegistry; - + this.label = new JLabel(header + ": "); this.comboBox = new JComboBox<>(); - + this.model = new DefaultComboBoxModel<>(); this.comboBox.setModel(this.model); this.comboBox.setRenderer(new DropdownItemRenderer(this.textureRegistry)); this.comboBox.setEditor(new DropdownItemEditor(this.textureRegistry)); - + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(this.label); this.add(this.comboBox); } - + /** * Getter for the currently selected entry * @@ -117,21 +117,21 @@ public DropdownSelector(final SwingTextureRegistry textureRegistry, final String public DropdownEntry getCurrentEntry() { return (DropdownEntry) this.comboBox.getEditor().getItem(); } - + /** * Setter for the currently selected entry *

* This should only be called from the swing ui thread *

* WARNING: This is not checked if it is available it can be ANY entry - * + * * @param entry * The entry to set as selected */ public void setCurrentEntry(final DropdownEntry entry) { this.comboBox.getEditor().setItem(entry); } - + /** * This function adds an entry to the selector *

@@ -143,13 +143,13 @@ public void setCurrentEntry(final DropdownEntry entry) { public void addEntry(final DropdownEntry... entries) { for (final DropdownEntry entry : entries) { this.model.addElement(entry); - + if (getCurrentEntry() == null) { this.setCurrentEntry(entry); } } } - + /** * This function removes all entries from the dropdown menu *

@@ -158,19 +158,19 @@ public void addEntry(final DropdownEntry... entries) { public void removeAllEntries() { this.model.removeAllElements(); } - + /** * Adds a listener which reacts to the selection and deselection of items *

* This should only be called from the swing ui thread - * + * * @param listener * The listener which is added */ public void addSelectionListener(final ItemListener listener) { this.comboBox.addItemListener(listener); } - + @Override public void setEnabled(final boolean enabled) { super.setEnabled(enabled); diff --git a/ICGE-Ui/src/main/java/module-info.java b/ICGE-Ui/src/main/java/module-info.java index 40ec1025d..2c89b3efa 100644 --- a/ICGE-Ui/src/main/java/module-info.java +++ b/ICGE-Ui/src/main/java/module-info.java @@ -1,16 +1,16 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ module de.unistuttgart.informatik.fius.icge.ui { requires java.desktop; requires de.unistuttgart.informatik.fius.icge.log; - + exports de.unistuttgart.informatik.fius.icge.ui; exports de.unistuttgart.informatik.fius.icge.ui.exception; } diff --git a/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java b/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java index 015a8ffc6..336a8e855 100644 --- a/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java +++ b/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -33,12 +33,12 @@ * @author Tim Neumann */ class SwingGameWindowUiTest { - + private SwingGameWindow window; - + /** * Setup the game window - * + * * @throws Exception * When anything goes wrong */ @@ -51,11 +51,11 @@ public void setup() throws Exception { final SwingEntitySidebar entitySidebar = new SwingEntitySidebar(textureRegistry, 1); final SwingConsole console = new SwingConsole(1); final SwingTaskStatusDisplay taskStatus = new SwingTaskStatusDisplay(1); - + this.window = new SwingGameWindow(textureRegistry, playfieldDrawer, toolbar, entitySidebar, console, taskStatus); }); } - + /** * Test {@link SwingGameWindow#start()} */ From 1c32ac4bc8dc8e4c61d3125460299870c345e39e Mon Sep 17 00:00:00 2001 From: graefjk Date: Thu, 4 Jan 2024 02:30:12 +0100 Subject: [PATCH 4/6] formatting --- .../informatik/fius/icge/log/Logger.java | 28 +-- .../fius/icge/log/OutputStreamMultiplier.java | 22 ++- .../fius/icge/manualstart/Coin.java | 10 +- .../manualstart/ManualStartSimulation.java | 16 +- .../fius/icge/manualstart/ManualStartUi.java | 8 +- .../fius/icge/manualstart/TestEntity.java | 10 +- .../fius/icge/manualstart/TestTask.java | 14 +- .../icge/manualstart/TestTaskVerifier.java | 96 ++++----- .../fius/icge/simulation/Direction.java | 3 +- .../fius/icge/simulation/MultiTypedList.java | 34 ++-- .../fius/icge/simulation/Playfield.java | 29 +-- .../fius/icge/simulation/Position.java | 18 +- .../fius/icge/simulation/Simulation.java | 24 +-- .../icge/simulation/SimulationBuilder.java | 27 +-- .../fius/icge/simulation/SimulationClock.java | 36 ++-- .../fius/icge/simulation/TaskVerifier.java | 8 +- .../fius/icge/simulation/actions/Action.java | 11 +- .../icge/simulation/actions/ActionLog.java | 21 +- .../icge/simulation/actions/EntityAction.java | 10 +- .../actions/EntityCollectAction.java | 18 +- .../actions/EntityDespawnAction.java | 12 +- .../simulation/actions/EntityDropAction.java | 18 +- .../simulation/actions/EntityMoveAction.java | 12 +- .../simulation/actions/EntitySpawnAction.java | 14 +- .../simulation/actions/EntityStepAction.java | 8 +- .../actions/EntityTeleportAction.java | 6 +- .../simulation/actions/EntityTurnAction.java | 14 +- .../icge/simulation/entity/BasicEntity.java | 35 ++-- .../simulation/entity/CollectableEntity.java | 2 +- .../fius/icge/simulation/entity/Entity.java | 10 +- .../simulation/entity/EntityCollector.java | 12 +- .../simulation/entity/EntityTypeRegistry.java | 17 +- .../icge/simulation/entity/GreedyEntity.java | 41 ++-- .../icge/simulation/entity/Inventory.java | 6 +- .../icge/simulation/entity/MovableEntity.java | 57 +++--- .../icge/simulation/entity/SolidEntity.java | 3 +- .../simulation/entity/UntilableDrawable.java | 8 +- .../CannotCollectEntityException.java | 11 +- .../exception/CannotDropEntityException.java | 11 +- .../exception/CannotRunProgramException.java | 11 +- .../exception/ElementExistsException.java | 7 +- .../EntityAlreadyOnFieldExcpetion.java | 7 +- .../exception/EntityNotOnFieldException.java | 7 +- .../EntityOnAnotherFieldException.java | 9 +- .../exception/IllegalMoveException.java | 7 +- .../exception/SimulationExcpetion.java | 11 +- .../exception/TimerAlreadyRunning.java | 6 +- .../UncheckedInterruptedException.java | 11 +- .../inspection/AnnotationReader.java | 16 +- .../simulation/inspection/ClassFinder.java | 22 ++- .../inspection/InspectionAttribute.java | 9 +- .../simulation/inspection/InspectionData.java | 115 +++++------ .../inspection/InspectionManager.java | 32 +-- .../inspection/InspectionMethod.java | 8 +- .../internal/StandardSimulation.java | 43 ++-- .../internal/StandardSimulationClock.java | 96 +++++---- .../internal/StandardSimulationProxy.java | 111 +++++------ .../internal/actions/StandardActionLog.java | 29 +-- .../entity/StandardEntityTypeRegistry.java | 30 +-- .../internal/playfield/PlayfieldCell.java | 8 +- .../internal/playfield/StandardPlayfield.java | 140 +++++++------ .../programs/StandardProgramRunner.java | 28 +-- .../internal/tasks/StandardTaskRunner.java | 29 ++- .../icge/simulation/programs/Program.java | 6 +- .../fius/icge/simulation/tasks/Task.java | 6 +- .../simulation/tools/PlayfieldModifier.java | 13 +- .../src/main/java/module-info.java | 2 +- .../fius/icge/ui/AnimatedDrawable.java | 41 ++-- .../fius/icge/ui/BasicDrawable.java | 19 +- .../informatik/fius/icge/ui/Console.java | 3 +- .../informatik/fius/icge/ui/Drawable.java | 17 +- .../fius/icge/ui/EntityInspectorEntry.java | 22 ++- .../fius/icge/ui/EntitySidebar.java | 23 +-- .../informatik/fius/icge/ui/GameWindow.java | 19 +- .../fius/icge/ui/PlayfieldDrawer.java | 21 +- .../fius/icge/ui/SimulationProxy.java | 33 ++-- .../fius/icge/ui/SimulationTreeNode.java | 56 +++--- .../fius/icge/ui/TaskInformation.java | 12 +- .../fius/icge/ui/TaskStatusDisplay.java | 3 +- .../fius/icge/ui/TaskVerificationStatus.java | 2 +- .../fius/icge/ui/TextureRegistry.java | 17 +- .../informatik/fius/icge/ui/Toolbar.java | 26 +-- .../fius/icge/ui/WindowBuilder.java | 51 +++-- .../icge/ui/exception/LeafNodeException.java | 3 +- .../ui/exception/ListenerSetException.java | 3 +- .../exception/TextureNotFoundException.java | 7 +- .../icge/ui/internal/AnimatedTexture.java | 24 +-- .../internal/ConsoleBufferedOutputStream.java | 48 +++-- .../fius/icge/ui/internal/OutputStyle.java | 5 +- .../fius/icge/ui/internal/StaticTexture.java | 12 +- .../icge/ui/internal/StaticUiTextures.java | 23 +-- .../fius/icge/ui/internal/SwingConsole.java | 25 ++- .../ui/internal/SwingEntityInspector.java | 95 +++++---- .../icge/ui/internal/SwingEntitySidebar.java | 90 +++++---- .../icge/ui/internal/SwingGameWindow.java | 58 +++--- .../ui/internal/SwingPlayfieldDrawer.java | 186 ++++++++---------- .../ui/internal/SwingTaskStatusDisplay.java | 71 ++++--- .../ui/internal/SwingTextureRegistry.java | 38 ++-- .../fius/icge/ui/internal/SwingToolbar.java | 94 +++++---- .../fius/icge/ui/internal/Texture.java | 12 +- .../internal/dropdown/DropdownItemEditor.java | 37 ++-- .../dropdown/DropdownItemRenderer.java | 30 ++- .../internal/dropdown/DropdownSelector.java | 48 +++-- ICGE-Ui/src/main/java/module-info.java | 2 +- .../fius/icge/ui/SwingGameWindowUiTest.java | 19 +- .../src/main/java/module-info.java | 4 +- .../fius/icge/example/mario/Main.java | 6 +- .../fius/icge/example/mario/Texture.java | 4 +- .../icge/example/mario/WalkingProgram.java | 6 +- .../fius/icge/example/mario/entity/Coin.java | 6 +- .../fius/icge/example/mario/entity/Mario.java | 6 +- .../example/mario/entity/MarioProgram.java | 6 +- .../fius/icge/example/mario/entity/Wall.java | 6 +- .../icge/example/mario/tasks/Solution1.java | 6 +- .../icge/example/mario/tasks/Solution2.java | 6 +- .../fius/icge/example/mario/tasks/Task1.java | 6 +- .../fius/icge/example/mario/tasks/Task2.java | 6 +- examples/mario/src/main/java/module-info.java | 4 +- scriptsAndTools/#correctJavaFileComment.txt# | 9 + scriptsAndTools/Unbenanntes Dokument | 27 +++ scriptsAndTools/correctJavaFileComment.txt | 4 +- 121 files changed, 1525 insertions(+), 1441 deletions(-) create mode 100644 scriptsAndTools/#correctJavaFileComment.txt# create mode 100644 scriptsAndTools/Unbenanntes Dokument diff --git a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java index d9377281d..388697dd9 100644 --- a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java +++ b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.log; +* + import java.io.OutputStream; -import java.io.PrintStream; +import java.io.PrintStream;** /** @@ -23,27 +25,25 @@ * @version 2.0 */ public abstract class Logger { - + * /** The main logger printing to {@link System#out} */ - public static PrintStream out; + public static PrintStream out; /** The error logger printing to {@link System#err} */ - public static PrintStream error; - + public static PrintStream error;* private static OutputStreamMultiplier outStream; - private static OutputStreamMultiplier errorStream; - + private static OutputStreamMultiplier errorStream;* // This block intercepts {@link System.out} and {@link System.err} static { Logger.outStream = new OutputStreamMultiplier(); Logger.outStream.addOutputStream(System.out); Logger.out = new PrintStream(Logger.outStream); System.setOut(Logger.out); - + * Logger.errorStream = new OutputStreamMultiplier(); Logger.errorStream.addOutputStream(System.err); Logger.error = new PrintStream(Logger.errorStream); System.setErr(Logger.error); - } + }* /** * Function to add a {@link OutputStream} to the out logger @@ -55,7 +55,7 @@ public abstract class Logger { */ public static boolean addOutOutputStream(final OutputStream stream) { return Logger.outStream.addOutputStream(stream); - } + }* /** * Function to remove a {@link OutputStream} from the out logger @@ -67,7 +67,7 @@ public static boolean addOutOutputStream(final OutputStream stream) { */ public static boolean removeOutOutputStream(final OutputStream stream) { return Logger.outStream.removeOutputStream(stream); - } + }* /** * Clears the out OutputStreams @@ -76,7 +76,7 @@ public static boolean removeOutOutputStream(final OutputStream stream) { */ public static void clearOutOutputStream() { Logger.outStream.clearOutputStreams(); - } + }* /** * Function to add a {@link OutputStream} to the error logger @@ -88,7 +88,7 @@ public static void clearOutOutputStream() { */ public static boolean addErrorOutputStream(final OutputStream stream) { return Logger.errorStream.addOutputStream(stream); - } + }* /** * Function to remove a {@link OutputStream} from the error logger @@ -100,7 +100,7 @@ public static boolean addErrorOutputStream(final OutputStream stream) { */ public static boolean removeErrorOutputStream(final OutputStream stream) { return Logger.errorStream.removeOutputStream(stream); - } + }* /** * Clears the error OutputStreams diff --git a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java index c7c7dc155..678bf3efa 100644 --- a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java +++ b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java @@ -9,9 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.log; +* + import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; +import java.util.ArrayList;** /** @@ -21,15 +23,15 @@ * @version 1.0 */ public class OutputStreamMultiplier extends OutputStream { - - private final ArrayList listenerStreams; + * + private final ArrayList listenerStreams;* /** * Default Constructor */ public OutputStreamMultiplier() { this.listenerStreams = new ArrayList<>(); - } + }* /** * Add a output stream to also recieve everything this stream recieves @@ -40,7 +42,7 @@ public OutputStreamMultiplier() { */ public boolean addOutputStream(final OutputStream listenerStream) { return this.listenerStreams.add(listenerStream); - } + }* /** * Remove a output stream from recieving everything this stream recieves @@ -51,30 +53,30 @@ public boolean addOutputStream(final OutputStream listenerStream) { */ public boolean removeOutputStream(final OutputStream listenerStream) { return this.listenerStreams.remove(listenerStream); - } + }* /** * Clears all connected output streams */ public void clearOutputStreams() { this.listenerStreams.clear(); - } + }* @Override public void flush() throws IOException { super.flush(); - + * for (final OutputStream listenerStream : this.listenerStreams) { listenerStream.flush(); } - } + }* @Override public void write(final int arg0) throws IOException { for (final OutputStream listenerStream : this.listenerStreams) { listenerStream.write(arg0); } - } + }* @Override public void close() throws IOException { diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java index 6c6950e44..20db316a7 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; +* + import de.unistuttgart.informatik.fius.icge.simulation.entity.BasicEntity; -import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity;** /** @@ -19,17 +21,17 @@ * @author Fabian Bühler */ public class Coin extends BasicEntity implements CollectableEntity { - + * /** * The texture handle used for the test entity. */ public static String TEXTURE_HANDLE; - + * @Override protected String getTextureHandle() { return TEXTURE_HANDLE; } - + * @Override protected int getZPosition() { return 0; diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java index 80d9f4d37..e960d55b4 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java @@ -9,11 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; +* + import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.SimulationBuilder; import de.unistuttgart.informatik.fius.icge.ui.GameWindow; import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.WindowBuilder; +import de.unistuttgart.informatik.fius.icge.ui.WindowBuilder;** /** @@ -22,10 +24,10 @@ * @author Tim Neumann */ public class ManualStartSimulation { - + * private static String textureHandleWall; private static String textureHandleCoin; - private static String animated; + private static String animated;* /** * @param args @@ -38,20 +40,20 @@ public static void main(final String[] args) { // wb.setDpiScale(1.0); wb.buildWindow(); final GameWindow w = wb.getBuiltWindow(); - + * ManualStartSimulation.prepareTextures(w.getTextureRegistry()); TestEntity.TEXTURE_HANDLE = ManualStartSimulation.animated; Coin.TEXTURE_HANDLE = textureHandleCoin; - + * final SimulationBuilder sb = new SimulationBuilder(); sb.setTaskVerifier(new TestTaskVerifier()); sb.buildSimulation(); final Simulation sim = sb.getBuiltSimulation(); - + * w.start(); sim.attachToWindow(w, true); sim.runTask(new TestTask()); - } + }* private static void prepareTextures(final TextureRegistry tr) { ManualStartSimulation.textureHandleWall = tr diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java index 4510360bc..c891b53e1 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; +* + import de.unistuttgart.informatik.fius.icge.ui.GameWindow; -import de.unistuttgart.informatik.fius.icge.ui.WindowBuilder; +import de.unistuttgart.informatik.fius.icge.ui.WindowBuilder;** /** @@ -19,7 +21,7 @@ * @author Tim Neumann */ public class ManualStartUi { - + * /** * Main entry point of the program * @@ -29,7 +31,7 @@ public class ManualStartUi { public static void main(final String[] args) { ManualStartUi.newStyleBuilder(); } - + * private static void newStyleBuilder() { final WindowBuilder wb = new WindowBuilder(); wb.setTitle("Window Builder start!"); diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java index b5b2ca9c1..9815ab830 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java @@ -9,24 +9,26 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; -import de.unistuttgart.informatik.fius.icge.simulation.entity.GreedyEntity; +* + +import de.unistuttgart.informatik.fius.icge.simulation.entity.GreedyEntity;** /** * Basic test entity. */ public class TestEntity extends GreedyEntity { - + * /** * The texture handle used for the test entity. */ public static String TEXTURE_HANDLE; - + * @Override protected String getTextureHandle() { return TestEntity.TEXTURE_HANDLE; } - + * @Override protected int getZPosition() { return 0; diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java index 458034ed5..2e639997c 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java @@ -9,27 +9,29 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; +* + import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity; import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; -import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; +import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task;** /** * Test task for manual start. */ public class TestTask implements Task { - + * @Override public void run(final Simulation sim) { final TestEntity tE = new TestEntity(); - + * sim.getPlayfield().addEntity(new Position(3, 4), tE); - + * CollectableEntity coin = new Coin(); sim.getPlayfield().addEntity(new Position(3, 4), coin); - + * while (true) { tE.collect(coin); tE.drop(coin); @@ -44,7 +46,7 @@ public void run(final Simulation sim) { break; } } - + * sim.runProgram(new Program() { @Override public void run(TestEntity entity) { diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java index 52704a591..c5a54d7d8 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java @@ -9,16 +9,17 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; +* + import java.util.ArrayList; import java.util.Collections; -import java.util.List; - +import java.util.List;* import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier; import de.unistuttgart.informatik.fius.icge.simulation.actions.ActionLog; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityMoveAction; import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; -import de.unistuttgart.informatik.fius.icge.ui.TaskVerificationStatus; +import de.unistuttgart.informatik.fius.icge.ui.TaskVerificationStatus;** /** @@ -30,18 +31,18 @@ * @author Fabian Bühler */ public class TestTaskVerifier implements TaskVerifier, TaskInformation { - + * private ActionLog log; private TaskVerificationStatus taskIsValid = TaskVerificationStatus.UNDECIDED; private int minStepsToWalk = 4; private int maxStepsToWalk = 14; - private int stepsWalked = 0; + private int stepsWalked = 0;* @Override public void attachToSimulation(Simulation sim) { // get the log to verify if the required events did happen later this.log = sim.getActionLog(); - } + }* @Override public void verify() { @@ -50,32 +51,32 @@ public void verify() { } // check the number of steps/moves all entity have taken together this.stepsWalked = this.log.getActionsOfType(EntityMoveAction.class, true).size(); - + * // as long as task is still achievable use UNDECIDED status if (this.stepsWalked < this.minStepsToWalk) { this.taskIsValid = TaskVerificationStatus.UNDECIDED; return; } - + * // if task is failed irreversibly use FAILED status if (this.stepsWalked > this.maxStepsToWalk) { this.taskIsValid = TaskVerificationStatus.FAILED; return; } - + * // use SUCCESSFUL status if task is solved correctly this.taskIsValid = TaskVerificationStatus.SUCCESSFUL; - } + }* @Override public TaskInformation getTaskInformation() { return this; - } + }* @Override public String getTaskTitle() { return "Test Task"; - } + }* @Override public String getTaskDescription() { @@ -87,158 +88,157 @@ public String getTaskDescription() { description += " (1 step walked)"; } return description; - } + }* @Override public TaskVerificationStatus getTaskStatus() { return this.taskIsValid; - } + }* @Override public List getChildTasks() { ArrayList subTasks = new ArrayList<>(); - + * subTasks.add(new TaskInformation() { - + * @Override public String getTaskTitle() { return "a) Successful sub task"; } - + * @Override public String getTaskDescription() { return "Super basic sample description"; } - + * @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.SUCCESSFUL; } - + * @Override public List getChildTasks() { return Collections.emptyList(); } }); - + * subTasks.add(new TaskInformation() { - + * @Override public String getTaskTitle() { return "b) undecided sub task"; } - + * @Override public String getTaskDescription() { return "Super basic sample description"; } - + * @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.UNDECIDED; } - + * @Override public List getChildTasks() { ArrayList subTasks = new ArrayList<>(); - + * subTasks.add(new TaskInformation() { - + * @Override public String getTaskTitle() { return "b.1) Successful sub sub task"; } - + * @Override public String getTaskDescription() { return "Super basic sample description"; } - + * @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.SUCCESSFUL; } - + * @Override public List getChildTasks() { return Collections.emptyList(); } }); - + * subTasks.add(new TaskInformation() { - + * @Override public String getTaskTitle() { return "b.2) undecided sub sub task"; } - + * @Override public String getTaskDescription() { return "Super basic sample description"; } - + * @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.UNDECIDED; } - + * @Override public List getChildTasks() { return Collections.emptyList(); } }); - + * subTasks.add(new TaskInformation() { - + * @Override public String getTaskTitle() { return "b.3) failed sub sub task"; } - + * @Override public String getTaskDescription() { return "Super basic sample description"; } - + * @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.FAILED; } - + * @Override public List getChildTasks() { return Collections.emptyList(); } }); - + * return subTasks; } }); - + * subTasks.add(new TaskInformation() { - + * @Override public String getTaskTitle() { return "c) failed sub task"; } - + * @Override public String getTaskDescription() { return "Super basic sample description"; } - + * @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.FAILED; } - + * @Override public List getChildTasks() { return Collections.emptyList(); } }); - + * return subTasks; - } - + }* } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java index 10d657617..1b885b5f0 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; +* /** * The four fundamental directions possible in the simulation. *

@@ -37,7 +38,7 @@ public enum Direction { SOUTH, /** The west direction; at the left of the screen ({@link Position#getX()} getting smaller) */ WEST; - + * /** * Get the direction that is next in a clock wise rotation * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java index d79aff19f..d0612c43b 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java @@ -9,11 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; +* + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Optional; -import java.util.Set; +import java.util.Set;** /** @@ -24,8 +26,8 @@ * The parent type of all types contained in this list. */ public class MultiTypedList

{ - - private final HashMap, List

> items = new HashMap<>(); + * + private final HashMap, List

> items = new HashMap<>();* /** * Get the relevant list for the given type. @@ -42,7 +44,7 @@ private Optional> getRelevantListGeneric(final Class) list; return Optional.ofNullable(listOfCorrectType); - } + }* private Class getClass(final P o) { //Actually a cast should not be necessary here. @@ -50,7 +52,7 @@ private Class getClass(final P o) { @SuppressWarnings("unchecked") final var type = (Class) o.getClass(); return type; - } + }* /** * Get the relevant list for the given object. @@ -61,7 +63,7 @@ private Class getClass(final P o) { */ private Optional> getRelevantList(final P o) { return this.getRelevantListGeneric(this.getClass(o)); - } + }* /** * Get the relevant list for the given entity and create it if it is not there. @@ -73,11 +75,11 @@ private Optional> getRelevantList(final P o) { private List

getRelevantListAndCreate(final P o) { final var type = this.getClass(o); if (this.items.containsKey(type)) return this.items.get(type); - + * final List

list = new ArrayList<>(); this.items.put(type, list); return list; - } + }* /** * Add the given object to this list. @@ -87,7 +89,7 @@ private List

getRelevantListAndCreate(final P o) { */ public synchronized void add(final P o) { this.getRelevantListAndCreate(o).add(o); - } + }* /** * Check whether this list contains the given object. @@ -100,7 +102,7 @@ public synchronized boolean contains(final P o) { final var opt = this.getRelevantList(o); if (opt.isEmpty()) return false; return opt.get().contains(o); - } + }* /** * Return {@code true} iff the list contains no objects. @@ -109,7 +111,7 @@ public synchronized boolean contains(final P o) { */ public synchronized boolean isEmpty() { return this.items.isEmpty(); - } + }* /** * Remove the given object from this list. @@ -122,7 +124,7 @@ public synchronized boolean remove(final P o) { final var opt = this.getRelevantList(o); if (opt.isEmpty()) return false; return opt.get().remove(o); - } + }* /** * Get all objects in this list of the given type. @@ -137,9 +139,9 @@ public synchronized boolean remove(final P o) { */ public synchronized List get(final Class type, final boolean includeSubclasses) { if (!includeSubclasses) return this.getRelevantListGeneric(type).orElse(List.of()); - + * final List result = new ArrayList<>(); - + * for (final Class storedType : this.items.keySet()) { if (type.isAssignableFrom(storedType)) { final Class storedTypeAsSubOfRequested = storedType.asSubclass(type); @@ -147,9 +149,9 @@ public synchronized List get(final Class type, fin result.addAll(listForStoredType); } } - + * return result; - } + }* /** * @return a list of stored types. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java index 78f3f8279..4928b4460 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java @@ -9,14 +9,15 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -import java.util.List; +* +import java.util.List;* import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityMoveAction; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityTeleportAction; import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityAlreadyOnFieldExcpetion; import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityNotOnFieldException; -import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityOnAnotherFieldException; +import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityOnAnotherFieldException;** /** @@ -25,19 +26,19 @@ * @author Tim Neumann */ public interface Playfield { - + * /** * @return the simulation this playfield is part of */ Simulation getSimulation(); - + * /** * Get a list of all entities on this playfield. * * @return A list of all entities */ List getAllEntities(); - + * /** * Get a list of all entities matching the given type on this playfield. * @@ -52,7 +53,7 @@ public interface Playfield { * if the given type is null */ List getAllEntitiesOfType(Class type, boolean includeSubclasses); - + * /** * Get a list of all entities at the given position on this playfield. * @@ -63,7 +64,7 @@ public interface Playfield { * if the given pos is null */ List getEntitiesAt(final Position pos); - + * /** * Get a list of all entities matching the given type at the given position on this playfield. * @@ -80,7 +81,7 @@ public interface Playfield { * if the given pos or type is null */ List getEntitiesOfTypeAt(final Position pos, Class type, boolean includeSubclasses); - + * /** * Add a given entity to this simulation at a given position on this playfield. * @@ -97,7 +98,7 @@ public interface Playfield { * if the given pos or entity is null */ void addEntity(Position pos, Entity entity); - + * /** * Move a entity of this simulation to a given position on this playfield. *

@@ -114,7 +115,7 @@ public interface Playfield { * if the given pos or entity is null */ void moveEntity(Entity entity, Position pos); - + * /** * Move a entity of this simulation to a given position on this playfield. * @@ -132,7 +133,7 @@ public interface Playfield { * if the given action match with the other arguments */ void moveEntity(Entity entity, Position pos, EntityMoveAction action); - + * /** * Remove a entity of this simulation from this playfield. * @@ -144,7 +145,7 @@ public interface Playfield { * if the given entity is null */ void removeEntity(Entity entity); - + * /** * Get the position of the specified entity on the playfield. * @@ -157,7 +158,7 @@ public interface Playfield { * if the given entity is null */ Position getEntityPosition(Entity entity); - + * /** * Check whether the specified entity is on this playfield. * @@ -168,7 +169,7 @@ public interface Playfield { * if the given entity is null */ boolean containsEntity(Entity entity); - + * /** * Check whether a solid entity is at the given position. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java index 56f61ac3f..63cfde44d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java @@ -9,7 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -import java.util.Arrays; +* + +import java.util.Arrays;** /** @@ -34,7 +36,7 @@ public class Position { private final int x; private final int y; - + * /** * Create a new position from the given parameters. * @@ -47,21 +49,21 @@ public Position(final int x, final int y) { this.x = x; this.y = y; } - + * /** * @return the x coordinate of this position */ public int getX() { return this.x; } - + * /** * @return the y coordinate of this position */ public int getY() { return this.y; } - + * /** * Get the adjacent position in the given direction. * @@ -83,20 +85,20 @@ public Position adjacentPosition(final Direction direction) { throw new IllegalArgumentException("Unknown direction"); } } - + * @Override public boolean equals(final Object o) { if (!(o instanceof Position)) return false; final Position p = (Position) o; return (this.x == p.getX()) && (this.y == p.getY()); } - + * @Override public int hashCode() { final int[] numbers = { this.x, this.y }; return Arrays.hashCode(numbers); } - + * @Override public String toString() { return "(x=" + this.x + ", y=" + this.y + ")"; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java index 9c6828f9c..527ac721e 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java @@ -9,13 +9,15 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; +* + import de.unistuttgart.informatik.fius.icge.simulation.actions.ActionLog; import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; import de.unistuttgart.informatik.fius.icge.simulation.entity.EntityTypeRegistry; import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; import de.unistuttgart.informatik.fius.icge.ui.GameWindow; -import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; +import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy;** /** @@ -30,42 +32,42 @@ public interface Simulation { * @return The playfield used by this simulation */ Playfield getPlayfield(); - + * /** * Get the task verifier set for this simulation. * * @return The task verifier set for this simulation */ TaskVerifier getTaskVerifier(); - + * /** * Get the simulation clock for this simulation. * * @return the simulation clock used by this simulation */ SimulationClock getSimulationClock(); - + * /** * Get the entity type registry associated with the simulation host. * * @return The entity type registry */ EntityTypeRegistry getEntityTypeRegistry(); - + * /** * Get the action log for this simulation. * * @return the action log used by this siumulation */ ActionLog getActionLog(); - + * /** * Get the simulation proxy used by the game window to communicate with the simulation. * * @return The simulation proxy for the UI to use */ SimulationProxy getSimulationProxyForWindow(); - + * /** * Attach this simulation to the given window. * @@ -73,7 +75,7 @@ public interface Simulation { * The window to attach to */ void attachToWindow(GameWindow window); - + * /** * Attach this simulation to the given window. * @@ -83,14 +85,14 @@ public interface Simulation { * If {@code true} the simulation will stop when the attached window is closed */ void attachToWindow(GameWindow window, boolean stopWithWindowClose); - + * /** * Irreversibly stop the simulation and all running background tasks and programs. * * Calling this method twice will not throw an exception. */ void stop(); - + * /** * Run the given task in the background. * @@ -100,7 +102,7 @@ public interface Simulation { * The task to run */ void runTask(Task taskToRun); - + * /** * Run the given program for the given Entity in the background. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java index f5fbdf2f2..2b22b2a98 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java @@ -9,12 +9,14 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; +* + import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionManager; import de.unistuttgart.informatik.fius.icge.simulation.internal.StandardSimulation; import de.unistuttgart.informatik.fius.icge.simulation.internal.StandardSimulationClock; import de.unistuttgart.informatik.fius.icge.simulation.internal.actions.StandardActionLog; import de.unistuttgart.informatik.fius.icge.simulation.internal.entity.StandardEntityTypeRegistry; -import de.unistuttgart.informatik.fius.icge.simulation.internal.playfield.StandardPlayfield; +import de.unistuttgart.informatik.fius.icge.simulation.internal.playfield.StandardPlayfield;** /** @@ -23,10 +25,9 @@ * @author Tim Neumann */ public class SimulationBuilder { - - private TaskVerifier taskVerifier; - - private Simulation simulation; + * + private TaskVerifier taskVerifier;* + private Simulation simulation;* /** * Set the task verifier to use with this simulation. @@ -46,7 +47,7 @@ public void setTaskVerifier(final TaskVerifier taskVerifier) { "The simulation was already built! Use the methods of the Simulation Object to change its properties." ); this.taskVerifier = taskVerifier; - } + }* /** * Actually build the simulation. @@ -60,17 +61,17 @@ public void buildSimulation() { throw new IllegalStateException("The simulation was already built! Use getBuiltSimulation() to acess the built window."); final StandardPlayfield playfield = new StandardPlayfield(); final StandardSimulationClock simulationClock = new StandardSimulationClock(); - + * final StandardEntityTypeRegistry entityTypeRegistry = new StandardEntityTypeRegistry(); - + * final StandardActionLog actionLog = new StandardActionLog(); - + * final InspectionManager inspectionManager = new InspectionManager(); - + * this.simulation = new StandardSimulation( playfield, simulationClock, entityTypeRegistry, actionLog, inspectionManager, this.taskVerifier ); - } + }* /** * Get whether the window has been built. @@ -79,7 +80,7 @@ public void buildSimulation() { */ public boolean hasBuiltSimulation() { return this.simulation != null; - } + }* /** * Get the simulation that was built. @@ -92,7 +93,7 @@ public boolean hasBuiltSimulation() { public Simulation getBuiltSimulation() { if (!this.hasBuiltSimulation()) throw new IllegalStateException("The simulation was not yet built! Use buildSimulation() to do that."); - + * return this.simulation; } } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java index 1857b9e1a..ffdb01adf 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; +* + import java.util.concurrent.CompletableFuture; -import java.util.function.Function; +import java.util.function.Function;** /** @@ -21,17 +23,17 @@ * @version 1.0 */ public interface SimulationClock { - + * /** * The number of render ticks per one simulation tick. */ int RENDER_TICKS_PER_SIMULATION_TICK = 8; - + * /** * The render period, that is set by default. */ int DEFAULT_RENDER_TICK_PERIOD = 50; - + * /** * Set the period of the render ticks. The game ticks will have this period times * {@value #RENDER_TICKS_PER_SIMULATION_TICK}. @@ -40,33 +42,33 @@ public interface SimulationClock { * The new period in milliseconds. */ void setPeriod(int millis); - + * /** * Get the period of the render ticks. * * @return The number of milliseconds per render tick period. */ int getRenderTickPeriod(); - + * /** * Get the period of the game ticks. * * @return The number of milliseconds per game tick period. */ int getGameTickPeriod(); - + * /** * Query the clock if its running * * @return if the clock is running */ boolean isRunning(); - + * /** * Start ticking. */ void start(); - + * /** * Stop ticking. *

@@ -74,12 +76,12 @@ public interface SimulationClock { *

*/ void stop(); - + * /** * Execute one single tick */ void step(); - + * /** * Register a listener for simulation ticks. *

@@ -90,7 +92,7 @@ public interface SimulationClock { * The listener to be called. */ void registerTickListener(Function listener); - + * /** * Register a listener for the end of simulation ticks. *

@@ -101,17 +103,17 @@ public interface SimulationClock { * The listener to be called. */ void registerPostTickListener(Function listener); - + * /** * @return the number of the last simulation tick */ long getLastTickNumber(); - + * /** * @return the number of the last render tick */ long getLastRenderTickNumber(); - + * /** * Schedule an operation, to happen during the given tick. This method will block until that tick. Then the tick * processing will halt until the given end of operation is completed. @@ -127,7 +129,7 @@ public interface SimulationClock { * if the end of operation completes exceptionally */ void scheduleOperationAtTick(long tick, CompletableFuture endOfOperation); - + * /** * Schedule an operation, to happen during the tick a given number of ticks in the future. This method will block * until that tick. Then the tick processing will halt until the given end of operation is completed. @@ -143,7 +145,7 @@ public interface SimulationClock { * if the end of operation completes exceptionally */ void scheduleOperationInTicks(long ticks, CompletableFuture endOfOperation); - + * /** * Schedule an operation, to happen during the next tick. This method will block until that tick. Then the tick * processing will halt until the given end of operation is completed. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java index 7e2bfa00e..3c771eeac 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java @@ -9,7 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; +* + +import de.unistuttgart.informatik.fius.icge.ui.TaskInformation;** /** @@ -27,14 +29,14 @@ public interface TaskVerifier { * the simulation to verify */ void attachToSimulation(Simulation sim); - + * /** * Verify if the current state of the simulation matches the requirements for the successful completion of the task. *

* This method should update the task information returned by {@link #getTaskInformation}. */ void verify(); - + * /** * Get the current task information. *

diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java index 94f49a22f..8e0d20102 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java @@ -9,15 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* /** * An action which happens during the execution of a simulation. * * @author Tim Neumann */ public abstract class Action { - + * private final long tickNumber; - + * /** * Create an action. * @@ -27,19 +28,19 @@ public abstract class Action { public Action(final long tickNumber) { this.tickNumber = tickNumber; } - + * /** * @return the description of this action */ public abstract String getDescription(); - + * /** * @return the number of the simulation tick the action happened */ public long getTickNumber() { return this.tickNumber; } - + * @Override public String toString() { return this.getDescription(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java index 29700b5f7..860ab933c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java @@ -9,9 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -import java.util.List; +* -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import java.util.List;* +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -20,7 +21,7 @@ * @author Tim Neumann */ public interface ActionLog { - + * /** * Get all actions which were logged. *

@@ -30,7 +31,7 @@ public interface ActionLog { * @return A list of all actions logged */ List getAllActions(); - + * /** * Get all actions which were logged of the given type. * @@ -43,7 +44,7 @@ public interface ActionLog { * @return A list of all matching actions */ List getActionsOfType(final Class type, final boolean includeSubclasses); - + * /** * Get all actions which were logged and were caused by the given entity. * @@ -52,7 +53,7 @@ public interface ActionLog { * @return A list of all matching actions */ List getAllActionsOfEntity(Entity entity); - + * /** * Get all actions which were logged of the given type and were caused by the given entity. * @@ -69,7 +70,7 @@ public interface ActionLog { List getActionsOfTypeOfEntity( Entity entity, final Class type, final boolean includeSubclasses ); - + * /** * Log an action. * @@ -77,7 +78,7 @@ List getActionsOfTypeOfEntity( * The action to log */ void logAction(Action actionToLog); - + * /** * Set ActionLog console output (default: {@code true}) * @@ -85,7 +86,7 @@ List getActionsOfTypeOfEntity( * true: log to console, false: do not log to console */ void setConsoleOutput(boolean enable); - + * /** * Get ActionLog console output status. *

@@ -93,5 +94,5 @@ List getActionsOfTypeOfEntity( * logged but not printed to console. */ boolean getConsoleOutput(); - + * } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java index a0f45a739..6a3ffad6c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java @@ -9,7 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +* + +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -18,9 +20,9 @@ * @author Tim Neumann */ public abstract class EntityAction extends Action { - + * private final Entity entity; - + * /** * Create an entity action. * @@ -33,7 +35,7 @@ public EntityAction(final long tickNumber, final Entity entity) { super(tickNumber); this.entity = entity; } - + * /** * @return the entity that caused this action. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java index 97db49de2..af69802af 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java @@ -9,9 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* + import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -20,11 +22,11 @@ * @author Tim Neumann */ public class EntityCollectAction extends EntityAction { - + * private final CollectableEntity collected; private final Position collectorPos; private final Position collectedPos; - + * /** * Create an entity collect action. * @@ -49,32 +51,32 @@ public EntityCollectAction( this.collectedPos = collectedPos; this.collectorPos = collectorPos; } - + * /** * @return the entity that was collected */ public CollectableEntity getCollectedEntity() { return this.collected; } - + * /** * @return the position the collected entity was at while being collected */ public Position getCollectedEntityPosition() { return this.collectedPos; } - + * /** * @return the position the collector was at while collecting */ public Position getCollectorPosition() { return this.collectorPos; } - + * @Override public String getDescription() { return this.getEntity() + " (at " + this.getCollectorPosition() + ") collected " + this.getCollectedEntity() + " at " + this.getCollectedEntityPosition(); } - + * } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java index 38d31591c..47c149784 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* + import de.unistuttgart.informatik.fius.icge.simulation.Playfield; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -19,9 +21,9 @@ * @author Tim Neumann */ public class EntityDespawnAction extends EntityAction { - + * private final Playfield playfield; - + * /** * Create an entity despawn action * @@ -36,14 +38,14 @@ public EntityDespawnAction(final long tickNumber, final Entity entity, final Pla super(tickNumber, entity); this.playfield = playfield; } - + * /** * @return the playfield the entity was removed from */ public Playfield getPlayfield() { return this.playfield; } - + * @Override public String getDescription() { return this.getEntity() + " despawned from " + this.getPlayfield(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java index 50d03beba..9801fc769 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java @@ -9,9 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* + import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -20,11 +22,11 @@ * @author Tim Neumann */ public class EntityDropAction extends EntityAction { - + * private final CollectableEntity dropped; private final Position dropperPos; private final Position dropppedPos; - + * /** * Create an entity drop action. * @@ -49,32 +51,32 @@ public EntityDropAction( this.dropppedPos = droppedPos; this.dropperPos = dropperPos; } - + * /** * @return the entity that was dropped */ public CollectableEntity getDroppedEntity() { return this.dropped; } - + * /** * @return the position the dropped entity was dropped to */ public Position getDroppedEntityPosition() { return this.dropppedPos; } - + * /** * @return the position the dropper was at while dropping */ public Position getDropperPosition() { return this.dropperPos; } - + * @Override public String getDescription() { return this.getEntity() + " (at " + this.getDropperPosition() + ") dropped " + this.getDroppedEntity() + " at " + this.getDroppedEntityPosition(); } - + * } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java index 3905273ae..605f04a6d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* + import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -21,10 +23,10 @@ * @see EntityTeleportAction */ public abstract class EntityMoveAction extends EntityAction { - + * private final Position from; private final Position to; - + * /** * Create an entity move action. * @@ -42,14 +44,14 @@ public EntityMoveAction(final long tickNumber, final Entity entity, final Positi this.from = from; this.to = to; } - + * /** * @return the position the entity was at before the move */ public Position from() { return this.from; } - + * /** * @return the position the entity is after the move */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java index 73e3e0fa6..efeafd410 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java @@ -9,9 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* + import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -20,10 +22,10 @@ * @author Tim Neumann */ public class EntitySpawnAction extends EntityAction { - + * private final Playfield playfield; private final Position position; - + * /** * Create an entity spawn action. * @@ -41,21 +43,21 @@ public EntitySpawnAction(final long tickNumber, final Entity entity, final Playf this.playfield = playfield; this.position = position; } - + * /** * @return the playfield the entity was added to */ public Playfield getPlayfield() { return this.playfield; } - + * /** * @return the position the entity was added at */ public Position getPosition() { return this.position; } - + * @Override public String getDescription() { return this.getEntity() + " spawned in " + this.getPlayfield() + " at " + this.getPosition(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java index 9515ebd9b..30f579a08 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* + import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -19,7 +21,7 @@ * @author Tim Neumann */ public class EntityStepAction extends EntityMoveAction { - + * /** * Create an entity step action. * @@ -35,7 +37,7 @@ public class EntityStepAction extends EntityMoveAction { public EntityStepAction(final long tickNumber, final Entity entity, final Position from, final Position to) { super(tickNumber, entity, from, to); } - + * @Override public String getDescription() { return this.getEntity() + " stepped from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java index f533be88c..572628a66 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* + import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -34,7 +36,7 @@ public class EntityTeleportAction extends EntityMoveAction { public EntityTeleportAction(final long tickNumber, final Entity entity, final Position from, final Position to) { super(tickNumber, entity, from, to); } - + * @Override public String getDescription() { return this.getEntity() + " teleported from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java index 5f219c83f..b76b43607 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; +* + import de.unistuttgart.informatik.fius.icge.simulation.Direction; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -19,10 +21,10 @@ * @author Tim Neumann */ public class EntityTurnAction extends EntityAction { - + * private final Direction from; private final Direction to; - + * /** * Create an entity turn action. * @@ -40,21 +42,21 @@ public EntityTurnAction(final long tickNumber, final Entity entity, final Direct this.from = from; this.to = to; } - + * /** * @return the direction the entity was facing before the turn */ public Direction from() { return this.from; } - + * /** * @return the direction the entity is facing after the turn */ public Direction to() { return this.to; } - + * @Override public String getDescription() { return this.getEntity() + " turned from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java index 04de18bbc..4760def93 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java @@ -9,9 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -import java.lang.ref.WeakReference; -import java.util.concurrent.CompletableFuture; +* +import java.lang.ref.WeakReference; +import java.util.concurrent.CompletableFuture;* import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; @@ -19,7 +20,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityOnAnotherFieldException; import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionAttribute; import de.unistuttgart.informatik.fius.icge.ui.BasicDrawable; -import de.unistuttgart.informatik.fius.icge.ui.Drawable; +import de.unistuttgart.informatik.fius.icge.ui.Drawable;** /** @@ -28,19 +29,19 @@ * @author Tim Neumann */ public abstract class BasicEntity implements Entity { - + * /** Lock object to make setting the Playfield threadsafe. */ private Object fieldLock = new Object(); /** The current (weak) reference to the playfield. */ private WeakReference field; - + * /** * Lock object to ensure no two long running operations ({@code >= 1} clock tick) are scheduled at the same time. */ private Object operationQueueLock = new Object(); /** The completable future representing the completion of the last enqueued operation. */ protected CompletableFuture endOfLastEnqueuedOperation; - + * /** * @throws EntityNotOnFieldException * if this entity is not on a playfield @@ -56,14 +57,14 @@ public Position getPosition() { if (playfield == null) throw new EntityNotOnFieldException("This entity is not on a playfield"); return playfield.getEntityPosition(this); } - + * /** * Get the texture handle, with which to get the texture for this entity. * * @return the texture handle for the texture of this entity */ protected abstract String getTextureHandle(); - + * /** * Get the z position of this entity. *

@@ -73,7 +74,7 @@ public Position getPosition() { * @return the z position of this entity. */ protected abstract int getZPosition(); - + * /** * @throws EntityNotOnFieldException * if this entity is not on a playfield @@ -83,7 +84,7 @@ public Drawable getDrawInformation() { final Position pos = this.getPosition(); return new BasicDrawable(pos.getX(), pos.getY(), this.getZPosition(), this.getTextureHandle()); } - + * @Override public void initOnPlayfield(final Playfield playfield) { if (playfield == null) throw new IllegalArgumentException("The given playfield is null."); @@ -92,7 +93,7 @@ public void initOnPlayfield(final Playfield playfield) { this.field = new WeakReference<>(playfield); } } - + * /** * Check whether this entity is on a playfield * @@ -114,7 +115,7 @@ public boolean isOnPlayfield() { return true; } } - + * /** * Get the playfield of this entity. * @@ -128,7 +129,7 @@ protected Playfield getPlayfield() { return this.field.get(); } } - + * /** * Get the simulation of this entity. * @@ -143,7 +144,7 @@ protected Simulation getSimulation() { return this.getPlayfield().getSimulation(); } } - + * /** * Prevent this entity from performing any long running operation for {@code ticks} simulation ticks. *

@@ -164,7 +165,7 @@ public void sleep(final int ticks) { endOfOperation.complete(null); } } - + * /** * Wait for the last enqueued long running operation to finish before allowing the new Operation to perform. *

@@ -204,10 +205,10 @@ protected void enqueueToPerformNewOperation(CompletableFuture endOfNewOper endOfLastEnqueuedOperation.join(); } } - + * @Override public String toString() { return this.getClass().getSimpleName() + "@" + Integer.toHexString(this.hashCode()); } - + * } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java index 892ea8f24..3b8f60e73 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java @@ -8,7 +8,7 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.entity; - + * /** * An entity, which can be collected by {@link EntityCollector}. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java index 74b3ea471..6e03ea963 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java @@ -9,10 +9,12 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; +* + import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityOnAnotherFieldException; -import de.unistuttgart.informatik.fius.icge.ui.Drawable; +import de.unistuttgart.informatik.fius.icge.ui.Drawable;** /** @@ -25,12 +27,12 @@ public interface Entity { * @return the position of this entity */ Position getPosition(); - + * /** * @return the information required to draw this entity; must not be null */ Drawable getDrawInformation(); - + * /** * Method to initialize this entity after being added to the playfield. *

@@ -49,5 +51,5 @@ public interface Entity { * if the entity is already on a field */ void initOnPlayfield(Playfield playfield); - + * } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java index b9752ac75..f497dced9 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java @@ -9,9 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; +* + import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotCollectEntityException; -import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotDropEntityException; +import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotDropEntityException;** /** @@ -20,7 +22,7 @@ * @author Tim Neumann */ public interface EntityCollector { - + * /** * Check if this can collect and drop the given collectable entity type. * @@ -29,7 +31,7 @@ public interface EntityCollector { * @return true if this entity collector can collect or drop the given entity type */ boolean canCarry(Class type); - + * /** * Collect the given entity. * @@ -41,7 +43,7 @@ public interface EntityCollector { * if an argument is null */ void collect(CollectableEntity entity); - + * /** * Drop the given entity. * @@ -55,5 +57,5 @@ public interface EntityCollector { * if an argument is null */ void drop(CollectableEntity entity, Position pos); - + * } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java index dd9739d38..aa7e75877 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java @@ -9,10 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -import java.util.Set; -import java.util.function.Supplier; +* -import de.unistuttgart.informatik.fius.icge.simulation.exception.ElementExistsException; +import java.util.Set; +import java.util.function.Supplier;* +import de.unistuttgart.informatik.fius.icge.simulation.exception.ElementExistsException;** /** @@ -21,7 +22,7 @@ * @author Fabian Bühler */ public interface EntityTypeRegistry { - + * /** * Register a new entity type by name. *

@@ -42,7 +43,7 @@ public interface EntityTypeRegistry { * if the name is already used */ void registerEntityType(final String typeName, final String textureHandle, Class entityType); - + * /** * Register a new entity type by name. *

@@ -62,14 +63,14 @@ public interface EntityTypeRegistry { * if the name is already used */ void registerEntityType(final String typeName, final String textureHandle, Supplier entityFactory); - + * /** * Get a set of all currently registered entity types. * * @return registered entity types */ Set getRegisteredEntityTypes(); - + * /** * Get the texture handle of a registered entity type. * @@ -80,7 +81,7 @@ public interface EntityTypeRegistry { * if an argument is null */ String getTextureHandleOfEntityType(final String typeName); - + * /** * Get a new Entity instance of a registered entity type. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java index 35c10a440..118a526f4 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java @@ -9,15 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -import java.util.List; +* +import java.util.List;* import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.actions.Action; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityCollectAction; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityDropAction; import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotCollectEntityException; import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotDropEntityException; -import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityNotOnFieldException; +import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityNotOnFieldException;** /** @@ -26,23 +27,22 @@ * @author Tim Neumann */ public abstract class GreedyEntity extends MovableEntity implements EntityCollector { - + * /** A lock to synchronize all operations involving the entities inventory. */ - protected final Object inventoryOperationLock = new Object(); - - private final Inventory inventory = new Inventory(); + protected final Object inventoryOperationLock = new Object();* + private final Inventory inventory = new Inventory();* /** * @return the inventory of this greedy entity */ public Inventory getInventory() { return this.inventory; - } + }* @Override public boolean canCarry(final Class type) { return true; - } + }* /** * Get all the currently collectable entities of the given type @@ -57,14 +57,14 @@ public boolean canCarry(final Class type) { */ public List getCurrentlyCollectableEntities(final Class type, final boolean includeSubclasses) { return this.getPlayfield().getEntitiesOfTypeAt(this.getPosition(), type, includeSubclasses); - } + }* @Override public void collect(final CollectableEntity entity) { if (entity == null) throw new IllegalArgumentException("An argument is null."); Position myPos; Position otherPos; - + * synchronized (this.inventoryOperationLock) { try { myPos = this.getPosition(); @@ -72,18 +72,18 @@ public void collect(final CollectableEntity entity) { } catch (final EntityNotOnFieldException e) { throw new CannotCollectEntityException(e); } - + * if (!myPos.equals(otherPos)) throw new CannotCollectEntityException("Not on my field"); - + * this.getSimulation().getPlayfield().removeEntity(entity); this.getInventory().add(entity); - + * final Action action = new EntityCollectAction( this.getSimulation().getSimulationClock().getLastTickNumber(), this, entity, myPos, otherPos ); this.getSimulation().getActionLog().logAction(action); } - } + }* /** * Get all the currently droppable entities of the given type @@ -98,7 +98,7 @@ public void collect(final CollectableEntity entity) { */ public List getCurrentlyDroppableEntities(final Class type, final boolean includeSubclasses) { return this.getInventory().get(type, includeSubclasses); - } + }* @Override public void drop(final CollectableEntity entity, final Position pos) { @@ -110,18 +110,18 @@ public void drop(final CollectableEntity entity, final Position pos) { } catch (final EntityNotOnFieldException e) { throw new CannotCollectEntityException(e); } - + * if (!myPos.equals(pos)) throw new CannotCollectEntityException("Not on my field"); - + * this.getInventory().remove(entity); this.getPlayfield().addEntity(pos, entity); - + * final Action action = new EntityDropAction( this.getSimulation().getSimulationClock().getLastTickNumber(), this, entity, myPos, pos ); this.getSimulation().getActionLog().logAction(action); } - } + }* /** * Drop the given entity at the current position. @@ -135,6 +135,5 @@ public void drop(final CollectableEntity entity, final Position pos) { */ public void drop(final CollectableEntity entity) { this.drop(entity, this.getPosition()); - } - + }* } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java index 9698fd6fd..b6ad89ffb 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java @@ -8,10 +8,10 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.entity; - + * import de.unistuttgart.informatik.fius.icge.simulation.MultiTypedList; - - + * + * /** * An inventory of a entity. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java index d54e68555..4e141afdf 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java @@ -9,8 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -import java.util.concurrent.CompletableFuture; +* +import java.util.concurrent.CompletableFuture;* import de.unistuttgart.informatik.fius.icge.simulation.Direction; import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock; @@ -22,7 +23,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionAttribute; import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionMethod; import de.unistuttgart.informatik.fius.icge.ui.AnimatedDrawable; -import de.unistuttgart.informatik.fius.icge.ui.Drawable; +import de.unistuttgart.informatik.fius.icge.ui.Drawable;** /** @@ -31,12 +32,10 @@ * @author Tim Neumann */ public abstract class MovableEntity extends BasicEntity { - - private Direction lookingDirection = Direction.EAST; - - private AnimatedDrawable movingDrawable = null; - - private Direction directionOfAlmostArrivedMove; + * + private Direction lookingDirection = Direction.EAST;* + private AnimatedDrawable movingDrawable = null;* + private Direction directionOfAlmostArrivedMove;* @Override public Drawable getDrawInformation() { @@ -44,7 +43,7 @@ public Drawable getDrawInformation() { if (movingDrawable != null) return movingDrawable; final Position pos = this.getPosition(); return new UntilableDrawable(pos.getX(), pos.getY(), this.getZPosition(), this.getTextureHandle()); - } + }* /** * Turn this entity for 90 degrees in clock wise direction. @@ -58,50 +57,50 @@ public void turnClockWise() { } finally { endOfOperation.complete(null); } - } + }* private void turnClockWiseInternal() { final Direction oldLookingDirection = this.lookingDirection; this.lookingDirection = this.lookingDirection.clockWiseNext(); final long tick = this.getSimulation().getSimulationClock().getLastTickNumber(); this.getSimulation().getActionLog().logAction(new EntityTurnAction(tick, this, oldLookingDirection, this.lookingDirection)); - } + }* @InspectionMethod(name = "turnClockwise") private void turnClockWiseInspector() { this.turnClockWiseInternal(); this.recalculateAnimationAfterInspector(); - } + }* private void recalculateAnimationAfterInspector() { if (this.movingDrawable != null) { - + * final long tickStart = this.movingDrawable.getTickStart(); final long duration = this.movingDrawable.getDuration(); - + * Direction movingDir; if (this.directionOfAlmostArrivedMove == null) { movingDir = this.lookingDirection; } else { movingDir = this.directionOfAlmostArrivedMove; } - + * final Position currentPos = this.getPosition(); final Position nextPos = currentPos.adjacentPosition(movingDir); - + * this.movingDrawable = new AnimatedDrawable( tickStart, currentPos.getX(), currentPos.getY(), duration, nextPos.getX(), nextPos.getY(), this.getZPosition(), this.getTextureHandle() ); } - } + }* /** * @return the current looking direction of this entity */ public Direction getLookingDirection() { return this.lookingDirection; - } + }* /** * Set the looking direction @@ -113,7 +112,7 @@ public Direction getLookingDirection() { private void setLookingDirectionByString(final String direction) { this.lookingDirection = Direction.valueOf(direction.toUpperCase()); this.recalculateAnimationAfterInspector(); - } + }* /** * @return the looking direction as a string @@ -121,11 +120,11 @@ private void setLookingDirectionByString(final String direction) { @InspectionAttribute(name = "LookingDirection") public String getLookingDirectionString() { return this.getLookingDirection().toString(); - } + }* private boolean isSolidEntityAt(final Position pos) { return this.getPlayfield().isSolidEntityAt(pos); - } + }* /** * Move this entity forward one field. @@ -139,7 +138,7 @@ public void move() { // use extra future for whole operation as it is split amongst two futures final CompletableFuture endOfOperation = new CompletableFuture<>(); this.enqueueToPerformNewOperation(endOfOperation); - + * // setup move final int duration = 4; final int renderTickDuration = duration * SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; @@ -152,7 +151,7 @@ public void move() { currentTick, currentPos.getX(), currentPos.getY(), renderTickDuration, nextPos.getX(), nextPos.getY(), this.getZPosition(), this.getTextureHandle() ); - + * final CompletableFuture endOfOperation1 = new CompletableFuture<>(); try { clock.scheduleOperationInTicks(duration / 2, endOfOperation1); @@ -162,7 +161,7 @@ public void move() { } finally { endOfOperation1.complete(null); } - + * final CompletableFuture endOfOperation2 = new CompletableFuture<>(); try { clock.scheduleOperationInTicks(duration / 2, endOfOperation2); @@ -174,16 +173,16 @@ public void move() { endOfOperation.complete(null); // complete future for whole operation this.movingDrawable = null; } - } + }* @InspectionMethod(name = "move") private void moveInspector() { final Position currentPos = this.getPosition(); final Position nextPos = currentPos.adjacentPosition(this.lookingDirection); - + * this.internalMove(currentPos, nextPos); this.recalculateAnimationAfterInspector(); - } + }* private void internalMove(final Position currentPos, final Position nextPos) { if (this.isSolidEntityAt(nextPos)) throw new IllegalMoveException("Solid Entity in the way"); @@ -191,7 +190,7 @@ private void internalMove(final Position currentPos, final Position nextPos) { this.getSimulation().getSimulationClock().getLastTickNumber(), this, currentPos, nextPos ); this.getPlayfield().moveEntity(this, nextPos, action); - } + }* /** * @return whether this entity can move forward one field. @@ -199,7 +198,7 @@ private void internalMove(final Position currentPos, final Position nextPos) { public boolean canMove() { final Position nextPos = this.getPosition().adjacentPosition(this.lookingDirection); return this.isOnPlayfield() && !this.isSolidEntityAt(nextPos); - } + }* /** * Move this entity forward one field if that is possible. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java index 227b4bdcb..53633fbbe 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java @@ -9,13 +9,14 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; +* /** * A solid entity, through which a movable entity cannot move. * * @author Tim Neumann */ public interface SolidEntity extends Entity { - + * /** * Get whether this entity is really solid at the moment. *

diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java index 11dccaa7c..0b1ddb4ae 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java @@ -9,14 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -import de.unistuttgart.informatik.fius.icge.ui.BasicDrawable; +* + +import de.unistuttgart.informatik.fius.icge.ui.BasicDrawable;** /** * Same as {@link BasicDrawable} but won't tile. */ public class UntilableDrawable extends BasicDrawable { - + * /** * Create a new untilable Drawable. * @@ -28,7 +30,7 @@ public class UntilableDrawable extends BasicDrawable { public UntilableDrawable(final double x, final double y, final int z, final String textureHandle) { super(x, y, z, textureHandle); } - + * @Override public boolean isTilable() { return false; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java index 140d7b2f1..826e4b900 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java @@ -9,18 +9,19 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates that an entity program cannot be run. * * @author Tim Neumann */ public class CannotCollectEntityException extends SimulationExcpetion { - + * /** * generated */ private static final long serialVersionUID = 6758366706458330276L; - + * /** * Constructs a new CannotCollectEntityException with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +29,7 @@ public class CannotCollectEntityException extends SimulationExcpetion { public CannotCollectEntityException() { super(); } - + * /** * Constructs a new CannotCollectEntityException with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +40,7 @@ public CannotCollectEntityException() { public CannotCollectEntityException(final String message) { super(message); } - + * /** * Constructs a new CannotCollectEntityException with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -54,7 +55,7 @@ public CannotCollectEntityException(final String message) { public CannotCollectEntityException(final Throwable cause) { super(cause); } - + * /** * Constructs a new CannotCollectEntityException with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java index cb8687bcc..79c5f93e1 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java @@ -9,18 +9,19 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates that an entity program cannot be run. * * @author Tim Neumann */ public class CannotDropEntityException extends SimulationExcpetion { - + * /** * generated */ private static final long serialVersionUID = 8237903756645049779L; - + * /** * Constructs a new CannotDropEntityException with {@code null} as its detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +29,7 @@ public class CannotDropEntityException extends SimulationExcpetion { public CannotDropEntityException() { super(); } - + * /** * Constructs a new CannotDropEntityException with the specified detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +40,7 @@ public CannotDropEntityException() { public CannotDropEntityException(final String message) { super(message); } - + * /** * Constructs a new CannotDropEntityException with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -54,7 +55,7 @@ public CannotDropEntityException(final String message) { public CannotDropEntityException(final Throwable cause) { super(cause); } - + * /** * Constructs a new CannotDropEntityException with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java index 82bdd010f..5c2e9303d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java @@ -9,25 +9,26 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates that an entity program cannot be run. * * @author Tim Neumann */ public class CannotRunProgramException extends IllegalArgumentException { - + * /** * generated */ private static final long serialVersionUID = -5283363131395011240L; - + * /** * Constructs an CannotRunProgramException with no detail message. */ public CannotRunProgramException() { super(); } - + * /** * Constructs an CannotRunProgramException with the specified detail message. * @@ -37,7 +38,7 @@ public CannotRunProgramException() { public CannotRunProgramException(final String s) { super(s); } - + * /** * Constructs a new exception with the specified detail message and cause. * @@ -55,7 +56,7 @@ public CannotRunProgramException(final String s) { public CannotRunProgramException(final String message, final Throwable cause) { super(message, cause); } - + * /** * Constructs a new exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java index 848418cd3..b3c64d996 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java @@ -9,25 +9,26 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates that the element already exists. * * @author Tim Neumann */ public class ElementExistsException extends IllegalArgumentException { - + * /** * generated */ private static final long serialVersionUID = -564159508677510779L; - + * /** * Constructs an ElementExistsException with no detail message. */ public ElementExistsException() { super(); } - + * /** * Constructs an ElementExistsException with the specified detail message. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java index 1cfcc701c..8f340295d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates that an action is illegal, because the subject entity is already in on the relevant * playfield. @@ -20,7 +21,7 @@ public class EntityAlreadyOnFieldExcpetion extends SimulationExcpetion { * generated */ private static final long serialVersionUID = 3177203739377160043L; - + * /** * Constructs a new EntityAlreadyOnFieldExcpetion with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +29,7 @@ public class EntityAlreadyOnFieldExcpetion extends SimulationExcpetion { public EntityAlreadyOnFieldExcpetion() { super(); } - + * /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +40,7 @@ public EntityAlreadyOnFieldExcpetion() { public EntityAlreadyOnFieldExcpetion(final String message) { super(message); } - + * /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java index c36fd3cb6..2c5abf422 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates that an action was illegal, because the subject entity is not the the relevant playfield. * @@ -19,7 +20,7 @@ public class EntityNotOnFieldException extends SimulationExcpetion { * generated */ private static final long serialVersionUID = -8786124964224174226L; - + * /** * Constructs a new EntityAlreadyOnFieldExcpetion with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -27,7 +28,7 @@ public class EntityNotOnFieldException extends SimulationExcpetion { public EntityNotOnFieldException() { super(); } - + * /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -38,7 +39,7 @@ public EntityNotOnFieldException() { public EntityNotOnFieldException(final String message) { super(message); } - + * /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java index 6378e6448..28a55d953 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java @@ -9,18 +9,19 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates that an action is illegal, because the subject entity is already on another playfield. * * @author Tim Neumann */ public class EntityOnAnotherFieldException extends SimulationExcpetion { - + * /** * generated */ private static final long serialVersionUID = -2894368466373991151L; - + * /** * Constructs a new EntityOnAnotherFieldException with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +29,7 @@ public class EntityOnAnotherFieldException extends SimulationExcpetion { public EntityOnAnotherFieldException() { super(); } - + * /** * Constructs a new EntityOnAnotherFieldException with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +40,7 @@ public EntityOnAnotherFieldException() { public EntityOnAnotherFieldException(final String message) { super(message); } - + * /** * Constructs a new EntityOnAnotherFieldException with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java index 7856ef11d..b07df57c1 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates, that a entity could not move. *

@@ -22,7 +23,7 @@ public class IllegalMoveException extends SimulationExcpetion { * generated */ private static final long serialVersionUID = -4781899414191823139L; - + * /** * Constructs a new IllegalMoveException with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -30,7 +31,7 @@ public class IllegalMoveException extends SimulationExcpetion { public IllegalMoveException() { super(); } - + * /** * Constructs a new IllegalMoveException with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -41,7 +42,7 @@ public IllegalMoveException() { public IllegalMoveException(final String message) { super(message); } - + * /** * Constructs a new IllegalMoveException with the specified detail message and cause. * * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java index 085bb0fa4..edd26ac2f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java @@ -9,18 +9,19 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * The parent of all exceptions thrown by the simulation. * * @author Tim Neumann */ public class SimulationExcpetion extends RuntimeException { - + * /** * generated */ private static final long serialVersionUID = 8969492057602725022L; - + * /** * Constructs a new SimulationExcpetion with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +29,7 @@ public class SimulationExcpetion extends RuntimeException { public SimulationExcpetion() { super(); } - + * /** * Constructs a new SimulationExcpetion with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +40,7 @@ public SimulationExcpetion() { public SimulationExcpetion(final String message) { super(message); } - + * /** * Constructs a new SimulationExcpetion with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -54,7 +55,7 @@ public SimulationExcpetion(final String message) { public SimulationExcpetion(final Throwable cause) { super(cause); } - + * /** * Constructs a new SimulationExcpetion with the specified detail message and cause. * * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java index c94f941e3..d368f56e2 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java @@ -9,7 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock; +* + +import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock;** /** @@ -20,7 +22,7 @@ */ public class TimerAlreadyRunning extends IllegalStateException { private static final long serialVersionUID = 1715637086603245424L; - + * /** * Default constructor */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java index 18ae81a10..db67688ae 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java @@ -9,25 +9,26 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; +* /** * This exception indicates that an entity program cannot be run. * * @author Tim Neumann */ public class UncheckedInterruptedException extends IllegalArgumentException { - + * /** * generated */ private static final long serialVersionUID = -8407441370711369840L; - + * /** * Constructs an EntityProgramInterruptedException with no detail message. */ public UncheckedInterruptedException() { super(); } - + * /** * Constructs an EntityProgramInterruptedException with the specified detail message. * @@ -37,7 +38,7 @@ public UncheckedInterruptedException() { public UncheckedInterruptedException(final String s) { super(s); } - + * /** * Constructs a new exception with the specified detail message and cause. * @@ -55,7 +56,7 @@ public UncheckedInterruptedException(final String s) { public UncheckedInterruptedException(final String message, final Throwable cause) { super(message, cause); } - + * /** * Constructs a new exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java index 4e4e5d84e..be366738d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java @@ -9,11 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; +* + import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.List; +import java.util.List;** /** @@ -24,7 +26,7 @@ public class AnnotationReader { private AnnotationReader() { //hide constructor - } + }* /** * Get all methods with the given annotation in the given class and all parent classes. @@ -38,19 +40,19 @@ private AnnotationReader() { public static List getAllMethodsWithAnnotationRecursively(final Class cls, final Class annotation) { final Method[] methods = cls.getDeclaredMethods(); final List ret = new ArrayList<>(); - + * for (final Method m : methods) { if (m.isAnnotationPresent(annotation)) { ret.add(m); } } - + * final Class superCls = cls.getSuperclass(); if (superCls != null) { ret.addAll(AnnotationReader.getAllMethodsWithAnnotationRecursively(superCls, annotation)); } return ret; - } + }* /** * Get all attributes with the given annotation in the given class and all parent classes. @@ -64,13 +66,13 @@ public static List getAllMethodsWithAnnotationRecursively(final Class public static List getAllAttributesWithAnnotationRecursively(final Class cls, final Class annotation) { final Field[] fields = cls.getDeclaredFields(); final List ret = new ArrayList<>(); - + * for (final Field f : fields) { if (f.isAnnotationPresent(annotation)) { ret.add(f); } } - + * final Class superCls = cls.getSuperclass(); if (superCls != null) { ret.addAll(AnnotationReader.getAllAttributesWithAnnotationRecursively(superCls, annotation)); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java index e1df282e5..8767c5d40 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; +* + import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -18,7 +20,7 @@ import java.util.List; import java.util.function.Predicate; import java.util.jar.JarEntry; -import java.util.jar.JarFile; +import java.util.jar.JarFile;** /** @@ -29,7 +31,7 @@ public class ClassFinder { private ClassFinder() { //hide constructor - } + }* /** * Get all classes in the current context class loader, which match the filter. @@ -43,9 +45,9 @@ private ClassFinder() { public static List> getClassesInClassLoader(final Predicate> filter) throws IOException { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final List urls = Collections.list(loader.getResources("de")); - + * final List> classes = new ArrayList<>(); - + * for (final URL url : urls) { if (url.getProtocol().equals("jar")) { ClassFinder.loadClassesFromJar(url, filter, classes); @@ -53,9 +55,9 @@ public static List> getClassesInClassLoader(final Predicate> f ClassFinder.loadClassesFromFS(url, filter, classes, loader); } } - + * return classes; - } + }* private static void loadClassesFromJar(final URL url, final Predicate> filter, final List> classes) throws IOException { @@ -82,7 +84,7 @@ private static void loadClassesFromJar(final URL url, final Predicate> } catch (final URISyntaxException e2) { throw new IOException(e2); } - } + }* private static void loadClassesFromFS( final URL url, final Predicate> filter, final List> classes, final ClassLoader loader @@ -93,7 +95,7 @@ private static void loadClassesFromFS( } catch (URISyntaxException | ClassNotFoundException e) { throw new IOException(e); } - } + }* private static void loadClassInFile( final File file, final List> classes, final ClassLoader loader, final String rootDir, final Predicate> filter @@ -115,7 +117,7 @@ private static void loadClassInFile( } } } - } + }* private static String convertPathToClassName(final String path, final String rootDir) { if (!path.startsWith(rootDir)) throw new IllegalStateException("File not starting with root dir!"); @@ -128,6 +130,6 @@ private static String convertPathToClassName(final String path, final String roo relPath = relPath.replace(fileSep, "."); } return relPath; - + * } } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java index 6a0703432..9fee02a8e 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java @@ -9,13 +9,14 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; +* + import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - +import static java.lang.annotation.RetentionPolicy.RUNTIME;* import java.lang.annotation.Documented; import java.lang.annotation.Retention; -import java.lang.annotation.Target; +import java.lang.annotation.Target;** /** @@ -31,7 +32,7 @@ public @interface InspectionAttribute { /** @return The optional name of the attribute, to be displayed in the front end. */ String name() default ""; - + * /** @return Optional argument setting this attribute to read only. */ boolean readOnly() default false; } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java index f98a59fa9..b5784eff1 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; +* + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -17,7 +19,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; +import java.util.Map.Entry;** /** @@ -26,10 +28,9 @@ * @author Tim Neumann */ public class InspectionData { - private final Class c; - + private final Class c;* private final Map inspectableAttributes; - private final Map inspectableMethods; + private final Map inspectableMethods;* /** * Creates a new inspection data object for the given class @@ -43,7 +44,7 @@ public InspectionData(final Class cls) { this.inspectableMethods = new HashMap<>(); this.initAttributes(); this.initMethods(); - } + }* /** * Get the value of the attribute with the given name from the given object. @@ -67,7 +68,7 @@ public Object getAttributeValue(final Object obj, final String name) { } } return null; - } + }* /** * Set's the value of the attribute with the given name for the given object @@ -91,7 +92,7 @@ public boolean setAttributeValue(final Object obj, final String name, final Obje } } return false; - } + }* /** * Get the attribute names of the class for this inspection data. @@ -100,7 +101,7 @@ public boolean setAttributeValue(final Object obj, final String name, final Obje */ public List getAttributeNames() { return Collections.unmodifiableList(new ArrayList<>(this.inspectableAttributes.keySet())); - } + }* /** * Get the type of the attribute with the given name. @@ -113,7 +114,7 @@ public Class getAttributeType(final String attributeName) { final AttributeInspectionPoint p = this.inspectableAttributes.get(attributeName); if (p == null) return null; return p.getType(); - } + }* /** * Check whether the attribute with the given name is read only. @@ -126,14 +127,14 @@ public boolean isAttributeReadOnly(final String attributeName) { final AttributeInspectionPoint p = this.inspectableAttributes.get(attributeName); if (p == null) return true; return p.isReadOnly(); - } + }* /** * @return Whether this inspection data has any inspectable elements. */ public boolean hasAnyInspectableElements() { return !(this.inspectableAttributes.isEmpty() && this.inspectableMethods.isEmpty()); - } + }* /** * Get the mathod names of the class for this inspection data. @@ -142,7 +143,7 @@ public boolean hasAnyInspectableElements() { */ public List getMethodNames() { return Collections.unmodifiableList(new ArrayList<>(this.inspectableMethods.keySet())); - } + }* /** * Get the method detail for the method with the given name @@ -153,7 +154,7 @@ public List getMethodNames() { */ public Method getMethodByName(final String methodName) { return this.inspectableMethods.get(methodName); - } + }* /** * Invoke the method with the given name in the given object, using the given arguments @@ -175,39 +176,39 @@ public Object invokeMethod(final Object obj, final String methodName, final Obje e.printStackTrace(); throw new IllegalStateException("Invokation didn't work", e); } - } + }* private void initMethods() { final List methods = AnnotationReader.getAllMethodsWithAnnotationRecursively(this.c, InspectionMethod.class); - + * for (final Method m : methods) { m.setAccessible(true); this.inspectableMethods.put(this.getDsiplayNameForInspectionMethod(m), m); } - } + }* private void initAttributes() { final List fields = AnnotationReader.getAllAttributesWithAnnotationRecursively(this.c, InspectionAttribute.class); final List methods = AnnotationReader.getAllMethodsWithAnnotationRecursively(this.c, InspectionAttribute.class); - + * for (final Field f : fields) { f.setAccessible(true); this.inspectableAttributes.put(this.getDisplayNameForField(f), new AttributeInspectionPoint(f)); } - + * final Map getters = new HashMap<>(); final Map setters = new HashMap<>(); - + * for (int i = 0; i < methods.size(); i++) { final Method m = methods.get(i); - + * if (this.isGetter(m)) { getters.put(this.getDisplayNameForMethod(m, "get"), m); } else if (this.isSetter(m)) { setters.put(this.getDisplayNameForMethod(m, "set"), m); } else throw new InspectionPointException("Method is neither a getter nor a setter! : " + m.getName()); } - + * for (final Entry entry : getters.entrySet()) { final String name = entry.getKey(); final Method setter = setters.remove(name); @@ -218,55 +219,55 @@ private void initAttributes() { this.validateReadOnlyGetter(getter); getter.setAccessible(true); this.inspectableAttributes.put(name, new AttributeInspectionPoint(getter)); - + * } else { this.validateMethodPair(getter, setter); getter.setAccessible(true); setter.setAccessible(true); this.inspectableAttributes.put(name, new AttributeInspectionPoint(getter, setter)); } - + * } - + * if (setters.size() > 0) throw new InspectionPointException("No getter for setter! : " + setters.values().iterator().next()); - - } + * + }* private boolean isGetter(final Method met) { return (met.getParameterTypes().length == 0) && (met.getReturnType() != Void.TYPE); - } + }* private boolean isSetter(final Method met) { return (met.getParameterTypes().length == 1) && (met.getReturnType() == Void.TYPE); - } + }* private void validateMethodPair(final Method getter, final Method setter) { final Class type = getter.getReturnType(); - + * if (type.equals(Void.TYPE)) throw new InspectionPointException("Getter should return something! : " + getter.getName()); - + * if (getter.getParameterTypes().length != 0) throw new InspectionPointException("Getter should not have parameters! : " + getter.getName()); - + * if (!setter.getReturnType().equals(Void.TYPE)) throw new InspectionPointException("Setter should not be return type null. : " + setter.getName()); - + * final Class[] setterParas = setter.getParameterTypes(); - + * if (setterParas.length != 1) throw new InspectionPointException("Setter should have exactly one parameter! : " + setter.getName()); - + * if (!setterParas[0].equals(type)) throw new InspectionPointException("Getter parameter is not the same type as getter return value"); - - } + * + }* private void validateReadOnlyGetter(final Method getter) { if (getter.getReturnType().equals(Void.TYPE)) throw new InspectionPointException("Getter should return something! : " + getter.getName()); - + * if (getter.getParameterTypes().length != 0) throw new InspectionPointException("Getter should not have parameters! : " + getter.getName()); - } + }* private String getDisplayNameForField(final Field f) { final InspectionAttribute anno = f.getAnnotation(InspectionAttribute.class); @@ -275,7 +276,7 @@ private String getDisplayNameForField(final Field f) { if ((name != null) && !name.isEmpty()) return name; } return f.getName(); - } + }* private String getDsiplayNameForInspectionMethod(final Method m) { final InspectionMethod anno = m.getAnnotation(InspectionMethod.class); @@ -284,7 +285,7 @@ private String getDsiplayNameForInspectionMethod(final Method m) { if ((name != null) && !name.isEmpty()) return name; } return m.getName(); - } + }* private String getDisplayNameForMethod(final Method m, final String possiblePrefixToRemove) { final InspectionAttribute anno = m.getAnnotation(InspectionAttribute.class); @@ -292,15 +293,15 @@ private String getDisplayNameForMethod(final Method m, final String possiblePref final String name = anno.name(); if ((name != null) && !name.isEmpty()) return name; } - + * String name = m.getName(); - + * if (name.toLowerCase().startsWith(possiblePrefixToRemove)) { name = name.substring(3); name = name.substring(0, 1).toLowerCase() + name.substring(1); } return name; - } + }* private static class AttributeInspectionPoint { private static final Map, Class> primitiveToWrapperMap = new HashMap<>(); @@ -321,7 +322,7 @@ private static class AttributeInspectionPoint { private final Method setter; private final Class type; private final boolean readOnly; - + * /** * Creates a new attribute inspection point for a field * @@ -336,7 +337,7 @@ public AttributeInspectionPoint(final Field field) { this.type = this.convertTypeToWrappers(field.getType()); this.readOnly = field.getAnnotation(InspectionAttribute.class).readOnly(); } - + * public AttributeInspectionPoint(final Method getter) { this.usesField = false; this.f = null; @@ -345,7 +346,7 @@ public AttributeInspectionPoint(final Method getter) { this.type = this.convertTypeToWrappers(getter.getReturnType()); this.readOnly = true; } - + * public AttributeInspectionPoint(final Method getter, final Method setter) { this.usesField = false; this.f = null; @@ -354,17 +355,17 @@ public AttributeInspectionPoint(final Method getter, final Method setter) { this.type = this.convertTypeToWrappers(getter.getReturnType()); this.readOnly = false; } - + * private Class convertTypeToWrappers(final Class cls) { if (!cls.isPrimitive()) return cls; return AttributeInspectionPoint.primitiveToWrapperMap.get(cls); } - + * public Object getValue(final Object obj) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (this.usesField) return this.f.get(obj); return this.getter.invoke(obj); } - + * public void setValue(final Object obj, final Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { if (this.readOnly) throw new InspectionPointException("Attribute is read only."); @@ -375,7 +376,7 @@ public void setValue(final Object obj, final Object value) this.setter.invoke(obj, value); } } - + * /** * Get's {@link #type type} * @@ -384,7 +385,7 @@ public void setValue(final Object obj, final Object value) public Class getType() { return this.type; } - + * /** * Get's {@link #readOnly readOnly} * @@ -393,7 +394,7 @@ public Class getType() { public boolean isReadOnly() { return this.readOnly; } - } + }* /** * A exception that is thrown when an error with a inspection point occurs. @@ -405,7 +406,7 @@ public static class InspectionPointException extends RuntimeException { * generated */ private static final long serialVersionUID = 6324656121971704376L; - + * /** * Constructs a new runtime exception with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -413,7 +414,7 @@ public static class InspectionPointException extends RuntimeException { public InspectionPointException() { super(); } - + * /** * Constructs a new runtime exception with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -424,7 +425,7 @@ public InspectionPointException() { public InspectionPointException(final String message) { super(message); } - + * /** * Constructs a new runtime exception with the specified detail message and cause. *

@@ -441,7 +442,7 @@ public InspectionPointException(final String message) { public InspectionPointException(final String message, final Throwable cause) { super(message, cause); } - + * /** * Constructs a new runtime exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -456,7 +457,7 @@ public InspectionPointException(final String message, final Throwable cause) { public InspectionPointException(final Throwable cause) { super(cause); } - + * /** * Constructs a new runtime exception with the specified detail message, cause, suppression enabled or disabled, * and writable stack trace enabled or disabled. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java index 5fe7331e0..1337bb826 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java @@ -9,14 +9,15 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; +* + import java.io.IOException; import java.lang.reflect.Method; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map; - -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import java.util.Map;* +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -25,8 +26,8 @@ * @author Tim Neumann */ public class InspectionManager { - - private final Map, InspectionData> inspectableClasses = new HashMap<>(); + * + private final Map, InspectionData> inspectableClasses = new HashMap<>();* /** * Create a new inspection manager. @@ -34,7 +35,7 @@ public class InspectionManager { public InspectionManager() { try { final List> classes = ClassFinder.getClassesInClassLoader(c -> true); - + * for (final Class cls : classes) { final InspectionData d = new InspectionData(cls); if (d.hasAnyInspectableElements()) { @@ -44,7 +45,7 @@ public InspectionManager() { } catch (final IOException e) { e.printStackTrace(); } - } + }* /** * Get's all attribute names of the given entity. @@ -57,7 +58,7 @@ public List getAttributeNamesOfEntity(final Entity entity) { final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return Collections.emptyList(); return d.getAttributeNames(); - } + }* /** * Get's all method names of the given entity. @@ -70,7 +71,7 @@ public List getMethodNamesOfEntity(final Entity entity) { final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return Collections.emptyList(); return d.getMethodNames(); - } + }* /** * Checks whether the attribute with the given name in the given entity is writable. @@ -85,7 +86,7 @@ public boolean isAttributeEditable(final Entity entity, final String attributeNa final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return false; return !d.isAttributeReadOnly(attributeName); - } + }* /** * Get's the type of the attribute with the given name in the given entity. @@ -100,7 +101,7 @@ public Class getAttributeType(final Entity entity, final String attributeName final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return null; return d.getAttributeType(attributeName); - } + }* /** * Get the value of the attribute with the given name from the given entity @@ -115,7 +116,7 @@ public Object getAttributeValue(final Entity entity, final String attributeName) final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return null; return d.getAttributeValue(entity, attributeName); - } + }* /** * Set the value of the attribute with the given name in the given entity @@ -132,7 +133,7 @@ public boolean setAttributeValue(final Entity entity, final String attributeName final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return false; return d.setAttributeValue(entity, attributeName, value); - } + }* /** * Get the detail of the method with the given name of the given name. @@ -147,7 +148,7 @@ public Method getMethodDetail(final Entity entity, final String methodName) { final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return null; return d.getMethodByName(methodName); - } + }* /** * Invokes the method with the given name on the given entity. Uses the given arguments. @@ -166,6 +167,5 @@ public Object invokeMethod(final Entity entity, final String methodName, final O final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) throw new IllegalStateException("Not a known inspectable class"); return d.invokeMethod(entity, methodName, args); - } - + }* } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java index a8b540048..b51ca5ee0 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java @@ -8,15 +8,15 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; - + * import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; - + * import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; - - + * + * /** * A annotation specifying that the annotated method should be displayed as a method in the inspector. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java index d023fec70..5b48e6ad3 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal; +* + import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; @@ -25,7 +27,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.internal.tasks.StandardTaskRunner; import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; import de.unistuttgart.informatik.fius.icge.ui.GameWindow; -import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; +import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy;** /** @@ -34,16 +36,15 @@ * @author Tim Neumann */ public class StandardSimulation implements Simulation { - + * private final StandardPlayfield playfield; private final StandardSimulationClock simulationClock; private final StandardActionLog actionLog; private final StandardEntityTypeRegistry entityTypeRegistry; private final TaskVerifier taskVerifier; - private final StandardSimulationProxy simulationProxy; - - private StandardTaskRunner runningTask; - private final StandardProgramRunner programRunner; + private final StandardSimulationProxy simulationProxy;* + private StandardTaskRunner runningTask; + private final StandardProgramRunner programRunner;* /** * Creates a new standard simulation with the given parameters. @@ -71,59 +72,59 @@ public StandardSimulation( this.actionLog = actionLog; this.entityTypeRegistry = entityTypeRegistry; this.taskVerifier = taskVerifier; - + * this.programRunner = new StandardProgramRunner(); - + * this.playfield.initialize(this); - + * if (taskVerifier != null) { taskVerifier.attachToSimulation(this); } - + * this.simulationProxy = new StandardSimulationProxy( this, simulationClock, inspectionManager, entityTypeRegistry, playfield, taskVerifier ); - } + }* @Override public Playfield getPlayfield() { return this.playfield; - } + }* @Override public TaskVerifier getTaskVerifier() { return this.taskVerifier; - } + }* @Override public SimulationClock getSimulationClock() { return this.simulationClock; - } + }* @Override public ActionLog getActionLog() { return this.actionLog; - } + }* @Override public EntityTypeRegistry getEntityTypeRegistry() { return this.entityTypeRegistry; - } + }* @Override public SimulationProxy getSimulationProxyForWindow() { return this.simulationProxy; - } + }* @Override public void attachToWindow(final GameWindow window) { this.attachToWindow(window, false); - } + }* @Override public void attachToWindow(final GameWindow window, final boolean stopWithWindowClose) { this.getSimulationProxyForWindow().attachToGameWindow(window, stopWithWindowClose); - } + }* @Override public void stop() { @@ -133,7 +134,7 @@ public void stop() { } this.programRunner.stopAll(); this.simulationClock.shutdown(); // stop the clock for good - } + }* @Override public void runTask(final Task taskToRun) { @@ -142,7 +143,7 @@ public void runTask(final Task taskToRun) { } this.runningTask = new StandardTaskRunner(taskToRun, this); this.runningTask.runTask(); - } + }* @Override public void runProgram(Program program, S entity) { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java index 6ce7abac6..7b149235f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal; +* + import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -20,12 +22,11 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; -import java.util.function.Function; - +import java.util.function.Function;* import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock; import de.unistuttgart.informatik.fius.icge.simulation.exception.TimerAlreadyRunning; import de.unistuttgart.informatik.fius.icge.simulation.exception.UncheckedInterruptedException; -import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException; +import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException;** /** @@ -36,21 +37,15 @@ * @version 1.0 */ public class StandardSimulationClock implements SimulationClock { - private final Object tickListenerLock = new Object(); - + private final Object tickListenerLock = new Object();* private final List> tickListeners; - private final List> postTickListeners; - - private final Set> operationBoundaries; - - private Consumer animationTickListener; - private StateChangeListener stateChangeListener; - - private TimerTask task; - private final Timer timer; - - private volatile long tickCount; - + private final List> postTickListeners;* + private final Set> operationBoundaries;* + private Consumer animationTickListener; + private StateChangeListener stateChangeListener;* + private TimerTask task; + private final Timer timer;* + private volatile long tickCount;* /** * Setting this to true will signal the clock that it is in shutdown mode. *

@@ -63,9 +58,8 @@ public class StandardSimulationClock implements SimulationClock { *

* */ - private volatile boolean shuttingDown; - - private int period; + private volatile boolean shuttingDown;* + private int period;* /** * Default constructor @@ -78,7 +72,7 @@ public StandardSimulationClock() { this.period = SimulationClock.DEFAULT_RENDER_TICK_PERIOD; this.shuttingDown = false; this.operationBoundaries = Collections.synchronizedSet(new HashSet<>()); - } + }* /** * This internal start function actually starts the timer but does not notify the simulation proxy. If you don't @@ -87,16 +81,16 @@ public StandardSimulationClock() { public synchronized void startInternal() { if (this.isRunning()) throw new TimerAlreadyRunning(); if (this.shuttingDown) return; - + * this.task = new TimerTask() { - + * @Override public void run() { StandardSimulationClock.this.tick(); } }; this.timer.schedule(this.task, 0, this.period); - } + }* /** * This internal stop function actually stops the timer but does not notify the simulation proxy. If you don't know @@ -107,7 +101,7 @@ public synchronized void stopInternal() { this.task.cancel(); } this.task = null; - } + }* /** * Shuts down this clock. @@ -130,62 +124,62 @@ public synchronized void shutdown() { for (final var boundary : Set.copyOf(this.operationBoundaries)) { boundary.cancel(true); } - } + }* @Override public synchronized void setPeriod(final int millis) { this.period = millis; - + * if (this.isRunning()) { this.stop(); this.start(); } - } + }* @Override public int getRenderTickPeriod() { return this.period; - } + }* @Override public int getGameTickPeriod() { return this.period * SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; - } + }* @Override public boolean isRunning() { return this.task != null; - } + }* @Override public synchronized void start() { if (this.stateChangeListener != null) { this.stateChangeListener.clockStarted(); } - + * this.startInternal(); - } + }* @Override public synchronized void stop() { if (this.stateChangeListener != null) { this.stateChangeListener.clockPaused(); } - + * this.stopInternal(); - } + }* @Override public synchronized void step() { if (this.isRunning()) throw new TimerAlreadyRunning(); if (this.shuttingDown) return; - + * new Thread(() -> { StandardSimulationClock.this.tickCount = ((StandardSimulationClock.this.tickCount - (StandardSimulationClock.this.tickCount % 8)) + 7); StandardSimulationClock.this.tick(); }, "single-step").start(); - } + }* /** * Process a tick @@ -204,7 +198,7 @@ private void tick() { this.animationTickListener.accept(this.tickCount); } } - } + }* /** * Process a simulation tick @@ -220,7 +214,7 @@ private void tickSimulation(final long tickNumber) { this.tickListeners.remove(listener); } } - + * for (final var listener : List.copyOf(this.postTickListeners)) { //Don't continue to process tick when shutting down. if (this.shuttingDown) return; @@ -228,7 +222,7 @@ private void tickSimulation(final long tickNumber) { this.postTickListeners.remove(listener); } } - } + }* /** * Set the animation tick listener, that gets called every animation tick and is responsible for informing the UI. @@ -242,7 +236,7 @@ public void setAnimationTickListener(final Consumer listener) { if ((this.animationTickListener == null) || (listener == null)) { this.animationTickListener = listener; } else throw new ListenerSetException(); - } + }* /** * Set the state change listener, that gets called when the clock get's started or paused through public API and is @@ -257,7 +251,7 @@ public void setStateChangeListener(final StateChangeListener listener) { if ((this.stateChangeListener == null) || (listener == null)) { this.stateChangeListener = listener; } else throw new ListenerSetException(); - } + }* /** * Remove the state change listener, that gets called when the clock get's started or paused through public API and @@ -265,7 +259,7 @@ public void setStateChangeListener(final StateChangeListener listener) { */ public void removeStateChangeListener() { this.stateChangeListener = null; - } + }* @Override public void registerTickListener(final Function listener) { @@ -273,7 +267,7 @@ public void registerTickListener(final Function listener) { synchronized (this.tickListenerLock) { this.tickListeners.add(listener); } - } + }* @Override public void registerPostTickListener(final Function listener) { @@ -281,18 +275,18 @@ public void registerPostTickListener(final Function listener) { synchronized (this.tickListenerLock) { this.postTickListeners.add(listener); } - } + }* @Override public long getLastTickNumber() { //not rounding is intended here as we'd need floor and casting is the same as floor for positive integers return this.tickCount / SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; - } + }* @Override public long getLastRenderTickNumber() { return this.tickCount; - } + }* @Override public void scheduleOperationAtTick(final long tick, final CompletableFuture endOfOperation) { @@ -327,17 +321,17 @@ public void scheduleOperationAtTick(final long tick, final CompletableFuture endOfOperation) { this.scheduleOperationAtTick(this.getLastTickNumber() + ticks, endOfOperation); - } + }* @Override public void scheduleOperationAtNextTick(final CompletableFuture endOfOperation) { this.scheduleOperationInTicks(1, endOfOperation); - } + }* /** * The interface for a listener listening for simulation clock starts and stops. The listener is only informed when @@ -348,7 +342,7 @@ public interface StateChangeListener { * The clock was started. */ void clockStarted(); - + * /** * The clock was paused/stopped. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java index 20a493495..7060924c1 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java @@ -9,12 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal; +* + import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Consumer; - +import java.util.function.Consumer;* import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier; @@ -31,7 +32,7 @@ import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode; import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ClockButtonState; -import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState; +import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState;** /** @@ -43,30 +44,26 @@ * @version 1.0 */ public class StandardSimulationProxy implements SimulationProxy { - + * /** A lookup table for the simulation times */ public static final int[] SIMULATION_TIMES = { // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 1000, 415, 200, 115, 75, 50, 42, 34, 26, 18, 10 // These values are aproximated by two functions originally by haslersn which where modified by waeltkts - }; - + };* // GAME WINDOW private GameWindow gameWindow; - private boolean stopSimulationWithWindowClose = false; - + private boolean stopSimulationWithWindowClose = false;* // MANAGERS - private final InspectionManager inspectionManager; - + private final InspectionManager inspectionManager;* // CURRENT SIMULATION - private final Simulation simulation; - private final StandardEntityTypeRegistry entityTypeRegistry; - private final StandardSimulationClock simulationClock; - private final StandardPlayfield playfield; - private final TaskVerifier taskVerifier; - private final Map simualtionSidebarMap; - - private Entity entityToInspect; + private final Simulation simulation; + private final StandardEntityTypeRegistry entityTypeRegistry; + private final StandardSimulationClock simulationClock; + private final StandardPlayfield playfield; + private final TaskVerifier taskVerifier; + private final Map simualtionSidebarMap;* + private Entity entityToInspect;* /** * Create a new standard simulation proxy @@ -95,7 +92,7 @@ public StandardSimulationProxy( this.playfield = playfield; this.taskVerifier = taskVerifier; this.simualtionSidebarMap = new ConcurrentHashMap<>(); - + * // attach tick listeners to simulation clock // only do this once per SimulationProxy as unsetting these listeners is not possible atm this.simulationClock.setAnimationTickListener(new Consumer() { @@ -106,24 +103,24 @@ public void accept(final Long tickCount) { } } }); - + * this.simulationClock.registerPostTickListener(unused -> { updateEntityInspector(); return true; // post tick listener could be removed by returning false here }); - } + }* @Override public void attachToGameWindow(final GameWindow window) { this.attachToGameWindow(window, false); - } + }* @Override public void attachToGameWindow(final GameWindow window, final boolean stopWithWindowClose) { if (this.gameWindow != null) throw new IllegalStateException("Already attached to a window!"); this.gameWindow = window; this.stopSimulationWithWindowClose = stopWithWindowClose; - + * //Simulation Clock if (this.simulationClock.isRunning()) { this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); @@ -131,21 +128,21 @@ public void attachToGameWindow(final GameWindow window, final boolean stopWithWi this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); } this.simulationSpeedChange(this.gameWindow.getToolbar().getSpeedSliderPosition()); - + * this.simulationClock.setStateChangeListener(new StateChangeListener() { @Override public void clockStarted() { StandardSimulationProxy.this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); } - + * @Override public void clockPaused() { StandardSimulationProxy.this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); } }); - + * //EntityDrawing - + * this.playfield.setDrawablesChangedListener(new Consumer>() { @Override public void accept(final List drawables) { @@ -154,10 +151,10 @@ public void accept(final List drawables) { } } }); - + * //ControlButtonState this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.VIEW); - + * //EntitySelection this.entityTypeRegistry.setEntityRegisteredListener((entityName, textureHandle) -> { if (StandardSimulationProxy.this.gameWindow != null) { @@ -175,7 +172,7 @@ public void accept(final List drawables) { } catch (@SuppressWarnings("unused") final NullPointerException e) { // catching exception instead of checking before allows to avoid synchronization here } - + * this.gameWindow.getEntitySidebar().setSimulationTreeRootNode(this.playfield.getSimulationTree()); this.gameWindow.getEntitySidebar().enableSimulationTree(); this.playfield.setSimulationTreeEntityAddedListener((node, entity) -> { @@ -186,18 +183,18 @@ public void accept(final List drawables) { this.simualtionSidebarMap.remove(node); this.gameWindow.getEntitySidebar().updateSimulationTree(); }); - + * this.gameWindow.getEntitySidebar().disableEntityInspector(); - + * // taskState TaskInformation task = null; if (this.taskVerifier != null) { task = this.taskVerifier.getTaskInformation(); } this.gameWindow.getTaskStatusDisplay().setTaskInformation(task); - + * this.gameWindow.setSimulationProxy(this); - } + }* @Override public void windowClosed() { @@ -208,15 +205,15 @@ public void windowClosed() { this.playfield.removeSimulationTreeEntityAddedListener(); this.playfield.removeSimulationTreeEntityRemovedListener(); this.entityTypeRegistry.removeEntityRegisteredListener(); - + * // remove gameWindow reference this.gameWindow = null; - + * // stop simulation if (this.stopSimulationWithWindowClose) { this.simulation.stop(); } - } + }* @Override public void buttonPressed(final ButtonType type) { @@ -227,7 +224,7 @@ public void buttonPressed(final ButtonType type) { } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); break; - + * case STEP: if (!this.simulationClock.isRunning()) { this.simulationClock.step(); @@ -236,37 +233,37 @@ public void buttonPressed(final ButtonType type) { } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); break; - + * case PAUSE: if (this.simulationClock.isRunning()) { this.simulationClock.stopInternal(); } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); break; - + * case VIEW: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.VIEW); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.VIEW); break; - + * case ADD: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.ADD); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.ADD); break; - + * case SUB: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.SUB); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.SUB); break; - + * default: } - } + }* @Override public void simulationSpeedChange(final int value) { this.simulationClock.setPeriod(StandardSimulationProxy.SIMULATION_TIMES[value]); - } + }* @Override public void selectedEntityChanged(final String name) { @@ -274,9 +271,9 @@ public void selectedEntityChanged(final String name) { if ((name != null) && !name.equals("")) { textureHandle = this.entityTypeRegistry.getTextureHandleOfEntityType(name); } - + * this.gameWindow.getPlayfieldDrawer().setSelectedEntityType(name, textureHandle); - } + }* @Override public void refreshTaskInformation() { @@ -286,7 +283,7 @@ public void refreshTaskInformation() { task = this.taskVerifier.getTaskInformation(); } this.gameWindow.getTaskStatusDisplay().setTaskInformation(task); - } + }* @Override public void spawnEntityAt(final String typeName, final int x, final int y) { @@ -301,12 +298,12 @@ public void spawnEntityAt(final String typeName, final int x, final int y) { System.out.println("Something went wrong while creating new entity."); e.printStackTrace(); } - } + }* @Override public void clearCell(final int x, final int y) { final List toRemove = this.playfield.getEntitiesAt(new Position(x, y)); - + * toRemove.forEach(entity -> { try { this.playfield.removeEntity(entity); @@ -314,11 +311,11 @@ public void clearCell(final int x, final int y) { // nothing to do because entity was either null or already not on the field } }); - } + }* private EntityInspectorEntry[] getEntries(final Entity e) { final List result = new ArrayList<>(); - + * for (final String name : this.inspectionManager.getAttributeNamesOfEntity(e)) { String type = "string"; if (!this.inspectionManager.isAttributeEditable(e, name)) { @@ -337,7 +334,7 @@ private EntityInspectorEntry[] getEntries(final Entity e) { this.updateEntityInspector(); })); } - + * for (final String name : this.inspectionManager.getMethodNamesOfEntity(e)) { final String type = "function"; result.add(new EntityInspectorEntry(name, type, "", unused -> { @@ -348,13 +345,13 @@ private EntityInspectorEntry[] getEntries(final Entity e) { })); } return result.toArray(new EntityInspectorEntry[result.size()]); - } + }* private void updateEntityInspector() { if (this.gameWindow == null) return; if (this.entityToInspect == null) return; this.gameWindow.getEntitySidebar().setEntityInspectorEntries(this.getEntries(this.entityToInspect)); - } + }* @Override public void selectedSimulationEntityChange(final SimulationTreeNode node) { @@ -363,7 +360,7 @@ public void selectedSimulationEntityChange(final SimulationTreeNode node) { } else { this.entityToInspect = this.simualtionSidebarMap.get(node); } - + * if (this.entityToInspect != null) { this.gameWindow.getEntitySidebar().enableEntityInspector(); this.gameWindow.getEntitySidebar().setEntityInspectorName(this.entityToInspect.toString()); @@ -373,7 +370,7 @@ public void selectedSimulationEntityChange(final SimulationTreeNode node) { this.gameWindow.getEntitySidebar().setEntityInspectorEntries(new EntityInspectorEntry[0]); this.gameWindow.getEntitySidebar().disableEntityInspector(); } - } + }* @Override public void entityValueChange(final String name, final String value) { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java index 5ff023cef..9e0c2ee36 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java @@ -9,16 +9,17 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.actions; +* + import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map; - +import java.util.Map;* import de.unistuttgart.informatik.fius.icge.simulation.MultiTypedList; import de.unistuttgart.informatik.fius.icge.simulation.actions.Action; import de.unistuttgart.informatik.fius.icge.simulation.actions.ActionLog; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityAction; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -27,30 +28,30 @@ * @author Tim Neumann */ public class StandardActionLog implements ActionLog { - + * private final Object actionsLock = new Object(); private final Object entityActionsLock = new Object(); - + * private final MultiTypedList actions = new MultiTypedList<>(); - + * private final Map> entityActions = new HashMap<>(); - + * private boolean consoleLog = true; - + * @Override public List getAllActions() { synchronized (this.actionsLock) { return this.actions.get(Action.class, true); } } - + * @Override public List getActionsOfType(final Class type, final boolean includeSubclasses) { synchronized (this.actionsLock) { return this.actions.get(type, includeSubclasses); } } - + * @Override public List getAllActionsOfEntity(final Entity entity) { synchronized (this.entityActionsLock) { @@ -59,7 +60,7 @@ public List getAllActionsOfEntity(final Entity entity) { return list.get(EntityAction.class, true); } } - + * @Override public List getActionsOfTypeOfEntity( final Entity entity, final Class type, final boolean includeSubclasses @@ -70,7 +71,7 @@ public List getActionsOfTypeOfEntity( return list.get(type, includeSubclasses); } } - + * @Override public void logAction(final Action actionToLog) { if (actionToLog instanceof EntityAction) { @@ -90,12 +91,12 @@ public void logAction(final Action actionToLog) { System.out.println(actionToLog.getDescription()); } } - + * @Override public void setConsoleOutput(boolean enable) { this.consoleLog = enable; } - + * @Override public boolean getConsoleOutput() { return this.consoleLog; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java index cb32e5870..e55819f6d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java @@ -9,16 +9,17 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.entity; +* + import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.function.Supplier; - +import java.util.function.Supplier;* import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; import de.unistuttgart.informatik.fius.icge.simulation.entity.EntityTypeRegistry; import de.unistuttgart.informatik.fius.icge.simulation.exception.ElementExistsException; -import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException; +import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException;** /** @@ -27,11 +28,10 @@ * @author Fabian Bühler */ public class StandardEntityTypeRegistry implements EntityTypeRegistry { - + * private final Map> typeToEntityFactory = new HashMap<>(); - private final Map typeToTextureHandle = new HashMap<>(); - - private EntityRegisteredListener entityRegisteredListener; + private final Map typeToTextureHandle = new HashMap<>();* + private EntityRegisteredListener entityRegisteredListener;* @Override public void registerEntityType(final String typeName, final String textureHandle, final Class entityType) { @@ -49,7 +49,7 @@ public void registerEntityType(final String typeName, final String textureHandle } }; this.registerEntityType(typeName, textureHandle, entityFactory); - } + }* @Override public synchronized void registerEntityType( @@ -63,22 +63,22 @@ public synchronized void registerEntityType( if (this.typeToEntityFactory.containsKey(typeName)) throw new ElementExistsException(); this.typeToEntityFactory.put(typeName, entityFactory); this.typeToTextureHandle.put(typeName, textureHandle); - + * if (this.entityRegisteredListener != null) { this.entityRegisteredListener.entityWasRegistered(typeName, textureHandle); } - } + }* @Override public Set getRegisteredEntityTypes() { return this.typeToEntityFactory.keySet(); - } + }* @Override public String getTextureHandleOfEntityType(final String typeName) { if ((typeName == null) || typeName.equals("")) throw new IllegalArgumentException("Type name cannot be null or empty!"); return this.typeToTextureHandle.get(typeName); - } + }* @Override public Entity getNewEntity(final String typeName) { @@ -86,7 +86,7 @@ public Entity getNewEntity(final String typeName) { final Supplier entityFactory = this.typeToEntityFactory.get(typeName); if (entityFactory == null) return null; return entityFactory.get(); - } + }* /** * Set an entity selector listener that gets informed about all entity types added. @@ -105,14 +105,14 @@ public synchronized void setEntityRegisteredListener(final EntityRegisteredListe } this.entityRegisteredListener = listener; } else throw new ListenerSetException(); - } + }* /** * Remove the set entity selector listener that gets informed about all entity types added. */ public synchronized void removeEntityRegisteredListener() { this.entityRegisteredListener = null; - } + }* /** * The interface for when an entity is registered diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java index a42c37afc..68469e60b 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java @@ -9,9 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.playfield; +* + import de.unistuttgart.informatik.fius.icge.simulation.MultiTypedList; import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -21,7 +23,7 @@ */ public class PlayfieldCell extends MultiTypedList { private final Position pos; - + * /** * Create a new playfield cell, * @@ -32,7 +34,7 @@ public PlayfieldCell(final Position pos) { super(); this.pos = pos; } - + * /** * @return the position of this cell */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java index 5aa777a98..7bc9cc970 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.playfield; +* + import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; @@ -17,8 +19,7 @@ import java.util.Timer; import java.util.TimerTask; import java.util.function.BiConsumer; -import java.util.function.Consumer; - +import java.util.function.Consumer;* import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; @@ -33,7 +34,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.internal.StandardSimulation; import de.unistuttgart.informatik.fius.icge.ui.Drawable; import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode; -import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException; +import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException;** /** @@ -42,22 +43,17 @@ * @author Tim Neumann */ public class StandardPlayfield implements Playfield { - private WeakReference sim; - - private final Object playfieldLock = new Object(); - - private final Map cells = new HashMap<>(); - private final Map entityPositions = new HashMap<>(); - - private SimulationTreeNode simualtionTreeRootNode; - + private WeakReference sim;* + private final Object playfieldLock = new Object();* + private final Map cells = new HashMap<>(); + private final Map entityPositions = new HashMap<>();* + private SimulationTreeNode simualtionTreeRootNode;* private BiConsumer simulationTreeEntityAddedListener; - private Consumer simulationTreeEntityRemovedListener; - - private Consumer> drawablesChangedListener; - - private boolean awaitingEntityDraw = false; - private long timeBetweenDraws = 32; //the time between draw calls in milliseconds + private Consumer simulationTreeEntityRemovedListener;* + private Consumer> drawablesChangedListener;* + private boolean awaitingEntityDraw = false; + private long timeBetweenDraws = 32; //the time between draw calls in milliseconds + * /** * Initialize the playfield for the given simulation @@ -71,18 +67,18 @@ public void initialize(final StandardSimulation simulation) { this.drawEntities(); return true; }); - + * this.simualtionTreeRootNode = new SimulationTreeNode("root", "Entities", "", false); - + * new Timer().scheduleAtFixedRate(new TimerTask() { - + * @Override public void run() { drawEntitiesInternal(); } - + * }, 0, this.timeBetweenDraws); - } + }* /** * @throws IllegalStateException @@ -94,7 +90,7 @@ public Simulation getSimulation() { final Simulation simulation = this.sim.get(); if (simulation == null) throw new IllegalStateException("This playfield is not part of any simulation."); return simulation; - } + }* /** * Queues a draw update to the playfield drawer. Draw updates are sent to the playfield drawer automatically every @@ -102,7 +98,7 @@ public Simulation getSimulation() { */ public void drawEntities() { this.awaitingEntityDraw = true; - } + }* /** * Converts all entities to drawables and sends them to the playfield drawer. @@ -127,13 +123,13 @@ private void drawEntitiesInternal() { } catch (@SuppressWarnings("unused") final IllegalStateException e) { //If we are not attached to a simultion we do not need to draw anything } - - } + * + }* @Override public List getAllEntities() { return this.getAllEntitiesOfType(Entity.class, true); - } + }* @Override public List getAllEntitiesOfType(final Class type, final boolean includeSubclasses) { @@ -145,13 +141,13 @@ public List getAllEntitiesOfType(final Class } } return result; - } + }* @Override public List getEntitiesAt(final Position pos) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); return this.getEntitiesOfTypeAt(pos, Entity.class, true); - } + }* @Override public List getEntitiesOfTypeAt( @@ -167,7 +163,7 @@ public List getEntitiesOfTypeAt( } } return result; - } + }* private void addEntityToCell(final Position pos, final Entity entity) { synchronized (this.playfieldLock) { @@ -178,7 +174,7 @@ private void addEntityToCell(final Position pos, final Entity entity) { } cell.add(entity); } - } + }* private void removeEntityFromCell(final Position pos, final Entity entity) { synchronized (this.playfieldLock) { @@ -192,30 +188,30 @@ private void removeEntityFromCell(final Position pos, final Entity entity) { this.cells.remove(pos, cell); } } - } + }* @Override public void addEntity(final Position pos, final Entity entity) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); if (entity == null) throw new IllegalArgumentException("The given entity is null."); - + * synchronized (this.playfieldLock) { if (this.entityPositions.containsKey(entity)) throw new EntityAlreadyOnFieldExcpetion("The given entity" + entity + "is already on this playfield."); - + * entity.initOnPlayfield(this); - + * this.addEntityToCell(pos, entity); - + * this.entityPositions.put(entity, pos); - + * this.getSimulation().getActionLog() .logAction(new EntitySpawnAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, this, pos)); - + * this.addEntityToSimulationTree(entity); } this.drawEntities(); - } + }* private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean create) { final List> classHiera = new ArrayList<>(); @@ -227,7 +223,7 @@ private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean } while (Entity.class.isAssignableFrom(clazz)); } SimulationTreeNode node = this.simualtionTreeRootNode; - + * hieraLoop: for (final Class clazz : classHiera) { for (final SimulationTreeNode child : node.getChildren()) { if (child.getElementId().equals(clazz.getName())) { @@ -243,38 +239,38 @@ private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean } else return null; } return node; - } + }* private void addEntityToSimulationTree(final Entity entity) { final SimulationTreeNode newNode = new SimulationTreeNode( Integer.toHexString(entity.hashCode()), entity.toString(), entity.getDrawInformation().getTextureHandle() ); this.findNodeForEntity(entity, true).appendChild(newNode); - + * if (this.simulationTreeEntityAddedListener != null) { // TODO check for bugs with simulation tree when window is reattached or attached late this.simulationTreeEntityAddedListener.accept(newNode, entity); } - } + }* @Override public void moveEntity(final Entity entity, final Position pos) { this.moveEntity(entity, pos, null); - } + }* @Override public void moveEntity(final Entity entity, final Position pos, final EntityMoveAction action) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); if (entity == null) throw new IllegalArgumentException("The given entity is null."); - + * synchronized (this.playfieldLock) { if (!this.entityPositions.containsKey(entity)) throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); - + * EntityMoveAction actionToLog = action; - + * final Position oldPos = this.entityPositions.get(entity); - + * if (actionToLog == null) { actionToLog = new EntityTeleportAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, oldPos, pos); } else { @@ -284,22 +280,22 @@ public void moveEntity(final Entity entity, final Position pos, final EntityMove throw new IllegalArgumentException("Given action does not start at current position of given entity."); if (!actionToLog.to().equals(pos)) throw new IllegalArgumentException("Given action does not end at given pos."); } - + * this.removeEntityFromCell(oldPos, entity); this.addEntityToCell(pos, entity); this.entityPositions.put(entity, pos); - + * this.getSimulation().getActionLog().logAction(actionToLog); - + * } this.drawEntities(); - } + }* private void removeEntityFromSimulationTree(final Entity entity) { final SimulationTreeNode node = this.findNodeForEntity(entity, false); - + * if (node == null) return; - + * for (final SimulationTreeNode child : node.getChildren()) { if (child.getElementId().equals(Integer.toHexString(entity.hashCode()))) { node.removeChild(child); @@ -309,28 +305,28 @@ private void removeEntityFromSimulationTree(final Entity entity) { } } } - } + }* @Override public void removeEntity(final Entity entity) { if (entity == null) throw new IllegalArgumentException("The given entity is null."); - + * synchronized (this.playfieldLock) { if (!this.entityPositions.containsKey(entity)) throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); - + * final Position pos = this.entityPositions.get(entity); this.removeEntityFromCell(pos, entity); this.entityPositions.remove(entity, pos); - + * this.getSimulation().getActionLog() .logAction(new EntityDespawnAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, this)); - + * this.removeEntityFromSimulationTree(entity); - + * } this.drawEntities(); - } + }* @Override public Position getEntityPosition(final Entity entity) { @@ -340,7 +336,7 @@ public Position getEntityPosition(final Entity entity) { if (pos == null) throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); return pos; } - } + }* @Override public boolean containsEntity(final Entity entity) { @@ -348,7 +344,7 @@ public boolean containsEntity(final Entity entity) { synchronized (this.playfieldLock) { return this.entityPositions.containsKey(entity); } - } + }* @Override public boolean isSolidEntityAt(final Position pos) { @@ -357,14 +353,14 @@ public boolean isSolidEntityAt(final Position pos) { if (entity.isCurrentlySolid()) return true; } return false; - } + }* /** * @return the root node of the simulation tree */ public SimulationTreeNode getSimulationTree() { return this.simualtionTreeRootNode; - } + }* /** * Set the listener for when an entity is added to the simulation tree. @@ -376,14 +372,14 @@ public void setSimulationTreeEntityAddedListener(final BiConsumer> listener) if ((this.drawablesChangedListener == null) || (listener == null)) { this.drawablesChangedListener = listener; } else throw new ListenerSetException(); - } + }* /** * Remove the listener for when the drawables on the playfield changed. This listener is responsible for informing @@ -423,7 +419,7 @@ public void setDrawablesChangedListener(final Consumer> listener) */ public void removeDrawablesChangedListener() { this.drawablesChangedListener = null; - } + }* @Override public String toString() { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java index 55106863d..5b6c6d82f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.programs; +* + import java.util.HashMap; import java.util.Map; import java.util.concurrent.CancellationException; @@ -16,11 +18,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinWorkerThread; -import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; - +import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;* import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; -import de.unistuttgart.informatik.fius.icge.simulation.exception.UncheckedInterruptedException; +import de.unistuttgart.informatik.fius.icge.simulation.exception.UncheckedInterruptedException;** /** @@ -29,17 +30,16 @@ * @author Fabian Bühler */ public class StandardProgramRunner { - - private ExecutorService executor; - - private final Map> runningPrograms = new HashMap<>(); + * + private ExecutorService executor;* + private final Map> runningPrograms = new HashMap<>();* /** * Standard constructor setting up the executor for the Futures. */ public StandardProgramRunner() { this.executor = this.createExecutor(); - } + }* /** * Create an executor that uses named threads for a better debugging experience, @@ -53,9 +53,9 @@ private ExecutorService createExecutor() { worker.setDaemon(true); return worker; }; - + * return new ForkJoinPool(Runtime.getRuntime().availableProcessors(), factory, null, false); - } + }* /** * Run a program for the given entity inside a completable future. @@ -79,7 +79,7 @@ public void run(final Program program, final throw new IllegalStateException("Already running a program for entity " + entity.toString() + "!"); } } - + * final CompletableFuture future = CompletableFuture.runAsync(() -> { try { program.run(entity); @@ -94,10 +94,10 @@ public void run(final Program program, final System.out.println("----------------------------------------------"); } }, this.executor); - + * // set the running program in the entityMap this.runningPrograms.put(entity, future); - } + }* /** * Get the running program as a CompletableFuture. @@ -108,7 +108,7 @@ public void run(final Program program, final */ public CompletableFuture getRunningProgram(Entity entity) { return this.runningPrograms.get(entity); - } + }* /** * Stop all running programs. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java index 9be58f903..b5c1365a0 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java @@ -9,15 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.tasks; +* + import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; - +import java.util.concurrent.ThreadFactory;* import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.exception.UncheckedInterruptedException; -import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; +import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task;** /** @@ -26,13 +27,11 @@ * @author Tim Neumann */ public class StandardTaskRunner { - - private final ExecutorService executor; - - private final Task taskToRun; - private final Simulation sim; - - private CompletableFuture taskResult; + * + private final ExecutorService executor;* + private final Task taskToRun; + private final Simulation sim;* + private CompletableFuture taskResult;* /** * Create a new task runner. @@ -50,10 +49,10 @@ public StandardTaskRunner(final Task taskToRun, final Simulation sim) { Thread worker = new Thread(runnable, "TaskThread-" + taskToRun.toString()); return worker; }; - + * // only one task can be run per task runner so parallelism of one is ok this.executor = Executors.newSingleThreadExecutor(factory); - } + }* /** * Run the given task. @@ -66,9 +65,9 @@ public StandardTaskRunner(final Task taskToRun, final Simulation sim) { public CompletableFuture runTask() { if (this.taskResult != null) return this.taskResult; this.taskResult = CompletableFuture.supplyAsync(this::executeTask, this.executor); - + * return this.taskResult; - } + }* private boolean executeTask() { try { @@ -94,7 +93,7 @@ private boolean executeTask() { System.out.println("----------------------------------------------"); return false; } - } + }* /** * Cancel the completable future and intterupt the underlying thread. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java index 49d8580c8..7ab37c2db 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java @@ -8,11 +8,11 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.programs; - + * import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; - - + * + * /** * The interface for programs that operate on entities. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java index 276a88b7b..7f9294f13 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java @@ -8,10 +8,10 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.tasks; - + * import de.unistuttgart.informatik.fius.icge.simulation.Simulation; - - + * + * /** * The interface for a task to be solved by students. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java index ac0db9320..da115587b 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java @@ -9,11 +9,12 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.tools; -import java.util.function.Supplier; +* +import java.util.function.Supplier;* import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** /** @@ -23,7 +24,7 @@ */ public class PlayfieldModifier { private final Playfield playfield; - + * /** * Create a new playfield modifier for the given playfield. * @@ -33,7 +34,7 @@ public class PlayfieldModifier { public PlayfieldModifier(final Playfield playfield) { this.playfield = playfield; } - + * /** * Place the given entity at the given position on the playfield. * @@ -45,7 +46,7 @@ public PlayfieldModifier(final Playfield playfield) { public void placeEntityAt(final Entity entity, final Position position) { this.playfield.addEntity(position, entity); } - + * /** * Place the given number of entities supplied by the given factory at the given location. * @@ -61,7 +62,7 @@ public void placeMultipleEntitiesAt(final Supplier entityFacto placeEntityAt(entityFactory.get(), position); } } - + * /** * Place an entity supplied by the given factory at each of the given positions * diff --git a/ICGE-Simulation/src/main/java/module-info.java b/ICGE-Simulation/src/main/java/module-info.java index 9117dd04f..5e6027aba 100644 --- a/ICGE-Simulation/src/main/java/module-info.java +++ b/ICGE-Simulation/src/main/java/module-info.java @@ -9,7 +9,7 @@ */ module de.unistuttgart.informatik.fius.icge.simulation { requires transitive de.unistuttgart.informatik.fius.icge.ui; - + * exports de.unistuttgart.informatik.fius.icge.simulation; exports de.unistuttgart.informatik.fius.icge.simulation.entity; exports de.unistuttgart.informatik.fius.icge.simulation.exception; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java index 400dbeec8..ea67febaa 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java @@ -9,28 +9,29 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* /** * A class containing all information needed to draw a moving object onto the playfield by a {@link PlayfieldDrawer}. * * @author Fabian Bühler */ public class AnimatedDrawable implements Drawable { - + * private final double xStart; private final double yStart; private final double xEnd; private final double yEnd; - + * private final int z; - + * private final String textureHandle; - + * private final long tickStart; private final long tickEnd; private final long duration; - + * private long currentTick = 0; - + * /** * Create a new animated Drawable. * @@ -66,12 +67,12 @@ public AnimatedDrawable( this.z = z; this.textureHandle = textureHandle; } - + * @Override public void setCurrentTick(final long renderTick) { this.currentTick = renderTick; } - + * @Override public double getX() { if (this.currentTick <= this.tickStart) return this.xStart; @@ -79,7 +80,7 @@ public double getX() { final double completion = (this.currentTick - this.tickStart) / (double) this.duration; return ((this.xEnd - this.xStart) * completion) + this.xStart; } - + * @Override public double getY() { if (this.currentTick <= this.tickStart) return this.yStart; @@ -87,27 +88,27 @@ public double getY() { final double completion = (this.currentTick - this.tickStart) / (double) this.duration; return ((this.yEnd - this.yStart) * completion) + this.yStart; } - + * @Override public int getZ() { return this.z; } - + * @Override public String getTextureHandle() { return this.textureHandle; } - + * @Override public boolean isTilable() { return false; } - + * @Override public boolean isAnimated() { return this.currentTick <= this.tickEnd; } - + * /** * Get's {@link #xStart xStart} * @@ -116,7 +117,7 @@ public boolean isAnimated() { public double getxStart() { return this.xStart; } - + * /** * Get's {@link #yStart yStart} * @@ -125,7 +126,7 @@ public double getxStart() { public double getyStart() { return this.yStart; } - + * /** * Get's {@link #xEnd xEnd} * @@ -134,7 +135,7 @@ public double getyStart() { public double getxEnd() { return this.xEnd; } - + * /** * Get's {@link #yEnd yEnd} * @@ -143,7 +144,7 @@ public double getxEnd() { public double getyEnd() { return this.yEnd; } - + * /** * Get's {@link #tickStart tickStart} * @@ -152,7 +153,7 @@ public double getyEnd() { public long getTickStart() { return this.tickStart; } - + * /** * Get's {@link #tickEnd tickEnd} * @@ -161,7 +162,7 @@ public long getTickStart() { public long getTickEnd() { return this.tickEnd; } - + * /** * Get's {@link #duration duration} * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java index 13766b9ec..bdcb01e2d 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java @@ -9,41 +9,42 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* /** * A class containing all information needed to draw an object onto the playfield by a {@link PlayfieldDrawer}. * * @author Tim Neumann */ public class BasicDrawable implements Drawable { - + * /** * The x coordinate of the drawable. * * The coordinate system is based on cells where fractionals denote positions between cells. */ private final double x; - + * /** * The y coordinate of the drawable. * * The coordinate system is based on cells where fractionals denote positions between cells. */ private final double y; - + * /** * The z value of the drawable. * * The z value is used to decide the drawing order of Drawables in the same cell. */ private final int z; - + * /** * The handle of the texture for this drawable. * * The texture must be registered in the TextureRegistry. */ private final String textureHandle; - + * /** * Create a new Drawable. * @@ -62,22 +63,22 @@ public BasicDrawable(final double x, final double y, final int z, final String t this.z = z; this.textureHandle = textureHandle; } - + * @Override public double getX() { return this.x; } - + * @Override public double getY() { return this.y; } - + * @Override public int getZ() { return this.z; } - + * @Override public String getTextureHandle() { return this.textureHandle; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java index 5c20d0cca..d8deb445e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* /** * A Console to show text output of the software * @@ -16,7 +17,7 @@ * @version 2.0 */ public interface Console { - + * /** * Clears the console in the ui. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java index d90d8f088..df80f6393 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* /** * A interface providing all information needed to draw an object onto the playfield by a {@link PlayfieldDrawer}. * @@ -17,7 +18,7 @@ * @version 1.0 */ public interface Drawable extends Comparable { - + * /** * Get the x coordinate of the drawable. * @@ -26,7 +27,7 @@ public interface Drawable extends Comparable { * @return returns the X position as a double */ double getX(); - + * /** * Get the y coordinate of the drawable. * @@ -35,7 +36,7 @@ public interface Drawable extends Comparable { * @return returns the Y position as a double */ double getY(); - + * /** * Get the z value of the drawable. * @@ -44,7 +45,7 @@ public interface Drawable extends Comparable { * @return returns the Z position as a double */ int getZ(); - + * /** * Get the handle of the texture for this drawable. * @@ -53,7 +54,7 @@ public interface Drawable extends Comparable { * @return returns the texture handle as a String */ String getTextureHandle(); - + * /** * Return wether this Drawable can be drawn tiled if multiple are present in the same cell. * @@ -62,7 +63,7 @@ public interface Drawable extends Comparable { default boolean isTilable() { return true; } - + * /** * Return wether the Drawable is animated. * @@ -71,7 +72,7 @@ default boolean isTilable() { default boolean isAnimated() { return false; } - + * /** * Set the current render tick for animated drawables. * @@ -81,7 +82,7 @@ default boolean isAnimated() { default void setCurrentTick(final long renderTick) { return; // default to noop } - + * @Override default int compareTo(final Drawable o) { double compareResult = 0; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java index 51c9203a2..c1907c4c6 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java @@ -9,22 +9,24 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -import java.util.function.Consumer; +* + +import java.util.function.Consumer;** /** * EntityInspectorEntry */ public class EntityInspectorEntry { - + * private final String name; - + * private final String type; - + * private final String value; - + * private final Consumer callback; - + * /** * Default constructor * @@ -43,7 +45,7 @@ public EntityInspectorEntry(final String name, final String type, final String v this.value = value; this.callback = callback; } - + * /** * Getter for the name * @@ -52,7 +54,7 @@ public EntityInspectorEntry(final String name, final String type, final String v public String getName() { return this.name; } - + * /** * Getter for the type * @@ -61,7 +63,7 @@ public String getName() { public String getType() { return this.type; } - + * /** * Getter for the value * @@ -70,7 +72,7 @@ public String getType() { public String getValue() { return this.value; } - + * /** * This function runs the callback of the item * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java index 1a9d56f32..639bbb3ad 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* /** * A sidebar showing all current entities * @@ -16,7 +17,7 @@ * @version 1.0 */ public interface EntitySidebar { - + * /** * Setter function to attach a SimulationTree to the entity sidebar. * @@ -24,12 +25,12 @@ public interface EntitySidebar { * The root node of the simulation tree. */ void setSimulationTreeRootNode(SimulationTreeNode treeNode); - + * /** * This function should be called if the simulation tree changes. */ void updateSimulationTree(); - + * /** * This function deletes all currently created ui elements and creates a new inspector * @@ -37,14 +38,14 @@ public interface EntitySidebar { * The entries to create the inspector from */ void setEntityInspectorEntries(EntityInspectorEntry[] entries); - + * /** * Get the selected element of the simulation tree. * * @return the currently selected SimulationTreeNode */ SimulationTreeNode getSimulationTreeSelectedElement(); - + * /** * Set the selected element of the simulation tree. * @@ -52,17 +53,17 @@ public interface EntitySidebar { * The SimulationTreeNode to select */ void setSimulationTreeSelectedElement(SimulationTreeNode node); - + * /** * Enable the simulation tree. */ void enableSimulationTree(); - + * /** * Disable the simulation tree. */ void disbaleSimulationTree(); - + * /** * Set the name of the entity inspector. * @@ -70,19 +71,19 @@ public interface EntitySidebar { * The name to set */ void setEntityInspectorName(String name); - + * /** * Get the current name of the entity inspector. * * @return The name */ String getEntityInspectorName(); - + * /** * Enable the entity inspector. */ void enableEntityInspector(); - + * /** * Disable the entity inspector. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java index 52b7d0f22..db38e8b7e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* /** * The interface for a game window of the ICGE. * @@ -21,42 +22,42 @@ public interface GameWindow { * @return The texture registry used by this window. */ TextureRegistry getTextureRegistry(); - + * /** * Get the drawer responsible for drawing the playfield for this game window. * * @return The playfield drawer used by this window. */ PlayfieldDrawer getPlayfieldDrawer(); - + * /** * Get the toolbar for this game window. * * @return The toolbar used by this window. */ Toolbar getToolbar(); - + * /** * Get the entity sidebar for this game window * * @return The entity sidebar used by this window */ EntitySidebar getEntitySidebar(); - + * /** * Get the console for this game window * * @return The console used by this window */ Console getConsole(); - + * /** * Get the task status display for this game window. * * @return The task status display used by this window */ TaskStatusDisplay getTaskStatusDisplay(); - + * /** * Set the title of the window, in which the ICGE is displayed. * @@ -64,17 +65,17 @@ public interface GameWindow { * The title to use. */ void setWindowTitle(String title); - + * /** * Start and show the game window. */ void start(); - + * /** * Stop and close the game window. This action is equivalent with pressing the "X"-button of the window. */ void stop(); - + * /** * Set the simulation proxy instance used by multiple UI components to inform the Simulation of user actions. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java index 83ac6e533..86076278c 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java @@ -9,9 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -import java.util.List; +* -import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState; +import java.util.List;* +import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState;** /** @@ -20,7 +21,7 @@ * @author Tim Neumann */ public interface PlayfieldDrawer { - + * /** * Set the current list of Drawables to be rendered onto the playfield. * @@ -30,7 +31,7 @@ public interface PlayfieldDrawer { * the list of Drawables to render */ void setDrawables(List drawables); - + * /** * Draws the playfield. * @@ -38,25 +39,25 @@ public interface PlayfieldDrawer { * The number of the current tick */ void draw(long tickCount); - + * /** * Reset Zoom and Pan applied by the user to the default values. */ void resetZoomAndPan(); - + * /** * @param useDoubleBuffering * true (default) uses doubleBuffering when rendering changes on the playfield. */ void setDoubleBuffering(boolean useDoubleBuffering); - + * /** * @param syncToScreen * true (default) actively tries to sync the updated graphics to the screen after rendering changes on the * playfield. */ void setSyncToScreen(boolean syncToScreen); - + * /** * Inform the playfield drawer about which tool is selected in the toolbar. This influences what happens when a user * clicks on the playfield. @@ -65,7 +66,7 @@ public interface PlayfieldDrawer { * The currently selected tool */ void setSelectedTool(ControlButtonState selectedTool); - + * /** * Inform the playfield drawer about which entity type is selected in the toolbar. This influences what entity is * spawned when a user uses the entity creation tool. @@ -76,5 +77,5 @@ public interface PlayfieldDrawer { * The texture handle for the entity type selected. */ void setSelectedEntityType(String typeName, String textureHandle); - + * } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java index 3e056494e..78103d378 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* /** * The SimulationProxy interface. This is used for communication most between the UI and the simulation. *

@@ -21,7 +22,7 @@ * @version 1.0 */ public interface SimulationProxy { - + * /** * Attach this simulation proxy to a specific game window. * @@ -29,7 +30,7 @@ public interface SimulationProxy { * The game window to attach to */ void attachToGameWindow(GameWindow gameWindow); - + * /** * Attach this simulation proxy to a specific game window. * @@ -39,16 +40,16 @@ public interface SimulationProxy { * If {@code true} the simulation will stop when the attached window is closed */ void attachToGameWindow(GameWindow gameWindow, boolean stopWithWindowClose); - + * /** * Called when the window is closing. */ void windowClosed(); - + * // // Toolbar // - + * /** * This is to identify the buttons */ @@ -66,7 +67,7 @@ public enum ButtonType { /** The sub button in the toolbar */ SUB } - + * /** * This is called when a button is pressed by the user * @@ -74,7 +75,7 @@ public enum ButtonType { * The type of the pressed button */ void buttonPressed(ButtonType type); - + * /** * This is called if the speed slider is changed by the user * @@ -82,7 +83,7 @@ public enum ButtonType { * The new selected speed */ void simulationSpeedChange(int value); - + * /** * This gets called when the user changes the selected element * @@ -90,18 +91,18 @@ public enum ButtonType { * The name of the selected element */ void selectedEntityChanged(String name); - + * /** * This gets called by the user to refresh task status information. *

* Calling this must verify the task. */ void refreshTaskInformation(); - + * // // Entity placing // - + * /** * Spawn a new entity of the given type at the given position and bind the program to this entity. * @@ -113,7 +114,7 @@ public enum ButtonType { * coordinate */ void spawnEntityAt(String typeName, int x, int y); - + * /** * Clear all entities in the given cell. * @@ -123,11 +124,11 @@ public enum ButtonType { * coordinate */ void clearCell(int x, int y); - + * // // Sidebar - Simulation Tree // - + * /** * This function gets called when the user selects a different node * @@ -135,11 +136,11 @@ public enum ButtonType { * The node with was selected */ void selectedSimulationEntityChange(SimulationTreeNode node); - + * // // Entity Inspector // - + * /** * This function gets called when a user changes a value or fires a function in the ui * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java index bd15e2f9e..d9817fe84 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java @@ -9,12 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* + import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.function.Consumer; - -import de.unistuttgart.informatik.fius.icge.ui.exception.LeafNodeException; +import java.util.function.Consumer;* +import de.unistuttgart.informatik.fius.icge.ui.exception.LeafNodeException;** /** @@ -25,13 +26,12 @@ * @version 1.0 */ public class SimulationTreeNode { - - private ArrayList children; - - private final String elementId; - private final String displayText; - private final String textureId; - private final boolean isLeaf; + * + private ArrayList children;* + private final String elementId; + private final String displayText; + private final String textureId; + private final boolean isLeaf;* /** * Default constructor for leaf nodes @@ -48,7 +48,7 @@ public SimulationTreeNode(final String elementId, final String displayText, fina this.displayText = displayText; this.textureId = textureId; this.isLeaf = true; - } + }* /** * This constructor can be used to create non leaf nodes as well as leaf nodes. @@ -66,12 +66,12 @@ public SimulationTreeNode(final String elementId, final String displayText, fina if (!isLeaf) { this.children = new ArrayList<>(); } - + * this.elementId = elementId; this.displayText = displayText; this.textureId = textureId; this.isLeaf = isLeaf; - } + }* /** * Getter for the element id the non visible string to better identify the selected entity. @@ -80,7 +80,7 @@ public SimulationTreeNode(final String elementId, final String displayText, fina */ public String getElementId() { return this.elementId; - } + }* /** * Getter for the display text which is the name of the entity which is displayed to the user. @@ -89,7 +89,7 @@ public String getElementId() { */ public String getDisplayText() { return this.displayText; - } + }* /** * Getter for the texture id the identifier of the texture which is rendered infront of the display text. @@ -98,7 +98,7 @@ public String getDisplayText() { */ public String getTextureId() { return this.textureId; - } + }* /** * This checks if node is a leaf node. @@ -107,7 +107,7 @@ public String getTextureId() { */ public boolean isLeaf() { return this.isLeaf; - } + }* /** * Function to check if the node has children. @@ -116,9 +116,9 @@ public boolean isLeaf() { */ public boolean hasChildren() { if (this.isLeaf) return false; - + * return !this.children.isEmpty(); - } + }* /** * Appends a child node to this node @@ -129,9 +129,9 @@ public boolean hasChildren() { */ public boolean appendChild(final SimulationTreeNode node) { if (this.isLeaf) throw new LeafNodeException(); - + * return this.children.add(node); - } + }* /** * Removes a child node from this node @@ -142,16 +142,16 @@ public boolean appendChild(final SimulationTreeNode node) { */ public boolean removeChild(final SimulationTreeNode node) { if (this.isLeaf) throw new LeafNodeException(); - + * return this.children.remove(node); - } + }* /** * @return a list of all children */ public List getChildren() { return List.copyOf(this.children); - } + }* /** * Runs a function for each added child node with the child node as a parameter @@ -161,22 +161,22 @@ public List getChildren() { */ public void forEachChild(final Consumer lamda) { if (this.isLeaf) throw new LeafNodeException(); - + * for (final SimulationTreeNode child : this.children) { lamda.accept(child); } - } + }* @Override public int hashCode() { return this.elementId.hashCode(); - } + }* @Override public boolean equals(final Object obj) { if (!(obj instanceof SimulationTreeNode)) return false; return Objects.equals(this.elementId, ((SimulationTreeNode) obj).elementId); - } + }* @Override public String toString() { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java index 86ab147eb..20aa8bfe3 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java @@ -9,7 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -import java.util.List; +* + +import java.util.List;** /** @@ -19,28 +21,28 @@ * @version 1.0 */ public interface TaskInformation { - + * /** * Get the title of the task. * * @return the task title (must not be {@code null}, without trailing newline) */ String getTaskTitle(); - + * /** * Get the description of the task. * * @return the task description (can be {@code null}, can contain newlines, without trailing newline) */ String getTaskDescription(); - + * /** * Get the verification status of the task. * * @return the task status (must not be {@code null}) */ TaskVerificationStatus getTaskStatus(); - + * /** * Get a list of child/sub tasks of this task. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java index a274b7416..6bf8f1a4c 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* /** * The task status used by a {@link GameWindow} to show the current task status. * @@ -16,7 +17,7 @@ * @version 1.0 */ public interface TaskStatusDisplay { - + * /** * Set the task information to be displayed. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java index fd96eb55c..e47e1a912 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java @@ -8,7 +8,7 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.ui; - + * /** * Enum describing the verification status of a task. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java index ee2a1eafe..1cefebe00 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java @@ -9,10 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -import java.io.InputStream; -import java.util.function.Function; +* -import de.unistuttgart.informatik.fius.icge.ui.exception.TextureNotFoundException; +import java.io.InputStream; +import java.util.function.Function;* +import de.unistuttgart.informatik.fius.icge.ui.exception.TextureNotFoundException;** /** @@ -21,7 +22,7 @@ * @author Tim Neumann */ public interface TextureRegistry { - + * /** * Load an image from an internal resource as texture and return the handle to the texture. * @@ -42,7 +43,7 @@ public interface TextureRegistry { * the texture could not be loaded from the given resource location */ String loadTextureFromResource(String resourceName, final Function resourceProvider); - + * /** * Create a new animated texture with the animation length in render ticks. * @@ -53,7 +54,7 @@ public interface TextureRegistry { * @return the handle to retrieve the texture */ String createAnimatedTexture(boolean loop); - + * /** * Add a animation frame to an animated texture. * @@ -65,7 +66,7 @@ public interface TextureRegistry { * the number of frames to show this texture */ void addAnimationFrameToTexture(String animatedTexture, String frameTexture, long frames); - + * /** * Check if a texture is animated. * @@ -74,7 +75,7 @@ public interface TextureRegistry { * @return true iff the texture is animated */ boolean isTextureAnimated(String textureHandle); - + * /** * Load an image from a file path as texture and return the handle to the texture. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java index f40679b4e..2984e1216 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java @@ -9,7 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector; +* + +import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector;** /** @@ -20,7 +22,7 @@ * @version 1.0 */ public interface Toolbar { - + * /** * The clock button state represents the states of the clock buttons in the ui */ @@ -32,7 +34,7 @@ enum ClockButtonState { /** Indicates an error or unavailable clock or simulation */ BLOCKED } - + * /** * The control button state represents the status of the control buttons in the ui */ @@ -46,7 +48,7 @@ enum ControlButtonState { /** Indicates that the user input is blocked or unavailable */ BLOCKED } - + * /** * Append the list of entities with the given entry * @@ -57,7 +59,7 @@ enum ControlButtonState { * @see DropdownSelector */ void addEntity(String displayName, String textureID); - + * /** * Set the state of the control buttons. * @@ -65,7 +67,7 @@ enum ControlButtonState { * The new state */ void setControlButtonState(ControlButtonState controlButtonState); - + * /** * Set the state of the clock buttons. * @@ -73,14 +75,14 @@ enum ControlButtonState { * The new state */ void setClockButtonState(ClockButtonState clockButtonState); - + * /** * Get the current position of the speed slider. * * @return The position from 0 to 10 (both inclusive) */ int getSpeedSliderPosition(); - + * /** * Set the position of the speed slider. * @@ -88,14 +90,14 @@ enum ControlButtonState { * The new position; can be from 0 to 10 (both inclusive) */ void setSpeedSliderPosition(int position); - + * /** * Get the entity currently selected in the entity selection dropdown. * * @return The name of the currently selected entity */ String getCurrentlySelectedEntity(); - + * /** * Set the entity selected in the entity selection dropdown. * @@ -103,12 +105,12 @@ enum ControlButtonState { * The name of the entity to select */ void setCurrentlySelectedEntity(String entity); - + * /** * Enable the entity selector */ void enableEntitySelector(); - + * /** * Disable the entity selector */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java index 1c1339ec5..b58bc5c69 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java @@ -9,23 +9,23 @@ */ package de.unistuttgart.informatik.fius.icge.ui; +* + import java.awt.GraphicsEnvironment; import java.lang.reflect.InvocationTargetException; -import java.awt.Font; - +import java.awt.Font;* import javax.swing.SwingUtilities; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; -import javax.swing.plaf.FontUIResource; - +import javax.swing.plaf.FontUIResource;* import de.unistuttgart.informatik.fius.icge.ui.internal.SwingConsole; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingEntitySidebar; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingGameWindow; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingPlayfieldDrawer; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTaskStatusDisplay; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.internal.SwingToolbar; +import de.unistuttgart.informatik.fius.icge.ui.internal.SwingToolbar;** /** @@ -36,22 +36,21 @@ * @author Tim Neumann */ public class WindowBuilder { - - private static boolean isDefaultLookAndFeelUpdated = false; - private static double dpiScale; - private static double fontScale; - - private String windowTitle = ""; + * + private static boolean isDefaultLookAndFeelUpdated = false; + private static double dpiScale; + private static double fontScale;* + private String windowTitle = ""; private boolean useDoubleBuffering; private boolean syncToScreen; - private volatile GameWindow window; + private volatile GameWindow window;* /** * Create a new WindowBuilder. */ public WindowBuilder() { this(WindowBuilder.getDeviceDpiScale()); - } + }* /** * Create a new WindowBuilder. @@ -62,14 +61,14 @@ public WindowBuilder() { public WindowBuilder(double dpiScale) { if (dpiScale < 0.5) throw new IllegalArgumentException("A dpi scale < 0.5 is not supported!"); if (dpiScale > 3.0) throw new IllegalArgumentException("A dpi scale > 3.0 is not supported!"); - + * if (!WindowBuilder.isDefaultLookAndFeelUpdated) { // only once WindowBuilder.isDefaultLookAndFeelUpdated = true; WindowBuilder.dpiScale = dpiScale; WindowBuilder.fontScale = ((dpiScale - 1) * 0.75) + 1; this.setUiDefaults(dpiScale, WindowBuilder.fontScale); } - } + }* /** * Get the scaling factor from the default display device. @@ -79,7 +78,7 @@ public WindowBuilder(double dpiScale) { private static double getDeviceDpiScale() { return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform() .getScaleX(); - } + }* /** * Set the UI Manager defaults forlook and feeel and dpi scaling. @@ -110,7 +109,7 @@ private void setUiDefaults(double dpiScale, double fontScale) { } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { System.err.println("Can't set look and feel because of: " + e.toString()); } - } + }* /** * Set the title of the new window. @@ -126,9 +125,9 @@ private void setUiDefaults(double dpiScale, double fontScale) { public void setTitle(final String title) { if (this.hasBuiltWindow()) throw new IllegalStateException("The window was already built! Use the methods of the Window Object to change its properties."); - + * this.windowTitle = title; - } + }* /** * Set the graphics settings of the playfield drawer. @@ -147,10 +146,10 @@ public void setTitle(final String title) { public void setGraphicsSettings(final boolean useDoubleBuffering, final boolean syncToScreen) { if (this.hasBuiltWindow()) throw new IllegalStateException("The window was already built! Use the methods of the Window Object to change its properties."); - + * this.useDoubleBuffering = useDoubleBuffering; this.syncToScreen = syncToScreen; - } + }* /** * Actually build the window. @@ -168,7 +167,7 @@ public void buildWindow() { // TODO better exception handling System.err.println("Can't build the window because of: " + e.toString()); } - } + }* /** * Build the window. @@ -182,15 +181,15 @@ private void buildWindowInternal() { final SwingEntitySidebar entitySidebar = new SwingEntitySidebar(textureRegistry, WindowBuilder.dpiScale); final SwingConsole console = new SwingConsole(WindowBuilder.fontScale); final SwingTaskStatusDisplay taskStatus = new SwingTaskStatusDisplay(WindowBuilder.fontScale); - + * playfieldDrawer.setDoubleBuffering(this.useDoubleBuffering); playfieldDrawer.setSyncToScreen(this.syncToScreen); - + * this.window = new SwingGameWindow(textureRegistry, playfieldDrawer, toolbar, entitySidebar, console, taskStatus); if (this.windowTitle != null) { this.window.setWindowTitle(this.windowTitle); } - } + }* /** * Get whether the window has been built. @@ -199,7 +198,7 @@ private void buildWindowInternal() { */ public boolean hasBuiltWindow() { return this.window != null; - } + }* /** * Get the window that was built. diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java index 144d389c8..d462e5a2a 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui.exception; +* /** * The LeafNodeException is thrown when someone tries to add a child node to a leaf node or interact with the child * nodes of a leaf node. @@ -18,7 +19,7 @@ */ public class LeafNodeException extends UnsupportedOperationException { private static final long serialVersionUID = 2227365905217962083L; - + * /** * Default constructor */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java index 6a772cf81..dfb85d75c 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java @@ -9,6 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui.exception; +* /** * The ListenerSetException is thrown if a set listener function in the SimulationProxy fails * @@ -17,7 +18,7 @@ */ public class ListenerSetException extends IllegalArgumentException { private static final long serialVersionUID = -2620520061340158420L; - + * /** * Default constructor */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java index 84728316f..3dfe64792 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java @@ -9,16 +9,17 @@ */ package de.unistuttgart.informatik.fius.icge.ui.exception; +* /** * Exception thrown when a texture file or resource could not be found. */ public class TextureNotFoundException extends RuntimeException { - + * /** * generated */ private static final long serialVersionUID = -6554875504029045378L; - + * /** * Construct a new {@code TextureNotFoundException} with the given message. * @@ -28,7 +29,7 @@ public class TextureNotFoundException extends RuntimeException { public TextureNotFoundException(final String message) { super(message); } - + * /** * Construct a new {@code TextureNotFoundException} with the given message. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java index c75bca1ed..e0ee595d0 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java @@ -9,9 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.Graphics; import java.awt.Image; -import java.util.ArrayList; +import java.util.ArrayList;** /** @@ -20,11 +22,11 @@ * @author Fabian Bühler */ public class AnimatedTexture implements Texture { - + * private final SwingTextureRegistry registry; private final ArrayList animationFrames; private long duration; - private final boolean loop; + private final boolean loop;* /** * Create a new animated Texture. @@ -39,7 +41,7 @@ public AnimatedTexture(final SwingTextureRegistry registry, final boolean loop) this.animationFrames = new ArrayList<>(); this.duration = 0; this.loop = loop; - } + }* /** * Add a texture at the end of the animation. @@ -56,7 +58,7 @@ public void addAnimationFrame(final String frameTexture, final long frames) { this.duration += frames; final AnimationFrame frame = new AnimationFrame(last, last + (frames - 1), texture); this.animationFrames.add(frame); - } + }* /** * Get the texture for the current frame. @@ -67,7 +69,7 @@ public void addAnimationFrame(final String frameTexture, final long frames) { */ public Texture getTextureForTick(final long frame) { return this.getTextureForTick(frame, 0); - } + }* /** * Get the texture for the current frame. @@ -80,7 +82,7 @@ public Texture getTextureForTick(final long frame) { */ private Texture getTextureForTick(final long frame, final long animationStart) { if (this.duration == 0) throw new IllegalStateException("AnimatedTexture is empty!"); - + * long animationFrame = frame - animationStart; if (this.loop) { animationFrame = animationFrame % this.duration; @@ -97,23 +99,23 @@ private Texture getTextureForTick(final long frame, final long animationStart) { if ((animFrame.startFrame <= animationFrame) && (animFrame.endFrame >= animationFrame)) return animFrame.texture; } throw new IllegalStateException("This can only happen if the start and end frames of the animation frames were set wrong!"); - } + }* @Override public Image getTexture(final long frame) { return this.getTextureForTick(frame).getTexture(); - } + }* @Override public void drawTexture(final long frame, final Graphics g, final int x, final int y, final int width, final int height) { this.getTextureForTick(frame).drawTexture(frame, g, x, y, width, height); - } + }* private class AnimationFrame { private final long startFrame; private final long endFrame; private final Texture texture; - + * private AnimationFrame(final long startFrame, final long endFrame, final Texture texture) { this.startFrame = startFrame; this.endFrame = endFrame; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java index 57f2ff3f7..3b7665e30 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java @@ -9,17 +9,18 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.Color; import java.io.IOException; -import java.io.OutputStream; - +import java.io.OutputStream;* import javax.swing.JTextPane; import javax.swing.SwingUtilities; import javax.swing.Timer; import javax.swing.text.BadLocationException; import javax.swing.text.Style; import javax.swing.text.StyleConstants; -import javax.swing.text.StyledDocument; +import javax.swing.text.StyledDocument;** /** @@ -41,17 +42,15 @@ * @version 2.0 */ public class ConsoleBufferedOutputStream extends OutputStream { - + * /** The maximum length of the line buffer. */ - static final int DEFAULT_MAX_BUFFER_LENGTH = 4096; - private final int maxBufferLength; - - private final Timer timer; - + static final int DEFAULT_MAX_BUFFER_LENGTH = 4096; + private final int maxBufferLength;* + private final Timer timer;* //TODO add actual buffer to avoid overflowing the textarea and cause lag private final JTextPane textPane; private final Style style; - private final StringBuilder lineBuffer; + private final StringBuilder lineBuffer;* /** * Default Constructor @@ -65,7 +64,7 @@ public class ConsoleBufferedOutputStream extends OutputStream { */ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle style) { this(textPane, style, DEFAULT_MAX_BUFFER_LENGTH); - } + }* /** * Constructor with maxBufferLenght included @@ -81,10 +80,10 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle style, int maxBufferLength) { this.maxBufferLength = maxBufferLength; this.lineBuffer = new StringBuilder(maxBufferLength * 2); - + * this.textPane = textPane; this.style = this.textPane.addStyle(style.toString(), null); - + * switch (style) { case STANDARD: break; @@ -94,7 +93,7 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s default: throw new UnsupportedOperationException("With stye type " + style.toString()); } - + * this.timer = new Timer(32, (event) -> { try { // flush the line buffer in regular intervalls @@ -105,45 +104,45 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s }); this.timer.setCoalesce(true); this.timer.start(); // start timer after everything is initialized - } + }* @Override public void flush() throws IOException { super.flush(); this.flushLineBufferToTextPane(); - } + }* @Override public void close() throws IOException { super.close(); this.timer.stop(); - } + }* @Override public void write(final int character) throws IOException { final char symbol = (char) character; - + * synchronized (this.lineBuffer) { this.lineBuffer.append(symbol); } - + * if (this.lineBuffer.length() >= this.maxBufferLength) { this.flushLineBufferToTextPane(); } - } + }* private void flushLineBufferToTextPane() throws IOException { if (this.lineBuffer.length() == 0) { // fast exit as default without costly synchronized return; // nothing to flush in the line buffer } - + * String newText; synchronized (this.lineBuffer) { // stringBuilder is not threadsafe // get the current buffer and reset linebuffer newText = this.lineBuffer.toString(); this.lineBuffer.setLength(0); } - + * if (newText.length() > 0) { // new null check because previous check may be obsolete now // print line to text pane SwingUtilities.invokeLater(() -> { @@ -157,7 +156,7 @@ private void flushLineBufferToTextPane() throws IOException { } }); } - } + }* /** * Get's {@link #maxBufferLength maxBufferLength} @@ -166,6 +165,5 @@ private void flushLineBufferToTextPane() throws IOException { */ public int getMaxBufferLength() { return this.maxBufferLength; - } - + }* } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java index da399d887..756a072a2 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java @@ -9,16 +9,17 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* /** * Enum to identify different standard styles for the ConsoleBufferedOutputStream * * @author David Ruff */ public enum OutputStyle { - + * /** Standard Style for text from stdout */ STANDARD, - + * /** Style for text from stderr (e.g. errors) */ ERROR } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java index 9e99fdfb7..4d5f2d38a 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.Graphics; -import java.awt.Image; +import java.awt.Image;** /** @@ -19,9 +21,9 @@ * @author Fabian Bühler */ public class StaticTexture implements Texture { - + * private final Image texture; - + * /** * Create a new Texture. * @@ -31,12 +33,12 @@ public class StaticTexture implements Texture { public StaticTexture(final Image texture) { this.texture = texture; } - + * @Override public Image getTexture(final long frame) { return this.texture; } - + * @Override public void drawTexture(final long frame, final Graphics g, final int x, final int y, final int width, final int height) { g.drawImage(this.texture, x, y, width, height, null); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java index de64140a8..ba5b3162e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java @@ -9,7 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry; +* + +import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry;** /** @@ -19,23 +21,22 @@ * @version 1.0 */ public abstract class StaticUiTextures { - + * /** A play icon */ - public static String playIcon; + public static String playIcon; /** A step icon */ - public static String stepIcon; + public static String stepIcon; /** A pause icon */ - public static String pauseIcon; + public static String pauseIcon; /** A stop icon */ @Deprecated - public static String stopIcon; - + public static String stopIcon;* /** A arrow icon */ - public static String arrowIcon; + public static String arrowIcon; /** A add icon */ - public static String addIcon; + public static String addIcon; /** A sub icon */ - public static String subIcon; + public static String subIcon;* /** * This function loads all textures into the given texture registry and stores the icon ids @@ -48,7 +49,7 @@ public static void load(final TextureRegistry registry) { StaticUiTextures.stepIcon = registry.loadTextureFromResource("textures/step.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.pauseIcon = registry.loadTextureFromResource("textures/pause.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.stopIcon = registry.loadTextureFromResource("textures/stop.png", TextureRegistry.class::getResourceAsStream); - + * StaticUiTextures.arrowIcon = registry.loadTextureFromResource("textures/arrow.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.addIcon = registry.loadTextureFromResource("textures/add.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.subIcon = registry.loadTextureFromResource("textures/sub.png", TextureRegistry.class::getResourceAsStream); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java index 3b588be2a..345b000e1 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java @@ -9,16 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -import java.awt.Font; -import java.io.IOException; +* +import java.awt.Font; +import java.io.IOException;* import javax.swing.JTextPane; import javax.swing.SwingUtilities; import javax.swing.text.DefaultCaret; -import javax.swing.text.DefaultStyledDocument; - +import javax.swing.text.DefaultStyledDocument;* import de.unistuttgart.informatik.fius.icge.log.Logger; -import de.unistuttgart.informatik.fius.icge.ui.Console; +import de.unistuttgart.informatik.fius.icge.ui.Console;** /** @@ -30,10 +30,9 @@ * @version 2.0 */ public class SwingConsole extends JTextPane implements Console { - private static final long serialVersionUID = 5100186594058483257L; - + private static final long serialVersionUID = 5100186594058483257L;* private ConsoleBufferedOutputStream systemOutputStream; - private ConsoleBufferedOutputStream systemErrorStream; + private ConsoleBufferedOutputStream systemErrorStream;* /** * Default constructor @@ -45,25 +44,25 @@ public class SwingConsole extends JTextPane implements Console { */ public SwingConsole(final double fontScale) { super(new DefaultStyledDocument()); - + * final int fontSize = (int) Math.floor(12 * fontScale); final Font standardFont = new Font("monospaced", Font.PLAIN, fontSize); - + * this.setEditable(false); this.setFont(standardFont); final DefaultCaret caret = (DefaultCaret) this.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); this.systemOutputStream = new ConsoleBufferedOutputStream(this, OutputStyle.STANDARD); this.systemErrorStream = new ConsoleBufferedOutputStream(this, OutputStyle.ERROR); - + * Logger.addOutOutputStream(this.systemOutputStream); Logger.addErrorOutputStream(this.systemErrorStream); - } + }* @Override public void clearConsole() { SwingUtilities.invokeLater(() -> this.setText("")); - } + }* /** * Detach the internal output streams from {@code Logger.out} and {@code Logger.error}. diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java index 395bf4dd9..d7cd3c718 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; @@ -18,39 +20,32 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer; - +import java.util.function.Consumer;* import javax.swing.JButton; import javax.swing.JFormattedTextField; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; -import javax.swing.text.NumberFormatter; - -import de.unistuttgart.informatik.fius.icge.ui.EntityInspectorEntry; +import javax.swing.text.NumberFormatter;* +import de.unistuttgart.informatik.fius.icge.ui.EntityInspectorEntry;** /** * EntityInspector */ public class SwingEntityInspector extends JPanel { - private static final long serialVersionUID = 1L; - - private final GridBagConstraints gbc; - + private static final long serialVersionUID = 1L;* + private final GridBagConstraints gbc;* /** The name at the top */ - private final JLabel title; - + private final JLabel title;* /** The JPanel containing all the ui elements */ - private JPanel inspector; - + private JPanel inspector;* /** The user warning at the bottom */ - private final JLabel warning; - - private Object updateLock = new Object(); - private EntityInspectorEntry[] currentEntries; - private List> uiValueUpdaters; + private final JLabel warning;* + private Object updateLock = new Object(); + private EntityInspectorEntry[] currentEntries; + private List> uiValueUpdaters;* /** * Default constructor @@ -62,26 +57,26 @@ public class SwingEntityInspector extends JPanel { */ public SwingEntityInspector(final SwingTextureRegistry textureRegistry) { this.setLayout(new BorderLayout()); - + * this.title = new JLabel("Empty"); this.add(this.title, BorderLayout.PAGE_START); - + * this.inspector = new JPanel(); this.inspector.setLayout(new GridBagLayout()); this.add(this.inspector, BorderLayout.CENTER); - + * this.warning = new JLabel("Pause the simulation to modify an entity!"); this.warning.setVisible(false); this.add(this.warning, BorderLayout.PAGE_END); - + * this.gbc = new GridBagConstraints(); this.gbc.fill = GridBagConstraints.HORIZONTAL; this.gbc.gridx = 0; this.gbc.gridy = 0; - + * this.setEnabled(false); this.warning.setVisible(false); - } + }* /** * Getter for the inspector name wich is displayed at the top @@ -91,7 +86,7 @@ public SwingEntityInspector(final SwingTextureRegistry textureRegistry) { @Override public String getName() { return this.title.getText(); - } + }* /** * Setter for the inspector name @@ -105,7 +100,7 @@ public void setName(final String name) { this.title.setText(name); return; } - + * // cannot call invokeAndWait when already in EventDispatchThread! try { SwingUtilities.invokeAndWait(() -> { @@ -114,7 +109,7 @@ public void setName(final String name) { } catch (InvocationTargetException | InterruptedException e) { System.err.println("Failed to set entity inspector name because of: " + e.toString()); } - } + }* /** * Update the entity inspector to reflect the new Values. @@ -131,15 +126,15 @@ public void updateEntityInspectorEntries(final EntityInspectorEntry[] entries) { List> valueUpdaters = this.uiValueUpdaters; if (valueUpdaters == null) return; // TODO throw exeptions here? if (valueUpdaters.size() != entries.length) return; - + * // update values for (int i = 0; i < entries.length; i++) { valueUpdaters.get(i).accept(entries[i].getValue()); } - + * // change to new entries list this.currentEntries = entries; - + * // update ui this.revalidate(); this.repaint(); @@ -147,32 +142,32 @@ public void updateEntityInspectorEntries(final EntityInspectorEntry[] entries) { }); return; } - + * // completely update the view SwingUtilities.invokeLater(() -> { synchronized (this.updateLock) { // clear old elements first, then update current entries list this.clearUIElements(); - + * // change to new entries list this.uiValueUpdaters = null; this.currentEntries = entries; // only do this after clearing old elements - + * // add new ui elements List> newUiValueUpdaters = new ArrayList<>(entries.length); for (int i = 0; i < entries.length; i++) { newUiValueUpdaters.add(this.addUIElement(entries[i], i)); } - + * // set new value updaters this.uiValueUpdaters = newUiValueUpdaters; - + * // update ui this.revalidate(); this.repaint(); } }); - } + }* /** * Check if the new list of entries matches the current entries structurally. @@ -193,7 +188,7 @@ private boolean canUpdateValuesOnly(final EntityInspectorEntry[] entries) { // only value can differ for updates without complete redraws! } return true; - } + }* /** * Callback to change the value of an entry. @@ -213,7 +208,7 @@ private void updateValueOnEntity(int index, String name, String value) { EntityInspectorEntry entry = this.currentEntries[index]; if (!entry.getName().equals(name)) return; entry.runCallback(value); - } + }* /** * Add a entry to the ui editor @@ -228,14 +223,14 @@ private void updateValueOnEntity(int index, String name, String value) { * @return A consumer that updates the newly added ui element to the given string value */ private Consumer addUIElement(final EntityInspectorEntry entry, final int index) { - + * final String name = entry.getName(); this.inspector.add(new JLabel(name + ": "), this.gbc); this.gbc.gridx = 1; - + * Consumer updateUiValueCallback = (newValue) -> { /* Default is to update nothing. */}; - + * switch (entry.getType()) { case "integer": { final NumberFormatter formatter = new NumberFormatter(NumberFormat.getInstance()); @@ -276,12 +271,12 @@ private Consumer addUIElement(final EntityInspectorEntry entry, final in updateUiValueCallback = (newValue) -> label.setText(newValue); this.inspector.add(label, this.gbc); } - + * this.gbc.gridx = 0; this.gbc.gridy += 1; - + * return updateUiValueCallback; - } + }* /** * Clears the entity editor @@ -293,19 +288,19 @@ private void clearUIElements() { this.inspector = new JPanel(); this.inspector.setLayout(new GridBagLayout()); this.add(this.inspector, BorderLayout.CENTER); - + * this.gbc.gridx = 0; this.gbc.gridy = 0; - } + }* @Override public void setEnabled(final boolean enabled) { super.setEnabled(enabled); - + * this.title.setEnabled(enabled); SwingEntityInspector.setEnabledState(this.inspector, enabled); this.warning.setVisible(!enabled); - } + }* /** * Recursive method to enable and disable a JPanel and its children @@ -317,14 +312,14 @@ public void setEnabled(final boolean enabled) { */ private static void setEnabledState(final JPanel panel, final boolean state) { panel.setEnabled(state); - + * for (final Component component : panel.getComponents()) { if (component instanceof JPanel) { SwingEntityInspector.setEnabledState((JPanel) component, state); } component.setEnabled(state); } - } + }* @Override public Dimension getPreferredSize() { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java index cd9757672..aff1a118f 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java @@ -9,12 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.BorderLayout; import java.awt.Dimension; import java.util.ArrayList; import java.util.Enumeration; -import java.util.List; - +import java.util.List;* import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; @@ -24,12 +25,11 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; - +import javax.swing.tree.TreePath;* import de.unistuttgart.informatik.fius.icge.ui.EntityInspectorEntry; import de.unistuttgart.informatik.fius.icge.ui.EntitySidebar; import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; -import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode; +import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode;** /** @@ -40,21 +40,19 @@ * @version 1.0 */ public class SwingEntitySidebar extends JPanel implements EntitySidebar { - private static final long serialVersionUID = -4409545257025298208L; - + private static final long serialVersionUID = -4409545257025298208L;* /** The simulation proxy */ private SimulationProxy simulationProxy; /** The texture registry */ - private final SwingTextureRegistry textureRegistry; - + private final SwingTextureRegistry textureRegistry;* /** The root node of the entity list */ - private SimulationTreeNode rootNode; + private SimulationTreeNode rootNode; /** The hierarchical list of all entities */ - private JTree entityList; + private JTree entityList; /** The model of the JTree component */ - private DefaultTreeModel entityListModel; + private DefaultTreeModel entityListModel; /** The entity inspector in the sidebar */ - private SwingEntityInspector entityInspector; + private SwingEntityInspector entityInspector;* /** * The default constructor @@ -69,7 +67,7 @@ public class SwingEntitySidebar extends JPanel implements EntitySidebar { public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final double dpiScale) { // class setup this.textureRegistry = textureRegistry; - + * // JTree setup this.entityListModel = new DefaultTreeModel(null, true); this.entityList = new JTree(this.entityListModel); @@ -84,7 +82,7 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub } return; } - + * if (SwingEntitySidebar.this.simulationProxy != null) { SwingEntitySidebar.this.simulationProxy.selectedSimulationEntityChange( (SimulationTreeNode) ((DefaultMutableTreeNode) SwingEntitySidebar.this.entityList.getLastSelectedPathComponent()) @@ -92,21 +90,21 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub ); } }); - + * // Entity inspector setup this.entityInspector = new SwingEntityInspector(this.textureRegistry); - + * // Sidebar layout final JScrollPane pane = new JScrollPane(this.entityList); pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - + * final JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pane, this.entityInspector); jsp.setOneTouchExpandable(true); jsp.setResizeWeight(0.4); this.setLayout(new BorderLayout()); this.add(jsp, BorderLayout.CENTER); - } + }* /** * TODO better doc @@ -116,9 +114,9 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - + * this.simulationProxy = simulationProxy; - } + }* @Override public void setSimulationTreeRootNode(final SimulationTreeNode treeNode) { @@ -129,7 +127,7 @@ public void setSimulationTreeRootNode(final SimulationTreeNode treeNode) { // As this method itself is using invoke later, it does not need to be in the block above. // The order of execution is still correct, because calls to invokeLater are processes in the order the calls happen. this.updateSimulationTree(); - } + }* private void getExpandedTreePaths(final List expanded, final TreePath path) { if (path == null) return; @@ -138,18 +136,18 @@ private void getExpandedTreePaths(final List expanded, final TreePath expanded.add(p); this.getExpandedTreePaths(expanded, p); } - } + }* private TreePath getRootPath() { final Object root = this.entityList.getModel().getRoot(); if (root == null) return null; return new TreePath(root); - } + }* @Override public void updateSimulationTree() { SwingUtilities.invokeLater(this::updateSimulationTreeInternal); - } + }* /** * Update the simulation tree model. @@ -166,31 +164,31 @@ private void updateSimulationTreeInternal() { for (final TreePath p : expanded) { this.entityList.expandPath(p); } - } + }* @Override public void setEnabled(final boolean enabled) { super.setEnabled(enabled); this.entityList.setEnabled(enabled); - } + }* @Override public void setEntityInspectorEntries(final EntityInspectorEntry[] entries) { this.entityInspector.updateEntityInspectorEntries(entries); - } + }* @Override public Dimension getPreferredSize() { return new Dimension(300, 800); - } + }* private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { if ((node == null) || !node.getAllowsChildren()) return; final SimulationTreeNode data = (SimulationTreeNode) node.getUserObject(); - + * final List toRemove = new ArrayList<>(); final List toAdd = new ArrayList<>(); - + * outer: for (final SimulationTreeNode child : data.getChildren()) { for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); @@ -200,7 +198,7 @@ private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { } toAdd.add(child); } - + * outer: for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); for (final SimulationTreeNode child : data.getChildren()) { @@ -210,20 +208,20 @@ private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { } toRemove.add(childNode); } - + * for (final DefaultMutableTreeNode child : toRemove) { node.remove(child); } - + * for (final SimulationTreeNode child : toAdd) { node.add(SwingEntitySidebar.generateDefaultMutableTreeNodeFromSimulationTreeNode(child)); } - + * for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); SwingEntitySidebar.updateTreeNodeChildren(childNode); } - } + }* /** * Recursively generate a {@link DefaultMutableTreeNode} from a {@link SimulationTreeNode} @@ -235,7 +233,7 @@ private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { */ private static DefaultMutableTreeNode generateDefaultMutableTreeNodeFromSimulationTreeNode(final SimulationTreeNode node) { final DefaultMutableTreeNode returnNode = new DefaultMutableTreeNode(node); - + * if (node.isLeaf()) { returnNode.setAllowsChildren(false); } else { @@ -244,24 +242,24 @@ private static DefaultMutableTreeNode generateDefaultMutableTreeNodeFromSimulati .add(SwingEntitySidebar.generateDefaultMutableTreeNodeFromSimulationTreeNode(childNode)) ); } - + * return returnNode; - } + }* @Override public SimulationTreeNode getSimulationTreeSelectedElement() { return (SimulationTreeNode) ((DefaultMutableTreeNode) this.entityList.getLastSelectedPathComponent()).getUserObject(); - } + }* @Override public void setSimulationTreeSelectedElement(final SimulationTreeNode node) { //TODO implement - } + }* @Override public void enableSimulationTree() { SwingUtilities.invokeLater(() -> this.entityList.setEnabled(true)); - } + }* @Override public void disbaleSimulationTree() { @@ -269,22 +267,22 @@ public void disbaleSimulationTree() { this.entityList.setEnabled(false); this.entityListModel.setRoot(null); }); - } + }* @Override public void setEntityInspectorName(final String name) { SwingUtilities.invokeLater(() -> this.entityInspector.setName(name)); - } + }* @Override public String getEntityInspectorName() { return this.entityInspector.getName(); - } + }* @Override public void enableEntityInspector() { SwingUtilities.invokeLater(() -> this.entityInspector.setEnabled(true)); - } + }* @Override public void disableEntityInspector() { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java index a43a27610..d1e426ebb 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java @@ -9,12 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - +import java.awt.event.WindowEvent;* import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; @@ -24,8 +25,7 @@ import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.UIManager; -import javax.swing.WindowConstants; - +import javax.swing.WindowConstants;* import de.unistuttgart.informatik.fius.icge.ui.Console; import de.unistuttgart.informatik.fius.icge.ui.EntitySidebar; import de.unistuttgart.informatik.fius.icge.ui.GameWindow; @@ -33,7 +33,7 @@ import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; import de.unistuttgart.informatik.fius.icge.ui.TaskStatusDisplay; import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.Toolbar; +import de.unistuttgart.informatik.fius.icge.ui.Toolbar;** /** @@ -44,16 +44,14 @@ * @version 1.0 */ public class SwingGameWindow extends JFrame implements GameWindow { - private static final long serialVersionUID = -7215617949088643819L; - + private static final long serialVersionUID = -7215617949088643819L;* private final SwingTextureRegistry textureRegistry; private final SwingPlayfieldDrawer playfieldDrawer; private final SwingToolbar toolbar; private final SwingEntitySidebar entitySidebar; private final SwingConsole console; - private final SwingTaskStatusDisplay taskStatus; - - private SimulationProxy simulationProxy; + private final SwingTaskStatusDisplay taskStatus;* + private SimulationProxy simulationProxy;* /** * Create a new Swing game window using the given submodules. @@ -82,7 +80,7 @@ public SwingGameWindow( this.console = console; this.taskStatus = taskStatus; SwingUtilities.invokeLater(this::initGameWindow); - } + }* @Override public void setSimulationProxy(final SimulationProxy simulationProxy) { @@ -92,55 +90,55 @@ public void setSimulationProxy(final SimulationProxy simulationProxy) { this.toolbar.setSimulationProxy(simulationProxy); this.entitySidebar.setSimulationProxy(simulationProxy); this.taskStatus.setSimulationProxy(simulationProxy); - } + }* @Override public TextureRegistry getTextureRegistry() { return this.textureRegistry; - } + }* @Override public PlayfieldDrawer getPlayfieldDrawer() { return this.playfieldDrawer; - } + }* @Override public Toolbar getToolbar() { return this.toolbar; - } + }* @Override public EntitySidebar getEntitySidebar() { return this.entitySidebar; - } + }* @Override public Console getConsole() { return this.console; - } + }* @Override public TaskStatusDisplay getTaskStatusDisplay() { return this.taskStatus; - } + }* @Override public void setWindowTitle(final String title) { // UI operations must happen in swing thread! SwingUtilities.invokeLater(() -> this.setTitle(title)); - } + }* @Override public void start() { // Asynchronously set visible to true SwingUtilities.invokeLater(() -> this.setVisible(true)); - } + }* @Override public void stop() { // programmatically close the window Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); - } + }* /** * Initialize window listeners and layout all child components. @@ -150,7 +148,7 @@ public void stop() { @SuppressWarnings("unused") // Suppress unused warnings on 'ClassCastException e' private void initGameWindow() { // init jFrame - + * // // setup window closing // @@ -161,9 +159,9 @@ public void windowClosing(final WindowEvent e) { SwingGameWindow.this.cleanup(); // stop simulation etc. } }); - + * this.playfieldDrawer.initialize(); - + * // // convert toolbar // @@ -173,7 +171,7 @@ public void windowClosing(final WindowEvent e) { } catch (ClassCastException | NullPointerException e) { toolbarComponent = new JLabel("Toolbar not valid!", UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - + * // // convert sidebar // @@ -183,7 +181,7 @@ public void windowClosing(final WindowEvent e) { } catch (ClassCastException | NullPointerException e) { sidebarComponent = new JLabel(UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - + * // // convert console // @@ -193,7 +191,7 @@ public void windowClosing(final WindowEvent e) { } catch (NullPointerException e) { consoleComponent = new JLabel("Console not valid!", UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - + * // // setup bottom pane layout // @@ -201,7 +199,7 @@ public void windowClosing(final WindowEvent e) { bottomPane.addTab("Console", new JScrollPane(consoleComponent)); bottomPane.addTab("Task Status", this.taskStatus); bottomPane.setPreferredSize(new Dimension(400, 200)); - + * // // setup JFrame layout // @@ -212,12 +210,12 @@ public void windowClosing(final WindowEvent e) { final JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jsp1, sidebarComponent); jsp2.setOneTouchExpandable(true); this.getContentPane().add(BorderLayout.CENTER, jsp2); - + * // // finalize jFrame // this.pack(); - } + }* /** * Clean up all resources used by this window and tell the simulation that the window is now closed. diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java index 03217ab0a..b9245da5f 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -18,16 +20,14 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; -import java.util.stream.Collectors; - +import java.util.stream.Collectors;* import javax.swing.JPanel; import javax.swing.RepaintManager; -import javax.swing.SwingUtilities; - +import javax.swing.SwingUtilities;* import de.unistuttgart.informatik.fius.icge.ui.Drawable; import de.unistuttgart.informatik.fius.icge.ui.PlayfieldDrawer; import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; -import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState; +import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState;** /** @@ -36,63 +36,51 @@ * @author Tim Neumann */ public class SwingPlayfieldDrawer extends JPanel implements PlayfieldDrawer { - + * /** * generated */ - private static final long serialVersionUID = 1800137555269066525L; - + private static final long serialVersionUID = 1800137555269066525L;* /** Stretch factor for mapping row/column coordinates to screen coordinates. */ - private final double CELL_SIZE; - - private final int INFO_BAR_HEIGHT; - + private final double CELL_SIZE;* + private final int INFO_BAR_HEIGHT;* // Colors - private static final Color BACKGROUND_COLOR = new Color(255, 255, 255); - private static final Color BACKGROUND_COLOR_TRANSPARENT = new Color(255, 255, 255, 230); - private static final Color GRID_COLOR = new Color(46, 52, 54); - private static final Color OVERLAY_COLOR = new Color(0, 40, 255, 50); - + private static final Color BACKGROUND_COLOR = new Color(255, 255, 255); + private static final Color BACKGROUND_COLOR_TRANSPARENT = new Color(255, 255, 255, 230); + private static final Color GRID_COLOR = new Color(46, 52, 54); + private static final Color OVERLAY_COLOR = new Color(0, 40, 255, 50);* private static final RenderingHints RENDERING_HINTS = new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON - ); - - private final SwingTextureRegistry textureRegistry; - + );* + private final SwingTextureRegistry textureRegistry;* // current display offset and zoom private double offsetX; private double offsetY; - private double scale = 1.0; - + private double scale = 1.0;* // mouse events private boolean mouseInWindow = false; private int currentMouseX = 0; private int currentMouseY = 0; private int mouseStartX = 0; private int mouseStartY = 0; - private boolean isDrag = false; - + private boolean isDrag = false;* // current tool state private ControlButtonState activeTool = ControlButtonState.BLOCKED; private String selectedEntityType = null; private String selectedEntityTexture = null; - private SimulationProxy simulationProxy; - - private List drawables = List.of(); - private List animatedDrawables = List.of(); - private boolean fullRepaintNeeded = true; - private Rectangle lastRedrawArea = null; - private long currentFrame = 0; - + private SimulationProxy simulationProxy;* + private List drawables = List.of(); + private List animatedDrawables = List.of(); + private boolean fullRepaintNeeded = true; + private Rectangle lastRedrawArea = null; + private long currentFrame = 0;* // current graphic settings private final RepaintManager repaintManager; private boolean useDoubleBuffer = true; - private boolean syncToscreen = true; - - private double dpiScale; - - private Font scaleFont; - private Font font; + private boolean syncToscreen = true;* + private double dpiScale;* + private Font scaleFont; + private Font font;* /** * Create a new SwingPlayfieldDrawer. @@ -106,21 +94,21 @@ public class SwingPlayfieldDrawer extends JPanel implements PlayfieldDrawer { */ public SwingPlayfieldDrawer(final SwingTextureRegistry textureRegistry, final double dpiScale) { this.textureRegistry = textureRegistry; - + * this.setOpaque(true); this.repaintManager = RepaintManager.currentManager(this); - + * this.INFO_BAR_HEIGHT = (int) Math.floor(25 * dpiScale); this.CELL_SIZE = (int) Math.floor(32 * dpiScale); this.offsetX = this.CELL_SIZE; this.offsetY = this.CELL_SIZE; this.dpiScale = dpiScale; - + * Font font = this.getFont(); final int newFontSize = (int) Math.floor(12 * dpiScale * this.scale); this.font = new Font(font.getFontName(), font.getStyle(), newFontSize); this.setFont(this.font); - } + }* /** * Set the simulation proxy. TODO better doc @@ -130,9 +118,9 @@ public SwingPlayfieldDrawer(final SwingTextureRegistry textureRegistry, final do */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - + * this.simulationProxy = simulationProxy; - } + }* /** * Initialize the PlayfieldDrawer. @@ -140,60 +128,60 @@ public void setSimulationProxy(final SimulationProxy simulationProxy) { * This should only be called from the swing ui thread */ public void initialize() { - + * this.addMouseListener(new MouseListener() { - + * @Override public void mouseReleased(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { SwingPlayfieldDrawer.this.mouseReleased(e.getX(), e.getY()); } } - + * @Override public void mousePressed(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { SwingPlayfieldDrawer.this.mousePressed(e.getX(), e.getY()); } } - + * @Override public void mouseExited(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMouseInWindow(false); } - + * @Override public void mouseEntered(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMouseInWindow(true); } - + * @Override public void mouseClicked(final MouseEvent e) { // ignore this for now } }); - + * this.addMouseMotionListener(new MouseMotionListener() { - + * @Override public void mouseMoved(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMousePosition(e.getX(), e.getY()); } - + * @Override public void mouseDragged(final MouseEvent e) { SwingPlayfieldDrawer.this.updateDrag(e.getX(), e.getY()); SwingPlayfieldDrawer.this.updateMousePosition(e.getX(), e.getY()); } }); - + * this.addMouseWheelListener(e -> { final int rot = e.getWheelRotation(); final int x = e.getX(); final int y = e.getY(); SwingPlayfieldDrawer.this.updateZoom(rot, x, y); }); - } + }* @Override public void setDrawables(final List drawables) { @@ -203,7 +191,7 @@ public void setDrawables(final List drawables) { .collect(Collectors.toUnmodifiableList()); this.fullRepaintNeeded = true; this.draw(this.currentFrame); - } + }* @Override public void draw(final long tickCount) { @@ -212,16 +200,16 @@ public void draw(final long tickCount) { if (this.animatedDrawables.size() > 0) { this.drawables = this.drawables.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toUnmodifiableList()); } - + * SwingUtilities.invokeLater(() -> { // synchronize this to fix possible null pointer when setting double buffer setting - + * final boolean bufferEnabled = this.repaintManager.isDoubleBufferingEnabled(); if (!this.useDoubleBuffer) { // only change strategy to false since true should already be default this.repaintManager.setDoubleBufferingEnabled(this.useDoubleBuffer); } - + * if (this.fullRepaintNeeded) { Rectangle visible = this.getVisibleRect(); if (visible == null) { @@ -272,7 +260,7 @@ public void draw(final long tickCount) { this.animatedDrawables = this.drawables.stream() .filter(d -> d.isAnimated() || this.textureRegistry.isTextureAnimated(d.getTextureHandle())) .collect(Collectors.toUnmodifiableList()); - } + }* @Override public void resetZoomAndPan() { @@ -282,42 +270,42 @@ public void resetZoomAndPan() { Font font = this.getFont(); final int newFontSize = (int) Math.floor(12 * this.dpiScale * this.scale); this.scaleFont = new Font(font.getFontName(), font.getStyle(), newFontSize); - } + }* @Override public void setDoubleBuffering(final boolean useDoubleBuffering) { this.useDoubleBuffer = useDoubleBuffering; - } + }* @Override public void setSyncToScreen(final boolean syncToScreen) { this.syncToscreen = syncToScreen; - } + }* @Override public Dimension getPreferredSize() { return new Dimension(800, 600); - } + }* private int getColumnCoordinateFromScreenCoordinate(final int screenX) { final double cellSize = this.CELL_SIZE * this.scale; return (int) Math.floor((screenX - this.offsetX) / cellSize); - } + }* private int getRowCoordinateFromScreenCoordinate(final int screenY) { final double cellSize = this.CELL_SIZE * this.scale; return (int) Math.floor((screenY - this.offsetY) / cellSize); - } + }* private Point getScreenPointFromCellCoordinates(final double x, final double y, final double cellSize) { final int screenX = Math.toIntExact(Math.round((x * cellSize) + this.offsetX)); final int screenY = Math.toIntExact(Math.round((y * cellSize) + this.offsetY)); return new Point(screenX, screenY); - } + }* private static Rectangle getPaintRectFromPoint(final Point upperLeftCorner, final int cellSize) { return new Rectangle(upperLeftCorner.x, upperLeftCorner.y, cellSize, cellSize); - } + }* @Override public void paintComponent(final Graphics g) { @@ -329,7 +317,7 @@ public void paintComponent(final Graphics g) { this.paintGrid(g); this.paintDrawableList(g, this.drawables); this.paintOverlay(g); - } + }* private void paintGrid(final Graphics g) { final Rectangle clipBounds = g.getClipBounds(); @@ -339,7 +327,7 @@ private void paintGrid(final Graphics g) { // to the top left corner of e cell on screen) final double firstX = (Math.IEEEremainder(this.offsetX - clipBounds.x, cellSize) + clipBounds.x) - cellSize; final double firstY = (Math.IEEEremainder(this.offsetY - clipBounds.y, cellSize) + clipBounds.y) - cellSize; - + * final int width = this.getWidth(); final int height = this.getHeight(); g.setColor(SwingPlayfieldDrawer.GRID_COLOR); @@ -353,7 +341,7 @@ private void paintGrid(final Graphics g) { final int iy = (int) y; g.drawLine(0, iy, width, iy); } - } + }* /** * Compare two drawables and checks if they can be grouped together. @@ -374,7 +362,7 @@ private static boolean canGroupDrawables(final Drawable a, final Drawable b) { if (Math.abs(a.getX() - b.getX()) > 0.001) return false; if (Math.abs(a.getY() - b.getY()) > 0.001) return false; return true; - } + }* private void paintDrawableList(final Graphics g, final List drawablesList) { if (drawablesList.size() <= 0) return; @@ -382,7 +370,7 @@ private void paintDrawableList(final Graphics g, final List drawablesL Drawable last = null; int currentCount = 0; boolean isTilable = true; - + * // group and count drawables while (iter.hasNext()) { final Drawable next = iter.next(); @@ -401,7 +389,7 @@ private void paintDrawableList(final Graphics g, final List drawablesL if (last != null) { this.paintDrawable(g, last, currentCount + 1, isTilable); } - } + }* private void paintDrawable(final Graphics g, final Drawable drawable, final int count, final boolean isTilable) { final double cellSize = this.CELL_SIZE * this.scale; @@ -428,7 +416,7 @@ private void paintDrawable(final Graphics g, final Drawable drawable, final int final Double[] yOffsets = { 0.0, 0.0, 0.0, third, third, third, twoThird, twoThird, twoThird }; final Double scaleAdjust = third; this.paintMultiCountDrawable(g, drawable, count, xOffsets, yOffsets, scaleAdjust); - } + }* private void paintMultiCountDrawable( final Graphics g, final Drawable drawable, final int count, final Double[] xOffsets, final Double[] yOffsets, @@ -455,7 +443,7 @@ private void paintMultiCountDrawable( texture.drawTexture(this.currentFrame, g, x, y, textureSize, textureSize); } } - } + }* private void drawNumber(int count, Graphics g, int x, int y) { final double cellSize = this.CELL_SIZE * this.scale; @@ -474,20 +462,20 @@ private void drawNumber(int count, Graphics g, int x, int y) { } g.drawString("" + count, x + xOffset, y + yOffset); g.setFont(this.font); - } + }* private void paintOverlay(final Graphics g) { final int width = this.getWidth(); final int height = this.getHeight(); - + * final int currentCellX = this.getColumnCoordinateFromScreenCoordinate(this.currentMouseX); final int currentCellY = this.getRowCoordinateFromScreenCoordinate(this.currentMouseY); - + * final double cellSize = this.CELL_SIZE * this.scale; final int roundedCellSize = Math.toIntExact(Math.round(cellSize)); final int screenX = Math.toIntExact(Math.round(this.offsetX + (currentCellX * cellSize))); final int screenY = Math.toIntExact(Math.round(this.offsetY + (currentCellY * cellSize))); - + * // draw cell highlight if (this.mouseInWindow && g.hitClip(screenX, screenY, roundedCellSize, roundedCellSize)) { // draw current tool texture @@ -508,44 +496,44 @@ private void paintOverlay(final Graphics g) { g.setColor(SwingPlayfieldDrawer.OVERLAY_COLOR); g.fillRect(screenX, screenY, roundedCellSize, roundedCellSize); } - + * // draw info bar if (this.mouseInWindow && g.hitClip(0, height - this.INFO_BAR_HEIGHT, width, this.INFO_BAR_HEIGHT)) { - + * g.setColor(SwingPlayfieldDrawer.BACKGROUND_COLOR); g.fillRect(0, height - this.INFO_BAR_HEIGHT, width, this.INFO_BAR_HEIGHT); g.setColor(SwingPlayfieldDrawer.GRID_COLOR); - + * // calculate baseline final FontMetrics font = g.getFontMetrics(); final int heightAboveBaseline = font.getAscent(); final int heightBelowBaseline = font.getMaxDescent(); final int baselineCentered = Math.toIntExact(Math.round((this.INFO_BAR_HEIGHT / 2.0) - (heightAboveBaseline / 2.0))); final int baseline = height - Math.max(baselineCentered, heightBelowBaseline); - + * // build string final String infoText = "Cell (x=" + currentCellX + ", y=" + currentCellY + ")"; g.drawString(infoText, 5, baseline); - + * } - } + }* private void mousePressed(final int screenX, final int screenY) { this.mouseStartX = screenX; this.mouseStartY = screenY; this.isDrag = false; - } + }* private void mouseReleased(final int screenX, final int screenY) { if (!this.isDrag) { this.mouseClick(this.mouseStartX, this.mouseStartY); } - } + }* private void mouseClick(final int screenX, final int screenY) { final int x = this.getColumnCoordinateFromScreenCoordinate(screenX); final int y = this.getRowCoordinateFromScreenCoordinate(screenY); - + * if (this.activeTool == ControlButtonState.ADD) { final String type = this.selectedEntityType; if ((type == null) || type.equals("")) { @@ -568,12 +556,12 @@ private void mouseClick(final int screenX, final int screenY) { } } this.repaint(); - } + }* private void updateMouseInWindow(final boolean mouseInWindow) { this.mouseInWindow = mouseInWindow; this.repaintMouseOverlay(); - } + }* private void updateMousePosition(final int x, final int y) { final int oldX = this.currentMouseX; @@ -582,18 +570,18 @@ private void updateMousePosition(final int x, final int y) { this.currentMouseY = y; this.repaintCellHighlight(oldX, oldY); this.repaintMouseOverlay(); - } + }* private void repaintMouseOverlay() { this.repaintCellHighlight(this.currentMouseX, this.currentMouseY); this.repaint(0, this.getHeight() - this.INFO_BAR_HEIGHT, this.getWidth(), this.INFO_BAR_HEIGHT); - } + }* private void repaintCellHighlight(final int x, final int y) { final double cellSize = this.CELL_SIZE * this.scale; final int roundedCellSize = Math.toIntExact(Math.round(cellSize)); this.repaint(x - roundedCellSize, y - roundedCellSize, 2 * roundedCellSize, 2 * roundedCellSize); - } + }* private void updateDrag(final int x, final int y) { this.isDrag = true; @@ -603,7 +591,7 @@ private void updateDrag(final int x, final int y) { this.mouseStartX = x; this.mouseStartY = y; this.repaint(); - } + }* private void updateZoom(final int amount, final int x, final int y) { final double zoomScaling = 0.1 * Math.ceil(this.scale); @@ -622,17 +610,17 @@ private void updateZoom(final int amount, final int x, final int y) { this.scale = newScale; this.offsetX += dx; this.offsetY += dy; - + * Font font = this.getFont(); final int newFontSize = (int) Math.floor(12 * this.dpiScale * this.scale); this.scaleFont = new Font(font.getFontName(), font.getStyle(), newFontSize); this.repaint(); - } + }* @Override public void setSelectedTool(final ControlButtonState selectedTool) { this.activeTool = selectedTool; - } + }* @Override public void setSelectedEntityType(final String typeName, final String textureHandle) { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java index be56839c3..6696dbc0d 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java @@ -9,10 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.BorderLayout; import java.awt.Color; -import java.util.List; - +import java.util.List;* import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -23,11 +24,10 @@ import javax.swing.text.DefaultStyledDocument; import javax.swing.text.Style; import javax.swing.text.StyleConstants; -import javax.swing.text.StyledDocument; - +import javax.swing.text.StyledDocument;* import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; -import de.unistuttgart.informatik.fius.icge.ui.TaskStatusDisplay; +import de.unistuttgart.informatik.fius.icge.ui.TaskStatusDisplay;** /** @@ -37,17 +37,14 @@ * @version 1.0 */ public class SwingTaskStatusDisplay extends JPanel implements TaskStatusDisplay { - - private static final long serialVersionUID = -2711911902591163118L; - - private final JTextPane textPane; - - private final Style textStyle; - private final Style taskTitle; - private final Style taskSuccess; - private final Style taskFail; - - private SimulationProxy simulationProxy; + * + private static final long serialVersionUID = -2711911902591163118L;* + private final JTextPane textPane;* + private final Style textStyle; + private final Style taskTitle; + private final Style taskSuccess; + private final Style taskFail;* + private SimulationProxy simulationProxy;* /** * Default constructor. @@ -59,27 +56,27 @@ public class SwingTaskStatusDisplay extends JPanel implements TaskStatusDisplay */ public SwingTaskStatusDisplay(final double fontScale) { super(new BorderLayout()); - + * // setup text pane this.textPane = new JTextPane(new DefaultStyledDocument()); this.textPane.setEditable(false); ((DefaultCaret) this.textPane.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE); - + * // setup text styles final int fontSize = (int) Math.floor(12 * fontScale); this.textStyle = this.textPane.addStyle("Text", null); StyleConstants.setFontFamily(this.textStyle, "serif"); StyleConstants.setFontSize(this.textStyle, fontSize); - + * this.taskTitle = this.textPane.addStyle("TaskTitle", this.textStyle); StyleConstants.setBold(this.taskTitle, true); - + * this.taskSuccess = this.textPane.addStyle("TaskSuccess", this.taskTitle); this.taskFail = this.textPane.addStyle("TaskFail", this.taskTitle); - + * StyleConstants.setForeground(this.taskSuccess, Color.GREEN); StyleConstants.setForeground(this.taskFail, Color.RED); - + * // setup refresh button final JButton refreshButton = new JButton("Refresh"); refreshButton.addActionListener(ae -> { @@ -87,11 +84,11 @@ public SwingTaskStatusDisplay(final double fontScale) { this.simulationProxy.refreshTaskInformation(); } }); - + * // pack component this.add(new JScrollPane(this.textPane), BorderLayout.CENTER); this.add(refreshButton, BorderLayout.LINE_END); - } + }* /** * Set the simulation proxy. TODO better doc @@ -101,9 +98,9 @@ public SwingTaskStatusDisplay(final double fontScale) { */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - + * this.simulationProxy = simulationProxy; - } + }* @Override public void setTaskInformation(final TaskInformation task) { @@ -118,7 +115,7 @@ public void setTaskInformation(final TaskInformation task) { this.appendText(document, "You can set a task verifier in the SimulationBuilder.", this.textStyle); } }); - } + }* /** * Appends the task information of the task and all subtasks to the styled document. @@ -131,14 +128,14 @@ public void setTaskInformation(final TaskInformation task) { * the current task depth (starts with 0, may be used to indent subtasks later) */ private void appendTaskInformation(final TaskInformation task, final StyledDocument document, final int depth) { - + * // append title String title = task.getTaskTitle(); if (title == null || title.length() == 0) { title = "Unnamed Task"; } this.appendText(document, indentText(title, depth), this.taskTitle); - + * // append task status switch (task.getTaskStatus()) { case SUCCESSFUL: @@ -151,13 +148,13 @@ private void appendTaskInformation(final TaskInformation task, final StyledDocum default: this.appendText(document, " (pending)\n", this.taskTitle); } - + * // append description final String description = task.getTaskDescription(); if (description != null && description.length() > 0) { this.appendText(document, indentText(description + '\n', depth + 2), this.textStyle); } - + * // handle subtasks final List childTasks = task.getChildTasks(); if (childTasks != null) { @@ -166,7 +163,7 @@ private void appendTaskInformation(final TaskInformation task, final StyledDocum this.appendTaskInformation(subTask, document, depth + 1); } } - } + }* /** * Appends text to a styled document while silently dismissing {@link BadLocationException}. @@ -184,7 +181,7 @@ private void appendText(final StyledDocument document, final String text, final } catch (final BadLocationException e) { e.printStackTrace(); } - } + }* /** * This function appends indentation spaces to a string @@ -197,21 +194,21 @@ private void appendText(final StyledDocument document, final String text, final */ private static String indentText(final String text, final int depth) { if (depth == 0) return text; - + * StringBuilder returnString = new StringBuilder(); String indention = "\u2003".repeat(depth); - + * for (String s : text.split("\n")) { returnString.append(indention); returnString.append(s); returnString.append('\n'); } - + * // Delete the final new line character if needed to prevent additional unwanted newlines in the result string if (!text.endsWith("\n")) { returnString.deleteCharAt(returnString.length() - 1); } - + * return returnString.toString(); } } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java index b77ee3c9d..539c29d29 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java @@ -9,6 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -20,12 +22,10 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.UUID; -import java.util.function.Function; - -import javax.imageio.ImageIO; - +import java.util.function.Function;* +import javax.imageio.ImageIO;* import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.exception.TextureNotFoundException; +import de.unistuttgart.informatik.fius.icge.ui.exception.TextureNotFoundException;** /** @@ -36,17 +36,17 @@ * @version 1.0 */ public class SwingTextureRegistry implements TextureRegistry { - private final Map resourceToHandle = new HashMap<>(); - private final Map pathToHandle = new HashMap<>(); - private final Set animatedTextures = new HashSet<>(); - private final Map handleToTexture = new HashMap<>(); + private final Map resourceToHandle = new HashMap<>(); + private final Map pathToHandle = new HashMap<>(); + private final Set animatedTextures = new HashSet<>(); + private final Map handleToTexture = new HashMap<>();* /** * Default constructor */ public SwingTextureRegistry() { StaticUiTextures.load(this); - } + }* /** * Generate a new unique texture handle. @@ -55,7 +55,7 @@ public SwingTextureRegistry() { */ private static String generateNewTextureHandle() { return UUID.randomUUID().toString(); - } + }* /** * Load a texture from a local (ui module) resource. @@ -67,7 +67,7 @@ private static String generateNewTextureHandle() { */ public String loadTextureFromResource(final String resourceName) { return this.loadTextureFromResource(resourceName, SwingTextureRegistry.class::getResourceAsStream); - } + }* @Override public String loadTextureFromResource(final String resourceName, final Function resourceProvider) { @@ -81,7 +81,7 @@ public String loadTextureFromResource(final String resourceName, final Function< } catch (IllegalArgumentException | IOException e) { throw new TextureNotFoundException("The requested Resource could not be loaded!", e); } - } + }* @Override public String loadTextureFromFile(final String filePath) { @@ -98,18 +98,18 @@ public String loadTextureFromFile(final String filePath) { throw new TextureNotFoundException("The requested path could not be loaded!", e); } return textureHandle; - } + }* @Override public String createAnimatedTexture(final boolean loop) { final String textureHandle = SwingTextureRegistry.generateNewTextureHandle(); - + * final AnimatedTexture animTexture = new AnimatedTexture(this, loop); this.handleToTexture.put(textureHandle, animTexture); this.animatedTextures.add(textureHandle); - + * return textureHandle; - } + }* @Override public void addAnimationFrameToTexture(final String animatedTexture, final String frameTexture, final long frames) { @@ -119,12 +119,12 @@ public void addAnimationFrameToTexture(final String animatedTexture, final Strin } catch (final ClassCastException e) { throw new IllegalArgumentException("Texture handle was not a handle for an animated texture!", e); } - } + }* @Override public boolean isTextureAnimated(final String textureHandle) { return this.animatedTextures.contains(textureHandle); - } + }* /** * Get the texture for the given texture handle. diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java index 453fd6bd8..2ef0991e0 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java @@ -9,9 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -import java.awt.event.ItemEvent; -import java.util.Hashtable; +* +import java.awt.event.ItemEvent; +import java.util.Hashtable;* import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JLabel; @@ -20,13 +21,12 @@ import javax.swing.JToggleButton; import javax.swing.JToolBar; import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; - +import javax.swing.SwingUtilities;* import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy.ButtonType; import de.unistuttgart.informatik.fius.icge.ui.Toolbar; import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector; -import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry; +import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry;** /** @@ -38,32 +38,27 @@ * @version 1.0 */ public class SwingToolbar extends JToolBar implements Toolbar { - private static final long serialVersionUID = -2525998620577603876L; - + private static final long serialVersionUID = -2525998620577603876L;* /** The simulation proxy */ private SimulationProxy simulationProxy; /** The texture registry */ - private final SwingTextureRegistry textureRegistry; - + private final SwingTextureRegistry textureRegistry;* /** The play button in the toolbar */ - private JButton play; + private JButton play; /** The step button in the toolbar */ - private JButton step; + private JButton step; /** The pause button in the toolbar */ - private JButton pause; - + private JButton pause;* /** A slider to set the simulation time */ - private JSlider simulationTime; - + private JSlider simulationTime;* /** The button to change to view mode */ - private JToggleButton view; + private JToggleButton view; /** The button to change to add mode */ - private JToggleButton add; + private JToggleButton add; /** The button to change to sub mode */ - private JToggleButton sub; - + private JToggleButton sub;* /** The selector which selects the entity for the user to place */ - private DropdownSelector entitySelect; + private DropdownSelector entitySelect;* /** * The constructor of the toolbar @@ -80,12 +75,12 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi // class setup // this.textureRegistry = textureRegistry; - + * // // toolbar setup // this.setFloatable(false); - + * // // play button setup // @@ -97,7 +92,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.play.setEnabled(false); this.add(this.play); - + * // // step button setup // @@ -109,7 +104,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.step.setEnabled(false); this.add(this.step); - + * // // pause button setup // @@ -121,7 +116,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.pause.setEnabled(false); this.add(this.pause); - + * // // simulation time slider setup // @@ -142,7 +137,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi // setup change listener this.simulationTime.addChangeListener(event -> { final JSlider source = (JSlider) event.getSource(); - + * if (!source.getValueIsAdjusting()) { if (this.simulationProxy != null) { this.simulationProxy.simulationSpeedChange(source.getValue()); @@ -152,12 +147,12 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi this.simulationTime.setEnabled(false); this.add(this.simulationTime); this.addSeparator(); - + * // // add visual separator // this.add(new JSeparator(SwingConstants.VERTICAL)); - + * // // view button setup // @@ -169,7 +164,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.view.setEnabled(false); this.add(this.view); - + * // // add button setup // @@ -181,7 +176,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.add.setEnabled(false); this.add(this.add); - + * // // sub button setup // @@ -193,7 +188,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.sub.setEnabled(false); this.add(this.sub); - + * // // entity selector setup // @@ -208,7 +203,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.entitySelect.setEnabled(false); this.add(this.entitySelect); - } + }* /** * @@ -217,16 +212,16 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - + * this.simulationProxy = simulationProxy; - } + }* @Override public void addEntity(final String displayName, final String textureID) { SwingUtilities.invokeLater(() -> { this.entitySelect.addEntry(this.entitySelect.new DropdownEntry(displayName, textureID)); }); - } + }* private void setControlButtonStateInternal(final ControlButtonState controlButtonState) { switch (controlButtonState) { @@ -235,33 +230,33 @@ private void setControlButtonStateInternal(final ControlButtonState controlButto this.add.setEnabled(true); this.sub.setEnabled(true); break; - + * case ADD: this.view.setEnabled(true); this.add.setEnabled(false); this.sub.setEnabled(true); break; - + * case SUB: this.view.setEnabled(true); this.add.setEnabled(true); this.sub.setEnabled(false); break; - + * case BLOCKED: this.view.setEnabled(false); this.add.setEnabled(false); this.sub.setEnabled(false); break; - + * default: } - } + }* @Override public void setControlButtonState(final ControlButtonState controlButtonState) { SwingUtilities.invokeLater(() -> this.setControlButtonStateInternal(controlButtonState)); - } + }* private void setClockButtonStateInternal(final ClockButtonState clockButtonState) { switch (clockButtonState) { @@ -285,17 +280,17 @@ private void setClockButtonStateInternal(final ClockButtonState clockButtonState break; default: } - } + }* @Override public void setClockButtonState(final ClockButtonState clockButtonState) { SwingUtilities.invokeLater(() -> this.setClockButtonStateInternal(clockButtonState)); - } + }* @Override public int getSpeedSliderPosition() { return this.simulationTime.getValue(); - } + }* @Override public void setSpeedSliderPosition(final int position) { @@ -305,28 +300,28 @@ public void setSpeedSliderPosition(final int position) { "Simulation Speed Value is out of bounds. Should be between 0 and 10 (both inclusive) but is: " + position ); SwingUtilities.invokeLater(() -> this.simulationTime.setValue(position)); - } + }* @Override public String getCurrentlySelectedEntity() { final DropdownEntry currentEntry = this.entitySelect.getCurrentEntry(); if (currentEntry == null) return ""; return currentEntry.displayName; - } + }* @Override public void setCurrentlySelectedEntity(final String entity) { SwingUtilities.invokeLater(() -> { this.entitySelect.setCurrentEntry(this.entitySelect.new DropdownEntry(entity)); }); - } + }* @Override public void enableEntitySelector() { SwingUtilities.invokeLater(() -> { this.entitySelect.setEnabled(true); }); - } + }* @Override public void disableEntitySelector() { @@ -334,6 +329,5 @@ public void disableEntitySelector() { this.entitySelect.removeAllEntries(); this.entitySelect.setEnabled(false); }); - } - + }* } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java index 73e5cc517..4d88d7b80 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java @@ -9,8 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; +* + import java.awt.Graphics; -import java.awt.Image; +import java.awt.Image;** /** @@ -19,7 +21,7 @@ * @author Fabian Bühler */ public interface Texture { - + * /** * Get the texture image. * @@ -28,7 +30,7 @@ public interface Texture { default Image getTexture() { return this.getTexture(0); } - + * /** * Get the texture image. * @@ -37,7 +39,7 @@ default Image getTexture() { * @return the image */ Image getTexture(long frame); - + * /** * Draw the texture onto the screen. *

@@ -57,7 +59,7 @@ default Image getTexture() { default void drawTexture(final long frame, final Graphics g, final int x, final int y, final int size) { this.drawTexture(frame, g, x, y, size, size); } - + * /** * Draw the texture onto the screen. *

diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java index 93cc766c2..3aac87d24 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java @@ -9,20 +9,20 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal.dropdown; +* + import java.awt.Color; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.Insets; - +import java.awt.Insets;* import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; -import javax.swing.plaf.basic.BasicComboBoxEditor; - +import javax.swing.plaf.basic.BasicComboBoxEditor;* import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry; +import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry;** /** @@ -32,13 +32,12 @@ * @version 1.0 */ class DropdownItemEditor extends BasicComboBoxEditor { - + * /** The texture registry */ - private final SwingTextureRegistry textureRegistry; - - private final JPanel panel; - private final JLabel labelItem; - private DropdownEntry selectedValue; + private final SwingTextureRegistry textureRegistry;* + private final JPanel panel; + private final JLabel labelItem; + private DropdownEntry selectedValue;* /** * Constructor for the DropdownItemEditor @@ -50,7 +49,7 @@ class DropdownItemEditor extends BasicComboBoxEditor { */ public DropdownItemEditor(final SwingTextureRegistry textureRegistry) { this.textureRegistry = textureRegistry; - + * this.panel = new JPanel(); this.panel.setBackground(Color.BLUE); this.panel.setLayout(new GridBagLayout()); @@ -58,32 +57,32 @@ public DropdownItemEditor(final SwingTextureRegistry textureRegistry) { constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; constraints.insets = new Insets(2, 5, 2, 2); - + * this.labelItem = new JLabel(); this.labelItem.setOpaque(false); this.labelItem.setHorizontalAlignment(SwingConstants.LEFT); this.labelItem.setForeground(Color.WHITE); - + * this.panel.add(this.labelItem, constraints); - } + }* @Override public Component getEditorComponent() { return this.panel; - } + }* @Override public Object getItem() { return this.selectedValue; - } + }* @Override public void setItem(final Object item) { if (item == null) return; - + * this.selectedValue = (DropdownEntry) item; this.labelItem.setText(this.selectedValue.displayName); - + * if (!this.selectedValue.textureID.equals("")) { this.labelItem.setIcon(new ImageIcon(this.textureRegistry.getTextureForHandle(this.selectedValue.textureID).getTexture())); } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java index 2a085d0a5..83becc192 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java @@ -9,21 +9,21 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal.dropdown; +* + import java.awt.Color; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.Insets; - +import java.awt.Insets;* import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListCellRenderer; -import javax.swing.SwingConstants; - +import javax.swing.SwingConstants;* import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry; +import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry;** /** @@ -33,12 +33,10 @@ * @version 1.0 */ class DropdownItemRenderer extends JPanel implements ListCellRenderer { - private static final long serialVersionUID = 2930839533138981414L; - + private static final long serialVersionUID = 2930839533138981414L;* /** The texture registry */ - private final SwingTextureRegistry textureRegistry; - - private final JLabel labelItem; + private final SwingTextureRegistry textureRegistry;* + private final JLabel labelItem;* /** * Constructor for the DropdownItemRenderer @@ -50,20 +48,20 @@ class DropdownItemRenderer extends JPanel implements ListCellRenderer comboBox; - + private final SwingTextureRegistry textureRegistry;* + private final JLabel label; + private final JComboBox comboBox;* /** The data model of the DropdownSelector */ - private final DefaultComboBoxModel model; + private final DefaultComboBoxModel model;* /** * Constructor of the DropdownSelector @@ -95,19 +93,19 @@ public DropdownEntry(final String name, final String texture) { */ public DropdownSelector(final SwingTextureRegistry textureRegistry, final String header) { this.textureRegistry = textureRegistry; - + * this.label = new JLabel(header + ": "); this.comboBox = new JComboBox<>(); - + * this.model = new DefaultComboBoxModel<>(); this.comboBox.setModel(this.model); this.comboBox.setRenderer(new DropdownItemRenderer(this.textureRegistry)); this.comboBox.setEditor(new DropdownItemEditor(this.textureRegistry)); - + * this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(this.label); this.add(this.comboBox); - } + }* /** * Getter for the currently selected entry @@ -116,7 +114,7 @@ public DropdownSelector(final SwingTextureRegistry textureRegistry, final String */ public DropdownEntry getCurrentEntry() { return (DropdownEntry) this.comboBox.getEditor().getItem(); - } + }* /** * Setter for the currently selected entry @@ -130,7 +128,7 @@ public DropdownEntry getCurrentEntry() { */ public void setCurrentEntry(final DropdownEntry entry) { this.comboBox.getEditor().setItem(entry); - } + }* /** * This function adds an entry to the selector @@ -143,12 +141,12 @@ public void setCurrentEntry(final DropdownEntry entry) { public void addEntry(final DropdownEntry... entries) { for (final DropdownEntry entry : entries) { this.model.addElement(entry); - + * if (getCurrentEntry() == null) { this.setCurrentEntry(entry); } } - } + }* /** * This function removes all entries from the dropdown menu @@ -157,7 +155,7 @@ public void addEntry(final DropdownEntry... entries) { */ public void removeAllEntries() { this.model.removeAllElements(); - } + }* /** * Adds a listener which reacts to the selection and deselection of items @@ -169,7 +167,7 @@ public void removeAllEntries() { */ public void addSelectionListener(final ItemListener listener) { this.comboBox.addItemListener(listener); - } + }* @Override public void setEnabled(final boolean enabled) { diff --git a/ICGE-Ui/src/main/java/module-info.java b/ICGE-Ui/src/main/java/module-info.java index 2c89b3efa..e334b157a 100644 --- a/ICGE-Ui/src/main/java/module-info.java +++ b/ICGE-Ui/src/main/java/module-info.java @@ -10,7 +10,7 @@ module de.unistuttgart.informatik.fius.icge.ui { requires java.desktop; requires de.unistuttgart.informatik.fius.icge.log; - + * exports de.unistuttgart.informatik.fius.icge.ui; exports de.unistuttgart.informatik.fius.icge.ui.exception; } diff --git a/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java b/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java index 336a8e855..e48a8391e 100644 --- a/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java +++ b/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java @@ -9,22 +9,21 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -import java.lang.reflect.InvocationTargetException; - -import javax.swing.SwingUtilities; +* +import java.lang.reflect.InvocationTargetException;* +import javax.swing.SwingUtilities;* import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - +import org.junit.jupiter.api.Test;* import de.unistuttgart.informatik.fius.icge.ui.internal.SwingConsole; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingEntitySidebar; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingGameWindow; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingPlayfieldDrawer; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTaskStatusDisplay; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.internal.SwingToolbar; +import de.unistuttgart.informatik.fius.icge.ui.internal.SwingToolbar;** /** @@ -33,8 +32,8 @@ * @author Tim Neumann */ class SwingGameWindowUiTest { - - private SwingGameWindow window; + * + private SwingGameWindow window;* /** * Setup the game window @@ -51,10 +50,10 @@ public void setup() throws Exception { final SwingEntitySidebar entitySidebar = new SwingEntitySidebar(textureRegistry, 1); final SwingConsole console = new SwingConsole(1); final SwingTaskStatusDisplay taskStatus = new SwingTaskStatusDisplay(1); - + * this.window = new SwingGameWindow(textureRegistry, playfieldDrawer, toolbar, entitySidebar, console, taskStatus); }); - } + }* /** * Test {@link SwingGameWindow#start()} diff --git a/ICGE-archetype-module/src/main/resources/archetype-resources/src/main/java/module-info.java b/ICGE-archetype-module/src/main/resources/archetype-resources/src/main/java/module-info.java index fb954f885..fa19f3d93 100644 --- a/ICGE-archetype-module/src/main/resources/archetype-resources/src/main/java/module-info.java +++ b/ICGE-archetype-module/src/main/resources/archetype-resources/src/main/java/module-info.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Main.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Main.java index 625433f85..475a208cf 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Main.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Main.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -18,7 +18,7 @@ /** * Main class of the example - * + * * @author Tim Neumann */ public class Main { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Texture.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Texture.java index dddd1129f..72d2fecf6 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Texture.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Texture.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/WalkingProgram.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/WalkingProgram.java index 68c650677..54959e0f7 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/WalkingProgram.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/WalkingProgram.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -18,7 +18,7 @@ /** * A program walking around mario a bit - * + * * @author Tim Neumann */ public class WalkingProgram extends MarioProgram { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Coin.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Coin.java index fb4eb9ed1..fd60522b7 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Coin.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Coin.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,7 +16,7 @@ /** * A coin - * + * * @author Tim Neumann */ public class Coin extends BasicEntity implements CollectableEntity { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Mario.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Mario.java index 0fe7b6a9f..a76dfa84a 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Mario.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Mario.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,7 +15,7 @@ /** * The mario entity - * + * * @author Tim Neumann */ public class Mario extends GreedyEntity { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/MarioProgram.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/MarioProgram.java index 5b8963498..769704d08 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/MarioProgram.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/MarioProgram.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -15,7 +15,7 @@ /** * A program for mario - * + * * @author Tim Neumann */ public abstract class MarioProgram implements EntityProgram { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Wall.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Wall.java index f72ff14fe..6f2d69e8a 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Wall.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/entity/Wall.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -16,7 +16,7 @@ /** * The wall entity - * + * * @author Tim Neumann */ public class Wall extends BasicEntity implements SolidEntity { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution1.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution1.java index bc2afe957..4cefb66d8 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution1.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution1.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -14,7 +14,7 @@ /** * The example solution for Task1 - * + * * @author Tim Neumann */ public class Solution1 extends Task1 { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution2.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution2.java index c265a1a89..0985546bc 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution2.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Solution2.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -11,7 +11,7 @@ /** * The solution for {@link Task2} - * + * * @author Tim Neumann */ public class Solution2 extends Task2 { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task1.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task1.java index 06d8ab747..28f02600d 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task1.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task1.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -19,7 +19,7 @@ /** * An example task - * + * * @author Tim Neumann */ public abstract class Task1 implements Task { diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task2.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task2.java index 477c1f62e..3d5dd17c1 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task2.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/tasks/Task2.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ @@ -22,7 +22,7 @@ /** * The Task 2 - * + * * @author Tim Neumann */ public abstract class Task2 implements Task { diff --git a/examples/mario/src/main/java/module-info.java b/examples/mario/src/main/java/module-info.java index 8a83c363e..2ea432c61 100644 --- a/examples/mario/src/main/java/module-info.java +++ b/examples/mario/src/main/java/module-info.java @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ diff --git a/scriptsAndTools/#correctJavaFileComment.txt# b/scriptsAndTools/#correctJavaFileComment.txt# new file mode 100644 index 000000000..ac876acd5 --- /dev/null +++ b/scriptsAndTools/#correctJavaFileComment.txt# @@ -0,0 +1,9 @@ +/* + * This source file is part of the FIUS ICGE project. + * For more information see github.com/FIUS/ICGE2 + * + * Copyright (c) 2019 the ICGE project authors. + * + * This software is available under the MIT license. + * SPDX-License-Identifier: MIT + */ \ No newline at end of file diff --git a/scriptsAndTools/Unbenanntes Dokument b/scriptsAndTools/Unbenanntes Dokument new file mode 100644 index 000000000..124c5b3ce --- /dev/null +++ b/scriptsAndTools/Unbenanntes Dokument @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# This script fixes all java file comments +# No arguments allowed + +dir="$(dirname "$(realpath "$0")")" + +function fail { + echo $1 + exit $2 +} + +if [ $# -ne 0 ] ; then + fail "No argument expected" 2 +fi + +script="$dir/internalOrCiOnly/fixSingleJavaFileComment.sh" + +correctHeaderFile="$dir/correctJavaFileHeader.txt" + +#Fix all headers +javaFiles=$($dir/checkJavaFileComments.sh | grep -o "\..*\.java") +for file in $javaFiles +do + echo "fixing $dir$file" + cat $correctHeaderFile $file > $file +done diff --git a/scriptsAndTools/correctJavaFileComment.txt b/scriptsAndTools/correctJavaFileComment.txt index 5e1654e54..a7722c026 100644 --- a/scriptsAndTools/correctJavaFileComment.txt +++ b/scriptsAndTools/correctJavaFileComment.txt @@ -1,9 +1,9 @@ /* * This source file is part of the FIUS ICGE project. * For more information see github.com/FIUS/ICGE2 - * + * * Copyright (c) 2019 the ICGE project authors. - * + * * This software is available under the MIT license. * SPDX-License-Identifier: MIT */ From 13b5d54e48dc1dbf1c01ee61dedc3e2c6d021590 Mon Sep 17 00:00:00 2001 From: graefjk Date: Thu, 4 Jan 2024 02:47:06 +0100 Subject: [PATCH 5/6] formatting --- .../informatik/fius/icge/log/Logger.java | 28 +-- .../fius/icge/log/OutputStreamMultiplier.java | 22 +-- .../fius/icge/simulation/Direction.java | 3 +- .../fius/icge/simulation/MultiTypedList.java | 34 ++-- .../fius/icge/simulation/Playfield.java | 29 ++- .../fius/icge/simulation/Position.java | 18 +- .../fius/icge/simulation/Simulation.java | 24 ++- .../icge/simulation/SimulationBuilder.java | 27 ++- .../fius/icge/simulation/SimulationClock.java | 36 ++-- .../fius/icge/simulation/TaskVerifier.java | 8 +- .../fius/icge/simulation/actions/Action.java | 11 +- .../icge/simulation/actions/ActionLog.java | 21 +- .../icge/simulation/actions/EntityAction.java | 10 +- .../actions/EntityCollectAction.java | 18 +- .../actions/EntityDespawnAction.java | 12 +- .../simulation/actions/EntityDropAction.java | 18 +- .../simulation/actions/EntityMoveAction.java | 12 +- .../simulation/actions/EntitySpawnAction.java | 14 +- .../simulation/actions/EntityStepAction.java | 8 +- .../actions/EntityTeleportAction.java | 6 +- .../simulation/actions/EntityTurnAction.java | 14 +- .../icge/simulation/entity/BasicEntity.java | 35 ++-- .../simulation/entity/CollectableEntity.java | 2 +- .../fius/icge/simulation/entity/Entity.java | 10 +- .../simulation/entity/EntityCollector.java | 12 +- .../simulation/entity/EntityTypeRegistry.java | 17 +- .../icge/simulation/entity/GreedyEntity.java | 41 ++-- .../icge/simulation/entity/Inventory.java | 6 +- .../icge/simulation/entity/MovableEntity.java | 57 +++--- .../icge/simulation/entity/SolidEntity.java | 3 +- .../simulation/entity/UntilableDrawable.java | 8 +- .../CannotCollectEntityException.java | 11 +- .../exception/CannotDropEntityException.java | 11 +- .../exception/CannotRunProgramException.java | 11 +- .../exception/ElementExistsException.java | 7 +- .../EntityAlreadyOnFieldExcpetion.java | 7 +- .../exception/EntityNotOnFieldException.java | 7 +- .../EntityOnAnotherFieldException.java | 9 +- .../exception/IllegalMoveException.java | 7 +- .../exception/SimulationExcpetion.java | 11 +- .../exception/TimerAlreadyRunning.java | 6 +- .../UncheckedInterruptedException.java | 11 +- .../inspection/AnnotationReader.java | 16 +- .../simulation/inspection/ClassFinder.java | 22 +-- .../inspection/InspectionAttribute.java | 9 +- .../simulation/inspection/InspectionData.java | 115 ++++++----- .../inspection/InspectionManager.java | 32 +-- .../inspection/InspectionMethod.java | 8 +- .../internal/StandardSimulation.java | 43 ++-- .../internal/StandardSimulationClock.java | 96 ++++----- .../internal/StandardSimulationProxy.java | 111 ++++++----- .../internal/actions/StandardActionLog.java | 29 ++- .../entity/StandardEntityTypeRegistry.java | 30 +-- .../internal/playfield/PlayfieldCell.java | 8 +- .../internal/playfield/StandardPlayfield.java | 140 ++++++------- .../programs/StandardProgramRunner.java | 28 +-- .../internal/tasks/StandardTaskRunner.java | 29 +-- .../icge/simulation/programs/Program.java | 6 +- .../fius/icge/simulation/tasks/Task.java | 6 +- .../simulation/tools/PlayfieldModifier.java | 13 +- .../src/main/java/module-info.java | 2 +- .../fius/icge/ui/AnimatedDrawable.java | 41 ++-- .../fius/icge/ui/BasicDrawable.java | 19 +- .../informatik/fius/icge/ui/Console.java | 3 +- .../informatik/fius/icge/ui/Drawable.java | 17 +- .../fius/icge/ui/EntityInspectorEntry.java | 22 +-- .../fius/icge/ui/EntitySidebar.java | 23 ++- .../informatik/fius/icge/ui/GameWindow.java | 19 +- .../fius/icge/ui/PlayfieldDrawer.java | 21 +- .../fius/icge/ui/SimulationProxy.java | 33 ++-- .../fius/icge/ui/SimulationTreeNode.java | 56 +++--- .../fius/icge/ui/TaskInformation.java | 12 +- .../fius/icge/ui/TaskStatusDisplay.java | 3 +- .../fius/icge/ui/TaskVerificationStatus.java | 2 +- .../fius/icge/ui/TextureRegistry.java | 17 +- .../informatik/fius/icge/ui/Toolbar.java | 26 ++- .../fius/icge/ui/WindowBuilder.java | 51 ++--- .../icge/ui/exception/LeafNodeException.java | 3 +- .../ui/exception/ListenerSetException.java | 3 +- .../exception/TextureNotFoundException.java | 7 +- .../icge/ui/internal/AnimatedTexture.java | 24 ++- .../internal/ConsoleBufferedOutputStream.java | 48 ++--- .../fius/icge/ui/internal/OutputStyle.java | 5 +- .../fius/icge/ui/internal/StaticTexture.java | 12 +- .../icge/ui/internal/StaticUiTextures.java | 23 ++- .../fius/icge/ui/internal/SwingConsole.java | 25 +-- .../ui/internal/SwingEntityInspector.java | 95 ++++----- .../icge/ui/internal/SwingEntitySidebar.java | 90 ++++----- .../icge/ui/internal/SwingGameWindow.java | 58 +++--- .../ui/internal/SwingPlayfieldDrawer.java | 186 ++++++++++-------- .../ui/internal/SwingTaskStatusDisplay.java | 71 +++---- .../ui/internal/SwingTextureRegistry.java | 38 ++-- .../fius/icge/ui/internal/SwingToolbar.java | 94 ++++----- .../fius/icge/ui/internal/Texture.java | 12 +- .../internal/dropdown/DropdownItemEditor.java | 37 ++-- .../dropdown/DropdownItemRenderer.java | 30 +-- .../internal/dropdown/DropdownSelector.java | 48 ++--- ICGE-Ui/src/main/java/module-info.java | 2 +- .../fius/icge/ui/SwingGameWindowUiTest.java | 19 +- 99 files changed, 1331 insertions(+), 1369 deletions(-) diff --git a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java index 388697dd9..d9377281d 100644 --- a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java +++ b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/Logger.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.log; -* - import java.io.OutputStream; -import java.io.PrintStream;** +import java.io.PrintStream; /** @@ -25,25 +23,27 @@ * @version 2.0 */ public abstract class Logger { - * + /** The main logger printing to {@link System#out} */ - public static PrintStream out; + public static PrintStream out; /** The error logger printing to {@link System#err} */ - public static PrintStream error;* + public static PrintStream error; + private static OutputStreamMultiplier outStream; - private static OutputStreamMultiplier errorStream;* + private static OutputStreamMultiplier errorStream; + // This block intercepts {@link System.out} and {@link System.err} static { Logger.outStream = new OutputStreamMultiplier(); Logger.outStream.addOutputStream(System.out); Logger.out = new PrintStream(Logger.outStream); System.setOut(Logger.out); - * + Logger.errorStream = new OutputStreamMultiplier(); Logger.errorStream.addOutputStream(System.err); Logger.error = new PrintStream(Logger.errorStream); System.setErr(Logger.error); - }* + } /** * Function to add a {@link OutputStream} to the out logger @@ -55,7 +55,7 @@ public abstract class Logger { */ public static boolean addOutOutputStream(final OutputStream stream) { return Logger.outStream.addOutputStream(stream); - }* + } /** * Function to remove a {@link OutputStream} from the out logger @@ -67,7 +67,7 @@ public static boolean addOutOutputStream(final OutputStream stream) { */ public static boolean removeOutOutputStream(final OutputStream stream) { return Logger.outStream.removeOutputStream(stream); - }* + } /** * Clears the out OutputStreams @@ -76,7 +76,7 @@ public static boolean removeOutOutputStream(final OutputStream stream) { */ public static void clearOutOutputStream() { Logger.outStream.clearOutputStreams(); - }* + } /** * Function to add a {@link OutputStream} to the error logger @@ -88,7 +88,7 @@ public static void clearOutOutputStream() { */ public static boolean addErrorOutputStream(final OutputStream stream) { return Logger.errorStream.addOutputStream(stream); - }* + } /** * Function to remove a {@link OutputStream} from the error logger @@ -100,7 +100,7 @@ public static boolean addErrorOutputStream(final OutputStream stream) { */ public static boolean removeErrorOutputStream(final OutputStream stream) { return Logger.errorStream.removeOutputStream(stream); - }* + } /** * Clears the error OutputStreams diff --git a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java index 678bf3efa..c7c7dc155 100644 --- a/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java +++ b/ICGE-Log/src/main/java/de/unistuttgart/informatik/fius/icge/log/OutputStreamMultiplier.java @@ -9,11 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.log; -* - import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList;** +import java.util.ArrayList; /** @@ -23,15 +21,15 @@ * @version 1.0 */ public class OutputStreamMultiplier extends OutputStream { - * - private final ArrayList listenerStreams;* + + private final ArrayList listenerStreams; /** * Default Constructor */ public OutputStreamMultiplier() { this.listenerStreams = new ArrayList<>(); - }* + } /** * Add a output stream to also recieve everything this stream recieves @@ -42,7 +40,7 @@ public OutputStreamMultiplier() { */ public boolean addOutputStream(final OutputStream listenerStream) { return this.listenerStreams.add(listenerStream); - }* + } /** * Remove a output stream from recieving everything this stream recieves @@ -53,30 +51,30 @@ public boolean addOutputStream(final OutputStream listenerStream) { */ public boolean removeOutputStream(final OutputStream listenerStream) { return this.listenerStreams.remove(listenerStream); - }* + } /** * Clears all connected output streams */ public void clearOutputStreams() { this.listenerStreams.clear(); - }* + } @Override public void flush() throws IOException { super.flush(); - * + for (final OutputStream listenerStream : this.listenerStreams) { listenerStream.flush(); } - }* + } @Override public void write(final int arg0) throws IOException { for (final OutputStream listenerStream : this.listenerStreams) { listenerStream.write(arg0); } - }* + } @Override public void close() throws IOException { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java index 1b885b5f0..10d657617 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Direction.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -* /** * The four fundamental directions possible in the simulation. *

@@ -38,7 +37,7 @@ public enum Direction { SOUTH, /** The west direction; at the left of the screen ({@link Position#getX()} getting smaller) */ WEST; - * + /** * Get the direction that is next in a clock wise rotation * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java index d0612c43b..d79aff19f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/MultiTypedList.java @@ -9,13 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -* - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Optional; -import java.util.Set;** +import java.util.Set; /** @@ -26,8 +24,8 @@ * The parent type of all types contained in this list. */ public class MultiTypedList

{ - * - private final HashMap, List

> items = new HashMap<>();* + + private final HashMap, List

> items = new HashMap<>(); /** * Get the relevant list for the given type. @@ -44,7 +42,7 @@ private Optional> getRelevantListGeneric(final Class) list; return Optional.ofNullable(listOfCorrectType); - }* + } private Class getClass(final P o) { //Actually a cast should not be necessary here. @@ -52,7 +50,7 @@ private Class getClass(final P o) { @SuppressWarnings("unchecked") final var type = (Class) o.getClass(); return type; - }* + } /** * Get the relevant list for the given object. @@ -63,7 +61,7 @@ private Class getClass(final P o) { */ private Optional> getRelevantList(final P o) { return this.getRelevantListGeneric(this.getClass(o)); - }* + } /** * Get the relevant list for the given entity and create it if it is not there. @@ -75,11 +73,11 @@ private Optional> getRelevantList(final P o) { private List

getRelevantListAndCreate(final P o) { final var type = this.getClass(o); if (this.items.containsKey(type)) return this.items.get(type); - * + final List

list = new ArrayList<>(); this.items.put(type, list); return list; - }* + } /** * Add the given object to this list. @@ -89,7 +87,7 @@ private List

getRelevantListAndCreate(final P o) { */ public synchronized void add(final P o) { this.getRelevantListAndCreate(o).add(o); - }* + } /** * Check whether this list contains the given object. @@ -102,7 +100,7 @@ public synchronized boolean contains(final P o) { final var opt = this.getRelevantList(o); if (opt.isEmpty()) return false; return opt.get().contains(o); - }* + } /** * Return {@code true} iff the list contains no objects. @@ -111,7 +109,7 @@ public synchronized boolean contains(final P o) { */ public synchronized boolean isEmpty() { return this.items.isEmpty(); - }* + } /** * Remove the given object from this list. @@ -124,7 +122,7 @@ public synchronized boolean remove(final P o) { final var opt = this.getRelevantList(o); if (opt.isEmpty()) return false; return opt.get().remove(o); - }* + } /** * Get all objects in this list of the given type. @@ -139,9 +137,9 @@ public synchronized boolean remove(final P o) { */ public synchronized List get(final Class type, final boolean includeSubclasses) { if (!includeSubclasses) return this.getRelevantListGeneric(type).orElse(List.of()); - * + final List result = new ArrayList<>(); - * + for (final Class storedType : this.items.keySet()) { if (type.isAssignableFrom(storedType)) { final Class storedTypeAsSubOfRequested = storedType.asSubclass(type); @@ -149,9 +147,9 @@ public synchronized List get(final Class type, fin result.addAll(listForStoredType); } } - * + return result; - }* + } /** * @return a list of stored types. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java index 4928b4460..78f3f8279 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Playfield.java @@ -9,15 +9,14 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -* +import java.util.List; -import java.util.List;* import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityMoveAction; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityTeleportAction; import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityAlreadyOnFieldExcpetion; import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityNotOnFieldException; -import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityOnAnotherFieldException;** +import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityOnAnotherFieldException; /** @@ -26,19 +25,19 @@ * @author Tim Neumann */ public interface Playfield { - * + /** * @return the simulation this playfield is part of */ Simulation getSimulation(); - * + /** * Get a list of all entities on this playfield. * * @return A list of all entities */ List getAllEntities(); - * + /** * Get a list of all entities matching the given type on this playfield. * @@ -53,7 +52,7 @@ public interface Playfield { * if the given type is null */ List getAllEntitiesOfType(Class type, boolean includeSubclasses); - * + /** * Get a list of all entities at the given position on this playfield. * @@ -64,7 +63,7 @@ public interface Playfield { * if the given pos is null */ List getEntitiesAt(final Position pos); - * + /** * Get a list of all entities matching the given type at the given position on this playfield. * @@ -81,7 +80,7 @@ public interface Playfield { * if the given pos or type is null */ List getEntitiesOfTypeAt(final Position pos, Class type, boolean includeSubclasses); - * + /** * Add a given entity to this simulation at a given position on this playfield. * @@ -98,7 +97,7 @@ public interface Playfield { * if the given pos or entity is null */ void addEntity(Position pos, Entity entity); - * + /** * Move a entity of this simulation to a given position on this playfield. *

@@ -115,7 +114,7 @@ public interface Playfield { * if the given pos or entity is null */ void moveEntity(Entity entity, Position pos); - * + /** * Move a entity of this simulation to a given position on this playfield. * @@ -133,7 +132,7 @@ public interface Playfield { * if the given action match with the other arguments */ void moveEntity(Entity entity, Position pos, EntityMoveAction action); - * + /** * Remove a entity of this simulation from this playfield. * @@ -145,7 +144,7 @@ public interface Playfield { * if the given entity is null */ void removeEntity(Entity entity); - * + /** * Get the position of the specified entity on the playfield. * @@ -158,7 +157,7 @@ public interface Playfield { * if the given entity is null */ Position getEntityPosition(Entity entity); - * + /** * Check whether the specified entity is on this playfield. * @@ -169,7 +168,7 @@ public interface Playfield { * if the given entity is null */ boolean containsEntity(Entity entity); - * + /** * Check whether a solid entity is at the given position. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java index 63cfde44d..56f61ac3f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Position.java @@ -9,9 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -* - -import java.util.Arrays;** +import java.util.Arrays; /** @@ -36,7 +34,7 @@ public class Position { private final int x; private final int y; - * + /** * Create a new position from the given parameters. * @@ -49,21 +47,21 @@ public Position(final int x, final int y) { this.x = x; this.y = y; } - * + /** * @return the x coordinate of this position */ public int getX() { return this.x; } - * + /** * @return the y coordinate of this position */ public int getY() { return this.y; } - * + /** * Get the adjacent position in the given direction. * @@ -85,20 +83,20 @@ public Position adjacentPosition(final Direction direction) { throw new IllegalArgumentException("Unknown direction"); } } - * + @Override public boolean equals(final Object o) { if (!(o instanceof Position)) return false; final Position p = (Position) o; return (this.x == p.getX()) && (this.y == p.getY()); } - * + @Override public int hashCode() { final int[] numbers = { this.x, this.y }; return Arrays.hashCode(numbers); } - * + @Override public String toString() { return "(x=" + this.x + ", y=" + this.y + ")"; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java index 527ac721e..9c6828f9c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/Simulation.java @@ -9,15 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -* - import de.unistuttgart.informatik.fius.icge.simulation.actions.ActionLog; import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; import de.unistuttgart.informatik.fius.icge.simulation.entity.EntityTypeRegistry; import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; import de.unistuttgart.informatik.fius.icge.ui.GameWindow; -import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy;** +import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; /** @@ -32,42 +30,42 @@ public interface Simulation { * @return The playfield used by this simulation */ Playfield getPlayfield(); - * + /** * Get the task verifier set for this simulation. * * @return The task verifier set for this simulation */ TaskVerifier getTaskVerifier(); - * + /** * Get the simulation clock for this simulation. * * @return the simulation clock used by this simulation */ SimulationClock getSimulationClock(); - * + /** * Get the entity type registry associated with the simulation host. * * @return The entity type registry */ EntityTypeRegistry getEntityTypeRegistry(); - * + /** * Get the action log for this simulation. * * @return the action log used by this siumulation */ ActionLog getActionLog(); - * + /** * Get the simulation proxy used by the game window to communicate with the simulation. * * @return The simulation proxy for the UI to use */ SimulationProxy getSimulationProxyForWindow(); - * + /** * Attach this simulation to the given window. * @@ -75,7 +73,7 @@ public interface Simulation { * The window to attach to */ void attachToWindow(GameWindow window); - * + /** * Attach this simulation to the given window. * @@ -85,14 +83,14 @@ public interface Simulation { * If {@code true} the simulation will stop when the attached window is closed */ void attachToWindow(GameWindow window, boolean stopWithWindowClose); - * + /** * Irreversibly stop the simulation and all running background tasks and programs. * * Calling this method twice will not throw an exception. */ void stop(); - * + /** * Run the given task in the background. * @@ -102,7 +100,7 @@ public interface Simulation { * The task to run */ void runTask(Task taskToRun); - * + /** * Run the given program for the given Entity in the background. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java index 2b22b2a98..f5fbdf2f2 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationBuilder.java @@ -9,14 +9,12 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -* - import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionManager; import de.unistuttgart.informatik.fius.icge.simulation.internal.StandardSimulation; import de.unistuttgart.informatik.fius.icge.simulation.internal.StandardSimulationClock; import de.unistuttgart.informatik.fius.icge.simulation.internal.actions.StandardActionLog; import de.unistuttgart.informatik.fius.icge.simulation.internal.entity.StandardEntityTypeRegistry; -import de.unistuttgart.informatik.fius.icge.simulation.internal.playfield.StandardPlayfield;** +import de.unistuttgart.informatik.fius.icge.simulation.internal.playfield.StandardPlayfield; /** @@ -25,9 +23,10 @@ * @author Tim Neumann */ public class SimulationBuilder { - * - private TaskVerifier taskVerifier;* - private Simulation simulation;* + + private TaskVerifier taskVerifier; + + private Simulation simulation; /** * Set the task verifier to use with this simulation. @@ -47,7 +46,7 @@ public void setTaskVerifier(final TaskVerifier taskVerifier) { "The simulation was already built! Use the methods of the Simulation Object to change its properties." ); this.taskVerifier = taskVerifier; - }* + } /** * Actually build the simulation. @@ -61,17 +60,17 @@ public void buildSimulation() { throw new IllegalStateException("The simulation was already built! Use getBuiltSimulation() to acess the built window."); final StandardPlayfield playfield = new StandardPlayfield(); final StandardSimulationClock simulationClock = new StandardSimulationClock(); - * + final StandardEntityTypeRegistry entityTypeRegistry = new StandardEntityTypeRegistry(); - * + final StandardActionLog actionLog = new StandardActionLog(); - * + final InspectionManager inspectionManager = new InspectionManager(); - * + this.simulation = new StandardSimulation( playfield, simulationClock, entityTypeRegistry, actionLog, inspectionManager, this.taskVerifier ); - }* + } /** * Get whether the window has been built. @@ -80,7 +79,7 @@ public void buildSimulation() { */ public boolean hasBuiltSimulation() { return this.simulation != null; - }* + } /** * Get the simulation that was built. @@ -93,7 +92,7 @@ public boolean hasBuiltSimulation() { public Simulation getBuiltSimulation() { if (!this.hasBuiltSimulation()) throw new IllegalStateException("The simulation was not yet built! Use buildSimulation() to do that."); - * + return this.simulation; } } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java index ffdb01adf..1857b9e1a 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/SimulationClock.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -* - import java.util.concurrent.CompletableFuture; -import java.util.function.Function;** +import java.util.function.Function; /** @@ -23,17 +21,17 @@ * @version 1.0 */ public interface SimulationClock { - * + /** * The number of render ticks per one simulation tick. */ int RENDER_TICKS_PER_SIMULATION_TICK = 8; - * + /** * The render period, that is set by default. */ int DEFAULT_RENDER_TICK_PERIOD = 50; - * + /** * Set the period of the render ticks. The game ticks will have this period times * {@value #RENDER_TICKS_PER_SIMULATION_TICK}. @@ -42,33 +40,33 @@ public interface SimulationClock { * The new period in milliseconds. */ void setPeriod(int millis); - * + /** * Get the period of the render ticks. * * @return The number of milliseconds per render tick period. */ int getRenderTickPeriod(); - * + /** * Get the period of the game ticks. * * @return The number of milliseconds per game tick period. */ int getGameTickPeriod(); - * + /** * Query the clock if its running * * @return if the clock is running */ boolean isRunning(); - * + /** * Start ticking. */ void start(); - * + /** * Stop ticking. *

@@ -76,12 +74,12 @@ public interface SimulationClock { *

*/ void stop(); - * + /** * Execute one single tick */ void step(); - * + /** * Register a listener for simulation ticks. *

@@ -92,7 +90,7 @@ public interface SimulationClock { * The listener to be called. */ void registerTickListener(Function listener); - * + /** * Register a listener for the end of simulation ticks. *

@@ -103,17 +101,17 @@ public interface SimulationClock { * The listener to be called. */ void registerPostTickListener(Function listener); - * + /** * @return the number of the last simulation tick */ long getLastTickNumber(); - * + /** * @return the number of the last render tick */ long getLastRenderTickNumber(); - * + /** * Schedule an operation, to happen during the given tick. This method will block until that tick. Then the tick * processing will halt until the given end of operation is completed. @@ -129,7 +127,7 @@ public interface SimulationClock { * if the end of operation completes exceptionally */ void scheduleOperationAtTick(long tick, CompletableFuture endOfOperation); - * + /** * Schedule an operation, to happen during the tick a given number of ticks in the future. This method will block * until that tick. Then the tick processing will halt until the given end of operation is completed. @@ -145,7 +143,7 @@ public interface SimulationClock { * if the end of operation completes exceptionally */ void scheduleOperationInTicks(long ticks, CompletableFuture endOfOperation); - * + /** * Schedule an operation, to happen during the next tick. This method will block until that tick. Then the tick * processing will halt until the given end of operation is completed. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java index 3c771eeac..7e2bfa00e 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/TaskVerifier.java @@ -9,9 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.simulation; -* - -import de.unistuttgart.informatik.fius.icge.ui.TaskInformation;** +import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; /** @@ -29,14 +27,14 @@ public interface TaskVerifier { * the simulation to verify */ void attachToSimulation(Simulation sim); - * + /** * Verify if the current state of the simulation matches the requirements for the successful completion of the task. *

* This method should update the task information returned by {@link #getTaskInformation}. */ void verify(); - * + /** * Get the current task information. *

diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java index 8e0d20102..94f49a22f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/Action.java @@ -9,16 +9,15 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* /** * An action which happens during the execution of a simulation. * * @author Tim Neumann */ public abstract class Action { - * + private final long tickNumber; - * + /** * Create an action. * @@ -28,19 +27,19 @@ public abstract class Action { public Action(final long tickNumber) { this.tickNumber = tickNumber; } - * + /** * @return the description of this action */ public abstract String getDescription(); - * + /** * @return the number of the simulation tick the action happened */ public long getTickNumber() { return this.tickNumber; } - * + @Override public String toString() { return this.getDescription(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java index 860ab933c..29700b5f7 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/ActionLog.java @@ -9,10 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* +import java.util.List; -import java.util.List;* -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -21,7 +20,7 @@ * @author Tim Neumann */ public interface ActionLog { - * + /** * Get all actions which were logged. *

@@ -31,7 +30,7 @@ public interface ActionLog { * @return A list of all actions logged */ List getAllActions(); - * + /** * Get all actions which were logged of the given type. * @@ -44,7 +43,7 @@ public interface ActionLog { * @return A list of all matching actions */ List getActionsOfType(final Class type, final boolean includeSubclasses); - * + /** * Get all actions which were logged and were caused by the given entity. * @@ -53,7 +52,7 @@ public interface ActionLog { * @return A list of all matching actions */ List getAllActionsOfEntity(Entity entity); - * + /** * Get all actions which were logged of the given type and were caused by the given entity. * @@ -70,7 +69,7 @@ public interface ActionLog { List getActionsOfTypeOfEntity( Entity entity, final Class type, final boolean includeSubclasses ); - * + /** * Log an action. * @@ -78,7 +77,7 @@ List getActionsOfTypeOfEntity( * The action to log */ void logAction(Action actionToLog); - * + /** * Set ActionLog console output (default: {@code true}) * @@ -86,7 +85,7 @@ List getActionsOfTypeOfEntity( * true: log to console, false: do not log to console */ void setConsoleOutput(boolean enable); - * + /** * Get ActionLog console output status. *

@@ -94,5 +93,5 @@ List getActionsOfTypeOfEntity( * logged but not printed to console. */ boolean getConsoleOutput(); - * + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java index 6a3ffad6c..a0f45a739 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityAction.java @@ -9,9 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -20,9 +18,9 @@ * @author Tim Neumann */ public abstract class EntityAction extends Action { - * + private final Entity entity; - * + /** * Create an entity action. * @@ -35,7 +33,7 @@ public EntityAction(final long tickNumber, final Entity entity) { super(tickNumber); this.entity = entity; } - * + /** * @return the entity that caused this action. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java index af69802af..97db49de2 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityCollectAction.java @@ -9,11 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -22,11 +20,11 @@ * @author Tim Neumann */ public class EntityCollectAction extends EntityAction { - * + private final CollectableEntity collected; private final Position collectorPos; private final Position collectedPos; - * + /** * Create an entity collect action. * @@ -51,32 +49,32 @@ public EntityCollectAction( this.collectedPos = collectedPos; this.collectorPos = collectorPos; } - * + /** * @return the entity that was collected */ public CollectableEntity getCollectedEntity() { return this.collected; } - * + /** * @return the position the collected entity was at while being collected */ public Position getCollectedEntityPosition() { return this.collectedPos; } - * + /** * @return the position the collector was at while collecting */ public Position getCollectorPosition() { return this.collectorPos; } - * + @Override public String getDescription() { return this.getEntity() + " (at " + this.getCollectorPosition() + ") collected " + this.getCollectedEntity() + " at " + this.getCollectedEntityPosition(); } - * + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java index 47c149784..38d31591c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDespawnAction.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - import de.unistuttgart.informatik.fius.icge.simulation.Playfield; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -21,9 +19,9 @@ * @author Tim Neumann */ public class EntityDespawnAction extends EntityAction { - * + private final Playfield playfield; - * + /** * Create an entity despawn action * @@ -38,14 +36,14 @@ public EntityDespawnAction(final long tickNumber, final Entity entity, final Pla super(tickNumber, entity); this.playfield = playfield; } - * + /** * @return the playfield the entity was removed from */ public Playfield getPlayfield() { return this.playfield; } - * + @Override public String getDescription() { return this.getEntity() + " despawned from " + this.getPlayfield(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java index 9801fc769..50d03beba 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityDropAction.java @@ -9,11 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -22,11 +20,11 @@ * @author Tim Neumann */ public class EntityDropAction extends EntityAction { - * + private final CollectableEntity dropped; private final Position dropperPos; private final Position dropppedPos; - * + /** * Create an entity drop action. * @@ -51,32 +49,32 @@ public EntityDropAction( this.dropppedPos = droppedPos; this.dropperPos = dropperPos; } - * + /** * @return the entity that was dropped */ public CollectableEntity getDroppedEntity() { return this.dropped; } - * + /** * @return the position the dropped entity was dropped to */ public Position getDroppedEntityPosition() { return this.dropppedPos; } - * + /** * @return the position the dropper was at while dropping */ public Position getDropperPosition() { return this.dropperPos; } - * + @Override public String getDescription() { return this.getEntity() + " (at " + this.getDropperPosition() + ") dropped " + this.getDroppedEntity() + " at " + this.getDroppedEntityPosition(); } - * + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java index 605f04a6d..3905273ae 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityMoveAction.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -23,10 +21,10 @@ * @see EntityTeleportAction */ public abstract class EntityMoveAction extends EntityAction { - * + private final Position from; private final Position to; - * + /** * Create an entity move action. * @@ -44,14 +42,14 @@ public EntityMoveAction(final long tickNumber, final Entity entity, final Positi this.from = from; this.to = to; } - * + /** * @return the position the entity was at before the move */ public Position from() { return this.from; } - * + /** * @return the position the entity is after the move */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java index efeafd410..73e3e0fa6 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntitySpawnAction.java @@ -9,11 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -22,10 +20,10 @@ * @author Tim Neumann */ public class EntitySpawnAction extends EntityAction { - * + private final Playfield playfield; private final Position position; - * + /** * Create an entity spawn action. * @@ -43,21 +41,21 @@ public EntitySpawnAction(final long tickNumber, final Entity entity, final Playf this.playfield = playfield; this.position = position; } - * + /** * @return the playfield the entity was added to */ public Playfield getPlayfield() { return this.playfield; } - * + /** * @return the position the entity was added at */ public Position getPosition() { return this.position; } - * + @Override public String getDescription() { return this.getEntity() + " spawned in " + this.getPlayfield() + " at " + this.getPosition(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java index 30f579a08..9515ebd9b 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityStepAction.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -21,7 +19,7 @@ * @author Tim Neumann */ public class EntityStepAction extends EntityMoveAction { - * + /** * Create an entity step action. * @@ -37,7 +35,7 @@ public class EntityStepAction extends EntityMoveAction { public EntityStepAction(final long tickNumber, final Entity entity, final Position from, final Position to) { super(tickNumber, entity, from, to); } - * + @Override public String getDescription() { return this.getEntity() + " stepped from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java index 572628a66..f533be88c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTeleportAction.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -36,7 +34,7 @@ public class EntityTeleportAction extends EntityMoveAction { public EntityTeleportAction(final long tickNumber, final Entity entity, final Position from, final Position to) { super(tickNumber, entity, from, to); } - * + @Override public String getDescription() { return this.getEntity() + " teleported from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java index b76b43607..5f219c83f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/actions/EntityTurnAction.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.actions; -* - import de.unistuttgart.informatik.fius.icge.simulation.Direction; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -21,10 +19,10 @@ * @author Tim Neumann */ public class EntityTurnAction extends EntityAction { - * + private final Direction from; private final Direction to; - * + /** * Create an entity turn action. * @@ -42,21 +40,21 @@ public EntityTurnAction(final long tickNumber, final Entity entity, final Direct this.from = from; this.to = to; } - * + /** * @return the direction the entity was facing before the turn */ public Direction from() { return this.from; } - * + /** * @return the direction the entity is facing after the turn */ public Direction to() { return this.to; } - * + @Override public String getDescription() { return this.getEntity() + " turned from " + this.from() + " to " + this.to(); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java index 4760def93..04de18bbc 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/BasicEntity.java @@ -9,10 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -* - import java.lang.ref.WeakReference; -import java.util.concurrent.CompletableFuture;* +import java.util.concurrent.CompletableFuture; + import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; @@ -20,7 +19,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityOnAnotherFieldException; import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionAttribute; import de.unistuttgart.informatik.fius.icge.ui.BasicDrawable; -import de.unistuttgart.informatik.fius.icge.ui.Drawable;** +import de.unistuttgart.informatik.fius.icge.ui.Drawable; /** @@ -29,19 +28,19 @@ * @author Tim Neumann */ public abstract class BasicEntity implements Entity { - * + /** Lock object to make setting the Playfield threadsafe. */ private Object fieldLock = new Object(); /** The current (weak) reference to the playfield. */ private WeakReference field; - * + /** * Lock object to ensure no two long running operations ({@code >= 1} clock tick) are scheduled at the same time. */ private Object operationQueueLock = new Object(); /** The completable future representing the completion of the last enqueued operation. */ protected CompletableFuture endOfLastEnqueuedOperation; - * + /** * @throws EntityNotOnFieldException * if this entity is not on a playfield @@ -57,14 +56,14 @@ public Position getPosition() { if (playfield == null) throw new EntityNotOnFieldException("This entity is not on a playfield"); return playfield.getEntityPosition(this); } - * + /** * Get the texture handle, with which to get the texture for this entity. * * @return the texture handle for the texture of this entity */ protected abstract String getTextureHandle(); - * + /** * Get the z position of this entity. *

@@ -74,7 +73,7 @@ public Position getPosition() { * @return the z position of this entity. */ protected abstract int getZPosition(); - * + /** * @throws EntityNotOnFieldException * if this entity is not on a playfield @@ -84,7 +83,7 @@ public Drawable getDrawInformation() { final Position pos = this.getPosition(); return new BasicDrawable(pos.getX(), pos.getY(), this.getZPosition(), this.getTextureHandle()); } - * + @Override public void initOnPlayfield(final Playfield playfield) { if (playfield == null) throw new IllegalArgumentException("The given playfield is null."); @@ -93,7 +92,7 @@ public void initOnPlayfield(final Playfield playfield) { this.field = new WeakReference<>(playfield); } } - * + /** * Check whether this entity is on a playfield * @@ -115,7 +114,7 @@ public boolean isOnPlayfield() { return true; } } - * + /** * Get the playfield of this entity. * @@ -129,7 +128,7 @@ protected Playfield getPlayfield() { return this.field.get(); } } - * + /** * Get the simulation of this entity. * @@ -144,7 +143,7 @@ protected Simulation getSimulation() { return this.getPlayfield().getSimulation(); } } - * + /** * Prevent this entity from performing any long running operation for {@code ticks} simulation ticks. *

@@ -165,7 +164,7 @@ public void sleep(final int ticks) { endOfOperation.complete(null); } } - * + /** * Wait for the last enqueued long running operation to finish before allowing the new Operation to perform. *

@@ -205,10 +204,10 @@ protected void enqueueToPerformNewOperation(CompletableFuture endOfNewOper endOfLastEnqueuedOperation.join(); } } - * + @Override public String toString() { return this.getClass().getSimpleName() + "@" + Integer.toHexString(this.hashCode()); } - * + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java index 3b8f60e73..892ea8f24 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/CollectableEntity.java @@ -8,7 +8,7 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.entity; - * + /** * An entity, which can be collected by {@link EntityCollector}. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java index 6e03ea963..74b3ea471 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Entity.java @@ -9,12 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -* - import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityOnAnotherFieldException; -import de.unistuttgart.informatik.fius.icge.ui.Drawable;** +import de.unistuttgart.informatik.fius.icge.ui.Drawable; /** @@ -27,12 +25,12 @@ public interface Entity { * @return the position of this entity */ Position getPosition(); - * + /** * @return the information required to draw this entity; must not be null */ Drawable getDrawInformation(); - * + /** * Method to initialize this entity after being added to the playfield. *

@@ -51,5 +49,5 @@ public interface Entity { * if the entity is already on a field */ void initOnPlayfield(Playfield playfield); - * + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java index f497dced9..b9752ac75 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityCollector.java @@ -9,11 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -* - import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotCollectEntityException; -import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotDropEntityException;** +import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotDropEntityException; /** @@ -22,7 +20,7 @@ * @author Tim Neumann */ public interface EntityCollector { - * + /** * Check if this can collect and drop the given collectable entity type. * @@ -31,7 +29,7 @@ public interface EntityCollector { * @return true if this entity collector can collect or drop the given entity type */ boolean canCarry(Class type); - * + /** * Collect the given entity. * @@ -43,7 +41,7 @@ public interface EntityCollector { * if an argument is null */ void collect(CollectableEntity entity); - * + /** * Drop the given entity. * @@ -57,5 +55,5 @@ public interface EntityCollector { * if an argument is null */ void drop(CollectableEntity entity, Position pos); - * + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java index aa7e75877..dd9739d38 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/EntityTypeRegistry.java @@ -9,11 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -* - import java.util.Set; -import java.util.function.Supplier;* -import de.unistuttgart.informatik.fius.icge.simulation.exception.ElementExistsException;** +import java.util.function.Supplier; + +import de.unistuttgart.informatik.fius.icge.simulation.exception.ElementExistsException; /** @@ -22,7 +21,7 @@ * @author Fabian Bühler */ public interface EntityTypeRegistry { - * + /** * Register a new entity type by name. *

@@ -43,7 +42,7 @@ public interface EntityTypeRegistry { * if the name is already used */ void registerEntityType(final String typeName, final String textureHandle, Class entityType); - * + /** * Register a new entity type by name. *

@@ -63,14 +62,14 @@ public interface EntityTypeRegistry { * if the name is already used */ void registerEntityType(final String typeName, final String textureHandle, Supplier entityFactory); - * + /** * Get a set of all currently registered entity types. * * @return registered entity types */ Set getRegisteredEntityTypes(); - * + /** * Get the texture handle of a registered entity type. * @@ -81,7 +80,7 @@ public interface EntityTypeRegistry { * if an argument is null */ String getTextureHandleOfEntityType(final String typeName); - * + /** * Get a new Entity instance of a registered entity type. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java index 118a526f4..35c10a440 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/GreedyEntity.java @@ -9,16 +9,15 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -* +import java.util.List; -import java.util.List;* import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.actions.Action; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityCollectAction; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityDropAction; import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotCollectEntityException; import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotDropEntityException; -import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityNotOnFieldException;** +import de.unistuttgart.informatik.fius.icge.simulation.exception.EntityNotOnFieldException; /** @@ -27,22 +26,23 @@ * @author Tim Neumann */ public abstract class GreedyEntity extends MovableEntity implements EntityCollector { - * + /** A lock to synchronize all operations involving the entities inventory. */ - protected final Object inventoryOperationLock = new Object();* - private final Inventory inventory = new Inventory();* + protected final Object inventoryOperationLock = new Object(); + + private final Inventory inventory = new Inventory(); /** * @return the inventory of this greedy entity */ public Inventory getInventory() { return this.inventory; - }* + } @Override public boolean canCarry(final Class type) { return true; - }* + } /** * Get all the currently collectable entities of the given type @@ -57,14 +57,14 @@ public boolean canCarry(final Class type) { */ public List getCurrentlyCollectableEntities(final Class type, final boolean includeSubclasses) { return this.getPlayfield().getEntitiesOfTypeAt(this.getPosition(), type, includeSubclasses); - }* + } @Override public void collect(final CollectableEntity entity) { if (entity == null) throw new IllegalArgumentException("An argument is null."); Position myPos; Position otherPos; - * + synchronized (this.inventoryOperationLock) { try { myPos = this.getPosition(); @@ -72,18 +72,18 @@ public void collect(final CollectableEntity entity) { } catch (final EntityNotOnFieldException e) { throw new CannotCollectEntityException(e); } - * + if (!myPos.equals(otherPos)) throw new CannotCollectEntityException("Not on my field"); - * + this.getSimulation().getPlayfield().removeEntity(entity); this.getInventory().add(entity); - * + final Action action = new EntityCollectAction( this.getSimulation().getSimulationClock().getLastTickNumber(), this, entity, myPos, otherPos ); this.getSimulation().getActionLog().logAction(action); } - }* + } /** * Get all the currently droppable entities of the given type @@ -98,7 +98,7 @@ public void collect(final CollectableEntity entity) { */ public List getCurrentlyDroppableEntities(final Class type, final boolean includeSubclasses) { return this.getInventory().get(type, includeSubclasses); - }* + } @Override public void drop(final CollectableEntity entity, final Position pos) { @@ -110,18 +110,18 @@ public void drop(final CollectableEntity entity, final Position pos) { } catch (final EntityNotOnFieldException e) { throw new CannotCollectEntityException(e); } - * + if (!myPos.equals(pos)) throw new CannotCollectEntityException("Not on my field"); - * + this.getInventory().remove(entity); this.getPlayfield().addEntity(pos, entity); - * + final Action action = new EntityDropAction( this.getSimulation().getSimulationClock().getLastTickNumber(), this, entity, myPos, pos ); this.getSimulation().getActionLog().logAction(action); } - }* + } /** * Drop the given entity at the current position. @@ -135,5 +135,6 @@ public void drop(final CollectableEntity entity, final Position pos) { */ public void drop(final CollectableEntity entity) { this.drop(entity, this.getPosition()); - }* + } + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java index b6ad89ffb..9698fd6fd 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/Inventory.java @@ -8,10 +8,10 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.entity; - * + import de.unistuttgart.informatik.fius.icge.simulation.MultiTypedList; - * - * + + /** * An inventory of a entity. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java index 4e141afdf..d54e68555 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/MovableEntity.java @@ -9,9 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -* +import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletableFuture;* import de.unistuttgart.informatik.fius.icge.simulation.Direction; import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock; @@ -23,7 +22,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionAttribute; import de.unistuttgart.informatik.fius.icge.simulation.inspection.InspectionMethod; import de.unistuttgart.informatik.fius.icge.ui.AnimatedDrawable; -import de.unistuttgart.informatik.fius.icge.ui.Drawable;** +import de.unistuttgart.informatik.fius.icge.ui.Drawable; /** @@ -32,10 +31,12 @@ * @author Tim Neumann */ public abstract class MovableEntity extends BasicEntity { - * - private Direction lookingDirection = Direction.EAST;* - private AnimatedDrawable movingDrawable = null;* - private Direction directionOfAlmostArrivedMove;* + + private Direction lookingDirection = Direction.EAST; + + private AnimatedDrawable movingDrawable = null; + + private Direction directionOfAlmostArrivedMove; @Override public Drawable getDrawInformation() { @@ -43,7 +44,7 @@ public Drawable getDrawInformation() { if (movingDrawable != null) return movingDrawable; final Position pos = this.getPosition(); return new UntilableDrawable(pos.getX(), pos.getY(), this.getZPosition(), this.getTextureHandle()); - }* + } /** * Turn this entity for 90 degrees in clock wise direction. @@ -57,50 +58,50 @@ public void turnClockWise() { } finally { endOfOperation.complete(null); } - }* + } private void turnClockWiseInternal() { final Direction oldLookingDirection = this.lookingDirection; this.lookingDirection = this.lookingDirection.clockWiseNext(); final long tick = this.getSimulation().getSimulationClock().getLastTickNumber(); this.getSimulation().getActionLog().logAction(new EntityTurnAction(tick, this, oldLookingDirection, this.lookingDirection)); - }* + } @InspectionMethod(name = "turnClockwise") private void turnClockWiseInspector() { this.turnClockWiseInternal(); this.recalculateAnimationAfterInspector(); - }* + } private void recalculateAnimationAfterInspector() { if (this.movingDrawable != null) { - * + final long tickStart = this.movingDrawable.getTickStart(); final long duration = this.movingDrawable.getDuration(); - * + Direction movingDir; if (this.directionOfAlmostArrivedMove == null) { movingDir = this.lookingDirection; } else { movingDir = this.directionOfAlmostArrivedMove; } - * + final Position currentPos = this.getPosition(); final Position nextPos = currentPos.adjacentPosition(movingDir); - * + this.movingDrawable = new AnimatedDrawable( tickStart, currentPos.getX(), currentPos.getY(), duration, nextPos.getX(), nextPos.getY(), this.getZPosition(), this.getTextureHandle() ); } - }* + } /** * @return the current looking direction of this entity */ public Direction getLookingDirection() { return this.lookingDirection; - }* + } /** * Set the looking direction @@ -112,7 +113,7 @@ public Direction getLookingDirection() { private void setLookingDirectionByString(final String direction) { this.lookingDirection = Direction.valueOf(direction.toUpperCase()); this.recalculateAnimationAfterInspector(); - }* + } /** * @return the looking direction as a string @@ -120,11 +121,11 @@ private void setLookingDirectionByString(final String direction) { @InspectionAttribute(name = "LookingDirection") public String getLookingDirectionString() { return this.getLookingDirection().toString(); - }* + } private boolean isSolidEntityAt(final Position pos) { return this.getPlayfield().isSolidEntityAt(pos); - }* + } /** * Move this entity forward one field. @@ -138,7 +139,7 @@ public void move() { // use extra future for whole operation as it is split amongst two futures final CompletableFuture endOfOperation = new CompletableFuture<>(); this.enqueueToPerformNewOperation(endOfOperation); - * + // setup move final int duration = 4; final int renderTickDuration = duration * SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; @@ -151,7 +152,7 @@ public void move() { currentTick, currentPos.getX(), currentPos.getY(), renderTickDuration, nextPos.getX(), nextPos.getY(), this.getZPosition(), this.getTextureHandle() ); - * + final CompletableFuture endOfOperation1 = new CompletableFuture<>(); try { clock.scheduleOperationInTicks(duration / 2, endOfOperation1); @@ -161,7 +162,7 @@ public void move() { } finally { endOfOperation1.complete(null); } - * + final CompletableFuture endOfOperation2 = new CompletableFuture<>(); try { clock.scheduleOperationInTicks(duration / 2, endOfOperation2); @@ -173,16 +174,16 @@ public void move() { endOfOperation.complete(null); // complete future for whole operation this.movingDrawable = null; } - }* + } @InspectionMethod(name = "move") private void moveInspector() { final Position currentPos = this.getPosition(); final Position nextPos = currentPos.adjacentPosition(this.lookingDirection); - * + this.internalMove(currentPos, nextPos); this.recalculateAnimationAfterInspector(); - }* + } private void internalMove(final Position currentPos, final Position nextPos) { if (this.isSolidEntityAt(nextPos)) throw new IllegalMoveException("Solid Entity in the way"); @@ -190,7 +191,7 @@ private void internalMove(final Position currentPos, final Position nextPos) { this.getSimulation().getSimulationClock().getLastTickNumber(), this, currentPos, nextPos ); this.getPlayfield().moveEntity(this, nextPos, action); - }* + } /** * @return whether this entity can move forward one field. @@ -198,7 +199,7 @@ private void internalMove(final Position currentPos, final Position nextPos) { public boolean canMove() { final Position nextPos = this.getPosition().adjacentPosition(this.lookingDirection); return this.isOnPlayfield() && !this.isSolidEntityAt(nextPos); - }* + } /** * Move this entity forward one field if that is possible. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java index 53633fbbe..227b4bdcb 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/SolidEntity.java @@ -9,14 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -* /** * A solid entity, through which a movable entity cannot move. * * @author Tim Neumann */ public interface SolidEntity extends Entity { - * + /** * Get whether this entity is really solid at the moment. *

diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java index 0b1ddb4ae..11dccaa7c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/entity/UntilableDrawable.java @@ -9,16 +9,14 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.entity; -* - -import de.unistuttgart.informatik.fius.icge.ui.BasicDrawable;** +import de.unistuttgart.informatik.fius.icge.ui.BasicDrawable; /** * Same as {@link BasicDrawable} but won't tile. */ public class UntilableDrawable extends BasicDrawable { - * + /** * Create a new untilable Drawable. * @@ -30,7 +28,7 @@ public class UntilableDrawable extends BasicDrawable { public UntilableDrawable(final double x, final double y, final int z, final String textureHandle) { super(x, y, z, textureHandle); } - * + @Override public boolean isTilable() { return false; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java index 826e4b900..140d7b2f1 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotCollectEntityException.java @@ -9,19 +9,18 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates that an entity program cannot be run. * * @author Tim Neumann */ public class CannotCollectEntityException extends SimulationExcpetion { - * + /** * generated */ private static final long serialVersionUID = 6758366706458330276L; - * + /** * Constructs a new CannotCollectEntityException with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -29,7 +28,7 @@ public class CannotCollectEntityException extends SimulationExcpetion { public CannotCollectEntityException() { super(); } - * + /** * Constructs a new CannotCollectEntityException with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -40,7 +39,7 @@ public CannotCollectEntityException() { public CannotCollectEntityException(final String message) { super(message); } - * + /** * Constructs a new CannotCollectEntityException with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -55,7 +54,7 @@ public CannotCollectEntityException(final String message) { public CannotCollectEntityException(final Throwable cause) { super(cause); } - * + /** * Constructs a new CannotCollectEntityException with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java index 79c5f93e1..cb8687bcc 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotDropEntityException.java @@ -9,19 +9,18 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates that an entity program cannot be run. * * @author Tim Neumann */ public class CannotDropEntityException extends SimulationExcpetion { - * + /** * generated */ private static final long serialVersionUID = 8237903756645049779L; - * + /** * Constructs a new CannotDropEntityException with {@code null} as its detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -29,7 +28,7 @@ public class CannotDropEntityException extends SimulationExcpetion { public CannotDropEntityException() { super(); } - * + /** * Constructs a new CannotDropEntityException with the specified detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -40,7 +39,7 @@ public CannotDropEntityException() { public CannotDropEntityException(final String message) { super(message); } - * + /** * Constructs a new CannotDropEntityException with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -55,7 +54,7 @@ public CannotDropEntityException(final String message) { public CannotDropEntityException(final Throwable cause) { super(cause); } - * + /** * Constructs a new CannotDropEntityException with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java index 5c2e9303d..82bdd010f 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/CannotRunProgramException.java @@ -9,26 +9,25 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates that an entity program cannot be run. * * @author Tim Neumann */ public class CannotRunProgramException extends IllegalArgumentException { - * + /** * generated */ private static final long serialVersionUID = -5283363131395011240L; - * + /** * Constructs an CannotRunProgramException with no detail message. */ public CannotRunProgramException() { super(); } - * + /** * Constructs an CannotRunProgramException with the specified detail message. * @@ -38,7 +37,7 @@ public CannotRunProgramException() { public CannotRunProgramException(final String s) { super(s); } - * + /** * Constructs a new exception with the specified detail message and cause. * @@ -56,7 +55,7 @@ public CannotRunProgramException(final String s) { public CannotRunProgramException(final String message, final Throwable cause) { super(message, cause); } - * + /** * Constructs a new exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java index b3c64d996..848418cd3 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/ElementExistsException.java @@ -9,26 +9,25 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates that the element already exists. * * @author Tim Neumann */ public class ElementExistsException extends IllegalArgumentException { - * + /** * generated */ private static final long serialVersionUID = -564159508677510779L; - * + /** * Constructs an ElementExistsException with no detail message. */ public ElementExistsException() { super(); } - * + /** * Constructs an ElementExistsException with the specified detail message. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java index 8f340295d..1cfcc701c 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityAlreadyOnFieldExcpetion.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates that an action is illegal, because the subject entity is already in on the relevant * playfield. @@ -21,7 +20,7 @@ public class EntityAlreadyOnFieldExcpetion extends SimulationExcpetion { * generated */ private static final long serialVersionUID = 3177203739377160043L; - * + /** * Constructs a new EntityAlreadyOnFieldExcpetion with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -29,7 +28,7 @@ public class EntityAlreadyOnFieldExcpetion extends SimulationExcpetion { public EntityAlreadyOnFieldExcpetion() { super(); } - * + /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -40,7 +39,7 @@ public EntityAlreadyOnFieldExcpetion() { public EntityAlreadyOnFieldExcpetion(final String message) { super(message); } - * + /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java index 2c5abf422..c36fd3cb6 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityNotOnFieldException.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates that an action was illegal, because the subject entity is not the the relevant playfield. * @@ -20,7 +19,7 @@ public class EntityNotOnFieldException extends SimulationExcpetion { * generated */ private static final long serialVersionUID = -8786124964224174226L; - * + /** * Constructs a new EntityAlreadyOnFieldExcpetion with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -28,7 +27,7 @@ public class EntityNotOnFieldException extends SimulationExcpetion { public EntityNotOnFieldException() { super(); } - * + /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -39,7 +38,7 @@ public EntityNotOnFieldException() { public EntityNotOnFieldException(final String message) { super(message); } - * + /** * Constructs a new EntityAlreadyOnFieldExcpetion with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java index 28a55d953..6378e6448 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/EntityOnAnotherFieldException.java @@ -9,19 +9,18 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates that an action is illegal, because the subject entity is already on another playfield. * * @author Tim Neumann */ public class EntityOnAnotherFieldException extends SimulationExcpetion { - * + /** * generated */ private static final long serialVersionUID = -2894368466373991151L; - * + /** * Constructs a new EntityOnAnotherFieldException with {@code null} as its detail message. The cause is not * initialized, and may subsequently be initialized by a call to {@link #initCause}. @@ -29,7 +28,7 @@ public class EntityOnAnotherFieldException extends SimulationExcpetion { public EntityOnAnotherFieldException() { super(); } - * + /** * Constructs a new EntityOnAnotherFieldException with the specified detail message. The cause is not initialized, * and may subsequently be initialized by a call to {@link #initCause}. @@ -40,7 +39,7 @@ public EntityOnAnotherFieldException() { public EntityOnAnotherFieldException(final String message) { super(message); } - * + /** * Constructs a new EntityOnAnotherFieldException with the specified detail message and cause. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java index b07df57c1..7856ef11d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/IllegalMoveException.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates, that a entity could not move. *

@@ -23,7 +22,7 @@ public class IllegalMoveException extends SimulationExcpetion { * generated */ private static final long serialVersionUID = -4781899414191823139L; - * + /** * Constructs a new IllegalMoveException with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -31,7 +30,7 @@ public class IllegalMoveException extends SimulationExcpetion { public IllegalMoveException() { super(); } - * + /** * Constructs a new IllegalMoveException with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -42,7 +41,7 @@ public IllegalMoveException() { public IllegalMoveException(final String message) { super(message); } - * + /** * Constructs a new IllegalMoveException with the specified detail message and cause. * * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java index edd26ac2f..085bb0fa4 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/SimulationExcpetion.java @@ -9,19 +9,18 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * The parent of all exceptions thrown by the simulation. * * @author Tim Neumann */ public class SimulationExcpetion extends RuntimeException { - * + /** * generated */ private static final long serialVersionUID = 8969492057602725022L; - * + /** * Constructs a new SimulationExcpetion with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -29,7 +28,7 @@ public class SimulationExcpetion extends RuntimeException { public SimulationExcpetion() { super(); } - * + /** * Constructs a new SimulationExcpetion with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -40,7 +39,7 @@ public SimulationExcpetion() { public SimulationExcpetion(final String message) { super(message); } - * + /** * Constructs a new SimulationExcpetion with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -55,7 +54,7 @@ public SimulationExcpetion(final String message) { public SimulationExcpetion(final Throwable cause) { super(cause); } - * + /** * Constructs a new SimulationExcpetion with the specified detail message and cause. * * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java index d368f56e2..c94f941e3 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/TimerAlreadyRunning.java @@ -9,9 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* - -import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock;** +import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock; /** @@ -22,7 +20,7 @@ */ public class TimerAlreadyRunning extends IllegalStateException { private static final long serialVersionUID = 1715637086603245424L; - * + /** * Default constructor */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java index db67688ae..18ae81a10 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/exception/UncheckedInterruptedException.java @@ -9,26 +9,25 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.exception; -* /** * This exception indicates that an entity program cannot be run. * * @author Tim Neumann */ public class UncheckedInterruptedException extends IllegalArgumentException { - * + /** * generated */ private static final long serialVersionUID = -8407441370711369840L; - * + /** * Constructs an EntityProgramInterruptedException with no detail message. */ public UncheckedInterruptedException() { super(); } - * + /** * Constructs an EntityProgramInterruptedException with the specified detail message. * @@ -38,7 +37,7 @@ public UncheckedInterruptedException() { public UncheckedInterruptedException(final String s) { super(s); } - * + /** * Constructs a new exception with the specified detail message and cause. * @@ -56,7 +55,7 @@ public UncheckedInterruptedException(final String s) { public UncheckedInterruptedException(final String message, final Throwable cause) { super(message, cause); } - * + /** * Constructs a new exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java index be366738d..4e4e5d84e 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/AnnotationReader.java @@ -9,13 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; -* - import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.List;** +import java.util.List; /** @@ -26,7 +24,7 @@ public class AnnotationReader { private AnnotationReader() { //hide constructor - }* + } /** * Get all methods with the given annotation in the given class and all parent classes. @@ -40,19 +38,19 @@ private AnnotationReader() { public static List getAllMethodsWithAnnotationRecursively(final Class cls, final Class annotation) { final Method[] methods = cls.getDeclaredMethods(); final List ret = new ArrayList<>(); - * + for (final Method m : methods) { if (m.isAnnotationPresent(annotation)) { ret.add(m); } } - * + final Class superCls = cls.getSuperclass(); if (superCls != null) { ret.addAll(AnnotationReader.getAllMethodsWithAnnotationRecursively(superCls, annotation)); } return ret; - }* + } /** * Get all attributes with the given annotation in the given class and all parent classes. @@ -66,13 +64,13 @@ public static List getAllMethodsWithAnnotationRecursively(final Class public static List getAllAttributesWithAnnotationRecursively(final Class cls, final Class annotation) { final Field[] fields = cls.getDeclaredFields(); final List ret = new ArrayList<>(); - * + for (final Field f : fields) { if (f.isAnnotationPresent(annotation)) { ret.add(f); } } - * + final Class superCls = cls.getSuperclass(); if (superCls != null) { ret.addAll(AnnotationReader.getAllAttributesWithAnnotationRecursively(superCls, annotation)); diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java index 8767c5d40..e1df282e5 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/ClassFinder.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; -* - import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -20,7 +18,7 @@ import java.util.List; import java.util.function.Predicate; import java.util.jar.JarEntry; -import java.util.jar.JarFile;** +import java.util.jar.JarFile; /** @@ -31,7 +29,7 @@ public class ClassFinder { private ClassFinder() { //hide constructor - }* + } /** * Get all classes in the current context class loader, which match the filter. @@ -45,9 +43,9 @@ private ClassFinder() { public static List> getClassesInClassLoader(final Predicate> filter) throws IOException { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final List urls = Collections.list(loader.getResources("de")); - * + final List> classes = new ArrayList<>(); - * + for (final URL url : urls) { if (url.getProtocol().equals("jar")) { ClassFinder.loadClassesFromJar(url, filter, classes); @@ -55,9 +53,9 @@ public static List> getClassesInClassLoader(final Predicate> f ClassFinder.loadClassesFromFS(url, filter, classes, loader); } } - * + return classes; - }* + } private static void loadClassesFromJar(final URL url, final Predicate> filter, final List> classes) throws IOException { @@ -84,7 +82,7 @@ private static void loadClassesFromJar(final URL url, final Predicate> } catch (final URISyntaxException e2) { throw new IOException(e2); } - }* + } private static void loadClassesFromFS( final URL url, final Predicate> filter, final List> classes, final ClassLoader loader @@ -95,7 +93,7 @@ private static void loadClassesFromFS( } catch (URISyntaxException | ClassNotFoundException e) { throw new IOException(e); } - }* + } private static void loadClassInFile( final File file, final List> classes, final ClassLoader loader, final String rootDir, final Predicate> filter @@ -117,7 +115,7 @@ private static void loadClassInFile( } } } - }* + } private static String convertPathToClassName(final String path, final String rootDir) { if (!path.startsWith(rootDir)) throw new IllegalStateException("File not starting with root dir!"); @@ -130,6 +128,6 @@ private static String convertPathToClassName(final String path, final String roo relPath = relPath.replace(fileSep, "."); } return relPath; - * + } } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java index 9fee02a8e..6a0703432 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionAttribute.java @@ -9,14 +9,13 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; -* - import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME;* +import static java.lang.annotation.RetentionPolicy.RUNTIME; + import java.lang.annotation.Documented; import java.lang.annotation.Retention; -import java.lang.annotation.Target;** +import java.lang.annotation.Target; /** @@ -32,7 +31,7 @@ public @interface InspectionAttribute { /** @return The optional name of the attribute, to be displayed in the front end. */ String name() default ""; - * + /** @return Optional argument setting this attribute to read only. */ boolean readOnly() default false; } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java index b5784eff1..f98a59fa9 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionData.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; -* - import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -19,7 +17,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry;** +import java.util.Map.Entry; /** @@ -28,9 +26,10 @@ * @author Tim Neumann */ public class InspectionData { - private final Class c;* + private final Class c; + private final Map inspectableAttributes; - private final Map inspectableMethods;* + private final Map inspectableMethods; /** * Creates a new inspection data object for the given class @@ -44,7 +43,7 @@ public InspectionData(final Class cls) { this.inspectableMethods = new HashMap<>(); this.initAttributes(); this.initMethods(); - }* + } /** * Get the value of the attribute with the given name from the given object. @@ -68,7 +67,7 @@ public Object getAttributeValue(final Object obj, final String name) { } } return null; - }* + } /** * Set's the value of the attribute with the given name for the given object @@ -92,7 +91,7 @@ public boolean setAttributeValue(final Object obj, final String name, final Obje } } return false; - }* + } /** * Get the attribute names of the class for this inspection data. @@ -101,7 +100,7 @@ public boolean setAttributeValue(final Object obj, final String name, final Obje */ public List getAttributeNames() { return Collections.unmodifiableList(new ArrayList<>(this.inspectableAttributes.keySet())); - }* + } /** * Get the type of the attribute with the given name. @@ -114,7 +113,7 @@ public Class getAttributeType(final String attributeName) { final AttributeInspectionPoint p = this.inspectableAttributes.get(attributeName); if (p == null) return null; return p.getType(); - }* + } /** * Check whether the attribute with the given name is read only. @@ -127,14 +126,14 @@ public boolean isAttributeReadOnly(final String attributeName) { final AttributeInspectionPoint p = this.inspectableAttributes.get(attributeName); if (p == null) return true; return p.isReadOnly(); - }* + } /** * @return Whether this inspection data has any inspectable elements. */ public boolean hasAnyInspectableElements() { return !(this.inspectableAttributes.isEmpty() && this.inspectableMethods.isEmpty()); - }* + } /** * Get the mathod names of the class for this inspection data. @@ -143,7 +142,7 @@ public boolean hasAnyInspectableElements() { */ public List getMethodNames() { return Collections.unmodifiableList(new ArrayList<>(this.inspectableMethods.keySet())); - }* + } /** * Get the method detail for the method with the given name @@ -154,7 +153,7 @@ public List getMethodNames() { */ public Method getMethodByName(final String methodName) { return this.inspectableMethods.get(methodName); - }* + } /** * Invoke the method with the given name in the given object, using the given arguments @@ -176,39 +175,39 @@ public Object invokeMethod(final Object obj, final String methodName, final Obje e.printStackTrace(); throw new IllegalStateException("Invokation didn't work", e); } - }* + } private void initMethods() { final List methods = AnnotationReader.getAllMethodsWithAnnotationRecursively(this.c, InspectionMethod.class); - * + for (final Method m : methods) { m.setAccessible(true); this.inspectableMethods.put(this.getDsiplayNameForInspectionMethod(m), m); } - }* + } private void initAttributes() { final List fields = AnnotationReader.getAllAttributesWithAnnotationRecursively(this.c, InspectionAttribute.class); final List methods = AnnotationReader.getAllMethodsWithAnnotationRecursively(this.c, InspectionAttribute.class); - * + for (final Field f : fields) { f.setAccessible(true); this.inspectableAttributes.put(this.getDisplayNameForField(f), new AttributeInspectionPoint(f)); } - * + final Map getters = new HashMap<>(); final Map setters = new HashMap<>(); - * + for (int i = 0; i < methods.size(); i++) { final Method m = methods.get(i); - * + if (this.isGetter(m)) { getters.put(this.getDisplayNameForMethod(m, "get"), m); } else if (this.isSetter(m)) { setters.put(this.getDisplayNameForMethod(m, "set"), m); } else throw new InspectionPointException("Method is neither a getter nor a setter! : " + m.getName()); } - * + for (final Entry entry : getters.entrySet()) { final String name = entry.getKey(); final Method setter = setters.remove(name); @@ -219,55 +218,55 @@ private void initAttributes() { this.validateReadOnlyGetter(getter); getter.setAccessible(true); this.inspectableAttributes.put(name, new AttributeInspectionPoint(getter)); - * + } else { this.validateMethodPair(getter, setter); getter.setAccessible(true); setter.setAccessible(true); this.inspectableAttributes.put(name, new AttributeInspectionPoint(getter, setter)); } - * + } - * + if (setters.size() > 0) throw new InspectionPointException("No getter for setter! : " + setters.values().iterator().next()); - * - }* + + } private boolean isGetter(final Method met) { return (met.getParameterTypes().length == 0) && (met.getReturnType() != Void.TYPE); - }* + } private boolean isSetter(final Method met) { return (met.getParameterTypes().length == 1) && (met.getReturnType() == Void.TYPE); - }* + } private void validateMethodPair(final Method getter, final Method setter) { final Class type = getter.getReturnType(); - * + if (type.equals(Void.TYPE)) throw new InspectionPointException("Getter should return something! : " + getter.getName()); - * + if (getter.getParameterTypes().length != 0) throw new InspectionPointException("Getter should not have parameters! : " + getter.getName()); - * + if (!setter.getReturnType().equals(Void.TYPE)) throw new InspectionPointException("Setter should not be return type null. : " + setter.getName()); - * + final Class[] setterParas = setter.getParameterTypes(); - * + if (setterParas.length != 1) throw new InspectionPointException("Setter should have exactly one parameter! : " + setter.getName()); - * + if (!setterParas[0].equals(type)) throw new InspectionPointException("Getter parameter is not the same type as getter return value"); - * - }* + + } private void validateReadOnlyGetter(final Method getter) { if (getter.getReturnType().equals(Void.TYPE)) throw new InspectionPointException("Getter should return something! : " + getter.getName()); - * + if (getter.getParameterTypes().length != 0) throw new InspectionPointException("Getter should not have parameters! : " + getter.getName()); - }* + } private String getDisplayNameForField(final Field f) { final InspectionAttribute anno = f.getAnnotation(InspectionAttribute.class); @@ -276,7 +275,7 @@ private String getDisplayNameForField(final Field f) { if ((name != null) && !name.isEmpty()) return name; } return f.getName(); - }* + } private String getDsiplayNameForInspectionMethod(final Method m) { final InspectionMethod anno = m.getAnnotation(InspectionMethod.class); @@ -285,7 +284,7 @@ private String getDsiplayNameForInspectionMethod(final Method m) { if ((name != null) && !name.isEmpty()) return name; } return m.getName(); - }* + } private String getDisplayNameForMethod(final Method m, final String possiblePrefixToRemove) { final InspectionAttribute anno = m.getAnnotation(InspectionAttribute.class); @@ -293,15 +292,15 @@ private String getDisplayNameForMethod(final Method m, final String possiblePref final String name = anno.name(); if ((name != null) && !name.isEmpty()) return name; } - * + String name = m.getName(); - * + if (name.toLowerCase().startsWith(possiblePrefixToRemove)) { name = name.substring(3); name = name.substring(0, 1).toLowerCase() + name.substring(1); } return name; - }* + } private static class AttributeInspectionPoint { private static final Map, Class> primitiveToWrapperMap = new HashMap<>(); @@ -322,7 +321,7 @@ private static class AttributeInspectionPoint { private final Method setter; private final Class type; private final boolean readOnly; - * + /** * Creates a new attribute inspection point for a field * @@ -337,7 +336,7 @@ public AttributeInspectionPoint(final Field field) { this.type = this.convertTypeToWrappers(field.getType()); this.readOnly = field.getAnnotation(InspectionAttribute.class).readOnly(); } - * + public AttributeInspectionPoint(final Method getter) { this.usesField = false; this.f = null; @@ -346,7 +345,7 @@ public AttributeInspectionPoint(final Method getter) { this.type = this.convertTypeToWrappers(getter.getReturnType()); this.readOnly = true; } - * + public AttributeInspectionPoint(final Method getter, final Method setter) { this.usesField = false; this.f = null; @@ -355,17 +354,17 @@ public AttributeInspectionPoint(final Method getter, final Method setter) { this.type = this.convertTypeToWrappers(getter.getReturnType()); this.readOnly = false; } - * + private Class convertTypeToWrappers(final Class cls) { if (!cls.isPrimitive()) return cls; return AttributeInspectionPoint.primitiveToWrapperMap.get(cls); } - * + public Object getValue(final Object obj) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (this.usesField) return this.f.get(obj); return this.getter.invoke(obj); } - * + public void setValue(final Object obj, final Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { if (this.readOnly) throw new InspectionPointException("Attribute is read only."); @@ -376,7 +375,7 @@ public void setValue(final Object obj, final Object value) this.setter.invoke(obj, value); } } - * + /** * Get's {@link #type type} * @@ -385,7 +384,7 @@ public void setValue(final Object obj, final Object value) public Class getType() { return this.type; } - * + /** * Get's {@link #readOnly readOnly} * @@ -394,7 +393,7 @@ public Class getType() { public boolean isReadOnly() { return this.readOnly; } - }* + } /** * A exception that is thrown when an error with a inspection point occurs. @@ -406,7 +405,7 @@ public static class InspectionPointException extends RuntimeException { * generated */ private static final long serialVersionUID = 6324656121971704376L; - * + /** * Constructs a new runtime exception with {@code null} as its detail message. The cause is not initialized, and * may subsequently be initialized by a call to {@link #initCause}. @@ -414,7 +413,7 @@ public static class InspectionPointException extends RuntimeException { public InspectionPointException() { super(); } - * + /** * Constructs a new runtime exception with the specified detail message. The cause is not initialized, and may * subsequently be initialized by a call to {@link #initCause}. @@ -425,7 +424,7 @@ public InspectionPointException() { public InspectionPointException(final String message) { super(message); } - * + /** * Constructs a new runtime exception with the specified detail message and cause. *

@@ -442,7 +441,7 @@ public InspectionPointException(final String message) { public InspectionPointException(final String message, final Throwable cause) { super(message, cause); } - * + /** * Constructs a new runtime exception with the specified cause and a detail message of * {@code (cause==null ? null : cause.toString())} (which typically contains the class and detail message of @@ -457,7 +456,7 @@ public InspectionPointException(final String message, final Throwable cause) { public InspectionPointException(final Throwable cause) { super(cause); } - * + /** * Constructs a new runtime exception with the specified detail message, cause, suppression enabled or disabled, * and writable stack trace enabled or disabled. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java index 1337bb826..5fe7331e0 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionManager.java @@ -9,15 +9,14 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; -* - import java.io.IOException; import java.lang.reflect.Method; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map;* -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import java.util.Map; + +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -26,8 +25,8 @@ * @author Tim Neumann */ public class InspectionManager { - * - private final Map, InspectionData> inspectableClasses = new HashMap<>();* + + private final Map, InspectionData> inspectableClasses = new HashMap<>(); /** * Create a new inspection manager. @@ -35,7 +34,7 @@ public class InspectionManager { public InspectionManager() { try { final List> classes = ClassFinder.getClassesInClassLoader(c -> true); - * + for (final Class cls : classes) { final InspectionData d = new InspectionData(cls); if (d.hasAnyInspectableElements()) { @@ -45,7 +44,7 @@ public InspectionManager() { } catch (final IOException e) { e.printStackTrace(); } - }* + } /** * Get's all attribute names of the given entity. @@ -58,7 +57,7 @@ public List getAttributeNamesOfEntity(final Entity entity) { final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return Collections.emptyList(); return d.getAttributeNames(); - }* + } /** * Get's all method names of the given entity. @@ -71,7 +70,7 @@ public List getMethodNamesOfEntity(final Entity entity) { final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return Collections.emptyList(); return d.getMethodNames(); - }* + } /** * Checks whether the attribute with the given name in the given entity is writable. @@ -86,7 +85,7 @@ public boolean isAttributeEditable(final Entity entity, final String attributeNa final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return false; return !d.isAttributeReadOnly(attributeName); - }* + } /** * Get's the type of the attribute with the given name in the given entity. @@ -101,7 +100,7 @@ public Class getAttributeType(final Entity entity, final String attributeName final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return null; return d.getAttributeType(attributeName); - }* + } /** * Get the value of the attribute with the given name from the given entity @@ -116,7 +115,7 @@ public Object getAttributeValue(final Entity entity, final String attributeName) final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return null; return d.getAttributeValue(entity, attributeName); - }* + } /** * Set the value of the attribute with the given name in the given entity @@ -133,7 +132,7 @@ public boolean setAttributeValue(final Entity entity, final String attributeName final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return false; return d.setAttributeValue(entity, attributeName, value); - }* + } /** * Get the detail of the method with the given name of the given name. @@ -148,7 +147,7 @@ public Method getMethodDetail(final Entity entity, final String methodName) { final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) return null; return d.getMethodByName(methodName); - }* + } /** * Invokes the method with the given name on the given entity. Uses the given arguments. @@ -167,5 +166,6 @@ public Object invokeMethod(final Entity entity, final String methodName, final O final InspectionData d = this.inspectableClasses.get(entity.getClass()); if (d == null) throw new IllegalStateException("Not a known inspectable class"); return d.invokeMethod(entity, methodName, args); - }* + } + } diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java index b51ca5ee0..a8b540048 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/inspection/InspectionMethod.java @@ -8,15 +8,15 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.inspection; - * + import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; - * + import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; - * - * + + /** * A annotation specifying that the annotated method should be displayed as a method in the inspector. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java index 5b48e6ad3..d023fec70 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulation.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal; -* - import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; @@ -27,7 +25,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.internal.tasks.StandardTaskRunner; import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; import de.unistuttgart.informatik.fius.icge.ui.GameWindow; -import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy;** +import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; /** @@ -36,15 +34,16 @@ * @author Tim Neumann */ public class StandardSimulation implements Simulation { - * + private final StandardPlayfield playfield; private final StandardSimulationClock simulationClock; private final StandardActionLog actionLog; private final StandardEntityTypeRegistry entityTypeRegistry; private final TaskVerifier taskVerifier; - private final StandardSimulationProxy simulationProxy;* - private StandardTaskRunner runningTask; - private final StandardProgramRunner programRunner;* + private final StandardSimulationProxy simulationProxy; + + private StandardTaskRunner runningTask; + private final StandardProgramRunner programRunner; /** * Creates a new standard simulation with the given parameters. @@ -72,59 +71,59 @@ public StandardSimulation( this.actionLog = actionLog; this.entityTypeRegistry = entityTypeRegistry; this.taskVerifier = taskVerifier; - * + this.programRunner = new StandardProgramRunner(); - * + this.playfield.initialize(this); - * + if (taskVerifier != null) { taskVerifier.attachToSimulation(this); } - * + this.simulationProxy = new StandardSimulationProxy( this, simulationClock, inspectionManager, entityTypeRegistry, playfield, taskVerifier ); - }* + } @Override public Playfield getPlayfield() { return this.playfield; - }* + } @Override public TaskVerifier getTaskVerifier() { return this.taskVerifier; - }* + } @Override public SimulationClock getSimulationClock() { return this.simulationClock; - }* + } @Override public ActionLog getActionLog() { return this.actionLog; - }* + } @Override public EntityTypeRegistry getEntityTypeRegistry() { return this.entityTypeRegistry; - }* + } @Override public SimulationProxy getSimulationProxyForWindow() { return this.simulationProxy; - }* + } @Override public void attachToWindow(final GameWindow window) { this.attachToWindow(window, false); - }* + } @Override public void attachToWindow(final GameWindow window, final boolean stopWithWindowClose) { this.getSimulationProxyForWindow().attachToGameWindow(window, stopWithWindowClose); - }* + } @Override public void stop() { @@ -134,7 +133,7 @@ public void stop() { } this.programRunner.stopAll(); this.simulationClock.shutdown(); // stop the clock for good - }* + } @Override public void runTask(final Task taskToRun) { @@ -143,7 +142,7 @@ public void runTask(final Task taskToRun) { } this.runningTask = new StandardTaskRunner(taskToRun, this); this.runningTask.runTask(); - }* + } @Override public void runProgram(Program program, S entity) { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java index 7b149235f..6ce7abac6 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationClock.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal; -* - import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -22,11 +20,12 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; -import java.util.function.Function;* +import java.util.function.Function; + import de.unistuttgart.informatik.fius.icge.simulation.SimulationClock; import de.unistuttgart.informatik.fius.icge.simulation.exception.TimerAlreadyRunning; import de.unistuttgart.informatik.fius.icge.simulation.exception.UncheckedInterruptedException; -import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException;** +import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException; /** @@ -37,15 +36,21 @@ * @version 1.0 */ public class StandardSimulationClock implements SimulationClock { - private final Object tickListenerLock = new Object();* + private final Object tickListenerLock = new Object(); + private final List> tickListeners; - private final List> postTickListeners;* - private final Set> operationBoundaries;* - private Consumer animationTickListener; - private StateChangeListener stateChangeListener;* - private TimerTask task; - private final Timer timer;* - private volatile long tickCount;* + private final List> postTickListeners; + + private final Set> operationBoundaries; + + private Consumer animationTickListener; + private StateChangeListener stateChangeListener; + + private TimerTask task; + private final Timer timer; + + private volatile long tickCount; + /** * Setting this to true will signal the clock that it is in shutdown mode. *

@@ -58,8 +63,9 @@ public class StandardSimulationClock implements SimulationClock { *

* */ - private volatile boolean shuttingDown;* - private int period;* + private volatile boolean shuttingDown; + + private int period; /** * Default constructor @@ -72,7 +78,7 @@ public StandardSimulationClock() { this.period = SimulationClock.DEFAULT_RENDER_TICK_PERIOD; this.shuttingDown = false; this.operationBoundaries = Collections.synchronizedSet(new HashSet<>()); - }* + } /** * This internal start function actually starts the timer but does not notify the simulation proxy. If you don't @@ -81,16 +87,16 @@ public StandardSimulationClock() { public synchronized void startInternal() { if (this.isRunning()) throw new TimerAlreadyRunning(); if (this.shuttingDown) return; - * + this.task = new TimerTask() { - * + @Override public void run() { StandardSimulationClock.this.tick(); } }; this.timer.schedule(this.task, 0, this.period); - }* + } /** * This internal stop function actually stops the timer but does not notify the simulation proxy. If you don't know @@ -101,7 +107,7 @@ public synchronized void stopInternal() { this.task.cancel(); } this.task = null; - }* + } /** * Shuts down this clock. @@ -124,62 +130,62 @@ public synchronized void shutdown() { for (final var boundary : Set.copyOf(this.operationBoundaries)) { boundary.cancel(true); } - }* + } @Override public synchronized void setPeriod(final int millis) { this.period = millis; - * + if (this.isRunning()) { this.stop(); this.start(); } - }* + } @Override public int getRenderTickPeriod() { return this.period; - }* + } @Override public int getGameTickPeriod() { return this.period * SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; - }* + } @Override public boolean isRunning() { return this.task != null; - }* + } @Override public synchronized void start() { if (this.stateChangeListener != null) { this.stateChangeListener.clockStarted(); } - * + this.startInternal(); - }* + } @Override public synchronized void stop() { if (this.stateChangeListener != null) { this.stateChangeListener.clockPaused(); } - * + this.stopInternal(); - }* + } @Override public synchronized void step() { if (this.isRunning()) throw new TimerAlreadyRunning(); if (this.shuttingDown) return; - * + new Thread(() -> { StandardSimulationClock.this.tickCount = ((StandardSimulationClock.this.tickCount - (StandardSimulationClock.this.tickCount % 8)) + 7); StandardSimulationClock.this.tick(); }, "single-step").start(); - }* + } /** * Process a tick @@ -198,7 +204,7 @@ private void tick() { this.animationTickListener.accept(this.tickCount); } } - }* + } /** * Process a simulation tick @@ -214,7 +220,7 @@ private void tickSimulation(final long tickNumber) { this.tickListeners.remove(listener); } } - * + for (final var listener : List.copyOf(this.postTickListeners)) { //Don't continue to process tick when shutting down. if (this.shuttingDown) return; @@ -222,7 +228,7 @@ private void tickSimulation(final long tickNumber) { this.postTickListeners.remove(listener); } } - }* + } /** * Set the animation tick listener, that gets called every animation tick and is responsible for informing the UI. @@ -236,7 +242,7 @@ public void setAnimationTickListener(final Consumer listener) { if ((this.animationTickListener == null) || (listener == null)) { this.animationTickListener = listener; } else throw new ListenerSetException(); - }* + } /** * Set the state change listener, that gets called when the clock get's started or paused through public API and is @@ -251,7 +257,7 @@ public void setStateChangeListener(final StateChangeListener listener) { if ((this.stateChangeListener == null) || (listener == null)) { this.stateChangeListener = listener; } else throw new ListenerSetException(); - }* + } /** * Remove the state change listener, that gets called when the clock get's started or paused through public API and @@ -259,7 +265,7 @@ public void setStateChangeListener(final StateChangeListener listener) { */ public void removeStateChangeListener() { this.stateChangeListener = null; - }* + } @Override public void registerTickListener(final Function listener) { @@ -267,7 +273,7 @@ public void registerTickListener(final Function listener) { synchronized (this.tickListenerLock) { this.tickListeners.add(listener); } - }* + } @Override public void registerPostTickListener(final Function listener) { @@ -275,18 +281,18 @@ public void registerPostTickListener(final Function listener) { synchronized (this.tickListenerLock) { this.postTickListeners.add(listener); } - }* + } @Override public long getLastTickNumber() { //not rounding is intended here as we'd need floor and casting is the same as floor for positive integers return this.tickCount / SimulationClock.RENDER_TICKS_PER_SIMULATION_TICK; - }* + } @Override public long getLastRenderTickNumber() { return this.tickCount; - }* + } @Override public void scheduleOperationAtTick(final long tick, final CompletableFuture endOfOperation) { @@ -321,17 +327,17 @@ public void scheduleOperationAtTick(final long tick, final CompletableFuture endOfOperation) { this.scheduleOperationAtTick(this.getLastTickNumber() + ticks, endOfOperation); - }* + } @Override public void scheduleOperationAtNextTick(final CompletableFuture endOfOperation) { this.scheduleOperationInTicks(1, endOfOperation); - }* + } /** * The interface for a listener listening for simulation clock starts and stops. The listener is only informed when @@ -342,7 +348,7 @@ public interface StateChangeListener { * The clock was started. */ void clockStarted(); - * + /** * The clock was paused/stopped. */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java index 7060924c1..20a493495 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/StandardSimulationProxy.java @@ -9,13 +9,12 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal; -* - import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Consumer;* +import java.util.function.Consumer; + import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier; @@ -32,7 +31,7 @@ import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode; import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ClockButtonState; -import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState;** +import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState; /** @@ -44,26 +43,30 @@ * @version 1.0 */ public class StandardSimulationProxy implements SimulationProxy { - * + /** A lookup table for the simulation times */ public static final int[] SIMULATION_TIMES = { // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 1000, 415, 200, 115, 75, 50, 42, 34, 26, 18, 10 // These values are aproximated by two functions originally by haslersn which where modified by waeltkts - };* + }; + // GAME WINDOW private GameWindow gameWindow; - private boolean stopSimulationWithWindowClose = false;* + private boolean stopSimulationWithWindowClose = false; + // MANAGERS - private final InspectionManager inspectionManager;* + private final InspectionManager inspectionManager; + // CURRENT SIMULATION - private final Simulation simulation; - private final StandardEntityTypeRegistry entityTypeRegistry; - private final StandardSimulationClock simulationClock; - private final StandardPlayfield playfield; - private final TaskVerifier taskVerifier; - private final Map simualtionSidebarMap;* - private Entity entityToInspect;* + private final Simulation simulation; + private final StandardEntityTypeRegistry entityTypeRegistry; + private final StandardSimulationClock simulationClock; + private final StandardPlayfield playfield; + private final TaskVerifier taskVerifier; + private final Map simualtionSidebarMap; + + private Entity entityToInspect; /** * Create a new standard simulation proxy @@ -92,7 +95,7 @@ public StandardSimulationProxy( this.playfield = playfield; this.taskVerifier = taskVerifier; this.simualtionSidebarMap = new ConcurrentHashMap<>(); - * + // attach tick listeners to simulation clock // only do this once per SimulationProxy as unsetting these listeners is not possible atm this.simulationClock.setAnimationTickListener(new Consumer() { @@ -103,24 +106,24 @@ public void accept(final Long tickCount) { } } }); - * + this.simulationClock.registerPostTickListener(unused -> { updateEntityInspector(); return true; // post tick listener could be removed by returning false here }); - }* + } @Override public void attachToGameWindow(final GameWindow window) { this.attachToGameWindow(window, false); - }* + } @Override public void attachToGameWindow(final GameWindow window, final boolean stopWithWindowClose) { if (this.gameWindow != null) throw new IllegalStateException("Already attached to a window!"); this.gameWindow = window; this.stopSimulationWithWindowClose = stopWithWindowClose; - * + //Simulation Clock if (this.simulationClock.isRunning()) { this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); @@ -128,21 +131,21 @@ public void attachToGameWindow(final GameWindow window, final boolean stopWithWi this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); } this.simulationSpeedChange(this.gameWindow.getToolbar().getSpeedSliderPosition()); - * + this.simulationClock.setStateChangeListener(new StateChangeListener() { @Override public void clockStarted() { StandardSimulationProxy.this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); } - * + @Override public void clockPaused() { StandardSimulationProxy.this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); } }); - * + //EntityDrawing - * + this.playfield.setDrawablesChangedListener(new Consumer>() { @Override public void accept(final List drawables) { @@ -151,10 +154,10 @@ public void accept(final List drawables) { } } }); - * + //ControlButtonState this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.VIEW); - * + //EntitySelection this.entityTypeRegistry.setEntityRegisteredListener((entityName, textureHandle) -> { if (StandardSimulationProxy.this.gameWindow != null) { @@ -172,7 +175,7 @@ public void accept(final List drawables) { } catch (@SuppressWarnings("unused") final NullPointerException e) { // catching exception instead of checking before allows to avoid synchronization here } - * + this.gameWindow.getEntitySidebar().setSimulationTreeRootNode(this.playfield.getSimulationTree()); this.gameWindow.getEntitySidebar().enableSimulationTree(); this.playfield.setSimulationTreeEntityAddedListener((node, entity) -> { @@ -183,18 +186,18 @@ public void accept(final List drawables) { this.simualtionSidebarMap.remove(node); this.gameWindow.getEntitySidebar().updateSimulationTree(); }); - * + this.gameWindow.getEntitySidebar().disableEntityInspector(); - * + // taskState TaskInformation task = null; if (this.taskVerifier != null) { task = this.taskVerifier.getTaskInformation(); } this.gameWindow.getTaskStatusDisplay().setTaskInformation(task); - * + this.gameWindow.setSimulationProxy(this); - }* + } @Override public void windowClosed() { @@ -205,15 +208,15 @@ public void windowClosed() { this.playfield.removeSimulationTreeEntityAddedListener(); this.playfield.removeSimulationTreeEntityRemovedListener(); this.entityTypeRegistry.removeEntityRegisteredListener(); - * + // remove gameWindow reference this.gameWindow = null; - * + // stop simulation if (this.stopSimulationWithWindowClose) { this.simulation.stop(); } - }* + } @Override public void buttonPressed(final ButtonType type) { @@ -224,7 +227,7 @@ public void buttonPressed(final ButtonType type) { } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PLAYING); break; - * + case STEP: if (!this.simulationClock.isRunning()) { this.simulationClock.step(); @@ -233,37 +236,37 @@ public void buttonPressed(final ButtonType type) { } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); break; - * + case PAUSE: if (this.simulationClock.isRunning()) { this.simulationClock.stopInternal(); } this.gameWindow.getToolbar().setClockButtonState(ClockButtonState.PAUSED); break; - * + case VIEW: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.VIEW); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.VIEW); break; - * + case ADD: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.ADD); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.ADD); break; - * + case SUB: this.gameWindow.getToolbar().setControlButtonState(ControlButtonState.SUB); this.gameWindow.getPlayfieldDrawer().setSelectedTool(ControlButtonState.SUB); break; - * + default: } - }* + } @Override public void simulationSpeedChange(final int value) { this.simulationClock.setPeriod(StandardSimulationProxy.SIMULATION_TIMES[value]); - }* + } @Override public void selectedEntityChanged(final String name) { @@ -271,9 +274,9 @@ public void selectedEntityChanged(final String name) { if ((name != null) && !name.equals("")) { textureHandle = this.entityTypeRegistry.getTextureHandleOfEntityType(name); } - * + this.gameWindow.getPlayfieldDrawer().setSelectedEntityType(name, textureHandle); - }* + } @Override public void refreshTaskInformation() { @@ -283,7 +286,7 @@ public void refreshTaskInformation() { task = this.taskVerifier.getTaskInformation(); } this.gameWindow.getTaskStatusDisplay().setTaskInformation(task); - }* + } @Override public void spawnEntityAt(final String typeName, final int x, final int y) { @@ -298,12 +301,12 @@ public void spawnEntityAt(final String typeName, final int x, final int y) { System.out.println("Something went wrong while creating new entity."); e.printStackTrace(); } - }* + } @Override public void clearCell(final int x, final int y) { final List toRemove = this.playfield.getEntitiesAt(new Position(x, y)); - * + toRemove.forEach(entity -> { try { this.playfield.removeEntity(entity); @@ -311,11 +314,11 @@ public void clearCell(final int x, final int y) { // nothing to do because entity was either null or already not on the field } }); - }* + } private EntityInspectorEntry[] getEntries(final Entity e) { final List result = new ArrayList<>(); - * + for (final String name : this.inspectionManager.getAttributeNamesOfEntity(e)) { String type = "string"; if (!this.inspectionManager.isAttributeEditable(e, name)) { @@ -334,7 +337,7 @@ private EntityInspectorEntry[] getEntries(final Entity e) { this.updateEntityInspector(); })); } - * + for (final String name : this.inspectionManager.getMethodNamesOfEntity(e)) { final String type = "function"; result.add(new EntityInspectorEntry(name, type, "", unused -> { @@ -345,13 +348,13 @@ private EntityInspectorEntry[] getEntries(final Entity e) { })); } return result.toArray(new EntityInspectorEntry[result.size()]); - }* + } private void updateEntityInspector() { if (this.gameWindow == null) return; if (this.entityToInspect == null) return; this.gameWindow.getEntitySidebar().setEntityInspectorEntries(this.getEntries(this.entityToInspect)); - }* + } @Override public void selectedSimulationEntityChange(final SimulationTreeNode node) { @@ -360,7 +363,7 @@ public void selectedSimulationEntityChange(final SimulationTreeNode node) { } else { this.entityToInspect = this.simualtionSidebarMap.get(node); } - * + if (this.entityToInspect != null) { this.gameWindow.getEntitySidebar().enableEntityInspector(); this.gameWindow.getEntitySidebar().setEntityInspectorName(this.entityToInspect.toString()); @@ -370,7 +373,7 @@ public void selectedSimulationEntityChange(final SimulationTreeNode node) { this.gameWindow.getEntitySidebar().setEntityInspectorEntries(new EntityInspectorEntry[0]); this.gameWindow.getEntitySidebar().disableEntityInspector(); } - }* + } @Override public void entityValueChange(final String name, final String value) { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java index 9e0c2ee36..5ff023cef 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/actions/StandardActionLog.java @@ -9,17 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.actions; -* - import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map;* +import java.util.Map; + import de.unistuttgart.informatik.fius.icge.simulation.MultiTypedList; import de.unistuttgart.informatik.fius.icge.simulation.actions.Action; import de.unistuttgart.informatik.fius.icge.simulation.actions.ActionLog; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityAction; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -28,30 +27,30 @@ * @author Tim Neumann */ public class StandardActionLog implements ActionLog { - * + private final Object actionsLock = new Object(); private final Object entityActionsLock = new Object(); - * + private final MultiTypedList actions = new MultiTypedList<>(); - * + private final Map> entityActions = new HashMap<>(); - * + private boolean consoleLog = true; - * + @Override public List getAllActions() { synchronized (this.actionsLock) { return this.actions.get(Action.class, true); } } - * + @Override public List getActionsOfType(final Class type, final boolean includeSubclasses) { synchronized (this.actionsLock) { return this.actions.get(type, includeSubclasses); } } - * + @Override public List getAllActionsOfEntity(final Entity entity) { synchronized (this.entityActionsLock) { @@ -60,7 +59,7 @@ public List getAllActionsOfEntity(final Entity entity) { return list.get(EntityAction.class, true); } } - * + @Override public List getActionsOfTypeOfEntity( final Entity entity, final Class type, final boolean includeSubclasses @@ -71,7 +70,7 @@ public List getActionsOfTypeOfEntity( return list.get(type, includeSubclasses); } } - * + @Override public void logAction(final Action actionToLog) { if (actionToLog instanceof EntityAction) { @@ -91,12 +90,12 @@ public void logAction(final Action actionToLog) { System.out.println(actionToLog.getDescription()); } } - * + @Override public void setConsoleOutput(boolean enable) { this.consoleLog = enable; } - * + @Override public boolean getConsoleOutput() { return this.consoleLog; diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java index e55819f6d..cb32e5870 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/entity/StandardEntityTypeRegistry.java @@ -9,17 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.entity; -* - import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.function.Supplier;* +import java.util.function.Supplier; + import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; import de.unistuttgart.informatik.fius.icge.simulation.entity.EntityTypeRegistry; import de.unistuttgart.informatik.fius.icge.simulation.exception.ElementExistsException; -import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException;** +import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException; /** @@ -28,10 +27,11 @@ * @author Fabian Bühler */ public class StandardEntityTypeRegistry implements EntityTypeRegistry { - * + private final Map> typeToEntityFactory = new HashMap<>(); - private final Map typeToTextureHandle = new HashMap<>();* - private EntityRegisteredListener entityRegisteredListener;* + private final Map typeToTextureHandle = new HashMap<>(); + + private EntityRegisteredListener entityRegisteredListener; @Override public void registerEntityType(final String typeName, final String textureHandle, final Class entityType) { @@ -49,7 +49,7 @@ public void registerEntityType(final String typeName, final String textureHandle } }; this.registerEntityType(typeName, textureHandle, entityFactory); - }* + } @Override public synchronized void registerEntityType( @@ -63,22 +63,22 @@ public synchronized void registerEntityType( if (this.typeToEntityFactory.containsKey(typeName)) throw new ElementExistsException(); this.typeToEntityFactory.put(typeName, entityFactory); this.typeToTextureHandle.put(typeName, textureHandle); - * + if (this.entityRegisteredListener != null) { this.entityRegisteredListener.entityWasRegistered(typeName, textureHandle); } - }* + } @Override public Set getRegisteredEntityTypes() { return this.typeToEntityFactory.keySet(); - }* + } @Override public String getTextureHandleOfEntityType(final String typeName) { if ((typeName == null) || typeName.equals("")) throw new IllegalArgumentException("Type name cannot be null or empty!"); return this.typeToTextureHandle.get(typeName); - }* + } @Override public Entity getNewEntity(final String typeName) { @@ -86,7 +86,7 @@ public Entity getNewEntity(final String typeName) { final Supplier entityFactory = this.typeToEntityFactory.get(typeName); if (entityFactory == null) return null; return entityFactory.get(); - }* + } /** * Set an entity selector listener that gets informed about all entity types added. @@ -105,14 +105,14 @@ public synchronized void setEntityRegisteredListener(final EntityRegisteredListe } this.entityRegisteredListener = listener; } else throw new ListenerSetException(); - }* + } /** * Remove the set entity selector listener that gets informed about all entity types added. */ public synchronized void removeEntityRegisteredListener() { this.entityRegisteredListener = null; - }* + } /** * The interface for when an entity is registered diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java index 68469e60b..a42c37afc 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/PlayfieldCell.java @@ -9,11 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.playfield; -* - import de.unistuttgart.informatik.fius.icge.simulation.MultiTypedList; import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -23,7 +21,7 @@ */ public class PlayfieldCell extends MultiTypedList { private final Position pos; - * + /** * Create a new playfield cell, * @@ -34,7 +32,7 @@ public PlayfieldCell(final Position pos) { super(); this.pos = pos; } - * + /** * @return the position of this cell */ diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java index 7bc9cc970..5aa777a98 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/playfield/StandardPlayfield.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.playfield; -* - import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; @@ -19,7 +17,8 @@ import java.util.Timer; import java.util.TimerTask; import java.util.function.BiConsumer; -import java.util.function.Consumer;* +import java.util.function.Consumer; + import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; @@ -34,7 +33,7 @@ import de.unistuttgart.informatik.fius.icge.simulation.internal.StandardSimulation; import de.unistuttgart.informatik.fius.icge.ui.Drawable; import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode; -import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException;** +import de.unistuttgart.informatik.fius.icge.ui.exception.ListenerSetException; /** @@ -43,17 +42,22 @@ * @author Tim Neumann */ public class StandardPlayfield implements Playfield { - private WeakReference sim;* - private final Object playfieldLock = new Object();* - private final Map cells = new HashMap<>(); - private final Map entityPositions = new HashMap<>();* - private SimulationTreeNode simualtionTreeRootNode;* + private WeakReference sim; + + private final Object playfieldLock = new Object(); + + private final Map cells = new HashMap<>(); + private final Map entityPositions = new HashMap<>(); + + private SimulationTreeNode simualtionTreeRootNode; + private BiConsumer simulationTreeEntityAddedListener; - private Consumer simulationTreeEntityRemovedListener;* - private Consumer> drawablesChangedListener;* - private boolean awaitingEntityDraw = false; - private long timeBetweenDraws = 32; //the time between draw calls in milliseconds - * + private Consumer simulationTreeEntityRemovedListener; + + private Consumer> drawablesChangedListener; + + private boolean awaitingEntityDraw = false; + private long timeBetweenDraws = 32; //the time between draw calls in milliseconds /** * Initialize the playfield for the given simulation @@ -67,18 +71,18 @@ public void initialize(final StandardSimulation simulation) { this.drawEntities(); return true; }); - * + this.simualtionTreeRootNode = new SimulationTreeNode("root", "Entities", "", false); - * + new Timer().scheduleAtFixedRate(new TimerTask() { - * + @Override public void run() { drawEntitiesInternal(); } - * + }, 0, this.timeBetweenDraws); - }* + } /** * @throws IllegalStateException @@ -90,7 +94,7 @@ public Simulation getSimulation() { final Simulation simulation = this.sim.get(); if (simulation == null) throw new IllegalStateException("This playfield is not part of any simulation."); return simulation; - }* + } /** * Queues a draw update to the playfield drawer. Draw updates are sent to the playfield drawer automatically every @@ -98,7 +102,7 @@ public Simulation getSimulation() { */ public void drawEntities() { this.awaitingEntityDraw = true; - }* + } /** * Converts all entities to drawables and sends them to the playfield drawer. @@ -123,13 +127,13 @@ private void drawEntitiesInternal() { } catch (@SuppressWarnings("unused") final IllegalStateException e) { //If we are not attached to a simultion we do not need to draw anything } - * - }* + + } @Override public List getAllEntities() { return this.getAllEntitiesOfType(Entity.class, true); - }* + } @Override public List getAllEntitiesOfType(final Class type, final boolean includeSubclasses) { @@ -141,13 +145,13 @@ public List getAllEntitiesOfType(final Class } } return result; - }* + } @Override public List getEntitiesAt(final Position pos) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); return this.getEntitiesOfTypeAt(pos, Entity.class, true); - }* + } @Override public List getEntitiesOfTypeAt( @@ -163,7 +167,7 @@ public List getEntitiesOfTypeAt( } } return result; - }* + } private void addEntityToCell(final Position pos, final Entity entity) { synchronized (this.playfieldLock) { @@ -174,7 +178,7 @@ private void addEntityToCell(final Position pos, final Entity entity) { } cell.add(entity); } - }* + } private void removeEntityFromCell(final Position pos, final Entity entity) { synchronized (this.playfieldLock) { @@ -188,30 +192,30 @@ private void removeEntityFromCell(final Position pos, final Entity entity) { this.cells.remove(pos, cell); } } - }* + } @Override public void addEntity(final Position pos, final Entity entity) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); if (entity == null) throw new IllegalArgumentException("The given entity is null."); - * + synchronized (this.playfieldLock) { if (this.entityPositions.containsKey(entity)) throw new EntityAlreadyOnFieldExcpetion("The given entity" + entity + "is already on this playfield."); - * + entity.initOnPlayfield(this); - * + this.addEntityToCell(pos, entity); - * + this.entityPositions.put(entity, pos); - * + this.getSimulation().getActionLog() .logAction(new EntitySpawnAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, this, pos)); - * + this.addEntityToSimulationTree(entity); } this.drawEntities(); - }* + } private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean create) { final List> classHiera = new ArrayList<>(); @@ -223,7 +227,7 @@ private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean } while (Entity.class.isAssignableFrom(clazz)); } SimulationTreeNode node = this.simualtionTreeRootNode; - * + hieraLoop: for (final Class clazz : classHiera) { for (final SimulationTreeNode child : node.getChildren()) { if (child.getElementId().equals(clazz.getName())) { @@ -239,38 +243,38 @@ private SimulationTreeNode findNodeForEntity(final Entity entity, final boolean } else return null; } return node; - }* + } private void addEntityToSimulationTree(final Entity entity) { final SimulationTreeNode newNode = new SimulationTreeNode( Integer.toHexString(entity.hashCode()), entity.toString(), entity.getDrawInformation().getTextureHandle() ); this.findNodeForEntity(entity, true).appendChild(newNode); - * + if (this.simulationTreeEntityAddedListener != null) { // TODO check for bugs with simulation tree when window is reattached or attached late this.simulationTreeEntityAddedListener.accept(newNode, entity); } - }* + } @Override public void moveEntity(final Entity entity, final Position pos) { this.moveEntity(entity, pos, null); - }* + } @Override public void moveEntity(final Entity entity, final Position pos, final EntityMoveAction action) { if (pos == null) throw new IllegalArgumentException("The given pos is null."); if (entity == null) throw new IllegalArgumentException("The given entity is null."); - * + synchronized (this.playfieldLock) { if (!this.entityPositions.containsKey(entity)) throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); - * + EntityMoveAction actionToLog = action; - * + final Position oldPos = this.entityPositions.get(entity); - * + if (actionToLog == null) { actionToLog = new EntityTeleportAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, oldPos, pos); } else { @@ -280,22 +284,22 @@ public void moveEntity(final Entity entity, final Position pos, final EntityMove throw new IllegalArgumentException("Given action does not start at current position of given entity."); if (!actionToLog.to().equals(pos)) throw new IllegalArgumentException("Given action does not end at given pos."); } - * + this.removeEntityFromCell(oldPos, entity); this.addEntityToCell(pos, entity); this.entityPositions.put(entity, pos); - * + this.getSimulation().getActionLog().logAction(actionToLog); - * + } this.drawEntities(); - }* + } private void removeEntityFromSimulationTree(final Entity entity) { final SimulationTreeNode node = this.findNodeForEntity(entity, false); - * + if (node == null) return; - * + for (final SimulationTreeNode child : node.getChildren()) { if (child.getElementId().equals(Integer.toHexString(entity.hashCode()))) { node.removeChild(child); @@ -305,28 +309,28 @@ private void removeEntityFromSimulationTree(final Entity entity) { } } } - }* + } @Override public void removeEntity(final Entity entity) { if (entity == null) throw new IllegalArgumentException("The given entity is null."); - * + synchronized (this.playfieldLock) { if (!this.entityPositions.containsKey(entity)) throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); - * + final Position pos = this.entityPositions.get(entity); this.removeEntityFromCell(pos, entity); this.entityPositions.remove(entity, pos); - * + this.getSimulation().getActionLog() .logAction(new EntityDespawnAction(this.getSimulation().getSimulationClock().getLastTickNumber(), entity, this)); - * + this.removeEntityFromSimulationTree(entity); - * + } this.drawEntities(); - }* + } @Override public Position getEntityPosition(final Entity entity) { @@ -336,7 +340,7 @@ public Position getEntityPosition(final Entity entity) { if (pos == null) throw new EntityNotOnFieldException("The given entity" + entity + "is not on this playfield."); return pos; } - }* + } @Override public boolean containsEntity(final Entity entity) { @@ -344,7 +348,7 @@ public boolean containsEntity(final Entity entity) { synchronized (this.playfieldLock) { return this.entityPositions.containsKey(entity); } - }* + } @Override public boolean isSolidEntityAt(final Position pos) { @@ -353,14 +357,14 @@ public boolean isSolidEntityAt(final Position pos) { if (entity.isCurrentlySolid()) return true; } return false; - }* + } /** * @return the root node of the simulation tree */ public SimulationTreeNode getSimulationTree() { return this.simualtionTreeRootNode; - }* + } /** * Set the listener for when an entity is added to the simulation tree. @@ -372,14 +376,14 @@ public void setSimulationTreeEntityAddedListener(final BiConsumer> listener) if ((this.drawablesChangedListener == null) || (listener == null)) { this.drawablesChangedListener = listener; } else throw new ListenerSetException(); - }* + } /** * Remove the listener for when the drawables on the playfield changed. This listener is responsible for informing @@ -419,7 +423,7 @@ public void setDrawablesChangedListener(final Consumer> listener) */ public void removeDrawablesChangedListener() { this.drawablesChangedListener = null; - }* + } @Override public String toString() { diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java index 5b6c6d82f..55106863d 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/programs/StandardProgramRunner.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.programs; -* - import java.util.HashMap; import java.util.Map; import java.util.concurrent.CancellationException; @@ -18,10 +16,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinWorkerThread; -import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;* +import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; + import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; -import de.unistuttgart.informatik.fius.icge.simulation.exception.UncheckedInterruptedException;** +import de.unistuttgart.informatik.fius.icge.simulation.exception.UncheckedInterruptedException; /** @@ -30,16 +29,17 @@ * @author Fabian Bühler */ public class StandardProgramRunner { - * - private ExecutorService executor;* - private final Map> runningPrograms = new HashMap<>();* + + private ExecutorService executor; + + private final Map> runningPrograms = new HashMap<>(); /** * Standard constructor setting up the executor for the Futures. */ public StandardProgramRunner() { this.executor = this.createExecutor(); - }* + } /** * Create an executor that uses named threads for a better debugging experience, @@ -53,9 +53,9 @@ private ExecutorService createExecutor() { worker.setDaemon(true); return worker; }; - * + return new ForkJoinPool(Runtime.getRuntime().availableProcessors(), factory, null, false); - }* + } /** * Run a program for the given entity inside a completable future. @@ -79,7 +79,7 @@ public void run(final Program program, final throw new IllegalStateException("Already running a program for entity " + entity.toString() + "!"); } } - * + final CompletableFuture future = CompletableFuture.runAsync(() -> { try { program.run(entity); @@ -94,10 +94,10 @@ public void run(final Program program, final System.out.println("----------------------------------------------"); } }, this.executor); - * + // set the running program in the entityMap this.runningPrograms.put(entity, future); - }* + } /** * Get the running program as a CompletableFuture. @@ -108,7 +108,7 @@ public void run(final Program program, final */ public CompletableFuture getRunningProgram(Entity entity) { return this.runningPrograms.get(entity); - }* + } /** * Stop all running programs. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java index b5c1365a0..9be58f903 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/internal/tasks/StandardTaskRunner.java @@ -9,16 +9,15 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.internal.tasks; -* - import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory;* +import java.util.concurrent.ThreadFactory; + import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.exception.UncheckedInterruptedException; -import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task;** +import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; /** @@ -27,11 +26,13 @@ * @author Tim Neumann */ public class StandardTaskRunner { - * - private final ExecutorService executor;* - private final Task taskToRun; - private final Simulation sim;* - private CompletableFuture taskResult;* + + private final ExecutorService executor; + + private final Task taskToRun; + private final Simulation sim; + + private CompletableFuture taskResult; /** * Create a new task runner. @@ -49,10 +50,10 @@ public StandardTaskRunner(final Task taskToRun, final Simulation sim) { Thread worker = new Thread(runnable, "TaskThread-" + taskToRun.toString()); return worker; }; - * + // only one task can be run per task runner so parallelism of one is ok this.executor = Executors.newSingleThreadExecutor(factory); - }* + } /** * Run the given task. @@ -65,9 +66,9 @@ public StandardTaskRunner(final Task taskToRun, final Simulation sim) { public CompletableFuture runTask() { if (this.taskResult != null) return this.taskResult; this.taskResult = CompletableFuture.supplyAsync(this::executeTask, this.executor); - * + return this.taskResult; - }* + } private boolean executeTask() { try { @@ -93,7 +94,7 @@ private boolean executeTask() { System.out.println("----------------------------------------------"); return false; } - }* + } /** * Cancel the completable future and intterupt the underlying thread. diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java index 7ab37c2db..49d8580c8 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/programs/Program.java @@ -8,11 +8,11 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.programs; - * + import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; - * - * + + /** * The interface for programs that operate on entities. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java index 7f9294f13..276a88b7b 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tasks/Task.java @@ -8,10 +8,10 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.simulation.tasks; - * + import de.unistuttgart.informatik.fius.icge.simulation.Simulation; - * - * + + /** * The interface for a task to be solved by students. * diff --git a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java index da115587b..ac0db9320 100644 --- a/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java +++ b/ICGE-Simulation/src/main/java/de/unistuttgart/informatik/fius/icge/simulation/tools/PlayfieldModifier.java @@ -9,12 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.simulation.tools; -* +import java.util.function.Supplier; -import java.util.function.Supplier;* import de.unistuttgart.informatik.fius.icge.simulation.Playfield; import de.unistuttgart.informatik.fius.icge.simulation.Position; -import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; /** @@ -24,7 +23,7 @@ */ public class PlayfieldModifier { private final Playfield playfield; - * + /** * Create a new playfield modifier for the given playfield. * @@ -34,7 +33,7 @@ public class PlayfieldModifier { public PlayfieldModifier(final Playfield playfield) { this.playfield = playfield; } - * + /** * Place the given entity at the given position on the playfield. * @@ -46,7 +45,7 @@ public PlayfieldModifier(final Playfield playfield) { public void placeEntityAt(final Entity entity, final Position position) { this.playfield.addEntity(position, entity); } - * + /** * Place the given number of entities supplied by the given factory at the given location. * @@ -62,7 +61,7 @@ public void placeMultipleEntitiesAt(final Supplier entityFacto placeEntityAt(entityFactory.get(), position); } } - * + /** * Place an entity supplied by the given factory at each of the given positions * diff --git a/ICGE-Simulation/src/main/java/module-info.java b/ICGE-Simulation/src/main/java/module-info.java index 5e6027aba..9117dd04f 100644 --- a/ICGE-Simulation/src/main/java/module-info.java +++ b/ICGE-Simulation/src/main/java/module-info.java @@ -9,7 +9,7 @@ */ module de.unistuttgart.informatik.fius.icge.simulation { requires transitive de.unistuttgart.informatik.fius.icge.ui; - * + exports de.unistuttgart.informatik.fius.icge.simulation; exports de.unistuttgart.informatik.fius.icge.simulation.entity; exports de.unistuttgart.informatik.fius.icge.simulation.exception; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java index ea67febaa..400dbeec8 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/AnimatedDrawable.java @@ -9,29 +9,28 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* /** * A class containing all information needed to draw a moving object onto the playfield by a {@link PlayfieldDrawer}. * * @author Fabian Bühler */ public class AnimatedDrawable implements Drawable { - * + private final double xStart; private final double yStart; private final double xEnd; private final double yEnd; - * + private final int z; - * + private final String textureHandle; - * + private final long tickStart; private final long tickEnd; private final long duration; - * + private long currentTick = 0; - * + /** * Create a new animated Drawable. * @@ -67,12 +66,12 @@ public AnimatedDrawable( this.z = z; this.textureHandle = textureHandle; } - * + @Override public void setCurrentTick(final long renderTick) { this.currentTick = renderTick; } - * + @Override public double getX() { if (this.currentTick <= this.tickStart) return this.xStart; @@ -80,7 +79,7 @@ public double getX() { final double completion = (this.currentTick - this.tickStart) / (double) this.duration; return ((this.xEnd - this.xStart) * completion) + this.xStart; } - * + @Override public double getY() { if (this.currentTick <= this.tickStart) return this.yStart; @@ -88,27 +87,27 @@ public double getY() { final double completion = (this.currentTick - this.tickStart) / (double) this.duration; return ((this.yEnd - this.yStart) * completion) + this.yStart; } - * + @Override public int getZ() { return this.z; } - * + @Override public String getTextureHandle() { return this.textureHandle; } - * + @Override public boolean isTilable() { return false; } - * + @Override public boolean isAnimated() { return this.currentTick <= this.tickEnd; } - * + /** * Get's {@link #xStart xStart} * @@ -117,7 +116,7 @@ public boolean isAnimated() { public double getxStart() { return this.xStart; } - * + /** * Get's {@link #yStart yStart} * @@ -126,7 +125,7 @@ public double getxStart() { public double getyStart() { return this.yStart; } - * + /** * Get's {@link #xEnd xEnd} * @@ -135,7 +134,7 @@ public double getyStart() { public double getxEnd() { return this.xEnd; } - * + /** * Get's {@link #yEnd yEnd} * @@ -144,7 +143,7 @@ public double getxEnd() { public double getyEnd() { return this.yEnd; } - * + /** * Get's {@link #tickStart tickStart} * @@ -153,7 +152,7 @@ public double getyEnd() { public long getTickStart() { return this.tickStart; } - * + /** * Get's {@link #tickEnd tickEnd} * @@ -162,7 +161,7 @@ public long getTickStart() { public long getTickEnd() { return this.tickEnd; } - * + /** * Get's {@link #duration duration} * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java index bdcb01e2d..13766b9ec 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/BasicDrawable.java @@ -9,42 +9,41 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* /** * A class containing all information needed to draw an object onto the playfield by a {@link PlayfieldDrawer}. * * @author Tim Neumann */ public class BasicDrawable implements Drawable { - * + /** * The x coordinate of the drawable. * * The coordinate system is based on cells where fractionals denote positions between cells. */ private final double x; - * + /** * The y coordinate of the drawable. * * The coordinate system is based on cells where fractionals denote positions between cells. */ private final double y; - * + /** * The z value of the drawable. * * The z value is used to decide the drawing order of Drawables in the same cell. */ private final int z; - * + /** * The handle of the texture for this drawable. * * The texture must be registered in the TextureRegistry. */ private final String textureHandle; - * + /** * Create a new Drawable. * @@ -63,22 +62,22 @@ public BasicDrawable(final double x, final double y, final int z, final String t this.z = z; this.textureHandle = textureHandle; } - * + @Override public double getX() { return this.x; } - * + @Override public double getY() { return this.y; } - * + @Override public int getZ() { return this.z; } - * + @Override public String getTextureHandle() { return this.textureHandle; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java index d8deb445e..5c20d0cca 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Console.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* /** * A Console to show text output of the software * @@ -17,7 +16,7 @@ * @version 2.0 */ public interface Console { - * + /** * Clears the console in the ui. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java index df80f6393..d90d8f088 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Drawable.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* /** * A interface providing all information needed to draw an object onto the playfield by a {@link PlayfieldDrawer}. * @@ -18,7 +17,7 @@ * @version 1.0 */ public interface Drawable extends Comparable { - * + /** * Get the x coordinate of the drawable. * @@ -27,7 +26,7 @@ public interface Drawable extends Comparable { * @return returns the X position as a double */ double getX(); - * + /** * Get the y coordinate of the drawable. * @@ -36,7 +35,7 @@ public interface Drawable extends Comparable { * @return returns the Y position as a double */ double getY(); - * + /** * Get the z value of the drawable. * @@ -45,7 +44,7 @@ public interface Drawable extends Comparable { * @return returns the Z position as a double */ int getZ(); - * + /** * Get the handle of the texture for this drawable. * @@ -54,7 +53,7 @@ public interface Drawable extends Comparable { * @return returns the texture handle as a String */ String getTextureHandle(); - * + /** * Return wether this Drawable can be drawn tiled if multiple are present in the same cell. * @@ -63,7 +62,7 @@ public interface Drawable extends Comparable { default boolean isTilable() { return true; } - * + /** * Return wether the Drawable is animated. * @@ -72,7 +71,7 @@ default boolean isTilable() { default boolean isAnimated() { return false; } - * + /** * Set the current render tick for animated drawables. * @@ -82,7 +81,7 @@ default boolean isAnimated() { default void setCurrentTick(final long renderTick) { return; // default to noop } - * + @Override default int compareTo(final Drawable o) { double compareResult = 0; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java index c1907c4c6..51c9203a2 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntityInspectorEntry.java @@ -9,24 +9,22 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* - -import java.util.function.Consumer;** +import java.util.function.Consumer; /** * EntityInspectorEntry */ public class EntityInspectorEntry { - * + private final String name; - * + private final String type; - * + private final String value; - * + private final Consumer callback; - * + /** * Default constructor * @@ -45,7 +43,7 @@ public EntityInspectorEntry(final String name, final String type, final String v this.value = value; this.callback = callback; } - * + /** * Getter for the name * @@ -54,7 +52,7 @@ public EntityInspectorEntry(final String name, final String type, final String v public String getName() { return this.name; } - * + /** * Getter for the type * @@ -63,7 +61,7 @@ public String getName() { public String getType() { return this.type; } - * + /** * Getter for the value * @@ -72,7 +70,7 @@ public String getType() { public String getValue() { return this.value; } - * + /** * This function runs the callback of the item * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java index 639bbb3ad..1a9d56f32 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/EntitySidebar.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* /** * A sidebar showing all current entities * @@ -17,7 +16,7 @@ * @version 1.0 */ public interface EntitySidebar { - * + /** * Setter function to attach a SimulationTree to the entity sidebar. * @@ -25,12 +24,12 @@ public interface EntitySidebar { * The root node of the simulation tree. */ void setSimulationTreeRootNode(SimulationTreeNode treeNode); - * + /** * This function should be called if the simulation tree changes. */ void updateSimulationTree(); - * + /** * This function deletes all currently created ui elements and creates a new inspector * @@ -38,14 +37,14 @@ public interface EntitySidebar { * The entries to create the inspector from */ void setEntityInspectorEntries(EntityInspectorEntry[] entries); - * + /** * Get the selected element of the simulation tree. * * @return the currently selected SimulationTreeNode */ SimulationTreeNode getSimulationTreeSelectedElement(); - * + /** * Set the selected element of the simulation tree. * @@ -53,17 +52,17 @@ public interface EntitySidebar { * The SimulationTreeNode to select */ void setSimulationTreeSelectedElement(SimulationTreeNode node); - * + /** * Enable the simulation tree. */ void enableSimulationTree(); - * + /** * Disable the simulation tree. */ void disbaleSimulationTree(); - * + /** * Set the name of the entity inspector. * @@ -71,19 +70,19 @@ public interface EntitySidebar { * The name to set */ void setEntityInspectorName(String name); - * + /** * Get the current name of the entity inspector. * * @return The name */ String getEntityInspectorName(); - * + /** * Enable the entity inspector. */ void enableEntityInspector(); - * + /** * Disable the entity inspector. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java index db38e8b7e..52b7d0f22 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/GameWindow.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* /** * The interface for a game window of the ICGE. * @@ -22,42 +21,42 @@ public interface GameWindow { * @return The texture registry used by this window. */ TextureRegistry getTextureRegistry(); - * + /** * Get the drawer responsible for drawing the playfield for this game window. * * @return The playfield drawer used by this window. */ PlayfieldDrawer getPlayfieldDrawer(); - * + /** * Get the toolbar for this game window. * * @return The toolbar used by this window. */ Toolbar getToolbar(); - * + /** * Get the entity sidebar for this game window * * @return The entity sidebar used by this window */ EntitySidebar getEntitySidebar(); - * + /** * Get the console for this game window * * @return The console used by this window */ Console getConsole(); - * + /** * Get the task status display for this game window. * * @return The task status display used by this window */ TaskStatusDisplay getTaskStatusDisplay(); - * + /** * Set the title of the window, in which the ICGE is displayed. * @@ -65,17 +64,17 @@ public interface GameWindow { * The title to use. */ void setWindowTitle(String title); - * + /** * Start and show the game window. */ void start(); - * + /** * Stop and close the game window. This action is equivalent with pressing the "X"-button of the window. */ void stop(); - * + /** * Set the simulation proxy instance used by multiple UI components to inform the Simulation of user actions. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java index 86076278c..83ac6e533 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/PlayfieldDrawer.java @@ -9,10 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* +import java.util.List; -import java.util.List;* -import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState;** +import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState; /** @@ -21,7 +20,7 @@ * @author Tim Neumann */ public interface PlayfieldDrawer { - * + /** * Set the current list of Drawables to be rendered onto the playfield. * @@ -31,7 +30,7 @@ public interface PlayfieldDrawer { * the list of Drawables to render */ void setDrawables(List drawables); - * + /** * Draws the playfield. * @@ -39,25 +38,25 @@ public interface PlayfieldDrawer { * The number of the current tick */ void draw(long tickCount); - * + /** * Reset Zoom and Pan applied by the user to the default values. */ void resetZoomAndPan(); - * + /** * @param useDoubleBuffering * true (default) uses doubleBuffering when rendering changes on the playfield. */ void setDoubleBuffering(boolean useDoubleBuffering); - * + /** * @param syncToScreen * true (default) actively tries to sync the updated graphics to the screen after rendering changes on the * playfield. */ void setSyncToScreen(boolean syncToScreen); - * + /** * Inform the playfield drawer about which tool is selected in the toolbar. This influences what happens when a user * clicks on the playfield. @@ -66,7 +65,7 @@ public interface PlayfieldDrawer { * The currently selected tool */ void setSelectedTool(ControlButtonState selectedTool); - * + /** * Inform the playfield drawer about which entity type is selected in the toolbar. This influences what entity is * spawned when a user uses the entity creation tool. @@ -77,5 +76,5 @@ public interface PlayfieldDrawer { * The texture handle for the entity type selected. */ void setSelectedEntityType(String typeName, String textureHandle); - * + } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java index 78103d378..3e056494e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationProxy.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* /** * The SimulationProxy interface. This is used for communication most between the UI and the simulation. *

@@ -22,7 +21,7 @@ * @version 1.0 */ public interface SimulationProxy { - * + /** * Attach this simulation proxy to a specific game window. * @@ -30,7 +29,7 @@ public interface SimulationProxy { * The game window to attach to */ void attachToGameWindow(GameWindow gameWindow); - * + /** * Attach this simulation proxy to a specific game window. * @@ -40,16 +39,16 @@ public interface SimulationProxy { * If {@code true} the simulation will stop when the attached window is closed */ void attachToGameWindow(GameWindow gameWindow, boolean stopWithWindowClose); - * + /** * Called when the window is closing. */ void windowClosed(); - * + // // Toolbar // - * + /** * This is to identify the buttons */ @@ -67,7 +66,7 @@ public enum ButtonType { /** The sub button in the toolbar */ SUB } - * + /** * This is called when a button is pressed by the user * @@ -75,7 +74,7 @@ public enum ButtonType { * The type of the pressed button */ void buttonPressed(ButtonType type); - * + /** * This is called if the speed slider is changed by the user * @@ -83,7 +82,7 @@ public enum ButtonType { * The new selected speed */ void simulationSpeedChange(int value); - * + /** * This gets called when the user changes the selected element * @@ -91,18 +90,18 @@ public enum ButtonType { * The name of the selected element */ void selectedEntityChanged(String name); - * + /** * This gets called by the user to refresh task status information. *

* Calling this must verify the task. */ void refreshTaskInformation(); - * + // // Entity placing // - * + /** * Spawn a new entity of the given type at the given position and bind the program to this entity. * @@ -114,7 +113,7 @@ public enum ButtonType { * coordinate */ void spawnEntityAt(String typeName, int x, int y); - * + /** * Clear all entities in the given cell. * @@ -124,11 +123,11 @@ public enum ButtonType { * coordinate */ void clearCell(int x, int y); - * + // // Sidebar - Simulation Tree // - * + /** * This function gets called when the user selects a different node * @@ -136,11 +135,11 @@ public enum ButtonType { * The node with was selected */ void selectedSimulationEntityChange(SimulationTreeNode node); - * + // // Entity Inspector // - * + /** * This function gets called when a user changes a value or fires a function in the ui * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java index d9817fe84..bd15e2f9e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/SimulationTreeNode.java @@ -9,13 +9,12 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* - import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.function.Consumer;* -import de.unistuttgart.informatik.fius.icge.ui.exception.LeafNodeException;** +import java.util.function.Consumer; + +import de.unistuttgart.informatik.fius.icge.ui.exception.LeafNodeException; /** @@ -26,12 +25,13 @@ * @version 1.0 */ public class SimulationTreeNode { - * - private ArrayList children;* - private final String elementId; - private final String displayText; - private final String textureId; - private final boolean isLeaf;* + + private ArrayList children; + + private final String elementId; + private final String displayText; + private final String textureId; + private final boolean isLeaf; /** * Default constructor for leaf nodes @@ -48,7 +48,7 @@ public SimulationTreeNode(final String elementId, final String displayText, fina this.displayText = displayText; this.textureId = textureId; this.isLeaf = true; - }* + } /** * This constructor can be used to create non leaf nodes as well as leaf nodes. @@ -66,12 +66,12 @@ public SimulationTreeNode(final String elementId, final String displayText, fina if (!isLeaf) { this.children = new ArrayList<>(); } - * + this.elementId = elementId; this.displayText = displayText; this.textureId = textureId; this.isLeaf = isLeaf; - }* + } /** * Getter for the element id the non visible string to better identify the selected entity. @@ -80,7 +80,7 @@ public SimulationTreeNode(final String elementId, final String displayText, fina */ public String getElementId() { return this.elementId; - }* + } /** * Getter for the display text which is the name of the entity which is displayed to the user. @@ -89,7 +89,7 @@ public String getElementId() { */ public String getDisplayText() { return this.displayText; - }* + } /** * Getter for the texture id the identifier of the texture which is rendered infront of the display text. @@ -98,7 +98,7 @@ public String getDisplayText() { */ public String getTextureId() { return this.textureId; - }* + } /** * This checks if node is a leaf node. @@ -107,7 +107,7 @@ public String getTextureId() { */ public boolean isLeaf() { return this.isLeaf; - }* + } /** * Function to check if the node has children. @@ -116,9 +116,9 @@ public boolean isLeaf() { */ public boolean hasChildren() { if (this.isLeaf) return false; - * + return !this.children.isEmpty(); - }* + } /** * Appends a child node to this node @@ -129,9 +129,9 @@ public boolean hasChildren() { */ public boolean appendChild(final SimulationTreeNode node) { if (this.isLeaf) throw new LeafNodeException(); - * + return this.children.add(node); - }* + } /** * Removes a child node from this node @@ -142,16 +142,16 @@ public boolean appendChild(final SimulationTreeNode node) { */ public boolean removeChild(final SimulationTreeNode node) { if (this.isLeaf) throw new LeafNodeException(); - * + return this.children.remove(node); - }* + } /** * @return a list of all children */ public List getChildren() { return List.copyOf(this.children); - }* + } /** * Runs a function for each added child node with the child node as a parameter @@ -161,22 +161,22 @@ public List getChildren() { */ public void forEachChild(final Consumer lamda) { if (this.isLeaf) throw new LeafNodeException(); - * + for (final SimulationTreeNode child : this.children) { lamda.accept(child); } - }* + } @Override public int hashCode() { return this.elementId.hashCode(); - }* + } @Override public boolean equals(final Object obj) { if (!(obj instanceof SimulationTreeNode)) return false; return Objects.equals(this.elementId, ((SimulationTreeNode) obj).elementId); - }* + } @Override public String toString() { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java index 20aa8bfe3..86ab147eb 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskInformation.java @@ -9,9 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* - -import java.util.List;** +import java.util.List; /** @@ -21,28 +19,28 @@ * @version 1.0 */ public interface TaskInformation { - * + /** * Get the title of the task. * * @return the task title (must not be {@code null}, without trailing newline) */ String getTaskTitle(); - * + /** * Get the description of the task. * * @return the task description (can be {@code null}, can contain newlines, without trailing newline) */ String getTaskDescription(); - * + /** * Get the verification status of the task. * * @return the task status (must not be {@code null}) */ TaskVerificationStatus getTaskStatus(); - * + /** * Get a list of child/sub tasks of this task. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java index 6bf8f1a4c..a274b7416 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskStatusDisplay.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* /** * The task status used by a {@link GameWindow} to show the current task status. * @@ -17,7 +16,7 @@ * @version 1.0 */ public interface TaskStatusDisplay { - * + /** * Set the task information to be displayed. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java index e47e1a912..fd96eb55c 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TaskVerificationStatus.java @@ -8,7 +8,7 @@ * SPDX-License-Identifier: MIT */ package de.unistuttgart.informatik.fius.icge.ui; - * + /** * Enum describing the verification status of a task. */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java index 1cefebe00..ee2a1eafe 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/TextureRegistry.java @@ -9,11 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* - import java.io.InputStream; -import java.util.function.Function;* -import de.unistuttgart.informatik.fius.icge.ui.exception.TextureNotFoundException;** +import java.util.function.Function; + +import de.unistuttgart.informatik.fius.icge.ui.exception.TextureNotFoundException; /** @@ -22,7 +21,7 @@ * @author Tim Neumann */ public interface TextureRegistry { - * + /** * Load an image from an internal resource as texture and return the handle to the texture. * @@ -43,7 +42,7 @@ public interface TextureRegistry { * the texture could not be loaded from the given resource location */ String loadTextureFromResource(String resourceName, final Function resourceProvider); - * + /** * Create a new animated texture with the animation length in render ticks. * @@ -54,7 +53,7 @@ public interface TextureRegistry { * @return the handle to retrieve the texture */ String createAnimatedTexture(boolean loop); - * + /** * Add a animation frame to an animated texture. * @@ -66,7 +65,7 @@ public interface TextureRegistry { * the number of frames to show this texture */ void addAnimationFrameToTexture(String animatedTexture, String frameTexture, long frames); - * + /** * Check if a texture is animated. * @@ -75,7 +74,7 @@ public interface TextureRegistry { * @return true iff the texture is animated */ boolean isTextureAnimated(String textureHandle); - * + /** * Load an image from a file path as texture and return the handle to the texture. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java index 2984e1216..f40679b4e 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/Toolbar.java @@ -9,9 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* - -import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector;** +import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector; /** @@ -22,7 +20,7 @@ * @version 1.0 */ public interface Toolbar { - * + /** * The clock button state represents the states of the clock buttons in the ui */ @@ -34,7 +32,7 @@ enum ClockButtonState { /** Indicates an error or unavailable clock or simulation */ BLOCKED } - * + /** * The control button state represents the status of the control buttons in the ui */ @@ -48,7 +46,7 @@ enum ControlButtonState { /** Indicates that the user input is blocked or unavailable */ BLOCKED } - * + /** * Append the list of entities with the given entry * @@ -59,7 +57,7 @@ enum ControlButtonState { * @see DropdownSelector */ void addEntity(String displayName, String textureID); - * + /** * Set the state of the control buttons. * @@ -67,7 +65,7 @@ enum ControlButtonState { * The new state */ void setControlButtonState(ControlButtonState controlButtonState); - * + /** * Set the state of the clock buttons. * @@ -75,14 +73,14 @@ enum ControlButtonState { * The new state */ void setClockButtonState(ClockButtonState clockButtonState); - * + /** * Get the current position of the speed slider. * * @return The position from 0 to 10 (both inclusive) */ int getSpeedSliderPosition(); - * + /** * Set the position of the speed slider. * @@ -90,14 +88,14 @@ enum ControlButtonState { * The new position; can be from 0 to 10 (both inclusive) */ void setSpeedSliderPosition(int position); - * + /** * Get the entity currently selected in the entity selection dropdown. * * @return The name of the currently selected entity */ String getCurrentlySelectedEntity(); - * + /** * Set the entity selected in the entity selection dropdown. * @@ -105,12 +103,12 @@ enum ControlButtonState { * The name of the entity to select */ void setCurrentlySelectedEntity(String entity); - * + /** * Enable the entity selector */ void enableEntitySelector(); - * + /** * Disable the entity selector */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java index b58bc5c69..1c1339ec5 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/WindowBuilder.java @@ -9,23 +9,23 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* - import java.awt.GraphicsEnvironment; import java.lang.reflect.InvocationTargetException; -import java.awt.Font;* +import java.awt.Font; + import javax.swing.SwingUtilities; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; -import javax.swing.plaf.FontUIResource;* +import javax.swing.plaf.FontUIResource; + import de.unistuttgart.informatik.fius.icge.ui.internal.SwingConsole; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingEntitySidebar; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingGameWindow; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingPlayfieldDrawer; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTaskStatusDisplay; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.internal.SwingToolbar;** +import de.unistuttgart.informatik.fius.icge.ui.internal.SwingToolbar; /** @@ -36,21 +36,22 @@ * @author Tim Neumann */ public class WindowBuilder { - * - private static boolean isDefaultLookAndFeelUpdated = false; - private static double dpiScale; - private static double fontScale;* - private String windowTitle = ""; + + private static boolean isDefaultLookAndFeelUpdated = false; + private static double dpiScale; + private static double fontScale; + + private String windowTitle = ""; private boolean useDoubleBuffering; private boolean syncToScreen; - private volatile GameWindow window;* + private volatile GameWindow window; /** * Create a new WindowBuilder. */ public WindowBuilder() { this(WindowBuilder.getDeviceDpiScale()); - }* + } /** * Create a new WindowBuilder. @@ -61,14 +62,14 @@ public WindowBuilder() { public WindowBuilder(double dpiScale) { if (dpiScale < 0.5) throw new IllegalArgumentException("A dpi scale < 0.5 is not supported!"); if (dpiScale > 3.0) throw new IllegalArgumentException("A dpi scale > 3.0 is not supported!"); - * + if (!WindowBuilder.isDefaultLookAndFeelUpdated) { // only once WindowBuilder.isDefaultLookAndFeelUpdated = true; WindowBuilder.dpiScale = dpiScale; WindowBuilder.fontScale = ((dpiScale - 1) * 0.75) + 1; this.setUiDefaults(dpiScale, WindowBuilder.fontScale); } - }* + } /** * Get the scaling factor from the default display device. @@ -78,7 +79,7 @@ public WindowBuilder(double dpiScale) { private static double getDeviceDpiScale() { return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform() .getScaleX(); - }* + } /** * Set the UI Manager defaults forlook and feeel and dpi scaling. @@ -109,7 +110,7 @@ private void setUiDefaults(double dpiScale, double fontScale) { } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { System.err.println("Can't set look and feel because of: " + e.toString()); } - }* + } /** * Set the title of the new window. @@ -125,9 +126,9 @@ private void setUiDefaults(double dpiScale, double fontScale) { public void setTitle(final String title) { if (this.hasBuiltWindow()) throw new IllegalStateException("The window was already built! Use the methods of the Window Object to change its properties."); - * + this.windowTitle = title; - }* + } /** * Set the graphics settings of the playfield drawer. @@ -146,10 +147,10 @@ public void setTitle(final String title) { public void setGraphicsSettings(final boolean useDoubleBuffering, final boolean syncToScreen) { if (this.hasBuiltWindow()) throw new IllegalStateException("The window was already built! Use the methods of the Window Object to change its properties."); - * + this.useDoubleBuffering = useDoubleBuffering; this.syncToScreen = syncToScreen; - }* + } /** * Actually build the window. @@ -167,7 +168,7 @@ public void buildWindow() { // TODO better exception handling System.err.println("Can't build the window because of: " + e.toString()); } - }* + } /** * Build the window. @@ -181,15 +182,15 @@ private void buildWindowInternal() { final SwingEntitySidebar entitySidebar = new SwingEntitySidebar(textureRegistry, WindowBuilder.dpiScale); final SwingConsole console = new SwingConsole(WindowBuilder.fontScale); final SwingTaskStatusDisplay taskStatus = new SwingTaskStatusDisplay(WindowBuilder.fontScale); - * + playfieldDrawer.setDoubleBuffering(this.useDoubleBuffering); playfieldDrawer.setSyncToScreen(this.syncToScreen); - * + this.window = new SwingGameWindow(textureRegistry, playfieldDrawer, toolbar, entitySidebar, console, taskStatus); if (this.windowTitle != null) { this.window.setWindowTitle(this.windowTitle); } - }* + } /** * Get whether the window has been built. @@ -198,7 +199,7 @@ private void buildWindowInternal() { */ public boolean hasBuiltWindow() { return this.window != null; - }* + } /** * Get the window that was built. diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java index d462e5a2a..144d389c8 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/LeafNodeException.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui.exception; -* /** * The LeafNodeException is thrown when someone tries to add a child node to a leaf node or interact with the child * nodes of a leaf node. @@ -19,7 +18,7 @@ */ public class LeafNodeException extends UnsupportedOperationException { private static final long serialVersionUID = 2227365905217962083L; - * + /** * Default constructor */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java index dfb85d75c..6a772cf81 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/ListenerSetException.java @@ -9,7 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui.exception; -* /** * The ListenerSetException is thrown if a set listener function in the SimulationProxy fails * @@ -18,7 +17,7 @@ */ public class ListenerSetException extends IllegalArgumentException { private static final long serialVersionUID = -2620520061340158420L; - * + /** * Default constructor */ diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java index 3dfe64792..84728316f 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/exception/TextureNotFoundException.java @@ -9,17 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.ui.exception; -* /** * Exception thrown when a texture file or resource could not be found. */ public class TextureNotFoundException extends RuntimeException { - * + /** * generated */ private static final long serialVersionUID = -6554875504029045378L; - * + /** * Construct a new {@code TextureNotFoundException} with the given message. * @@ -29,7 +28,7 @@ public class TextureNotFoundException extends RuntimeException { public TextureNotFoundException(final String message) { super(message); } - * + /** * Construct a new {@code TextureNotFoundException} with the given message. * diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java index e0ee595d0..c75bca1ed 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/AnimatedTexture.java @@ -9,11 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.Graphics; import java.awt.Image; -import java.util.ArrayList;** +import java.util.ArrayList; /** @@ -22,11 +20,11 @@ * @author Fabian Bühler */ public class AnimatedTexture implements Texture { - * + private final SwingTextureRegistry registry; private final ArrayList animationFrames; private long duration; - private final boolean loop;* + private final boolean loop; /** * Create a new animated Texture. @@ -41,7 +39,7 @@ public AnimatedTexture(final SwingTextureRegistry registry, final boolean loop) this.animationFrames = new ArrayList<>(); this.duration = 0; this.loop = loop; - }* + } /** * Add a texture at the end of the animation. @@ -58,7 +56,7 @@ public void addAnimationFrame(final String frameTexture, final long frames) { this.duration += frames; final AnimationFrame frame = new AnimationFrame(last, last + (frames - 1), texture); this.animationFrames.add(frame); - }* + } /** * Get the texture for the current frame. @@ -69,7 +67,7 @@ public void addAnimationFrame(final String frameTexture, final long frames) { */ public Texture getTextureForTick(final long frame) { return this.getTextureForTick(frame, 0); - }* + } /** * Get the texture for the current frame. @@ -82,7 +80,7 @@ public Texture getTextureForTick(final long frame) { */ private Texture getTextureForTick(final long frame, final long animationStart) { if (this.duration == 0) throw new IllegalStateException("AnimatedTexture is empty!"); - * + long animationFrame = frame - animationStart; if (this.loop) { animationFrame = animationFrame % this.duration; @@ -99,23 +97,23 @@ private Texture getTextureForTick(final long frame, final long animationStart) { if ((animFrame.startFrame <= animationFrame) && (animFrame.endFrame >= animationFrame)) return animFrame.texture; } throw new IllegalStateException("This can only happen if the start and end frames of the animation frames were set wrong!"); - }* + } @Override public Image getTexture(final long frame) { return this.getTextureForTick(frame).getTexture(); - }* + } @Override public void drawTexture(final long frame, final Graphics g, final int x, final int y, final int width, final int height) { this.getTextureForTick(frame).drawTexture(frame, g, x, y, width, height); - }* + } private class AnimationFrame { private final long startFrame; private final long endFrame; private final Texture texture; - * + private AnimationFrame(final long startFrame, final long endFrame, final Texture texture) { this.startFrame = startFrame; this.endFrame = endFrame; diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java index 3b7665e30..57f2ff3f7 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/ConsoleBufferedOutputStream.java @@ -9,18 +9,17 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.Color; import java.io.IOException; -import java.io.OutputStream;* +import java.io.OutputStream; + import javax.swing.JTextPane; import javax.swing.SwingUtilities; import javax.swing.Timer; import javax.swing.text.BadLocationException; import javax.swing.text.Style; import javax.swing.text.StyleConstants; -import javax.swing.text.StyledDocument;** +import javax.swing.text.StyledDocument; /** @@ -42,15 +41,17 @@ * @version 2.0 */ public class ConsoleBufferedOutputStream extends OutputStream { - * + /** The maximum length of the line buffer. */ - static final int DEFAULT_MAX_BUFFER_LENGTH = 4096; - private final int maxBufferLength;* - private final Timer timer;* + static final int DEFAULT_MAX_BUFFER_LENGTH = 4096; + private final int maxBufferLength; + + private final Timer timer; + //TODO add actual buffer to avoid overflowing the textarea and cause lag private final JTextPane textPane; private final Style style; - private final StringBuilder lineBuffer;* + private final StringBuilder lineBuffer; /** * Default Constructor @@ -64,7 +65,7 @@ public class ConsoleBufferedOutputStream extends OutputStream { */ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle style) { this(textPane, style, DEFAULT_MAX_BUFFER_LENGTH); - }* + } /** * Constructor with maxBufferLenght included @@ -80,10 +81,10 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle style, int maxBufferLength) { this.maxBufferLength = maxBufferLength; this.lineBuffer = new StringBuilder(maxBufferLength * 2); - * + this.textPane = textPane; this.style = this.textPane.addStyle(style.toString(), null); - * + switch (style) { case STANDARD: break; @@ -93,7 +94,7 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s default: throw new UnsupportedOperationException("With stye type " + style.toString()); } - * + this.timer = new Timer(32, (event) -> { try { // flush the line buffer in regular intervalls @@ -104,45 +105,45 @@ public ConsoleBufferedOutputStream(final JTextPane textPane, final OutputStyle s }); this.timer.setCoalesce(true); this.timer.start(); // start timer after everything is initialized - }* + } @Override public void flush() throws IOException { super.flush(); this.flushLineBufferToTextPane(); - }* + } @Override public void close() throws IOException { super.close(); this.timer.stop(); - }* + } @Override public void write(final int character) throws IOException { final char symbol = (char) character; - * + synchronized (this.lineBuffer) { this.lineBuffer.append(symbol); } - * + if (this.lineBuffer.length() >= this.maxBufferLength) { this.flushLineBufferToTextPane(); } - }* + } private void flushLineBufferToTextPane() throws IOException { if (this.lineBuffer.length() == 0) { // fast exit as default without costly synchronized return; // nothing to flush in the line buffer } - * + String newText; synchronized (this.lineBuffer) { // stringBuilder is not threadsafe // get the current buffer and reset linebuffer newText = this.lineBuffer.toString(); this.lineBuffer.setLength(0); } - * + if (newText.length() > 0) { // new null check because previous check may be obsolete now // print line to text pane SwingUtilities.invokeLater(() -> { @@ -156,7 +157,7 @@ private void flushLineBufferToTextPane() throws IOException { } }); } - }* + } /** * Get's {@link #maxBufferLength maxBufferLength} @@ -165,5 +166,6 @@ private void flushLineBufferToTextPane() throws IOException { */ public int getMaxBufferLength() { return this.maxBufferLength; - }* + } + } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java index 756a072a2..da399d887 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/OutputStyle.java @@ -9,17 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* /** * Enum to identify different standard styles for the ConsoleBufferedOutputStream * * @author David Ruff */ public enum OutputStyle { - * + /** Standard Style for text from stdout */ STANDARD, - * + /** Style for text from stderr (e.g. errors) */ ERROR } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java index 4d5f2d38a..9e99fdfb7 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticTexture.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.Graphics; -import java.awt.Image;** +import java.awt.Image; /** @@ -21,9 +19,9 @@ * @author Fabian Bühler */ public class StaticTexture implements Texture { - * + private final Image texture; - * + /** * Create a new Texture. * @@ -33,12 +31,12 @@ public class StaticTexture implements Texture { public StaticTexture(final Image texture) { this.texture = texture; } - * + @Override public Image getTexture(final long frame) { return this.texture; } - * + @Override public void drawTexture(final long frame, final Graphics g, final int x, final int y, final int width, final int height) { g.drawImage(this.texture, x, y, width, height, null); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java index ba5b3162e..de64140a8 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/StaticUiTextures.java @@ -9,9 +9,7 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - -import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry;** +import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry; /** @@ -21,22 +19,23 @@ * @version 1.0 */ public abstract class StaticUiTextures { - * + /** A play icon */ - public static String playIcon; + public static String playIcon; /** A step icon */ - public static String stepIcon; + public static String stepIcon; /** A pause icon */ - public static String pauseIcon; + public static String pauseIcon; /** A stop icon */ @Deprecated - public static String stopIcon;* + public static String stopIcon; + /** A arrow icon */ - public static String arrowIcon; + public static String arrowIcon; /** A add icon */ - public static String addIcon; + public static String addIcon; /** A sub icon */ - public static String subIcon;* + public static String subIcon; /** * This function loads all textures into the given texture registry and stores the icon ids @@ -49,7 +48,7 @@ public static void load(final TextureRegistry registry) { StaticUiTextures.stepIcon = registry.loadTextureFromResource("textures/step.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.pauseIcon = registry.loadTextureFromResource("textures/pause.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.stopIcon = registry.loadTextureFromResource("textures/stop.png", TextureRegistry.class::getResourceAsStream); - * + StaticUiTextures.arrowIcon = registry.loadTextureFromResource("textures/arrow.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.addIcon = registry.loadTextureFromResource("textures/add.png", TextureRegistry.class::getResourceAsStream); StaticUiTextures.subIcon = registry.loadTextureFromResource("textures/sub.png", TextureRegistry.class::getResourceAsStream); diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java index 345b000e1..3b588be2a 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingConsole.java @@ -9,16 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.Font; -import java.io.IOException;* +import java.io.IOException; + import javax.swing.JTextPane; import javax.swing.SwingUtilities; import javax.swing.text.DefaultCaret; -import javax.swing.text.DefaultStyledDocument;* +import javax.swing.text.DefaultStyledDocument; + import de.unistuttgart.informatik.fius.icge.log.Logger; -import de.unistuttgart.informatik.fius.icge.ui.Console;** +import de.unistuttgart.informatik.fius.icge.ui.Console; /** @@ -30,9 +30,10 @@ * @version 2.0 */ public class SwingConsole extends JTextPane implements Console { - private static final long serialVersionUID = 5100186594058483257L;* + private static final long serialVersionUID = 5100186594058483257L; + private ConsoleBufferedOutputStream systemOutputStream; - private ConsoleBufferedOutputStream systemErrorStream;* + private ConsoleBufferedOutputStream systemErrorStream; /** * Default constructor @@ -44,25 +45,25 @@ public class SwingConsole extends JTextPane implements Console { */ public SwingConsole(final double fontScale) { super(new DefaultStyledDocument()); - * + final int fontSize = (int) Math.floor(12 * fontScale); final Font standardFont = new Font("monospaced", Font.PLAIN, fontSize); - * + this.setEditable(false); this.setFont(standardFont); final DefaultCaret caret = (DefaultCaret) this.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); this.systemOutputStream = new ConsoleBufferedOutputStream(this, OutputStyle.STANDARD); this.systemErrorStream = new ConsoleBufferedOutputStream(this, OutputStyle.ERROR); - * + Logger.addOutOutputStream(this.systemOutputStream); Logger.addErrorOutputStream(this.systemErrorStream); - }* + } @Override public void clearConsole() { SwingUtilities.invokeLater(() -> this.setText("")); - }* + } /** * Detach the internal output streams from {@code Logger.out} and {@code Logger.error}. diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java index d7cd3c718..395bf4dd9 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntityInspector.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; @@ -20,32 +18,39 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer;* +import java.util.function.Consumer; + import javax.swing.JButton; import javax.swing.JFormattedTextField; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; -import javax.swing.text.NumberFormatter;* -import de.unistuttgart.informatik.fius.icge.ui.EntityInspectorEntry;** +import javax.swing.text.NumberFormatter; + +import de.unistuttgart.informatik.fius.icge.ui.EntityInspectorEntry; /** * EntityInspector */ public class SwingEntityInspector extends JPanel { - private static final long serialVersionUID = 1L;* - private final GridBagConstraints gbc;* + private static final long serialVersionUID = 1L; + + private final GridBagConstraints gbc; + /** The name at the top */ - private final JLabel title;* + private final JLabel title; + /** The JPanel containing all the ui elements */ - private JPanel inspector;* + private JPanel inspector; + /** The user warning at the bottom */ - private final JLabel warning;* - private Object updateLock = new Object(); - private EntityInspectorEntry[] currentEntries; - private List> uiValueUpdaters;* + private final JLabel warning; + + private Object updateLock = new Object(); + private EntityInspectorEntry[] currentEntries; + private List> uiValueUpdaters; /** * Default constructor @@ -57,26 +62,26 @@ public class SwingEntityInspector extends JPanel { */ public SwingEntityInspector(final SwingTextureRegistry textureRegistry) { this.setLayout(new BorderLayout()); - * + this.title = new JLabel("Empty"); this.add(this.title, BorderLayout.PAGE_START); - * + this.inspector = new JPanel(); this.inspector.setLayout(new GridBagLayout()); this.add(this.inspector, BorderLayout.CENTER); - * + this.warning = new JLabel("Pause the simulation to modify an entity!"); this.warning.setVisible(false); this.add(this.warning, BorderLayout.PAGE_END); - * + this.gbc = new GridBagConstraints(); this.gbc.fill = GridBagConstraints.HORIZONTAL; this.gbc.gridx = 0; this.gbc.gridy = 0; - * + this.setEnabled(false); this.warning.setVisible(false); - }* + } /** * Getter for the inspector name wich is displayed at the top @@ -86,7 +91,7 @@ public SwingEntityInspector(final SwingTextureRegistry textureRegistry) { @Override public String getName() { return this.title.getText(); - }* + } /** * Setter for the inspector name @@ -100,7 +105,7 @@ public void setName(final String name) { this.title.setText(name); return; } - * + // cannot call invokeAndWait when already in EventDispatchThread! try { SwingUtilities.invokeAndWait(() -> { @@ -109,7 +114,7 @@ public void setName(final String name) { } catch (InvocationTargetException | InterruptedException e) { System.err.println("Failed to set entity inspector name because of: " + e.toString()); } - }* + } /** * Update the entity inspector to reflect the new Values. @@ -126,15 +131,15 @@ public void updateEntityInspectorEntries(final EntityInspectorEntry[] entries) { List> valueUpdaters = this.uiValueUpdaters; if (valueUpdaters == null) return; // TODO throw exeptions here? if (valueUpdaters.size() != entries.length) return; - * + // update values for (int i = 0; i < entries.length; i++) { valueUpdaters.get(i).accept(entries[i].getValue()); } - * + // change to new entries list this.currentEntries = entries; - * + // update ui this.revalidate(); this.repaint(); @@ -142,32 +147,32 @@ public void updateEntityInspectorEntries(final EntityInspectorEntry[] entries) { }); return; } - * + // completely update the view SwingUtilities.invokeLater(() -> { synchronized (this.updateLock) { // clear old elements first, then update current entries list this.clearUIElements(); - * + // change to new entries list this.uiValueUpdaters = null; this.currentEntries = entries; // only do this after clearing old elements - * + // add new ui elements List> newUiValueUpdaters = new ArrayList<>(entries.length); for (int i = 0; i < entries.length; i++) { newUiValueUpdaters.add(this.addUIElement(entries[i], i)); } - * + // set new value updaters this.uiValueUpdaters = newUiValueUpdaters; - * + // update ui this.revalidate(); this.repaint(); } }); - }* + } /** * Check if the new list of entries matches the current entries structurally. @@ -188,7 +193,7 @@ private boolean canUpdateValuesOnly(final EntityInspectorEntry[] entries) { // only value can differ for updates without complete redraws! } return true; - }* + } /** * Callback to change the value of an entry. @@ -208,7 +213,7 @@ private void updateValueOnEntity(int index, String name, String value) { EntityInspectorEntry entry = this.currentEntries[index]; if (!entry.getName().equals(name)) return; entry.runCallback(value); - }* + } /** * Add a entry to the ui editor @@ -223,14 +228,14 @@ private void updateValueOnEntity(int index, String name, String value) { * @return A consumer that updates the newly added ui element to the given string value */ private Consumer addUIElement(final EntityInspectorEntry entry, final int index) { - * + final String name = entry.getName(); this.inspector.add(new JLabel(name + ": "), this.gbc); this.gbc.gridx = 1; - * + Consumer updateUiValueCallback = (newValue) -> { /* Default is to update nothing. */}; - * + switch (entry.getType()) { case "integer": { final NumberFormatter formatter = new NumberFormatter(NumberFormat.getInstance()); @@ -271,12 +276,12 @@ private Consumer addUIElement(final EntityInspectorEntry entry, final in updateUiValueCallback = (newValue) -> label.setText(newValue); this.inspector.add(label, this.gbc); } - * + this.gbc.gridx = 0; this.gbc.gridy += 1; - * + return updateUiValueCallback; - }* + } /** * Clears the entity editor @@ -288,19 +293,19 @@ private void clearUIElements() { this.inspector = new JPanel(); this.inspector.setLayout(new GridBagLayout()); this.add(this.inspector, BorderLayout.CENTER); - * + this.gbc.gridx = 0; this.gbc.gridy = 0; - }* + } @Override public void setEnabled(final boolean enabled) { super.setEnabled(enabled); - * + this.title.setEnabled(enabled); SwingEntityInspector.setEnabledState(this.inspector, enabled); this.warning.setVisible(!enabled); - }* + } /** * Recursive method to enable and disable a JPanel and its children @@ -312,14 +317,14 @@ public void setEnabled(final boolean enabled) { */ private static void setEnabledState(final JPanel panel, final boolean state) { panel.setEnabled(state); - * + for (final Component component : panel.getComponents()) { if (component instanceof JPanel) { SwingEntityInspector.setEnabledState((JPanel) component, state); } component.setEnabled(state); } - }* + } @Override public Dimension getPreferredSize() { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java index aff1a118f..cd9757672 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingEntitySidebar.java @@ -9,13 +9,12 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.BorderLayout; import java.awt.Dimension; import java.util.ArrayList; import java.util.Enumeration; -import java.util.List;* +import java.util.List; + import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; @@ -25,11 +24,12 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath;* +import javax.swing.tree.TreePath; + import de.unistuttgart.informatik.fius.icge.ui.EntityInspectorEntry; import de.unistuttgart.informatik.fius.icge.ui.EntitySidebar; import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; -import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode;** +import de.unistuttgart.informatik.fius.icge.ui.SimulationTreeNode; /** @@ -40,19 +40,21 @@ * @version 1.0 */ public class SwingEntitySidebar extends JPanel implements EntitySidebar { - private static final long serialVersionUID = -4409545257025298208L;* + private static final long serialVersionUID = -4409545257025298208L; + /** The simulation proxy */ private SimulationProxy simulationProxy; /** The texture registry */ - private final SwingTextureRegistry textureRegistry;* + private final SwingTextureRegistry textureRegistry; + /** The root node of the entity list */ - private SimulationTreeNode rootNode; + private SimulationTreeNode rootNode; /** The hierarchical list of all entities */ - private JTree entityList; + private JTree entityList; /** The model of the JTree component */ - private DefaultTreeModel entityListModel; + private DefaultTreeModel entityListModel; /** The entity inspector in the sidebar */ - private SwingEntityInspector entityInspector;* + private SwingEntityInspector entityInspector; /** * The default constructor @@ -67,7 +69,7 @@ public class SwingEntitySidebar extends JPanel implements EntitySidebar { public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final double dpiScale) { // class setup this.textureRegistry = textureRegistry; - * + // JTree setup this.entityListModel = new DefaultTreeModel(null, true); this.entityList = new JTree(this.entityListModel); @@ -82,7 +84,7 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub } return; } - * + if (SwingEntitySidebar.this.simulationProxy != null) { SwingEntitySidebar.this.simulationProxy.selectedSimulationEntityChange( (SimulationTreeNode) ((DefaultMutableTreeNode) SwingEntitySidebar.this.entityList.getLastSelectedPathComponent()) @@ -90,21 +92,21 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub ); } }); - * + // Entity inspector setup this.entityInspector = new SwingEntityInspector(this.textureRegistry); - * + // Sidebar layout final JScrollPane pane = new JScrollPane(this.entityList); pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - * + final JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pane, this.entityInspector); jsp.setOneTouchExpandable(true); jsp.setResizeWeight(0.4); this.setLayout(new BorderLayout()); this.add(jsp, BorderLayout.CENTER); - }* + } /** * TODO better doc @@ -114,9 +116,9 @@ public SwingEntitySidebar(final SwingTextureRegistry textureRegistry, final doub */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - * + this.simulationProxy = simulationProxy; - }* + } @Override public void setSimulationTreeRootNode(final SimulationTreeNode treeNode) { @@ -127,7 +129,7 @@ public void setSimulationTreeRootNode(final SimulationTreeNode treeNode) { // As this method itself is using invoke later, it does not need to be in the block above. // The order of execution is still correct, because calls to invokeLater are processes in the order the calls happen. this.updateSimulationTree(); - }* + } private void getExpandedTreePaths(final List expanded, final TreePath path) { if (path == null) return; @@ -136,18 +138,18 @@ private void getExpandedTreePaths(final List expanded, final TreePath expanded.add(p); this.getExpandedTreePaths(expanded, p); } - }* + } private TreePath getRootPath() { final Object root = this.entityList.getModel().getRoot(); if (root == null) return null; return new TreePath(root); - }* + } @Override public void updateSimulationTree() { SwingUtilities.invokeLater(this::updateSimulationTreeInternal); - }* + } /** * Update the simulation tree model. @@ -164,31 +166,31 @@ private void updateSimulationTreeInternal() { for (final TreePath p : expanded) { this.entityList.expandPath(p); } - }* + } @Override public void setEnabled(final boolean enabled) { super.setEnabled(enabled); this.entityList.setEnabled(enabled); - }* + } @Override public void setEntityInspectorEntries(final EntityInspectorEntry[] entries) { this.entityInspector.updateEntityInspectorEntries(entries); - }* + } @Override public Dimension getPreferredSize() { return new Dimension(300, 800); - }* + } private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { if ((node == null) || !node.getAllowsChildren()) return; final SimulationTreeNode data = (SimulationTreeNode) node.getUserObject(); - * + final List toRemove = new ArrayList<>(); final List toAdd = new ArrayList<>(); - * + outer: for (final SimulationTreeNode child : data.getChildren()) { for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); @@ -198,7 +200,7 @@ private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { } toAdd.add(child); } - * + outer: for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); for (final SimulationTreeNode child : data.getChildren()) { @@ -208,20 +210,20 @@ private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { } toRemove.add(childNode); } - * + for (final DefaultMutableTreeNode child : toRemove) { node.remove(child); } - * + for (final SimulationTreeNode child : toAdd) { node.add(SwingEntitySidebar.generateDefaultMutableTreeNodeFromSimulationTreeNode(child)); } - * + for (final Enumeration e = node.children(); e.hasMoreElements();) { final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); SwingEntitySidebar.updateTreeNodeChildren(childNode); } - }* + } /** * Recursively generate a {@link DefaultMutableTreeNode} from a {@link SimulationTreeNode} @@ -233,7 +235,7 @@ private static void updateTreeNodeChildren(final DefaultMutableTreeNode node) { */ private static DefaultMutableTreeNode generateDefaultMutableTreeNodeFromSimulationTreeNode(final SimulationTreeNode node) { final DefaultMutableTreeNode returnNode = new DefaultMutableTreeNode(node); - * + if (node.isLeaf()) { returnNode.setAllowsChildren(false); } else { @@ -242,24 +244,24 @@ private static DefaultMutableTreeNode generateDefaultMutableTreeNodeFromSimulati .add(SwingEntitySidebar.generateDefaultMutableTreeNodeFromSimulationTreeNode(childNode)) ); } - * + return returnNode; - }* + } @Override public SimulationTreeNode getSimulationTreeSelectedElement() { return (SimulationTreeNode) ((DefaultMutableTreeNode) this.entityList.getLastSelectedPathComponent()).getUserObject(); - }* + } @Override public void setSimulationTreeSelectedElement(final SimulationTreeNode node) { //TODO implement - }* + } @Override public void enableSimulationTree() { SwingUtilities.invokeLater(() -> this.entityList.setEnabled(true)); - }* + } @Override public void disbaleSimulationTree() { @@ -267,22 +269,22 @@ public void disbaleSimulationTree() { this.entityList.setEnabled(false); this.entityListModel.setRoot(null); }); - }* + } @Override public void setEntityInspectorName(final String name) { SwingUtilities.invokeLater(() -> this.entityInspector.setName(name)); - }* + } @Override public String getEntityInspectorName() { return this.entityInspector.getName(); - }* + } @Override public void enableEntityInspector() { SwingUtilities.invokeLater(() -> this.entityInspector.setEnabled(true)); - }* + } @Override public void disableEntityInspector() { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java index d1e426ebb..a43a27610 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingGameWindow.java @@ -9,13 +9,12 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent;* +import java.awt.event.WindowEvent; + import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; @@ -25,7 +24,8 @@ import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.UIManager; -import javax.swing.WindowConstants;* +import javax.swing.WindowConstants; + import de.unistuttgart.informatik.fius.icge.ui.Console; import de.unistuttgart.informatik.fius.icge.ui.EntitySidebar; import de.unistuttgart.informatik.fius.icge.ui.GameWindow; @@ -33,7 +33,7 @@ import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; import de.unistuttgart.informatik.fius.icge.ui.TaskStatusDisplay; import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.Toolbar;** +import de.unistuttgart.informatik.fius.icge.ui.Toolbar; /** @@ -44,14 +44,16 @@ * @version 1.0 */ public class SwingGameWindow extends JFrame implements GameWindow { - private static final long serialVersionUID = -7215617949088643819L;* + private static final long serialVersionUID = -7215617949088643819L; + private final SwingTextureRegistry textureRegistry; private final SwingPlayfieldDrawer playfieldDrawer; private final SwingToolbar toolbar; private final SwingEntitySidebar entitySidebar; private final SwingConsole console; - private final SwingTaskStatusDisplay taskStatus;* - private SimulationProxy simulationProxy;* + private final SwingTaskStatusDisplay taskStatus; + + private SimulationProxy simulationProxy; /** * Create a new Swing game window using the given submodules. @@ -80,7 +82,7 @@ public SwingGameWindow( this.console = console; this.taskStatus = taskStatus; SwingUtilities.invokeLater(this::initGameWindow); - }* + } @Override public void setSimulationProxy(final SimulationProxy simulationProxy) { @@ -90,55 +92,55 @@ public void setSimulationProxy(final SimulationProxy simulationProxy) { this.toolbar.setSimulationProxy(simulationProxy); this.entitySidebar.setSimulationProxy(simulationProxy); this.taskStatus.setSimulationProxy(simulationProxy); - }* + } @Override public TextureRegistry getTextureRegistry() { return this.textureRegistry; - }* + } @Override public PlayfieldDrawer getPlayfieldDrawer() { return this.playfieldDrawer; - }* + } @Override public Toolbar getToolbar() { return this.toolbar; - }* + } @Override public EntitySidebar getEntitySidebar() { return this.entitySidebar; - }* + } @Override public Console getConsole() { return this.console; - }* + } @Override public TaskStatusDisplay getTaskStatusDisplay() { return this.taskStatus; - }* + } @Override public void setWindowTitle(final String title) { // UI operations must happen in swing thread! SwingUtilities.invokeLater(() -> this.setTitle(title)); - }* + } @Override public void start() { // Asynchronously set visible to true SwingUtilities.invokeLater(() -> this.setVisible(true)); - }* + } @Override public void stop() { // programmatically close the window Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); - }* + } /** * Initialize window listeners and layout all child components. @@ -148,7 +150,7 @@ public void stop() { @SuppressWarnings("unused") // Suppress unused warnings on 'ClassCastException e' private void initGameWindow() { // init jFrame - * + // // setup window closing // @@ -159,9 +161,9 @@ public void windowClosing(final WindowEvent e) { SwingGameWindow.this.cleanup(); // stop simulation etc. } }); - * + this.playfieldDrawer.initialize(); - * + // // convert toolbar // @@ -171,7 +173,7 @@ public void windowClosing(final WindowEvent e) { } catch (ClassCastException | NullPointerException e) { toolbarComponent = new JLabel("Toolbar not valid!", UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - * + // // convert sidebar // @@ -181,7 +183,7 @@ public void windowClosing(final WindowEvent e) { } catch (ClassCastException | NullPointerException e) { sidebarComponent = new JLabel(UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - * + // // convert console // @@ -191,7 +193,7 @@ public void windowClosing(final WindowEvent e) { } catch (NullPointerException e) { consoleComponent = new JLabel("Console not valid!", UIManager.getIcon("OptionPane.warningIcon"), SwingConstants.CENTER); } - * + // // setup bottom pane layout // @@ -199,7 +201,7 @@ public void windowClosing(final WindowEvent e) { bottomPane.addTab("Console", new JScrollPane(consoleComponent)); bottomPane.addTab("Task Status", this.taskStatus); bottomPane.setPreferredSize(new Dimension(400, 200)); - * + // // setup JFrame layout // @@ -210,12 +212,12 @@ public void windowClosing(final WindowEvent e) { final JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jsp1, sidebarComponent); jsp2.setOneTouchExpandable(true); this.getContentPane().add(BorderLayout.CENTER, jsp2); - * + // // finalize jFrame // this.pack(); - }* + } /** * Clean up all resources used by this window and tell the simulation that the window is now closed. diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java index b9245da5f..03217ab0a 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingPlayfieldDrawer.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -20,14 +18,16 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; -import java.util.stream.Collectors;* +import java.util.stream.Collectors; + import javax.swing.JPanel; import javax.swing.RepaintManager; -import javax.swing.SwingUtilities;* +import javax.swing.SwingUtilities; + import de.unistuttgart.informatik.fius.icge.ui.Drawable; import de.unistuttgart.informatik.fius.icge.ui.PlayfieldDrawer; import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; -import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState;** +import de.unistuttgart.informatik.fius.icge.ui.Toolbar.ControlButtonState; /** @@ -36,51 +36,63 @@ * @author Tim Neumann */ public class SwingPlayfieldDrawer extends JPanel implements PlayfieldDrawer { - * + /** * generated */ - private static final long serialVersionUID = 1800137555269066525L;* + private static final long serialVersionUID = 1800137555269066525L; + /** Stretch factor for mapping row/column coordinates to screen coordinates. */ - private final double CELL_SIZE;* - private final int INFO_BAR_HEIGHT;* + private final double CELL_SIZE; + + private final int INFO_BAR_HEIGHT; + // Colors - private static final Color BACKGROUND_COLOR = new Color(255, 255, 255); - private static final Color BACKGROUND_COLOR_TRANSPARENT = new Color(255, 255, 255, 230); - private static final Color GRID_COLOR = new Color(46, 52, 54); - private static final Color OVERLAY_COLOR = new Color(0, 40, 255, 50);* + private static final Color BACKGROUND_COLOR = new Color(255, 255, 255); + private static final Color BACKGROUND_COLOR_TRANSPARENT = new Color(255, 255, 255, 230); + private static final Color GRID_COLOR = new Color(46, 52, 54); + private static final Color OVERLAY_COLOR = new Color(0, 40, 255, 50); + private static final RenderingHints RENDERING_HINTS = new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON - );* - private final SwingTextureRegistry textureRegistry;* + ); + + private final SwingTextureRegistry textureRegistry; + // current display offset and zoom private double offsetX; private double offsetY; - private double scale = 1.0;* + private double scale = 1.0; + // mouse events private boolean mouseInWindow = false; private int currentMouseX = 0; private int currentMouseY = 0; private int mouseStartX = 0; private int mouseStartY = 0; - private boolean isDrag = false;* + private boolean isDrag = false; + // current tool state private ControlButtonState activeTool = ControlButtonState.BLOCKED; private String selectedEntityType = null; private String selectedEntityTexture = null; - private SimulationProxy simulationProxy;* - private List drawables = List.of(); - private List animatedDrawables = List.of(); - private boolean fullRepaintNeeded = true; - private Rectangle lastRedrawArea = null; - private long currentFrame = 0;* + private SimulationProxy simulationProxy; + + private List drawables = List.of(); + private List animatedDrawables = List.of(); + private boolean fullRepaintNeeded = true; + private Rectangle lastRedrawArea = null; + private long currentFrame = 0; + // current graphic settings private final RepaintManager repaintManager; private boolean useDoubleBuffer = true; - private boolean syncToscreen = true;* - private double dpiScale;* - private Font scaleFont; - private Font font;* + private boolean syncToscreen = true; + + private double dpiScale; + + private Font scaleFont; + private Font font; /** * Create a new SwingPlayfieldDrawer. @@ -94,21 +106,21 @@ public class SwingPlayfieldDrawer extends JPanel implements PlayfieldDrawer { */ public SwingPlayfieldDrawer(final SwingTextureRegistry textureRegistry, final double dpiScale) { this.textureRegistry = textureRegistry; - * + this.setOpaque(true); this.repaintManager = RepaintManager.currentManager(this); - * + this.INFO_BAR_HEIGHT = (int) Math.floor(25 * dpiScale); this.CELL_SIZE = (int) Math.floor(32 * dpiScale); this.offsetX = this.CELL_SIZE; this.offsetY = this.CELL_SIZE; this.dpiScale = dpiScale; - * + Font font = this.getFont(); final int newFontSize = (int) Math.floor(12 * dpiScale * this.scale); this.font = new Font(font.getFontName(), font.getStyle(), newFontSize); this.setFont(this.font); - }* + } /** * Set the simulation proxy. TODO better doc @@ -118,9 +130,9 @@ public SwingPlayfieldDrawer(final SwingTextureRegistry textureRegistry, final do */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - * + this.simulationProxy = simulationProxy; - }* + } /** * Initialize the PlayfieldDrawer. @@ -128,60 +140,60 @@ public void setSimulationProxy(final SimulationProxy simulationProxy) { * This should only be called from the swing ui thread */ public void initialize() { - * + this.addMouseListener(new MouseListener() { - * + @Override public void mouseReleased(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { SwingPlayfieldDrawer.this.mouseReleased(e.getX(), e.getY()); } } - * + @Override public void mousePressed(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { SwingPlayfieldDrawer.this.mousePressed(e.getX(), e.getY()); } } - * + @Override public void mouseExited(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMouseInWindow(false); } - * + @Override public void mouseEntered(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMouseInWindow(true); } - * + @Override public void mouseClicked(final MouseEvent e) { // ignore this for now } }); - * + this.addMouseMotionListener(new MouseMotionListener() { - * + @Override public void mouseMoved(final MouseEvent e) { SwingPlayfieldDrawer.this.updateMousePosition(e.getX(), e.getY()); } - * + @Override public void mouseDragged(final MouseEvent e) { SwingPlayfieldDrawer.this.updateDrag(e.getX(), e.getY()); SwingPlayfieldDrawer.this.updateMousePosition(e.getX(), e.getY()); } }); - * + this.addMouseWheelListener(e -> { final int rot = e.getWheelRotation(); final int x = e.getX(); final int y = e.getY(); SwingPlayfieldDrawer.this.updateZoom(rot, x, y); }); - }* + } @Override public void setDrawables(final List drawables) { @@ -191,7 +203,7 @@ public void setDrawables(final List drawables) { .collect(Collectors.toUnmodifiableList()); this.fullRepaintNeeded = true; this.draw(this.currentFrame); - }* + } @Override public void draw(final long tickCount) { @@ -200,16 +212,16 @@ public void draw(final long tickCount) { if (this.animatedDrawables.size() > 0) { this.drawables = this.drawables.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toUnmodifiableList()); } - * + SwingUtilities.invokeLater(() -> { // synchronize this to fix possible null pointer when setting double buffer setting - * + final boolean bufferEnabled = this.repaintManager.isDoubleBufferingEnabled(); if (!this.useDoubleBuffer) { // only change strategy to false since true should already be default this.repaintManager.setDoubleBufferingEnabled(this.useDoubleBuffer); } - * + if (this.fullRepaintNeeded) { Rectangle visible = this.getVisibleRect(); if (visible == null) { @@ -260,7 +272,7 @@ public void draw(final long tickCount) { this.animatedDrawables = this.drawables.stream() .filter(d -> d.isAnimated() || this.textureRegistry.isTextureAnimated(d.getTextureHandle())) .collect(Collectors.toUnmodifiableList()); - }* + } @Override public void resetZoomAndPan() { @@ -270,42 +282,42 @@ public void resetZoomAndPan() { Font font = this.getFont(); final int newFontSize = (int) Math.floor(12 * this.dpiScale * this.scale); this.scaleFont = new Font(font.getFontName(), font.getStyle(), newFontSize); - }* + } @Override public void setDoubleBuffering(final boolean useDoubleBuffering) { this.useDoubleBuffer = useDoubleBuffering; - }* + } @Override public void setSyncToScreen(final boolean syncToScreen) { this.syncToscreen = syncToScreen; - }* + } @Override public Dimension getPreferredSize() { return new Dimension(800, 600); - }* + } private int getColumnCoordinateFromScreenCoordinate(final int screenX) { final double cellSize = this.CELL_SIZE * this.scale; return (int) Math.floor((screenX - this.offsetX) / cellSize); - }* + } private int getRowCoordinateFromScreenCoordinate(final int screenY) { final double cellSize = this.CELL_SIZE * this.scale; return (int) Math.floor((screenY - this.offsetY) / cellSize); - }* + } private Point getScreenPointFromCellCoordinates(final double x, final double y, final double cellSize) { final int screenX = Math.toIntExact(Math.round((x * cellSize) + this.offsetX)); final int screenY = Math.toIntExact(Math.round((y * cellSize) + this.offsetY)); return new Point(screenX, screenY); - }* + } private static Rectangle getPaintRectFromPoint(final Point upperLeftCorner, final int cellSize) { return new Rectangle(upperLeftCorner.x, upperLeftCorner.y, cellSize, cellSize); - }* + } @Override public void paintComponent(final Graphics g) { @@ -317,7 +329,7 @@ public void paintComponent(final Graphics g) { this.paintGrid(g); this.paintDrawableList(g, this.drawables); this.paintOverlay(g); - }* + } private void paintGrid(final Graphics g) { final Rectangle clipBounds = g.getClipBounds(); @@ -327,7 +339,7 @@ private void paintGrid(final Graphics g) { // to the top left corner of e cell on screen) final double firstX = (Math.IEEEremainder(this.offsetX - clipBounds.x, cellSize) + clipBounds.x) - cellSize; final double firstY = (Math.IEEEremainder(this.offsetY - clipBounds.y, cellSize) + clipBounds.y) - cellSize; - * + final int width = this.getWidth(); final int height = this.getHeight(); g.setColor(SwingPlayfieldDrawer.GRID_COLOR); @@ -341,7 +353,7 @@ private void paintGrid(final Graphics g) { final int iy = (int) y; g.drawLine(0, iy, width, iy); } - }* + } /** * Compare two drawables and checks if they can be grouped together. @@ -362,7 +374,7 @@ private static boolean canGroupDrawables(final Drawable a, final Drawable b) { if (Math.abs(a.getX() - b.getX()) > 0.001) return false; if (Math.abs(a.getY() - b.getY()) > 0.001) return false; return true; - }* + } private void paintDrawableList(final Graphics g, final List drawablesList) { if (drawablesList.size() <= 0) return; @@ -370,7 +382,7 @@ private void paintDrawableList(final Graphics g, final List drawablesL Drawable last = null; int currentCount = 0; boolean isTilable = true; - * + // group and count drawables while (iter.hasNext()) { final Drawable next = iter.next(); @@ -389,7 +401,7 @@ private void paintDrawableList(final Graphics g, final List drawablesL if (last != null) { this.paintDrawable(g, last, currentCount + 1, isTilable); } - }* + } private void paintDrawable(final Graphics g, final Drawable drawable, final int count, final boolean isTilable) { final double cellSize = this.CELL_SIZE * this.scale; @@ -416,7 +428,7 @@ private void paintDrawable(final Graphics g, final Drawable drawable, final int final Double[] yOffsets = { 0.0, 0.0, 0.0, third, third, third, twoThird, twoThird, twoThird }; final Double scaleAdjust = third; this.paintMultiCountDrawable(g, drawable, count, xOffsets, yOffsets, scaleAdjust); - }* + } private void paintMultiCountDrawable( final Graphics g, final Drawable drawable, final int count, final Double[] xOffsets, final Double[] yOffsets, @@ -443,7 +455,7 @@ private void paintMultiCountDrawable( texture.drawTexture(this.currentFrame, g, x, y, textureSize, textureSize); } } - }* + } private void drawNumber(int count, Graphics g, int x, int y) { final double cellSize = this.CELL_SIZE * this.scale; @@ -462,20 +474,20 @@ private void drawNumber(int count, Graphics g, int x, int y) { } g.drawString("" + count, x + xOffset, y + yOffset); g.setFont(this.font); - }* + } private void paintOverlay(final Graphics g) { final int width = this.getWidth(); final int height = this.getHeight(); - * + final int currentCellX = this.getColumnCoordinateFromScreenCoordinate(this.currentMouseX); final int currentCellY = this.getRowCoordinateFromScreenCoordinate(this.currentMouseY); - * + final double cellSize = this.CELL_SIZE * this.scale; final int roundedCellSize = Math.toIntExact(Math.round(cellSize)); final int screenX = Math.toIntExact(Math.round(this.offsetX + (currentCellX * cellSize))); final int screenY = Math.toIntExact(Math.round(this.offsetY + (currentCellY * cellSize))); - * + // draw cell highlight if (this.mouseInWindow && g.hitClip(screenX, screenY, roundedCellSize, roundedCellSize)) { // draw current tool texture @@ -496,44 +508,44 @@ private void paintOverlay(final Graphics g) { g.setColor(SwingPlayfieldDrawer.OVERLAY_COLOR); g.fillRect(screenX, screenY, roundedCellSize, roundedCellSize); } - * + // draw info bar if (this.mouseInWindow && g.hitClip(0, height - this.INFO_BAR_HEIGHT, width, this.INFO_BAR_HEIGHT)) { - * + g.setColor(SwingPlayfieldDrawer.BACKGROUND_COLOR); g.fillRect(0, height - this.INFO_BAR_HEIGHT, width, this.INFO_BAR_HEIGHT); g.setColor(SwingPlayfieldDrawer.GRID_COLOR); - * + // calculate baseline final FontMetrics font = g.getFontMetrics(); final int heightAboveBaseline = font.getAscent(); final int heightBelowBaseline = font.getMaxDescent(); final int baselineCentered = Math.toIntExact(Math.round((this.INFO_BAR_HEIGHT / 2.0) - (heightAboveBaseline / 2.0))); final int baseline = height - Math.max(baselineCentered, heightBelowBaseline); - * + // build string final String infoText = "Cell (x=" + currentCellX + ", y=" + currentCellY + ")"; g.drawString(infoText, 5, baseline); - * + } - }* + } private void mousePressed(final int screenX, final int screenY) { this.mouseStartX = screenX; this.mouseStartY = screenY; this.isDrag = false; - }* + } private void mouseReleased(final int screenX, final int screenY) { if (!this.isDrag) { this.mouseClick(this.mouseStartX, this.mouseStartY); } - }* + } private void mouseClick(final int screenX, final int screenY) { final int x = this.getColumnCoordinateFromScreenCoordinate(screenX); final int y = this.getRowCoordinateFromScreenCoordinate(screenY); - * + if (this.activeTool == ControlButtonState.ADD) { final String type = this.selectedEntityType; if ((type == null) || type.equals("")) { @@ -556,12 +568,12 @@ private void mouseClick(final int screenX, final int screenY) { } } this.repaint(); - }* + } private void updateMouseInWindow(final boolean mouseInWindow) { this.mouseInWindow = mouseInWindow; this.repaintMouseOverlay(); - }* + } private void updateMousePosition(final int x, final int y) { final int oldX = this.currentMouseX; @@ -570,18 +582,18 @@ private void updateMousePosition(final int x, final int y) { this.currentMouseY = y; this.repaintCellHighlight(oldX, oldY); this.repaintMouseOverlay(); - }* + } private void repaintMouseOverlay() { this.repaintCellHighlight(this.currentMouseX, this.currentMouseY); this.repaint(0, this.getHeight() - this.INFO_BAR_HEIGHT, this.getWidth(), this.INFO_BAR_HEIGHT); - }* + } private void repaintCellHighlight(final int x, final int y) { final double cellSize = this.CELL_SIZE * this.scale; final int roundedCellSize = Math.toIntExact(Math.round(cellSize)); this.repaint(x - roundedCellSize, y - roundedCellSize, 2 * roundedCellSize, 2 * roundedCellSize); - }* + } private void updateDrag(final int x, final int y) { this.isDrag = true; @@ -591,7 +603,7 @@ private void updateDrag(final int x, final int y) { this.mouseStartX = x; this.mouseStartY = y; this.repaint(); - }* + } private void updateZoom(final int amount, final int x, final int y) { final double zoomScaling = 0.1 * Math.ceil(this.scale); @@ -610,17 +622,17 @@ private void updateZoom(final int amount, final int x, final int y) { this.scale = newScale; this.offsetX += dx; this.offsetY += dy; - * + Font font = this.getFont(); final int newFontSize = (int) Math.floor(12 * this.dpiScale * this.scale); this.scaleFont = new Font(font.getFontName(), font.getStyle(), newFontSize); this.repaint(); - }* + } @Override public void setSelectedTool(final ControlButtonState selectedTool) { this.activeTool = selectedTool; - }* + } @Override public void setSelectedEntityType(final String typeName, final String textureHandle) { diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java index 6696dbc0d..be56839c3 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTaskStatusDisplay.java @@ -9,11 +9,10 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.BorderLayout; import java.awt.Color; -import java.util.List;* +import java.util.List; + import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -24,10 +23,11 @@ import javax.swing.text.DefaultStyledDocument; import javax.swing.text.Style; import javax.swing.text.StyleConstants; -import javax.swing.text.StyledDocument;* +import javax.swing.text.StyledDocument; + import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; -import de.unistuttgart.informatik.fius.icge.ui.TaskStatusDisplay;** +import de.unistuttgart.informatik.fius.icge.ui.TaskStatusDisplay; /** @@ -37,14 +37,17 @@ * @version 1.0 */ public class SwingTaskStatusDisplay extends JPanel implements TaskStatusDisplay { - * - private static final long serialVersionUID = -2711911902591163118L;* - private final JTextPane textPane;* - private final Style textStyle; - private final Style taskTitle; - private final Style taskSuccess; - private final Style taskFail;* - private SimulationProxy simulationProxy;* + + private static final long serialVersionUID = -2711911902591163118L; + + private final JTextPane textPane; + + private final Style textStyle; + private final Style taskTitle; + private final Style taskSuccess; + private final Style taskFail; + + private SimulationProxy simulationProxy; /** * Default constructor. @@ -56,27 +59,27 @@ public class SwingTaskStatusDisplay extends JPanel implements TaskStatusDisplay */ public SwingTaskStatusDisplay(final double fontScale) { super(new BorderLayout()); - * + // setup text pane this.textPane = new JTextPane(new DefaultStyledDocument()); this.textPane.setEditable(false); ((DefaultCaret) this.textPane.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE); - * + // setup text styles final int fontSize = (int) Math.floor(12 * fontScale); this.textStyle = this.textPane.addStyle("Text", null); StyleConstants.setFontFamily(this.textStyle, "serif"); StyleConstants.setFontSize(this.textStyle, fontSize); - * + this.taskTitle = this.textPane.addStyle("TaskTitle", this.textStyle); StyleConstants.setBold(this.taskTitle, true); - * + this.taskSuccess = this.textPane.addStyle("TaskSuccess", this.taskTitle); this.taskFail = this.textPane.addStyle("TaskFail", this.taskTitle); - * + StyleConstants.setForeground(this.taskSuccess, Color.GREEN); StyleConstants.setForeground(this.taskFail, Color.RED); - * + // setup refresh button final JButton refreshButton = new JButton("Refresh"); refreshButton.addActionListener(ae -> { @@ -84,11 +87,11 @@ public SwingTaskStatusDisplay(final double fontScale) { this.simulationProxy.refreshTaskInformation(); } }); - * + // pack component this.add(new JScrollPane(this.textPane), BorderLayout.CENTER); this.add(refreshButton, BorderLayout.LINE_END); - }* + } /** * Set the simulation proxy. TODO better doc @@ -98,9 +101,9 @@ public SwingTaskStatusDisplay(final double fontScale) { */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - * + this.simulationProxy = simulationProxy; - }* + } @Override public void setTaskInformation(final TaskInformation task) { @@ -115,7 +118,7 @@ public void setTaskInformation(final TaskInformation task) { this.appendText(document, "You can set a task verifier in the SimulationBuilder.", this.textStyle); } }); - }* + } /** * Appends the task information of the task and all subtasks to the styled document. @@ -128,14 +131,14 @@ public void setTaskInformation(final TaskInformation task) { * the current task depth (starts with 0, may be used to indent subtasks later) */ private void appendTaskInformation(final TaskInformation task, final StyledDocument document, final int depth) { - * + // append title String title = task.getTaskTitle(); if (title == null || title.length() == 0) { title = "Unnamed Task"; } this.appendText(document, indentText(title, depth), this.taskTitle); - * + // append task status switch (task.getTaskStatus()) { case SUCCESSFUL: @@ -148,13 +151,13 @@ private void appendTaskInformation(final TaskInformation task, final StyledDocum default: this.appendText(document, " (pending)\n", this.taskTitle); } - * + // append description final String description = task.getTaskDescription(); if (description != null && description.length() > 0) { this.appendText(document, indentText(description + '\n', depth + 2), this.textStyle); } - * + // handle subtasks final List childTasks = task.getChildTasks(); if (childTasks != null) { @@ -163,7 +166,7 @@ private void appendTaskInformation(final TaskInformation task, final StyledDocum this.appendTaskInformation(subTask, document, depth + 1); } } - }* + } /** * Appends text to a styled document while silently dismissing {@link BadLocationException}. @@ -181,7 +184,7 @@ private void appendText(final StyledDocument document, final String text, final } catch (final BadLocationException e) { e.printStackTrace(); } - }* + } /** * This function appends indentation spaces to a string @@ -194,21 +197,21 @@ private void appendText(final StyledDocument document, final String text, final */ private static String indentText(final String text, final int depth) { if (depth == 0) return text; - * + StringBuilder returnString = new StringBuilder(); String indention = "\u2003".repeat(depth); - * + for (String s : text.split("\n")) { returnString.append(indention); returnString.append(s); returnString.append('\n'); } - * + // Delete the final new line character if needed to prevent additional unwanted newlines in the result string if (!text.endsWith("\n")) { returnString.deleteCharAt(returnString.length() - 1); } - * + return returnString.toString(); } } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java index 539c29d29..b77ee3c9d 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingTextureRegistry.java @@ -9,8 +9,6 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -22,10 +20,12 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.UUID; -import java.util.function.Function;* -import javax.imageio.ImageIO;* +import java.util.function.Function; + +import javax.imageio.ImageIO; + import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.exception.TextureNotFoundException;** +import de.unistuttgart.informatik.fius.icge.ui.exception.TextureNotFoundException; /** @@ -36,17 +36,17 @@ * @version 1.0 */ public class SwingTextureRegistry implements TextureRegistry { - private final Map resourceToHandle = new HashMap<>(); - private final Map pathToHandle = new HashMap<>(); - private final Set animatedTextures = new HashSet<>(); - private final Map handleToTexture = new HashMap<>();* + private final Map resourceToHandle = new HashMap<>(); + private final Map pathToHandle = new HashMap<>(); + private final Set animatedTextures = new HashSet<>(); + private final Map handleToTexture = new HashMap<>(); /** * Default constructor */ public SwingTextureRegistry() { StaticUiTextures.load(this); - }* + } /** * Generate a new unique texture handle. @@ -55,7 +55,7 @@ public SwingTextureRegistry() { */ private static String generateNewTextureHandle() { return UUID.randomUUID().toString(); - }* + } /** * Load a texture from a local (ui module) resource. @@ -67,7 +67,7 @@ private static String generateNewTextureHandle() { */ public String loadTextureFromResource(final String resourceName) { return this.loadTextureFromResource(resourceName, SwingTextureRegistry.class::getResourceAsStream); - }* + } @Override public String loadTextureFromResource(final String resourceName, final Function resourceProvider) { @@ -81,7 +81,7 @@ public String loadTextureFromResource(final String resourceName, final Function< } catch (IllegalArgumentException | IOException e) { throw new TextureNotFoundException("The requested Resource could not be loaded!", e); } - }* + } @Override public String loadTextureFromFile(final String filePath) { @@ -98,18 +98,18 @@ public String loadTextureFromFile(final String filePath) { throw new TextureNotFoundException("The requested path could not be loaded!", e); } return textureHandle; - }* + } @Override public String createAnimatedTexture(final boolean loop) { final String textureHandle = SwingTextureRegistry.generateNewTextureHandle(); - * + final AnimatedTexture animTexture = new AnimatedTexture(this, loop); this.handleToTexture.put(textureHandle, animTexture); this.animatedTextures.add(textureHandle); - * + return textureHandle; - }* + } @Override public void addAnimationFrameToTexture(final String animatedTexture, final String frameTexture, final long frames) { @@ -119,12 +119,12 @@ public void addAnimationFrameToTexture(final String animatedTexture, final Strin } catch (final ClassCastException e) { throw new IllegalArgumentException("Texture handle was not a handle for an animated texture!", e); } - }* + } @Override public boolean isTextureAnimated(final String textureHandle) { return this.animatedTextures.contains(textureHandle); - }* + } /** * Get the texture for the given texture handle. diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java index 2ef0991e0..453fd6bd8 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/SwingToolbar.java @@ -9,10 +9,9 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.event.ItemEvent; -import java.util.Hashtable;* +import java.util.Hashtable; + import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JLabel; @@ -21,12 +20,13 @@ import javax.swing.JToggleButton; import javax.swing.JToolBar; import javax.swing.SwingConstants; -import javax.swing.SwingUtilities;* +import javax.swing.SwingUtilities; + import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy; import de.unistuttgart.informatik.fius.icge.ui.SimulationProxy.ButtonType; import de.unistuttgart.informatik.fius.icge.ui.Toolbar; import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector; -import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry;** +import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry; /** @@ -38,27 +38,32 @@ * @version 1.0 */ public class SwingToolbar extends JToolBar implements Toolbar { - private static final long serialVersionUID = -2525998620577603876L;* + private static final long serialVersionUID = -2525998620577603876L; + /** The simulation proxy */ private SimulationProxy simulationProxy; /** The texture registry */ - private final SwingTextureRegistry textureRegistry;* + private final SwingTextureRegistry textureRegistry; + /** The play button in the toolbar */ - private JButton play; + private JButton play; /** The step button in the toolbar */ - private JButton step; + private JButton step; /** The pause button in the toolbar */ - private JButton pause;* + private JButton pause; + /** A slider to set the simulation time */ - private JSlider simulationTime;* + private JSlider simulationTime; + /** The button to change to view mode */ - private JToggleButton view; + private JToggleButton view; /** The button to change to add mode */ - private JToggleButton add; + private JToggleButton add; /** The button to change to sub mode */ - private JToggleButton sub;* + private JToggleButton sub; + /** The selector which selects the entity for the user to place */ - private DropdownSelector entitySelect;* + private DropdownSelector entitySelect; /** * The constructor of the toolbar @@ -75,12 +80,12 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi // class setup // this.textureRegistry = textureRegistry; - * + // // toolbar setup // this.setFloatable(false); - * + // // play button setup // @@ -92,7 +97,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.play.setEnabled(false); this.add(this.play); - * + // // step button setup // @@ -104,7 +109,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.step.setEnabled(false); this.add(this.step); - * + // // pause button setup // @@ -116,7 +121,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.pause.setEnabled(false); this.add(this.pause); - * + // // simulation time slider setup // @@ -137,7 +142,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi // setup change listener this.simulationTime.addChangeListener(event -> { final JSlider source = (JSlider) event.getSource(); - * + if (!source.getValueIsAdjusting()) { if (this.simulationProxy != null) { this.simulationProxy.simulationSpeedChange(source.getValue()); @@ -147,12 +152,12 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi this.simulationTime.setEnabled(false); this.add(this.simulationTime); this.addSeparator(); - * + // // add visual separator // this.add(new JSeparator(SwingConstants.VERTICAL)); - * + // // view button setup // @@ -164,7 +169,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.view.setEnabled(false); this.add(this.view); - * + // // add button setup // @@ -176,7 +181,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.add.setEnabled(false); this.add(this.add); - * + // // sub button setup // @@ -188,7 +193,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.sub.setEnabled(false); this.add(this.sub); - * + // // entity selector setup // @@ -203,7 +208,7 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi }); this.entitySelect.setEnabled(false); this.add(this.entitySelect); - }* + } /** * @@ -212,16 +217,16 @@ public SwingToolbar(final SwingTextureRegistry textureRegistry, final double dpi */ public void setSimulationProxy(final SimulationProxy simulationProxy) { if (this.simulationProxy != null) throw new IllegalStateException("SimulationProxy is already set and cannot be overwritten!"); - * + this.simulationProxy = simulationProxy; - }* + } @Override public void addEntity(final String displayName, final String textureID) { SwingUtilities.invokeLater(() -> { this.entitySelect.addEntry(this.entitySelect.new DropdownEntry(displayName, textureID)); }); - }* + } private void setControlButtonStateInternal(final ControlButtonState controlButtonState) { switch (controlButtonState) { @@ -230,33 +235,33 @@ private void setControlButtonStateInternal(final ControlButtonState controlButto this.add.setEnabled(true); this.sub.setEnabled(true); break; - * + case ADD: this.view.setEnabled(true); this.add.setEnabled(false); this.sub.setEnabled(true); break; - * + case SUB: this.view.setEnabled(true); this.add.setEnabled(true); this.sub.setEnabled(false); break; - * + case BLOCKED: this.view.setEnabled(false); this.add.setEnabled(false); this.sub.setEnabled(false); break; - * + default: } - }* + } @Override public void setControlButtonState(final ControlButtonState controlButtonState) { SwingUtilities.invokeLater(() -> this.setControlButtonStateInternal(controlButtonState)); - }* + } private void setClockButtonStateInternal(final ClockButtonState clockButtonState) { switch (clockButtonState) { @@ -280,17 +285,17 @@ private void setClockButtonStateInternal(final ClockButtonState clockButtonState break; default: } - }* + } @Override public void setClockButtonState(final ClockButtonState clockButtonState) { SwingUtilities.invokeLater(() -> this.setClockButtonStateInternal(clockButtonState)); - }* + } @Override public int getSpeedSliderPosition() { return this.simulationTime.getValue(); - }* + } @Override public void setSpeedSliderPosition(final int position) { @@ -300,28 +305,28 @@ public void setSpeedSliderPosition(final int position) { "Simulation Speed Value is out of bounds. Should be between 0 and 10 (both inclusive) but is: " + position ); SwingUtilities.invokeLater(() -> this.simulationTime.setValue(position)); - }* + } @Override public String getCurrentlySelectedEntity() { final DropdownEntry currentEntry = this.entitySelect.getCurrentEntry(); if (currentEntry == null) return ""; return currentEntry.displayName; - }* + } @Override public void setCurrentlySelectedEntity(final String entity) { SwingUtilities.invokeLater(() -> { this.entitySelect.setCurrentEntry(this.entitySelect.new DropdownEntry(entity)); }); - }* + } @Override public void enableEntitySelector() { SwingUtilities.invokeLater(() -> { this.entitySelect.setEnabled(true); }); - }* + } @Override public void disableEntitySelector() { @@ -329,5 +334,6 @@ public void disableEntitySelector() { this.entitySelect.removeAllEntries(); this.entitySelect.setEnabled(false); }); - }* + } + } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java index 4d88d7b80..73e5cc517 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/Texture.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal; -* - import java.awt.Graphics; -import java.awt.Image;** +import java.awt.Image; /** @@ -21,7 +19,7 @@ * @author Fabian Bühler */ public interface Texture { - * + /** * Get the texture image. * @@ -30,7 +28,7 @@ public interface Texture { default Image getTexture() { return this.getTexture(0); } - * + /** * Get the texture image. * @@ -39,7 +37,7 @@ default Image getTexture() { * @return the image */ Image getTexture(long frame); - * + /** * Draw the texture onto the screen. *

@@ -59,7 +57,7 @@ default Image getTexture() { default void drawTexture(final long frame, final Graphics g, final int x, final int y, final int size) { this.drawTexture(frame, g, x, y, size, size); } - * + /** * Draw the texture onto the screen. *

diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java index 3aac87d24..93cc766c2 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemEditor.java @@ -9,20 +9,20 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal.dropdown; -* - import java.awt.Color; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.Insets;* +import java.awt.Insets; + import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; -import javax.swing.plaf.basic.BasicComboBoxEditor;* +import javax.swing.plaf.basic.BasicComboBoxEditor; + import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry;** +import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry; /** @@ -32,12 +32,13 @@ * @version 1.0 */ class DropdownItemEditor extends BasicComboBoxEditor { - * + /** The texture registry */ - private final SwingTextureRegistry textureRegistry;* - private final JPanel panel; - private final JLabel labelItem; - private DropdownEntry selectedValue;* + private final SwingTextureRegistry textureRegistry; + + private final JPanel panel; + private final JLabel labelItem; + private DropdownEntry selectedValue; /** * Constructor for the DropdownItemEditor @@ -49,7 +50,7 @@ class DropdownItemEditor extends BasicComboBoxEditor { */ public DropdownItemEditor(final SwingTextureRegistry textureRegistry) { this.textureRegistry = textureRegistry; - * + this.panel = new JPanel(); this.panel.setBackground(Color.BLUE); this.panel.setLayout(new GridBagLayout()); @@ -57,32 +58,32 @@ public DropdownItemEditor(final SwingTextureRegistry textureRegistry) { constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; constraints.insets = new Insets(2, 5, 2, 2); - * + this.labelItem = new JLabel(); this.labelItem.setOpaque(false); this.labelItem.setHorizontalAlignment(SwingConstants.LEFT); this.labelItem.setForeground(Color.WHITE); - * + this.panel.add(this.labelItem, constraints); - }* + } @Override public Component getEditorComponent() { return this.panel; - }* + } @Override public Object getItem() { return this.selectedValue; - }* + } @Override public void setItem(final Object item) { if (item == null) return; - * + this.selectedValue = (DropdownEntry) item; this.labelItem.setText(this.selectedValue.displayName); - * + if (!this.selectedValue.textureID.equals("")) { this.labelItem.setIcon(new ImageIcon(this.textureRegistry.getTextureForHandle(this.selectedValue.textureID).getTexture())); } diff --git a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java index 83becc192..2a085d0a5 100644 --- a/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java +++ b/ICGE-Ui/src/main/java/de/unistuttgart/informatik/fius/icge/ui/internal/dropdown/DropdownItemRenderer.java @@ -9,21 +9,21 @@ */ package de.unistuttgart.informatik.fius.icge.ui.internal.dropdown; -* - import java.awt.Color; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.Insets;* +import java.awt.Insets; + import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListCellRenderer; -import javax.swing.SwingConstants;* +import javax.swing.SwingConstants; + import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry;** +import de.unistuttgart.informatik.fius.icge.ui.internal.dropdown.DropdownSelector.DropdownEntry; /** @@ -33,10 +33,12 @@ * @version 1.0 */ class DropdownItemRenderer extends JPanel implements ListCellRenderer { - private static final long serialVersionUID = 2930839533138981414L;* + private static final long serialVersionUID = 2930839533138981414L; + /** The texture registry */ - private final SwingTextureRegistry textureRegistry;* - private final JLabel labelItem;* + private final SwingTextureRegistry textureRegistry; + + private final JLabel labelItem; /** * Constructor for the DropdownItemRenderer @@ -48,20 +50,20 @@ class DropdownItemRenderer extends JPanel implements ListCellRenderer comboBox;* + private final SwingTextureRegistry textureRegistry; + + private final JLabel label; + private final JComboBox comboBox; + /** The data model of the DropdownSelector */ - private final DefaultComboBoxModel model;* + private final DefaultComboBoxModel model; /** * Constructor of the DropdownSelector @@ -93,19 +95,19 @@ public DropdownEntry(final String name, final String texture) { */ public DropdownSelector(final SwingTextureRegistry textureRegistry, final String header) { this.textureRegistry = textureRegistry; - * + this.label = new JLabel(header + ": "); this.comboBox = new JComboBox<>(); - * + this.model = new DefaultComboBoxModel<>(); this.comboBox.setModel(this.model); this.comboBox.setRenderer(new DropdownItemRenderer(this.textureRegistry)); this.comboBox.setEditor(new DropdownItemEditor(this.textureRegistry)); - * + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(this.label); this.add(this.comboBox); - }* + } /** * Getter for the currently selected entry @@ -114,7 +116,7 @@ public DropdownSelector(final SwingTextureRegistry textureRegistry, final String */ public DropdownEntry getCurrentEntry() { return (DropdownEntry) this.comboBox.getEditor().getItem(); - }* + } /** * Setter for the currently selected entry @@ -128,7 +130,7 @@ public DropdownEntry getCurrentEntry() { */ public void setCurrentEntry(final DropdownEntry entry) { this.comboBox.getEditor().setItem(entry); - }* + } /** * This function adds an entry to the selector @@ -141,12 +143,12 @@ public void setCurrentEntry(final DropdownEntry entry) { public void addEntry(final DropdownEntry... entries) { for (final DropdownEntry entry : entries) { this.model.addElement(entry); - * + if (getCurrentEntry() == null) { this.setCurrentEntry(entry); } } - }* + } /** * This function removes all entries from the dropdown menu @@ -155,7 +157,7 @@ public void addEntry(final DropdownEntry... entries) { */ public void removeAllEntries() { this.model.removeAllElements(); - }* + } /** * Adds a listener which reacts to the selection and deselection of items @@ -167,7 +169,7 @@ public void removeAllEntries() { */ public void addSelectionListener(final ItemListener listener) { this.comboBox.addItemListener(listener); - }* + } @Override public void setEnabled(final boolean enabled) { diff --git a/ICGE-Ui/src/main/java/module-info.java b/ICGE-Ui/src/main/java/module-info.java index e334b157a..2c89b3efa 100644 --- a/ICGE-Ui/src/main/java/module-info.java +++ b/ICGE-Ui/src/main/java/module-info.java @@ -10,7 +10,7 @@ module de.unistuttgart.informatik.fius.icge.ui { requires java.desktop; requires de.unistuttgart.informatik.fius.icge.log; - * + exports de.unistuttgart.informatik.fius.icge.ui; exports de.unistuttgart.informatik.fius.icge.ui.exception; } diff --git a/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java b/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java index e48a8391e..336a8e855 100644 --- a/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java +++ b/ICGE-Ui/src/test/java/de/unistuttgart/informatik/fius/icge/ui/SwingGameWindowUiTest.java @@ -9,21 +9,22 @@ */ package de.unistuttgart.informatik.fius.icge.ui; -* +import java.lang.reflect.InvocationTargetException; + +import javax.swing.SwingUtilities; -import java.lang.reflect.InvocationTargetException;* -import javax.swing.SwingUtilities;* import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test;* +import org.junit.jupiter.api.Test; + import de.unistuttgart.informatik.fius.icge.ui.internal.SwingConsole; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingEntitySidebar; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingGameWindow; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingPlayfieldDrawer; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTaskStatusDisplay; import de.unistuttgart.informatik.fius.icge.ui.internal.SwingTextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.internal.SwingToolbar;** +import de.unistuttgart.informatik.fius.icge.ui.internal.SwingToolbar; /** @@ -32,8 +33,8 @@ * @author Tim Neumann */ class SwingGameWindowUiTest { - * - private SwingGameWindow window;* + + private SwingGameWindow window; /** * Setup the game window @@ -50,10 +51,10 @@ public void setup() throws Exception { final SwingEntitySidebar entitySidebar = new SwingEntitySidebar(textureRegistry, 1); final SwingConsole console = new SwingConsole(1); final SwingTaskStatusDisplay taskStatus = new SwingTaskStatusDisplay(1); - * + this.window = new SwingGameWindow(textureRegistry, playfieldDrawer, toolbar, entitySidebar, console, taskStatus); }); - }* + } /** * Test {@link SwingGameWindow#start()} From 9a334497c760401dd3357ce3777aa88af5aa6a8f Mon Sep 17 00:00:00 2001 From: graefjk Date: Thu, 4 Jan 2024 02:47:39 +0100 Subject: [PATCH 6/6] formatting --- .../fius/icge/manualstart/Coin.java | 10 +- .../manualstart/ManualStartSimulation.java | 16 ++-- .../fius/icge/manualstart/ManualStartUi.java | 8 +- .../fius/icge/manualstart/TestEntity.java | 10 +- .../fius/icge/manualstart/TestTask.java | 14 ++- .../icge/manualstart/TestTaskVerifier.java | 96 +++++++++---------- .../fius/icge/example/mario/Texture.java | 2 +- scriptsAndTools/#correctJavaFileComment.txt# | 9 -- 8 files changed, 73 insertions(+), 92 deletions(-) delete mode 100644 scriptsAndTools/#correctJavaFileComment.txt# diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java index 20db316a7..6c6950e44 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/Coin.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; -* - import de.unistuttgart.informatik.fius.icge.simulation.entity.BasicEntity; -import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity; /** @@ -21,17 +19,17 @@ * @author Fabian Bühler */ public class Coin extends BasicEntity implements CollectableEntity { - * + /** * The texture handle used for the test entity. */ public static String TEXTURE_HANDLE; - * + @Override protected String getTextureHandle() { return TEXTURE_HANDLE; } - * + @Override protected int getZPosition() { return 0; diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java index e960d55b4..80d9f4d37 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartSimulation.java @@ -9,13 +9,11 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; -* - import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.SimulationBuilder; import de.unistuttgart.informatik.fius.icge.ui.GameWindow; import de.unistuttgart.informatik.fius.icge.ui.TextureRegistry; -import de.unistuttgart.informatik.fius.icge.ui.WindowBuilder;** +import de.unistuttgart.informatik.fius.icge.ui.WindowBuilder; /** @@ -24,10 +22,10 @@ * @author Tim Neumann */ public class ManualStartSimulation { - * + private static String textureHandleWall; private static String textureHandleCoin; - private static String animated;* + private static String animated; /** * @param args @@ -40,20 +38,20 @@ public static void main(final String[] args) { // wb.setDpiScale(1.0); wb.buildWindow(); final GameWindow w = wb.getBuiltWindow(); - * + ManualStartSimulation.prepareTextures(w.getTextureRegistry()); TestEntity.TEXTURE_HANDLE = ManualStartSimulation.animated; Coin.TEXTURE_HANDLE = textureHandleCoin; - * + final SimulationBuilder sb = new SimulationBuilder(); sb.setTaskVerifier(new TestTaskVerifier()); sb.buildSimulation(); final Simulation sim = sb.getBuiltSimulation(); - * + w.start(); sim.attachToWindow(w, true); sim.runTask(new TestTask()); - }* + } private static void prepareTextures(final TextureRegistry tr) { ManualStartSimulation.textureHandleWall = tr diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java index c891b53e1..4510360bc 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/ManualStartUi.java @@ -9,10 +9,8 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; -* - import de.unistuttgart.informatik.fius.icge.ui.GameWindow; -import de.unistuttgart.informatik.fius.icge.ui.WindowBuilder;** +import de.unistuttgart.informatik.fius.icge.ui.WindowBuilder; /** @@ -21,7 +19,7 @@ * @author Tim Neumann */ public class ManualStartUi { - * + /** * Main entry point of the program * @@ -31,7 +29,7 @@ public class ManualStartUi { public static void main(final String[] args) { ManualStartUi.newStyleBuilder(); } - * + private static void newStyleBuilder() { final WindowBuilder wb = new WindowBuilder(); wb.setTitle("Window Builder start!"); diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java index 9815ab830..b5b2ca9c1 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestEntity.java @@ -9,26 +9,24 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; -* - -import de.unistuttgart.informatik.fius.icge.simulation.entity.GreedyEntity;** +import de.unistuttgart.informatik.fius.icge.simulation.entity.GreedyEntity; /** * Basic test entity. */ public class TestEntity extends GreedyEntity { - * + /** * The texture handle used for the test entity. */ public static String TEXTURE_HANDLE; - * + @Override protected String getTextureHandle() { return TestEntity.TEXTURE_HANDLE; } - * + @Override protected int getZPosition() { return 0; diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java index 2e639997c..458034ed5 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTask.java @@ -9,29 +9,27 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; -* - import de.unistuttgart.informatik.fius.icge.simulation.Position; import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.entity.CollectableEntity; import de.unistuttgart.informatik.fius.icge.simulation.programs.Program; -import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task;** +import de.unistuttgart.informatik.fius.icge.simulation.tasks.Task; /** * Test task for manual start. */ public class TestTask implements Task { - * + @Override public void run(final Simulation sim) { final TestEntity tE = new TestEntity(); - * + sim.getPlayfield().addEntity(new Position(3, 4), tE); - * + CollectableEntity coin = new Coin(); sim.getPlayfield().addEntity(new Position(3, 4), coin); - * + while (true) { tE.collect(coin); tE.drop(coin); @@ -46,7 +44,7 @@ public void run(final Simulation sim) { break; } } - * + sim.runProgram(new Program() { @Override public void run(TestEntity entity) { diff --git a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java index c5a54d7d8..52704a591 100644 --- a/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java +++ b/ICGE-ManualStart/src/main/java/de/unistuttgart/informatik/fius/icge/manualstart/TestTaskVerifier.java @@ -9,17 +9,16 @@ */ package de.unistuttgart.informatik.fius.icge.manualstart; -* - import java.util.ArrayList; import java.util.Collections; -import java.util.List;* +import java.util.List; + import de.unistuttgart.informatik.fius.icge.simulation.Simulation; import de.unistuttgart.informatik.fius.icge.simulation.TaskVerifier; import de.unistuttgart.informatik.fius.icge.simulation.actions.ActionLog; import de.unistuttgart.informatik.fius.icge.simulation.actions.EntityMoveAction; import de.unistuttgart.informatik.fius.icge.ui.TaskInformation; -import de.unistuttgart.informatik.fius.icge.ui.TaskVerificationStatus;** +import de.unistuttgart.informatik.fius.icge.ui.TaskVerificationStatus; /** @@ -31,18 +30,18 @@ * @author Fabian Bühler */ public class TestTaskVerifier implements TaskVerifier, TaskInformation { - * + private ActionLog log; private TaskVerificationStatus taskIsValid = TaskVerificationStatus.UNDECIDED; private int minStepsToWalk = 4; private int maxStepsToWalk = 14; - private int stepsWalked = 0;* + private int stepsWalked = 0; @Override public void attachToSimulation(Simulation sim) { // get the log to verify if the required events did happen later this.log = sim.getActionLog(); - }* + } @Override public void verify() { @@ -51,32 +50,32 @@ public void verify() { } // check the number of steps/moves all entity have taken together this.stepsWalked = this.log.getActionsOfType(EntityMoveAction.class, true).size(); - * + // as long as task is still achievable use UNDECIDED status if (this.stepsWalked < this.minStepsToWalk) { this.taskIsValid = TaskVerificationStatus.UNDECIDED; return; } - * + // if task is failed irreversibly use FAILED status if (this.stepsWalked > this.maxStepsToWalk) { this.taskIsValid = TaskVerificationStatus.FAILED; return; } - * + // use SUCCESSFUL status if task is solved correctly this.taskIsValid = TaskVerificationStatus.SUCCESSFUL; - }* + } @Override public TaskInformation getTaskInformation() { return this; - }* + } @Override public String getTaskTitle() { return "Test Task"; - }* + } @Override public String getTaskDescription() { @@ -88,157 +87,158 @@ public String getTaskDescription() { description += " (1 step walked)"; } return description; - }* + } @Override public TaskVerificationStatus getTaskStatus() { return this.taskIsValid; - }* + } @Override public List getChildTasks() { ArrayList subTasks = new ArrayList<>(); - * + subTasks.add(new TaskInformation() { - * + @Override public String getTaskTitle() { return "a) Successful sub task"; } - * + @Override public String getTaskDescription() { return "Super basic sample description"; } - * + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.SUCCESSFUL; } - * + @Override public List getChildTasks() { return Collections.emptyList(); } }); - * + subTasks.add(new TaskInformation() { - * + @Override public String getTaskTitle() { return "b) undecided sub task"; } - * + @Override public String getTaskDescription() { return "Super basic sample description"; } - * + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.UNDECIDED; } - * + @Override public List getChildTasks() { ArrayList subTasks = new ArrayList<>(); - * + subTasks.add(new TaskInformation() { - * + @Override public String getTaskTitle() { return "b.1) Successful sub sub task"; } - * + @Override public String getTaskDescription() { return "Super basic sample description"; } - * + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.SUCCESSFUL; } - * + @Override public List getChildTasks() { return Collections.emptyList(); } }); - * + subTasks.add(new TaskInformation() { - * + @Override public String getTaskTitle() { return "b.2) undecided sub sub task"; } - * + @Override public String getTaskDescription() { return "Super basic sample description"; } - * + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.UNDECIDED; } - * + @Override public List getChildTasks() { return Collections.emptyList(); } }); - * + subTasks.add(new TaskInformation() { - * + @Override public String getTaskTitle() { return "b.3) failed sub sub task"; } - * + @Override public String getTaskDescription() { return "Super basic sample description"; } - * + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.FAILED; } - * + @Override public List getChildTasks() { return Collections.emptyList(); } }); - * + return subTasks; } }); - * + subTasks.add(new TaskInformation() { - * + @Override public String getTaskTitle() { return "c) failed sub task"; } - * + @Override public String getTaskDescription() { return "Super basic sample description"; } - * + @Override public TaskVerificationStatus getTaskStatus() { return TaskVerificationStatus.FAILED; } - * + @Override public List getChildTasks() { return Collections.emptyList(); } }); - * + return subTasks; - }* + } + } diff --git a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Texture.java b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Texture.java index 72d2fecf6..2bbbccef6 100644 --- a/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Texture.java +++ b/examples/mario/src/main/java/de/unistuttgart/informatik/fius/icge/example/mario/Texture.java @@ -16,7 +16,7 @@ /** * The enum for all builtin mario textures. - * + * * @author Tim Neumann */ public enum Texture { diff --git a/scriptsAndTools/#correctJavaFileComment.txt# b/scriptsAndTools/#correctJavaFileComment.txt# deleted file mode 100644 index ac876acd5..000000000 --- a/scriptsAndTools/#correctJavaFileComment.txt# +++ /dev/null @@ -1,9 +0,0 @@ -/* - * This source file is part of the FIUS ICGE project. - * For more information see github.com/FIUS/ICGE2 - * - * Copyright (c) 2019 the ICGE project authors. - * - * This software is available under the MIT license. - * SPDX-License-Identifier: MIT - */ \ No newline at end of file