Package com.jgoodies.looks.common
Class ShadowPopup
- java.lang.Object
-
- javax.swing.Popup
-
- com.jgoodies.looks.common.ShadowPopup
-
public final class ShadowPopup extends javax.swing.PopupDoes all the magic for getting popups with drop shadows. It adds the drop shadow border to the Popup, in#showit snapshots the screen background as needed, and in#hideit cleans up all changes made before.- Version:
- $Revision: 1.12 $
- See Also:
ShadowPopupBorder,ShadowPopupFactory
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<ShadowPopup>cacheThe cache to use for ShadowPopups.private static booleancanSnapshotIndicates whether we can make snapshots from screen or not.private java.awt.ComponentcontentsThe contents of the popup.private java.awt.ContainerheavyWeightContainerThe heavy weight container of the popup contents, may be null.private static intMAX_CACHE_SIZEMax number of items to store in the cache.private javax.swing.border.BorderoldBorderThe border of the contents' parent replaced by SHADOW_BORDER.private booleanoldOpaqueThe old value of the opaque property of the contents' parent.private java.awt.ComponentownerThe component mouse coordinates are relative to, may be null.private static java.awt.PointPOINTThe 'scratch pad' objects used to calculate dirty regions of the screen snapshots.private javax.swing.PopuppopupThe real popup.private static java.awt.RectangleRECTprivate static javax.swing.border.BorderSHADOW_BORDERThe singleton instance used to draw all borders.private static intSHADOW_SIZEThe size of the drop shadow.private intxThe desired x and y location of the popup.private intyThe desired x and y location of the popup.
-
Constructor Summary
Constructors Constructor Description ShadowPopup()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancanSnapshot()(package private) static javax.swing.PopupgetInstance(java.awt.Component owner, java.awt.Component contents, int x, int y, javax.swing.Popup delegate)Returns a previously usedShadowPopup, or a new one if none of the popups have been recycled.private java.awt.ContainergetLayeredPane()voidhide()Hides and disposes of thePopup.private static voidrecycle(ShadowPopup popup)Recycles the ShadowPopup.private voidreset(java.awt.Component owner, java.awt.Component contents, int x, int y, javax.swing.Popup popup)Reinitializes this ShadowPopup using the given parameters.voidshow()Makes thePopupvisible.private voidsnapshot()Snapshots the background.
-
-
-
Field Detail
-
MAX_CACHE_SIZE
private static final int MAX_CACHE_SIZE
Max number of items to store in the cache.- See Also:
- Constant Field Values
-
cache
private static java.util.List<ShadowPopup> cache
The cache to use for ShadowPopups.
-
SHADOW_BORDER
private static final javax.swing.border.Border SHADOW_BORDER
The singleton instance used to draw all borders.
-
SHADOW_SIZE
private static final int SHADOW_SIZE
The size of the drop shadow.- See Also:
- Constant Field Values
-
canSnapshot
private static boolean canSnapshot
Indicates whether we can make snapshots from screen or not.
-
owner
private java.awt.Component owner
The component mouse coordinates are relative to, may be null.
-
contents
private java.awt.Component contents
The contents of the popup.
-
x
private int x
The desired x and y location of the popup.
-
y
private int y
The desired x and y location of the popup.
-
popup
private javax.swing.Popup popup
The real popup. The #show() and #hide() methods will delegate all calls to these popup.
-
oldBorder
private javax.swing.border.Border oldBorder
The border of the contents' parent replaced by SHADOW_BORDER.
-
oldOpaque
private boolean oldOpaque
The old value of the opaque property of the contents' parent.
-
heavyWeightContainer
private java.awt.Container heavyWeightContainer
The heavy weight container of the popup contents, may be null.
-
POINT
private static final java.awt.Point POINT
The 'scratch pad' objects used to calculate dirty regions of the screen snapshots.- See Also:
snapshot()
-
RECT
private static final java.awt.Rectangle RECT
-
-
Method Detail
-
getInstance
static javax.swing.Popup getInstance(java.awt.Component owner, java.awt.Component contents, int x, int y, javax.swing.Popup delegate)Returns a previously usedShadowPopup, or a new one if none of the popups have been recycled.
-
recycle
private static void recycle(ShadowPopup popup)
Recycles the ShadowPopup.
-
canSnapshot
public static boolean canSnapshot()
-
hide
public void hide()
Hides and disposes of thePopup. Once aPopuphas been disposed you should no longer invoke methods on it. AdisposedPopupmay be reclaimed and later used based on thePopupFactory. As such, if you invoke methods on adisposedPopup, indeterminate behavior will result.In addition to the superclass behavior, we reset the stored horizontal and vertical drop shadows - if any.
- Overrides:
hidein classjavax.swing.Popup
-
show
public void show()
Makes thePopupvisible. If the popup has a heavy-weight container, we try to snapshot the background. If thePopupis currently visible, it remains visible.- Overrides:
showin classjavax.swing.Popup
-
reset
private void reset(java.awt.Component owner, java.awt.Component contents, int x, int y, javax.swing.Popup popup)Reinitializes this ShadowPopup using the given parameters.- Parameters:
owner- component mouse coordinates are relative to, may be nullcontents- the contents of the popupx- the desired x location of the popupy- the desired y location of the popuppopup- the popup to wrap
-
snapshot
private void snapshot()
Snapshots the background. The snapshots are stored as client properties of the contents' parent. The next time the border is drawn, this background will be used.Uses a robot on the default screen device to capture the screen region under the drop shadow. Does not use the window's device, because that may be an outdated device (due to popup reuse) and the robot's origin seems to be adjusted with the default screen device.
- See Also:
show(),ShadowPopupBorder,Robot.createScreenCapture(Rectangle)
-
getLayeredPane
private java.awt.Container getLayeredPane()
- Returns:
- the top level layered pane which contains the owner.
-
-