Class CustomPopup

java.lang.Object
javax.swing.Popup
com.github.lgooddatepicker.zinternaltools.CustomPopup
All Implemented Interfaces:
ComponentListener, WindowFocusListener, EventListener

public class CustomPopup extends Popup implements WindowFocusListener, ComponentListener
CustomPopup, This is a custom popup class, which provides a fine level of control over when the popup opens and closes. This was created to overcome particular shortcomings of the JPopupMenu class. WindowFocusListener notes: This class listens for focus change events in the popup displayWindow. This class will close the popup when the popup displayWindow loses focus. This class handles its own registration and de-registration of the focus change listener. ComponentListener notes: This class listens for movement in the top window of the component which initiated the popup. If the topWindow moves, then the popup will be closed. This class handles its own registration and de-registration of the listener with the top window component.
  • Constructor Details

    • CustomPopup

      public CustomPopup(Component contentsComponent, Window topWindow, CustomPopup.CustomPopupCloseListener optionalCustomPopupCloseListener, Border optionalBorder)
      Constructor, This creates and initializes instances of this class.
      Parameters:
      contentsComponent - This is the component that you wish to display inside this popup.
      topWindow - When the window that surrounds a popup is moved, the popup will be automatically closed. The topWindow is the window that should be watched for movement. The window that is needed is usually the top window of the component hierarchy, of the component that initiated the popup. The function SwingUtilities.getWindowAncestor() can be useful for getting the topWindow.
      optionalCustomPopupCloseListener - If this is supplied, it will be notified when the hide() function is called on this popup. This will occur regardless of whether the hide() function was called internally or externally.
      optionalBorder - If this is supplied, it will be used as the border for the popup window. If no border is supplied, then a default border will be used.
  • Method Details

    • componentHidden

      public void componentHidden(ComponentEvent e)
      componentHidden, Part of ComponentListener. Whenever the topWindow is hidden, the popup will be hidden.
      Specified by:
      componentHidden in interface ComponentListener
    • componentMoved

      public void componentMoved(ComponentEvent e)
      componentMoved, Part of ComponentListener. Whenever the topWindow is moved, the popup will be hidden.
      Specified by:
      componentMoved in interface ComponentListener
    • componentResized

      public void componentResized(ComponentEvent e)
      componentResized, Part of ComponentListener. Whenever the topWindow is resized, the popup will be hidden.
      Specified by:
      componentResized in interface ComponentListener
    • componentShown

      public void componentShown(ComponentEvent e)
      componentShown, Part of ComponentListener. This does nothing, it is included because all listener functions must be implemented.
      Specified by:
      componentShown in interface ComponentListener
    • getBounds

      public Rectangle getBounds()
      getBounds, This returns the bounds of the CustomPopup displayWindow in the form of a Rectangle object. The bounds specify this component's width, height, and location relative to its parent.
    • hide

      public void hide()
      hide, This hides the popup window. This removes this class from the list of window focus listeners for the popup window, and removes this class from the list of window movement listeners for the top window. This can be called internally or externally. If this is called multiple times, then only the first call will have an effect.
      Overrides:
      hide in class Popup
    • setLocation

      public void setLocation(int popupX, int popupY)
      setLocation, This changes the location of the popup window.
    • show

      public void show()
      show, This shows the visible component of the popup window.
      Overrides:
      show in class Popup
    • windowGainedFocus

      public void windowGainedFocus(WindowEvent e)
      windowGainedFocus, Part of WindowFocusListener. This does nothing, it is included because all listener functions must be implemented.
      Specified by:
      windowGainedFocus in interface WindowFocusListener
    • windowLostFocus

      public void windowLostFocus(WindowEvent e)
      windowLostFocus, Part of WindowFocusListener. Whenever the popup window loses focus, it will be hidden.
      Specified by:
      windowLostFocus in interface WindowFocusListener
    • setMinimumSize

      public void setMinimumSize(Dimension minimumSize)