Package mpjp.client
Class MPJPResources
java.lang.Object
mpjp.client.MPJPResources
public class MPJPResources
extends java.lang.Object
Access to resources -- images and audio -- stored in the server
in a Java source directory. By default, this directory is
/mpjp/resource/ but may be changed using
setResourceDir(String).
All methods in this class are static. The loadAudio(String)
method returns an audio object that may be played using it as context
for the play() method as in the following example.
MPJPAudioResource clip = MPJPResources.loadAudio(soundName);
clip.play();
The loadImageElement(String, Consumer) method is void. It
receives as argument a consumer of a ImageElement that is
invoked when the image is available, as in the following example
MPJPResources.loadImageElement(imageName, i -> {
image = i;
paint();
});
This ImageElement can be
given as argument to the Context2d.drawImage() method.- Author:
- José Paulo Leal
zp@dcc.fc.up.pt
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMPJPResources.MPJPAudioResourceAn audio resource implemented as a native JavaScript Audio element GWT doesn't have audio support and needs to be implemented as native (JavaScript) method calls. -
Constructor Summary
Constructors Constructor Description MPJPResources() -
Method Summary
Modifier and Type Method Description static java.lang.StringgetResourceDir()Pathname of the remote directory holding the resources fetch using HTTP.(package private) static MPJPResources.MPJPAudioResourceloadAudio(java.lang.String audioName)Load an audio resource.static voidloadImageElement(java.lang.String imageName, java.util.function.Consumer<com.google.gwt.dom.client.ImageElement> onLoad)Load given image and execute consumer when loaded.static voidsetResourceDir(java.lang.String resourceDir)Change the pathname of the remote directory holding the resources fetch using HTTP.
-
Constructor Details
-
MPJPResources
public MPJPResources()
-
-
Method Details
-
getResourceDir
public static java.lang.String getResourceDir()Pathname of the remote directory holding the resources fetch using HTTP. This pathname should correspond to the prefix configured inWEB-INF/web.xmlwith the<url-pattern>element, contained in the<servlet-mapping>element.- Returns:
- resource directory
-
setResourceDir
public static void setResourceDir(java.lang.String resourceDir)Change the pathname of the remote directory holding the resources fetch using HTTP. This pathname should correspond to the prefix configured inWEB-INF/web.xmlwith the<url-pattern>element, contained in the<servlet-mapping>element.- Parameters:
resourceDir- new name of resource dir
-
loadAudio
Load an audio resource. The returned instance can be used for playing the audio clipMPJPResources.loadAudio(soundName).play();- Parameters:
audioName- name of the audio clip (without diretories)- Returns:
- an audio clip
-
loadImageElement
public static void loadImageElement(java.lang.String imageName, java.util.function.Consumer<com.google.gwt.dom.client.ImageElement> onLoad)Load given image and execute consumer when loaded. Locally available images are reused, otherwise are loaded from the server. A typical use isMPJPResources.loadImageElement(imageName, i -> { image = i; paint(); });- Parameters:
imageName- name of image to loadonLoad- method to consume image when loaded
-