Removed unnecessary placement logic

This commit is contained in:
Robinson 2023-02-03 00:17:00 +01:00
parent bbde9ceb3d
commit 6c5493944e
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
3 changed files with 0 additions and 90 deletions

View File

@ -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) {}
}

View File

@ -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)

View File

@ -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()
}
}
}