Ticket #23002: josm_23002_notification.patch
| File josm_23002_notification.patch, 5.1 KB (added by , 3 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/NotificationManager.java
4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.BasicStroke; 7 import java.awt.BorderLayout; 7 8 import java.awt.Color; 8 9 import java.awt.Component; 9 10 import java.awt.Container; … … 40 41 import org.openstreetmap.josm.gui.help.HelpBrowser; 41 42 import org.openstreetmap.josm.gui.help.HelpUtil; 42 43 import org.openstreetmap.josm.gui.util.GuiHelper; 44 import org.openstreetmap.josm.spi.preferences.Config; 43 45 import org.openstreetmap.josm.tools.ImageProvider; 44 46 import org.openstreetmap.josm.tools.Logging; 45 47 46 48 /** 47 49 * Manages {@link Notification}s, i.e. displays them on screen. 48 * 50 * <p> 49 51 * Don't use this class directly, but use {@link Notification#show()}. 50 * 52 * <p> 51 53 * If multiple messages are sent in a short period of time, they are put in 52 54 * a queue and displayed one after the other. 53 * 55 * <p> 54 56 * The user can stop the timer (freeze the message) by moving the mouse cursor 55 57 * above the panel. As a visual cue, the background color changes from 56 58 * semi-transparent to opaque while the timer is frozen. … … 57 59 */ 58 60 class NotificationManager { 59 61 60 private final Timer hideTimer; // started when message is shown, responsible for hiding the message62 private final Timer hideTimer; // started when a message is shown, responsible for hiding the message 61 63 private final Timer pauseTimer; // makes sure, there is a small pause between two consecutive messages 62 64 private final Timer unfreezeDelayTimer; // tiny delay before resuming the timer when mouse cursor is moved off the panel 63 65 private boolean running; … … 129 131 currentNotificationPanel = new NotificationPanel(currentNotification, new FreezeMouseListener(), e -> this.stopHideTimer()); 130 132 currentNotificationPanel.validate(); 131 133 132 int margin = 5;134 int margin = 10; 133 135 JFrame parentWindow = MainApplication.getMainFrame(); 134 Dimension size= currentNotificationPanel.getPreferredSize();136 Dimension notificatonDimension = currentNotificationPanel.getPreferredSize(); 135 137 if (parentWindow != null) { 136 138 int x; 137 139 int y; … … 138 140 MapFrame map = MainApplication.getMap(); 139 141 if (MainApplication.isDisplayingMapView() && map.mapView.getHeight() > 0) { 140 142 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); 142 144 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 } 144 152 } else { 145 153 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; 147 155 } 148 156 parentWindow.getLayeredPane().add(currentNotificationPanel, JLayeredPane.POPUP_LAYER, 0); 149 157 150 158 currentNotificationPanel.setLocation(x, y); 151 159 } 152 currentNotificationPanel.setSize( size);160 currentNotificationPanel.setSize(notificatonDimension); 153 161 currentNotificationPanel.setVisible(true); 154 162 }); 155 163 … … 235 243 } 236 244 237 245 private void build(final Notification note, MouseListener freeze, ActionListener hideListener) { 246 // use BorderLayout to remove default margins 247 setLayout(new BorderLayout()); 238 248 JButton btnClose = new JButton(); 239 249 btnClose.addActionListener(hideListener); 240 250 btnClose.setIcon(ImageProvider.get("misc", "grey_x")); … … 270 280 layout.setAutoCreateGaps(true); 271 281 layout.setAutoCreateContainerGaps(true); 272 282 273 innerPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 283 // fix border appearance 284 innerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 1)); 285 274 286 add(innerPanel); 275 287 276 288 JLabel icon = null;
