1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.animation;
|
---|
3 |
|
---|
4 | import java.util.Calendar;
|
---|
5 | import java.util.Date;
|
---|
6 | import java.util.GregorianCalendar;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Animation extension manager. Copied from Icedtea-Web.
|
---|
12 | * @author Jiri Vanek (Red Hat)
|
---|
13 | * @see <a href="http://icedtea.classpath.org/hg/icedtea-web/rev/87d3081ab573">Initial commit</a>
|
---|
14 | * @since 14578
|
---|
15 | */
|
---|
16 | public final class AnimationExtensionManager {
|
---|
17 |
|
---|
18 | private static volatile AnimationExtension currentExtension;
|
---|
19 | private static final BooleanProperty PROP_ANIMATION = new BooleanProperty("gui.start.animation", true);
|
---|
20 |
|
---|
21 | private AnimationExtensionManager() {
|
---|
22 | // Hide default constructor for utility classes
|
---|
23 | }
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Returns the current animation extension.
|
---|
27 | * @return the current animation extension
|
---|
28 | */
|
---|
29 | public static AnimationExtension getExtension() {
|
---|
30 | if (currentExtension == null) {
|
---|
31 | currentExtension = Boolean.TRUE.equals(PROP_ANIMATION.get()) && isChristmas() ? new ChristmasExtension()
|
---|
32 | : new NoExtension();
|
---|
33 | }
|
---|
34 | return currentExtension;
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Determines if an extension other than {@link NoExtension} is enabled.
|
---|
39 | * @return {@code true} if an extension other than {@code NoExtension} is enabled.
|
---|
40 | * @since 17322
|
---|
41 | */
|
---|
42 | public static boolean isExtensionEnabled() {
|
---|
43 | return !(getExtension() instanceof NoExtension);
|
---|
44 | }
|
---|
45 |
|
---|
46 | private static boolean isChristmas() {
|
---|
47 | Calendar c = new GregorianCalendar();
|
---|
48 | c.setTime(new Date());
|
---|
49 | return c.get(Calendar.DAY_OF_YEAR) > 350;
|
---|
50 | }
|
---|
51 | }
|
---|