From f20c4e73a05ae233a5026464872dabe32f11d8d3 Mon Sep 17 00:00:00 2001 From: Robinson Date: Fri, 3 Feb 2023 00:29:30 +0100 Subject: [PATCH] Cleaned logic --- src/dorkbox/notify/AppNotify.kt | 39 +++++++++++++---------------- src/dorkbox/notify/DesktopNotify.kt | 14 +++++------ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/dorkbox/notify/AppNotify.kt b/src/dorkbox/notify/AppNotify.kt index 9cd5cd5..0602633 100755 --- a/src/dorkbox/notify/AppNotify.kt +++ b/src/dorkbox/notify/AppNotify.kt @@ -15,10 +15,10 @@ */ package dorkbox.notify +import dorkbox.notify.LAFUtil.tweenEngine import dorkbox.tweenEngine.Tween import dorkbox.tweenEngine.TweenEquations import dorkbox.tweenEngine.TweenEvents -import dorkbox.util.SwingUtil import java.awt.Canvas import java.awt.Dimension import java.awt.Graphics @@ -148,7 +148,6 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp throw RuntimeException("Not able to add the notification to the window glassPane") } - // now we setup the rendering of the image refresh() } @@ -226,15 +225,16 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp override fun setupHide() { if (hideTween == null && notification.hideAfterDurationInMillis > 0) { // begin a timeline to get rid of the popup (default is 5 seconds) - hideTween = LAFUtil.tweenEngine.to(this, AppAccessor.PROGRESS, tweenAccessor, notification.hideAfterDurationInMillis / 1000.0f) + val tween = tweenEngine + .to(this, AppAccessor.PROGRESS, tweenAccessor, notification.hideAfterDurationInMillis / 1000.0f) .value(Notify.WIDTH.toFloat()) .ease(TweenEquations.Linear) .addCallback(TweenEvents.COMPLETE) { - SwingUtil.invokeLater { - notification.onClose() - } + notification.onClose() } - .start() + + hideTween = tween + tween.start() } } @@ -242,7 +242,7 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp if (moveTween != null) { moveTween!!.value(y) } else { - val tween = LAFUtil.tweenEngine + val tween = tweenEngine .to(this, AppAccessor.Y_POS, tweenAccessor, Notify.MOVE_DURATION) .value(y) .ease(TweenEquations.Linear) @@ -261,7 +261,7 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp shakeTween!!.valueRelative(targetX, targetY) .repeatAutoReverse(count, 0f) } else { - val tween = LAFUtil.tweenEngine + val tween = tweenEngine .to(this, AppAccessor.X_Y_POS, tweenAccessor, 0.05f) .valueRelative(targetX, targetY) .repeatAutoReverse(count, 0f) @@ -273,20 +273,17 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp } fun onClick(x: Int, y: Int) { - // this must happen in the Swing EDT. This is usually called by the active renderer - SwingUtil.invokeLater { - // Check - we were over the 'X' (and thus no notify), or was it in the general area? + // Check - we were over the 'X' (and thus no notify), or was it in the general area? - val isClickOnCloseButton = !notification.hideCloseButton && x >= 280 && y <= 20 + val isClickOnCloseButton = !notification.hideCloseButton && x >= 280 && y <= 20 - // reasonable position for detecting mouse over - if (!isClickOnCloseButton) { - // only call the general click handler IF we click in the general area! - notification.onClickAction() - } else { - // we always close the notification popup - notification.onClose() - } + // reasonable position for detecting mouse over + if (isClickOnCloseButton) { + // we always close the notification popup + notification.onClose() + } else { + // only call the general click handler IF we click in the general area! + notification.onClickAction() } } diff --git a/src/dorkbox/notify/DesktopNotify.kt b/src/dorkbox/notify/DesktopNotify.kt index 8dbc555..0bd8cd4 100755 --- a/src/dorkbox/notify/DesktopNotify.kt +++ b/src/dorkbox/notify/DesktopNotify.kt @@ -21,7 +21,6 @@ import dorkbox.tweenEngine.Tween import dorkbox.tweenEngine.TweenEquations import dorkbox.tweenEngine.TweenEvents import dorkbox.util.ScreenUtil -import dorkbox.util.SwingUtil import java.awt.Dimension import java.awt.Graphics import java.awt.MouseInfo @@ -142,15 +141,16 @@ internal class DesktopNotify(override val notification: Notify) : JWindow(), Not override fun setupHide() { if (hideTween == null && notification.hideAfterDurationInMillis > 0) { // begin a timeline to get rid of the popup (default is 5 seconds) - hideTween = tweenEngine.to(this, DesktopAccessor.PROGRESS, tweenAccessor, notification.hideAfterDurationInMillis / 1000.0f) + val tween = tweenEngine + .to(this, DesktopAccessor.PROGRESS, tweenAccessor, notification.hideAfterDurationInMillis / 1000.0f) .value(Notify.WIDTH.toFloat()) .ease(TweenEquations.Linear) .addCallback(TweenEvents.COMPLETE) { - SwingUtil.invokeLater { - notification.onClose() - } + notification.onClose() } - .start() + + hideTween = tween + tween.start() } } @@ -175,7 +175,7 @@ internal class DesktopNotify(override val notification: Notify) : JWindow(), Not override fun doShake(count: Int, targetX: Float, targetY: Float) { if (shakeTween != null) { shakeTween!!.valueRelative(targetX, targetY) - .repeatAutoReverse(count, 0f) + .repeatAutoReverse(count, 0f) } else { val tween = tweenEngine .to(this, DesktopAccessor.X_Y_POS, tweenAccessor, 0.05f)