001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.animation; 003 004import java.awt.Graphics; 005import java.util.ArrayList; 006import java.util.List; 007 008/** 009 * Christmas animation extension. Copied from Icedtea-Web. 010 * @author Jiri Vanek (Red Hat) 011 * @see <a href="http://icedtea.classpath.org/hg/icedtea-web/rev/87d3081ab573">Initial commit</a> 012 * @since 14578 013 */ 014public class ChristmasExtension implements AnimationExtension { 015 016 private final List<Star> stars = new ArrayList<>(50); 017 018 @Override 019 public void paint(Graphics g) { 020 stars.forEach(s -> s.paint(g)); 021 } 022 023 @Override 024 public void animate() { 025 stars.forEach(Star::animate); 026 } 027 028 @Override 029 public final void adjustForSize(int w, int h) { 030 int count = w / (2 * (Star.averageStarWidth + 1)); 031 while (stars.size() > count) { 032 stars.remove(stars.size() - 1); 033 } 034 while (stars.size() < count) { 035 stars.add(new Star(w, h)); 036 } 037 } 038}