diff options
Diffstat (limited to 'netx/net/sourceforge')
-rw-r--r-- | netx/net/sourceforge/jnlp/GuiLaunchHandler.java | 63 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/JNLPSplashScreen.java | 107 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/Launcher.java | 75 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/NetxPanel.java | 36 |
4 files changed, 198 insertions, 83 deletions
diff --git a/netx/net/sourceforge/jnlp/GuiLaunchHandler.java b/netx/net/sourceforge/jnlp/GuiLaunchHandler.java index ad8ba96..74960f0 100644 --- a/netx/net/sourceforge/jnlp/GuiLaunchHandler.java +++ b/netx/net/sourceforge/jnlp/GuiLaunchHandler.java @@ -1,5 +1,5 @@ /* GuiLaunchHandler.java - Copyright (C) 2011 Red Hat, Inc. + Copyright (C) 2012 Red Hat, Inc. This file is part of IcedTea. @@ -54,7 +54,7 @@ import net.sourceforge.jnlp.util.BasicExceptionDialog; */ public class GuiLaunchHandler extends AbstractLaunchHandler { - private JNLPSplashScreen splashScreen = null; + private volatile JNLPSplashScreen splashScreen = null; private final Object mutex = new Object(); private UpdatePolicy policy = UpdatePolicy.ALWAYS; @@ -80,10 +80,11 @@ public class GuiLaunchHandler extends AbstractLaunchHandler { } private void closeSplashScreen() { - synchronized(mutex) { + synchronized (mutex) { if (splashScreen != null) { if (splashScreen.isSplashScreenValid()) { splashScreen.setVisible(false); + splashScreen.stopAnimation(); } splashScreen.dispose(); } @@ -102,40 +103,56 @@ public class GuiLaunchHandler extends AbstractLaunchHandler { @Override public void launchInitialized(final JNLPFile file) { - + int preferredWidth = 500; int preferredHeight = 400; final URL splashImageURL = file.getInformation().getIconLocation( IconDesc.SPLASH, preferredWidth, preferredHeight); + final ResourceTracker resourceTracker = new ResourceTracker(true); if (splashImageURL != null) { - final ResourceTracker resourceTracker = new ResourceTracker(true); resourceTracker.addResource(splashImageURL, file.getFileVersion(), null, policy); - synchronized(mutex) { - try { - SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - splashScreen = new JNLPSplashScreen(resourceTracker, file); - } - }); - } catch (InterruptedException ie) { - // Wait till splash screen is created - while (splashScreen == null); - } catch (InvocationTargetException ite) { - ite.printStackTrace(); - } + } + synchronized (mutex) { + try { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + splashScreen = new JNLPSplashScreen(resourceTracker, file); + } + }); + } catch (InterruptedException ie) { + // Wait till splash screen is created + while (splashScreen == null); + } catch (InvocationTargetException ite) { + ite.printStackTrace(); + } + try { + SwingUtilities.invokeAndWait(new Runnable() { - splashScreen.setSplashImageURL(splashImageURL); + @Override + public void run() { + splashScreen.setSplashImageURL(splashImageURL); + } + }); + } catch (InterruptedException ie) { + // Wait till splash screen is created + while (!splashScreen.isSplashImageLoaded()); + } catch (InvocationTargetException ite) { + ite.printStackTrace(); } + + } - + SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { - if (splashImageURL != null) { - synchronized(mutex) { + if (splashScreen != null) { + synchronized (mutex) { if (splashScreen.isSplashScreenValid()) { splashScreen.setVisible(true); } diff --git a/netx/net/sourceforge/jnlp/JNLPSplashScreen.java b/netx/net/sourceforge/jnlp/JNLPSplashScreen.java index 212696a..77698db 100644 --- a/netx/net/sourceforge/jnlp/JNLPSplashScreen.java +++ b/netx/net/sourceforge/jnlp/JNLPSplashScreen.java @@ -43,19 +43,16 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Insets; -import java.awt.Toolkit; import java.io.IOException; import java.net.URL; - import javax.imageio.ImageIO; 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; +import net.sourceforge.jnlp.util.ImageResources; public class JNLPSplashScreen extends JDialog { @@ -68,6 +65,7 @@ public class JNLPSplashScreen extends JDialog { public static final int DEF_WIDTH=635; public static final int DEF_HEIGHT=480; private SplashPanel componetSplash; + private boolean splashImageLoaded=false; public JNLPSplashScreen(ResourceTracker resourceTracker, final JNLPFile file) { @@ -78,61 +76,86 @@ public class JNLPSplashScreen extends JDialog { // JNLP file. this.resourceTracker = resourceTracker; - - this.file=file; + this.file=file; } public void setSplashImageURL(URL url) { - splashImageUrl = url; - splashImage = null; + splashImageLoaded = false; try { - splashImage = ImageIO.read(resourceTracker - .getCacheFile(splashImageUrl)); - if (splashImage == null) { - if (JNLPRuntime.isDebug()) { - System.err.println("Error loading splash image: " + url); + if (url != null) { + splashImageUrl = url; + splashImage = null; + try { + splashImage = ImageIO.read(resourceTracker.getCacheFile(splashImageUrl)); + if (splashImage == null) { + if (JNLPRuntime.isDebug()) { + System.err.println("Error loading splash image: " + url); + } + } + } catch (IOException e) { + if (JNLPRuntime.isDebug()) { + System.err.println("Error loading splash image: " + url); + } + splashImage = null; + } catch (IllegalArgumentException argumentException) { + if (JNLPRuntime.isDebug()) { + System.err.println("Error loading splash image: " + url); + } + splashImage = null; } - return; } - } catch (IOException e) { - if (JNLPRuntime.isDebug()) { - System.err.println("Error loading splash image: " + url); - } - splashImage = null; - return; - } catch (IllegalArgumentException argumentException) { - if (JNLPRuntime.isDebug()) { - System.err.println("Error loading splash image: " + url); + + if (splashImage == null) { + this.setLayout(new BorderLayout()); + SplashPanel splash = SplashUtils.getSplashScreen(DEF_WIDTH, DEF_HEIGHT); + if (splash != null) { + splash.startAnimation(); + splash.setInformationElement(InformationElement.createFromJNLP(file)); + this.add(splash.getSplashComponent()); + this.componetSplash = splash; + } } - splashImage = null; - return; + correctSize(); + } finally { + splashImageLoaded = true; } + } - correctSize(); + public boolean isSplashImageLoaded() { + return splashImageLoaded; } + public boolean isSplashScreenValid() { - return (splashImage != null); + return (splashImage != null) || (componetSplash != null); } private void correctSize() { - - Insets insets = getInsets(); - int minimumWidth = splashImage.getWidth(null) + insets.left - + insets.right; - int minimumHeight = splashImage.getHeight(null) + insets.top - + insets.bottom; - setMinimumSize(new Dimension(minimumWidth, minimumHeight)); - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - setLocation((screenSize.width - minimumWidth) / 2, - (screenSize.height - minimumHeight) / 2); + int minimumWidth = DEF_WIDTH; + int minimumHeight = DEF_HEIGHT; + if (splashImage != null) { + Insets insets = getInsets(); + minimumWidth = splashImage.getWidth(null) + insets.left + + insets.right; + minimumHeight = splashImage.getHeight(null) + insets.top + + insets.bottom; + } + setMinimumSize(new Dimension(0, 0)); + setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); + setSize(new Dimension(minimumWidth, minimumHeight)); + setPreferredSize(new Dimension(minimumWidth, minimumHeight)); + // Centering to middle of Toolkit.getDefaultToolkit().getScreenSize() + // centers to the middle of all monitors. Let's center to the middle + // of the primary monitor instead. + // TODO center on the 'current' monitor to meet user expectation + setLocationRelativeTo(null); } @Override public void paint(Graphics g) { if (splashImage == null) { + super.paint(g); return; } @@ -141,4 +164,12 @@ public class JNLPSplashScreen extends JDialog { g2.drawImage(splashImage, getInsets().left, getInsets().top, null); } + + public boolean isCustomSplashscreen() { + return (componetSplash!=null); + } + + public void stopAnimation() { + if (isCustomSplashscreen()) componetSplash.stopAnimation(); + } } diff --git a/netx/net/sourceforge/jnlp/Launcher.java b/netx/net/sourceforge/jnlp/Launcher.java index 1692b0e..c6712cd 100644 --- a/netx/net/sourceforge/jnlp/Launcher.java +++ b/netx/net/sourceforge/jnlp/Launcher.java @@ -20,6 +20,7 @@ import static net.sourceforge.jnlp.runtime.Translator.R; import java.applet.Applet; import java.awt.Container; +import java.awt.SplashScreen; import java.io.File; import java.lang.reflect.Method; import java.net.InetAddress; @@ -42,6 +43,8 @@ import net.sourceforge.jnlp.services.ServiceUtil; import javax.swing.SwingUtilities; import javax.swing.text.html.parser.ParserDelegator; +import net.sourceforge.jnlp.runtime.AppletEnvironment; +import net.sourceforge.jnlp.splashscreen.SplashUtils; import sun.awt.SunToolkit; @@ -543,6 +546,12 @@ public class Launcher { } if (JNLPRuntime.getForksAllowed() && file.needsNewVM()) { + if (!JNLPRuntime.isHeadless()){ + SplashScreen sp = SplashScreen.getSplashScreen(); + if (sp!=null) { + sp.close(); + } + } List<String> netxArguments = new LinkedList<String>(); netxArguments.add("-Xnofork"); netxArguments.addAll(JNLPRuntime.getInitialArguments()); @@ -652,25 +661,42 @@ public class Launcher { * @param enableCodeBase whether to add the codebase URL to the classloader */ protected ApplicationInstance launchApplet(JNLPFile file, boolean enableCodeBase, Container cont) throws LaunchException { - if (!file.isApplet()) + if (!file.isApplet()) { throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplet"), R("LNotAppletInfo"))); - + } + + if (JNLPRuntime.getForksAllowed() && file.needsNewVM()) { + if (!JNLPRuntime.isHeadless()) { + SplashScreen sp = SplashScreen.getSplashScreen(); + if (sp != null) { + sp.close(); + } + } + } + if (handler != null) { + handler.launchInitialized(file); + } + + AppletInstance applet = null; try { ServiceUtil.checkExistingSingleInstance(file); - AppletInstance applet = createApplet(file, enableCodeBase, cont); + applet = createApplet(file, enableCodeBase, cont); applet.initialize(); - applet.getAppletEnvironment().startApplet(); // this should be a direct call to applet instance return applet; } catch (InstanceExistsException ieex) { if (JNLPRuntime.isDebug()) { System.out.println("Single instance applet is already running."); } - throw launchError(new LaunchException(file, ieex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LSingleInstanceExists"))); + throw launchError(new LaunchException(file, ieex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LSingleInstanceExists")), applet); } catch (LaunchException lex) { - throw launchError(lex); + throw launchError(lex, applet); } catch (Exception ex) { - throw launchError(new LaunchException(file, ex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LCouldNotLaunchInfo"))); + throw launchError(new LaunchException(file, ex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LCouldNotLaunchInfo")), applet); + }finally{ + if (handler != null) { + handler.launchStarting(applet); + } } } @@ -678,13 +704,13 @@ public class Launcher { * Gets an ApplicationInstance, but does not launch the applet. */ protected ApplicationInstance getApplet(JNLPFile file, boolean enableCodeBase, Container cont) throws LaunchException { - if (!file.isApplet()) + if (!file.isApplet()) { throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplet"), R("LNotAppletInfo"))); - + } + AppletInstance applet = null; try { ServiceUtil.checkExistingSingleInstance(file); - - AppletInstance applet = createApplet(file, enableCodeBase, cont); + applet = createApplet(file, enableCodeBase, cont); applet.initialize(); return applet; @@ -692,11 +718,11 @@ public class Launcher { if (JNLPRuntime.isDebug()) { System.out.println("Single instance applet is already running."); } - throw launchError(new LaunchException(file, ieex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LSingleInstanceExists"))); + throw launchError(new LaunchException(file, ieex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LSingleInstanceExists")), applet); } catch (LaunchException lex) { - throw launchError(lex); + throw launchError(lex, applet); } catch (Exception ex) { - throw launchError(new LaunchException(file, ex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LCouldNotLaunchInfo"))); + throw launchError(new LaunchException(file, ex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LCouldNotLaunchInfo")), applet); } } @@ -715,8 +741,13 @@ public class Launcher { * * @param enableCodeBase whether to add the code base URL to the classloader */ - protected AppletInstance createApplet(JNLPFile file, boolean enableCodeBase, Container cont) throws LaunchException { - try { + //FIXME - when multiple applets are on one page, this method is visited simultaneously + //and then appelts creates in little bit strange manner. This issue is visible with + //randomly showing/notshowing spalshscreens. + //See also PluginAppletViewer.framePanel + protected AppletInstance createApplet(JNLPFile file, boolean enableCodeBase, Container cont) throws LaunchException { + AppletInstance appletInstance = null; + try { JNLPClassLoader loader = JNLPClassLoader.getInstance(file, updatePolicy); if (enableCodeBase) { @@ -730,7 +761,6 @@ public class Launcher { // appletInstance is needed by ServiceManager when looking up // services. This could potentially be done in applet constructor // so initialize appletInstance before creating applet. - AppletInstance appletInstance; if (cont == null) appletInstance = new AppletInstance(file, group, loader, null); else @@ -751,7 +781,7 @@ public class Launcher { return appletInstance; } catch (Exception ex) { - throw launchError(new LaunchException(file, ex, R("LSFatal"), R("LCInit"), R("LInitApplet"), R("LInitAppletInfo"))); + throw launchError(new LaunchException(file, ex, R("LSFatal"), R("LCInit"), R("LInitApplet"), R("LInitAppletInfo")), appletInstance); } } @@ -822,6 +852,13 @@ public class Launcher { * caller. */ private LaunchException launchError(LaunchException ex) { + return launchError(ex, null); + } + + private LaunchException launchError(LaunchException ex, AppletInstance applet) { + if (applet != null) { + SplashUtils.showErrorCaught(ex, applet); + } if (handler != null) handler.launchError(ex); @@ -861,7 +898,7 @@ public class Launcher { new ParserDelegator(); } - /** + /** * This runnable is used to call the appropriate launch method * for the application, applet, or installer in its thread group. */ diff --git a/netx/net/sourceforge/jnlp/NetxPanel.java b/netx/net/sourceforge/jnlp/NetxPanel.java index 59c3ce0..f6496b6 100644 --- a/netx/net/sourceforge/jnlp/NetxPanel.java +++ b/netx/net/sourceforge/jnlp/NetxPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2007 Red Hat, Inc. + * Copyright 2012 Red Hat, Inc. * This file is part of IcedTea, http://icedtea.classpath.org * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -22,7 +22,6 @@ package net.sourceforge.jnlp; -import net.sourceforge.jnlp.AppletLog; import net.sourceforge.jnlp.runtime.AppletInstance; import net.sourceforge.jnlp.runtime.JNLPRuntime; @@ -32,6 +31,8 @@ import java.util.Hashtable; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import net.sourceforge.jnlp.splashscreen.SplashController; +import net.sourceforge.jnlp.splashscreen.SplashPanel; import sun.applet.AppletViewerPanel; import sun.awt.SunToolkit; @@ -42,10 +43,11 @@ import sun.awt.SunToolkit; * * @author Francis Kung <[email protected]> */ -public class NetxPanel extends AppletViewerPanel { +public class NetxPanel extends AppletViewerPanel implements SplashController { private PluginBridge bridge = null; private boolean exitOnFailure = true; private AppletInstance appInst = null; + private SplashController splashController; private boolean appletAlive; private final String uKey; @@ -232,4 +234,32 @@ public class NetxPanel extends AppletViewerPanel { SunToolkit.createNewAppContext(); } } + + + + + public void setAppletViewerFrame(SplashController framePanel) { + splashController=framePanel; + } + + @Override + public void removeSplash() { + splashController.removeSplash(); + } + + @Override + public void replaceSplash(SplashPanel r) { + splashController.replaceSplash(r); + } + + @Override + public int getSplashWidth() { + return splashController.getSplashWidth(); + } + + @Override + public int getSplashHeigth() { + return splashController.getSplashHeigth(); + } + } |