Ticket #23002: josm_23002_notification.patch

File josm_23002_notification.patch, 5.1 KB (added by gaben, 3 years ago)
  • src/org/openstreetmap/josm/gui/NotificationManager.java

     
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    66import java.awt.BasicStroke;
     7import java.awt.BorderLayout;
    78import java.awt.Color;
    89import java.awt.Component;
    910import java.awt.Container;
     
    4041import org.openstreetmap.josm.gui.help.HelpBrowser;
    4142import org.openstreetmap.josm.gui.help.HelpUtil;
    4243import org.openstreetmap.josm.gui.util.GuiHelper;
     44import org.openstreetmap.josm.spi.preferences.Config;
    4345import org.openstreetmap.josm.tools.ImageProvider;
    4446import org.openstreetmap.josm.tools.Logging;
    4547
    4648/**
    4749 * Manages {@link Notification}s, i.e. displays them on screen.
    48  *
     50 * <p>
    4951 * Don't use this class directly, but use {@link Notification#show()}.
    50  *
     52 * <p>
    5153 * If multiple messages are sent in a short period of time, they are put in
    5254 * a queue and displayed one after the other.
    53  *
     55 * <p>
    5456 * The user can stop the timer (freeze the message) by moving the mouse cursor
    5557 * above the panel. As a visual cue, the background color changes from
    5658 * semi-transparent to opaque while the timer is frozen.
     
    5759 */
    5860class NotificationManager {
    5961
    60     private final Timer hideTimer; // started when message is shown, responsible for hiding the message
     62    private final Timer hideTimer; // started when a message is shown, responsible for hiding the message
    6163    private final Timer pauseTimer; // makes sure, there is a small pause between two consecutive messages
    6264    private final Timer unfreezeDelayTimer; // tiny delay before resuming the timer when mouse cursor is moved off the panel
    6365    private boolean running;
     
    129131            currentNotificationPanel = new NotificationPanel(currentNotification, new FreezeMouseListener(), e -> this.stopHideTimer());
    130132            currentNotificationPanel.validate();
    131133
    132             int margin = 5;
     134            int margin = 10;
    133135            JFrame parentWindow = MainApplication.getMainFrame();
    134             Dimension size = currentNotificationPanel.getPreferredSize();
     136            Dimension notificatonDimension = currentNotificationPanel.getPreferredSize();
    135137            if (parentWindow != null) {
    136138                int x;
    137139                int y;
     
    138140                MapFrame map = MainApplication.getMap();
    139141                if (MainApplication.isDisplayingMapView() && map.mapView.getHeight() > 0) {
    140142                    MapView mv = map.mapView;
    141                     Point mapViewPos = SwingUtilities.convertPoint(mv.getParent(), mv.getX(), mv.getY(), MainApplication.getMainFrame());
     143                    Point mapViewPos = SwingUtilities.convertPoint(mv.getParent(), mv.getX(), mv.getY(), parentWindow);
    142144                    x = mapViewPos.x + margin;
    143                     y = mapViewPos.y + mv.getHeight() - map.statusLine.getHeight() - size.height - margin;
     145                    if (Config.getPref().getBoolean("draw.fullscreen")) {
     146                        y = parentWindow.getHeight() - map.statusLine.getHeight() - notificatonDimension.height - margin;
     147                    } else {
     148                        // the extra 2px here is to add the missing border sizes
     149                        y = parentWindow.getHeight() - MainApplication.getToolbar().control.getSize().height + 2 -
     150                            map.statusLine.getHeight() - notificatonDimension.height - margin;
     151                    }
    144152                } else {
    145153                    x = margin;
    146                     y = parentWindow.getHeight() - MainApplication.getToolbar().control.getSize().height - size.height - margin;
     154                    y = parentWindow.getHeight() - MainApplication.getToolbar().control.getSize().height - notificatonDimension.height - margin;
    147155                }
    148156                parentWindow.getLayeredPane().add(currentNotificationPanel, JLayeredPane.POPUP_LAYER, 0);
    149157
    150158                currentNotificationPanel.setLocation(x, y);
    151159            }
    152             currentNotificationPanel.setSize(size);
     160            currentNotificationPanel.setSize(notificatonDimension);
    153161            currentNotificationPanel.setVisible(true);
    154162        });
    155163
     
    235243        }
    236244
    237245        private void build(final Notification note, MouseListener freeze, ActionListener hideListener) {
     246            // use BorderLayout to remove default margins
     247            setLayout(new BorderLayout());
    238248            JButton btnClose = new JButton();
    239249            btnClose.addActionListener(hideListener);
    240250            btnClose.setIcon(ImageProvider.get("misc", "grey_x"));
     
    270280            layout.setAutoCreateGaps(true);
    271281            layout.setAutoCreateContainerGaps(true);
    272282
    273             innerPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
     283            // fix border appearance
     284            innerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 1));
     285
    274286            add(innerPanel);
    275287
    276288            JLabel icon = null;