From 6c5493944e09ef40b00aa4b436adf684cfe56904 Mon Sep 17 00:00:00 2001 From: Robinson Date: Fri, 3 Feb 2023 00:17:00 +0100 Subject: [PATCH] Removed unnecessary placement logic --- src/dorkbox/notify/AppComponentListener.kt | 18 ------ src/dorkbox/notify/AppNotify.kt | 58 -------------------- src/dorkbox/notify/AppWindowStateListener.kt | 14 ----- 3 files changed, 90 deletions(-) delete mode 100644 src/dorkbox/notify/AppComponentListener.kt delete mode 100644 src/dorkbox/notify/AppWindowStateListener.kt diff --git a/src/dorkbox/notify/AppComponentListener.kt b/src/dorkbox/notify/AppComponentListener.kt deleted file mode 100644 index d8ac3f0..0000000 --- a/src/dorkbox/notify/AppComponentListener.kt +++ /dev/null @@ -1,18 +0,0 @@ -package dorkbox.notify - -import java.awt.event.ComponentEvent -import java.awt.event.ComponentListener - -internal class AppComponentListener(val notify: AppNotify) : ComponentListener { - override fun componentShown(e: ComponentEvent) { - notify.reLayout() - } - - override fun componentHidden(e: ComponentEvent) {} - - override fun componentResized(e: ComponentEvent) { - notify.reLayout() - } - - override fun componentMoved(e: ComponentEvent) {} -} diff --git a/src/dorkbox/notify/AppNotify.kt b/src/dorkbox/notify/AppNotify.kt index 43bcb1c..9cd5cd5 100755 --- a/src/dorkbox/notify/AppNotify.kt +++ b/src/dorkbox/notify/AppNotify.kt @@ -97,11 +97,6 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp private val parent = notification.attachedFrame!! private var glassPane: JPanel - // this makes sure that our notify canvas stay anchored to the parent window (if it's hidden/shown/moved/etc) - private val parentListener = AppComponentListener(this) - private val windowStateListener = AppWindowStateListener(this) - - // this is on the swing EDT init { val actualSize = Dimension(Notify.WIDTH, Notify.HEIGHT) @@ -124,9 +119,6 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp anchorX = getAnchorX(notification.position, parent.bounds) anchorY = getAnchorY(notification.position, parent.bounds) - parent.addWindowStateListener(windowStateListener) - parent.addComponentListener(parentListener) - val pane = parent.glassPane if (pane is JPanel) { glassPane = pane @@ -169,43 +161,6 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp return super.getY() } - - // when the parent window moves, we stop all animation and snap the popup into place. This simplifies logic greatly - fun reLayout() { - val bounds = parent.bounds - anchorX = getAnchorX(notification.position, bounds) - anchorY = getAnchorY(notification.position, bounds) -// -// val growDown = growDown(this) -// -// if (tween != null) { -// tween!!.cancel() // cancel does its thing on the next tick of animation cycle -// tween = null -// } -// -// -// var changedY: Int -// if (popupIndex == 0) { -// changedY = anchorY -// } else { -// synchronized(popups) { -// val id = idAndPosition -// val looks = popups[id] -// changedY = if (looks != null) { -// if (growDown) { -// anchorY + popupIndex * (NotifyCanvas.HEIGHT + SPACER) -// } else { -// anchorY - popupIndex * (NotifyCanvas.HEIGHT + SPACER) -// } -// } else { -// anchorY -// } -// } -// } -// -// setLocation(anchorX, changedY) - } - override fun refresh() { cachedImage = renderBackgroundInfo(notification.title, notification.text, notification.theme, notification.image) cachedClose = renderCloseButton(notification.theme, false) @@ -213,14 +168,6 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp idAndPosition = parent.name + ":" + notification.position - val growDown = LAFUtil.growDown(this) - - val offset = if (growDown) { - Notify.MARGIN - } else { - -Notify.MARGIN - } - anchorX = getAnchorX(notification.position, parent.bounds) anchorY = getAnchorY(notification.position, parent.bounds) } @@ -232,8 +179,6 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp try { g.drawImage(cachedImage, 0, 0, null) -// println("$mouseX, $mouseY") - if (mouseOver && mouseX >= 280 && mouseY <= 20) { g.drawImage(cachedCloseEnabled, 0, 0, null) } else { @@ -369,9 +314,6 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp glassPane.remove(this) - parent.removeWindowStateListener(windowStateListener) - parent.removeComponentListener(parentListener) - removeMouseMotionListener(mouseListener) removeMouseListener(mouseListener) diff --git a/src/dorkbox/notify/AppWindowStateListener.kt b/src/dorkbox/notify/AppWindowStateListener.kt deleted file mode 100644 index 8330d74..0000000 --- a/src/dorkbox/notify/AppWindowStateListener.kt +++ /dev/null @@ -1,14 +0,0 @@ -package dorkbox.notify - -import java.awt.Frame -import java.awt.event.WindowEvent -import java.awt.event.WindowStateListener - -internal class AppWindowStateListener(val notify: AppNotify): WindowStateListener { - override fun windowStateChanged(e: WindowEvent) { - val state = e.newState - if (state and Frame.ICONIFIED == 0) { - notify.reLayout() - } - } -}