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 class  MPJPResources.MPJPAudioResource
    An 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.String getResourceDir()
    Pathname of the remote directory holding the resources fetch using HTTP.
    (package private) static MPJPResources.MPJPAudioResource loadAudio​(java.lang.String audioName)
    Load an audio resource.
    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.
    static void setResourceDir​(java.lang.String resourceDir)
    Change the pathname of the remote directory holding the resources fetch using HTTP.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • 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 in WEB-INF/web.xml with 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 in WEB-INF/web.xml with the <url-pattern> element, contained in the <servlet-mapping> element.
      Parameters:
      resourceDir - new name of resource dir
    • loadAudio

      static MPJPResources.MPJPAudioResource loadAudio​(java.lang.String audioName)
      Load an audio resource. The returned instance can be used for playing the audio clip
                      MPJPResources.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 is
                      MPJPResources.loadImageElement(imageName, i -> {
                                      image = i;
                                      paint();
                      });
       
      Parameters:
      imageName - name of image to load
      onLoad - method to consume image when loaded