예제 #1
0
  @Override
  public void onModuleLoad() {
    this.agentInfo = computeAgentInfo();
    this.listener = getApplicationListener();
    this.config = getConfig();

    if (config.rootPanel != null) {
      this.root = config.rootPanel;
    } else {
      Element element = Document.get().getElementById("embed-" + GWT.getModuleName());
      if (element == null) {
        VerticalPanel panel = new VerticalPanel();
        panel.setWidth("" + config.width + "px");
        panel.setHeight("" + config.height + "px");
        panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        RootPanel.get().add(panel);
        RootPanel.get().setWidth("" + config.width + "px");
        RootPanel.get().setHeight("" + config.height + "px");
        this.root = panel;
      } else {
        VerticalPanel panel = new VerticalPanel();
        panel.setWidth("" + config.width + "px");
        panel.setHeight("" + config.height + "px");
        panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        element.appendChild(panel.getElement());
        root = panel;
      }
    }

    // initialize SoundManager2
    SoundManager.init(GWT.getModuleBaseURL(), 9);

    // wait for soundmanager to load, this is fugly, but for
    // some reason the ontimeout and onerror callbacks are never
    // called (function instanceof Function fails, wtf JS?).
    new Timer() {
      @Override
      public void run() {
        if (SoundManager.swfLoaded()) {
          final PreloaderCallback callback = getPreloaderCallback();
          preloader = new Preloader();
          preloader.preload(
              "assets.txt",
              new PreloaderCallback() {
                @Override
                public void loaded(String file, int loaded, int total) {
                  callback.loaded(file, loaded, total);
                }

                @Override
                public void error(String file) {
                  callback.error(file);
                }

                @Override
                public void done() {
                  callback.done();
                  root.clear();
                  setupLoop();
                }
              });
          cancel();
        }
      }
    }.scheduleRepeating(100);
  }
예제 #2
0
  @Override
  public void onModuleLoad() {
    GwtApplication.agentInfo = computeAgentInfo();
    this.listener = createApplicationListener();
    this.config = getConfig();
    setApplicationLogger(new GwtApplicationLogger(this.config.log));

    addEventListeners();

    if (config.rootPanel != null) {
      this.root = config.rootPanel;
    } else {
      Element element = Document.get().getElementById("embed-" + GWT.getModuleName());
      if (element == null) {
        VerticalPanel panel = new VerticalPanel();
        panel.setWidth("" + config.width + "px");
        panel.setHeight("" + config.height + "px");
        panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        RootPanel.get().add(panel);
        RootPanel.get().setWidth("" + config.width + "px");
        RootPanel.get().setHeight("" + config.height + "px");
        this.root = panel;
      } else {
        VerticalPanel panel = new VerticalPanel();
        panel.setWidth("" + config.width + "px");
        panel.setHeight("" + config.height + "px");
        panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        element.appendChild(panel.getElement());
        root = panel;
      }
    }

    // initialize SoundManager2
    SoundManager.init(
        GWT.getModuleBaseURL(),
        9,
        config.preferFlash,
        new SoundManager.SoundManagerCallback() {

          @Override
          public void onready() {
            final PreloaderCallback callback = getPreloaderCallback();
            preloader = createPreloader();
            preloader.preload(
                "assets.txt",
                new PreloaderCallback() {
                  @Override
                  public void error(String file) {
                    callback.error(file);
                  }

                  @Override
                  public void update(PreloaderState state) {
                    callback.update(state);
                    if (state.hasEnded()) {
                      getRootPanel().clear();
                      if (loadingListener != null) loadingListener.beforeSetup();
                      setupLoop();
                      if (loadingListener != null) loadingListener.afterSetup();
                    }
                  }
                });
          }

          @Override
          public void ontimeout(String status, String errorType) {
            error("SoundManager", status + " " + errorType);
          }
        });
  }