示例#1
0
 /** Hides all but the info panel closest to the mouse point */
 private synchronized void checkInfoPanelVisiblity() {
   InfoPanel closestInfoPanel = null;
   for (Component component : getGlassPanel().getComponents()) {
     if (component instanceof InfoPanel && component.isVisible()) {
       InfoPanel infoPanel = (InfoPanel) component;
       if (closestInfoPanel != null
           && infoPanel.getMouseDist() < closestInfoPanel.getMouseDist()) {
         closestInfoPanel.setVisible(false);
         closestInfoPanel = infoPanel;
       } else if (closestInfoPanel != null) {
         infoPanel.setVisible(false);
       } else if (closestInfoPanel == null) {
         closestInfoPanel = infoPanel;
       }
     }
   }
 }
示例#2
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;
  }
示例#3
0
 /** Hides all info panels. */
 protected void hideInfoPanels() {
   for (InfoPanel infoPanel : infoPanels.getInfoPanels()) {
     infoPanel.setVisible(false);
   }
 }