Skip to content
Snippets Groups Projects
Commit 0c272170 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Cleanup pad warning methods

parent d881417d
No related branches found
No related tags found
No related merge requests found
package de.tobias.playpad.design; package de.tobias.playpad.design;
import de.tobias.playpad.pad.view.IPadView; 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.util.FadeableColor;
import de.tobias.playpad.view.PseudoClasses; import de.tobias.playpad.view.PseudoClasses;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
...@@ -17,22 +17,21 @@ import java.util.HashMap; ...@@ -17,22 +17,21 @@ import java.util.HashMap;
public class ModernDesignAnimator { public class ModernDesignAnimator {
// alles nur static, neine objecte von der Klasse
private ModernDesignAnimator() { 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<>(); ObjectProperty<FadeableColor> backgroundColor = new SimpleObjectProperty<>();
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(0), new KeyValue(backgroundColor, startColor)), Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(0), new KeyValue(backgroundColor, startColor)),
new KeyFrame(duration, new KeyValue(backgroundColor, endColor))); 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<>(); ObjectProperty<FadeableColor> backgroundColor = new SimpleObjectProperty<>();
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(0), new KeyValue(backgroundColor, startColor)), Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(0), new KeyValue(backgroundColor, startColor)),
...@@ -42,17 +41,17 @@ public class ModernDesignAnimator { ...@@ -42,17 +41,17 @@ public class ModernDesignAnimator {
timeline.setAutoReverse(true); timeline.setAutoReverse(true);
timeline.setCycleCount((int) (duration.toSeconds() / 0.625)); 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) { private static void animate(IPad pad, IPadView padView, Timeline timeline, ObjectProperty<FadeableColor> objectProperty) {
int index = padViewController.getPad().getPosition(); int index = pad.getPosition();
if (timelines.containsKey(index)) { if (timelines.containsKey(index)) {
timelines.get(index).stop(); 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); objectProperty.addListener(fadeListener);
timeline.playFromStart(); timeline.playFromStart();
...@@ -60,7 +59,7 @@ public class ModernDesignAnimator { ...@@ -60,7 +59,7 @@ public class ModernDesignAnimator {
timeline.setOnFinished(event -> timeline.setOnFinished(event ->
{ {
objectProperty.removeListener(fadeListener); objectProperty.removeListener(fadeListener);
padViewController.getView().setStyle(""); padView.setStyle("");
timelines.remove(index); timelines.remove(index);
}); });
...@@ -68,16 +67,15 @@ public class ModernDesignAnimator { ...@@ -68,16 +67,15 @@ public class ModernDesignAnimator {
timelines.put(index, timeline); timelines.put(index, timeline);
} }
public static void stopAnimation(AbstractPadViewController controller) { public static void stopAnimation(IPad pad) {
int index = controller.getPad().getPosition(); int index = pad.getPosition();
if (timelines.containsKey(index)) { if (timelines.containsKey(index)) {
timelines.get(index).stop(); timelines.get(index).stop();
} }
} }
public static void warnFlash(AbstractPadViewController controller) { public static void warnFlash(IPadView view) {
final IPadView view = controller.getView();
try { try {
while (!Thread.interrupted()) { while (!Thread.interrupted()) {
......
...@@ -133,7 +133,7 @@ public class PadPositionListener implements Runnable, IPadPositionListener { ...@@ -133,7 +133,7 @@ public class PadPositionListener implements Runnable, IPadPositionListener {
final ModernDesignProvider modernDesign = PlayPadMain.getProgramInstance().getModernDesign(); final ModernDesignProvider modernDesign = PlayPadMain.getProgramInstance().getModernDesign();
final ModernWarningDesignHandler handler = modernDesign.warning(); final ModernWarningDesignHandler handler = modernDesign.warning();
handler.stopWarning(controller); handler.stopWarning(controller.getPad());
controller.getView().setStyle(""); controller.getView().setStyle("");
} }
} }
...@@ -3,6 +3,7 @@ package de.tobias.playpad.design ...@@ -3,6 +3,7 @@ package de.tobias.playpad.design
import de.tobias.playpad.design.modern.ModernWarningDesignHandler import de.tobias.playpad.design.modern.ModernWarningDesignHandler
import de.tobias.playpad.design.modern.model.ModernGlobalDesign import de.tobias.playpad.design.modern.model.ModernGlobalDesign
import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController
import de.tobias.playpad.project.api.IPad
import de.tobias.playpad.util.FadeableColor import de.tobias.playpad.util.FadeableColor
import javafx.util.Duration import javafx.util.Duration
...@@ -10,11 +11,11 @@ class ModernWarningDesignHandlerImpl extends ModernWarningDesignHandler { ...@@ -10,11 +11,11 @@ class ModernWarningDesignHandlerImpl extends ModernWarningDesignHandler {
override def performWarning(design: ModernGlobalDesign, fadeStartColor: FadeableColor, fadeStopColor: FadeableColor, controller: AbstractPadViewController, warningDuration: Duration): Unit = { override def performWarning(design: ModernGlobalDesign, fadeStartColor: FadeableColor, fadeStopColor: FadeableColor, controller: AbstractPadViewController, warningDuration: Duration): Unit = {
if (design.isWarnAnimation) { if (design.isWarnAnimation) {
ModernDesignAnimator.animateWarn(controller, fadeStartColor, fadeStopColor, warningDuration) ModernDesignAnimator.animateWarn(controller.getPad, controller.getView, fadeStartColor, fadeStopColor, warningDuration)
} else { } 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)
} }
...@@ -5,6 +5,7 @@ import de.tobias.playpad.design.modern.model.ModernGlobalDesign; ...@@ -5,6 +5,7 @@ import de.tobias.playpad.design.modern.model.ModernGlobalDesign;
import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.Pad;
import de.tobias.playpad.pad.content.play.Durationable; import de.tobias.playpad.pad.content.play.Durationable;
import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController; import de.tobias.playpad.pad.viewcontroller.AbstractPadViewController;
import de.tobias.playpad.project.api.IPad;
import de.tobias.playpad.util.FadeableColor; import de.tobias.playpad.util.FadeableColor;
import javafx.util.Duration; import javafx.util.Duration;
...@@ -45,6 +46,6 @@ public interface ModernWarningDesignHandler { ...@@ -45,6 +46,6 @@ public interface ModernWarningDesignHandler {
*/ */
void performWarning(ModernGlobalDesign design, FadeableColor fadeStartColor, FadeableColor fadeStopColor, AbstractPadViewController controller, Duration duration); void performWarning(ModernGlobalDesign design, FadeableColor fadeStartColor, FadeableColor fadeStopColor, AbstractPadViewController controller, Duration duration);
default void stopWarning(AbstractPadViewController controller) { default void stopWarning(IPad pad) {
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment