Logo Search packages:      
Sourcecode: josm version File versions  Download package

void org::openstreetmap::josm::gui::MapStatus::Collector::run (  )  [inline]

Execution function for the Collector.

Definition at line 105 of file MapStatus.java.

References org::openstreetmap::josm::gui::NavigatableComponent::center, org::openstreetmap::josm::gui::NavigatableComponent::getAllNearest(), org::openstreetmap::josm::data::osm::visitor::NameVisitor::icon, org::openstreetmap::josm::gui::MapStatus::MouseState::modifiers, org::openstreetmap::josm::gui::MapStatus::MouseState::mousePos, org::openstreetmap::josm::gui::MapStatus::mouseState, org::openstreetmap::josm::gui::MapStatus::mv, org::openstreetmap::josm::data::osm::visitor::NameVisitor::name, oldModifiers, osmStatus, and popup.

                              {
                  for (;;) {
                        MouseState ms = new MouseState();
                        synchronized (this) {
                              try {wait();} catch (InterruptedException e) {}
                              ms.modifiers = mouseState.modifiers;
                              ms.mousePos = mouseState.mousePos;
                        }
                        if (parent != Main.map)
                              return; // exit, if new parent.
                        if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null)
                              continue; // freeze display when holding down ctrl

                        if (mv.center == null)
                              continue;

                        // This try/catch is a hack to stop the flooding bug reports about this.
                        // The exception needed to handle with in the first place, means that this
                        // access to the data need to be restarted, if the main thread modifies
                        // the data.
                        try {
                              // Popup Information
                              if ((ms.modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0 ) {
                                    Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos);

                                    if (osms == null)
                                          continue;
                                    if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers)
                                          continue;
                              /*
                              osmStatus = osms;
                              oldModifiers = ms.modifiers;

                              OsmPrimitive osmNearest = null;
                              // Set the text label in the bottom status bar
                              osmNearest = mv.getNearest(ms.mousePos);
                              if (osmNearest != null) {
                                    NameVisitor visitor = new NameVisitor();
                                    osmNearest.visit(visitor);
                                    nameText.setText(visitor.name);
                              } else
                                    nameText.setText("");
                              */
                              

                                    if (popup != null) {
                                          try {
                                  EventQueue.invokeAndWait(new Runnable() {
                                      public void run() {
                                          popup.hide();
                                      }
                                  });
                            } catch (InterruptedException e) {
                            } catch (InvocationTargetException e) {
                              throw new RuntimeException(e);
                            }
                                    }

                                    JPanel c = new JPanel(new GridBagLayout());
                                    for (final OsmPrimitive osm : osms) {
                                          NameVisitor visitor = new NameVisitor();
                                          osm.visit(visitor);
                                          final StringBuilder text = new StringBuilder();
                                          if (osm.id == 0 || osm.modified)
                                                visitor.name = "<i><b>"+visitor.name+"*</b></i>";
                                          text.append(visitor.name);
                                          if (osm.id != 0)
                                                text.append("<br>id="+osm.id);
                                          for (Entry<String, String> e : osm.entrySet())
                                                text.append("<br>"+e.getKey()+"="+e.getValue());
                                          final JLabel l = new JLabel("<html>"+text.toString()+"</html>", visitor.icon, JLabel.HORIZONTAL);
                                          l.setFont(l.getFont().deriveFont(Font.PLAIN));
                                          l.setVerticalTextPosition(JLabel.TOP);
                                          l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                                          l.addMouseListener(new MouseAdapter(){
                                                @Override public void mouseEntered(MouseEvent e) {
                                                      l.setText("<html><u color='blue'>"+text.toString()+"</u></html>");
                                                }
                                                @Override public void mouseExited(MouseEvent e) {
                                                      l.setText("<html>"+text.toString()+"</html>");
                                                }
                                                @Override public void mouseClicked(MouseEvent e) {
                                                      Main.ds.setSelected(osm);
                                                      mv.repaint();
                                                }
                                          });
                                          c.add(l, GBC.eol());
                                    }

                                    Point p = mv.getLocationOnScreen();
                                    popup = PopupFactory.getSharedInstance().getPopup(mv, c, p.x+ms.mousePos.x+16, p.y+ms.mousePos.y+16);
                                    final Popup staticPopup = popup;
                                    EventQueue.invokeLater(new Runnable(){
                                          public void run() {
                                                staticPopup.show();
                            }
                                    });
                              } else if (popup != null) {
                                    final Popup staticPopup = popup;
                                    popup = null;
                                    EventQueue.invokeLater(new Runnable(){
                                          public void run() {
                                                staticPopup.hide();
                            }
                                    });
                              }
                        } catch (ConcurrentModificationException x) {
                        } catch (NullPointerException x) {
                        }
                  }
            }


Generated by  Doxygen 1.6.0   Back to index