com.vaadin.terminal.gwt.client
Class ResourceLoader

java.lang.Object
  extended by com.vaadin.terminal.gwt.client.ResourceLoader

public class ResourceLoader
extends Object

ResourceLoader lets you dynamically include external scripts and styles on the page and lets you know when the resource has been loaded. You can also preload resources, allowing them to get cached by the browser without being evaluated. This enables downloading multiple resources at once while still controlling in which order e.g. scripts are executed.

Since:
7.0.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd

Nested Class Summary
static class ResourceLoader.ResourceLoadEvent
          Event fired when a resource has been loaded.
static interface ResourceLoader.ResourceLoadListener
          Event listener that gets notified when a resource has been loaded
 
Constructor Summary
protected ResourceLoader()
          Creates a new resource loader.
 
Method Summary
static ResourceLoader get()
          Returns the default ResourceLoader
 void loadScript(String scriptUrl, ResourceLoader.ResourceLoadListener resourceLoadListener)
          Load a script and notify a listener when the script is loaded.
 void loadStylesheet(String stylesheetUrl, ResourceLoader.ResourceLoadListener resourceLoadListener)
          Load a stylesheet and notify a listener when the stylesheet is loaded.
 void preloadResource(String url, ResourceLoader.ResourceLoadListener resourceLoadListener)
          Download a resource and notify a listener when the resource is loaded without attempting to interpret the resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceLoader

protected ResourceLoader()
Creates a new resource loader. You should generally not create you own resource loader, but instead use get() to get an instance.

Method Detail

get

public static ResourceLoader get()
Returns the default ResourceLoader

Returns:
the default ResourceLoader

loadScript

public void loadScript(String scriptUrl,
                       ResourceLoader.ResourceLoadListener resourceLoadListener)
Load a script and notify a listener when the script is loaded. Calling this method when the script is currently loading or already loaded doesn't cause the script to be loaded again, but the listener will still be notified when appropriate.

Parameters:
scriptUrl - the url of the script to load
resourceLoadListener - the listener that will get notified when the script is loaded

preloadResource

public void preloadResource(String url,
                            ResourceLoader.ResourceLoadListener resourceLoadListener)
Download a resource and notify a listener when the resource is loaded without attempting to interpret the resource. When a resource has been preloaded, it will be present in the browser's cache (provided the HTTP headers allow caching), making a subsequent load operation complete without having to wait for the resource to be downloaded again. Calling this method when the resource is currently loading, currently preloading, already preloaded or already loaded doesn't cause the resource to be preloaded again, but the listener will still be notified when appropriate.

Parameters:
url - the url of the resource to preload
resourceLoadListener - the listener that will get notified when the resource is preloaded

loadStylesheet

public void loadStylesheet(String stylesheetUrl,
                           ResourceLoader.ResourceLoadListener resourceLoadListener)
Load a stylesheet and notify a listener when the stylesheet is loaded. Calling this method when the stylesheet is currently loading or already loaded doesn't cause the stylesheet to be loaded again, but the listener will still be notified when appropriate.

Parameters:
stylesheetUrl - the url of the stylesheet to load
resourceLoadListener - the listener that will get notified when the stylesheet is loaded


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.