Class CustomPopup
- java.lang.Object
-
- javax.swing.Popup
-
- com.github.lgooddatepicker.zinternaltools.CustomPopup
-
- All Implemented Interfaces:
java.awt.event.ComponentListener
,java.awt.event.WindowFocusListener
,java.util.EventListener
public class CustomPopup extends javax.swing.Popup implements java.awt.event.WindowFocusListener, java.awt.event.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CustomPopup.CustomPopupCloseListener
CustomPopupCloseListener, Any class that uses a CustomPopup (or any other class), may implement this interface to be notified when the CustomPopup is closed.
-
Constructor Summary
Constructors Constructor Description CustomPopup(java.awt.Component contentsComponent, java.awt.Window topWindow, CustomPopup.CustomPopupCloseListener optionalCustomPopupCloseListener, javax.swing.border.Border optionalBorder)
Constructor, This creates and initializes instances of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
componentHidden(java.awt.event.ComponentEvent e)
componentHidden, Part of ComponentListener.void
componentMoved(java.awt.event.ComponentEvent e)
componentMoved, Part of ComponentListener.void
componentResized(java.awt.event.ComponentEvent e)
componentResized, Part of ComponentListener.void
componentShown(java.awt.event.ComponentEvent e)
componentShown, Part of ComponentListener.java.awt.Rectangle
getBounds()
getBounds, This returns the bounds of the CustomPopup displayWindow in the form of a Rectangle object.void
hide()
hide, This hides the popup window.void
setLocation(int popupX, int popupY)
setLocation, This changes the location of the popup window.void
setMinimumSize(java.awt.Dimension minimumSize)
void
show()
show, This shows the visible component of the popup window.void
windowGainedFocus(java.awt.event.WindowEvent e)
windowGainedFocus, Part of WindowFocusListener.void
windowLostFocus(java.awt.event.WindowEvent e)
windowLostFocus, Part of WindowFocusListener.
-
-
-
Constructor Detail
-
CustomPopup
public CustomPopup(java.awt.Component contentsComponent, java.awt.Window topWindow, CustomPopup.CustomPopupCloseListener optionalCustomPopupCloseListener, javax.swing.border.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 Detail
-
componentHidden
public void componentHidden(java.awt.event.ComponentEvent e)
componentHidden, Part of ComponentListener. Whenever the topWindow is hidden, the popup will be hidden.- Specified by:
componentHidden
in interfacejava.awt.event.ComponentListener
-
componentMoved
public void componentMoved(java.awt.event.ComponentEvent e)
componentMoved, Part of ComponentListener. Whenever the topWindow is moved, the popup will be hidden.- Specified by:
componentMoved
in interfacejava.awt.event.ComponentListener
-
componentResized
public void componentResized(java.awt.event.ComponentEvent e)
componentResized, Part of ComponentListener. Whenever the topWindow is resized, the popup will be hidden.- Specified by:
componentResized
in interfacejava.awt.event.ComponentListener
-
componentShown
public void componentShown(java.awt.event.ComponentEvent e)
componentShown, Part of ComponentListener. This does nothing, it is included because all listener functions must be implemented.- Specified by:
componentShown
in interfacejava.awt.event.ComponentListener
-
getBounds
public java.awt.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 classjavax.swing.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 classjavax.swing.Popup
-
windowGainedFocus
public void windowGainedFocus(java.awt.event.WindowEvent e)
windowGainedFocus, Part of WindowFocusListener. This does nothing, it is included because all listener functions must be implemented.- Specified by:
windowGainedFocus
in interfacejava.awt.event.WindowFocusListener
-
windowLostFocus
public void windowLostFocus(java.awt.event.WindowEvent e)
windowLostFocus, Part of WindowFocusListener. Whenever the popup window loses focus, it will be hidden.- Specified by:
windowLostFocus
in interfacejava.awt.event.WindowFocusListener
-
setMinimumSize
public void setMinimumSize(java.awt.Dimension minimumSize)
-
-