/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* <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();
* ...
* popup.hide();
* </pre>
*
* @see Popup
*
* @since 1.4
*/
public class PopupFactory {
/**
* 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>.
*/
new StringBuffer("PopupFactory.SharedInstanceKey");
/**
* Max number of items to store in any one particular cache.
*/
/**
* Key used to indicate a light weight popup should be used.
*/
/**
* Key used to indicate a medium weight Popup should be used.
*/
/*
* Key used to indicate a heavy weight Popup should be used.
*/
/**
* Default type of Popup to create.
*/
/**
* 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
*/
throw new IllegalArgumentException("PopupFactory can not be null");
}
}
/**
* Returns the shared <code>PopupFactory</code> which can be used
* to obtain <code>Popup</code>s.
*
* @return Shared PopupFactory
*/
factory = new PopupFactory();
}
return factory;
}
/**
* Provides a hint as to the type of <code>Popup</code> that should
* be created.
*/
}
/**
* Returns the preferred type of Popup to create.
*/
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
* @exception IllegalArgumentException if contents is null
* @return Popup containing Contents
*/
int x, int y) throws IllegalArgumentException {
throw new IllegalArgumentException(
"Popup.getPopup must be passed non-null contents");
}
// Didn't fit, force to heavy.
}
return popup;
}
/**
* Returns the popup type to use for the specified parameters.
*/
int popupType = getPopupType();
}
else if (popupType == LIGHT_WEIGHT_POPUP &&
!(contents instanceof JPopupMenu)) {
}
// 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.
while (c != null) {
if (c instanceof JComponent) {
if (((JComponent)c).getClientProperty(
break;
}
}
c = c.getParent();
}
return popupType;
}
/**
* Obtains the appropriate <code>Popup</code> based on
* <code>popupType</code>.
*/
if (GraphicsEnvironment.isHeadless()) {
}
switch(popupType) {
case LIGHT_WEIGHT_POPUP:
case MEDIUM_WEIGHT_POPUP:
case HEAVY_WEIGHT_POPUP:
}
return null;
}
/**
* Creates a headless popup
*/
}
/**
* Creates a light weight popup.
*/
ownerY);
}
/**
* Creates a medium weight popup.
*/
}
/**
* Creates a heavy weight popup.
*/
if (GraphicsEnvironment.isHeadless()) {
}
ownerY);
}
/**
* Returns true if the Component <code>i</code> inside a heavy weight
* <code>Popup</code>.
*/
if (i != null) {
return true;
}
}
}
return false;
}
/**
* Popup implementation that uses a Window as the popup.
*/
new StringBuffer("PopupFactory.heavyWeightPopupCache");
/**
* Returns either a new or recycled <code>Popup</code> containing
* the specified children.
*/
}
boolean focusPopup = false;
if(contents instanceof JPopupMenu) {
if (!(popComp instanceof MenuElement) &&
!(popComp instanceof JSeparator)) {
focusPopup = true;
break;
}
}
}
}
.getFocusableWindowState() != focusPopup) {
// The recycled popup can't serve us well
// dispose it and create new one
}
popup = new HeavyWeightPopup();
}
if(focusPopup) {
wnd.setFocusableWindowState(true);
// Set window name. We need this in BasicPopupMenuUI
// to identify focusable popup window.
}
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>.
*/
synchronized (HeavyWeightPopup.class) {
if (heavyPopupCache.containsKey(w)) {
} else {
return null;
}
return r;
}
return null;
}
}
/**
* Returns the cache to use for heavy weight popups. Maps from
* <code>Window</code> to a <code>List</code> of
* <code>HeavyWeightPopup</code>s.
*/
synchronized (HeavyWeightPopup.class) {
Map<Window, List<HeavyWeightPopup>> cache = (Map<Window, List<HeavyWeightPopup>>)SwingUtilities.appContextGet(
cache);
}
return cache;
}
}
/**
* Recycles the passed in <code>HeavyWeightPopup</code>.
*/
synchronized (HeavyWeightPopup.class) {
popup.getComponent());
// If the Window isn't visible, we don't cache it as we
// likely won't ever get a windowClosed event to clean up.
// We also don't cache DefaultFrames as this indicates
// there wasn't a valid Window parent, and thus we don't
// know when to clean up.
return;
} else {
// Clean up if the Window is closed
w.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
synchronized(HeavyWeightPopup.class) {
}
}
}
}
});
}
} else {
}
}
}
//
// Popup methods
//
public void hide() {
super.hide();
recycleHeavyWeightPopup(this);
}
/**
* 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() {
}
void _dispose() {
super.dispose();
}
}
/**
* weight implementations of <code>Popup</code>.
*/
/** Component we are to be added to. */
/** Desired x location. */
int x;
/** Desired y location. */
int y;
public void hide() {
}
}
}
public void pack() {
}
}
int ownerY) {
// Force the content to be added to the layered pane, otherwise
// we'll get an exception when adding to the RootPaneContainer.
}
x = ownerX;
y = ownerY;
}
boolean overlappedByOwnedWindow() {
if (w == null) {
return false;
}
if(ownedWindows != null) {
return true;
}
}
}
}
return false;
}
/**
* Returns true if popup can fit the screen and the owner's top parent.
* It determines can popup be lightweight or mediumweight.
*/
boolean fitsOnScreen() {
boolean result = false;
parentBounds.x += i.left;
parentBounds.y += i.top;
if (JPopupMenu.canPopupOverlapTaskBar()) {
} else {
}
parentBounds.x = p.x;
parentBounds.y = p.y;
}
}
return result;
}
// If we have GraphicsConfiguration use it
// to get screen bounds
} else {
// If we don't have GraphicsConfiguration use primary screen
}
// Take insets into account
return screenBounds;
}
}
/**
* Popup implementation that is used in headless environment.
*/
return popup;
}
return new Panel(new BorderLayout());
}
public void show() {
}
public void hide() {
}
}
/**
* Popup implementation that uses a JPanel as the popup.
*/
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.
*/
popup = new LightWeightPopup();
}
if (!popup.fitsOnScreen() ||
return null;
}
return popup;
}
/**
* Returns the cache to use for heavy weight popups.
*/
}
return cache;
}
/**
* Recycles the LightWeightPopup <code>popup</code>.
*/
synchronized (LightWeightPopup.class) {
}
}
}
/**
* Returns a previously used <code>LightWeightPopup</code>, or null
* if none of the popups have been recycled.
*/
synchronized (LightWeightPopup.class) {
return r;
}
return null;
}
}
//
// Popup methods
//
public void hide() {
super.hide();
recycleLightWeightPopup(this);
}
public void show() {
}
// Try to find a JLayeredPane and Window to add
if (p instanceof JRootPane) {
if (p.getParent() instanceof JInternalFrame) {
continue;
}
// Continue, so that if there is a higher JRootPane, we'll
// pick it up.
} else if(p instanceof Window) {
parent = p;
}
break;
} else if (p instanceof JApplet) {
// Painting code stops at Applets, we don't want
// to add to a Component above an Applet otherwise
// you'll never see it painted.
break;
}
}
y);
component.setLocation(p.x, p.y);
if (parent instanceof JLayeredPane) {
} else {
}
}
return component;
}
//
// Local methods
//
/**
* Resets the <code>Popup</code> to an initial state.
*/
int ownerY) {
pack();
}
}
/**
* Popup implementation that uses a Panel as the popup.
*/
new StringBuffer("PopupFactory.mediumPopupCache");
/** Child of the panel. The contents are added to this. */
/**
* 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.
*/
popup = new MediumWeightPopup();
}
if (!popup.fitsOnScreen() ||
return null;
}
return popup;
}
/**
* Returns the cache to use for medium weight popups.
*/
}
return cache;
}
/**
* Recycles the MediumWeightPopup <code>popup</code>.
*/
synchronized (MediumWeightPopup.class) {
}
}
}
/**
* Returns a previously used <code>MediumWeightPopup</code>, or null
* if none of the popups have been recycled.
*/
synchronized (MediumWeightPopup.class) {
return r;
}
return null;
}
}
//
// Popup
//
public void hide() {
super.hide();
recycleMediumWeightPopup(this);
}
public void show() {
}
/*
Find the top level window,
if it has a layered pane,
add to that, otherwise
add to the window. */
}
// Set the visibility to false before adding to workaround a
// bug in Solaris in which the Popup gets added at the wrong
// location, which will result in a mouseExit, which will then
// result in the ToolTip being removed.
if (parent instanceof RootPaneContainer) {
x, y);
component.setVisible(false);
component.setLocation(p.x, p.y);
0);
} else {
x, y);
component.setLocation(p.x, p.y);
component.setVisible(false);
}
component.setVisible(true);
}
// NOTE: this uses setOpaque vs LookAndFeel.installProperty as
// there is NO reason for the RootPane not to be opaque. For
// painting to work the contentPane must be opaque, therefor the
// RootPane can also be opaque.
return component;
}
/**
* Resets the <code>Popup</code> to an initial state.
*/
int ownerY) {
pack();
}
// This implements SwingHeavyWeight so that repaints on it
// are processed by the RepaintManager and SwingPaintEventDispatcher.
super(new BorderLayout());
}
}
}
}