2016-02-11 01:14:23 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2015 dorkbox, llc
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-07-28 22:07:01 +02:00
|
|
|
import java.awt.FlowLayout;
|
2017-09-17 16:29:46 +02:00
|
|
|
import java.awt.Image;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2017-07-28 22:07:01 +02:00
|
|
|
|
2017-09-17 16:29:46 +02:00
|
|
|
import javax.imageio.ImageIO;
|
2017-07-28 22:07:01 +02:00
|
|
|
import javax.swing.JButton;
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
2016-02-11 01:14:23 +01:00
|
|
|
import dorkbox.notify.Notify;
|
|
|
|
import dorkbox.notify.Pos;
|
2017-01-31 01:10:35 +01:00
|
|
|
import dorkbox.util.ActionHandler;
|
2017-09-17 16:29:46 +02:00
|
|
|
import dorkbox.util.ImageUtil;
|
|
|
|
import dorkbox.util.LocationResolver;
|
2017-07-28 22:07:01 +02:00
|
|
|
import dorkbox.util.ScreenUtil;
|
2016-02-11 01:14:23 +01:00
|
|
|
|
|
|
|
public
|
|
|
|
class NotifyTest {
|
|
|
|
|
|
|
|
public static
|
|
|
|
void main(String[] args) {
|
|
|
|
Notify notify;
|
|
|
|
|
2017-07-28 22:07:01 +02:00
|
|
|
|
|
|
|
JFrame frame = new JFrame("Test");
|
|
|
|
|
|
|
|
JPanel panel = new JPanel();
|
|
|
|
panel.setLayout(new FlowLayout());
|
|
|
|
|
|
|
|
JLabel label = new JLabel("This is a label!");
|
|
|
|
|
|
|
|
JButton button = new JButton();
|
|
|
|
button.setText("Press me");
|
|
|
|
|
|
|
|
panel.add(label);
|
|
|
|
panel.add(button);
|
|
|
|
|
|
|
|
frame.add(panel);
|
2017-09-17 14:32:52 +02:00
|
|
|
frame.setSize(900, 600);
|
2017-07-28 22:07:01 +02:00
|
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
frame.setVisible(true);
|
|
|
|
|
|
|
|
ScreenUtil.showOnSameScreenAsMouse_Center(frame);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int count = 2;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
final int finalI = i;
|
|
|
|
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)
|
2017-08-23 11:08:22 +02:00
|
|
|
.position(Pos.BOTTOM_RIGHT)
|
|
|
|
// .position(Pos.CENTER)
|
2017-07-28 22:07:01 +02:00
|
|
|
// .setScreen(0)
|
|
|
|
.darkStyle()
|
|
|
|
// .shake(1300, 4)
|
2017-09-17 14:32:52 +02:00
|
|
|
.shake(1300, 10)
|
2017-07-28 22:07:01 +02:00
|
|
|
.attach(frame)
|
|
|
|
.hideCloseButton()
|
|
|
|
.onAction(new ActionHandler<Notify>() {
|
|
|
|
@Override
|
|
|
|
public
|
|
|
|
void handle(final Notify arg0) {
|
|
|
|
System.err.println("Notification " + finalI + " clicked on!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
notify.showWarning();
|
|
|
|
|
2017-09-17 14:32:52 +02:00
|
|
|
// try {
|
|
|
|
// Thread.sleep(1000);
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
final int finalI = i;
|
|
|
|
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)
|
|
|
|
.position(Pos.TOP_LEFT)
|
|
|
|
// .position(Pos.CENTER)
|
|
|
|
// .setScreen(0)
|
|
|
|
// .darkStyle()
|
|
|
|
// .shake(1300, 4)
|
|
|
|
// .shake(1300, 10)
|
|
|
|
.attach(frame)
|
|
|
|
// .hideCloseButton()
|
|
|
|
.onAction(new ActionHandler<Notify>() {
|
|
|
|
@Override
|
|
|
|
public
|
|
|
|
void handle(final Notify arg0) {
|
|
|
|
System.err.println("Notification " + finalI + " clicked on!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
notify.showWarning();
|
|
|
|
|
2017-07-28 22:07:01 +02:00
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 01:14:23 +01:00
|
|
|
|
2017-09-17 14:32:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-11 01:14:23 +01:00
|
|
|
for (int i = 0; i < count; i++) {
|
2017-07-28 22:07:01 +02:00
|
|
|
final int finalI = i;
|
2016-02-11 01:14:23 +01:00
|
|
|
notify = Notify.create()
|
|
|
|
.title("Notify title " + i)
|
2017-01-31 01:10:35 +01:00
|
|
|
.text("This is a notification " + i + " popup message This is a notification popup message This is a " +
|
|
|
|
"notification popup message")
|
2017-08-23 11:08:22 +02:00
|
|
|
.hideAfter(3000)
|
2016-02-11 01:14:23 +01:00
|
|
|
.position(Pos.TOP_RIGHT)
|
|
|
|
// .setScreen(0)
|
|
|
|
.darkStyle()
|
2017-07-28 22:07:01 +02:00
|
|
|
// .shake(1300, 4)
|
2017-09-17 14:32:52 +02:00
|
|
|
.shake(1300, 10)
|
2017-07-28 22:07:01 +02:00
|
|
|
.hideCloseButton()
|
2016-02-11 01:14:23 +01:00
|
|
|
.onAction(new ActionHandler<Notify>() {
|
2017-07-28 22:07:01 +02:00
|
|
|
@Override
|
|
|
|
public
|
|
|
|
void handle(final Notify arg0) {
|
|
|
|
System.err.println("Notification " + finalI + " clicked on!");
|
|
|
|
}
|
|
|
|
});
|
2017-09-17 16:29:46 +02:00
|
|
|
notify.show();
|
2017-07-28 22:07:01 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 16:29:46 +02:00
|
|
|
InputStream resourceAsStream = LocationResolver.getResourceAsStream("notify-dark.png");
|
|
|
|
Image image = null;
|
|
|
|
try {
|
|
|
|
image = ImageUtil.getImageImmediate(ImageIO.read(resourceAsStream));
|
|
|
|
// image = image.getScaledInstance(144, 104, Image.SCALE_SMOOTH);
|
2017-09-17 21:05:31 +02:00
|
|
|
// image = image.getScaledInstance(104, 144, Image.SCALE_SMOOTH);
|
|
|
|
image = image.getScaledInstance(144, 144, Image.SCALE_SMOOTH);
|
2017-09-17 16:29:46 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-28 22:07:01 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
final int finalI = i;
|
|
|
|
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")
|
2017-09-17 14:32:52 +02:00
|
|
|
// .hideAfter(13000)
|
2017-07-28 22:07:01 +02:00
|
|
|
.position(Pos.BOTTOM_LEFT)
|
|
|
|
// .setScreen(0)
|
2017-09-03 17:34:09 +02:00
|
|
|
// .darkStyle()
|
2017-07-28 22:07:01 +02:00
|
|
|
// .shake(1300, 4)
|
|
|
|
// .shake(1300, 10)
|
2017-09-17 14:32:52 +02:00
|
|
|
// .hideCloseButton()
|
2017-07-28 22:07:01 +02:00
|
|
|
.onAction(new ActionHandler<Notify>() {
|
|
|
|
@Override
|
|
|
|
public
|
|
|
|
void handle(final Notify arg0) {
|
|
|
|
System.err.println("Notification " + finalI + " clicked on!");
|
|
|
|
}
|
|
|
|
});
|
2017-09-17 16:29:46 +02:00
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
notify.image(image);
|
|
|
|
notify.show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notify.showConfirm();
|
|
|
|
}
|
2017-07-28 22:07:01 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-02-11 01:14:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|