Class SnowLayerUI

java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.LayerUI<JPanel>
ca.corbett.extras.image.animation.SnowLayerUI
All Implemented Interfaces:
Serializable

public class SnowLayerUI extends LayerUI<JPanel>
A custom LayerUI that can apply a fun "falling snow" effect to a JPanel by drawing little animated snowflakes over it. The underlying panel remains fully interactive while the snow is falling - it's a purely cosmetic effect.

USAGE: Create a JLayer with an instance of this SnowLayerUI, wrapping the JPanel you want to snow on. Call letItSnow(true) to start the snow animation, and letItSnow(false) to stop it.

     JPanel contentPanel = ...;
     SnowLayerUI snowLayerUI = new SnowLayerUI();
     JLayer<JPanel> layeredPanel = new JLayer<>(contentPanel, snowLayerUI);
     containerPanel.add(layeredPanel);

     // Set your snow options, or live with the defaults:
     snowLayerUI.setQuantity(SnowLayerUI.Quantity.Strong);
     snowLayerUI.setWind(SnowLayerUI.Wind.MildRight);

     // Then, in a button handler or whatever:
     snowLayerUI.letItSnow(true); // To start snowing
     snowLayerUI.letItSnow(false); // To stop snowing
 
Since:
swing-extras 2.7
Author:
scorbo2 with claude.ai
See Also:
  • Field Details

    • DEFAULT_QUANTITY

      public static final SnowLayerUI.Quantity DEFAULT_QUANTITY
    • DEFAULT_SNOW_COLOR

      public static final Color DEFAULT_SNOW_COLOR
    • DEFAULT_WIND

      public static final SnowLayerUI.Wind DEFAULT_WIND
  • Constructor Details

    • SnowLayerUI

      public SnowLayerUI()
      Creates a new SnowLayerUI with default settings.
  • Method Details

    • isSnowing

      public boolean isSnowing()
      Reports whether the snow animation is currently active.
    • letItSnow

      public SnowLayerUI letItSnow(boolean isSnowing)
      Let it snow! Or not, depending on the parameter.
    • getQuantity

      public SnowLayerUI.Quantity getQuantity()
      Returns the current snow quantity setting.
    • getWind

      public SnowLayerUI.Wind getWind()
      Returns the current wind setting.
    • setWind

      public void setWind(SnowLayerUI.Wind wind)
      Sets the wind effect for the snowflakes.
    • getSnowColor

      public Color getSnowColor()
      Returns the current snow color.
    • setSnowColor

      public SnowLayerUI setSnowColor(Color snowColor)
      Why would you choose anything other than white for snow?
    • setQuantity

      public void setQuantity(SnowLayerUI.Quantity quantity)
      Sets the snow quantity setting.
    • installUI

      public void installUI(JComponent c)
      Invoked when this UI delegate is being installed on a JLayer. We don't automatically start snowing when added! We wait for an explicit call to letItSnow(true).
      Overrides:
      installUI in class LayerUI<JPanel>
    • uninstallUI

      public void uninstallUI(JComponent c)
      Overrides:
      uninstallUI in class LayerUI<JPanel>
    • paint

      public void paint(Graphics g, JComponent c)
      Overrides:
      paint in class LayerUI<JPanel>