From 0d948a2de1189564cd81244b4850468a738aa34d Mon Sep 17 00:00:00 2001
From: Robert Goldmann <deadlocker@gmx.de>
Date: Thu, 2 Dec 2021 22:10:47 +0100
Subject: [PATCH] #157 - Removed remaining calls to old isCustomDesign property

---
 .../pad/listener/PadPositionListener.java     | 32 ++++-------
 .../design/ModernCartDesignHandlerImpl.scala  | 44 +++++++--------
 .../ModernGlobalDesignHandlerImpl.scala       | 33 +++---------
 .../modern/ModernCartDesignHandler.java       | 14 +----
 .../modern/ModernDesignHandlerParent.java     | 54 +++++++++++++++++++
 .../modern/ModernGlobalDesignHandler.java     | 12 +----
 .../de/tobias/playpad/pad/PadSettings.java    |  4 --
 .../playpad/pad/PadSettingsSerializer.java    |  1 -
 8 files changed, 90 insertions(+), 104 deletions(-)
 create mode 100644 PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernDesignHandlerParent.java

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 5326b5f9..761fae5a 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
@@ -3,7 +3,6 @@ package de.tobias.playpad.pad.listener;
 import de.tobias.playpad.PlayPadMain;
 import de.tobias.playpad.action.actions.CartAction;
 import de.tobias.playpad.design.ModernDesignHandler;
-import de.tobias.playpad.design.modern.ModernCartDesignHandler;
 import de.tobias.playpad.design.modern.ModernGlobalDesignHandler;
 import de.tobias.playpad.design.modern.model.ModernCartDesign;
 import de.tobias.playpad.design.modern.model.ModernGlobalDesign;
