< prev index next >

src/java.desktop/share/classes/javax/swing/PopupFactory.java

Print this page

        

*** 39,55 **** import java.util.List; import java.util.Map; import static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP; /** ! * <code>PopupFactory</code>, as the name implies, is used to obtain ! * instances of <code>Popup</code>s. <code>Popup</code>s are used to ! * display a <code>Component</code> above all other <code>Component</code>s * in a particular containment hierarchy. The general contract is that ! * once you have obtained a <code>Popup</code> from a ! * <code>PopupFactory</code>, you must invoke <code>hide</code> on the ! * <code>Popup</code>. The typical usage is: * <pre> * PopupFactory factory = PopupFactory.getSharedInstance(); * Popup popup = factory.getPopup(owner, contents, x, y); * popup.show(); * ... --- 39,55 ---- import java.util.List; import java.util.Map; import static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP; /** ! * {@code PopupFactory}, as the name implies, is used to obtain ! * instances of {@code Popup}s. {@code Popup}s are used to ! * display a {@code Component} above all other {@code Component}s * in a particular containment hierarchy. The general contract is that ! * once you have obtained a {@code Popup} from a ! * {@code PopupFactory}, you must invoke {@code hide} on the ! * {@code Popup}. The typical usage is: * <pre> * PopupFactory factory = PopupFactory.getSharedInstance(); * Popup popup = factory.getPopup(owner, contents, x, y); * popup.show(); * ...
*** 70,82 **** return factory.getPopup(owner, contents, ownerX, ownerY, HEAVY_WEIGHT_POPUP); } }); } /** ! * The shared instanceof <code>PopupFactory</code> is per ! * <code>AppContext</code>. This is the key used in the ! * <code>AppContext</code> to locate the <code>PopupFactory</code>. */ private static final Object SharedInstanceKey = new StringBuffer("PopupFactory.SharedInstanceKey"); /** --- 70,82 ---- return factory.getPopup(owner, contents, ownerX, ownerY, HEAVY_WEIGHT_POPUP); } }); } /** ! * The shared instanceof {@code PopupFactory} is per ! * {@code AppContext}. This is the key used in the ! * {@code AppContext} to locate the {@code PopupFactory}. */ private static final Object SharedInstanceKey = new StringBuffer("PopupFactory.SharedInstanceKey"); /**
*** 104,132 **** */ private int popupType = LIGHT_WEIGHT_POPUP; /** ! * Sets the <code>PopupFactory</code> that will be used to obtain ! * <code>Popup</code>s. ! * This will throw an <code>IllegalArgumentException</code> if ! * <code>factory</code> is null. * * @param factory Shared PopupFactory ! * @exception IllegalArgumentException if <code>factory</code> is null * @see #getPopup */ public static void setSharedInstance(PopupFactory factory) { if (factory == null) { throw new IllegalArgumentException("PopupFactory can not be null"); } SwingUtilities.appContextPut(SharedInstanceKey, factory); } /** ! * Returns the shared <code>PopupFactory</code> which can be used ! * to obtain <code>Popup</code>s. * * @return Shared PopupFactory */ public static PopupFactory getSharedInstance() { PopupFactory factory = (PopupFactory)SwingUtilities.appContextGet( --- 104,132 ---- */ private int popupType = LIGHT_WEIGHT_POPUP; /** ! * Sets the {@code PopupFactory} that will be used to obtain ! * {@code Popup}s. ! * This will throw an {@code IllegalArgumentException} if ! * {@code factory} is null. * * @param factory Shared PopupFactory ! * @exception IllegalArgumentException if {@code factory} is null * @see #getPopup */ public static void setSharedInstance(PopupFactory factory) { if (factory == null) { throw new IllegalArgumentException("PopupFactory can not be null"); } SwingUtilities.appContextPut(SharedInstanceKey, factory); } /** ! * Returns the shared {@code PopupFactory} which can be used ! * to obtain {@code Popup}s. * * @return Shared PopupFactory */ public static PopupFactory getSharedInstance() { PopupFactory factory = (PopupFactory)SwingUtilities.appContextGet(
*** 139,149 **** return factory; } /** ! * Provides a hint as to the type of <code>Popup</code> that should * be created. */ void setPopupType(int type) { popupType = type; } --- 139,149 ---- return factory; } /** ! * Provides a hint as to the type of {@code Popup} that should * be created. */ void setPopupType(int type) { popupType = type; }
*** 154,173 **** int getPopupType() { return popupType; } /** ! * Creates a <code>Popup</code> for the Component <code>owner</code> ! * containing the Component <code>contents</code>. <code>owner</code> ! * is used to determine which <code>Window</code> the new ! * <code>Popup</code> will parent the <code>Component</code> the ! * <code>Popup</code> creates to. A null <code>owner</code> implies there ! * is no valid parent. <code>x</code> and ! * <code>y</code> specify the preferred initial location to place ! * the <code>Popup</code> at. Based on screen size, or other paramaters, ! * the <code>Popup</code> may not display at <code>x</code> and ! * <code>y</code>. * * @param owner Component mouse coordinates are relative to, may be null * @param contents Contents of the Popup * @param x Initial x screen coordinate * @param y Initial y screen coordinate --- 154,173 ---- int getPopupType() { return popupType; } /** ! * Creates a {@code Popup} for the Component {@code owner} ! * containing the Component {@code contents}. {@code owner} ! * is used to determine which {@code Window} the new ! * {@code Popup} will parent the {@code Component} the ! * {@code Popup} creates to. A null {@code owner} implies there ! * is no valid parent. {@code x} and ! * {@code y} specify the preferred initial location to place ! * the {@code Popup} at. Based on screen size, or other paramaters, ! * the {@code Popup} may not display at {@code x} and ! * {@code y}. * * @param owner Component mouse coordinates are relative to, may be null * @param contents Contents of the Popup * @param x Initial x screen coordinate * @param y Initial y screen coordinate
*** 224,235 **** return popupType; } /** ! * Obtains the appropriate <code>Popup</code> based on ! * <code>popupType</code>. */ private Popup getPopup(Component owner, Component contents, int ownerX, int ownerY, int popupType) { if (GraphicsEnvironment.isHeadless()) { return getHeadlessPopup(owner, contents, ownerX, ownerY); --- 224,235 ---- return popupType; } /** ! * Obtains the appropriate {@code Popup} based on ! * {@code popupType}. */ private Popup getPopup(Component owner, Component contents, int ownerX, int ownerY, int popupType) { if (GraphicsEnvironment.isHeadless()) { return getHeadlessPopup(owner, contents, ownerX, ownerY);
*** 289,300 **** return HeavyWeightPopup.getHeavyWeightPopup(owner, contents, ownerX, ownerY); } /** ! * Returns true if the Component <code>i</code> inside a heavy weight ! * <code>Popup</code>. */ private boolean invokerInHeavyWeightPopup(Component i) { if (i != null) { Container parent; for(parent = i.getParent() ; parent != null ; parent = --- 289,300 ---- return HeavyWeightPopup.getHeavyWeightPopup(owner, contents, ownerX, ownerY); } /** ! * Returns true if the Component {@code i} inside a heavy weight ! * {@code Popup}. */ private boolean invokerInHeavyWeightPopup(Component i) { if (i != null) { Container parent; for(parent = i.getParent() ; parent != null ; parent =
*** 316,326 **** new StringBuffer("PopupFactory.heavyWeightPopupCache"); private volatile boolean isCacheEnabled = true; /** ! * Returns either a new or recycled <code>Popup</code> containing * the specified children. */ static Popup getHeavyWeightPopup(Component owner, Component contents, int ownerX, int ownerY) { Window window = (owner != null) ? SwingUtilities. --- 316,326 ---- new StringBuffer("PopupFactory.heavyWeightPopupCache"); private volatile boolean isCacheEnabled = true; /** ! * Returns either a new or recycled {@code Popup} containing * the specified children. */ static Popup getHeavyWeightPopup(Component owner, Component contents, int ownerX, int ownerY) { Window window = (owner != null) ? SwingUtilities.
*** 371,384 **** return popup; } /** ! * Returns a previously disposed heavy weight <code>Popup</code> ! * associated with <code>window</code>. This will return null if ! * there is no <code>HeavyWeightPopup</code> associated with ! * <code>window</code>. */ private static HeavyWeightPopup getRecycledHeavyWeightPopup(Window w) { synchronized (HeavyWeightPopup.class) { List<HeavyWeightPopup> cache; Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache(); --- 371,384 ---- return popup; } /** ! * Returns a previously disposed heavy weight {@code Popup} ! * associated with {@code window}. This will return null if ! * there is no {@code HeavyWeightPopup} associated with ! * {@code window}. */ private static HeavyWeightPopup getRecycledHeavyWeightPopup(Window w) { synchronized (HeavyWeightPopup.class) { List<HeavyWeightPopup> cache; Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();
*** 397,408 **** } } /** * Returns the cache to use for heavy weight popups. Maps from ! * <code>Window</code> to a <code>List</code> of ! * <code>HeavyWeightPopup</code>s. */ @SuppressWarnings("unchecked") private static Map<Window, List<HeavyWeightPopup>> getHeavyWeightPopupCache() { synchronized (HeavyWeightPopup.class) { Map<Window, List<HeavyWeightPopup>> cache = (Map<Window, List<HeavyWeightPopup>>)SwingUtilities.appContextGet( --- 397,408 ---- } } /** * Returns the cache to use for heavy weight popups. Maps from ! * {@code Window} to a {@code List} of ! * {@code HeavyWeightPopup}s. */ @SuppressWarnings("unchecked") private static Map<Window, List<HeavyWeightPopup>> getHeavyWeightPopupCache() { synchronized (HeavyWeightPopup.class) { Map<Window, List<HeavyWeightPopup>> cache = (Map<Window, List<HeavyWeightPopup>>)SwingUtilities.appContextGet(
*** 416,426 **** return cache; } } /** ! * Recycles the passed in <code>HeavyWeightPopup</code>. */ private static void recycleHeavyWeightPopup(HeavyWeightPopup popup) { synchronized (HeavyWeightPopup.class) { List<HeavyWeightPopup> cache; Window window = SwingUtilities.getWindowAncestor( --- 416,426 ---- return cache; } } /** ! * Recycles the passed in {@code HeavyWeightPopup}. */ private static void recycleHeavyWeightPopup(HeavyWeightPopup popup) { synchronized (HeavyWeightPopup.class) { List<HeavyWeightPopup> cache; Window window = SwingUtilities.getWindowAncestor(
*** 490,501 **** this._dispose(); } } /** ! * As we recycle the <code>Window</code>, we don't want to dispose it, ! * thus this method does nothing, instead use <code>_dipose</code> * which will handle the disposing. */ void dispose() { } --- 490,501 ---- this._dispose(); } } /** ! * As we recycle the {@code Window}, we don't want to dispose it, ! * thus this method does nothing, instead use {@code _dipose} * which will handle the disposing. */ void dispose() { }
*** 506,516 **** /** * ContainerPopup consolidates the common code used in the light/medium ! * weight implementations of <code>Popup</code>. */ private static class ContainerPopup extends Popup { /** Component we are to be added to. */ Component owner; /** Desired x location. */ --- 506,516 ---- /** * ContainerPopup consolidates the common code used in the light/medium ! * weight implementations of {@code Popup}. */ private static class ContainerPopup extends Popup { /** Component we are to be added to. */ Component owner; /** Desired x location. */
*** 675,687 **** private static class LightWeightPopup extends ContainerPopup { private static final Object lightWeightPopupCacheKey = new StringBuffer("PopupFactory.lightPopupCache"); /** ! * Returns a light weight <code>Popup</code> implementation. If ! * the <code>Popup</code> needs more space that in available in ! * <code>owner</code>, this will return null. */ static Popup getLightWeightPopup(Component owner, Component contents, int ownerX, int ownerY) { LightWeightPopup popup = getRecycledLightWeightPopup(); --- 675,687 ---- private static class LightWeightPopup extends ContainerPopup { private static final Object lightWeightPopupCacheKey = new StringBuffer("PopupFactory.lightPopupCache"); /** ! * Returns a light weight {@code Popup} implementation. If ! * the {@code Popup} needs more space that in available in ! * {@code owner}, this will return null. */ static Popup getLightWeightPopup(Component owner, Component contents, int ownerX, int ownerY) { LightWeightPopup popup = getRecycledLightWeightPopup();
*** 710,720 **** } return cache; } /** ! * Recycles the LightWeightPopup <code>popup</code>. */ private static void recycleLightWeightPopup(LightWeightPopup popup) { synchronized (LightWeightPopup.class) { List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache(); if (lightPopupCache.size() < MAX_CACHE_SIZE) { --- 710,720 ---- } return cache; } /** ! * Recycles the LightWeightPopup {@code popup}. */ private static void recycleLightWeightPopup(LightWeightPopup popup) { synchronized (LightWeightPopup.class) { List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache(); if (lightPopupCache.size() < MAX_CACHE_SIZE) {
*** 722,732 **** } } } /** ! * Returns a previously used <code>LightWeightPopup</code>, or null * if none of the popups have been recycled. */ private static LightWeightPopup getRecycledLightWeightPopup() { synchronized (LightWeightPopup.class) { List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache(); --- 722,732 ---- } } } /** ! * Returns a previously used {@code LightWeightPopup}, or null * if none of the popups have been recycled. */ private static LightWeightPopup getRecycledLightWeightPopup() { synchronized (LightWeightPopup.class) { List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache();
*** 803,813 **** // // Local methods // /** ! * Resets the <code>Popup</code> to an initial state. */ void reset(Component owner, Component contents, int ownerX, int ownerY) { super.reset(owner, contents, ownerX, ownerY); --- 803,813 ---- // // Local methods // /** ! * Resets the {@code Popup} to an initial state. */ void reset(Component owner, Component contents, int ownerX, int ownerY) { super.reset(owner, contents, ownerX, ownerY);
*** 832,844 **** /** Child of the panel. The contents are added to this. */ private JRootPane rootPane; /** ! * Returns a medium weight <code>Popup</code> implementation. If ! * the <code>Popup</code> needs more space that in available in ! * <code>owner</code>, this will return null. */ static Popup getMediumWeightPopup(Component owner, Component contents, int ownerX, int ownerY) { MediumWeightPopup popup = getRecycledMediumWeightPopup(); --- 832,844 ---- /** Child of the panel. The contents are added to this. */ private JRootPane rootPane; /** ! * Returns a medium weight {@code Popup} implementation. If ! * the {@code Popup} needs more space that in available in ! * {@code owner}, this will return null. */ static Popup getMediumWeightPopup(Component owner, Component contents, int ownerX, int ownerY) { MediumWeightPopup popup = getRecycledMediumWeightPopup();
*** 868,878 **** } return cache; } /** ! * Recycles the MediumWeightPopup <code>popup</code>. */ private static void recycleMediumWeightPopup(MediumWeightPopup popup) { synchronized (MediumWeightPopup.class) { List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache(); if (mediumPopupCache.size() < MAX_CACHE_SIZE) { --- 868,878 ---- } return cache; } /** ! * Recycles the MediumWeightPopup {@code popup}. */ private static void recycleMediumWeightPopup(MediumWeightPopup popup) { synchronized (MediumWeightPopup.class) { List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache(); if (mediumPopupCache.size() < MAX_CACHE_SIZE) {
*** 880,890 **** } } } /** ! * Returns a previously used <code>MediumWeightPopup</code>, or null * if none of the popups have been recycled. */ private static MediumWeightPopup getRecycledMediumWeightPopup() { synchronized (MediumWeightPopup.class) { List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache(); --- 880,890 ---- } } } /** ! * Returns a previously used {@code MediumWeightPopup}, or null * if none of the popups have been recycled. */ private static MediumWeightPopup getRecycledMediumWeightPopup() { synchronized (MediumWeightPopup.class) { List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache();
*** 958,968 **** component.add(rootPane, BorderLayout.CENTER); return component; } /** ! * Resets the <code>Popup</code> to an initial state. */ void reset(Component owner, Component contents, int ownerX, int ownerY) { super.reset(owner, contents, ownerX, ownerY); --- 958,968 ---- component.add(rootPane, BorderLayout.CENTER); return component; } /** ! * Resets the {@code Popup} to an initial state. */ void reset(Component owner, Component contents, int ownerX, int ownerY) { super.reset(owner, contents, ownerX, ownerY);
< prev index next >