Exemplo n.º 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;
  }
Exemplo n.º 2
0
 /** Hides all info panels. */
 protected void hideInfoPanels() {
   for (InfoPanel infoPanel : infoPanels.getInfoPanels()) {
     infoPanel.setVisible(false);
   }
 }
Exemplo n.º 3
0
 /** Called when a glass pane has been resolved. Adds all info panels to the glass pane */
 private void addInfoPanelsToGlassPane() {
   for (InfoPanel infoPanel : infoPanels.getInfoPanels()) {
     getGlassPanel().add(infoPanel);
   }
 }
Exemplo n.º 4
0
 /**
  * Registers the {@linkplain InfoPanel} binding.
  *
  * <p>These panels will automatically be added to the glass pane and will automatically be
  * displayed in the {@code mouseMoved} method.
  *
  * <p>Override the {@linkplain #initInfoPanel()} method to initialize the info panel about to be
  * shown.
  *
  * @param infoPanels the {@linkplain InfoPanel} panels to register
  * @param graphics the list of {@linkplain OMGraphic} elements that triggers the info panel
  */
 @SafeVarargs
 protected final void registerInfoPanel(
     InfoPanel infoPanel, Class<? extends OMGraphic>... graphics) {
   infoPanels.addBinding(infoPanel, graphics);
 }