From 0c272170b6348bd30977b7f38860f1355428d9d0 Mon Sep 17 00:00:00 2001
From: tobias <thinkdifferent055@gmail.com>
Date: Mon, 20 Dec 2021 20:54:55 +0100
Subject: [PATCH] Cleanup pad warning methods

---
 .../playpad/design/ModernDesignAnimator.java  | 28 +++++++++----------
 .../pad/listener/PadPositionListener.java     |  2 +-
 .../ModernWarningDesignHandlerImpl.scala      |  7 +++--
 .../modern/ModernWarningDesignHandler.java    |  3 +-
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/PlayWall/src/main/java/de/tobias/playpad/design/ModernDesignAnimator.java b/PlayWall/src/main/java/de/tobias/playpad/design/ModernDesignAnimator.java
index ffd70e7b..08b99ef1 100644
--- a/PlayWall/src/main/java/de/tobias/playpad/design/ModernDesignAnimator.java
+++ b/PlayWall/src/main/java/de/tobias/playpad/design/ModernDesignAnimator.java
@@ -1,7 +1,7 @@
 package de.tobias.playpad.design;
 
 import de.tobias.playpad.pad.view.IPadView;
-import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController;
+import de.tobias.playpad.project.api.IPad;
 import de.tobias.playpad.util.FadeableColor;
 import de.tobias.playpad.view.PseudoClasses;
 import javafx.animation.KeyFrame;
@@ -17,22 +17,21 @@ import java.util.HashMap;
 
 public class ModernDesignAnimator {
 
-	// alles nur static, neine objecte von der Klasse
 	private ModernDesignAnimator() {
 	}
 
-	private static HashMap<Integer, Timeline> timelines = new HashMap<>();
+	private static final HashMap<Integer, Timeline> timelines = new HashMap<>();
 
-	public static void animateFade(AbstractPadViewController padViewController, FadeableColor startColor, FadeableColor endColor, Duration duration) {
+	public static void animateFade(IPad pad, IPadView padView, FadeableColor startColor, FadeableColor endColor, Duration duration) {
 		ObjectProperty<FadeableColor> backgroundColor = new SimpleObjectProperty<>();
 
 		Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(0), new KeyValue(backgroundColor, startColor)),
 				new KeyFrame(duration, new KeyValue(backgroundColor, endColor)));
 
-		animate(padViewController, timeline, backgroundColor);
+		animate(pad, padView, timeline, backgroundColor);
 	}
 
