public static EventService getEventService(Component component) {
      while (component != null) {
         if (component instanceof ContainerEventServiceSupplier) {
            return ((ContainerEventServiceSupplier) component).getContainerEventService();
         }
         if (component instanceof JPopupMenu) {
            component = ((JPopupMenu) component).getInvoker();
         } else {
            if (component.getParent() == null) {
               //There is no supplier.  Instead of returning null, make an event service
               //and stick it in the client properties of the top level container.
               if (component instanceof RootPaneContainer) {
                  component = ((RootPaneContainer) component).getRootPane();
               }
               if (!(component instanceof JComponent)) {
                  return null;
               }
               JComponent jComp = ((JComponent) component);
               SwingEventService eventService = (SwingEventService) jComp.getClientProperty(CLIENT_PROPERTY_KEY_TOP_LEVEL_EVENT_SERVICE);
               if (eventService == null) {
                  eventService = new SwingEventService();
                  jComp.putClientProperty(CLIENT_PROPERTY_KEY_TOP_LEVEL_EVENT_SERVICE, eventService);
               }
               return eventService;
            } else {
               component = component.getParent();
            }
         }
      }
      return null;
   }