@Override
    public void eventDispatched(AWTEvent ev) {
      // We are interested in MouseEvents only
      if (!(ev instanceof MouseEvent)) {
        return;
      }
      MouseEvent me = (MouseEvent) ev;
      Component src = me.getComponent();
      switch (me.getID()) {
        case MouseEvent.MOUSE_PRESSED:
          if (isInPopup(src)) {
            return;
          }
          hide();
          // Ask UIManager about should we consume event that closes
          // popup. This made to match native apps behaviour.
          // Consume the event so that normal processing stops.
          if (UIManager.getBoolean("PopupMenu.consumeEventOnClose")) { //$NON-NLS-1$
            me.consume();
          }
          break;
        case MouseEvent.MOUSE_WHEEL:
          if (isInPopup(src)) {
            return;
          }
          hide();
          break;
      }
    }