diff options
Diffstat (limited to 'netx/net/sourceforge')
29 files changed, 3839 insertions, 11 deletions
diff --git a/netx/net/sourceforge/jnlp/GuiLaunchHandler.java b/netx/net/sourceforge/jnlp/GuiLaunchHandler.java index 7bb8bc1..ad8ba96 100644 --- a/netx/net/sourceforge/jnlp/GuiLaunchHandler.java +++ b/netx/net/sourceforge/jnlp/GuiLaunchHandler.java @@ -117,7 +117,7 @@ public class GuiLaunchHandler extends AbstractLaunchHandler { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { - splashScreen = new JNLPSplashScreen(resourceTracker, null, null); + splashScreen = new JNLPSplashScreen(resourceTracker, file); } }); } catch (InterruptedException ie) { diff --git a/netx/net/sourceforge/jnlp/InformationDesc.java b/netx/net/sourceforge/jnlp/InformationDesc.java index cec8964..f83329a 100644 --- a/netx/net/sourceforge/jnlp/InformationDesc.java +++ b/netx/net/sourceforge/jnlp/InformationDesc.java @@ -34,7 +34,8 @@ public class InformationDesc { // specification name. /** one-line description */ - public static final Object ONE_LINE = "oneline"; + /**http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html**/ + public static final Object ONE_LINE = "one-line"; /** short description */ public static final Object SHORT = "short"; @@ -110,13 +111,24 @@ public class InformationDesc { * Information.TOOLTIP, Information.DEFAULT */ public String getDescription(Object kind) { - String result = (String) getItem("description-" + kind); + String result = getDescriptionStrict(kind); if (result == null) return (String) getItem("description-" + DEFAULT); else return result; } + /** + * Returns the application's description of the specified type. + * + * @param kind one of Information.SHORT, Information.ONE_LINE, + * Information.TOOLTIP, Information.DEFAULT + */ + public String getDescriptionStrict(Object kind) { + return (String) getItem("description-" + kind); + + } + /** * Returns the icons specified by the JNLP file. * diff --git a/netx/net/sourceforge/jnlp/JNLPSplashScreen.java b/netx/net/sourceforge/jnlp/JNLPSplashScreen.java index 867e953..212696a 100644 --- a/netx/net/sourceforge/jnlp/JNLPSplashScreen.java +++ b/netx/net/sourceforge/jnlp/JNLPSplashScreen.java @@ -1,5 +1,43 @@ +/* JNLPSplashScreen.java + 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; +import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; @@ -15,19 +53,23 @@ import javax.swing.JDialog; import net.sourceforge.jnlp.cache.ResourceTracker; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.util.ImageResources; +import net.sourceforge.jnlp.splashscreen.SplashPanel; +import net.sourceforge.jnlp.splashscreen.SplashUtils; +import net.sourceforge.jnlp.splashscreen.parts.InformationElement; public class JNLPSplashScreen extends JDialog { - String applicationTitle; - String applicationVendor; ResourceTracker resourceTracker; URL splashImageUrl; Image splashImage; + private final JNLPFile file; + public static final int DEF_WIDTH=635; + public static final int DEF_HEIGHT=480; + private SplashPanel componetSplash; - public JNLPSplashScreen(ResourceTracker resourceTracker, - String applicationTitle, String applicationVendor) { + public JNLPSplashScreen(ResourceTracker resourceTracker, final JNLPFile file) { setIconImages(ImageResources.INSTANCE.getApplicationImages()); @@ -36,8 +78,8 @@ public class JNLPSplashScreen extends JDialog { // JNLP file. this.resourceTracker = resourceTracker; - this.applicationTitle = applicationTitle; - this.applicationVendor = applicationVendor; + + this.file=file; } diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index 587e6ae..3c42cb8 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -440,3 +440,27 @@ CLResetDescription=Resets the value for property-name to it\'s default value CLInfoDescription=Shows more information about the given property
CLCheckDescription=Shows any properties that have been defined but are not recognized by IcedTea Web
CLHelpDescription=The itweb-settings tool allows a user to modify, view and check configuration. \nTo use the GUI, do not pass any arguments. To use the CLI mode, pass in the approrpiate command and parameters. For help with a particular command, try: {0} command help
+
+# splash screen related
+SPLASHerror = Click here for details. Serious exception occurred.
+SPLASH_ERROR = ERROR
+SPLASHtitle = Title
+SPLASHvendor = Vendor
+SPLASHhomepage = Homepage
+SPLASHdescription = Description
+SPLASHClose= Close
+SPLASHclosewAndCopyException = Close and copy StackTrace to clipboard
+SPLASHexOccured = Sorry, an serious exception have occurred...
+SPLASHHome = Home
+SPLASHcantCopyEx = Can not copy exception
+SPLASHnoExRecorded = No exception recorded
+SPLASHmainL1 = For even more information you can visit {0} and follow the steps to obtain information and fill bug
+SPLASHurl = http://icedtea.classpath.org/wiki/IcedTea-Web#Filing_bugs
+SPLASHurlLooks = http://icedtea.classpath.org/wiki/IcedTea-Web
+SPLASHmainL3 = Sorry no more information available, try to launch browser from command line and watch output.
+SPLASHcloseAndCopyShorter = Close and copy to clipboard
+SPLASHmainL4 = We have noticed exception written below, for even more information try to launch browser from command line and watch output
+SPLASHexWas = Exception was:
+SPLASHcfl = Can't follow link to
+SPLASHvendorsInfo = Information from vendor of your application
+SPLASHanotherInfo = Another available info
diff --git a/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java b/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java index 03ab465..8e89530 100644 --- a/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java +++ b/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java @@ -27,6 +27,7 @@ import java.io.*; import javax.swing.*; import net.sourceforge.jnlp.*; +import net.sourceforge.jnlp.splashscreen.SplashController; import net.sourceforge.jnlp.util.*; /** @@ -130,6 +131,15 @@ public class AppletEnvironment implements AppletContext, AppletStub { return cont; } + /** + * container must be SplashContoler + * + */ + public SplashController getSplashControler() { + + return (SplashController)cont; + } + /** * Initialize, start, and show the applet. */ diff --git a/netx/net/sourceforge/jnlp/runtime/Boot.java b/netx/net/sourceforge/jnlp/runtime/Boot.java index b35b338..cd7d71a 100644 --- a/netx/net/sourceforge/jnlp/runtime/Boot.java +++ b/netx/net/sourceforge/jnlp/runtime/Boot.java @@ -53,8 +53,8 @@ public final class Boot implements PrivilegedAction<Void> { // todo: decide whether a spawned netx (external launch) // should inherit the same options as this instance (store argv?) - private static final String name = Boot.class.getPackage().getImplementationTitle(); - private static final String version = Boot.class.getPackage().getImplementationVersion(); + public static final String name = Boot.class.getPackage().getImplementationTitle(); + public static final String version = Boot.class.getPackage().getImplementationVersion(); /** the text to display before launching the about link */ private static final String aboutMessage = "" diff --git a/netx/net/sourceforge/jnlp/splashscreen/SplashController.java b/netx/net/sourceforge/jnlp/splashscreen/SplashController.java new file mode 100644 index 0000000..df042e7 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/SplashController.java @@ -0,0 +1,48 @@ +/* SplashController.java +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; + +public interface SplashController { + + public void removeSplash(); + + public void replaceSplash(SplashPanel r); + + public int getSplashWidth(); + + public int getSplashHeigth(); +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/SplashErrorPanel.java b/netx/net/sourceforge/jnlp/splashscreen/SplashErrorPanel.java new file mode 100644 index 0000000..6f58c3e --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/SplashErrorPanel.java @@ -0,0 +1,47 @@ +/* SplashErrorPanel.java +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; + +public interface SplashErrorPanel extends SplashPanel { + + /** + * When applet loading fails, then dying stacktrace can be set, and is then shown to user on demand. + */ + public Throwable getLoadingException(); + + public void setLoadingException(Throwable loadingException); +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/SplashPanel.java b/netx/net/sourceforge/jnlp/splashscreen/SplashPanel.java new file mode 100644 index 0000000..6710685 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/SplashPanel.java @@ -0,0 +1,115 @@ +/* SplashPanel.java +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; + +import java.awt.Graphics; +import java.awt.event.ComponentListener; + +import javax.swing.JComponent; +import net.sourceforge.jnlp.splashscreen.SplashUtils.SplashReason; +import net.sourceforge.jnlp.splashscreen.parts.InformationElement; + +public interface SplashPanel { + + /** + * The plugin splashscreens must be placed into another containers, + * So must return themselves as JComponent. + * Mostly your SplashScreen will extend some JComponent, so this method will + * just return "this" + */ + public JComponent getSplashComponent(); + + + public void setInformationElement(InformationElement content); + + public InformationElement getInformationElement(); + + /** Width of the plugin window */ + public void setSplashWidth(int pluginWidth); + + /** Height of the plugin window */ + public void setSplashHeight(int pluginHeight); + + /** Width of the plugin window */ + public int getSplashWidth(); + + /** Height of the plugin window */ + public int getSplashHeight(); + + public void adjustForSize(); + + // Add a new listener for resizes + public void addComponentListener(ComponentListener cl); + + public boolean isAnimationRunning(); + + /** + * Methods to start the animation in the splash panel. + * + * This method exits after starting a new thread to do the animation. It + * is synchronized to prevent multiple startAnimation threads from being created. + */ + public void startAnimation(); + + public void stopAnimation(); + + void paintTo(Graphics g); + + public void setSplashReason(SplashReason splashReason); + + public SplashReason getSplashReason(); + + /** + * Version can be printed in splash window + * @param version + */ + public void setVersion(String version); + + String getVersion(); + + /** + * how mny percentage loaded is shown in progress bar (if any) + * @param done - should be in 0-100 inclusinve + */ + public void setPercentage(int done); + + /** + * returns state of loading progress bar + * @return percentage showed in possible progress bar - should be in 0-100 + */ + int getPercentage(); +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/SplashUtils.java b/netx/net/sourceforge/jnlp/splashscreen/SplashUtils.java new file mode 100644 index 0000000..7aa84cb --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/SplashUtils.java @@ -0,0 +1,212 @@ +/* SplashUtils.java +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; + +import net.sourceforge.jnlp.runtime.AppletEnvironment; +import net.sourceforge.jnlp.runtime.AppletInstance; +import net.sourceforge.jnlp.runtime.Boot; +import net.sourceforge.jnlp.runtime.JNLPRuntime; +import net.sourceforge.jnlp.splashscreen.impls.*; + +public class SplashUtils { + + static final String ICEDTEA_WEB_PLUGIN_SPLASH = "ICEDTEA_WEB_PLUGIN_SPLASH"; + static final String ICEDTEA_WEB_SPLASH = "ICEDTEA_WEB_SPLASH"; + static final String NONE = "none"; + static final String DEFAULT = "default"; + + + /** + * + * Indicator whether to show icedtea-web plugin or just icedtea-web + * For "just icedtea-web" will be done an attempt to show content of + * information element + * + */ + public static enum SplashReason { + + APPLET, JAVAWS; + + @Override + public String toString() { + switch (this) { + case APPLET: + return "IcedTea-Web Plugin"; + case JAVAWS: + return "IcedTea-Web"; + } + return "unknown"; + } + } + + public static void showErrorCaught(Throwable ex, AppletInstance appletInstance) { + try { + showError(ex, appletInstance); + } catch (Throwable t) { + if (JNLPRuntime.isDebug()) { + // prinitng this exception is discutable. I have let it in for case that + //some retyping will fail + t.printStackTrace(); + } + } + } + + public static void showError(Throwable ex, AppletInstance appletInstance) { + if (appletInstance == null) { + return; + } + AppletEnvironment ae = appletInstance.getAppletEnvironment(); + showError(ex, ae); + } + + public static void showError(Throwable ex, AppletEnvironment ae) { + if (ae == null) { + return; + } + SplashController p = ae.getSplashControler(); + showError(ex, p); + } + + public static void showError(Throwable ex, SplashController f) { + if (f == null) { + return; + } + + f.replaceSplash(getErrorSplashScreen(f.getSplashWidth(), f.getSplashHeigth(), ex)); + } + + + private static SplashReason getReason() { + if (JNLPRuntime.isWebstartApplication()){ + return SplashReason.JAVAWS; + }else{ + return SplashReason.APPLET; + } + + } + + + /** + * Warrning - splash should have recieve width and height without borders. + * plugin's window have NO border, but javaws window HAVE border. This msut be calcualted prior calling this method + * @param width + * @param height + * @return + */ + public static SplashPanel getSplashScreen(int width, int height) { + return getSplashScreen(width, height, getReason()); + } + + /** + * Warrning - splash should have recieve width and height without borders. + * plugin's window have NO border, but javaws window HAVE border. This msut be calcualted prior calling this method + * @param width + * @param height + * @param ex - exception to be shown if any + * @return + */ + public static SplashErrorPanel getErrorSplashScreen(int width, int height, Throwable ex) { + return getErrorSplashScreen(width, height, getReason(), ex); + } + + /** + * Warrning - splash should have recieve width and height without borders. + * plugin's window have NO border, but javaws window HAVE border. This msut be calcualted prior calling this method + * @param width + * @param height + * @param splashReason + * @return + */ + static SplashPanel getSplashScreen(int width, int height, SplashUtils.SplashReason splashReason) { + return getSplashScreen(width, height, splashReason, null, false); + } + + /** + * Warrning - splash should have recieve width and height without borders. + * plugin's window have NO border, but javaws window HAVE border. This msut be calcualted prior calling this method + * @param width + * @param height + * @param splashReason + * @return + */ + static SplashErrorPanel getErrorSplashScreen(int width, int height, SplashUtils.SplashReason splashReason, Throwable ex) { + return (SplashErrorPanel) getSplashScreen(width, height, splashReason, ex, true); + } + + static SplashPanel getSplashScreen(int width, int height, SplashUtils.SplashReason splashReason, Throwable loadingException, boolean isError) { + String splashEnvironmetVar = null; + String pluginSplashEnvironmetVar = null; + try { + pluginSplashEnvironmetVar = System.getenv(ICEDTEA_WEB_PLUGIN_SPLASH); + splashEnvironmetVar = System.getenv(ICEDTEA_WEB_SPLASH); + } catch (Exception ex) { + ex.printStackTrace(); + } + SplashPanel sp = null; + if (SplashReason.JAVAWS.equals(splashReason)) { + if (NONE.equals(splashEnvironmetVar)) { + return null; + } + if (DEFAULT.equals(splashEnvironmetVar)) { + if (isError) { + sp = new DefaultErrorSplashScreen2012(width, height, splashReason, loadingException); + } else { + sp = new DefaultSplashScreen2012(width, height, splashReason); + } + } + } + if (SplashReason.APPLET.equals(splashReason)) { + if (NONE.equals(pluginSplashEnvironmetVar)) { + return null; + } + if (DEFAULT.equals(pluginSplashEnvironmetVar)) { + if (isError) { + sp = new DefaultErrorSplashScreen2012(width, height, splashReason, loadingException); + } else { + sp = new DefaultSplashScreen2012(width, height, splashReason); + } + } + } + if (isError) { + sp = new DefaultErrorSplashScreen2012(width, height, splashReason, loadingException); + } else { + sp = new DefaultSplashScreen2012(width, height, splashReason); + } + sp.setVersion(Boot.version); + return sp; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultErrorSplashScreen2012.java b/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultErrorSplashScreen2012.java new file mode 100644 index 0000000..a9e38a2 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultErrorSplashScreen2012.java @@ -0,0 +1,118 @@ +/* DefaultErrorSplashScreen12.java +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.impls; + +import java.awt.Graphics; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import net.sourceforge.jnlp.splashscreen.SplashUtils.SplashReason; +import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.ErrorPainter; +import net.sourceforge.jnlp.splashscreen.parts.BasicComponentErrorSplashScreen; + +public final class DefaultErrorSplashScreen2012 extends BasicComponentErrorSplashScreen { + + private final DefaultErrorSplashScreen2012 self; + private final ErrorPainter painter; + private final DefaultSplashScreens2012Commons commons; + + public DefaultErrorSplashScreen2012(int width, int height, SplashReason splashReason, Throwable ex) { + //setting width and height now is causing unnecessary blinking + //setSplashHeight(height); + //setSplashWidth(width); + //to have this in inner classes + self = this; + setLoadingException(ex); + setSplashReason(splashReason); + painter = new ErrorPainter(self, true); + addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + if (((ErrorPainter) painter).getErrorCorner() != null + && e.getX() > ((ErrorPainter) painter).getErrorCorner().x + && e.getY() > ((ErrorPainter) painter).getErrorCorner().y) { + raiseExceptionDialog(); + } + } + }); + commons = new DefaultSplashScreens2012Commons(painter, self); + } + + @Override + public void paintComponent(Graphics g) { + paintTo(g); + } + + @Override + public void paintTo(Graphics g) { + commons.paintTo(g); + + + } + + @Override + public void adjustForSize() { + commons.adjustForSize(); + } + + @Override + public void stopAnimation() { + commons.stopAnimation(); + } + + /** + * Methods to start the animation in the splash panel. + * + * This method exits after starting a new thread to do the animation. It + * is synchronized to prevent multiple startAnimation threads from being created. + */ + @Override + public void startAnimation() { + commons.startAnimation(); + } + + @Override + public void setPercentage(int done) { + commons.setPercentage(done); + } + + @Override + public int getPercentage() { + return commons.getPercentage(); + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultSplashScreen2012.java b/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultSplashScreen2012.java new file mode 100644 index 0000000..7b964f7 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultSplashScreen2012.java @@ -0,0 +1,105 @@ +/* DefaultSplashScreen12.java +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.impls; + +import java.awt.Graphics; + + +import net.sourceforge.jnlp.splashscreen.SplashUtils.SplashReason; +import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.BasePainter; +import net.sourceforge.jnlp.splashscreen.parts.BasicComponentSplashScreen; + +public final class DefaultSplashScreen2012 extends BasicComponentSplashScreen { + + private final DefaultSplashScreen2012 self; + private final BasePainter painter; + private final DefaultSplashScreens2012Commons commons; + + public DefaultSplashScreen2012(int width, int height, SplashReason splashReason) { + //setting width and height now is causing unnecessary blinking + //setSplashHeight(height); + //setSplashWidth(width); + //to have this in inner classes + self = this; + setSplashReason(splashReason); + painter = new BasePainter(this); + commons = new DefaultSplashScreens2012Commons(painter, self); + } + + @Override + public void paintComponent(Graphics g) { + paintTo(g); + } + + @Override + public void paintTo(Graphics g) { + commons.paintTo(g); + + + } + + @Override + public void adjustForSize() { + commons.adjustForSize(); + } + + @Override + public void stopAnimation() { + commons.stopAnimation(); + } + + /** + * Methods to start the animation in the splash panel. + * + * This method exits after starting a new thread to do the animation. It + * is synchronized to prevent multiple startAnimation threads from being created. + */ + @Override + public void startAnimation() { + commons.startAnimation(); + } + + @Override + public void setPercentage(int done) { + commons.setPercentage(done); + } + + @Override + public int getPercentage() { + return commons.getPercentage(); + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultSplashScreens2012Commons.java b/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultSplashScreens2012Commons.java new file mode 100644 index 0000000..a22d943 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/DefaultSplashScreens2012Commons.java @@ -0,0 +1,119 @@ +/* DefaultSplashScreensCommons2012.java +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.impls; + +import java.awt.Graphics; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Observable; + +import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.BasePainter; +import net.sourceforge.jnlp.splashscreen.parts.BasicComponentSplashScreen; + +public final class DefaultSplashScreens2012Commons { + + private final BasicComponentSplashScreen parent; + private final BasePainter painter; + + + public DefaultSplashScreens2012Commons(BasePainter painterr, BasicComponentSplashScreen parentt) { + this.painter = painterr; + this.parent = parentt; + parent.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + painter.increaseAnimationPosition(); + parent.repaint(); + } + }); + // Add a new listener for resizes + parent.addComponentListener(new ComponentAdapter() { + // Re-adjust variables based on size + + @Override + public void componentResized(ComponentEvent e) { + parent.setSplashWidth(parent.getWidth()); + parent.setSplashHeight(parent.getHeight()); + parent.adjustForSize(); + parent.repaint(); + } + }); + } + + public void paintTo(Graphics g) { + painter.paint(g); + + + } + + public void adjustForSize() { + painter.adjustForSize(parent.getSplashWidth(), parent.getSplashHeight()); + } + + public void stopAnimation() { + parent.setAnimationRunning(false); + } + + /** + * Methods to start the animation in the splash panel. + * + * This method exits after starting a new thread to do the animation. It + * is synchronized to prevent multiple startAnimation threads from being created. + */ + public synchronized void startAnimation() { + if (parent.isAnimationRunning()) { + return; + } + parent.setAnimationRunning(true); + painter.startAnimationThreads(); + + } + + public void setPercentage(int done) { + painter.clearCachedWaterTextImage(); + painter.setWaterLevel(done); + } + + public int getPercentage() { + return painter.getWaterLevel(); + } + + +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java new file mode 100644 index 0000000..729b278 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java @@ -0,0 +1,540 @@ +/* BasePainter.java +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.impls.defaultsplashscreen2012; + +import net.sourceforge.jnlp.splashscreen.impls.*; +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Toolkit; +import java.awt.font.TextAttribute; +import java.awt.image.BufferedImage; +import java.util.HashMap; +import java.util.List; + +import java.util.Map; +import java.util.Observable; +import java.util.Observer; + +import javax.swing.SwingUtilities; +import net.sourceforge.jnlp.splashscreen.SplashUtils.SplashReason; +import net.sourceforge.jnlp.splashscreen.parts.BasicComponentSplashScreen; +import net.sourceforge.jnlp.splashscreen.parts.InfoItem; +import net.sourceforge.jnlp.splashscreen.parts.InformationElement; + +public class BasePainter implements Observer { + + protected final BasicComponentSplashScreen master; + //animations + //waterLevel of water (0-100%) + private int waterLevel = 0; + //waving of water and position of shhadowed WEB + private int animationsPosition = 0; + 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 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 Color teaColor; + protected Color backgroundColor; + protected Color teaLeafsStalksColor; + protected Color pluginColor; + protected Color waterColor; + protected Color plainTextColor; + //BufferedImage tmpBackround; //testingBackground for fitting + protected BufferedImage prerenderedStuff; + private Font teaFont; + private Font icedFont; + private Font webFont; + private Font pluginFont; + private Font plainTextsFont; + private Font alternativeTextFont; + //those spaces are meaningful for centering the text.. thats why alternative;) + private static final String alternativeICED = "Iced "; + private static final String alternativeWeb = "Web "; + private static final String alternativeTtea = " Tea"; + private static final String alternativePlugin = "plugin "; + private static final String ICED = "Iced"; + private static final String web = "web"; + private static final String tea = "Tea"; + private static final String plugin = "plugin "; + //inidivdual sizes, all converging to ZERO!! + /** + * Experimentaly meassured best top position for painted parts of vectros + */ + private final int WEB_TOP_ALIGMENT = 324; + /** + * Experimentaly meassured best left position for painted parts of vectors + */ + private final int WEB_LEFT_ALIGMENT = 84; + //enabling + protected boolean showNiceTexts = true; + private boolean showLeaf = true; + private boolean showInfo = true; + protected TextWithWaterLevel twl; + protected TextWithWaterLevel oldTwl; + protected boolean canWave = true; + + protected void paintNiceTexts(Graphics2D g2d) { + //the only animated stuff + oldTwl = twl; + twl = new TextWithWaterLevel(ICED, icedFont); + if (oldTwl != null && !canWave) { + twl.setCachedPolygon(oldTwl.getCachedPolygon()); + } + twl.setPercentageOfWater(waterLevel); + twl.setBgColor(backgroundColor); + twl.setWaterColor(waterColor); + twl.cutTo(g2d, scaleX(42), scaleY(278)); + MovingText mt = new MovingText(web, webFont); + mt.setPercentageOfWater(animationsPosition); + mt.cutTo(g2d, scaleX(WEB_LEFT_ALIGMENT), scaleY(WEB_TOP_ALIGMENT)); + } + + protected void paintPlainTexts(Graphics2D g2d) { + g2d.setFont(alternativeTextFont); + g2d.setColor(waterColor); + drawTextAroundCenter(g2d, -0.6d, alternativeICED); + g2d.setColor(teaColor); + drawTextAroundCenter(g2d, -0.6d, alternativeTtea); + g2d.setColor(pluginColor); + String s = getAlternativeProductName(); + int sub = animationsPosition / greyTextIncrment; + sub = sub % s.length(); + if (!master.isAnimationRunning()) { + sub = s.length(); + } + drawTextAroundCenter(g2d, 0.3d, s.substring(0, sub)); + } + //enabling end + + private int scaleAvarage(double origValue) { + return (int) (avarageRatio() * origValue); + } + + private int scaleMax(double origValue) { + return (int) (maxRatio() * origValue); + } + + private int scaleMin(double origValue) { + return (int) (minRatio() * origValue); + } + + private double avarageRatio() { + return (getRatioX() + getRatioY()) / 2d; + } + + private double minRatio() { + return Math.min(getRatioX(), getRatioY()); + } + + private double maxRatio() { + return Math.max(getRatioX(), getRatioY()); + } + + private int scaleY(double origValue) { + return (int) scaleY(master.getSplashHeight(), origValue); + } + + private int scaleX(double origValue) { + return (int) scaleX(master.getSplashWidth(), origValue); + } + + private double getRatioY() { + return getRatio(DefaultSplashScreen2012.ORIGINAL_H, master.getSplashHeight()); + } + + private double getRatioX() { + return getRatio(DefaultSplashScreen2012.ORIGINAL_W, master.getSplashWidth()); + } + + private static double scaleY(double currentSize, double origValue) { + return scale(DefaultSplashScreen2012.ORIGINAL_H, currentSize, origValue); + } + + private static double scaleX(double currentSize, double origValue) { + return scale(DefaultSplashScreen2012.ORIGINAL_W, currentSize, origValue); + } + + private static double getRatioY(double currentSize) { + return getRatio(DefaultSplashScreen2012.ORIGINAL_H, currentSize); + } + + private static double getRatioX(double currentSize) { + return getRatio(DefaultSplashScreen2012.ORIGINAL_W, currentSize); + } + + public static double scale(double origSize, double currentSize, double origValue) { + return getRatio(origSize, currentSize) * origValue; + } + + public static double getRatio(double origSize, double currentSize) { + return (currentSize / origSize); + } + //size is considered from 0-origsize as 0-1. + + //scaling end + public BasePainter(BasicComponentSplashScreen master) { + this(master, false); + } + + public BasePainter(BasicComponentSplashScreen master, boolean startAnimation) { + //to have this in inner classes + this.master = master; + setColors(); + adjustForSize(master.getSplashWidth(), master.getSplashHeight()); + if (startAnimation) { + startAnimationThreads(); + } + + } + + public void increaseAnimationPosition() { + animationsPosition += greyTextIncrment; + } + + protected void ensurePrerenderedStuff() { + if (this.prerenderedStuff == null) { + this.prerenderedStuff = prerenderStill(); + } + } + + public void paint(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + ensurePrerenderedStuff(); + if (prerenderedStuff != null) { + g2d.drawImage(prerenderedStuff, 0, 0, null); + } + + if (showNiceTexts) { + paintNiceTexts(g2d); + } else { + paintPlainTexts(g2d); + } + + + + } + + public final void adjustForSize(int width, int height) { + prepareFonts(width, height); + //enablings depends on fonts + setEnablings(width, height, master.getVersion(), master.getInformationElement(), (Graphics2D) (master.getGraphics())); + prerenderedStuff = prerenderStill(); + } + + private void setEnablings(int w, int h, String version, InformationElement ic, Graphics2D g2d) { + showLeaf = true; + if (w > 0 && h > 0) { + //leaf stretch much better to wide then to high + if (h / w > 2 || w / h > 6) { + showLeaf = false; + } + } + showInfo = true; + if (version != null && g2d != null && ic != null && ic.getHeader() != null && ic.getHeader().size() > 0) { + String s = ic.getHeader().get(0); + FontMetrics fm = g2d.getFontMetrics(plainTextsFont); + int versionLength = fm.stringWidth(version); + int firsDescLineLengthg = fm.stringWidth(s); + if (firsDescLineLengthg > w - versionLength - 10) { + showInfo = false; + } + } + if (Math.min(h, w) < Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 10) { + showNiceTexts = false; + } else { + showNiceTexts = true; + } + } + + public final void startAnimationThreads() { + Thread tt = getMovingTextThread(); + tt.start(); + Thread t = getWaterLevelThread(); + t.start(); + } + + private void prepareFonts(int w, int h) { + master.setSplashHeight(h); + master.setSplashWidth(w); + Map<TextAttribute, Object> teaFontAttributes = new HashMap<TextAttribute, Object>(); + teaFontAttributes.put(TextAttribute.SIZE, new Integer(scaleMin(84))); + teaFontAttributes.put(TextAttribute.WIDTH, new Double((0.95))); + teaFontAttributes.put(TextAttribute.FAMILY, "Serif"); + teaFont = new Font(teaFontAttributes); + Map<TextAttribute, Object> icedFontAttributes = new HashMap<TextAttribute, Object>(); + icedFontAttributes.put(TextAttribute.SIZE, new Integer(scaleMin(82))); + icedFontAttributes.put(TextAttribute.WIDTH, new Double((0.80))); + icedFontAttributes.put(TextAttribute.FAMILY, "Serif"); + icedFont = new Font(icedFontAttributes); + Map<TextAttribute, Object> webFontAttributes = new HashMap<TextAttribute, Object>(); + webFontAttributes.put(TextAttribute.SIZE, new Integer(scaleMin(41))); + webFontAttributes.put(TextAttribute.WIDTH, new Double((2))); + webFontAttributes.put(TextAttribute.FAMILY, "Serif"); + webFont = new Font(webFontAttributes); + Map<TextAttribute, Object> pluginFontAttributes = new HashMap<TextAttribute, Object>(); + pluginFontAttributes.put(TextAttribute.SIZE, new Integer(scaleMin(32))); + pluginFontAttributes.put(TextAttribute.WEIGHT, new Double((5d))); + pluginFontAttributes.put(TextAttribute.WIDTH, new Double((0.9))); + pluginFontAttributes.put(TextAttribute.FAMILY, "Serif"); + pluginFont = new Font(pluginFontAttributes); + Map<TextAttribute, Object> plainFontAttributes = new HashMap<TextAttribute, Object>(); + plainFontAttributes.put(TextAttribute.SIZE, new Integer(12)); + plainFontAttributes.put(TextAttribute.FAMILY, "Monospaced"); + plainTextsFont = new Font(plainFontAttributes); + Map<TextAttribute, Object> alternativeTextFontAttributes = new HashMap<TextAttribute, Object>(); + alternativeTextFontAttributes.put(TextAttribute.SIZE, Math.min(w, h) / 5); + alternativeTextFontAttributes.put(TextAttribute.WIDTH, new Double((0.7))); + alternativeTextFontAttributes.put(TextAttribute.FAMILY, "Monospaced"); + alternativeTextFont = new Font(alternativeTextFontAttributes); + + } + + private void setColors() { + + teaColor = TEA_LIVE_COLOR; + backgroundColor = BACKGROUND_LIVE_COLOR; + teaLeafsStalksColor = TEA_LEAFS_STALKS_LIVE_COLOR; + pluginColor = PLUGIN_LIVE_COLOR; + waterColor = WATER_LIVE_COLOR; + plainTextColor = PLAIN_TEXT_LIVE_COLOR; + + } + + protected BufferedImage prerenderStill() { + if (master.getSplashWidth() <= 0 || master.getSplashHeight() <= 0) { + return null; + } + BufferedImage bi = new BufferedImage(master.getSplashWidth(), master.getSplashHeight(), BufferedImage.TYPE_INT_ARGB); + paintStillTo(bi.createGraphics(), master.getInformationElement(), master.getVersion()); + return bi; + } + + protected void paintStillTo(Graphics2D g2d, InformationElement ic, String version) { + RenderingHints r = g2d.getRenderingHints(); + drawBase(g2d, ic, version); + g2d.setRenderingHints(r); + } + + protected void drawTextAroundCenter(Graphics2D g2d, double heightOffset, String msg) { + + int y = (master.getSplashHeight() / 2) + (g2d.getFontMetrics().getHeight() / 2 + (int) (heightOffset * g2d.getFontMetrics().getHeight())); + int x = (master.getSplashWidth() / 2) - (g2d.getFontMetrics().stringWidth(msg) / 2); + g2d.drawString(msg, x, y); + } + + private Thread getMovingTextThread() { + Thread tt = new Thread(new MovingTextRunner(this)); + //tt.setDaemon(true); + return tt; + } + + private final class MovingTextRunner extends Observable implements Runnable { + + private static final int MAX_ANIMATION_VALUE = 10000; + private static final int ANIMATION_RESTART_VALUE = 1; + private static final long MOOVING_TEXT_DELAY = 150; + + public MovingTextRunner(Observer o) { + this.addObserver(o); + } + + @Override + public void run() { + while (master.isAnimationRunning()) { + try { + animationsPosition += greyTextIncrment; + if (animationsPosition > MAX_ANIMATION_VALUE) { + animationsPosition = ANIMATION_RESTART_VALUE; + } + this.setChanged(); + this.notifyObservers(); + Thread.sleep(MOOVING_TEXT_DELAY); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }; + + private Thread getWaterLevelThread() { + Thread t = new Thread(new WaterLevelThread(this)); + //t.setDaemon(true); + return t; + } + + private final class WaterLevelThread extends Observable implements Runnable { + + private static final int MAX_WATERLEVEL_VALUE = 120; + private static final int WATER_LEVEL_INCREMENT = 2; + + private WaterLevelThread(BasePainter o) { + this.addObserver(o); + } + + @Override + public void run() { + while (master.isAnimationRunning()) { + if (waterLevel > MAX_WATERLEVEL_VALUE) { + break; + } + try { + waterLevel += WATER_LEVEL_INCREMENT; + this.setChanged(); + this.notifyObservers(); + //it is risinfg slower and slower + Thread.sleep((waterLevel / 4) * 30); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }; + + private String getAlternativeProductName() { + if (SplashReason.JAVAWS.equals(master.getSplashReason())) { + return alternativeWeb; + } else if (SplashReason.APPLET.equals(master.getSplashReason())) { + return alternativeWeb + alternativePlugin; + } else { + return "...."; + } + } + + protected FontMetrics drawBase(Graphics2D g2d, InformationElement ic, String version) { + g2d.setColor(backgroundColor); + g2d.fillRect(0, 0, master.getSplashWidth() + 5, master.getSplashHeight() + 5); + if (showNiceTexts) { + //g2d.drawImage(tmpBackround, 0, 0, null); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g2d.setFont(teaFont); + g2d.setColor(teaColor); + g2d.drawString(tea, scaleX(42) + g2d.getFontMetrics(icedFont).stringWidth(ICED), scaleY(278)); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); + if (showLeaf) { + g2d.fillPolygon(SplinesDefs.getMainLeafCurve(getRatioX(), getRatioY())); + } + if (showLeaf) { + g2d.fillPolygon(SplinesDefs.getSecondLeafCurve(getRatioX(), getRatioY())); + } + g2d.setColor(teaLeafsStalksColor); + if (showLeaf) { + g2d.fillPolygon(SplinesDefs.getMainLeafStalkCurve(getRatioX(), getRatioY())); + } + if (showLeaf) { + g2d.fillPolygon(SplinesDefs.getSecondLeafStalkCurve(getRatioX(), getRatioY())); + } + g2d.setFont(pluginFont); + g2d.setColor(pluginColor); + if (SplashReason.APPLET.equals(master.getSplashReason())) { + if (showLeaf) { + g2d.drawString(plugin, scaleX(404), scaleY(145)); + } else { + FontMetrics wfm = g2d.getFontMetrics(webFont); + g2d.drawString(plugin, wfm.stringWidth(web) + scaleX(WEB_LEFT_ALIGMENT) + 10, scaleY(WEB_TOP_ALIGMENT)); + } + } + g2d.setFont(plainTextsFont); + g2d.setColor(plainTextColor); + FontMetrics fm = g2d.getFontMetrics(); + if (ic != null) { + InfoItem des = ic.getBestMatchingDescriptionForSplash(); + List<String> head = ic.getHeader(); + if (head != null && showInfo) { + for (int i = 0; i < head.size(); i++) { + String string = head.get(i); + g2d.drawString(string, 5, (i + 1) * fm.getHeight()); + } + } + if (des != null && des.getValue() != null) { + g2d.drawString(des.getValue(), 5, master.getSplashHeight() - fm.getHeight()); + } + } + } + g2d.setFont(plainTextsFont); + g2d.setColor(plainTextColor); + FontMetrics fm = g2d.getFontMetrics(); + if (version != null) { + int y = master.getSplashWidth() - fm.stringWidth(version + " "); + if (y < 0) { + y = 0; + } + g2d.drawString(version, y, fm.getHeight()); + } + return fm; + } + + public int getWaterLevel() { + return waterLevel; + } + + public void setWaterLevel(int level) { + this.waterLevel = level; + } + + public int getAnimationsPosition() { + return animationsPosition; + } + + public void clearCachedWaterTextImage() { + oldTwl = null; + } + + @Override + public void update(Observable o, Object arg) { + try { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + master.repaint(); + } + }); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ControlCurve.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ControlCurve.java new file mode 100644 index 0000000..1a35928 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ControlCurve.java @@ -0,0 +1,190 @@ +/* ControlCurve.java +Copyright (C) 2012 Tim Lambert, 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.impls.defaultsplashscreen2012; + +/** This class represents a curve defined by a sequence of control points */ + +/* + * This class is part of the NatCubic implementation (http://www.cse.unsw.edu.au/~lambert/) + * which does not have a license. The author (Tim Lambert) has agreed to + * license this under GPL+Classpath by email + * + */ +import java.awt.*; + +public class ControlCurve { + + protected Polygon pts; + protected Polygon result; + protected boolean withPoints = true; + protected int selection = -1; + + public ControlCurve() { + pts = new Polygon(); + } + + public ControlCurve(Polygon p) { + pts = p; + } + + public Polygon getSourcePolygon() { + return pts; + } + + public void setSourcePolygon(Polygon pts) { + this.pts = pts; + } + static Font f = new Font("Courier", Font.PLAIN, 12); + + /** + * to be overwriten + */ + public Polygon calcualteResult() { + return null; + } + + public void calcualteAndSaveResult() { + result = calcualteResult(); + } + + /** paint this curve into g.*/ + public void paint(Graphics g) { + if (isWithPoints()) { + FontMetrics fm = g.getFontMetrics(f); + g.setFont(f); + int h = fm.getAscent() / 2; + + for (int i = 0; i < pts.npoints; i++) { + String s = Integer.toString(i); + int w = fm.stringWidth(s) / 2; + g.drawString(Integer.toString(i), pts.xpoints[i] - w, pts.ypoints[i] + h); + } + } + } + static final int EPSILON = 36; /* square of distance for picking */ + + + /** return index of control point near to (x,y) or -1 if nothing near */ + public int selectPoint(int x, int y) { + int mind = Integer.MAX_VALUE; + selection = -1; + for (int i = 0; i < pts.npoints; i++) { + int d = sqr(pts.xpoints[i] - x) + sqr(pts.ypoints[i] - y); + if (d < mind && d < EPSILON) { + mind = d; + selection = i; + } + } + return selection; + } + + // square of an int + static int sqr(int x) { + return x * x; + } + + public Polygon getResult() { + return result; + } + + public void resetResult() { + this.result = null; + } + + /** add a control point, return index of new control point */ + public int addPoint(int x, int y) { + pts.addPoint(x, y); + resetResult(); + return selection = pts.npoints - 1; + } + + /** set selected control point */ + public void setPoint(int x, int y) { + setPoint(selection, x, y); + } + + /** set selected control point */ + public void setPoint(int index, int x, int y) { + if (index >= 0 && index < pts.npoints) { + pts.xpoints[index] = x; + pts.ypoints[index] = y; + resetResult(); + } + } + + /** remove selected control point */ + public void removePoint(int index) { + if (index >= 0 && index < pts.npoints) { + pts.npoints--; + for (int i = index; i < pts.npoints; i++) { + pts.xpoints[i] = pts.xpoints[i + 1]; + pts.ypoints[i] = pts.ypoints[i + 1]; + } + resetResult(); + } + } + + /** remove selected control point */ + public void removePoint() { + removePoint(selection); + } + + public boolean isWithPoints() { + return withPoints; + } + + public void setWithPoints(boolean withPoints) { + this.withPoints = withPoints; + } + + @Override + public String toString() { + StringBuilder r = new StringBuilder(); + for (int i = 0; i < pts.npoints; i++) { + r.append(" ").append(pts.xpoints[i]).append(" ").append(pts.ypoints[i]); + } + return r.toString(); + } + + /** + * for testing purposes + * @param selection + */ + void setSelection(int selection) { + this.selection = selection; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/Cubic.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/Cubic.java new file mode 100644 index 0000000..3497829 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/Cubic.java @@ -0,0 +1,63 @@ +/* Cubic.java +Copyright (C) 2012 Tim Lambert, 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.impls.defaultsplashscreen2012; + +/** this class represents a cubic polynomial */ + +/* + * This class is part of the NatCubic implementation (http://www.cse.unsw.edu.au/~lambert/) + * which does not have a license. The author (Tim Lambert) has agreed to + * license this under GPL+Classpath by email + * + */ +public class Cubic { + + float a, b, c, d; /* a + b*u + c*u^2 +d*u^3 */ + + + public Cubic(float a, float b, float c, float d) { + this.a = a; + this.b = b; + this.c = c; + this.d = d; + } + + /** evaluate cubic */ + public float eval(float u) { + return (((d * u) + c) * u + b) * u + a; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ErrorPainter.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ErrorPainter.java new file mode 100644 index 0000000..96372c2 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/ErrorPainter.java @@ -0,0 +1,260 @@ +/* ErrorPainter.java +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.impls.defaultsplashscreen2012; + +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.RenderingHints; +import java.util.Observable; + +import net.sourceforge.jnlp.runtime.Translator; +import net.sourceforge.jnlp.splashscreen.parts.BasicComponentSplashScreen; +import net.sourceforge.jnlp.splashscreen.parts.InformationElement; + +public final class ErrorPainter extends BasePainter { + + //colors + private static final Color TEA_DEAD_COLOR = Color.darkGray; + private static final Color BACKGROUND_DEAD_COLOR = Color.gray; + private static final Color TEA_LEAFS_STALKS_DEAD_COLOR = new Color(100, 100, 100); + private static final Color PLUGIN_DEAD_COLOR = Color.darkGray; + private static final Color WATER_DEAD_COLOR = Color.darkGray; + private static final Color PLAIN_TEXT_DEAD_COLOR = Color.white; + private static final String ERROR_MESSAGE_KEY = "SPLASHerror"; + private static final String ERROR_FLY_MESSAGE_KEY = "SPLASH_ERROR"; + private static final Color ERROR_FLY_COLOR = Color.red; + //for clicking ot error message + private Point errorCorner = null; + private boolean errorIsFlying = false; + private int errorFlyPercentage = 100; + + /** + * Interpolation is root ratior is r= (currentSize / origSize) + * then value to-from is interpolaed from to to from accroding to ratio + * + * @param origSize + * @param currentSize + * @param from + * @param to + * @return + */ + public static double interpol(double origSize, double currentSize, double from, double to) { + return getRatio(origSize, currentSize) * (to - from) + from; + } + + /** + * is interpolating one color to another based on ration current/orig + * Each (r,g,b,a) part of color is interpolated separately + * resturned is new color composed form new r,g,b,a + * @param origSize + * @param currentSize + * @param from + * @param to + * @return + */ + public static Color interpolateColor(double origSize, double currentSize, Color from, Color to) { + double r = interpol(origSize, currentSize, to.getRed(), from.getRed()); + double g = interpol(origSize, currentSize, to.getGreen(), from.getGreen()); + double b = interpol(origSize, currentSize, to.getBlue(), from.getBlue()); + double a = interpol(origSize, currentSize, to.getAlpha(), from.getAlpha()); + return new Color((int) r, (int) g, (int) b, (int) a); + } + //scaling end + + public ErrorPainter(BasicComponentSplashScreen master) { + this(master, false); + } + + public ErrorPainter(BasicComponentSplashScreen master, boolean startScream) { + super(master); + if (startScream) { + startErrorScream(); + } + + } + + public void startErrorScream() { + errorIsFlying = true; + getFlyingRedErrorTextThread().start(); + } + + @Override + public void paint(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + ensurePrerenderedStuff(); + if (errorIsFlying) { + paintStillTo(g2d, master.getInformationElement(), master.getVersion()); + } else { + if (prerenderedStuff != null) { + g2d.drawImage(prerenderedStuff, 0, 0, null); + } + } + + if (super.showNiceTexts) { + paintNiceTexts(g2d); + } else { + paintPlainTexts(g2d); + } + + if (errorIsFlying) { + g2d.setClip(0, 0, master.getSplashWidth(), master.getSplashHeight()); + drawBigError(g2d); + } + + + } + + private void drawBigError(Graphics2D g2d) { + Font f = new Font("Serif", Font.PLAIN, (int) scale(100, errorFlyPercentage, master.getSplashHeight())); + g2d.setColor(ERROR_FLY_COLOR); + g2d.setFont(f); + drawTextAroundCenter(g2d, 0, geFlyingErrorMessage()); + } + + public Point getErrorCorner() { + return errorCorner; + } + + private void setColors() { + + teaColor = TEA_DEAD_COLOR; + backgroundColor = BACKGROUND_DEAD_COLOR; + teaLeafsStalksColor = TEA_LEAFS_STALKS_DEAD_COLOR; + pluginColor = PLUGIN_DEAD_COLOR; + waterColor = WATER_DEAD_COLOR; + + } + + private void interpolateColor(int origSize, int currentSize) { + teaColor = interpolateColor(origSize, currentSize, TEA_LIVE_COLOR, TEA_DEAD_COLOR); + backgroundColor = interpolateColor(origSize, currentSize, BACKGROUND_LIVE_COLOR, BACKGROUND_DEAD_COLOR); + teaLeafsStalksColor = interpolateColor(origSize, currentSize, TEA_LEAFS_STALKS_LIVE_COLOR, TEA_LEAFS_STALKS_DEAD_COLOR); + pluginColor = interpolateColor(origSize, currentSize, PLUGIN_LIVE_COLOR, PLUGIN_DEAD_COLOR); + waterColor = interpolateColor(origSize, currentSize, WATER_LIVE_COLOR, WATER_DEAD_COLOR); + plainTextColor = interpolateColor(origSize, currentSize, PLAIN_TEXT_LIVE_COLOR, PLAIN_TEXT_DEAD_COLOR); + } + + @Override + protected void paintStillTo(Graphics2D g2d, InformationElement ic, String version) { + RenderingHints r = g2d.getRenderingHints(); + FontMetrics fm = drawBase(g2d, ic, version); + drawError(g2d, ic, version, fm); + g2d.setRenderingHints(r); + } + + private String getErrorMessage() { + String localised = Translator.R(ERROR_MESSAGE_KEY); + //if (localised==null)return errorMessage; + return localised; + } + + private String geFlyingErrorMessage() { + String localised = Translator.R(ERROR_FLY_MESSAGE_KEY); + return localised; + } + + private Thread getFlyingRedErrorTextThread() { + // Create a new thread to draw big flying error in case of failure + Thread t = new Thread(new FlyingRedErrorTextRunner(this)); + //t.setDaemon(true); + return t; + } + + private final class FlyingRedErrorTextRunner extends Observable implements Runnable { + + private static final int FLYING_ERROR_PERCENTAGE_INCREMENT = -3; + private static final int FLYING_ERROR_PERCENTAGE_MINIMUM = 5; + private static final int FLYING_ERROR_PERCENTAGE_LOWER_BOUND = 80; + private static final int FLYING_ERROR_PERCENTAGE_UPPER_BOUND = 90; + private static final int FLYING_ERROR_DELAY = 75; + + private FlyingRedErrorTextRunner(ErrorPainter o) { + this.addObserver(o); + } + + @Override + public void run() { + try { + while (errorIsFlying) { + errorFlyPercentage += FLYING_ERROR_PERCENTAGE_INCREMENT; + interpolateColor(100, errorFlyPercentage); + if (errorFlyPercentage <= FLYING_ERROR_PERCENTAGE_MINIMUM) { + errorIsFlying = false; + setColors(); + prerenderedStuff = null; + } + this.setChanged(); + this.notifyObservers(); + Thread.sleep(FLYING_ERROR_DELAY); + if (errorFlyPercentage < FLYING_ERROR_PERCENTAGE_UPPER_BOUND + && errorFlyPercentage > FLYING_ERROR_PERCENTAGE_LOWER_BOUND) { + clearCachedWaterTextImage(); + canWave = false; + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + canWave = true; + errorIsFlying = false; + setColors(); + prerenderedStuff = null; + master.repaint(); + + } + } + }; + + private void drawError(Graphics2D g2d, InformationElement ic, String version, FontMetrics fm) { + int minh = fm.getHeight(); + int minw = fm.stringWidth(getErrorMessage()); + int space = 5; + g2d.setColor(backgroundColor); + errorCorner = new Point(master.getSplashWidth() - space * 4 - minw, master.getSplashHeight() - space * 4 - minh); + if (errorCorner.x < 0) { + errorCorner.x = 0; + } + g2d.fillRect(errorCorner.x, errorCorner.y, space * 4 + minw, space * 4 + minh); + g2d.setColor(plainTextColor); + g2d.drawRect(errorCorner.x + space, errorCorner.y + space, space * 2 + minw, space * 2 + minh); + g2d.drawString(getErrorMessage(), errorCorner.x + 2 * space, errorCorner.y + 5 * space); + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/MovingText.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/MovingText.java new file mode 100644 index 0000000..ed7021b --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/MovingText.java @@ -0,0 +1,77 @@ +/* MovingText.java +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.impls.defaultsplashscreen2012; + +import java.awt.Color; +import java.awt.Font; +import java.awt.GradientPaint; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.image.BufferedImage; + +public class MovingText extends TextWithWaterLevel { + + public MovingText(String s, Font f) { + super(s, f); + + } + + @Override + public BufferedImage getBackground() { + Point p = getFutureSize(); + int w = p.x; + int h = p.y; + if (w <= 0 || h <= 0) { + return null; + } + BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = bi.createGraphics(); + + Color e1 = Color.gray; + Color s1 = Color.white; + int level = getPercentageOfWater() % (2 * w); + GradientPaint gradient = new GradientPaint(level - w, h / 2, s1, level, h / 2, e1, true); + g2d.setPaint(gradient); + g2d.fillRect(100, 100, 200, 120); + + g2d.fillRect(0, 0, w, h); + + + + return bi; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/NatCubic.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/NatCubic.java new file mode 100644 index 0000000..43bda84 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/NatCubic.java @@ -0,0 +1,127 @@ +/* NatCubic.java +Copyright (C) 2012 Tim Lambert, 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.impls.defaultsplashscreen2012; + +import java.awt.*; + +public class NatCubic extends ControlCurve { + + /* + * This class is part of the NatCubic implementation (http://www.cse.unsw.edu.au/~lambert/) + * which does not have a license. The author (Tim Lambert) has agreed to + * license this under GPL+Classpath by email + * + */ + /* + NatCubic calcualtion + calculates the natural cubic spline that interpolates + y[0], y[1], ... y[n] + The first segment is returned as + C[0].a + C[0].b*u + C[0].c*u^2 + C[0].d*u^3 0<=u <1 + the other segments are in C[1], C[2], ... C[n-1] */ + Cubic[] calcNaturalCubic(int n, int[] x) { + float[] gamma = new float[n + 1]; + float[] delta = new float[n + 1]; + float[] D = new float[n + 1]; + int i; + /* We solve the equation + [2 1 ] [D[0]] [3(x[1] - x[0]) ] + |1 4 1 | |D[1]| |3(x[2] - x[0]) | + | 1 4 1 | | . | = | . | + | ..... | | . | | . | + | 1 4 1| | . | |3(x[n] - x[n-2])| + [ 1 2] [D[n]] [3(x[n] - x[n-1])] + + by using row operations to convert the matrix to upper triangular + and then back sustitution. The D[i] are the derivatives at the knots. + */ + + gamma[0] = 1.0f / 2.0f; + for (i = 1; i < n; i++) { + gamma[i] = 1 / (4 - gamma[i - 1]); + } + gamma[n] = 1 / (2 - gamma[n - 1]); + + delta[0] = 3 * (x[1] - x[0]) * gamma[0]; + for (i = 1; i < n; i++) { + delta[i] = (3 * (x[i + 1] - x[i - 1]) - delta[i - 1]) * gamma[i]; + } + delta[n] = (3 * (x[n] - x[n - 1]) - delta[n - 1]) * gamma[n]; + + D[n] = delta[n]; + for (i = n - 1; i >= 0; i--) { + D[i] = delta[i] - gamma[i] * D[i + 1]; + } + + /* now compute the coefficients of the cubics */ + Cubic[] C = new Cubic[n]; + for (i = 0; i < n; i++) { + C[i] = new Cubic((float) x[i], D[i], 3 * (x[i + 1] - x[i]) - 2 * D[i] - D[i + 1], + 2 * (x[i] - x[i + 1]) + D[i] + D[i + 1]); + } + return C; + } + final int STEPS = 12; + + /* draw a cubic spline */ + @Override + public void paint(Graphics g) { + super.paint(g); + if (pts.npoints >= 2) { + if (getResult() == null) { + calcualteAndSaveResult(); + } + g.drawPolyline(result.xpoints, result.ypoints, result.npoints); + } + } + + @Override + public Polygon calcualteResult() { + Cubic[] X = calcNaturalCubic(pts.npoints - 1, pts.xpoints); + Cubic[] Y = calcNaturalCubic(pts.npoints - 1, pts.ypoints); + /* very crude technique - just break each segment up into steps lines */ + Polygon p = new Polygon(); + p.addPoint((int) Math.round(X[0].eval(0)), (int) Math.round(Y[0].eval(0))); + for (int i = 0; i < X.length; i++) { + for (int j = 1; j <= STEPS; j++) { + float u = j / (float) STEPS; + p.addPoint(Math.round(X[i].eval(u)), Math.round(Y[i].eval(u))); + } + } + return p; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/NatCubicClosed.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/NatCubicClosed.java new file mode 100644 index 0000000..1ccd60c --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/NatCubicClosed.java @@ -0,0 +1,107 @@ +/* NatCubicClosed.java +Copyright (C) 2012 Tim Lambert, 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.impls.defaultsplashscreen2012; + +public class NatCubicClosed extends NatCubic { + + /* + * This class is part of the NatCubic implementation (http://www.cse.unsw.edu.au/~lambert/) + * which does not have a license. The author (Tim Lambert) has agreed to + * license this under GPL+Classpath by email + * + */ + /* + NatCubic calcualtion + calculates the closed natural cubic spline that interpolates + x[0], x[1], ... x[n] + The first segment is returned as + C[0].a + C[0].b*u + C[0].c*u^2 + C[0].d*u^3 0<=u <1 + the other segments are in C[1], C[2], ... C[n] */ + @Override + Cubic[] calcNaturalCubic(int n, int[] x) { + float[] w = new float[n + 1]; + float[] v = new float[n + 1]; + float[] y = new float[n + 1]; + float[] D = new float[n + 1]; + float z, F, G, H; + int k; + /* We solve the equation + [4 1 1] [D[0]] [3(x[1] - x[n]) ] + |1 4 1 | |D[1]| |3(x[2] - x[0]) | + | 1 4 1 | | . | = | . | + | ..... | | . | | . | + | 1 4 1| | . | |3(x[n] - x[n-2])| + [1 1 4] [D[n]] [3(x[0] - x[n-1])] + + by decomposing the matrix into upper triangular and lower matrices + and then back sustitution. See Spath "Spline Algorithms for Curves + and Surfaces" pp 19--21. The D[i] are the derivatives at the knots. + */ + w[1] = v[1] = z = 1.0f / 4.0f; + y[0] = z * 3 * (x[1] - x[n]); + H = 4; + F = 3 * (x[0] - x[n - 1]); + G = 1; + for (k = 1; k < n; k++) { + v[k + 1] = z = 1 / (4 - v[k]); + w[k + 1] = -z * w[k]; + y[k] = z * (3 * (x[k + 1] - x[k - 1]) - y[k - 1]); + H = H - G * w[k]; + F = F - G * y[k - 1]; + G = -v[k] * G; + } + H = H - (G + 1) * (v[n] + w[n]); + y[n] = F - (G + 1) * y[n - 1]; + + D[n] = y[n] / H; + D[n - 1] = y[n - 1] - (v[n] + w[n]) * D[n]; /* This equation is WRONG! in my copy of Spath */ + for (k = n - 2; k >= 0; k--) { + D[k] = y[k] - v[k + 1] * D[k + 1] - w[k + 1] * D[n]; + } + + + /* now compute the coefficients of the cubics */ + Cubic[] C = new Cubic[n + 1]; + for (k = 0; k < n; k++) { + C[k] = new Cubic((float) x[k], D[k], 3 * (x[k + 1] - x[k]) - 2 * D[k] - D[k + 1], + 2 * (x[k] - x[k + 1]) + D[k] + D[k + 1]); + } + C[n] = new Cubic((float) x[n], D[n], 3 * (x[0] - x[n]) - 2 * D[n] - D[0], + 2 * (x[n] - x[0]) + D[n] + D[0]); + return C; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/SplinesDefs.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/SplinesDefs.java new file mode 100644 index 0000000..0f18fe9 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/SplinesDefs.java @@ -0,0 +1,198 @@ +/* SplinesDefs.java +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.impls.defaultsplashscreen2012; + +import java.awt.Point; +import java.awt.Polygon; + +public class SplinesDefs { + + private final static Point[] mainLeafArray = { + new Point(268, 307), + new Point(274, 326), + new Point(289, 337), + new Point(317, 349), + new Point(362, 350), + new Point(413, 334), + new Point(428, 326), + new Point(453, 309), + new Point(469, 292), + new Point(496, 264), + new Point(516, 236), + new Point(531, 215), + new Point(550, 185), + new Point(567, 155), + new Point(580, 130), + new Point(571, 139), + new Point(555, 148), + new Point(540, 157), + new Point(521, 167), + new Point(502, 174), + new Point(477, 183), + new Point(443, 193), + new Point(413, 201), + new Point(392, 209), + new Point(376, 218), + new Point(363, 228), + new Point(356, 250), + new Point(372, 231), + new Point(398, 218), + new Point(420, 209), + new Point(446, 200), + new Point(479, 192), + new Point(505, 182), + new Point(547, 168), + new Point(539, 182), + new Point(526, 204), + new Point(509, 227), + new Point(498, 244), + new Point(486, 257), + new Point(469, 272), + new Point(460, 281), + new Point(449, 293), + new Point(436, 303), + new Point(418, 315), + new Point(400, 323), + new Point(383, 332), + new Point(367, 334), + new Point(343, 338), + new Point(322, 335), + new Point(304, 330), + new Point(288, 322) + }; + private final static Point[] mainLeafStalkArray = { + new Point(353, 287), + new Point(366, 295), + new Point(376, 291), + new Point(392, 283), + new Point(428, 251), + new Point(441, 233), + new Point(462, 217), + new Point(446, 225), + new Point(434, 236), + new Point(428, 242), + new Point(408, 261), + new Point(392, 275), + new Point(373, 284), + new Point(363, 289) + }; + private final static Point[] smallLeafArray = { + new Point(342, 207), + new Point(352, 213), + new Point(360, 218), + new Point(374, 217), + new Point(389, 202), + new Point(397, 175), + new Point(396, 143), + new Point(397, 113), + new Point(380, 127), + new Point(350, 145), + new Point(327, 155), + new Point(313, 166), + new Point(297, 182), + new Point(293, 196), + new Point(308, 183), + new Point(332, 167), + new Point(364, 150), + new Point(385, 137), + new Point(384, 158), + new Point(382, 187), + new Point(371, 204) + }; + private final static Point[] smallLeafStalkArray = { + new Point(320, 203), + new Point(331, 191), + new Point(345, 185), + new Point(356, 183), + new Point(365, 177), + new Point(368, 171), + new Point(368, 165), + new Point(360, 173), + new Point(354, 176), + new Point(341, 180), + new Point(334, 184), + new Point(321, 194) + }; + + public static Polygon getMainLeaf(Double scalex, double scaley) { + + return polygonizeControlPoints(mainLeafArray, scalex, scaley); + } + + static Polygon polygonizeControlPoints(Point[] pp, Double scalex, double scaley) { + Polygon r = new Polygon(); + for (int i = 0; i < pp.length; i++) { + Point p = pp[i]; + r.addPoint((int) ((double) p.x * (double) scalex), (int) ((double) p.y * (double) scaley)); + } + return r; + } + + public static Polygon getSecondLeaf(Double scalex, double scaley) { + return polygonizeControlPoints(smallLeafArray, scalex, scaley); + } + + public static Polygon getSecondLeafStalk(Double scalex, double scaley) { + return polygonizeControlPoints(smallLeafStalkArray, scalex, scaley); + } + + public static Polygon getMainLeafStalk(Double scalex, double scaley) { + return polygonizeControlPoints(mainLeafStalkArray, scalex, scaley); + } + + public static Polygon getMainLeafCurve(Double scalex, double scaley) { + return getNatCubicClosed(getMainLeaf(scalex, scaley)); + } + + public static Polygon getMainLeafStalkCurve(Double scalex, double scaley) { + return getNatCubicClosed(getMainLeafStalk(scalex, scaley)); + } + + public static Polygon getSecondLeafCurve(Double scalex, double scaley) { + return getNatCubicClosed(getSecondLeaf(scalex, scaley)); + } + + public static Polygon getSecondLeafStalkCurve(Double scalex, double scaley) { + return getNatCubicClosed(getSecondLeafStalk(scalex, scaley)); + } + + static Polygon getNatCubicClosed(Polygon p) { + NatCubicClosed c = new NatCubicClosed(); + c.setSourcePolygon(p); + return c.calcualteResult(); + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRenderer.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRenderer.java new file mode 100644 index 0000000..83dc979 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRenderer.java @@ -0,0 +1,152 @@ +/* TextOutlineRenderer.java +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.impls.defaultsplashscreen2012; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.font.FontRenderContext; +import java.awt.font.TextLayout; +import java.awt.geom.AffineTransform; + +public class TextOutlineRenderer { + + private Image img; + private Font font; + private Color outlineColor; + private final String text; + + public TextOutlineRenderer(Font f, String s) { + this.font = f; + outlineColor = Color.black; + this.text = s; + + } + + public TextOutlineRenderer(Font f, String s, Color textOutline) { + this(f, s); + this.outlineColor = textOutline; + } + + public int getWidth() { + if (img == null) { + return -1; + } + return img.getWidth(null); + } + + public int getHeight() { + if (img == null) { + return -1; + } + return img.getHeight(null); + } + + public void cutTo(Graphics2D g2, int x, int y) { + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + g2.setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_QUALITY); + + FontRenderContext frc = g2.getFontRenderContext(); + TextLayout tl = new TextLayout(getText(), getFont(), frc); + float sw = (float) tl.getBounds().getWidth(); + AffineTransform transform = new AffineTransform(); + transform.setToTranslation(x, y); + Shape shape = tl.getOutline(transform); + Rectangle r = shape.getBounds(); + g2.setColor(getTextOutline()); + g2.draw(shape); + g2.setClip(shape); + g2.drawImage(getImg(), r.x, r.y, r.width, r.height, null); + + } + + /** + * @return the img + */ + public Image getImg() { + return img; + } + + /** + * @param img the img to set + */ + public void setImg(Image img) { + this.img = img; + } + + /** + * @return the font + */ + public Font getFont() { + return font; + } + + /** + * @param font the font to set + */ + public void setFont(Font font) { + this.font = font; + } + + /** + * @return the color of outline + */ + public Color getTextOutline() { + return outlineColor; + } + + /** + * @param outlineColor the color of outline + */ + public void setTextOutline(Color textOutline) { + this.outlineColor = textOutline; + } + + /** + * @return the text + */ + public String getText() { + return text; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevel.java b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevel.java new file mode 100644 index 0000000..cc873ae --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevel.java @@ -0,0 +1,179 @@ +/* TextWithWaterLevel.java +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.impls.defaultsplashscreen2012; + +import java.awt.Polygon; +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.util.Random; + +public class TextWithWaterLevel extends TextOutlineRenderer { + + private Color waterColor; + private Color bgColor; + private int percentageOfWater; + private Random sea = new Random(); + //set to null befor getBackground if waving is needed + //or create new TWL ;) + private Polygon cachedPolygon; + + public TextWithWaterLevel(String s, Font f) { + super(f, s); + waterColor = Color.BLUE; + bgColor = Color.white; + + } + + protected Point getFutureSize() { + BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB); + FontMetrics fm = bi.createGraphics().getFontMetrics(getFont()); + int w = fm.stringWidth(getText()); + int h = fm.getHeight(); + return new Point(w, h); + } + + public BufferedImage getBackground() { + Point p = getFutureSize(); + int w = p.x; + int h = p.y; + if (w <= 0 || h <= 0) { + return null; + } + BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = bi.createGraphics(); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setColor(bgColor); + g2d.fillRect(0, 0, w, h); + if (cachedPolygon == null) { + int level = (h * percentageOfWater) / 100; + int waveHeight = 10; + int waveLength = 20; + if (level > waveHeight / 2 + 1) { + NatCubic line = new NatCubic(); + int x = 0; + while (x < w + 2 * waveLength) { + line.addPoint(x, h - level - waveHeight / 2 - sea.nextInt(waveHeight)); + x = x + waveLength; + } + cachedPolygon = line.calcualteResult(); + cachedPolygon.addPoint(w, h); + cachedPolygon.addPoint(0, h); + } + } + g2d.setColor(waterColor); + if (cachedPolygon != null) { + g2d.fillPolygon(cachedPolygon); + } + //line.paint(g2d); + //FlodFill.floodFill(bi, waterColor, new Point(1, h - 1)); + return bi; + } + + public Polygon getCachedPolygon() { + return cachedPolygon; + } + + public void setCachedPolygon(Polygon cachedPolygon) { + this.cachedPolygon = cachedPolygon; + } + + @Override + public void cutTo(Graphics2D g2, int x, int y) { + if (this.getImg() == null) { + this.setImg(getBackground()); + } + if (this.getImg() == null) { + return; + } + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setFont(getFont()); + g2.setColor(getTextOutline()); + g2.drawString(getText(), x, y - 2); + g2.drawString(getText(), x, y + 2); + g2.drawString(getText(), x - 2, y); + g2.drawString(getText(), x + 2, y); + //sorry, cuted text have disturbed borders + super.cutTo(g2, x, y); + } + + /** + * @return the waterColor + */ + public Color getWaterColor() { + return waterColor; + } + + /** + * @param waterColor the waterColor to set + */ + public void setWaterColor(Color waterColor) { + this.waterColor = waterColor; + } + + /** + * @return the bgColor + */ + public Color getBgColor() { + return bgColor; + } + + /** + * @param bgColor the bgColor to set + */ + public void setBgColor(Color bgColor) { + this.bgColor = bgColor; + } + + /** + * @return the percentageOfWater + */ + public int getPercentageOfWater() { + return percentageOfWater; + } + + /** + * @param percentageOfWater the percentageOfWater to set + */ + public void setPercentageOfWater(int percentageOfWater) { + this.percentageOfWater = percentageOfWater; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentErrorSplashScreen.java b/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentErrorSplashScreen.java new file mode 100644 index 0000000..6210de9 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentErrorSplashScreen.java @@ -0,0 +1,85 @@ +/* BasicComponentSplashScreen.java +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; + +import net.sourceforge.jnlp.splashscreen.SplashErrorPanel; + +public abstract class BasicComponentErrorSplashScreen extends BasicComponentSplashScreen implements SplashErrorPanel { + + /** + * When applet loading fails, then dying stacktrace can be stted, and is then shown to user on demand. + */ + private Throwable loadingException; + + + /** + * @return the loadingException + */ + @Override + public Throwable getLoadingException() { + return loadingException; + } + + /** + * @param loadingException the loadingException to set + */ + @Override + public void setLoadingException(Throwable loadingException) { + this.loadingException = loadingException; + } + + + + protected void raiseExceptionDialogNOW() { + JEditorPaneBasedExceptionDialog dialog = new JEditorPaneBasedExceptionDialog(null, true, getLoadingException(), getInformationElement(), createAditionalInfo()); + dialog.setVisible(true); + } + + protected void raiseExceptionDialogQUEUED() { + java.awt.EventQueue.invokeLater(new Runnable() { + + @Override + public void run() { + raiseExceptionDialogNOW(); + } + }); + } + + protected void raiseExceptionDialog() { + raiseExceptionDialogQUEUED(); + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentSplashScreen.java b/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentSplashScreen.java new file mode 100644 index 0000000..eaadf39 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/BasicComponentSplashScreen.java @@ -0,0 +1,156 @@ +/* BasicComponentSplashScreen.java +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; + +import javax.swing.JComponent; +import net.sourceforge.jnlp.splashscreen.SplashPanel; +import net.sourceforge.jnlp.splashscreen.SplashUtils.SplashReason; + +public abstract class BasicComponentSplashScreen extends JComponent implements SplashPanel { + //scaling 100% + public static final double ORIGINAL_W = 635; + public static final double ORIGINAL_H = 480; + /** Width of the plugin window */ + protected int pluginWidth; + /** Height of the plugin window */ + protected int pluginHeight; + /** The project name to display */ + private SplashReason splashReason; + private boolean animationRunning = false; + private InformationElement content; + private String version; + + @Override + public JComponent getSplashComponent() { + return this; + } + + @Override + public boolean isAnimationRunning() { + return animationRunning; + } + + public void setAnimationRunning(boolean b){ + animationRunning=b; + } + + @Override + public void setInformationElement(InformationElement content) { + this.content = content; + } + + @Override + public InformationElement getInformationElement() { + return content; + } + + + /** + * @return the pluginWidth + */ + @Override + public int getSplashWidth() { + return pluginWidth; + } + + /** + * @param pluginWidth the pluginWidth to set + */ + @Override + public void setSplashWidth(int pluginWidth) { + this.pluginWidth = pluginWidth; + } + + /** + * @return the pluginHeight + */ + @Override + public int getSplashHeight() { + return pluginHeight; + } + + /** + * @param pluginHeight the pluginHeight to set + */ + @Override + public void setSplashHeight(int pluginHeight) { + this.pluginHeight = pluginHeight; + } + + /** + * @return the splashReason + */ + @Override + public SplashReason getSplashReason() { + return splashReason; + } + + /** + * @param splashReason the splashReason to set + */ + @Override + public void setSplashReason(SplashReason splashReason) { + this.splashReason = splashReason; + } + + /** + * @return the version + */ + @Override + public String getVersion() { + return version; + } + + /** + * @param version the version to set + */ + @Override + public void setVersion(String version) { + this.version = version; + } + + + protected String createAditionalInfo() { + if (getVersion() != null) { + return getSplashReason().toString() + " version: " + getVersion(); + } else { + return null; + } + } + + +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/DescriptionInfoItem.java b/netx/net/sourceforge/jnlp/splashscreen/parts/DescriptionInfoItem.java new file mode 100644 index 0000000..6af7562 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/DescriptionInfoItem.java @@ -0,0 +1,126 @@ +/* DescriptionInfoItem.java +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; + +/** + *description element: A short statement about the application. Description + * elements are optional. The kind attribute defines how the description should + * be used. It can have one of the following values: + * + * * one-line: If a reference to the application is going to appear on one row + * in a list or a table, this description will be used. + * * short: If a reference to the application is going to be displayed in a + * situation where there is room for a paragraph, this description is used. + * * tooltip: If a reference to the application is going to appear in a + * tooltip, this description is used. + * + * Only one description element of each kind can be specified. A description + * element without a kind is used as a default value. Thus, if Java Web Start + * needs a description of kind short, and it is not specified in the JNLP file, + * then the text from the description without an attribute is used. + * + * All descriptions contain plain text. No formatting, such as with HTML tags, + * is supported. + */ +public class DescriptionInfoItem extends InfoItem { + + protected String kind; + + public DescriptionInfoItem(String value, String kind) { + super(InfoItem.description, value); + this.kind = kind; + } + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + + public boolean isOfSameKind(DescriptionInfoItem o) { + if (o.getKind() == null && getKind() == null) { + return true; + } + if (o.getKind() == null && getKind() != null) { + return false; + } + if (o.getKind() != null && getKind() == null) { + return false; + } + return (o.getKind().equals(getKind())); + } + + public boolean isSame(DescriptionInfoItem o) { + return isOfSameKind(o) && isofSameType(o); + + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof DescriptionInfoItem)) { + return false; + } + DescriptionInfoItem o = (DescriptionInfoItem) obj; + return super.equals(o) && isOfSameKind(o); + + + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + (this.kind != null ? this.kind.hashCode() : 0); + hash = 59 * hash + (this.getType() != null ? this.getType().hashCode() : 0); + hash = 59 * hash + (this.getValue() != null ? this.getValue().hashCode() : 0); + return hash; + } + + @Override + public String toString() { + return super.toString() + " (" + getKind() + ")"; + } + + + + @Override + public String toNiceString() { + return super.toNiceString(); + } + +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/InfoItem.java b/netx/net/sourceforge/jnlp/splashscreen/parts/InfoItem.java new file mode 100644 index 0000000..8dea28b --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/InfoItem.java @@ -0,0 +1,145 @@ +/* InfoItem.java +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; + +import net.sourceforge.jnlp.InformationDesc; +import net.sourceforge.jnlp.runtime.Translator; + +/** + * The optional kind="splash" attribute may be used in an icon element to + * indicate that the image is to be used as a "splash" screen during the launch + * of an application. If the JNLP file does not contain an icon element with + * kind="splash" attribute, Java Web Start will construct a splash screen using + * other items from the information Element. + * If the JNLP file does not contain any icon images, the splash image will + * consist of the application's title and vendor, as taken from the JNLP file. + * + * items not used inside + */ +public class InfoItem { + + public static final String SPLASH = "SPLASH"; + public static final String title = "title"; + public static final String vendor = "vendor"; + public static final String homepage = "homepage"; + public static final String homepageHref = "href"; + public static final String description = "description"; + public static final String descriptionKind = "kind"; + public static final String descriptionKindOneLine = (String) InformationDesc.ONE_LINE; + //when no kind is specified, then it should behave as short + public static final String descriptionKindShort = (String) InformationDesc.SHORT; + public static final String descriptionKindToolTip = (String) InformationDesc.TOOLTIP; + protected String type; + protected String value; + + + public InfoItem(String type, String value) { + this.type = type; + this.value = value; + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + + /** + * @return the value + */ + public String getValue() { + return value; + } + + /** + * @param value the value to set + */ + public void setValue(String value) { + this.value = value; + } + + public boolean isofSameType(InfoItem o) { + return ((getType().equals(o.getType()))); + + + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof InfoItem)) { + return false; + } + InfoItem o = (InfoItem) obj; + return isofSameType(o) && (getValue().equals(o.getValue())); + + + + } + + @Override + public String toString() { + return type + ": " + value; + } + + + + + public String toNiceString() { + String key = SPLASH + type; + return localise(key, value); + } + + public static String localise(String key, String s) { + return Translator.R(key) + ": " + s; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + (this.getType() != null ? this.getType().hashCode() : 0); + hash = 59 * hash + (this.getValue() != null ? this.getValue().hashCode() : 0); + return hash; + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/InformationElement.java b/netx/net/sourceforge/jnlp/splashscreen/parts/InformationElement.java new file mode 100644 index 0000000..9e5101a --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/InformationElement.java @@ -0,0 +1,214 @@ +/* InformationElement.java +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. */ +/** +http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html + */ +package net.sourceforge.jnlp.splashscreen.parts; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import net.sourceforge.jnlp.InformationDesc; +import net.sourceforge.jnlp.JNLPFile; + +/** + * This class is wrapper arround <information> tag which should + * javaws provide from source jnlp file + */ +public class InformationElement { + + private InfoItem title; + private InfoItem vendor; + private InfoItem homepage; + private List<DescriptionInfoItem> descriptions = new ArrayList<DescriptionInfoItem>(5); + + public void setTitle(String title) { + if (title == null) { + return; + } + this.title = new InfoItem(InfoItem.title, title); + } + + public void setvendor(String vendor) { + if (vendor == null) { + return; + } + this.vendor = new InfoItem(InfoItem.vendor, vendor); + } + + public void setHomepage(String homepage) { + if (homepage == null) { + return; + } + this.homepage = new InfoItem(InfoItem.homepage, homepage); + } + + public void addDescription(String description) { + addDescription(description, null); + } + + /** + * Just one description of each kind (4 including null) are allowed in information element. + * This method should throw exception when trying to add second description of same kind + * But I do not consider it as good idea to force this behaviour for somesing like psalsh screen, + * so I jsut replace the previous one with new one. without any warning + */ + public void addDescription(String description, String kind) { + if (description == null) { + return; + } + DescriptionInfoItem d = new DescriptionInfoItem(description, kind); + for (DescriptionInfoItem descriptionInfoItem : descriptions) { + if (descriptionInfoItem.isOfSameKind(d)) { + descriptions.remove(descriptionInfoItem); + descriptions.add(d); + return; + } + } + descriptions.add(d); + + } + + public InfoItem getBestMatchingDescriptionForSplash() { + for (DescriptionInfoItem d : descriptions) { + if (InfoItem.descriptionKindOneLine.equals(d.getKind())) { + return d; + } + } + for (DescriptionInfoItem d : descriptions) { + if (d.getKind() == null) { + return d; + } + } + return null; + } + + public InfoItem getLongestDescriptionForSplash() { + for (DescriptionInfoItem d : descriptions) { + if (InfoItem.descriptionKindShort.equals(d.getKind())) { + return d; + } + } + for (DescriptionInfoItem d : descriptions) { + if (d.getKind() == null) { + return d; + } + } + for (DescriptionInfoItem d : descriptions) { + if (InfoItem.descriptionKindOneLine.equals(d.getKind())) { + return d; + } + } + for (DescriptionInfoItem d : descriptions) { + if (InfoItem.descriptionKindToolTip.equals(d.getKind())) { + return d; + } + } + return null; + } + + public String getTitle() { + if (title == null) { + return null; + } + return title.toNiceString(); + } + + public String getVendor() { + if (vendor == null) { + return null; + } + return vendor.toNiceString(); + } + + public String getHomepage() { + if (homepage == null) { + return null; + } + return homepage.toNiceString(); + } + + List<DescriptionInfoItem> getDescriptions() { + return Collections.unmodifiableList(descriptions); + } + + public String getDescription() { + InfoItem i = getBestMatchingDescriptionForSplash(); + if (i == null) { + return null; + } + return i.toNiceString(); + } + + public List<String> getHeader() { + List<String> r = new ArrayList<String>(4); + String t = getTitle(); + String v = getVendor(); + String h = getHomepage(); + if (t != null) { + r.add(t); + } + if (v != null) { + r.add(v); + } + if (h != null) { + r.add(h); + } + + return r; + } + + public static InformationElement createFromJNLP(JNLPFile file) { + if (file == null) { + return null; + } + try { + InformationElement ie = new InformationElement(); + ie.setHomepage(file.getInformation().getHomepage().toString()); + ie.setTitle(file.getInformation().getTitle()); + ie.setvendor(file.getInformation().getVendor()); + ie.addDescription(file.getInformation().getDescriptionStrict((String) (InformationDesc.DEFAULT))); + ie.addDescription(file.getInformation().getDescriptionStrict(InfoItem.descriptionKindOneLine), InfoItem.descriptionKindOneLine); + ie.addDescription(file.getInformation().getDescriptionStrict(InfoItem.descriptionKindShort), InfoItem.descriptionKindShort); + ie.addDescription(file.getInformation().getDescriptionStrict(InfoItem.descriptionKindToolTip), InfoItem.descriptionKindToolTip); + return ie; + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } +} diff --git a/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java b/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java new file mode 100644 index 0000000..8cc6070 --- /dev/null +++ b/netx/net/sourceforge/jnlp/splashscreen/parts/JEditorPaneBasedExceptionDialog.java @@ -0,0 +1,357 @@ +/* JeditorPaneBasedExceptionDialog.java +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; + +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; +import java.awt.event.WindowEvent; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.List; +import javax.swing.BorderFactory; +import javax.swing.GroupLayout; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.SwingConstants; +import javax.swing.WindowConstants; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import net.sourceforge.jnlp.runtime.Translator; + +public class JEditorPaneBasedExceptionDialog extends JDialog implements HyperlinkListener { + + // components + private JButton closeButton; + private JButton closeAndCopyButton; + private JButton homeButton; + private JEditorPane htmlErrorAndHelpPanel; + private JLabel exceptionLabel; + private JLabel iconLabel; + private JPanel mainPanel; + private JPanel topPanel; + private JPanel bottomPanel; + private JScrollPane htmlPaneScroller; + // End of components declaration + private final String message; + private final Throwable exception; + + /** Creates new form JEditorPaneBasedExceptionDialog */ + public JEditorPaneBasedExceptionDialog(java.awt.Frame parent, boolean modal, Throwable ex, InformationElement information, String anotherInfo) { + super(parent, modal); + initComponents(); + htmlErrorAndHelpPanel.setContentType("text/html"); + htmlErrorAndHelpPanel.setEditable(false); + List<String> l = infoElementToList(information); + this.message = getText(ex, l, anotherInfo); + this.exception = ex; + if (exception == null) { + closeAndCopyButton.setVisible(false); + } + htmlErrorAndHelpPanel.setText(message); + //htmlPaneScroller.getVerticalScrollBar().setValue(1); + htmlErrorAndHelpPanel.setCaretPosition(0); + try { + Icon icon = new ImageIcon(this.getClass().getResource("/net/sourceforge/jnlp/resources/warning.png")); + iconLabel.setIcon(icon); + } catch (Exception lex) { + lex.printStackTrace(); + } + htmlErrorAndHelpPanel.addHyperlinkListener(this); + homeButton.setVisible(false); + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + + } + + static List<String> infoElementToList(InformationElement information) { + List<String> l = null; + if (information != null) { + l = information.getHeader(); + InfoItem ii = information.getLongestDescriptionForSplash(); + if (ii != null) { + l.add(ii.toNiceString()); + } + } + return l; + } + + private void initComponents() { + + topPanel = new JPanel(); + closeButton = new JButton(); + closeAndCopyButton = new JButton(); + mainPanel = new JPanel(); + exceptionLabel = new JLabel(); + iconLabel = new JLabel(); + bottomPanel = new JPanel(); + htmlPaneScroller = new JScrollPane(); + htmlErrorAndHelpPanel = new JEditorPane(); + homeButton = new JButton(); + + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + + closeButton.setText(Translator.R(InfoItem.SPLASH + "Close")); + closeButton.addActionListener(new java.awt.event.ActionListener() { + + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + closeWindowButtonActionPerformed(evt); + } + }); + + closeAndCopyButton.setText(Translator.R(InfoItem.SPLASH + "closewAndCopyException")); + closeAndCopyButton.addActionListener(new java.awt.event.ActionListener() { + + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + copyAndCloseButtonActionPerformed(evt); + } + }); + + GroupLayout jPanel2Layout = new GroupLayout(topPanel); + topPanel.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(closeButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 314, Short.MAX_VALUE).addComponent(closeAndCopyButton).addContainerGap())); + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addContainerGap(24, Short.MAX_VALUE).addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(closeButton).addComponent(closeAndCopyButton)).addContainerGap())); + + exceptionLabel.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N + exceptionLabel.setHorizontalAlignment(SwingConstants.CENTER); + exceptionLabel.setText(Translator.R(InfoItem.SPLASH + "exOccured")); + + bottomPanel.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); + bottomPanel.setLayout(new java.awt.BorderLayout()); + + htmlPaneScroller.setViewportView(htmlErrorAndHelpPanel); + + bottomPanel.add(htmlPaneScroller, java.awt.BorderLayout.CENTER); + + homeButton.setText(Translator.R(InfoItem.SPLASH + "Home")); + homeButton.addActionListener(new java.awt.event.ActionListener() { + + @Override + public void actionPerformed(java.awt.event.ActionEvent evt) { + homeButtonActionPerformed(evt); + } + }); + + GroupLayout jPanel1Layout = new GroupLayout(mainPanel); + mainPanel.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(exceptionLabel, GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(homeButton, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE).addContainerGap()).addComponent(bottomPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 723, Short.MAX_VALUE)); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE).addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(exceptionLabel, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE).addComponent(homeButton, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE))).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(bottomPanel, GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))); + + GroupLayout layout = new GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING).addComponent(mainPanel, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(topPanel, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap())); + layout.setVerticalGroup( + layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(topPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap())); + + pack(); + } + + private void copyAndCloseButtonActionPerformed(java.awt.event.ActionEvent evt) { + if (exception != null) { + try { + StringSelection data = new StringSelection(getExceptionStackTraceAsString(exception)); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(data, data); + } catch (Exception ex) { + JOptionPane.showMessageDialog(this, Translator.R(InfoItem.SPLASH + "cantCopyEx")); + ex.printStackTrace(); + } + } else { + JOptionPane.showMessageDialog(this, Translator.R(InfoItem.SPLASH + "noExRecorded")); + } + close(); + } + + private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) { + htmlErrorAndHelpPanel.setText(message); + homeButton.setVisible(false); + } + + private void closeWindowButtonActionPerformed(java.awt.event.ActionEvent evt) { + close(); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + Exception ex = new RuntimeException("dsgsfdg"); + JEditorPaneBasedExceptionDialog dialog = new JEditorPaneBasedExceptionDialog(new JFrame(), true, ex, null, "uaaa: aaa\nwqdeweq:sdsds"); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + static String getText(Throwable ex, List<String> l, String anotherInfo) { + StringBuilder s = new StringBuilder("<html><body>"); + String info = "<p>" + + Translator.R(InfoItem.SPLASH + "mainL1", createLink()) + + " </p> \n"; + String t = "<p>" + + Translator.R(InfoItem.SPLASH + "mainL3") + + "</p> \n" + + info + formatListInfoList(l) + formatInfo(anotherInfo); + Object[] options = new String[2]; + options[0] = Translator.R(InfoItem.SPLASH + "Close"); + options[1] = Translator.R(InfoItem.SPLASH + "closeAndCopyShorter"); + if (ex != null) { + t = "<p>" + + Translator.R(InfoItem.SPLASH + "mainL4") + + " </p>\n" + + info + formatListInfoList(l) + formatInfo(anotherInfo) + + "<p>" + + Translator.R(InfoItem.SPLASH + "exWas") + + " <br/>\n" + "<pre>" + getExceptionStackTraceAsString(ex) + "</pre>"; + + + } else { + t += formatListInfoList(l); + } + s.append(t); + s.append("</body></html>"); + return s.toString(); + } + + public static String getExceptionStackTraceAsString(Throwable exception) { + if (exception == null) { + return ""; + } + StringWriter sw = new StringWriter(); + exception.printStackTrace(new PrintWriter(sw)); + return sw.toString(); + } + + public static String[] getExceptionStackTraceAsStrings(Throwable exception) { + if (exception == null) { + return new String[0]; + } + StringWriter sw = new StringWriter(); + exception.printStackTrace(new PrintWriter(sw)); + return sw.toString().split("\n"); + } + + @Override + public void hyperlinkUpdate(HyperlinkEvent event) { + if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + try { + htmlErrorAndHelpPanel.setPage(event.getURL()); + homeButton.setVisible(true); + + } catch (Exception ioe) { + JOptionPane.showMessageDialog(this, Translator.R(InfoItem.SPLASH + "cfl") + " " + + event.getURL().toExternalForm() + ": " + ioe); + } + } + } + + private void close() { + processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); + } + + static String formatListInfoList(List<String> l) { + if (l == null) { + return ""; + } + StringBuilder sb = new StringBuilder(); + sb.append("<p>"); + sb.append("<h3>"). + append(Translator.R(InfoItem.SPLASH + "vendorsInfo")).append(":</h3>"); + sb.append("<pre>"); + for (int i = 0; i < l.size(); i++) { + String string = l.get(i); + sb.append(string).append("\n"); + } + sb.append("</pre>"); + sb.append("</p>"); + return sb.toString(); + } + + static String formatInfo(String l) { + if (l == null) { + return ""; + } + StringBuilder sb = new StringBuilder(); + sb.append("<p>"); + sb.append("<h3>"). + append(Translator.R(InfoItem.SPLASH + "anotherInfo")).append(": </h3>"); + sb.append("<pre>"); + sb.append(l); + sb.append("</pre>"); + sb.append("</p>"); + return sb.toString(); + } + + Throwable getException() { + return exception; + } + + String getMessage() { + return message; + } + + private static String createLink() { + return "<a href=\"" + Translator.R(InfoItem.SPLASH + "url") + "\">" + + Translator.R(InfoItem.SPLASH + "urlLooks") + "</a>"; + } + + +} |