Class ShadowPopup

java.lang.Object
javax.swing.Popup
com.jgoodies.looks.common.ShadowPopup

public final class ShadowPopup extends Popup
Does all the magic for getting popups with drop shadows. It adds the drop shadow border to the Popup, in #show it snapshots the screen background as needed, and in #hide it cleans up all changes made before.
Version:
$Revision: 1.12 $
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static List<ShadowPopup>
    The cache to use for ShadowPopups.
    private static boolean
    Indicates whether we can make snapshots from screen or not.
    private Component
    The contents of the popup.
    private Container
    The heavy weight container of the popup contents, may be null.
    private static final int
    Max number of items to store in the cache.
    private Border
    The border of the contents' parent replaced by SHADOW_BORDER.
    private boolean
    The old value of the opaque property of the contents' parent.
    private Component
    The component mouse coordinates are relative to, may be null.
    private static final Point
    The 'scratch pad' objects used to calculate dirty regions of the screen snapshots.
    private Popup
    The real popup.
    private static final Rectangle
     
    private static final Border
    The singleton instance used to draw all borders.
    private static final int
    The size of the drop shadow.
    private int
    The desired x and y location of the popup.
    private int
    The desired x and y location of the popup.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
     
    (package private) static Popup
    getInstance(Component owner, Component contents, int x, int y, Popup delegate)
    Returns a previously used ShadowPopup, or a new one if none of the popups have been recycled.
    private Container
     
    void
    Hides and disposes of the Popup.
    private static void
    Recycles the ShadowPopup.
    private void
    reset(Component owner, Component contents, int x, int y, Popup popup)
    Reinitializes this ShadowPopup using the given parameters.
    void
    Makes the Popup visible.
    private void
    Snapshots the background.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_CACHE_SIZE

      private static final int MAX_CACHE_SIZE
      Max number of items to store in the cache.
      See Also:
    • cache

      private static List<ShadowPopup> cache
      The cache to use for ShadowPopups.
    • SHADOW_BORDER

      private static final 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:
    • canSnapshot

      private static boolean canSnapshot
      Indicates whether we can make snapshots from screen or not.
    • owner

      private Component owner
      The component mouse coordinates are relative to, may be null.
    • contents

      private 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.
    • oldBorder

      private 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 Container heavyWeightContainer
      The heavy weight container of the popup contents, may be null.
    • POINT

      private static final Point POINT
      The 'scratch pad' objects used to calculate dirty regions of the screen snapshots.
      See Also:
    • RECT

      private static final Rectangle RECT
  • Constructor Details

    • ShadowPopup

      public ShadowPopup()
  • Method Details

    • getInstance

      static Popup getInstance(Component owner, Component contents, int x, int y, Popup delegate)
      Returns a previously used ShadowPopup, 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 the Popup. Once a Popup has been disposed you should no longer invoke methods on it. A disposed Popup may be reclaimed and later used based on the PopupFactory. As such, if you invoke methods on a disposed Popup, indeterminate behavior will result.

      In addition to the superclass behavior, we reset the stored horizontal and vertical drop shadows - if any.

      Overrides:
      hide in class Popup
    • show

      public void show()
      Makes the Popup visible. If the popup has a heavy-weight container, we try to snapshot the background. If the Popup is currently visible, it remains visible.
      Overrides:
      show in class Popup
    • reset

      private void reset(Component owner, Component contents, int x, int y, Popup popup)
      Reinitializes this ShadowPopup using the given parameters.
      Parameters:
      owner - component mouse coordinates are relative to, may be null
      contents - the contents of the popup
      x - the desired x location of the popup
      y - the desired y location of the popup
      popup - 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:
    • getLayeredPane

      private Container getLayeredPane()
      Returns:
      the top level layered pane which contains the owner.