Changeset 16313 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-04-15T23:29:36+02:00 (4 years ago)
Author:
simon04
Message:

fix #19089 - Avoid displaying multiple notifications with the same text

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/Notification.java

    r12846 r16313  
    44import java.awt.Color;
    55import java.awt.Component;
     6import java.util.Objects;
    67
    78import javax.swing.Icon;
     
    910import javax.swing.JOptionPane;
    1011import javax.swing.UIManager;
     12import javax.swing.text.JTextComponent;
    1113
    1214import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
     
    211213        NotificationManager.getInstance().showNotification(this);
    212214    }
     215
     216    private Object getContentTextOrComponent() {
     217        return content instanceof JTextComponent ? ((JTextComponent) content).getText() : content;
     218    }
     219
     220    @Override
     221    public boolean equals(Object o) {
     222        if (this == o) return true;
     223        if (o == null || getClass() != o.getClass()) return false;
     224        Notification that = (Notification) o;
     225        System.out.println(getContentTextOrComponent().getClass());
     226        return duration == that.duration
     227                && Objects.equals(getContentTextOrComponent(), that.getContentTextOrComponent())
     228                && Objects.equals(helpTopic, that.helpTopic);
     229    }
     230
     231    @Override
     232    public int hashCode() {
     233        return Objects.hash(getContentTextOrComponent(), duration, helpTopic);
     234    }
     235
     236    @Override
     237    public String toString() {
     238        return "Notification{" +
     239                "content=" + getContentTextOrComponent() +
     240                ", duration=" + duration +
     241                ", helpTopic='" + helpTopic + '\'' +
     242                '}';
     243    }
    213244}
  • trunk/src/org/openstreetmap/josm/gui/NotificationManager.java

    r14153 r16313  
    2121import java.awt.event.MouseListener;
    2222import java.awt.geom.RoundRectangle2D;
     23import java.util.Deque;
    2324import java.util.LinkedList;
    24 import java.util.Queue;
     25import java.util.Objects;
    2526
    2627import javax.swing.AbstractAction;
     
    4142import org.openstreetmap.josm.gui.util.GuiHelper;
    4243import org.openstreetmap.josm.tools.ImageProvider;
     44import org.openstreetmap.josm.tools.Logging;
    4345
    4446/**
     
    6365    private Notification currentNotification;
    6466    private NotificationPanel currentNotificationPanel;
    65     private final Queue<Notification> queue;
     67    private final Deque<Notification> queue;
    6668
    6769    private static IntegerProperty pauseTime = new IntegerProperty("notification-default-pause-time-ms", 300); // milliseconds
     
    8688
    8789    /**
    88      * Show the given notification
     90     * Show the given notification (unless a duplicate notification is being shown at the moment or at the end of the queue)
    8991     * @param note The note to show.
    9092     * @see Notification#show()
     
    9294    public void showNotification(Notification note) {
    9395        synchronized (queue) {
     96            if (Objects.equals(note, currentNotification) || Objects.equals(note, queue.peekLast())) {
     97                Logging.debug("Dropping duplicate notification {0}", note);
     98                return;
     99            }
    94100            queue.add(note);
    95101            processQueue();
Note: See TracChangeset for help on using the changeset viewer.