Class JPopupMenuHelper
- java.lang.Object
-
- com.inductiveautomation.ignition.client.util.gui.popup.JPopupMenuHelper
-
- All Implemented Interfaces:
java.awt.event.MouseListener
,java.util.EventListener
,javax.swing.event.PopupMenuListener
public class JPopupMenuHelper extends java.lang.Object implements java.awt.event.MouseListener, javax.swing.event.PopupMenuListener
This class contains the correct logic for a component that wants to pop up a popup menu. You'd think this was unnecessary, but it's tricky to do correctly because if you pop up the popup on mouse press, it'll be wrong in the case when the press should "toggle" the popup's visibility. This is because The press will first hide the popup automatically, and then the press would show the popup again.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.Component
component
protected long
lastHidden
protected PopupLocation
location
protected boolean
memoizePopup
protected javax.swing.JPopupMenu
popup
protected java.util.function.Supplier<javax.swing.JPopupMenu>
popupMaker
protected long
threshold
protected PopupTrigger
trigger
-
Constructor Summary
Constructors Constructor Description JPopupMenuHelper(java.awt.Component component, java.util.function.Supplier<javax.swing.JPopupMenu> popupMaker)
Alternate constructor allows for lazy popup instantiationJPopupMenuHelper(java.awt.Component component, javax.swing.JPopupMenu popup)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.awt.Point
adjustPopupLocationToFitScreen(int xPosition, int yPosition)
Moves the popup location so that the menu does not overlap the task bar.protected java.awt.Point
adjustPopupLocationToFitWindow(int xPosition, int yPosition)
void
bind()
static void
bind(java.awt.Component component, javax.swing.JPopupMenu popup)
Creates a PopupHelper with trigger=OnPress, location=UnderneathComponent, and threshold=20ms and binds it.void
doShowPopup(java.awt.event.MouseEvent e)
java.awt.Component
getComponent()
PopupLocation
getLocation()
javax.swing.JPopupMenu
getPopup()
long
getThreshold()
PopupTrigger
getTrigger()
boolean
isMemoizePopup()
void
mouseClicked(java.awt.event.MouseEvent e)
void
mouseEntered(java.awt.event.MouseEvent e)
void
mouseExited(java.awt.event.MouseEvent e)
void
mousePressed(java.awt.event.MouseEvent e)
void
mouseReleased(java.awt.event.MouseEvent e)
void
popupMenuCanceled(javax.swing.event.PopupMenuEvent e)
void
popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent e)
void
popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent e)
void
setComponent(java.awt.Component component)
void
setLocation(PopupLocation location)
void
setMemoizePopup(boolean memoizePopup)
Controls whether the menu supplier is only called once (the default) or every time the popup is shown.void
setPopup(javax.swing.JPopupMenu popup)
void
setThreshold(long threshold)
void
setTrigger(PopupTrigger trigger)
void
unbind()
-
-
-
Field Detail
-
component
protected java.awt.Component component
-
popup
protected javax.swing.JPopupMenu popup
-
popupMaker
protected java.util.function.Supplier<javax.swing.JPopupMenu> popupMaker
-
trigger
protected PopupTrigger trigger
-
location
protected PopupLocation location
-
memoizePopup
protected boolean memoizePopup
-
lastHidden
protected long lastHidden
-
threshold
protected long threshold
-
-
Constructor Detail
-
JPopupMenuHelper
public JPopupMenuHelper(java.awt.Component component, javax.swing.JPopupMenu popup)
-
JPopupMenuHelper
public JPopupMenuHelper(java.awt.Component component, java.util.function.Supplier<javax.swing.JPopupMenu> popupMaker)
Alternate constructor allows for lazy popup instantiation
-
-
Method Detail
-
bind
public void bind()
-
unbind
public void unbind()
-
bind
public static void bind(java.awt.Component component, javax.swing.JPopupMenu popup)
Creates a PopupHelper with trigger=OnPress, location=UnderneathComponent, and threshold=20ms and binds it.
-
setTrigger
public void setTrigger(PopupTrigger trigger)
-
getTrigger
public PopupTrigger getTrigger()
-
setLocation
public void setLocation(PopupLocation location)
-
getLocation
public PopupLocation getLocation()
-
getThreshold
public long getThreshold()
-
setThreshold
public void setThreshold(long threshold)
-
setComponent
public void setComponent(java.awt.Component component)
-
getComponent
public java.awt.Component getComponent()
-
setPopup
public void setPopup(javax.swing.JPopupMenu popup)
-
getPopup
public javax.swing.JPopupMenu getPopup()
-
setMemoizePopup
public void setMemoizePopup(boolean memoizePopup)
Controls whether the menu supplier is only called once (the default) or every time the popup is shown. This setting is only used if the popup menu helper was created with a menu supplier.
-
isMemoizePopup
public boolean isMemoizePopup()
-
popupMenuWillBecomeVisible
public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent e)
- Specified by:
popupMenuWillBecomeVisible
in interfacejavax.swing.event.PopupMenuListener
-
popupMenuWillBecomeInvisible
public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent e)
- Specified by:
popupMenuWillBecomeInvisible
in interfacejavax.swing.event.PopupMenuListener
-
popupMenuCanceled
public void popupMenuCanceled(javax.swing.event.PopupMenuEvent e)
- Specified by:
popupMenuCanceled
in interfacejavax.swing.event.PopupMenuListener
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)
- Specified by:
mouseClicked
in interfacejava.awt.event.MouseListener
-
doShowPopup
public void doShowPopup(java.awt.event.MouseEvent e)
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
- Specified by:
mouseEntered
in interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
- Specified by:
mouseExited
in interfacejava.awt.event.MouseListener
-
adjustPopupLocationToFitScreen
protected java.awt.Point adjustPopupLocationToFitScreen(int xPosition, int yPosition)
Moves the popup location so that the menu does not overlap the task bar. This is taken from JPopupMenu.java. The JPopupMenu version has a condition that can allow the screen insets to not be considered in the adjustment. This was taken in full in order to perform the same function while forcing the insets to be part of the adjustment.
-
adjustPopupLocationToFitWindow
protected java.awt.Point adjustPopupLocationToFitWindow(int xPosition, int yPosition)
-
-