示例#1
0
  /**
   * Default implementation of the mouseMoved method that opens {@linkplain InfoPanel} based on the
   * graphics closest to the mouse location.
   *
   * <p>In order to use this mechanism, first register the info panels using the {@code
   * registerInfoPanel()} method.
   *
   * @param evt the mouse event
   * @return if the event was handled
   */
  @Override
  public boolean mouseMoved(MouseEvent evt) {

    if (!isVisible() || mapMenu == null || mapMenu.isVisible()) {
      return false;
    }

    if (!infoPanels.isEmpty()) {
      OMGraphic newClosest =
          getSelectedGraphic(infoPanelsGraphics, evt, infoPanels.getGraphicsList());

      if (newClosest != null && newClosest.isVisible()) {

        InfoPanel infoPanel = infoPanels.getInfoPanel(newClosest.getClass());

        // Register the distance between the mouse position and the closest graphics
        infoPanel.setMouseDist(newClosest.distance(evt.getPoint().getX(), evt.getPoint().getY()));

        if (newClosest != closest) {
          closest = newClosest;
          Point containerPoint = convertPoint(evt.getPoint());

          infoPanel.setPos((int) containerPoint.getX(), (int) containerPoint.getY() - 10);

          // Allow custom initialization by sub-classes
          if (initInfoPanel(infoPanel, newClosest, evt, containerPoint)) {
            infoPanel.setVisible(true);
            getGlassPanel().setVisible(true);
          }

          // Hides all but the info panel closest to the mouse point
          checkInfoPanelVisiblity();
        }

        return true;
      } else if (newClosest == null) {
        closest = null;
        hideInfoPanels();
      }
    }

    return false;
  }