From da885fd5f2e03d59e77bdefeaf72373b562df209 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 26 Sep 2016 16:16:33 +0800 Subject: [PATCH] Make sure that notification boundaries don't exceed screen bounds --- .../ui/notification/NotificationWindow.java | 32 +++---------------- .../notification/QueueNotificationLayout.java | 11 ++++--- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/source/net/filebot/util/ui/notification/NotificationWindow.java b/source/net/filebot/util/ui/notification/NotificationWindow.java index b520757c..8c558ea6 100644 --- a/source/net/filebot/util/ui/notification/NotificationWindow.java +++ b/source/net/filebot/util/ui/notification/NotificationWindow.java @@ -4,31 +4,25 @@ package net.filebot.util.ui.notification; +import static net.filebot.util.ui.SwingUI.*; import java.awt.Window; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.awt.event.WindowEvent; import javax.swing.JWindow; import javax.swing.Timer; -import net.filebot.util.ui.SwingUI; - - public class NotificationWindow extends JWindow { private final int timeout; - public NotificationWindow(Window owner, int timeout) { this(owner, timeout, true); } - public NotificationWindow(Window owner, int timeout, boolean closeOnClick) { super(owner); this.timeout = timeout; @@ -36,21 +30,19 @@ public class NotificationWindow extends JWindow { setAlwaysOnTop(true); if (closeOnClick) { - getGlassPane().addMouseListener(clickListener); + getGlassPane().addMouseListener(mouseClicked(evt -> close())); getGlassPane().setVisible(true); } addComponentListener(closeOnTimeout); } - public NotificationWindow(Window owner) { this(owner, -1); } - public final void close() { - SwingUI.checkEventDispatchThread(); + checkEventDispatchThread(); // window events are not fired automatically, required for layout updates processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); @@ -67,21 +59,13 @@ public class NotificationWindow extends JWindow { private Timer timer = null; - @Override public void componentShown(ComponentEvent e) { if (timeout >= 0) { - timer = SwingUI.invokeLater(timeout, new Runnable() { - - @Override - public void run() { - close(); - } - }); + timer = invokeLater(timeout, () -> close()); } } - @Override public void componentHidden(ComponentEvent e) { if (timer != null) { @@ -91,12 +75,4 @@ public class NotificationWindow extends JWindow { }; - private final MouseAdapter clickListener = new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent e) { - close(); - } - }; - } diff --git a/source/net/filebot/util/ui/notification/QueueNotificationLayout.java b/source/net/filebot/util/ui/notification/QueueNotificationLayout.java index 1a4a92cd..c10367a3 100644 --- a/source/net/filebot/util/ui/notification/QueueNotificationLayout.java +++ b/source/net/filebot/util/ui/notification/QueueNotificationLayout.java @@ -84,21 +84,24 @@ public class QueueNotificationLayout implements NotificationLayout { // avoid flickering by moving windows in reverse order Point anchor = getBaseAnchor(screen, insets); - align(anchor, notifications.iterator()); + align(anchor, screen, notifications.iterator()); } - private void align(Point anchor, Iterator seq) { + private void align(Point anchor, Dimension screen, Iterator seq) { if (!seq.hasNext()) { return; } NotificationWindow window = seq.next(); + Dimension size = window.getSize(); + size.width = Math.min(size.width, (int) (screen.width * 0.8)); + size.height = Math.min(size.height, (int) (screen.height * 0.2)); Point p = getLocation(anchor, size); - align(getNextAnchor(anchor, size), seq); + align(getNextAnchor(anchor, size), screen, seq); - window.setLocation(p); + window.setBounds(p.x, p.y, size.width, size.height); } @Override