-	public static void animateWarn(AbstractPadViewController padViewController, FadeableColor startColor, FadeableColor endColor, Duration duration) {
+	public static void animateWarn(IPad pad, IPadView padView, FadeableColor startColor, FadeableColor endColor, Duration duration) {
 		ObjectProperty<FadeableColor> backgroundColor = new SimpleObjectProperty<>();
 
 		Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(0), new KeyValue(backgroundColor, startColor)),
@@ -42,17 +41,17 @@ public class ModernDesignAnimator {
 
 		timeline.setAutoReverse(true);
 		timeline.setCycleCount((int) (duration.toSeconds() / 0.625));
-		animate(padViewController, timeline, backgroundColor);
+		animate(pad, padView, timeline, backgroundColor);
 	}
 
-	private static void animate(AbstractPadViewController padViewController, Timeline timeline, ObjectProperty<FadeableColor> objectProperty) {
-		int index = padViewController.getPad().getPosition();
+	private static void animate(IPad pad, IPadView padView, Timeline timeline, ObjectProperty<FadeableColor> objectProperty) {
+		int index = pad.getPosition();
 
 		if (timelines.containsKey(index)) {
 			timelines.get(index).stop();
 		}
 
-		ChangeListener<FadeableColor> fadeListener = (observable, oldValue, newValue) -> padViewController.getView().setStyle("-fx-background-color: " + newValue.toString() + ";");
+		ChangeListener<FadeableColor> fadeListener = (observable, oldValue, newValue) -> padView.setStyle("-fx-background-color: " + newValue.toString() + ";");
 		objectProperty.addListener(fadeListener);
 
 		timeline.playFromStart();
@@ -60,7 +59,7 @@ public class ModernDesignAnimator {
 		timeline.setOnFinished(event ->
 		{
 			objectProperty.removeListener(fadeListener);
-			padViewController.getView().setStyle("");
+			padView.setStyle("");
 			timelines.remove(index);
 		});
 
@@ -68,16 +67,15 @@ public class ModernDesignAnimator {
 		timelines.put(index, timeline);
 	}
 
-	public static void stopAnimation(AbstractPadViewController controller) {
-		int index = controller.getPad().getPosition();
+	public static void stopAnimation(IPad pad) {
+		int index = pad.getPosition();
 
 		if (timelines.containsKey(index)) {
 			timelines.get(index).stop();
 		}
 	}
 
-	public static void warnFlash(AbstractPadViewController controller) {
-		final IPadView view = controller.getView();
+	public static void warnFlash(IPadView view) {
 		try {
 			while (!Thread.interrupted()) {
 
diff --git a/PlayWall/src/main/java/de/tobias/playpad/pad/listener/PadPositionListener.java b/PlayWall/src/main/java/de/tobias/playpad/pad/listener/PadPositionListener.java
index 4feab061..d2eee40c 100644
--- a/PlayWall/src/main/java/de/tobias/playpad/pad/listener/PadPositionListener.java
+++ b/PlayWall/src/main/java/de/tobias/playpad/pad/listener/PadPositionListener.java
@@ -133,7 +133,7 @@ public class PadPositionListener implements Runnable, IPadPositionListener {
 		final ModernDesignProvider modernDesign = PlayPadMain.getProgramInstance().getModernDesign();
 
 		final ModernWarningDesignHandler handler = modernDesign.warning();
-		handler.stopWarning(controller);
+		handler.stopWarning(controller.getPad());
 		controller.getView().setStyle("");
 	}
 }
diff --git a/PlayWall/src/main/scala/de/tobias/playpad/design/ModernWarningDesignHandlerImpl.scala b/PlayWall/src/main/scala/de/tobias/playpad/design/ModernWarningDesignHandlerImpl.scala
index 30a8c490..c849a213 100644
--- a/PlayWall/src/main/scala/de/tobias/playpad/design/ModernWarningDesignHandlerImpl.scala
+++ b/PlayWall/src/main/scala/de/tobias/playpad/design/ModernWarningDesignHandlerImpl.scala
@@ -3,6 +3,7 @@ package de.tobias.playpad.design
 import de.tobias.playpad.design.modern.ModernWarningDesignHandler
 import de.tobias.playpad.design.modern.model.ModernGlobalDesign
 import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController
+import de.tobias.playpad.project.api.IPad
 import de.tobias.playpad.util.FadeableColor
 import javafx.util.Duration
 
@@ -10,11 +11,11 @@ class ModernWarningDesignHandlerImpl extends ModernWarningDesignHandler {
 
 	override def performWarning(design: ModernGlobalDesign, fadeStartColor: FadeableColor, fadeStopColor: FadeableColor, controller: AbstractPadViewController, warningDuration: Duration): Unit = {
 		if (design.isWarnAnimation) {
-			ModernDesignAnimator.animateWarn(controller, fadeStartColor, fadeStopColor, warningDuration)
+			ModernDesignAnimator.animateWarn(controller.getPad, controller.getView, fadeStartColor, fadeStopColor, warningDuration)
 		} else {
-			ModernDesignAnimator.warnFlash(controller)
+			ModernDesignAnimator.warnFlash(controller.getView)
 		}
 	}
 
-	override def stopWarning(controller: AbstractPadViewController): Unit = ModernDesignAnimator.stopAnimation(controller)
+	override def stopWarning(pad: IPad): Unit = ModernDesignAnimator.stopAnimation(pad)
 }
diff --git a/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernWarningDesignHandler.java b/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernWarningDesignHandler.java
index aeed4d5a..405b60e0 100644
--- a/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernWarningDesignHandler.java
+++ b/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernWarningDesignHandler.java
@@ -5,6 +5,7 @@ import de.tobias.playpad.design.modern.model.ModernGlobalDesign;
 import de.tobias.playpad.pad.Pad;
 import de.tobias.playpad.pad.content.play.Durationable;
 import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController;
+import de.tobias.playpad.project.api.IPad;
 import de.tobias.playpad.util.FadeableColor;
 import javafx.util.Duration;
 
@@ -45,6 +46,6 @@ public interface ModernWarningDesignHandler {
 	 */
 	void performWarning(ModernGlobalDesign design, FadeableColor fadeStartColor, FadeableColor fadeStopColor, AbstractPadViewController controller, Duration duration);
 
-	default void stopWarning(AbstractPadViewController controller) {
+	default void stopWarning(IPad pad) {
 	}
 }
-- 
GitLab