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

Last change on this file since 5051 was 5051, checked in by xeen, 12 years ago

fix #7036

  • Property svn:eol-style set to native
File size: 31.4 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.AWTEvent;
8import java.awt.Color;
9import java.awt.Component;
10import java.awt.Cursor;
11import java.awt.Dimension;
12import java.awt.EventQueue;
13import java.awt.Font;
14import java.awt.GridBagLayout;
15import java.awt.Point;
16import java.awt.SystemColor;
17import java.awt.Toolkit;
18import java.awt.event.AWTEventListener;
19import java.awt.event.InputEvent;
20import java.awt.event.KeyAdapter;
21import java.awt.event.KeyEvent;
22import java.awt.event.MouseAdapter;
23import java.awt.event.MouseEvent;
24import java.awt.event.MouseListener;
25import java.awt.event.MouseMotionListener;
26import java.util.ArrayList;
27import java.util.Collection;
28import java.util.ConcurrentModificationException;
29import java.util.List;
30
31import javax.swing.BorderFactory;
32import javax.swing.JLabel;
33import javax.swing.JPanel;
34import javax.swing.JProgressBar;
35import javax.swing.JScrollPane;
36import javax.swing.JTextField;
37import javax.swing.Popup;
38import javax.swing.PopupFactory;
39import javax.swing.UIManager;
40
41import org.openstreetmap.josm.Main;
42import org.openstreetmap.josm.data.coor.CoordinateFormat;
43import org.openstreetmap.josm.data.coor.LatLon;
44import org.openstreetmap.josm.data.osm.DataSet;
45import org.openstreetmap.josm.data.osm.OsmPrimitive;
46import org.openstreetmap.josm.gui.help.Helpful;
47import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
48import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog;
49import org.openstreetmap.josm.tools.GBC;
50import org.openstreetmap.josm.tools.ImageProvider;
51
52/**
53 * A component that manages some status information display about the map.
54 * It keeps a status line below the map up to date and displays some tooltip
55 * information if the user hold the mouse long enough at some point.
56 *
57 * All this is done in background to not disturb other processes.
58 *
59 * The background thread does not alter any data of the map (read only thread).
60 * Also it is rather fail safe. In case of some error in the data, it just does
61 * nothing instead of whining and complaining.
62 *
63 * @author imi
64 */
65public class MapStatus extends JPanel implements Helpful {
66
67 /**
68 * The MapView this status belongs to.
69 */
70 final MapView mv;
71 final Collector collector;
72
73 /**
74 * A small user interface component that consists of an image label and
75 * a fixed text content to the right of the image.
76 */
77 static class ImageLabel extends JPanel {
78 private JLabel tf;
79 private int chars;
80 public ImageLabel(String img, String tooltip, int chars) {
81 super();
82 setLayout(new GridBagLayout());
83 setBackground(Color.decode("#b8cfe5"));
84 add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));
85 add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));
86 setToolTipText(tooltip);
87 this.chars = chars;
88 }
89 public void setText(String t) {
90 tf.setText(t);
91 }
92 @Override public Dimension getPreferredSize() {
93 return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);
94 }
95 @Override public Dimension getMinimumSize() {
96 return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);
97 }
98 }
99
100 public class BackgroundProgressMonitor implements ProgressMonitorDialog {
101
102 private String title;
103 private String customText;
104
105 private void updateText() {
106 if (customText != null && !customText.isEmpty()) {
107 progressBar.setToolTipText(tr("{0} ({1})", title, customText));
108 } else {
109 progressBar.setToolTipText(title);
110 }
111 }
112
113 public void setVisible(boolean visible) {
114 progressBar.setVisible(visible);
115 }
116
117 public void updateProgress(int progress) {
118 progressBar.setValue(progress);
119 MapStatus.this.doLayout();
120 }
121
122 public void setCustomText(String text) {
123 this.customText = text;
124 updateText();
125 }
126
127 public void setCurrentAction(String text) {
128 this.title = text;
129 updateText();
130 }
131
132 public void setIndeterminate(boolean newValue) {
133 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
134 progressBar.setIndeterminate(newValue);
135 }
136
137 @Override
138 public void appendLogMessage(String message) {
139 if (message != null && !message.isEmpty()) {
140 System.out.println("appendLogMessage not implemented for background tasks. Message was: " + message);
141 }
142 }
143
144 }
145
146 final ImageLabel lonText = new ImageLabel("lon", tr("The geographic longitude at the mouse pointer."), 11);
147 final ImageLabel nameText = new ImageLabel("name", tr("The name of the object at the mouse pointer."), 20);
148 final JTextField helpText = new JTextField();
149 final ImageLabel latText = new ImageLabel("lat", tr("The geographic latitude at the mouse pointer."), 11);
150 final ImageLabel angleText = new ImageLabel("angle", tr("The angle between the previous and the current way segment."), 6);
151 final ImageLabel headingText = new ImageLabel("heading", tr("The (compass) heading of the line segment being drawn."), 6);
152 final ImageLabel distText = new ImageLabel("dist", tr("The length of the new way segment being drawn."), 10);
153 final JProgressBar progressBar = new JProgressBar();
154 public final BackgroundProgressMonitor progressMonitor = new BackgroundProgressMonitor();
155
156 /**
157 * This is the thread that runs in the background and collects the information displayed.
158 * It gets destroyed by MapFrame.java/destroy() when the MapFrame itself is destroyed.
159 */
160 public Thread thread;
161
162 private final List<StatusTextHistory> statusText = new ArrayList<StatusTextHistory>();
163
164 private static class StatusTextHistory {
165 final Object id;
166 final String text;
167
168 public StatusTextHistory(Object id, String text) {
169 this.id = id;
170 this.text = text;
171 }
172
173 @Override
174 public boolean equals(Object obj) {
175 return obj instanceof StatusTextHistory && ((StatusTextHistory)obj).id == id;
176 }
177
178 @Override
179 public int hashCode() {
180 return System.identityHashCode(id);
181 }
182 }
183
184 /**
185 * The collector class that waits for notification and then update
186 * the display objects.
187 *
188 * @author imi
189 */
190 private final class Collector implements Runnable {
191 /**
192 * the mouse position of the previous iteration. This is used to show
193 * the popup until the cursor is moved.
194 */
195 private Point oldMousePos;
196 /**
197 * Contains the labels that are currently shown in the information
198 * popup
199 */
200 private List<JLabel> popupLabels = null;
201 /**
202 * The popup displayed to show additional information
203 */
204 private Popup popup;
205
206 private MapFrame parent;
207
208 public Collector(MapFrame parent) {
209 this.parent = parent;
210 }
211
212 /**
213 * Execution function for the Collector.
214 */
215 public void run() {
216 registerListeners();
217 try {
218 for (;;) {
219
220 final MouseState ms = new MouseState();
221 synchronized (this) {
222 // TODO Would be better if the timeout wasn't necessary
223 try {wait(1000);} catch (InterruptedException e) {}
224 ms.modifiers = mouseState.modifiers;
225 ms.mousePos = mouseState.mousePos;
226 }
227 if (parent != Main.map)
228 return; // exit, if new parent.
229
230 // Do nothing, if required data is missing
231 if(ms.mousePos == null || mv.center == null) {
232 continue;
233 }
234
235 try {
236 EventQueue.invokeAndWait(new Runnable() {
237
238 @Override
239 public void run() {
240 // Freeze display when holding down CTRL
241 if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0) {
242 // update the information popup's labels though, because
243 // the selection might have changed from the outside
244 popupUpdateLabels();
245 return;
246 }
247
248 // This try/catch is a hack to stop the flooding bug reports about this.
249 // The exception needed to handle with in the first place, means that this
250 // access to the data need to be restarted, if the main thread modifies
251 // the data.
252 DataSet ds = null;
253 // The popup != null check is required because a left-click
254 // produces several events as well, which would make this
255 // variable true. Of course we only want the popup to show
256 // if the middle mouse button has been pressed in the first
257 // place
258 boolean mouseNotMoved = oldMousePos != null
259 && oldMousePos.equals(ms.mousePos);
260 boolean isAtOldPosition = mouseNotMoved && popup != null;
261 boolean middleMouseDown = (ms.modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0;
262 try {
263 ds = mv.getCurrentDataSet();
264 if (ds != null) {
265 // This is not perfect, if current dataset was changed during execution, the lock would be useless
266 if(isAtOldPosition && middleMouseDown) {
267 // Write lock is necessary when selecting in popupCycleSelection
268 // locks can not be upgraded -> if do read lock here and write lock later (in OsmPrimitive.updateFlags)
269 // then always occurs deadlock (#5814)
270 ds.beginUpdate();
271 } else {
272 ds.getReadLock().lock();
273 }
274 }
275
276 // Set the text label in the bottom status bar
277 // "if mouse moved only" was added to stop heap growing
278 if (!mouseNotMoved) statusBarElementUpdate(ms);
279
280
281 // Popup Information
282 // display them if the middle mouse button is pressed and
283 // keep them until the mouse is moved
284 if (middleMouseDown || isAtOldPosition)
285 {
286 Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos, OsmPrimitive.isUsablePredicate);
287
288 if (osms == null)
289 return;
290
291 final JPanel c = new JPanel(new GridBagLayout());
292 final JLabel lbl = new JLabel(
293 "<html>"+tr("Middle click again to cycle through.<br>"+
294 "Hold CTRL to select directly from this list with the mouse.<hr>")+"</html>",
295 null,
296 JLabel.HORIZONTAL
297 );
298 lbl.setHorizontalAlignment(JLabel.LEFT);
299 c.add(lbl, GBC.eol().insets(2, 0, 2, 0));
300
301 // Only cycle if the mouse has not been moved and the
302 // middle mouse button has been pressed at least twice
303 // (the reason for this is the popup != null check for
304 // isAtOldPosition, see above. This is a nice side
305 // effect though, because it does not change selection
306 // of the first middle click)
307 if(isAtOldPosition && middleMouseDown) {
308 // Hand down mouse modifiers so the SHIFT mod can be
309 // handled correctly (see funcion)
310 popupCycleSelection(osms, ms.modifiers);
311 }
312
313 // These labels may need to be updated from the outside
314 // so collect them
315 List<JLabel> lbls = new ArrayList<JLabel>();
316 for (final OsmPrimitive osm : osms) {
317 JLabel l = popupBuildPrimitiveLabels(osm);
318 lbls.add(l);
319 c.add(l, GBC.eol().fill(GBC.HORIZONTAL).insets(2, 0, 2, 2));
320 }
321
322 popupShowPopup(popupCreatePopup(c, ms), lbls);
323 } else {
324 popupHidePopup();
325 }
326
327 oldMousePos = ms.mousePos;
328 } catch (ConcurrentModificationException x) {
329 //x.printStackTrace();
330 } catch (NullPointerException x) {
331 //x.printStackTrace();
332 } finally {
333 if (ds != null) {
334 if(isAtOldPosition && middleMouseDown) {
335 ds.endUpdate();
336 } else {
337 ds.getReadLock().unlock();
338 }
339 }
340 }
341 }
342 });
343 } catch (Exception e) {
344
345 }
346 }
347 } finally {
348 unregisterListeners();
349 }
350 }
351
352 /**
353 * Creates a popup for the given content next to the cursor. Tries to
354 * keep the popup on screen and shows a vertical scrollbar, if the
355 * screen is too small.
356 * @param content
357 * @param ms
358 * @return popup
359 */
360 private final Popup popupCreatePopup(Component content, MouseState ms) {
361 Point p = mv.getLocationOnScreen();
362 Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize();
363
364 // Create a JScrollPane around the content, in case there's not
365 // enough space
366 JScrollPane sp = new JScrollPane(content);
367 sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
368 sp.setBorder(BorderFactory.createRaisedBevelBorder());
369 // Implement max-size content-independent
370 Dimension prefsize = sp.getPreferredSize();
371 int w = Math.min(prefsize.width, Math.min(800, (scrn.width/2) - 16));
372 int h = Math.min(prefsize.height, scrn.height - 10);
373 sp.setPreferredSize(new Dimension(w, h));
374
375 int xPos = p.x + ms.mousePos.x + 16;
376 // Display the popup to the left of the cursor if it would be cut
377 // off on its right, but only if more space is available
378 if(xPos + w > scrn.width && xPos > scrn.width/2) {
379 xPos = p.x + ms.mousePos.x - 4 - w;
380 }
381 int yPos = p.y + ms.mousePos.y + 16;
382 // Move the popup up if it would be cut off at its bottom but do not
383 // move it off screen on the top
384 if(yPos + h > scrn.height - 5) {
385 yPos = Math.max(5, scrn.height - h - 5);
386 }
387
388 PopupFactory pf = PopupFactory.getSharedInstance();
389 return pf.getPopup(mv, sp, xPos, yPos);
390 }
391
392 /**
393 * Calls this to update the element that is shown in the statusbar
394 * @param ms
395 */
396 private final void statusBarElementUpdate(MouseState ms) {
397 final OsmPrimitive osmNearest = mv.getNearestNodeOrWay(ms.mousePos, OsmPrimitive.isUsablePredicate, false);
398 if (osmNearest != null) {
399 nameText.setText(osmNearest.getDisplayName(DefaultNameFormatter.getInstance()));
400 } else {
401 nameText.setText(tr("(no object)"));
402 }
403 }
404
405 /**
406 * Call this with a set of primitives to cycle through them. Method
407 * will automatically select the next item and update the map
408 * @param osms
409 * @param mouse modifiers
410 */
411 private final void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {
412 DataSet ds = Main.main.getCurrentDataSet();
413 // Find some items that are required for cycling through
414 OsmPrimitive firstItem = null;
415 OsmPrimitive firstSelected = null;
416 OsmPrimitive nextSelected = null;
417 for (final OsmPrimitive osm : osms) {
418 if(firstItem == null) {
419 firstItem = osm;
420 }
421 if(firstSelected != null && nextSelected == null) {
422 nextSelected = osm;
423 }
424 if(firstSelected == null && ds.isSelected(osm)) {
425 firstSelected = osm;
426 }
427 }
428
429 // Clear previous selection if SHIFT (add to selection) is not
430 // pressed. Cannot use "setSelected()" because it will cause a
431 // fireSelectionChanged event which is unnecessary at this point.
432 if((mods & MouseEvent.SHIFT_DOWN_MASK) == 0) {
433 ds.clearSelection();
434 }
435
436 // This will cycle through the available items.
437 if(firstSelected == null) {
438 ds.addSelected(firstItem);
439 } else {
440 ds.clearSelection(firstSelected);
441 if(nextSelected != null) {
442 ds.addSelected(nextSelected);
443 }
444 }
445 }
446
447 /**
448 * Tries to hide the given popup
449 * @param popup
450 */
451 private final void popupHidePopup() {
452 popupLabels = null;
453 if(popup == null)
454 return;
455 final Popup staticPopup = popup;
456 popup = null;
457 EventQueue.invokeLater(new Runnable(){
458 public void run() { staticPopup.hide(); }});
459 }
460
461 /**
462 * Tries to show the given popup, can be hidden using popupHideOldPopup
463 * If an old popup exists, it will be automatically hidden
464 * @param popup
465 */
466 private final void popupShowPopup(Popup newPopup, List<JLabel> lbls) {
467 final Popup staticPopup = newPopup;
468 if(this.popup != null) {
469 // If an old popup exists, remove it when the new popup has been
470 // drawn to keep flickering to a minimum
471 final Popup staticOldPopup = this.popup;
472 EventQueue.invokeLater(new Runnable(){
473 public void run() {
474 staticPopup.show();
475 staticOldPopup.hide();
476 }
477 });
478 } else {
479 // There is no old popup
480 EventQueue.invokeLater(new Runnable(){
481 public void run() { staticPopup.show(); }});
482 }
483 this.popupLabels = lbls;
484 this.popup = newPopup;
485 }
486
487 /**
488 * This method should be called if the selection may have changed from
489 * outside of this class. This is the case when CTRL is pressed and the
490 * user clicks on the map instead of the popup.
491 */
492 private final void popupUpdateLabels() {
493 if(this.popup == null || this.popupLabels == null)
494 return;
495 for(JLabel l : this.popupLabels) {
496 l.validate();
497 }
498 }
499
500 /**
501 * Sets the colors for the given label depending on the selected status of
502 * the given OsmPrimitive
503 *
504 * @param lbl The label to color
505 * @param osm The primitive to derive the colors from
506 */
507 private final void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {
508 DataSet ds = Main.main.getCurrentDataSet();
509 if(ds.isSelected(osm)) {
510 lbl.setBackground(SystemColor.textHighlight);
511 lbl.setForeground(SystemColor.textHighlightText);
512 } else {
513 lbl.setBackground(SystemColor.control);
514 lbl.setForeground(SystemColor.controlText);
515 }
516 }
517
518 /**
519 * Builds the labels with all necessary listeners for the info popup for the
520 * given OsmPrimitive
521 * @param osm The primitive to create the label for
522 * @return
523 */
524 private final JLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) {
525 final StringBuilder text = new StringBuilder();
526 String name = osm.getDisplayName(DefaultNameFormatter.getInstance());
527 if (osm.isNewOrUndeleted() || osm.isModified()) {
528 name = "<i><b>"+ name + "*</b></i>";
529 }
530 text.append(name);
531
532 if (!osm.isNew()) {
533 text.append(" [id="+osm.getId()+"]");
534 }
535
536 if(osm.getUser() != null) {
537 text.append(" [" + tr("User:") + " " + osm.getUser().getName() + "]");
538 }
539
540 for (String key : osm.keySet()) {
541 text.append("<br>" + key + "=" + osm.get(key));
542 }
543
544 final JLabel l = new JLabel(
545 "<html>" +text.toString() + "</html>",
546 ImageProvider.get(osm.getDisplayType()),
547 JLabel.HORIZONTAL
548 ) {
549 // This is necessary so the label updates its colors when the
550 // selection is changed from the outside
551 @Override public void validate() {
552 super.validate();
553 popupSetLabelColors(this, osm);
554 }
555 };
556 l.setOpaque(true);
557 popupSetLabelColors(l, osm);
558 l.setFont(l.getFont().deriveFont(Font.PLAIN));
559 l.setVerticalTextPosition(JLabel.TOP);
560 l.setHorizontalAlignment(JLabel.LEFT);
561 l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
562 l.addMouseListener(new MouseAdapter(){
563 @Override public void mouseEntered(MouseEvent e) {
564 l.setBackground(SystemColor.info);
565 l.setForeground(SystemColor.infoText);
566 }
567 @Override public void mouseExited(MouseEvent e) {
568 popupSetLabelColors(l, osm);
569 }
570 @Override public void mouseClicked(MouseEvent e) {
571 DataSet ds = Main.main.getCurrentDataSet();
572 // Let the user toggle the selection
573 ds.toggleSelected(osm);
574 l.validate();
575 }
576 });
577 // Sometimes the mouseEntered event is not catched, thus the label
578 // will not be highlighted, making it confusing. The MotionListener
579 // can correct this defect.
580 l.addMouseMotionListener(new MouseMotionListener() {
581 public void mouseMoved(MouseEvent e) {
582 l.setBackground(SystemColor.info);
583 l.setForeground(SystemColor.infoText);
584 }
585 public void mouseDragged(MouseEvent e) {
586 l.setBackground(SystemColor.info);
587 l.setForeground(SystemColor.infoText);
588 }
589 });
590 return l;
591 }
592 }
593
594 /**
595 * Everything, the collector is interested of. Access must be synchronized.
596 * @author imi
597 */
598 static class MouseState {
599 Point mousePos;
600 int modifiers;
601 }
602 /**
603 * The last sent mouse movement event.
604 */
605 MouseState mouseState = new MouseState();
606
607 private AWTEventListener awtListener = new AWTEventListener() {
608 public void eventDispatched(AWTEvent event) {
609 if (event instanceof InputEvent &&
610 ((InputEvent)event).getComponent() == mv) {
611 synchronized (collector) {
612 mouseState.modifiers = ((InputEvent)event).getModifiersEx();
613 if (event instanceof MouseEvent) {
614 mouseState.mousePos = ((MouseEvent)event).getPoint();
615 }
616 collector.notify();
617 }
618 }
619 }
620 };
621
622 private MouseMotionListener mouseMotionListener = new MouseMotionListener() {
623 public void mouseMoved(MouseEvent e) {
624 synchronized (collector) {
625 mouseState.modifiers = e.getModifiersEx();
626 mouseState.mousePos = e.getPoint();
627 collector.notify();
628 }
629 }
630
631 public void mouseDragged(MouseEvent e) {
632 mouseMoved(e);
633 }
634 };
635
636 private KeyAdapter keyAdapter = new KeyAdapter() {
637 @Override public void keyPressed(KeyEvent e) {
638 synchronized (collector) {
639 mouseState.modifiers = e.getModifiersEx();
640 collector.notify();
641 }
642 }
643
644 @Override public void keyReleased(KeyEvent e) {
645 keyPressed(e);
646 }
647 };
648
649 private void registerListeners() {
650 // Listen to keyboard/mouse events for pressing/releasing alt key and
651 // inform the collector.
652 try {
653 Toolkit.getDefaultToolkit().addAWTEventListener(awtListener,
654 AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
655 } catch (SecurityException ex) {
656 mv.addMouseMotionListener(mouseMotionListener);
657 mv.addKeyListener(keyAdapter);
658 }
659 }
660
661 private void unregisterListeners() {
662 try {
663 Toolkit.getDefaultToolkit().removeAWTEventListener(awtListener);
664 } catch (SecurityException e) {
665 // Don't care, awtListener probably wasn't registered anyway
666 }
667 mv.removeMouseMotionListener(mouseMotionListener);
668 mv.removeKeyListener(keyAdapter);
669 }
670
671
672 /**
673 * Construct a new MapStatus and attach it to the map view.
674 * @param mapFrame The MapFrame the status line is part of.
675 */
676 public MapStatus(final MapFrame mapFrame) {
677 this.mv = mapFrame.mapView;
678 this.collector = new Collector(mapFrame);
679
680 lonText.addMouseListener(Main.main.menu.jumpToAct);
681 latText.addMouseListener(Main.main.menu.jumpToAct);
682
683 // Listen for mouse movements and set the position text field
684 mv.addMouseMotionListener(new MouseMotionListener(){
685 public void mouseDragged(MouseEvent e) {
686 mouseMoved(e);
687 }
688 public void mouseMoved(MouseEvent e) {
689 if (mv.center == null)
690 return;
691 // Do not update the view if ctrl is pressed.
692 if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == 0) {
693 CoordinateFormat mCord = CoordinateFormat.getDefaultFormat();
694 LatLon p = mv.getLatLon(e.getX(),e.getY());
695 latText.setText(p.latToString(mCord));
696 lonText.setText(p.lonToString(mCord));
697 }
698 }
699 });
700
701 setLayout(new GridBagLayout());
702 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
703
704 add(latText, GBC.std());
705 add(lonText, GBC.std().insets(3,0,0,0));
706 add(headingText, GBC.std().insets(3,0,0,0));
707 add(angleText, GBC.std().insets(3,0,0,0));
708 add(distText, GBC.std().insets(3,0,0,0));
709
710 helpText.setEditable(false);
711 add(nameText, GBC.std().insets(3,0,0,0));
712 add(helpText, GBC.std().insets(3,0,0,0).fill(GBC.HORIZONTAL));
713
714 progressBar.setMaximum(PleaseWaitProgressMonitor.PROGRESS_BAR_MAX);
715 progressBar.setVisible(false);
716 GBC gbc = GBC.eol();
717 gbc.ipadx = 100;
718 add(progressBar,gbc);
719 progressBar.addMouseListener(new MouseAdapter() {
720 @Override
721 public void mouseClicked(MouseEvent e) {
722 PleaseWaitProgressMonitor monitor = Main.currentProgressMonitor;
723 if (monitor != null) {
724 monitor.showForegroundDialog();
725 }
726 }
727 });
728
729 // The background thread
730 thread = new Thread(collector, "Map Status Collector");
731 thread.setDaemon(true);
732 thread.start();
733 }
734
735 public JPanel getAnglePanel() {
736 return angleText;
737 }
738
739 public String helpTopic() {
740 return ht("/Statusline");
741 }
742
743 @Override
744 public synchronized void addMouseListener(MouseListener ml) {
745 //super.addMouseListener(ml);
746 lonText.addMouseListener(ml);
747 latText.addMouseListener(ml);
748 }
749
750 public void setHelpText(String t) {
751 setHelpText(null, t);
752 }
753 public void setHelpText(Object id, String text) {
754
755 StatusTextHistory entry = new StatusTextHistory(id, text);
756
757 statusText.remove(entry);
758 statusText.add(entry);
759
760 helpText.setText(text);
761 helpText.setToolTipText(text);
762 }
763 public void resetHelpText(Object id) {
764 if (statusText.isEmpty())
765 return;
766
767 StatusTextHistory entry = new StatusTextHistory(id, null);
768 if (statusText.get(statusText.size() - 1).equals(entry)) {
769 if (statusText.size() == 1) {
770 setHelpText("");
771 } else {
772 StatusTextHistory history = statusText.get(statusText.size() - 2);
773 setHelpText(history.id, history.text);
774 }
775 }
776 statusText.remove(entry);
777 }
778 public void setAngle(double a) {
779 angleText.setText(a < 0 ? "--" : Math.round(a*10)/10.0 + " \u00B0");
780 }
781 public void setHeading(double h) {
782 headingText.setText(h < 0 ? "--" : Math.round(h*10)/10.0 + " \u00B0");
783 }
784 public void setDist(double dist) {
785 distText.setText(dist < 0 ? "--" : NavigatableComponent.getDistText(dist));
786 }
787}
Note: See TracBrowser for help on using the repository browser.