# HG changeset patch # User Jiri Vanek # Date 1390227966 -3600 # Node ID 2e5478f9c65a2d97c4f5d2c878486c02e093e78e # Parent 91e191cac1181a6c709da0b2d0f4e2175381b8c4 Added Christmas splashscreen extension. diff -r 91e191cac118 -r 2e5478f9c65a ChangeLog --- a/ChangeLog Tue Jan 07 10:12:17 2014 +0100 +++ b/ChangeLog Mon Jan 20 15:26:06 2014 +0100 @@ -1,3 +1,23 @@ +2014-01-20 Jiri Vanek + + Added Christmas splashscreen extension. + * netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java: + base colors are derived from active extension. And extension is painted (if any) + * netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ErrorPainter.java: + same + * netx/net/sourceforge/jnlp/splashscreen/parts/extensions/ChristmasExtension.java: + extension valid in Christmas time, painting falling stars and dimming colors. + * netx/net/sourceforge/jnlp/splashscreen/parts/extensions/ExtensionManager.java + provider of extension. Know only the Christmas one right now. + * netx/net/sourceforge/jnlp/splashscreen/parts/extensions/NoExtension.java: + no op extension for no extension times + * netx/net/sourceforge/jnlp/splashscreen/parts/extensions/SplashExtension.java: + unfinished extension interface + * tests/netx/unit/net/sourceforge/jnlp/splashscreen/ErrorSplashScreenTest.java: + and + * tests/netx/unit/net/sourceforge/jnlp/splashscreen/SplashScreenTest.java: + adapted to current purposes + 2013-01-07 Adam Domurad Backport of Fix PR1271: icedtea-web does not handle javascript:-protocol URLs diff -r 91e191cac118 -r 2e5478f9c65a netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java --- a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java Tue Jan 07 10:12:17 2014 +0100 +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java Mon Jan 20 15:26:06 2014 +0100 @@ -58,6 +58,7 @@ import net.sourceforge.jnlp.splashscreen.parts.BasicComponentSplashScreen; import net.sourceforge.jnlp.splashscreen.parts.InfoItem; import net.sourceforge.jnlp.splashscreen.parts.InformationElement; +import net.sourceforge.jnlp.splashscreen.parts.extensions.ExtensionManager; import net.sourceforge.jnlp.util.ScreenFinder; public class BasePainter implements Observer { @@ -71,11 +72,11 @@ private int greyTextIncrment = 15; //how quickly is greyed web moving //colors protected static final Color TEA_LIVE_COLOR = new Color(205, 1, 3); - protected static final Color BACKGROUND_LIVE_COLOR = Color.white; + protected static final Color BACKGROUND_LIVE_COLOR = ExtensionManager.getExtension().getBackground(); protected static final Color TEA_LEAFS_STALKS_LIVE_COLOR = Color.black; - protected static final Color PLUGIN_LIVE_COLOR = Color.black; - protected static final Color WATER_LIVE_COLOR = new Color(80, 131, 160); - protected static final Color PLAIN_TEXT_LIVE_COLOR = Color.black; + protected static final Color PLUGIN_LIVE_COLOR = ExtensionManager.getExtension().getPluginTextColor(); + public static final Color WATER_LIVE_COLOR = new Color(80, 131, 160); + protected static final Color PLAIN_TEXT_LIVE_COLOR = ExtensionManager.getExtension().getTextColor(); protected Color teaColor; protected Color backgroundColor; protected Color teaLeafsStalksColor; @@ -224,6 +225,7 @@ this.master = master; setColors(); adjustForSize(master.getSplashWidth(), master.getSplashHeight()); + ExtensionManager.getExtension().adjustForSize(master.getSplashWidth(), master.getSplashHeight()); if (startAnimation) { startAnimationThreads(); } @@ -231,6 +233,7 @@ } public void increaseAnimationPosition() { + ExtensionManager.getExtension().animate(); animationsPosition += greyTextIncrment; } @@ -248,6 +251,7 @@ } if (showNiceTexts) { + ExtensionManager.getExtension().paint(g, this); paintNiceTexts(g2d); } else { paintPlainTexts(g2d); @@ -262,6 +266,7 @@ //enablings depends on fonts setEnablings(width, height, master.getVersion(), master.getInformationElement(), (Graphics2D) (master.getGraphics())); prerenderedStuff = prerenderStill(); + ExtensionManager.getExtension().adjustForSize(width, height); } private void setEnablings(int w, int h, String version, InformationElement ic, Graphics2D g2d) { @@ -543,6 +548,7 @@ @Override public void run() { + ExtensionManager.getExtension().animate(); master.repaint(); } }); @@ -550,4 +556,14 @@ ex.printStackTrace(); } } + + public Color getWaterColor() { + return waterColor; + } + + public Color getBackgroundColor() { + return backgroundColor; + } + + } diff -r 91e191cac118 -r 2e5478f9c65a netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ErrorPainter.java --- a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ErrorPainter.java Tue Jan 07 10:12:17 2014 +0100 +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ErrorPainter.java Mon Jan 20 15:26:06 2014 +0100 @@ -48,6 +48,7 @@ import net.sourceforge.jnlp.runtime.Translator; import net.sourceforge.jnlp.splashscreen.parts.BasicComponentSplashScreen; import net.sourceforge.jnlp.splashscreen.parts.InformationElement; +import net.sourceforge.jnlp.splashscreen.parts.extensions.ExtensionManager; public final class ErrorPainter extends BasePainter { @@ -129,6 +130,7 @@ } if (super.showNiceTexts) { + ExtensionManager.getExtension().paint(g, this); paintNiceTexts(g2d); } else { paintPlainTexts(g2d); diff -r 91e191cac118 -r 2e5478f9c65a netx/net/sourceforge/jnlp/splashscreen/parts/extensions/ChristmasExtension.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/extensions/ChristmasExtension.java Mon Jan 20 15:26:06 2014 +0100 @@ -0,0 +1,257 @@ +/* + Copyright (C) 2012 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + IcedTea is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts.extensions; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Polygon; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.BasePainter; +import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.ErrorPainter; + +public class ChristmasExtension implements SplashExtension { + + @Override + public Color getBackground() { + return Color.black; + } + + @Override + public Color getTextColor() { + return Color.DARK_GRAY; + } + + @Override + public Color getPluginTextColor() { + return new Color(30, 30, 30); + } + + ChristmasExtension() { + this(0, 0); + } + private static final Random seed = new Random(); + private static final int avarege_star_width = 10; //stars will be 5-15 + private final int avarege_fall_speed = 4; //2-6 + private final int avarege_rotation_speed = 2; //1-3 + + private class Star { + + private int radiusX; + private int radiusY; + private int maxRadiusX; + private int maxRadiusY; + private int centerX; + private int centerY; + private final int fallSpeed; + private final boolean orientation; + private final int[] originalColor = new int[3]; + private final int[] color = new int[originalColor.length]; + private int direction; + private final boolean haveEight; + + public Star() { + createRadiuses(); + haveEight = seed.nextBoolean(); + this.centerX = seed.nextInt(w + 1); + this.centerY = seed.nextInt(h + 1); + this.fallSpeed = avarege_fall_speed / 2 + seed.nextInt(avarege_fall_speed / 2); + this.orientation = seed.nextBoolean(); + this.direction = -(avarege_rotation_speed / 2 + seed.nextInt(avarege_rotation_speed / 2)); + if (seed.nextInt(4) == 0) { + originalColor[0] = Color.yellow.getRed(); + originalColor[1] = Color.yellow.getGreen(); + originalColor[2] = Color.yellow.getBlue(); + } else { + originalColor[0] = BasePainter.WATER_LIVE_COLOR.getRed(); + originalColor[1] = BasePainter.WATER_LIVE_COLOR.getGreen(); + originalColor[2] = BasePainter.WATER_LIVE_COLOR.getBlue(); + } + } + + public void paint(Graphics g, Color forceColor1, Color forceColor2) { + Color c = g.getColor(); + if (forceColor1 == null || forceColor2 == null) { + g.setColor(new Color(color[0], color[1], color[2])); + } else { + g.setColor(ErrorPainter.interpolateColor(h, centerY, forceColor1, forceColor2)); + } + Polygon p = createPolygon(); + if (haveEight) { + int min1 = Math.min(radiusX, radiusY); + int min2 = min1 / 2; + g.fillRect(centerX - min2, centerY - min2, min1, min1); + } + g.fillPolygon(p); + g.setColor(c); + } + + private void animate() { + centerY += fallSpeed; + if (orientation) { + radiusX += direction; + if (radiusX <= -direction) { + direction = -direction; + radiusX = direction; + } + if (radiusX >= maxRadiusX) { + direction = -direction; + radiusX = maxRadiusX; + } + interpolateColors(radiusX, maxRadiusX); + } else { + radiusY += direction; + if (radiusY <= -direction) { + direction = -direction; + radiusY = direction; + } + if (radiusY >= maxRadiusY) { + direction = -direction; + radiusY = maxRadiusY; + } + interpolateColors(radiusY, maxRadiusY); + } + if (centerY > h + radiusX * 2 || centerY > h + radiusY * 2) { + createRadiuses(); + this.centerX = seed.nextInt(w + 1); + this.centerY = -radiusY * 2; + } + } + + private int createRadius() { + return avarege_star_width / 2 + seed.nextInt(avarege_star_width); + } + + private Polygon createPolygon() { + int min = Math.min(radiusX, radiusY) / 3; + Polygon p = new Polygon(); + p.addPoint(centerX - radiusX, centerY); + p.addPoint(centerX - min, centerY - min); + p.addPoint(centerX, centerY - radiusY); + p.addPoint(centerX + min, centerY - min); + p.addPoint(centerX + radiusX, centerY); + p.addPoint(centerX + min, centerY + min); + p.addPoint(centerX, centerY + radiusY); + p.addPoint(centerX - min, centerY + min); + return p; + } + + private void interpolateColors(int is, int max) { + for (int i = 0; i < originalColor.length; i++) { + int fadeMin; + if (centerY < 0) { + fadeMin = 0; + } else if (centerY > h) { + fadeMin = 255; + } else { + fadeMin = (int) ErrorPainter.interpol(h, centerY, 255, 0); //from white to black + } + int fadeMax; + if (centerY < 0) { + fadeMax = 0; + } else if (centerY > h) { + fadeMax = originalColor[i]; + } else { + fadeMax = (int) ErrorPainter.interpol(h, centerY, originalColor[i], 0); //from color tho black + } + color[i] = (int) ErrorPainter.interpol(max, is, fadeMin, fadeMax); + } + } + + private void createRadiuses() { + this.radiusX = createRadius(); + this.radiusY = radiusX; + switch (seed.nextInt(3)) { + case (0): + radiusX = radiusX + (2 * radiusX) / 3; + break; + case (1): + radiusY = radiusY + (2 * radiusY) / 3; + break; + case (2): + //noop + break; + } + maxRadiusX = radiusX; + maxRadiusY = radiusY; + } + } + private int w; + private int h; + private List stars = new ArrayList(50); + + ChristmasExtension(int w, int h) { + adjustForSize(w, h); + } + + @Override + public void paint(Graphics g, BasePainter b) { + for (ChristmasExtension.Star star : stars) { + Color forceColor1 = null; + Color forceColor2 = null; + if (b instanceof ErrorPainter){ + forceColor1 = b.getBackgroundColor(); + forceColor2 = b.getWaterColor(); + } + star.paint(g, forceColor1, forceColor2); + } + } + + @Override + public void animate() { + for (ChristmasExtension.Star star : stars) { + star.animate(); + + } + } + + @Override + public final void adjustForSize(int w, int h) { + this.w = w; + this.h = h; + int count = w / (2 * (avarege_star_width + 1)); + while (stars.size() > count) { + stars.remove(stars.size() - 1); + } + while (stars.size() < count) { + stars.add(new Star()); + + } + + } +} diff -r 91e191cac118 -r 2e5478f9c65a netx/net/sourceforge/jnlp/splashscreen/parts/extensions/ExtensionManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/extensions/ExtensionManager.java Mon Jan 20 15:26:06 2014 +0100 @@ -0,0 +1,63 @@ +/* + Copyright (C) 2012 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + IcedTea is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts.extensions; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +public class ExtensionManager { + + private static SplashExtension currentExtension; + + public static SplashExtension getExtension() { + if (currentExtension == null) { + if (areChristmas()) { + currentExtension = new ChristmasExtension(); + } else { + currentExtension = new NoExtension(); + } + } + return currentExtension; + } + + private static boolean areChristmas() { + Calendar c = new GregorianCalendar(); + c.setTime(new Date()); + return c.get(Calendar.DAY_OF_YEAR) > 350; + } +} diff -r 91e191cac118 -r 2e5478f9c65a netx/net/sourceforge/jnlp/splashscreen/parts/extensions/NoExtension.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/extensions/NoExtension.java Mon Jan 20 15:26:06 2014 +0100 @@ -0,0 +1,75 @@ +/* + Copyright (C) 2012 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + IcedTea is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts.extensions; + +import java.awt.Color; +import java.awt.Graphics; +import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.BasePainter; + +public class NoExtension implements SplashExtension{ + + public NoExtension() { + } + + @Override + public Color getBackground() { + return Color.white; + } + + @Override + public Color getTextColor() { + return Color.black; + } + + @Override + public Color getPluginTextColor() { + return Color.black; + } + + @Override + public void adjustForSize(int w, int h) { + } + + @Override + public void animate() { + } + + @Override + public void paint(Graphics g, BasePainter origin) { + } + +} diff -r 91e191cac118 -r 2e5478f9c65a netx/net/sourceforge/jnlp/splashscreen/parts/extensions/SplashExtension.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/extensions/SplashExtension.java Mon Jan 20 15:26:06 2014 +0100 @@ -0,0 +1,52 @@ +/* + Copyright (C) 2012 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + IcedTea is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ +package net.sourceforge.jnlp.splashscreen.parts.extensions; + +import java.awt.Color; +import java.awt.Graphics; +import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.BasePainter; + +public interface SplashExtension { + + public Color getBackground() ; + public Color getTextColor() ; + public Color getPluginTextColor(); + public void adjustForSize(int w, int h) ; + public void paint(Graphics g, BasePainter origin) ; + public void animate(); + +} diff -r 91e191cac118 -r 2e5478f9c65a tests/netx/unit/net/sourceforge/jnlp/splashscreen/ErrorSplashScreenTest.java --- a/tests/netx/unit/net/sourceforge/jnlp/splashscreen/ErrorSplashScreenTest.java Tue Jan 07 10:12:17 2014 +0100 +++ b/tests/netx/unit/net/sourceforge/jnlp/splashscreen/ErrorSplashScreenTest.java Mon Jan 20 15:26:06 2014 +0100 @@ -143,6 +143,7 @@ public static void main(String args[]) { ErrorSplashScreenTest app = new ErrorSplashScreenTest(); + app.setSize(800, 600); app.setVisible(true); app.addWindowListener( new WindowAdapter() { diff -r 91e191cac118 -r 2e5478f9c65a tests/netx/unit/net/sourceforge/jnlp/splashscreen/SplashScreenTest.java --- a/tests/netx/unit/net/sourceforge/jnlp/splashscreen/SplashScreenTest.java Tue Jan 07 10:12:17 2014 +0100 +++ b/tests/netx/unit/net/sourceforge/jnlp/splashscreen/SplashScreenTest.java Mon Jan 20 15:26:06 2014 +0100 @@ -57,6 +57,7 @@ static int height = JNLPSplashScreen.DEF_HEIGHT; static SplashPanel panel; private static boolean swap = true; + private static InformationElement ie = new InformationElement(); public SplashScreenTest() { @@ -67,15 +68,14 @@ //setLocation(x, y); setLocationRelativeTo(null); this.pack(); - panel = SplashUtils.getSplashScreen(width, height, SplashUtils.SplashReason.JAVAWS); - InformationElement ie = new InformationElement(); + panel = SplashUtils.getSplashScreen(width, height, SplashUtils.SplashReason.APPLET); ie.setHomepage("http://someones.org/amazing?page"); ie.setTitle("Testing information title"); ie.setvendor("IcedTea-Web team"); ie.addDescription("Testing null description"); ie.addDescription("tsting twoline des ...break\ncription of kind short", InfoItem.descriptionKindShort); - //panel.setInformationElement(ie); - //panel.setVersion("1.2-re45fdg"); + panel.setInformationElement(ie); + panel.setVersion("1.2-re45fdg"); setLayout(new BorderLayout()); getContentPane().add(panel.getSplashComponent(), BorderLayout.CENTER); @@ -145,6 +145,7 @@ public static void main(String args[]) { SplashScreenTest app = new SplashScreenTest(); + app.setSize(800, 600); app.setVisible(true); app.addWindowListener( @@ -159,21 +160,22 @@ panel.startAnimation(); try { - Thread.sleep(5000); + Thread.sleep(10000); } catch (Exception e) { } //not needed //panel.stopAnimation(); if (swap) { - SplashErrorPanel r = SplashUtils.getErrorSplashScreen(panel.getSplashWidth(), panel.getSplashHeight(), SplashUtils.SplashReason.JAVAWS, null); + SplashErrorPanel r = SplashUtils.getErrorSplashScreen(panel.getSplashWidth(), panel.getSplashHeight(), SplashUtils.SplashReason.APPLET, null); + r.setInformationElement(ie); app.remove(panel.getSplashComponent()); r.setPercentage(panel.getPercentage()); r.adjustForSize(); panel = r; app.add(panel.getSplashComponent()); - app.validateTree(); - //app.pack(); - //app.setVisible(true); + app.validate(); + app.pack(); + app.setVisible(true); try { Thread.sleep(10000); } catch (Exception e) {