javax.swing
Class PopupFactory

java.lang.Object
  extended byjavax.swing.PopupFactory

public class PopupFactory
extends Object

PopupFactory, as the name implies, is used to obtain instances of Popups. Popups are used to display a Component above all other Components 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();
 

Since:
1.4
See Also:
PopupFactory.HeavyWeightPopup

Nested Class Summary
private static class PopupFactory.ContainerPopup
          ContainerPopup consolidates the common code used in the light/medium weight implementations of Popup.
private static class PopupFactory.HeadlessPopup
          Popup implementation that is used in headless environment.
private static class PopupFactory.HeavyWeightPopup
          Popup implementation that uses a Window as the popup.
private static class PopupFactory.LightWeightPopup
          Popup implementation that uses a JPanel as the popup.
private static class PopupFactory.MediumWeightPopup
          Popup implementation that uses a Panel as the popup.
 
Field Summary
(package private) static int HEAVY_WEIGHT_POPUP
           
(package private) static int LIGHT_WEIGHT_POPUP
          Key used to indicate a light weight popup should be used.
private static int MAX_CACHE_SIZE
          Max number of items to store in any one particular cache.
(package private) static int MEDIUM_WEIGHT_POPUP
          Key used to indicate a medium weight Popup should be used.
private  int popupType
          Default type of Popup to create.
private static Object SharedInstanceKey
          The shared instanceof PopupFactory is per AppContext.
 
Constructor Summary
PopupFactory()
           
 
Method Summary
private  Popup getHeadlessPopup(Component owner, Component contents, int ownerX, int ownerY)
          Creates a headless popup
private  Popup getHeavyWeightPopup(Component owner, Component contents, int ownerX, int ownerY)
          Creates a heavy weight popup.
private  Popup getLightWeightPopup(Component owner, Component contents, int ownerX, int ownerY)
          Creates a light weight popup.
private  Popup getMediumWeightPopup(Component owner, Component contents, int ownerX, int ownerY)
          Creates a medium weight popup.
 Popup getPopup(Component owner, Component contents, int x, int y)
          Creates a Popup for the Component owner containing the Component contents.
private  Popup getPopup(Component owner, Component contents, int ownerX, int ownerY, int popupType)
          Obtains the appropriate Popup based on popupType.
(package private)  int getPopupType()
          Returns the preferred type of Popup to create.
private  int getPopupType(Component owner, Component contents, int ownerX, int ownerY)
          Returns the popup type to use for the specified parameters.
static PopupFactory getSharedInstance()
          Returns the shared PopupFactory which can be used to obtain Popups.
private  boolean invokerInHeavyWeightPopup(Component i)
          Returns true if the Component i inside a heavy weight Popup.
(package private)  void setPopupType(int type)
          Provides a hint as to the type of Popup that should be created.
static void setSharedInstance(PopupFactory factory)
          Sets the AppContext specific PopupFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SharedInstanceKey

private static final Object SharedInstanceKey
The shared instanceof PopupFactory is per AppContext. This is the key used in the AppContext to locate the PopupFactory.


MAX_CACHE_SIZE

private static final int MAX_CACHE_SIZE
Max number of items to store in any one particular cache.

See Also:
Constant Field Values

LIGHT_WEIGHT_POPUP

static final int LIGHT_WEIGHT_POPUP
Key used to indicate a light weight popup should be used.

See Also:
Constant Field Values

MEDIUM_WEIGHT_POPUP

static final int MEDIUM_WEIGHT_POPUP
Key used to indicate a medium weight Popup should be used.

See Also:
Constant Field Values

HEAVY_WEIGHT_POPUP

static final int HEAVY_WEIGHT_POPUP
See Also:
Constant Field Values

popupType

private int popupType
Default type of Popup to create.

Constructor Detail

PopupFactory

public PopupFactory()
Method Detail

setSharedInstance

public static void setSharedInstance(PopupFactory factory)
Sets the AppContext specific PopupFactory. This will throw an IllegalArgumentException if factory is null.

Parameters:
factory - Shared PopupFactory
Throws:
IllegalArgumentException - if factory is null

getSharedInstance

public static PopupFactory getSharedInstance()
Returns the shared PopupFactory which can be used to obtain Popups.

Returns:
Shared PopupFactory

setPopupType

void setPopupType(int type)
Provides a hint as to the type of Popup that should be created.


getPopupType

int getPopupType()
Returns the preferred type of Popup to create.


getPopup

public Popup getPopup(Component owner,
                      Component contents,
                      int x,
                      int y)
               throws IllegalArgumentException
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.

Parameters:
owner - Component mouse coordinates are relative to, may be null
contents - Contents of the Popup
x - Initial x screen coordinate
y - Initial y screen coordinate
Returns:
Popup containing Contents
Throws:
IllegalArgumentException - if contents is null

getPopupType

private int getPopupType(Component owner,
                         Component contents,
                         int ownerX,
                         int ownerY)
Returns the popup type to use for the specified parameters.


getPopup

private Popup getPopup(Component owner,
                       Component contents,
                       int ownerX,
                       int ownerY,
                       int popupType)
Obtains the appropriate Popup based on popupType.


getHeadlessPopup

private Popup getHeadlessPopup(Component owner,
                               Component contents,
                               int ownerX,
                               int ownerY)
Creates a headless popup


getLightWeightPopup

private Popup getLightWeightPopup(Component owner,
                                  Component contents,
                                  int ownerX,
                                  int ownerY)
Creates a light weight popup.


getMediumWeightPopup

private Popup getMediumWeightPopup(Component owner,
                                   Component contents,
                                   int ownerX,
                                   int ownerY)
Creates a medium weight popup.


getHeavyWeightPopup

private Popup getHeavyWeightPopup(Component owner,
                                  Component contents,
                                  int ownerX,
                                  int ownerY)
Creates a heavy weight popup.


invokerInHeavyWeightPopup

private boolean invokerInHeavyWeightPopup(Component i)
Returns true if the Component i inside a heavy weight Popup.