source: josm/trunk/src/org/openstreetmap/josm/gui/MapStatus.java

Last change on this file was 19122, checked in by stoecker, 13 months ago

fix #23745 - add more icons, patch by gaben

  • Property svn:eol-style set to native
File size: 51.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.marktr;
6import static org.openstreetmap.josm.tools.I18n.tr;
7
8import java.awt.AWTEvent;
9import java.awt.Color;
10import java.awt.Component;
11import java.awt.Cursor;
12import java.awt.Dimension;
13import java.awt.EventQueue;
14import java.awt.Font;
15import java.awt.GraphicsEnvironment;
16import java.awt.GridBagConstraints;
17import java.awt.GridBagLayout;
18import java.awt.MouseInfo;
19import java.awt.Point;
20import java.awt.PointerInfo;
21import java.awt.SystemColor;
22import java.awt.Toolkit;
23import java.awt.event.AWTEventListener;
24import java.awt.event.ActionEvent;
25import java.awt.event.ComponentAdapter;
26import java.awt.event.ComponentEvent;
27import java.awt.event.InputEvent;
28import java.awt.event.KeyAdapter;
29import java.awt.event.KeyEvent;
30import java.awt.event.MouseAdapter;
31import java.awt.event.MouseEvent;
32import java.awt.event.MouseListener;
33import java.awt.event.MouseMotionListener;
34import java.lang.reflect.InvocationTargetException;
35import java.text.DecimalFormat;
36import java.util.ArrayList;
37import java.util.Collection;
38import java.util.Comparator;
39import java.util.ConcurrentModificationException;
40import java.util.Iterator;
41import java.util.List;
42import java.util.Objects;
43import java.util.concurrent.BlockingQueue;
44import java.util.concurrent.LinkedBlockingQueue;
45import java.util.stream.Collectors;
46
47import javax.swing.AbstractAction;
48import javax.swing.BorderFactory;
49import javax.swing.JCheckBoxMenuItem;
50import javax.swing.JLabel;
51import javax.swing.JMenuItem;
52import javax.swing.JOptionPane;
53import javax.swing.JPanel;
54import javax.swing.JPopupMenu;
55import javax.swing.JProgressBar;
56import javax.swing.JScrollPane;
57import javax.swing.JSeparator;
58import javax.swing.Popup;
59import javax.swing.PopupFactory;
60import javax.swing.SwingConstants;
61import javax.swing.UIManager;
62import javax.swing.event.PopupMenuEvent;
63import javax.swing.event.PopupMenuListener;
64
65import org.openstreetmap.josm.data.SystemOfMeasurement;
66import org.openstreetmap.josm.data.SystemOfMeasurement.SoMChangeListener;
67import org.openstreetmap.josm.data.coor.ILatLon;
68import org.openstreetmap.josm.data.coor.LatLon;
69import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
70import org.openstreetmap.josm.data.coor.conversion.DMSCoordinateFormat;
71import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;
72import org.openstreetmap.josm.data.coor.conversion.ProjectedCoordinateFormat;
73import org.openstreetmap.josm.data.osm.DataSelectionListener;
74import org.openstreetmap.josm.data.osm.DataSet;
75import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
76import org.openstreetmap.josm.data.osm.IPrimitive;
77import org.openstreetmap.josm.data.osm.OsmPrimitive;
78import org.openstreetmap.josm.data.osm.Way;
79import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
80import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
81import org.openstreetmap.josm.data.osm.event.DataSetListener;
82import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
83import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
84import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
85import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
86import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;
87import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
88import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
89import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
90import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
91import org.openstreetmap.josm.data.preferences.AbstractProperty;
92import org.openstreetmap.josm.data.preferences.BooleanProperty;
93import org.openstreetmap.josm.data.preferences.DoubleProperty;
94import org.openstreetmap.josm.data.preferences.NamedColorProperty;
95import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener;
96import org.openstreetmap.josm.gui.help.Helpful;
97import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
98import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor.ProgressMonitorDialog;
99import org.openstreetmap.josm.gui.util.GuiHelper;
100import org.openstreetmap.josm.gui.widgets.ImageLabel;
101import org.openstreetmap.josm.gui.widgets.JosmTextField;
102import org.openstreetmap.josm.spi.preferences.Config;
103import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
104import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
105import org.openstreetmap.josm.tools.ColorHelper;
106import org.openstreetmap.josm.tools.Destroyable;
107import org.openstreetmap.josm.tools.GBC;
108import org.openstreetmap.josm.tools.ImageProvider;
109import org.openstreetmap.josm.tools.Logging;
110import org.openstreetmap.josm.tools.SubclassFilteredCollection;
111import org.openstreetmap.josm.tools.Utils;
112
113/**
114 * A component that manages some status information display about the map.
115 * It keeps a status line below the map up to date and displays some tooltip
116 * information if the user hold the mouse long enough at some point.
117 * <p>
118 * All this is done in background to not disturb other processes.
119 * <p>
120 * The background thread does not alter any data of the map (read only thread).
121 * Also it is rather fail safe. In case of some error in the data, it just does
122 * nothing instead of whining and complaining.
123 *
124 * @author imi
125 */
126public final class MapStatus extends JPanel implements
127 Helpful, Destroyable, PreferenceChangedListener, SoMChangeListener, DataSelectionListener, DataSetListener, ZoomChangeListener {
128
129 private final DecimalFormat DECIMAL_FORMAT = new DecimalFormat(Config.getPref().get("statusbar.decimal-format", "0.00"));
130 private static final AbstractProperty<Double> DISTANCE_THRESHOLD = new DoubleProperty("statusbar.distance-threshold", 0.01).cached();
131
132 private static final AbstractProperty<Boolean> SHOW_ID = new BooleanProperty("osm-primitives.showid", false);
133
134 private static final List<SystemOfMeasurement> SORTED_SYSTEM_OF_MEASUREMENTS = SystemOfMeasurement.ALL_SYSTEMS.values().stream()
135 .sorted(Comparator.comparing(SystemOfMeasurement::toString))
136 .collect(Collectors.toList());
137
138 /**
139 * Property for map status background color.
140 * @since 6789
141 */
142 public static final NamedColorProperty PROP_BACKGROUND_COLOR = new NamedColorProperty(
143 marktr("Status bar background"), ColorHelper.html2color("#b8cfe5"));
144
145 /**
146 * Property for map status background color (active state).
147 * @since 6789
148 */
149 public static final NamedColorProperty PROP_ACTIVE_BACKGROUND_COLOR = new NamedColorProperty(
150 marktr("Status bar background: active"), ColorHelper.html2color("#aaff5e"));
151
152 /**
153 * Property for map status foreground color.
154 * @since 6789
155 */
156 public static final NamedColorProperty PROP_FOREGROUND_COLOR = new NamedColorProperty(
157 marktr("Status bar foreground"), Color.black);
158
159 /**
160 * Property for map status foreground color (active state).
161 * @since 6789
162 */
163 public static final NamedColorProperty PROP_ACTIVE_FOREGROUND_COLOR = new NamedColorProperty(
164 marktr("Status bar foreground: active"), Color.black);
165
166 /**
167 * The MapView this status belongs to.
168 */
169 private final MapView mv;
170 private final transient Collector collector;
171
172 static final class ShowMonitorDialogMouseAdapter extends MouseAdapter {
173 @Override
174 public void mouseClicked(MouseEvent e) {
175 PleaseWaitProgressMonitor monitor = PleaseWaitProgressMonitor.getCurrent();
176 if (monitor != null) {
177 monitor.showForegroundDialog();
178 }
179 }
180 }
181
182 static final class JumpToOnLeftClickMouseAdapter extends MouseAdapter {
183 @Override
184 public void mouseClicked(MouseEvent e) {
185 if (e.getButton() != MouseEvent.BUTTON3) {
186 MainApplication.getMenu().jumpToAct.showJumpToDialog();
187 }
188 }
189 }
190
191 /**
192 * The progress monitor that is used to display the progress if the user selects to run in background
193 */
194 public class BackgroundProgressMonitor implements ProgressMonitorDialog {
195
196 private String title;
197 private String customText;
198
199 private void updateText() {
200 if (!Utils.isEmpty(customText)) {
201 progressBar.setToolTipText(tr("{0} ({1})", title, customText));
202 } else {
203 progressBar.setToolTipText(title);
204 }
205 }
206
207 @Override
208 public void setVisible(boolean visible) {
209 progressBar.setVisible(visible);
210 }
211
212 @Override
213 public void updateProgress(int progress) {
214 progressBar.setValue(progress);
215 progressBar.repaint();
216 MapStatus.this.doLayout();
217 }
218
219 @Override
220 public void setCustomText(String text) {
221 this.customText = text;
222 updateText();
223 }
224
225 @Override
226 public void setCurrentAction(String text) {
227 this.title = text;
228 updateText();
229 }
230
231 @Override
232 public void setIndeterminate(boolean newValue) {
233 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
234 progressBar.setIndeterminate(newValue);
235 }
236
237 @Override
238 public void appendLogMessage(String message) {
239 if (!Utils.isEmpty(message)) {
240 Logging.info("appendLogMessage not implemented for background tasks. Message was: " + message);
241 }
242 }
243
244 }
245
246 /** The {@link ICoordinateFormat} set in the previous update */
247 private transient ICoordinateFormat previousCoordinateFormat;
248 private final ImageLabel latText = new ImageLabel("lat",
249 null, DMSCoordinateFormat.INSTANCE.latToString(LatLon.SOUTH_POLE).length(), PROP_BACKGROUND_COLOR.get());
250 private final ImageLabel lonText = new ImageLabel("lon",
251 null, DMSCoordinateFormat.INSTANCE.lonToString(new LatLon(0, 180)).length(), PROP_BACKGROUND_COLOR.get());
252 private final ImageLabel headingText = new ImageLabel("heading",
253 tr("The (compass) heading of the line segment being drawn."),
254 DECIMAL_FORMAT.format(360).length() + 1, PROP_BACKGROUND_COLOR.get());
255 private final ImageLabel angleText = new ImageLabel("angle",
256 tr("The angle between the previous and the current way segment."),
257 DECIMAL_FORMAT.format(360).length() + 1, PROP_BACKGROUND_COLOR.get());
258 private final ImageLabel distText = new ImageLabel("dist",
259 tr("The length of the new way segment being drawn."), 10, PROP_BACKGROUND_COLOR.get());
260 private final ImageLabel nameText = new ImageLabel("name",
261 tr("The name of the object at the mouse pointer."),
262 getNameLabelCharacterCount(MainApplication.getMainFrame()), PROP_BACKGROUND_COLOR.get());
263 private final JosmTextField helpText = new JosmTextField(null, null, 0, false);
264 private final JProgressBar progressBar = new JProgressBar();
265 private final transient ComponentAdapter mvComponentAdapter;
266 /**
267 * The progress monitor for displaying a background progress
268 */
269 public final transient BackgroundProgressMonitor progressMonitor = new BackgroundProgressMonitor();
270
271 // Distance value displayed in distText, stored if refresh needed after a change of system of measurement
272 private double distValue;
273
274 // Determines if angle panel is enabled or not
275 private boolean angleEnabled;
276
277 /**
278 * This is the thread that runs in the background and collects the information displayed.
279 * It gets destroyed by destroy() when the MapFrame itself is destroyed.
280 */
281 private final transient Thread thread;
282
283 private final transient List<StatusTextHistory> statusText = new ArrayList<>();
284
285 protected static final class StatusTextHistory {
286 private final Object id;
287 private final String text;
288
289 StatusTextHistory(Object id, String text) {
290 this.id = id;
291 this.text = text;
292 }
293
294 @Override
295 public boolean equals(Object obj) {
296 return obj instanceof StatusTextHistory && ((StatusTextHistory) obj).id == id;
297 }
298
299 @Override
300 public int hashCode() {
301 return System.identityHashCode(id);
302 }
303 }
304
305 /**
306 * The collector class that waits for notification and then update the display objects.
307 *
308 * @author imi
309 */
310 private final class Collector implements Runnable {
311 private final class CollectorWorker implements Runnable {
312 private final MouseState ms;
313
314 private CollectorWorker(MouseState ms) {
315 this.ms = ms;
316 }
317
318 @Override
319 public void run() {
320 // Freeze display when holding down CTRL
321 if ((ms.modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
322 // update the information popup's labels though, because the selection might have changed from the outside
323 popupUpdateLabels();
324 return;
325 }
326
327 // The popup != null check is required because a left-click produces several events as well,
328 // which would make this variable true. Of course we only want the popup to show
329 // if the middle mouse button has been pressed in the first place
330 boolean mouseNotMoved = oldMousePos != null && oldMousePos.equals(ms.mousePos);
331 boolean isAtOldPosition = mouseNotMoved && popup != null;
332 boolean middleMouseDown = (ms.modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0;
333
334 DataSet ds = mv.getLayerManager().getActiveDataSet();
335 if (ds != null) {
336 // This is not perfect, if current dataset was changed during execution, the lock would be useless
337 if (isAtOldPosition && middleMouseDown) {
338 // Write lock is necessary when selecting in popupCycleSelection
339 // locks can not be upgraded -> if do read lock here and write lock later
340 // (in OsmPrimitive.updateFlags) then always occurs deadlock (#5814)
341 ds.beginUpdate();
342 } else {
343 ds.getReadLock().lock();
344 }
345 }
346 // This try/catch is a hack to stop the flooding bug reports about this.
347 // The exception needed to handle with in the first place, means that this
348 // access to the data need to be restarted, if the main thread modifies the data.
349 try {
350 // Set the text label in the bottom status bar
351 // "if mouse moved only" was added to stop heap growing
352 if (!mouseNotMoved) {
353 statusBarElementUpdate(ms);
354 }
355
356 // Popup Information
357 // display them if the middle mouse button is pressed and keep them until the mouse is moved
358 if (middleMouseDown || isAtOldPosition) {
359 Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos, OsmPrimitive::isSelectable);
360
361 final JPanel c = new JPanel(new GridBagLayout());
362 final JLabel lbl = new JLabel(
363 "<html>"+tr("Middle click again to cycle through.<br>"+
364 "Hold CTRL to select directly from this list with the mouse.<hr>")+"</html>",
365 null,
366 SwingConstants.CENTER
367 );
368 lbl.setHorizontalAlignment(SwingConstants.LEADING);
369 c.add(lbl, GBC.eol().insets(2, 0, 2, 0));
370
371 // Only cycle if the mouse has not been moved and the middle mouse button has been pressed at least
372 // twice (the reason for this is the popup != null check for isAtOldPosition, see above.
373 // This is a nice side effect though, because it does not change selection of the first middle click)
374 if (isAtOldPosition && middleMouseDown) {
375 // Hand down mouse modifiers so the SHIFT mod can be handled correctly (see function)
376 popupCycleSelection(osms, ms.modifiers);
377 }
378
379 // These labels may need to be updated from the outside so collect them
380 List<JLabel> lbls = new ArrayList<>(osms.size());
381 for (final OsmPrimitive osm : osms) {
382 JLabel l = popupBuildPrimitiveLabels(osm);
383 lbls.add(l);
384 c.add(l, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(2, 0, 2, 2));
385 }
386
387 popupShowPopup(popupCreatePopup(c, ms), lbls);
388 } else {
389 popupHidePopup();
390 }
391
392 oldMousePos = ms.mousePos;
393 } catch (ConcurrentModificationException ex) {
394 Logging.warn(ex);
395 } finally {
396 if (ds != null) {
397 if (isAtOldPosition && middleMouseDown) {
398 ds.endUpdate();
399 } else {
400 ds.getReadLock().unlock();
401 }
402 }
403 }
404 }
405 }
406
407 /**
408 * the mouse position of the previous iteration. This is used to show
409 * the popup until the cursor is moved.
410 */
411 private Point oldMousePos;
412 /**
413 * Contains the labels that are currently shown in the information
414 * popup
415 */
416 private List<JLabel> popupLabels;
417 /**
418 * The popup displayed to show additional information
419 */
420 private Popup popup;
421
422 private final MapFrame parent;
423
424 private final BlockingQueue<MouseState> incomingMouseState = new LinkedBlockingQueue<>();
425
426 private Point lastMousePos;
427
428 Collector(MapFrame parent) {
429 this.parent = parent;
430 }
431
432 /**
433 * Execution function for the Collector.
434 */
435 @Override
436 public void run() {
437 registerListeners();
438 try {
439 for (;;) {
440 try {
441 final MouseState ms = incomingMouseState.take();
442 if (parent != MainApplication.getMap())
443 return; // exit, if new parent.
444
445 // Do nothing, if required data is missing
446 if (ms.mousePos == null || mv.getCenter() == null) {
447 continue;
448 }
449
450 EventQueue.invokeAndWait(new CollectorWorker(ms));
451 } catch (InvocationTargetException e) {
452 Logging.warn(e);
453 }
454 }
455 } catch (InterruptedException e) {
456 // Occurs frequently during JOSM shutdown, log set to trace only
457 Logging.trace("InterruptedException in "+MapStatus.class.getSimpleName());
458 Thread.currentThread().interrupt();
459 } finally {
460 unregisterListeners();
461 }
462 }
463
464 /**
465 * Creates a popup for the given content next to the cursor. Tries to
466 * keep the popup on screen and shows a vertical scrollbar, if the
467 * screen is too small.
468 * @param content popup content
469 * @param ms mouse state
470 * @return popup
471 */
472 private Popup popupCreatePopup(Component content, MouseState ms) {
473 Point p = mv.getLocationOnScreen();
474 Dimension scrn = GuiHelper.getScreenSize();
475
476 // Create a JScrollPane around the content, in case there's not enough space
477 JScrollPane sp = GuiHelper.embedInVerticalScrollPane(content);
478 sp.setBorder(BorderFactory.createRaisedBevelBorder());
479 // Implement max-size content-independent
480 Dimension prefsize = sp.getPreferredSize();
481 int w = Math.min(prefsize.width, Math.min(800, (scrn.width/2) - 16));
482 int h = Math.min(prefsize.height, scrn.height - 10);
483 sp.setPreferredSize(new Dimension(w, h));
484
485 int xPos = p.x + ms.mousePos.x + 16;
486 // Display the popup to the left of the cursor if it would be cut
487 // off on its right, but only if more space is available
488 if (xPos + w > scrn.width && xPos > scrn.width/2) {
489 xPos = p.x + ms.mousePos.x - 4 - w;
490 }
491 int yPos = p.y + ms.mousePos.y + 16;
492 // Move the popup up if it would be cut off at its bottom but do not
493 // move it off screen on the top
494 if (yPos + h > scrn.height - 5) {
495 yPos = Math.max(5, scrn.height - h - 5);
496 }
497
498 PopupFactory pf = PopupFactory.getSharedInstance();
499 return pf.getPopup(mv, sp, xPos, yPos);
500 }
501
502 /**
503 * Calls this to update the element that is shown in the statusbar
504 * @param ms mouse state
505 */
506 private void statusBarElementUpdate(MouseState ms) {
507 final OsmPrimitive osmNearest = mv.getNearestNodeOrWay(ms.mousePos, OsmPrimitive::isUsable, false);
508 if (osmNearest != null) {
509 nameText.setText(osmNearest.getDisplayName(DefaultNameFormatter.getInstance()));
510 } else {
511 nameText.setText(tr("(no object)"));
512 }
513 }
514
515 /**
516 * Call this with a set of primitives to cycle through them. Method
517 * will automatically select the next item and update the map
518 * @param osms primitives to cycle through
519 * @param mods modifiers (i.e. control keys)
520 */
521 private void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {
522 DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
523 // Find some items that are required for cycling through
524 OsmPrimitive firstItem = null;
525 OsmPrimitive firstSelected = null;
526 OsmPrimitive nextSelected = null;
527 for (final OsmPrimitive osm : osms) {
528 if (firstItem == null) {
529 firstItem = osm;
530 }
531 if (firstSelected != null && nextSelected == null) {
532 nextSelected = osm;
533 }
534 if (firstSelected == null && ds.isSelected(osm)) {
535 firstSelected = osm;
536 }
537 }
538
539 // Clear previous selection if SHIFT (add to selection) is not
540 // pressed. Cannot use "setSelected()" because it will cause a
541 // fireSelectionChanged event which is unnecessary at this point.
542 if ((mods & InputEvent.SHIFT_DOWN_MASK) == 0) {
543 ds.clearSelection();
544 }
545
546 // This will cycle through the available items.
547 if (firstSelected != null) {
548 ds.clearSelection(firstSelected);
549 if (nextSelected != null) {
550 ds.addSelected(nextSelected);
551 }
552 } else if (firstItem != null) {
553 ds.addSelected(firstItem);
554 }
555 }
556
557 /**
558 * Tries to hide the given popup
559 */
560 private void popupHidePopup() {
561 popupLabels = null;
562 if (popup == null)
563 return;
564 final Popup staticPopup = popup;
565 popup = null;
566 EventQueue.invokeLater(staticPopup::hide);
567 }
568
569 /**
570 * Tries to show the given popup, can be hidden using {@link #popupHidePopup}
571 * If an old popup exists, it will be automatically hidden
572 * @param newPopup popup to show
573 * @param lbls labels to show (see {@link #popupLabels})
574 */
575 private void popupShowPopup(Popup newPopup, List<JLabel> lbls) {
576 final Popup staticPopup = newPopup;
577 if (this.popup != null) {
578 // If an old popup exists, remove it when the new popup has been drawn to keep flickering to a minimum
579 final Popup staticOldPopup = this.popup;
580 EventQueue.invokeLater(() -> {
581 staticPopup.show();
582 staticOldPopup.hide();
583 });
584 } else {
585 // There is no old popup
586 EventQueue.invokeLater(staticPopup::show);
587 }
588 this.popupLabels = lbls;
589 this.popup = newPopup;
590 }
591
592 /**
593 * This method should be called if the selection may have changed from
594 * outside of this class. This is the case when CTRL is pressed and the
595 * user clicks on the map instead of the popup.
596 */
597 private void popupUpdateLabels() {
598 if (this.popup == null || this.popupLabels == null)
599 return;
600 for (JLabel l : this.popupLabels) {
601 l.validate();
602 }
603 }
604
605 /**
606 * Sets the colors for the given label depending on the selected status of
607 * the given OsmPrimitive
608 *
609 * @param lbl The label to color
610 * @param osm The primitive to derive the colors from
611 */
612 private void popupSetLabelColors(JLabel lbl, IPrimitive osm) {
613 if (osm.isSelected()) {
614 lbl.setBackground(SystemColor.textHighlight);
615 lbl.setForeground(SystemColor.textHighlightText);
616 } else {
617 lbl.setBackground(SystemColor.control);
618 lbl.setForeground(SystemColor.controlText);
619 }
620 }
621
622 /**
623 * Builds the labels with all necessary listeners for the info popup for the
624 * given OsmPrimitive
625 * @param osm The primitive to create the label for
626 * @return labels for info popup
627 */
628 private JLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) {
629 final StringBuilder text = new StringBuilder(32);
630 String name = Utils.escapeReservedCharactersHTML(osm.getDisplayName(DefaultNameFormatter.getInstance()));
631 if (osm.isNewOrUndeleted() || osm.isModified()) {
632 name = "<i><b>"+ name + "*</b></i>";
633 }
634 text.append(name);
635
636 boolean idShown = SHOW_ID.get();
637 // fix #7557 - do not show ID twice
638
639 if (!osm.isNew() && !idShown) {
640 text.append(" [id=").append(osm.getId()).append(']');
641 }
642
643 if (osm.getUser() != null) {
644 text.append(" [").append(tr("User:")).append(' ')
645 .append(Utils.escapeReservedCharactersHTML(osm.getUser().getName())).append(']');
646 }
647
648 osm.visitKeys((primitive, key, value) -> text.append("<br>").append(key).append('=').append(value));
649
650 final JLabel l = new JLabel(
651 "<html>" + text.toString() + "</html>",
652 ImageProvider.get(osm.getDisplayType()),
653 SwingConstants.HORIZONTAL
654 ) {
655 // This is necessary so the label updates its colors when the
656 // selection is changed from the outside
657 @Override
658 public void validate() {
659 super.validate();
660 popupSetLabelColors(this, osm);
661 }
662 };
663 l.setOpaque(true);
664 popupSetLabelColors(l, osm);
665 l.setFont(l.getFont().deriveFont(Font.PLAIN));
666 l.setVerticalTextPosition(SwingConstants.TOP);
667 l.setHorizontalAlignment(SwingConstants.LEADING);
668 l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
669 l.addMouseListener(new MouseAdapter() {
670 @Override
671 public void mouseEntered(MouseEvent e) {
672 l.setBackground(SystemColor.info);
673 l.setForeground(SystemColor.infoText);
674 }
675
676 @Override
677 public void mouseExited(MouseEvent e) {
678 popupSetLabelColors(l, osm);
679 }
680
681 @Override
682 public void mouseClicked(MouseEvent e) {
683 DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
684 // Let the user toggle the selection
685 ds.toggleSelected(osm);
686 l.validate();
687 }
688 });
689 // Sometimes the mouseEntered event is not catched, thus the label
690 // will not be highlighted, making it confusing. The MotionListener can correct this defect.
691 l.addMouseMotionListener(new MouseMotionListener() {
692 @Override
693 public void mouseMoved(MouseEvent e) {
694 l.setBackground(SystemColor.info);
695 l.setForeground(SystemColor.infoText);
696 }
697
698 @Override
699 public void mouseDragged(MouseEvent e) {
700 mouseMoved(e);
701 }
702 });
703 return l;
704 }
705
706 /**
707 * Called whenever the mouse position or modifiers changed.
708 * @param mousePos The new mouse position. <code>null</code> if it did not change.
709 * @param modifiers The new modifiers.
710 */
711 public synchronized void updateMousePosition(Point mousePos, int modifiers) {
712 if (mousePos != null) {
713 lastMousePos = mousePos;
714 }
715 MouseState ms = new MouseState(lastMousePos, modifiers);
716 // remove mouse states that are in the queue. Our mouse state is newer.
717 incomingMouseState.clear();
718 if (!incomingMouseState.offer(ms)) {
719 Logging.warn("Unable to handle new MouseState: " + ms);
720 }
721 }
722 }
723
724 /**
725 * Everything, the collector is interested of. Access must be synchronized.
726 * @author imi
727 */
728 private static class MouseState {
729 private final Point mousePos;
730 private final int modifiers;
731
732 MouseState(Point mousePos, int modifiers) {
733 this.mousePos = mousePos;
734 this.modifiers = modifiers;
735 }
736 }
737
738 private final transient AWTEventListener awtListener;
739
740 private final transient MouseMotionListener mouseMotionListener = new MouseMotionListener() {
741 @Override
742 public void mouseMoved(MouseEvent e) {
743 synchronized (collector) {
744 collector.updateMousePosition(e.getPoint(), e.getModifiersEx());
745 }
746 }
747
748 @Override
749 public void mouseDragged(MouseEvent e) {
750 mouseMoved(e);
751 }
752 };
753
754 private final transient KeyAdapter keyAdapter = new KeyAdapter() {
755 @Override public void keyPressed(KeyEvent e) {
756 synchronized (collector) {
757 collector.updateMousePosition(null, e.getModifiersEx());
758 }
759 }
760
761 @Override public void keyReleased(KeyEvent e) {
762 keyPressed(e);
763 }
764 };
765
766 /** see #19887: determine if the {@code distValue} field should be filled with length of selected object */
767 private boolean autoLength = true;
768
769 private void registerListeners() {
770 // Listen to keyboard/mouse events for pressing/releasing alt key and inform the collector.
771 try {
772 Toolkit.getDefaultToolkit().addAWTEventListener(awtListener,
773 AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
774 } catch (SecurityException ex) {
775 Logging.trace(ex);
776 mv.addMouseMotionListener(mouseMotionListener);
777 mv.addKeyListener(keyAdapter);
778 }
779 }
780
781 private void unregisterListeners() {
782 try {
783 Toolkit.getDefaultToolkit().removeAWTEventListener(awtListener);
784 } catch (SecurityException e) {
785 // Don't care, awtListener probably wasn't registered anyway
786 Logging.trace(e);
787 }
788 mv.removeMouseMotionListener(mouseMotionListener);
789 mv.removeKeyListener(keyAdapter);
790 }
791
792 private class MapStatusPopupMenu extends JPopupMenu {
793
794 private final JMenuItem jumpButton = add(MainApplication.getMenu().jumpToAct);
795
796 /** Icons for selecting {@link SystemOfMeasurement} */
797 private final Collection<JCheckBoxMenuItem> somItems = new ArrayList<>();
798 /** Icons for selecting {@link ICoordinateFormat} */
799 private final Collection<JCheckBoxMenuItem> coordinateFormatItems = new ArrayList<>();
800
801 private final JSeparator separator = new JSeparator();
802
803 private final JMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide status bar")) {
804 @Override
805 public void actionPerformed(ActionEvent e) {
806 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState();
807 Config.getPref().putBoolean("statusbar.always-visible", sel);
808 }
809 });
810
811 MapStatusPopupMenu() {
812 for (final SystemOfMeasurement som : SORTED_SYSTEM_OF_MEASUREMENTS) {
813 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new AbstractAction(som.toString()) {
814 @Override
815 public void actionPerformed(ActionEvent e) {
816 updateSystemOfMeasurement(som);
817 }
818 });
819 somItems.add(item);
820 add(item);
821 }
822 for (final ICoordinateFormat format : CoordinateFormatManager.getCoordinateFormats()) {
823 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new AbstractAction(format.getDisplayName()) {
824 @Override
825 public void actionPerformed(ActionEvent e) {
826 CoordinateFormatManager.setCoordinateFormat(format);
827 }
828 });
829 coordinateFormatItems.add(item);
830 add(item);
831 }
832
833 add(separator);
834 add(doNotHide);
835
836 addPopupMenuListener(new PopupMenuListener() {
837 @Override
838 public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
839 Component invoker = ((JPopupMenu) e.getSource()).getInvoker();
840 jumpButton.setVisible(latText.equals(invoker) || lonText.equals(invoker));
841 String currentSOM = SystemOfMeasurement.getSystemOfMeasurement().toString();
842 for (JMenuItem item : somItems) {
843 item.setSelected(item.getText().equals(currentSOM));
844 item.setVisible(distText.equals(invoker));
845 }
846 final String currentCorrdinateFormat = CoordinateFormatManager.getDefaultFormat().getDisplayName();
847 for (JMenuItem item : coordinateFormatItems) {
848 item.setSelected(currentCorrdinateFormat.equals(item.getText()));
849 item.setVisible(latText.equals(invoker) || lonText.equals(invoker));
850 }
851 separator.setVisible(distText.equals(invoker) || latText.equals(invoker) || lonText.equals(invoker));
852 doNotHide.setSelected(Config.getPref().getBoolean("statusbar.always-visible", true));
853 }
854
855 @Override
856 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
857 // Do nothing
858 }
859
860 @Override
861 public void popupMenuCanceled(PopupMenuEvent e) {
862 // Do nothing
863 }
864 });
865 }
866 }
867
868 /**
869 * Construct a new MapStatus and attach it to the map view.
870 * @param mapFrame The MapFrame the status line is part of.
871 */
872 public MapStatus(final MapFrame mapFrame) {
873 this.mv = mapFrame.mapView;
874 this.collector = new Collector(mapFrame);
875 this.awtListener = event -> {
876 if (event instanceof InputEvent &&
877 ((InputEvent) event).getComponent() == mv) {
878 synchronized (collector) {
879 int modifiers = ((InputEvent) event).getModifiersEx();
880 Point mousePos = null;
881 if (event instanceof MouseEvent) {
882 mousePos = ((MouseEvent) event).getPoint();
883 }
884 collector.updateMousePosition(mousePos, modifiers);
885 }
886 }
887 };
888
889 // Context menu of status bar
890 setComponentPopupMenu(new MapStatusPopupMenu());
891
892 // also show Jump To dialog on mouse click (except context menu)
893 MouseListener jumpToOnLeftClick = new JumpToOnLeftClickMouseAdapter();
894
895 // Listen for mouse movements and set the position text field
896 mv.addMouseMotionListener(new MouseMotionListener() {
897 @Override
898 public void mouseDragged(MouseEvent e) {
899 mouseMoved(e);
900 }
901
902 @Override
903 public void mouseMoved(MouseEvent e) {
904 if (mv.getCenter() == null)
905 return;
906 // Do not update the view if ctrl or right button is pressed.
907 if ((e.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.BUTTON3_DOWN_MASK)) == 0) {
908 updateLatLonText(e.getX(), e.getY());
909 }
910 }
911 });
912
913 setLayout(new GridBagLayout());
914 setBorder(BorderFactory.createEmptyBorder(1, 2, 1, 2));
915
916 latText.setForeground(PROP_FOREGROUND_COLOR.get());
917 lonText.setForeground(PROP_FOREGROUND_COLOR.get());
918 headingText.setForeground(PROP_FOREGROUND_COLOR.get());
919 distText.setForeground(PROP_FOREGROUND_COLOR.get());
920 nameText.setForeground(PROP_FOREGROUND_COLOR.get());
921
922 latText.setInheritsPopupMenu(true);
923 lonText.setInheritsPopupMenu(true);
924 headingText.setInheritsPopupMenu(true);
925 distText.setInheritsPopupMenu(true);
926 nameText.setInheritsPopupMenu(true);
927
928 add(latText, GBC.std());
929 add(lonText, GBC.std().insets(3, 0, 0, 0));
930 add(headingText, GBC.std().insets(3, 0, 0, 0));
931 add(angleText, GBC.std().insets(3, 0, 0, 0));
932 add(distText, GBC.std().insets(3, 0, 0, 0));
933
934 if (Config.getPref().getBoolean("statusbar.change-system-of-measurement-on-click", true)) {
935 distText.addMouseListener(new MouseAdapter() {
936 @Override
937 public void mouseClicked(MouseEvent e) {
938 if (!e.isPopupTrigger() && e.getButton() == MouseEvent.BUTTON1) {
939 SystemOfMeasurement som = SystemOfMeasurement.getSystemOfMeasurement();
940 int i = (SORTED_SYSTEM_OF_MEASUREMENTS.indexOf(som) + 1) % SORTED_SYSTEM_OF_MEASUREMENTS.size();
941 SystemOfMeasurement newsom = SORTED_SYSTEM_OF_MEASUREMENTS.get(i);
942 updateSystemOfMeasurement(newsom);
943 }
944 }
945 });
946 }
947
948 SystemOfMeasurement.addSoMChangeListener(this);
949 NavigatableComponent.addZoomChangeListener(this);
950
951 latText.addMouseListener(jumpToOnLeftClick);
952 lonText.addMouseListener(jumpToOnLeftClick);
953
954 helpText.setEditable(false);
955 add(nameText, GBC.std().insets(3, 0, 0, 0));
956 add(helpText, GBC.std().insets(3, 0, 0, 0).fill(GridBagConstraints.HORIZONTAL));
957
958 progressBar.setMaximum(PleaseWaitProgressMonitor.PROGRESS_BAR_MAX);
959 progressBar.setVisible(false);
960 GBC gbc = GBC.eol();
961 gbc.ipadx = 100;
962 add(progressBar, gbc);
963 progressBar.addMouseListener(new ShowMonitorDialogMouseAdapter());
964
965 Config.getPref().addPreferenceChangeListener(this);
966 DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT_CONSOLIDATED);
967 SelectionEventManager.getInstance().addSelectionListenerForEdt(this);
968
969 mvComponentAdapter = new ComponentAdapter() {
970 @Override
971 public void componentResized(ComponentEvent e) {
972 nameText.setCharCount(getNameLabelCharacterCount(MainApplication.getMainFrame()));
973 revalidate();
974 }
975 };
976 mv.addComponentListener(mvComponentAdapter);
977
978 // The background thread
979 thread = new Thread(collector, "Map Status Collector");
980 thread.setDaemon(true);
981 thread.start();
982 }
983
984 private void updateLatLonText(int x, int y) {
985 LatLon p = mv.getLatLon(x, y);
986 ICoordinateFormat mCord = CoordinateFormatManager.getDefaultFormat();
987 latText.setText(mCord.latToString(p));
988 lonText.setText(mCord.lonToString(p));
989 if (Objects.equals(previousCoordinateFormat, mCord)) {
990 // do nothing
991 } else if (ProjectedCoordinateFormat.INSTANCE.equals(mCord)) {
992 latText.setIcon("northing");
993 lonText.setIcon("easting");
994 latText.setToolTipText(tr("The northing at the mouse pointer."));
995 lonText.setToolTipText(tr("The easting at the mouse pointer."));
996 previousCoordinateFormat = mCord;
997 } else {
998 latText.setIcon("lat");
999 lonText.setIcon("lon");
1000 latText.setToolTipText(tr("The geographic latitude at the mouse pointer."));
1001 lonText.setToolTipText(tr("The geographic longitude at the mouse pointer."));
1002 previousCoordinateFormat = mCord;
1003 }
1004 }
1005
1006 @Override
1007 public void systemOfMeasurementChanged(String oldSoM, String newSoM) {
1008 setDist(distValue);
1009 }
1010
1011 /**
1012 * Updates the system of measurement and displays a notification.
1013 * @param som The new system of measurement to set
1014 * @since 6960
1015 */
1016 public void updateSystemOfMeasurement(SystemOfMeasurement som) {
1017 SystemOfMeasurement.setSystemOfMeasurement(som);
1018 if (Config.getPref().getBoolean("statusbar.notify.change-system-of-measurement", true)) {
1019 new Notification(tr("System of measurement changed to {0}", som.toString()))
1020 .setIcon(JOptionPane.INFORMATION_MESSAGE)
1021 .setDuration(Notification.TIME_SHORT)
1022 .show();
1023 }
1024 }
1025
1026 /**
1027 * Gets the panel that displays the angle
1028 * @return The angle panel
1029 */
1030 public JPanel getAnglePanel() {
1031 return angleText;
1032 }
1033
1034 @Override
1035 public String helpTopic() {
1036 return ht("/StatusBar");
1037 }
1038
1039 @Override
1040 public synchronized void addMouseListener(MouseListener ml) {
1041 lonText.addMouseListener(ml);
1042 latText.addMouseListener(ml);
1043 }
1044
1045 /**
1046 * Sets the help text in the status panel
1047 * @param text The text
1048 */
1049 public void setHelpText(String text) {
1050 setHelpText(null, text);
1051 }
1052
1053 /**
1054 * Sets the help status text to display
1055 * @param id The object that caused the status update (or a id object it selects). May be <code>null</code>
1056 * @param text The text
1057 */
1058 public synchronized void setHelpText(Object id, final String text) {
1059 StatusTextHistory entry = new StatusTextHistory(id, text);
1060
1061 statusText.remove(entry);
1062 statusText.add(entry);
1063
1064 GuiHelper.runInEDT(() -> {
1065 helpText.setText(text);
1066 helpText.setToolTipText(text);
1067 });
1068 }
1069
1070 /**
1071 * Removes a help text and restores the previous one
1072 * @param id The id passed to {@link #setHelpText(Object, String)}
1073 */
1074 public synchronized void resetHelpText(Object id) {
1075 if (statusText.isEmpty())
1076 return;
1077
1078 StatusTextHistory entry = new StatusTextHistory(id, null);
1079 if (statusText.get(statusText.size() - 1).equals(entry)) {
1080 if (statusText.size() == 1) {
1081 setHelpText("");
1082 } else {
1083 StatusTextHistory history = statusText.get(statusText.size() - 2);
1084 setHelpText(history.id, history.text);
1085 }
1086 }
1087 statusText.remove(entry);
1088 }
1089
1090 /**
1091 * Sets the angle to display in the angle panel. Values less than 0 yield "--".
1092 * @param a The angle
1093 * @see #setAngleNaN
1094 * @see #setAngleText
1095 */
1096 public void setAngle(double a) {
1097 angleText.setText(a < 0 ? "--" : DECIMAL_FORMAT.format(a) + " \u00B0");
1098 }
1099
1100 /**
1101 * Sets the angle to display in the angle panel. NaN yields "--".
1102 * @param a The angle
1103 * @see #setAngle
1104 * @see #setAngleText
1105 */
1106 public void setAngleNaN(double a) {
1107 angleText.setText(!Double.isFinite(a) ? "--" : DECIMAL_FORMAT.format(a) + " \u00B0");
1108 }
1109
1110 /**
1111 * Sets the angle to display in the angle panel
1112 * @param text The angle text
1113 */
1114 public void setAngleText(String text) {
1115 angleText.setText(text);
1116 }
1117
1118 /**
1119 * Sets the heading to display in the heading panel
1120 * @param h The heading
1121 */
1122 public void setHeading(double h) {
1123 headingText.setText(h < 0 ? "--" : DECIMAL_FORMAT.format(h) + " \u00B0");
1124 }
1125
1126 /**
1127 * Sets the distance text to the given value
1128 * @param dist The distance value to display, in meters
1129 */
1130 public void setDist(double dist) {
1131 distValue = dist;
1132 distText.setText(dist < 0 ? "--" : NavigatableComponent.getDistText(dist, DECIMAL_FORMAT, DISTANCE_THRESHOLD.get()));
1133 }
1134
1135 /**
1136 * Sets the distance text to the total sum of given ways length
1137 * @param ways The ways to consider for the total distance
1138 * @since 5991
1139 */
1140 public void setDist(Collection<Way> ways) {
1141 double dist = -1;
1142 // Compute total length of selected way(s) until an arbitrary limit set to 250 ways
1143 // in order to prevent performance issue if a large number of ways are selected (old behaviour kept in that case, see #8403)
1144 int maxWays = Math.max(1, Config.getPref().getInt("selection.max-ways-for-statusline", 250));
1145 if (!ways.isEmpty() && ways.size() <= maxWays) {
1146 dist = ways.stream().mapToDouble(Way::getLength).sum();
1147 }
1148 setDist(dist);
1149 }
1150
1151 /**
1152 * Activates the angle panel.
1153 * @param activeFlag {@code true} to activate it, {@code false} to deactivate it
1154 */
1155 public void activateAnglePanel(boolean activeFlag) {
1156 angleEnabled = activeFlag;
1157 refreshAnglePanel();
1158 }
1159
1160 private void refreshAnglePanel() {
1161 angleText.setBackground(angleEnabled ? PROP_ACTIVE_BACKGROUND_COLOR.get() : PROP_BACKGROUND_COLOR.get());
1162 angleText.setForeground(angleEnabled ? PROP_ACTIVE_FOREGROUND_COLOR.get() : PROP_FOREGROUND_COLOR.get());
1163 }
1164
1165 @Override
1166 public void destroy() {
1167 SystemOfMeasurement.removeSoMChangeListener(this);
1168 NavigatableComponent.removeZoomChangeListener(this);
1169 Config.getPref().removePreferenceChangeListener(this);
1170 DatasetEventManager.getInstance().removeDatasetListener(this);
1171 SelectionEventManager.getInstance().removeSelectionListener(this);
1172 mv.removeComponentListener(mvComponentAdapter);
1173
1174 // MapFrame gets destroyed when the last layer is removed, but the status line background
1175 // thread that collects the information doesn't get destroyed automatically.
1176 if (thread != null) {
1177 try {
1178 thread.interrupt();
1179 } catch (SecurityException e) {
1180 Logging.error(e);
1181 }
1182 }
1183 }
1184
1185 @Override
1186 public void preferenceChanged(PreferenceChangeEvent e) {
1187 String key = e.getKey();
1188 if (key.startsWith(NamedColorProperty.NAMED_COLOR_PREFIX)) {
1189 if (PROP_BACKGROUND_COLOR.getKey().equals(key) || PROP_FOREGROUND_COLOR.getKey().equals(key)) {
1190 for (ImageLabel il : new ImageLabel[]{latText, lonText, headingText, distText, nameText}) {
1191 il.setBackground(PROP_BACKGROUND_COLOR.get());
1192 il.setForeground(PROP_FOREGROUND_COLOR.get());
1193 }
1194 refreshAnglePanel();
1195 } else if (PROP_ACTIVE_BACKGROUND_COLOR.getKey().equals(key) || PROP_ACTIVE_FOREGROUND_COLOR.getKey().equals(key)) {
1196 refreshAnglePanel();
1197 }
1198 }
1199 }
1200
1201 /**
1202 * Loads all colors from preferences.
1203 * @since 6789
1204 */
1205 public static void getColors() {
1206 PROP_BACKGROUND_COLOR.get();
1207 PROP_FOREGROUND_COLOR.get();
1208 PROP_ACTIVE_BACKGROUND_COLOR.get();
1209 PROP_ACTIVE_FOREGROUND_COLOR.get();
1210 }
1211
1212 private static int getNameLabelCharacterCount(Component parent) {
1213 int w = parent != null ? parent.getWidth() : 800;
1214 return Math.min(80, 20 + Math.max(0, w-1280) * 60 / (1920-1280));
1215 }
1216
1217 private void refreshDistText(Collection<? extends OsmPrimitive> newSelection) {
1218 if (!autoLength) {
1219 return;
1220 }
1221
1222 if (newSelection.size() == 2) {
1223 Iterator<? extends OsmPrimitive> it = newSelection.iterator();
1224 OsmPrimitive n1 = it.next();
1225 OsmPrimitive n2 = it.next();
1226 // show distance between two selected nodes with coordinates
1227 if (n1 instanceof ILatLon && n2 instanceof ILatLon && ((ILatLon) n1).isLatLonKnown() && ((ILatLon) n2).isLatLonKnown()) {
1228 setDist(((ILatLon) n1).greatCircleDistance((ILatLon) n2));
1229 return;
1230 }
1231 }
1232 setDist(new SubclassFilteredCollection<>(newSelection, Way.class::isInstance));
1233 }
1234
1235 @Override
1236 public void selectionChanged(SelectionChangeEvent event) {
1237 refreshDistText(event.getSelection());
1238 }
1239
1240 @Override
1241 public void zoomChanged() {
1242 if (!GraphicsEnvironment.isHeadless()) {
1243 try {
1244 PointerInfo pointerInfo = MouseInfo.getPointerInfo();
1245 if (pointerInfo != null) {
1246 Point mp = pointerInfo.getLocation();
1247 updateLatLonText(mp.x, mp.y);
1248 }
1249 } catch (SecurityException ex) {
1250 Logging.log(Logging.LEVEL_ERROR, "Unable to get mouse pointer info", ex);
1251 }
1252 }
1253 }
1254
1255 @Override
1256 public void wayNodesChanged(WayNodesChangedEvent event) {
1257 refreshDistText(event.getDataset().getSelected());
1258 }
1259
1260 @Override
1261 public void nodeMoved(NodeMovedEvent event) {
1262 refreshDistText(event.getDataset().getSelected());
1263 }
1264
1265 @Override
1266 public void primitivesAdded(PrimitivesAddedEvent event) {
1267 // Do nothing
1268 }
1269
1270 @Override
1271 public void primitivesRemoved(PrimitivesRemovedEvent event) {
1272 // Do nothing
1273 }
1274
1275 @Override
1276 public void tagsChanged(TagsChangedEvent event) {
1277 // Do nothing
1278 }
1279
1280 @Override
1281 public void relationMembersChanged(RelationMembersChangedEvent event) {
1282 // Do nothing
1283 }
1284
1285 @Override
1286 public void otherDatasetChange(AbstractDatasetChangedEvent event) {
1287 // Do nothing
1288 }
1289
1290 @Override
1291 public void dataChanged(DataChangedEvent event) {
1292 if (event.getDataset() != null) {
1293 refreshDistText(event.getDataset().getSelected());
1294 }
1295 }
1296
1297 /**
1298 * Enable or disable the automatic refresh of the length field.
1299 * @param b if {@code true} the automatic refresh is enabled, else disabled
1300 * @since 17108
1301 */
1302 public void setAutoLength(boolean b) {
1303 autoLength = b;
1304 }
1305
1306}
Note: See TracBrowser for help on using the repository browser.