2023-01-27 21:32:25 +01:00
|
|
|
@file:Suppress("UNUSED_VALUE")
|
|
|
|
|
2023-01-27 02:15:05 +01:00
|
|
|
package dorkbox.notify
|
|
|
|
|
|
|
|
import dorkbox.util.ImageUtil
|
|
|
|
import dorkbox.util.LocationResolver
|
|
|
|
import dorkbox.util.ScreenUtil
|
|
|
|
import java.awt.FlowLayout
|
|
|
|
import java.awt.Image
|
|
|
|
import java.io.IOException
|
|
|
|
import javax.imageio.ImageIO
|
|
|
|
import javax.swing.JButton
|
|
|
|
import javax.swing.JFrame
|
|
|
|
import javax.swing.JLabel
|
|
|
|
import javax.swing.JPanel
|
|
|
|
|
|
|
|
object NotifyTest {
|
|
|
|
@JvmStatic
|
|
|
|
fun main(args: Array<String>) {
|
|
|
|
val frame = JFrame("Test")
|
|
|
|
val panel = JPanel()
|
|
|
|
panel.layout = FlowLayout()
|
|
|
|
val label = JLabel("This is a label!")
|
|
|
|
val button = JButton()
|
|
|
|
button.text = "Press me"
|
|
|
|
button.addActionListener { println("Clicked button!") }
|
|
|
|
|
|
|
|
panel.add(label)
|
|
|
|
panel.add(button)
|
|
|
|
frame.add(panel)
|
|
|
|
frame.setSize(900, 600)
|
|
|
|
frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
|
|
|
|
frame.isVisible = true
|
|
|
|
|
|
|
|
ScreenUtil.showOnSameScreenAsMouse_Center(frame)
|
|
|
|
|
|
|
|
// The purpose of this, is to display this image AS A SQUARE!
|
|
|
|
val resourceAsStream = LocationResolver.getResourceAsStream("notify-dark.png")
|
|
|
|
var image: Image? = null
|
|
|
|
try {
|
|
|
|
image = ImageIO.read(resourceAsStream)
|
|
|
|
ImageUtil.waitForImageLoad(image)
|
|
|
|
|
|
|
|
// image = image.getScaledInstance(144, 104, Image.SCALE_SMOOTH);
|
|
|
|
// image = image.getScaledInstance(104, 144, Image.SCALE_SMOOTH);
|
|
|
|
image = image.getScaledInstance(144, 144, Image.SCALE_SMOOTH)
|
|
|
|
} catch (e: IOException) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
|
|
|
|
2023-02-03 00:05:10 +01:00
|
|
|
image!!
|
2023-01-27 02:15:05 +01:00
|
|
|
|
2023-02-03 12:22:39 +01:00
|
|
|
// bottomRightInFrame(3, frame)
|
|
|
|
// topLeftInFrame(2, frame)
|
2023-02-03 00:05:10 +01:00
|
|
|
|
2023-02-03 12:22:39 +01:00
|
|
|
// react()
|
|
|
|
topRightMonitor(4)
|
2023-02-03 00:05:10 +01:00
|
|
|
// topAndBottomRightMonitor(1)
|
|
|
|
// bottomLeftScaled(image)
|
|
|
|
// bottomLeftStacking(3, image)
|
2023-01-27 02:15:05 +01:00
|
|
|
}
|
|
|
|
|
2023-01-27 21:32:25 +01:00
|
|
|
fun react() {
|
|
|
|
val notify = Notify.create()
|
|
|
|
notify.title("Notify title modify")
|
|
|
|
.text("This is a notification popup message This is a notification popup message This is a " +
|
|
|
|
"notification popup message")
|
|
|
|
.hideAfter(13000)
|
|
|
|
.position(Position.TOP_RIGHT)
|
|
|
|
// .setScreen(0)
|
|
|
|
.theme(Theme.defaultDark)
|
|
|
|
// .shake(1300, 4)
|
|
|
|
.shake(4300, 10)
|
|
|
|
// .hideCloseButton() // if the hideButton is visible, then it's possible to change things when clicked
|
|
|
|
.onClickAction {
|
2023-01-28 21:15:19 +01:00
|
|
|
text = "HOWDY"
|
2023-01-27 21:32:25 +01:00
|
|
|
System.err.println("Notification clicked on!")
|
|
|
|
}
|
|
|
|
notify.show()
|
|
|
|
try {
|
|
|
|
Thread.sleep(3000)
|
|
|
|
} catch (e: InterruptedException) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-28 21:15:19 +01:00
|
|
|
private fun topRightMonitor(count: Int) {
|
2023-01-27 02:15:05 +01:00
|
|
|
for (i in 0 until count) {
|
2023-02-03 00:05:10 +01:00
|
|
|
var notify = Notify.create()
|
2023-01-27 02:15:05 +01:00
|
|
|
.title("Notify title $i")
|
|
|
|
.text("This is a notification " + i + " popup message This is a notification popup message This is a " +
|
|
|
|
"notification popup message")
|
2023-01-27 21:32:25 +01:00
|
|
|
.position(Position.TOP_RIGHT)
|
2023-01-27 02:15:05 +01:00
|
|
|
// .setScreen(0)
|
2023-01-28 21:15:19 +01:00
|
|
|
.theme(Theme.defaultDark)
|
2023-01-27 02:15:05 +01:00
|
|
|
// .shake(1300, 4)
|
2023-02-03 12:22:39 +01:00
|
|
|
// .shake(18300, 10)
|
2023-01-28 21:15:19 +01:00
|
|
|
// .hideCloseButton()
|
2023-01-27 21:32:25 +01:00
|
|
|
.onClickAction { System.err.println("Notification $i clicked on!") }
|
2023-02-03 12:22:39 +01:00
|
|
|
// if (i == 0) {
|
2023-02-03 00:05:10 +01:00
|
|
|
notify.hideAfter(2100)
|
2023-02-03 12:22:39 +01:00
|
|
|
// }
|
2023-01-27 02:15:05 +01:00
|
|
|
notify.show()
|
2023-02-03 00:05:10 +01:00
|
|
|
try {
|
|
|
|
Thread.sleep(1000)
|
|
|
|
} catch (e: InterruptedException) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun topAndBottomRightMonitor(count: Int) {
|
|
|
|
for (i in 0 until count) {
|
|
|
|
Notify.create()
|
|
|
|
.title("Notify title $i")
|
|
|
|
.text("This is a notification " + i + " top popup message This is a notification popup message This is a " +
|
|
|
|
"notification popup message")
|
|
|
|
.hideAfter(4300)
|
|
|
|
.position(Position.TOP_RIGHT)
|
|
|
|
// .setScreen(0)
|
|
|
|
.theme(Theme.defaultDark)
|
|
|
|
// .shake(1300, 4)
|
|
|
|
// .shake(4300, 10)
|
|
|
|
// .hideCloseButton()
|
|
|
|
.onClickAction { System.err.println("Notification $i clicked on!") }
|
|
|
|
.show()
|
|
|
|
|
|
|
|
Notify.create()
|
|
|
|
.title("Notify title $i")
|
|
|
|
.text("This is a notification " + i + " bottom popup message This is a notification popup message This is a " +
|
|
|
|
"notification popup message")
|
|
|
|
.hideAfter(4300)
|
|
|
|
.position(Position.BOTTOM_RIGHT)
|
|
|
|
// .setScreen(0)
|
|
|
|
.theme(Theme.defaultDark)
|
|
|
|
// .shake(1300, 4)
|
|
|
|
// .shake(4300, 10)
|
|
|
|
// .hideCloseButton()
|
|
|
|
.onClickAction { System.err.println("Notification $i clicked on!") }
|
|
|
|
.show()
|
2023-01-27 02:15:05 +01:00
|
|
|
try {
|
2023-01-28 21:15:19 +01:00
|
|
|
Thread.sleep(2000)
|
2023-01-27 02:15:05 +01:00
|
|
|
} catch (e: InterruptedException) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun bottomLeftScaled(image: Image) {
|
|
|
|
val notify = Notify.create()
|
|
|
|
.title("Notify scaled")
|
|
|
|
.text("This is a notification popup message scaled This is a notification popup message This is a " +
|
|
|
|
"notification popup message scaled ") // .hideAfter(13000)
|
2023-01-27 21:32:25 +01:00
|
|
|
.position(Position.BOTTOM_LEFT) // .setScreen(0)
|
2023-01-27 02:15:05 +01:00
|
|
|
// .darkStyle()
|
|
|
|
// .shake(1300, 4)
|
|
|
|
// .shake(1300, 10)
|
|
|
|
// .hideCloseButton()
|
2023-01-27 21:32:25 +01:00
|
|
|
.onClickAction { System.err.println("Notification scaled clicked on!") }
|
2023-01-27 02:15:05 +01:00
|
|
|
notify.image(image)
|
|
|
|
notify.show()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun bottomLeftStacking(count: Int, image: Image) {
|
|
|
|
var notify: Notify
|
|
|
|
|
|
|
|
for (i in 0 until count) {
|
|
|
|
notify = Notify.create()
|
|
|
|
.title("Notify title $i")
|
|
|
|
.text("This is a notification " + i + " popup message This is a notification popup message This is a " +
|
|
|
|
"notification popup message")
|
|
|
|
// .hideAfter(13000)
|
2023-01-27 21:32:25 +01:00
|
|
|
.position(Position.BOTTOM_LEFT)
|
2023-01-27 02:15:05 +01:00
|
|
|
// .setScreen(0)
|
|
|
|
// .darkStyle()
|
|
|
|
// .shake(1300, 4)
|
|
|
|
// .shake(1300, 10)
|
|
|
|
// .hideCloseButton()
|
2023-01-27 21:32:25 +01:00
|
|
|
.onClickAction { System.err.println("Notification $i clicked on!") }
|
2023-01-27 02:15:05 +01:00
|
|
|
if (i == 0) {
|
|
|
|
notify.image(image)
|
|
|
|
notify.show()
|
|
|
|
} else {
|
|
|
|
notify.showConfirm()
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000)
|
|
|
|
} catch (e: InterruptedException) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun topLeftInFrame(count: Int, frame: JFrame) {
|
|
|
|
var notify: Notify
|
|
|
|
for (i in 0 until count) {
|
|
|
|
notify = Notify.create()
|
|
|
|
.title("Notify title $i")
|
|
|
|
.text("This is a notification " + i + " popup message This is a notification popup message This is a " +
|
|
|
|
"notification popup message")
|
|
|
|
.hideAfter(13000)
|
2023-01-27 21:32:25 +01:00
|
|
|
.position(Position.TOP_LEFT) // .position(Pos.CENTER)
|
2023-01-27 02:15:05 +01:00
|
|
|
// .setScreen(0)
|
|
|
|
// .darkStyle()
|
|
|
|
// .shake(1300, 4)
|
|
|
|
// .shake(1300, 10)
|
|
|
|
.attach(frame) // .hideCloseButton()
|
2023-01-27 21:32:25 +01:00
|
|
|
.onClickAction { System.err.println("Notification $i clicked on!") }
|
2023-01-27 02:15:05 +01:00
|
|
|
notify.showWarning()
|
|
|
|
|
|
|
|
try {
|
|
|
|
Thread.sleep(3000)
|
|
|
|
} catch (e: InterruptedException) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun bottomRightInFrame(count: Int, frame: JFrame) {
|
|
|
|
var notify: Notify
|
|
|
|
for (i in 0 until count) {
|
|
|
|
notify = Notify.create()
|
|
|
|
.title("Notify title $i")
|
|
|
|
.text("This is a notification " + i + " popup message This is a notification popup message This is a " +
|
|
|
|
"notification popup message")
|
2023-02-03 00:05:10 +01:00
|
|
|
// .hideAfter(13000)
|
|
|
|
.position(Position.BOTTOM_RIGHT)
|
|
|
|
// .position(Pos.CENTER)
|
2023-01-27 02:15:05 +01:00
|
|
|
// .setScreen(0)
|
2023-01-27 21:32:25 +01:00
|
|
|
.theme(Theme.defaultDark)
|
|
|
|
// .shake(1300, 4)
|
2023-02-03 12:22:39 +01:00
|
|
|
.shake(13200, 10)
|
2023-01-27 02:15:05 +01:00
|
|
|
.attach(frame)
|
2023-02-03 00:05:10 +01:00
|
|
|
// .hideCloseButton()
|
2023-01-27 21:32:25 +01:00
|
|
|
.onClickAction { System.err.println("Notification $i clicked on!") }
|
2023-01-27 02:15:05 +01:00
|
|
|
notify.showWarning()
|
|
|
|
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000)
|
|
|
|
} catch (e: InterruptedException) {
|
|
|
|
e.printStackTrace()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|