@@ -104,21 +103,17 @@ public class PadPositionListener implements Runnable, IPadPositionListener {
 	 */
 	@Override
 	public void run() {
-		PadSettings padSettings = pad.getPadSettings();
-		Duration warning = padSettings.getWarning();
+		final PadSettings padSettings = pad.getPadSettings();
+		final Duration warningDuration = padSettings.getWarning();
+
+		final ModernGlobalDesign globalDesign = Profile.currentProfile().getProfileSettings().getDesign();
+		final ModernCartDesign cartDesign = padSettings.getDesign();
 
-		ModernGlobalDesign globalDesign = Profile.currentProfile().getProfileSettings().getDesign();
 		final ModernDesignHandler modernDesign = PlayPadMain.getProgramInstance().getModernDesign();
 
-		if (padSettings.isCustomDesign()) {
-			ModernCartDesignHandler handler = modernDesign.cart();
-			ModernCartDesign design = pad.getPadSettings().getDesign();
+		final ModernGlobalDesignHandler handler = modernDesign.global();
 
-			handler.handleWarning(design, controller, warning, globalDesign);
-		} else {
-			ModernGlobalDesignHandler handler = modernDesign.global();
-			handler.handleWarning(globalDesign, controller, warning);
-		}
+		handler.handleWarning(globalDesign, cartDesign, controller, warningDuration);
 	}
 
 	private void startWarningThread() {
@@ -139,17 +134,8 @@ public class PadPositionListener implements Runnable, IPadPositionListener {
 		PadSettings padSettings = pad.getPadSettings();
 		final ModernDesignHandler modernDesign = PlayPadMain.getProgramInstance().getModernDesign();
 
-		if (padSettings.isCustomDesign()) {
-			ModernCartDesignHandler handler = modernDesign.cart();
-			ModernCartDesign design = pad.getPadSettings().getDesign();
-
-			handler.stopWarning(design, controller);
-		} else {
-			ModernGlobalDesignHandler handler = modernDesign.global();
-			ModernGlobalDesign globalDesign = Profile.currentProfile().getProfileSettings().getDesign();
-
-			handler.stopWarning(globalDesign, controller);
-		}
+		final ModernGlobalDesignHandler handler = modernDesign.global();
+		handler.stopWarning(controller);
 		controller.getView().setStyle("");
 	}
 }
diff --git a/PlayWall/src/main/scala/de/tobias/playpad/design/ModernCartDesignHandlerImpl.scala b/PlayWall/src/main/scala/de/tobias/playpad/design/ModernCartDesignHandlerImpl.scala
index b639f909..7d966d51 100644
--- a/PlayWall/src/main/scala/de/tobias/playpad/design/ModernCartDesignHandlerImpl.scala
+++ b/PlayWall/src/main/scala/de/tobias/playpad/design/ModernCartDesignHandlerImpl.scala
@@ -3,9 +3,8 @@ package de.tobias.playpad.design
 import de.thecodelabs.utils.application.ApplicationUtils
 import de.tobias.playpad.design.modern.model.{ModernCartDesign, ModernGlobalDesign}
 import de.tobias.playpad.design.modern.{ModernCartDesignHandler, ModernColor}
-import de.tobias.playpad.pad.content.play.Durationable
 import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController
-import de.tobias.playpad.util.Minifier
+import de.tobias.playpad.util.{FadeableColor, Minifier}
 import de.tobias.playpad.view.PseudoClasses
 import javafx.util.Duration
 import org.springframework.expression.ExpressionParser
@@ -18,11 +17,20 @@ import scala.jdk.CollectionConverters._
 class ModernCartDesignHandlerImpl extends ModernCartDesignHandler {
 
 	override def generateCss(design: ModernCartDesign, classSuffix: String, flat: Boolean): String = {
-		String.join(
-			generateCss(design, flat, classSuffix, design.getBackgroundColor),
-			generateCss(design, flat, classSuffix, design.getPlayColor, s":${PseudoClasses.PLAY_CLASS.getPseudoClassName}"),
+		var result = ""
+
+		if(design.isEnableCustomBackgroundColor)
+		{
+			result +=	generateCss(design, flat, classSuffix, design.getBackgroundColor)
 			generateCss(design, flat, classSuffix, design.getBackgroundColor, s":${PseudoClasses.WARN_CLASS.getPseudoClassName}")
-		)
+		}
+
+		if(design.isEnableCustomPlayColor)
+		{
+			result += generateCss(design, flat, classSuffix, design.getPlayColor, s":${PseudoClasses.PLAY_CLASS.getPseudoClassName}")
+		}
+
+		result
 	}
 
 	private def generateCss(design: ModernCartDesign, flat: Boolean, padIdentifier: String, color: ModernColor, styleState: String = ""): String = {
@@ -47,29 +55,13 @@ class ModernCartDesignHandlerImpl extends ModernCartDesignHandler {
 		expressionParser.parseExpression(string, new TemplateParserContext("${", "}")).getValue(context, classOf[String])
 	}
 
-	override def handleWarning(design: ModernCartDesign, controller: AbstractPadViewController, warning: Duration, globalDesign: ModernGlobalDesign): Unit = {
-		if (globalDesign.isWarnAnimation) {
-			val playColor = design.getPlayColor
-			val backgroundColor = design.getBackgroundColor
-
-			val fadeStopColor = if (globalDesign.isFlatDesign) backgroundColor.toFlatFadeableColor else backgroundColor.toFadeableColor
-			val fadePlayColor = if (globalDesign.isFlatDesign) playColor.toFlatFadeableColor else playColor.toFadeableColor
-
-			val pad = controller.getPad
-			val animationDuration = pad.getContent match {
-				case durationable: Durationable =>
-					if (warning greaterThan durationable.getDuration) {
-						durationable.getDuration
-					} else {
-						warning
-					}
-				case _ => warning
-			}
-			ModernDesignAnimator.animateWarn(controller, fadePlayColor, fadeStopColor, animationDuration)
+	override def performWarning(design: ModernGlobalDesign, fadeStartColor: FadeableColor, fadeStopColor: FadeableColor, controller: AbstractPadViewController, warningDuration: Duration): Unit = {
+		if(design.isWarnAnimation) {
+			ModernDesignAnimator.animateWarn(controller, fadeStartColor, fadeStopColor, warningDuration)
 		} else {
 			ModernDesignAnimator.warnFlash(controller)
 		}
 	}
 
-	override def stopWarning(design: ModernCartDesign, controller: AbstractPadViewController): Unit = ModernDesignAnimator.stopAnimation(controller)
+	override def stopWarning(controller: AbstractPadViewController): Unit = ModernDesignAnimator.stopAnimation(controller)
 }
diff --git a/PlayWall/src/main/scala/de/tobias/playpad/design/ModernGlobalDesignHandlerImpl.scala b/PlayWall/src/main/scala/de/tobias/playpad/design/ModernGlobalDesignHandlerImpl.scala
index 3eea45b7..ab88fb9b 100644
--- a/PlayWall/src/main/scala/de/tobias/playpad/design/ModernGlobalDesignHandlerImpl.scala
+++ b/PlayWall/src/main/scala/de/tobias/playpad/design/ModernGlobalDesignHandlerImpl.scala
@@ -7,7 +7,7 @@ import de.tobias.playpad.design.modern.{ModernColor, ModernGlobalDesignHandler}
 import de.tobias.playpad.pad.content.play.Durationable
 import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController
 import de.tobias.playpad.project.Project
-import de.tobias.playpad.util.Minifier
+import de.tobias.playpad.util.{FadeableColor, Minifier}
 import de.tobias.playpad.view.{ColorPickerView, PseudoClasses}
 import de.tobias.playpad.viewcontroller.main.IMainViewController
 import de.tobias.playpad.{DisplayableColor, PlayPadMain}
@@ -50,10 +50,8 @@ class ModernGlobalDesignHandlerImpl extends ModernGlobalDesignHandler with Color
 		project.getPage(controller.getPage).getPads.forEach(pad => {
 			val padSettings = pad.getPadSettings
 
-			if (padSettings.isCustomDesign) {
-				val cartDesign = padSettings.getDesign
-				stringBuilder.append(cartDesignHandler.generateCss(cartDesign, s"${pad.getPadIndex}", design.isFlatDesign))
-			}
+			val cartDesign = padSettings.getDesign
+			stringBuilder.append(cartDesignHandler.generateCss(cartDesign, s"${pad.getPadIndex}", design.isFlatDesign))
 		})
 		Files.write(customCss, stringBuilder.toString().getBytes())
 
@@ -92,32 +90,15 @@ class ModernGlobalDesignHandlerImpl extends ModernGlobalDesignHandler with Color
 		expressionParser.parseExpression(string, new TemplateParserContext("${", "}")).getValue(context, classOf[String])
 	}
 
-	override def handleWarning(design: ModernGlobalDesign, controller: AbstractPadViewController, warning: Duration): Unit = {
-		if (design.isWarnAnimation) {
-			warnAnimation(design, controller, warning)
+	override def performWarning(design: ModernGlobalDesign, fadeStartColor: FadeableColor, fadeStopColor: FadeableColor, controller: AbstractPadViewController, warningDuration: Duration): Unit = {
+		if(design.isWarnAnimation) {
+			ModernDesignAnimator.animateWarn(controller, fadeStartColor, fadeStopColor, warningDuration)
 		} else {
 			ModernDesignAnimator.warnFlash(controller)
 		}
 	}
 
-	private def warnAnimation(design: ModernGlobalDesign, controller: AbstractPadViewController, warning: Duration): Unit = {
-		val stopColor = if (design.isFlatDesign) design.getBackgroundColor.toFlatFadeableColor else design.getBackgroundColor.toFadeableColor
-		val playColor = if (design.isFlatDesign) design.getPlayColor.toFlatFadeableColor else design.getPlayColor.toFadeableColor
-
-		val pad = controller.getPad
-		val duration = pad.getContent match {
-			case durationable: Durationable =>
-				if (warning.greaterThan(durationable.getDuration)) {
-					durationable.getDuration
-				} else {
-					warning
-				}
-			case _ => warning
-		}
-		ModernDesignAnimator.animateWarn(controller, playColor, stopColor, duration)
-	}
-
-	override def stopWarning(design: ModernGlobalDesign, controller: AbstractPadViewController): Unit = ModernDesignAnimator.stopAnimation(controller)
+	override def stopWarning(controller: AbstractPadViewController): Unit = ModernDesignAnimator.stopAnimation(controller)
 
 	override def getColorInterface(onSelection: Consumer[DisplayableColor]) = new ColorPickerView(null, ModernColor.values.asInstanceOf[Array[DisplayableColor]], onSelection)
 
diff --git a/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernCartDesignHandler.java b/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernCartDesignHandler.java
index 200ead1f..a2eae3f8 100644
--- a/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernCartDesignHandler.java
+++ b/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernCartDesignHandler.java
@@ -1,20 +1,8 @@
 package de.tobias.playpad.design.modern;
 
 import de.tobias.playpad.design.modern.model.ModernCartDesign;
-import de.tobias.playpad.design.modern.model.ModernGlobalDesign;
-import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController;
-import javafx.util.Duration;
 
-public interface ModernCartDesignHandler {
+public interface ModernCartDesignHandler extends ModernDesignHandlerParent {
 
 	String generateCss(ModernCartDesign design, String classSuffix, boolean flat);
-
-	/*
-	 * Wird in einem neuen Thread aufgerufen
-	 */
-	void handleWarning(ModernCartDesign design, AbstractPadViewController controller, Duration warning, ModernGlobalDesign globalDesign);
-
-	default void stopWarning(ModernCartDesign design, AbstractPadViewController controller) {
-	}
-
 }
diff --git a/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernDesignHandlerParent.java b/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernDesignHandlerParent.java
new file mode 100644
index 00000000..223c02f7
--- /dev/null
+++ b/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernDesignHandlerParent.java
@@ -0,0 +1,54 @@
+package de.tobias.playpad.design.modern;
+
+import de.tobias.playpad.design.modern.model.ModernCartDesign;
+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.util.FadeableColor;
+import javafx.util.Duration;
+
+public interface ModernDesignHandlerParent
+{
+	default void handleWarning(ModernGlobalDesign globalDesign, ModernCartDesign cartDesign, AbstractPadViewController controller, Duration warningDuration)
+	{
+		ModernColor backgroundColor = globalDesign.getBackgroundColor();
+		ModernColor playColor = globalDesign.getPlayColor();
+
+		if(cartDesign.isEnableCustomBackgroundColor()) {
+			backgroundColor = cartDesign.getBackgroundColor();
+		}
+
+		if(cartDesign.isEnableCustomPlayColor()) {
+			playColor = cartDesign.getPlayColor();
+		}
+
+		final FadeableColor fadeStartColor = globalDesign.isFlatDesign() ? playColor.toFlatFadeableColor() : playColor.toFadeableColor();
+		final FadeableColor fadeStopColor = globalDesign.isFlatDesign() ? backgroundColor.toFlatFadeableColor() : backgroundColor.toFadeableColor();
+		final Duration duration = determineDuration(controller.getPad(), warningDuration);
+
+		performWarning(globalDesign, fadeStartColor, fadeStopColor, controller, duration);
+	}
+
+	default Duration determineDuration(Pad pad, Duration warningDuration)
+	{
+		if(pad.getContent() instanceof Durationable)
+		{
+			final Durationable durationable = (Durationable) pad;
+			if(warningDuration.greaterThan(durationable.getDuration()))
+			{
+				return durationable.getDuration();
+			}
+		}
+
+		return warningDuration;
+	}
+
+	/*
+	 * Wird in einem neuen Thread aufgerufen
+	 */
+	void performWarning(ModernGlobalDesign design, FadeableColor fadeStartColor, FadeableColor fadeStopColor, AbstractPadViewController controller, Duration duration);
+
+	default void stopWarning(AbstractPadViewController controller) {
+	}
+}
diff --git a/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernGlobalDesignHandler.java b/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernGlobalDesignHandler.java
index bca1e4aa..db2ed86b 100644
--- a/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernGlobalDesignHandler.java
+++ b/PlayWallCore/src/main/java/de/tobias/playpad/design/modern/ModernGlobalDesignHandler.java
@@ -1,23 +1,13 @@
 package de.tobias.playpad.design.modern;
 
 import de.tobias.playpad.design.modern.model.ModernGlobalDesign;
-import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController;
 import de.tobias.playpad.project.Project;
 import de.tobias.playpad.viewcontroller.main.IMainViewController;
 import javafx.stage.Stage;
-import javafx.util.Duration;
 
-public interface ModernGlobalDesignHandler {
+public interface ModernGlobalDesignHandler extends ModernDesignHandlerParent {
 
 	void applyStyleSheet(Stage stage);
 
 	void applyStyleSheetToMainViewController(ModernGlobalDesign design, IMainViewController controller, Stage stage, Project project);
-
-	/*
-	 * Wird in einem neuen Thread aufgerufen
-	 */
-	void handleWarning(ModernGlobalDesign design, AbstractPadViewController controller, Duration warning);
-
-	default void stopWarning(ModernGlobalDesign design, AbstractPadViewController controller) {
-	}
 }
diff --git a/PlayWallCore/src/main/java/de/tobias/playpad/pad/PadSettings.java b/PlayWallCore/src/main/java/de/tobias/playpad/pad/PadSettings.java
index db4b411e..3ca40f91 100644
--- a/PlayWallCore/src/main/java/de/tobias/playpad/pad/PadSettings.java
+++ b/PlayWallCore/src/main/java/de/tobias/playpad/pad/PadSettings.java
@@ -187,10 +187,6 @@ public class PadSettings {
 		return cueInProperty.get();
 	}
 
-	public boolean isCustomDesign() {
-		return customDesignProperty.get();
-	}
-
 	public void setCustomDesign(boolean customLayout) {
 		this.customDesignProperty.set(customLayout);
 	}
diff --git a/PlayWallCore/src/main/java/de/tobias/playpad/pad/PadSettingsSerializer.java b/PlayWallCore/src/main/java/de/tobias/playpad/pad/PadSettingsSerializer.java
index 73a2f13b..3af4771b 100644
--- a/PlayWallCore/src/main/java/de/tobias/playpad/pad/PadSettingsSerializer.java
+++ b/PlayWallCore/src/main/java/de/tobias/playpad/pad/PadSettingsSerializer.java
@@ -126,7 +126,6 @@ public class PadSettingsSerializer {
 		Element designElement = settingsElement.addElement(DESIGN_ELEMENT);
 		ModernCartDesignSerializer serializer = new ModernCartDesignSerializer();
 		serializer.save(designElement, padSettings.getDesign());
-		designElement.addAttribute(CUSTOM_DESIGN_ELEMENT, String.valueOf(padSettings.isCustomDesign()));
 
 		Element userInfoElement = settingsElement.addElement(CUSTOM_SETTINGS_ELEMENT);
 		for (String key : padSettings.getCustomSettings().keySet()) {
-- 
GitLab