mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 16:58:51 -05:00
Avoid notification flickering by moving windows in reverse order
This commit is contained in:
parent
d53dd1ffec
commit
0a039d943b
@ -23,7 +23,7 @@ public class NotificationHandler extends Handler {
|
|||||||
private final NotificationManager manager;
|
private final NotificationManager manager;
|
||||||
|
|
||||||
public NotificationHandler(String title) {
|
public NotificationHandler(String title) {
|
||||||
this(title, 2500, new NotificationManager(new QueueNotificationLayout(NORTH, SOUTH)));
|
this(title, 2500, new NotificationManager(new QueueNotificationLayout(NORTH, SOUTH), 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotificationHandler(String title, int timeout, NotificationManager manager) {
|
public NotificationHandler(String title, int timeout, NotificationManager manager) {
|
||||||
|
@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
package net.filebot.util.ui.notification;
|
package net.filebot.util.ui.notification;
|
||||||
|
|
||||||
|
|
||||||
public interface NotificationLayout {
|
public interface NotificationLayout {
|
||||||
|
|
||||||
public void add(NotificationWindow notification);
|
public void add(NotificationWindow notification);
|
||||||
|
|
||||||
|
|
||||||
public void remove(NotificationWindow notification);
|
public void remove(NotificationWindow notification);
|
||||||
|
|
||||||
|
public int size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,38 +4,35 @@
|
|||||||
|
|
||||||
package net.filebot.util.ui.notification;
|
package net.filebot.util.ui.notification;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
import net.filebot.util.ui.SwingUI;
|
import net.filebot.util.ui.SwingUI;
|
||||||
|
|
||||||
|
|
||||||
public class NotificationManager {
|
public class NotificationManager {
|
||||||
|
|
||||||
private final NotificationLayout layout;
|
private final NotificationLayout layout;
|
||||||
|
private final int limit;
|
||||||
|
|
||||||
public NotificationManager() {
|
public NotificationManager() {
|
||||||
this(new QueueNotificationLayout());
|
this(new QueueNotificationLayout(), 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NotificationManager(NotificationLayout layout, int limit) {
|
||||||
public NotificationManager(NotificationLayout layout) {
|
|
||||||
this.layout = layout;
|
this.layout = layout;
|
||||||
|
this.limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void show(NotificationWindow notification) {
|
public void show(NotificationWindow notification) {
|
||||||
SwingUI.checkEventDispatchThread();
|
SwingUI.checkEventDispatchThread();
|
||||||
|
|
||||||
notification.addWindowListener(new RemoveListener());
|
if (layout.size() < limit) {
|
||||||
layout.add(notification);
|
layout.add(notification);
|
||||||
|
notification.addWindowListener(new RemoveListener());
|
||||||
notification.setVisible(true);
|
notification.setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class RemoveListener extends WindowAdapter {
|
private class RemoveListener extends WindowAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package net.filebot.util.ui.notification;
|
package net.filebot.util.ui.notification;
|
||||||
|
|
||||||
|
|
||||||
import static net.filebot.util.ui.notification.Direction.*;
|
import static net.filebot.util.ui.notification.Direction.*;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
@ -13,9 +12,9 @@ import java.awt.Insets;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class QueueNotificationLayout implements NotificationLayout {
|
public class QueueNotificationLayout implements NotificationLayout {
|
||||||
|
|
||||||
private final List<NotificationWindow> notifications = new ArrayList<NotificationWindow>();
|
private final List<NotificationWindow> notifications = new ArrayList<NotificationWindow>();
|
||||||
@ -24,26 +23,22 @@ public class QueueNotificationLayout implements NotificationLayout {
|
|||||||
private final Direction direction;
|
private final Direction direction;
|
||||||
private final Direction growAnchor;
|
private final Direction growAnchor;
|
||||||
|
|
||||||
|
|
||||||
public QueueNotificationLayout() {
|
public QueueNotificationLayout() {
|
||||||
this(SOUTH_EAST, WEST);
|
this(SOUTH_EAST, WEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public QueueNotificationLayout(Direction alignment, Direction direction) {
|
public QueueNotificationLayout(Direction alignment, Direction direction) {
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
this.growAnchor = alignment;
|
this.growAnchor = alignment;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public QueueNotificationLayout(Direction orientation, Direction direction, Direction growAnchor) {
|
public QueueNotificationLayout(Direction orientation, Direction direction, Direction growAnchor) {
|
||||||
this.alignment = orientation;
|
this.alignment = orientation;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
this.growAnchor = growAnchor;
|
this.growAnchor = growAnchor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Point getBaseAnchor(Dimension screen, Insets insets) {
|
private Point getBaseAnchor(Dimension screen, Insets insets) {
|
||||||
Point p = new Point();
|
Point p = new Point();
|
||||||
|
|
||||||
@ -59,7 +54,6 @@ public class QueueNotificationLayout implements NotificationLayout {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Point getLocation(Point anchor, Dimension size) {
|
private Point getLocation(Point anchor, Dimension size) {
|
||||||
Point p = new Point();
|
Point p = new Point();
|
||||||
|
|
||||||
@ -69,7 +63,6 @@ public class QueueNotificationLayout implements NotificationLayout {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Point getNextAnchor(Point anchor, Dimension size) {
|
private Point getNextAnchor(Point anchor, Dimension size) {
|
||||||
Point p = new Point();
|
Point p = new Point();
|
||||||
|
|
||||||
@ -79,30 +72,34 @@ public class QueueNotificationLayout implements NotificationLayout {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(NotificationWindow notification) {
|
public void add(NotificationWindow notification) {
|
||||||
notifications.add(notification);
|
notifications.add(notification);
|
||||||
align(notification.getGraphicsConfiguration());
|
align(notification.getGraphicsConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void align(GraphicsConfiguration gc) {
|
private void align(GraphicsConfiguration gc) {
|
||||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
|
||||||
|
|
||||||
|
// avoid flickering by moving windows in reverse order
|
||||||
Point anchor = getBaseAnchor(screen, insets);
|
Point anchor = getBaseAnchor(screen, insets);
|
||||||
|
align(anchor, notifications.iterator());
|
||||||
for (NotificationWindow window : notifications) {
|
|
||||||
Dimension size = window.getSize();
|
|
||||||
|
|
||||||
Point p = getLocation(anchor, size);
|
|
||||||
window.setLocation(p);
|
|
||||||
|
|
||||||
anchor = getNextAnchor(anchor, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void align(Point anchor, Iterator<NotificationWindow> seq) {
|
||||||
|
if (!seq.hasNext()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationWindow window = seq.next();
|
||||||
|
Dimension size = window.getSize();
|
||||||
|
|
||||||
|
Point p = getLocation(anchor, size);
|
||||||
|
align(getNextAnchor(anchor, size), seq);
|
||||||
|
|
||||||
|
window.setLocation(p);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(NotificationWindow notification) {
|
public void remove(NotificationWindow notification) {
|
||||||
@ -111,4 +108,9 @@ public class QueueNotificationLayout implements NotificationLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return notifications.size();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package net.filebot.util.ui.notification;
|
package net.filebot.util.ui.notification;
|
||||||
|
|
||||||
|
|
||||||
import static net.filebot.util.ui.notification.Direction.*;
|
import static net.filebot.util.ui.notification.Direction.*;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
@ -12,23 +11,19 @@ import java.awt.Insets;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
|
||||||
|
|
||||||
public class SimpleNotificationLayout implements NotificationLayout {
|
public class SimpleNotificationLayout implements NotificationLayout {
|
||||||
|
|
||||||
private NotificationWindow currentNotification;
|
private NotificationWindow current;
|
||||||
private Direction alignment;
|
private Direction alignment;
|
||||||
|
|
||||||
|
|
||||||
public SimpleNotificationLayout() {
|
public SimpleNotificationLayout() {
|
||||||
this(NORTH);
|
this(NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SimpleNotificationLayout(Direction alignment) {
|
public SimpleNotificationLayout(Direction alignment) {
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Point getBaseAnchor(Dimension screen, Insets insets) {
|
private Point getBaseAnchor(Dimension screen, Insets insets) {
|
||||||
Point p = new Point();
|
Point p = new Point();
|
||||||
|
|
||||||
@ -44,7 +39,6 @@ public class SimpleNotificationLayout implements NotificationLayout {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Point getLocation(Point anchor, Dimension size) {
|
private Point getLocation(Point anchor, Dimension size) {
|
||||||
Point p = new Point();
|
Point p = new Point();
|
||||||
|
|
||||||
@ -54,7 +48,6 @@ public class SimpleNotificationLayout implements NotificationLayout {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(NotificationWindow notification) {
|
public void add(NotificationWindow notification) {
|
||||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
@ -64,17 +57,23 @@ public class SimpleNotificationLayout implements NotificationLayout {
|
|||||||
Point anchor = getBaseAnchor(screen, insets);
|
Point anchor = getBaseAnchor(screen, insets);
|
||||||
notification.setLocation(getLocation(anchor, size));
|
notification.setLocation(getLocation(anchor, size));
|
||||||
|
|
||||||
if (currentNotification != null) {
|
if (current != null) {
|
||||||
currentNotification.close();
|
current.close();
|
||||||
}
|
}
|
||||||
|
current = notification;
|
||||||
currentNotification = notification;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(NotificationWindow notification) {
|
public void remove(NotificationWindow notification) {
|
||||||
|
if (current != null && current == notification) {
|
||||||
|
current.close();
|
||||||
|
}
|
||||||
|
current = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return current == null ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user