PopupFactorypublic class PopupFactory extends Object PopupFactory , as the name implies, is used to obtain
instances of Popup s. Popup s are used to
display a Component above all other Component s
in a particular containment hierarchy. The general contract is that
once you have obtained a Popup from a
PopupFactory , you must invoke hide on the
Popup . The typical usage is:
PopupFactory factory = PopupFactory.getSharedInstance();
Popup popup = factory.getPopup(owner, contents, x, y);
popup.show();
...
popup.hide();
|
Fields Summary |
---|
private static final Object | SharedInstanceKeyThe shared instanceof PopupFactory is per
AppContext . This is the key used in the
AppContext to locate the PopupFactory . | private static final int | MAX_CACHE_SIZEMax number of items to store in any one particular cache. | static final int | LIGHT_WEIGHT_POPUPKey used to indicate a light weight popup should be used. | static final int | MEDIUM_WEIGHT_POPUPKey used to indicate a medium weight Popup should be used. | static final int | HEAVY_WEIGHT_POPUP | private int | popupTypeDefault type of Popup to create. | static final StringBuffer | forceHeavyWeightPopupKeyKey used for client property to force heavy weight popups for a
component. |
Methods Summary |
---|
private javax.swing.Popup | getHeadlessPopup(java.awt.Component owner, java.awt.Component contents, int ownerX, int ownerY)Creates a headless popup
return HeadlessPopup.getHeadlessPopup(owner, contents, ownerX, ownerY);
| private javax.swing.Popup | getHeavyWeightPopup(java.awt.Component owner, java.awt.Component contents, int ownerX, int ownerY)Creates a heavy weight popup.
if (GraphicsEnvironment.isHeadless()) {
return getMediumWeightPopup(owner, contents, ownerX, ownerY);
}
return HeavyWeightPopup.getHeavyWeightPopup(owner, contents, ownerX,
ownerY);
| private javax.swing.Popup | getLightWeightPopup(java.awt.Component owner, java.awt.Component contents, int ownerX, int ownerY)Creates a light weight popup.
return LightWeightPopup.getLightWeightPopup(owner, contents, ownerX,
ownerY);
| private javax.swing.Popup | getMediumWeightPopup(java.awt.Component owner, java.awt.Component contents, int ownerX, int ownerY)Creates a medium weight popup.
return MediumWeightPopup.getMediumWeightPopup(owner, contents,
ownerX, ownerY);
| public javax.swing.Popup | getPopup(java.awt.Component owner, java.awt.Component contents, int x, int y)Creates a Popup for the Component owner
containing the Component contents . owner
is used to determine which Window the new
Popup will parent the Component the
Popup creates to. A null owner implies there
is no valid parent. x and
y specify the preferred initial location to place
the Popup at. Based on screen size, or other paramaters,
the Popup may not display at x and
y .
if (contents == null) {
throw new IllegalArgumentException(
"Popup.getPopup must be passed non-null contents");
}
int popupType = getPopupType(owner, contents, x, y);
Popup popup = getPopup(owner, contents, x, y, popupType);
if (popup == null) {
// Didn't fit, force to heavy.
popup = getPopup(owner, contents, x, y, HEAVY_WEIGHT_POPUP);
}
return popup;
| private javax.swing.Popup | getPopup(java.awt.Component owner, java.awt.Component contents, int ownerX, int ownerY, int popupType)Obtains the appropriate Popup based on
popupType .
if (GraphicsEnvironment.isHeadless()) {
return getHeadlessPopup(owner, contents, ownerX, ownerY);
}
switch(popupType) {
case LIGHT_WEIGHT_POPUP:
return getLightWeightPopup(owner, contents, ownerX, ownerY);
case MEDIUM_WEIGHT_POPUP:
return getMediumWeightPopup(owner, contents, ownerX, ownerY);
case HEAVY_WEIGHT_POPUP:
return getHeavyWeightPopup(owner, contents, ownerX, ownerY);
}
return null;
| int | getPopupType()Returns the preferred type of Popup to create.
return popupType;
| private int | getPopupType(java.awt.Component owner, java.awt.Component contents, int ownerX, int ownerY)Returns the popup type to use for the specified parameters.
int popupType = getPopupType();
if (owner == null || invokerInHeavyWeightPopup(owner)) {
popupType = HEAVY_WEIGHT_POPUP;
}
else if (popupType == LIGHT_WEIGHT_POPUP &&
!(contents instanceof JToolTip) &&
!(contents instanceof JPopupMenu)) {
popupType = MEDIUM_WEIGHT_POPUP;
}
// Check if the parent component is an option pane. If so we need to
// force a heavy weight popup in order to have event dispatching work
// correctly.
Component c = owner;
while (c != null) {
if (c instanceof JComponent) {
if (((JComponent)c).getClientProperty(
forceHeavyWeightPopupKey) == Boolean.TRUE) {
popupType = HEAVY_WEIGHT_POPUP;
break;
}
}
c = c.getParent();
}
return popupType;
| public static javax.swing.PopupFactory | getSharedInstance()Returns the shared PopupFactory which can be used
to obtain Popup s.
PopupFactory factory = (PopupFactory)SwingUtilities.appContextGet(
SharedInstanceKey);
if (factory == null) {
factory = new PopupFactory();
setSharedInstance(factory);
}
return factory;
| private boolean | invokerInHeavyWeightPopup(java.awt.Component i)Returns true if the Component i inside a heavy weight
Popup .
if (i != null) {
Container parent;
for(parent = i.getParent() ; parent != null ; parent =
parent.getParent()) {
if (parent instanceof Popup.HeavyWeightWindow) {
return true;
}
}
}
return false;
| void | setPopupType(int type)Provides a hint as to the type of Popup that should
be created.
popupType = type;
| public static void | setSharedInstance(javax.swing.PopupFactory factory)Sets the PopupFactory that will be used to obtain
Popup s.
This will throw an IllegalArgumentException if
factory is null.
if (factory == null) {
throw new IllegalArgumentException("PopupFactory can not be null");
}
SwingUtilities.appContextPut(SharedInstanceKey, factory);
|
|