001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.animation; 003 004import java.time.LocalDate; 005import java.time.ZoneId; 006 007import org.openstreetmap.josm.data.preferences.BooleanProperty; 008 009/** 010 * Animation extension manager. 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 final class AnimationExtensionManager { 016 017 private static volatile AnimationExtension currentExtension; 018 private static final BooleanProperty PROP_ANIMATION = new BooleanProperty("gui.start.animation", true); 019 020 private AnimationExtensionManager() { 021 // Hide default constructor for utility classes 022 } 023 024 /** 025 * Returns the current animation extension. 026 * @return the current animation extension 027 */ 028 public static AnimationExtension getExtension() { 029 if (currentExtension == null) { 030 currentExtension = Boolean.TRUE.equals(PROP_ANIMATION.get()) && isChristmas() ? new ChristmasExtension() 031 : new NoExtension(); 032 } 033 return currentExtension; 034 } 035 036 /** 037 * Determines if an extension other than {@link NoExtension} is enabled. 038 * @return {@code true} if an extension other than {@code NoExtension} is enabled. 039 * @since 17322 040 */ 041 public static boolean isExtensionEnabled() { 042 return !(getExtension() instanceof NoExtension); 043 } 044 045 private static boolean isChristmas() { 046 return LocalDate.now(ZoneId.systemDefault()).getDayOfYear() > 350; 047 } 048}