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;
007import java.util.Random;
008
009/**
010 * Christmas animation extension. Copied from Icedtea-Web.
011 * @author Jiri Vanek (Red Hat)
012 * @see <a href="http://icedtea.classpath.org/hg/icedtea-web/rev/87d3081ab573">Initial commit</a>
013 * @since 14578
014 */
015public class ChristmasExtension implements AnimationExtension {
016
017    private static final Random seed = new Random();
018    private final List<IAnimObject> objs = new ArrayList<>(50);
019
020    @Override
021    public void paint(Graphics g) {
022        objs.forEach(o -> o.paint(g));
023    }
024
025    @Override
026    public void animate() {
027        objs.forEach(IAnimObject::animate);
028    }
029
030    @Override
031    public final void adjustForSize(int w, int h, int x, int y) {
032        int count = w / (2 * (Star.averageStarWidth + 1));
033        while (objs.size() > count) {
034            objs.remove(objs.size() - 1);
035        }
036        objs.forEach(o -> o.setExtend(w, h));
037        while (objs.size() < count) {
038            objs.add(seed.nextInt(5) > 0 ? new Star(w, h) : new DropImage(w, h));
039        }
040    }
041}