Esempio n. 1
0
  /**
   * Disconnects the <code>ViewAppState</code> from the associated {@link Application}.
   *
   * <p><b>Note:</b> If this method is overridden, then the first call from the sub-class should be
   * <code>super.cleanupAppState();</code> in order to properly clean up the default <code>
   * SimpleAppState</code> and <code>ViewAppState</code> features.
   */
  @Override
  public void cleanupAppState() {

    // Detach this view's root node and GUI node from the application's
    // respective nodes.
    app.getRootNode().detachChild(rootNode);
    app.getGuiNode().detachChild(rootGuiNode);

    // Un-initialize all of the initialized components of the ViewAppState.
    clearAxes();

    // Unset the reference to the MasterApplication.
    app = null;

    // Proceed with the default cleanup last.
    super.cleanupAppState();
  }
Esempio n. 2
0
  /**
   * Creates a new SWT {@link Composite} with this <code>ViewAppState</code> embedded within it.
   * This method gets an {@link VizEmbeddedView} from the {@link MasterApplication}, connects with
   * that view, and embeds that view in the <code>Composite</code>.
   *
   * @param parent The parent <code>Composite</code>.
   * @return The <code>Composite</code> that has an embedded jME view managed by this <code>
   *     ViewAppState</code>. This <code>Composite</code>'s layout should be set by the caller.
   *     <b>This <code>Composite</code> should be disposed when it is no longer required</b>.
   */
  public Composite createComposite(Composite parent) {

    // Set the default return value and check the parameter.
    Composite composite = null;
    if (parent != null && embeddedView == null) {

      // Get an EmbeddedView that uses the app for rendering.
      embeddedView = app.getEmbeddedView();

      // Create the embedded Composite. When it is disposed, the
      // associated EmbeddedView should be released.
      composite =
          new Composite(parent, SWT.EMBEDDED) {
            @Override
            public void dispose() {
              // Dispose of resources tied with this specific view.
              disposeView(embeddedView);
              super.dispose();
            }
          };
      // Create the AWT frame inside the SWT.EMBEDDED Composite.
      Frame embeddedFrame = SWT_AWT.new_Frame(composite);
      // Add the AwtPanel to the embedded AWT Frame. The panel needs to
      // fill the Frame.
      embeddedFrame.setLayout(new BorderLayout());
      // Attach the EmbeddedView to the embedded Frame.
      embeddedView.addToEmbeddedFrame(embeddedFrame);
      embeddedFrame.pack();
      embeddedFrame.setVisible(true);

      // Wait for a maximum of 5 seconds if the view has not been
      // initialized yet. The ViewAppState must be initialized!!!
      int limit = 5000;
      int count = 0;
      while (!isInitialized() && count < limit) {
        try {
          Thread.sleep(50);
          count += 50;
        } catch (InterruptedException e) {
          logger.error(getClass().getName() + " Exception!", e);
        }
      }

      // Register with the EmbeddedView.
      embeddedView.registerViewClient(this);

      // Make sure the controls are enabled.
      enableControls();
    }

    return composite;
  }
Esempio n. 3
0
  /** Creates a default {@link FlightCamera} for the specified <code>EmbeddedView</code>. */
  @Override
  public Object createViewCamera(EmbeddedView view) {
    Object cam = null;

    if (view != null && view == embeddedView) {
      FlightCamera flyCam = new FlightCamera(view.getCamera());
      flyCam.setInputManager(app.getInputManager());
      // The camera should be enabled initially.
      flyCam.setEnabled(true);
      cam = flyCam;
    }

    return cam;
  }
Esempio n. 4
0
 /**
  * Sets whether or not to show the HUD ({@link #guiNode}). If the value changes, this will
  * enable/disable the HUD in the rendering thread.
  *
  * @param display Whether or not to show the HUD.
  * @see #getDisplayHUD()
  */
 public void setDisplayHUD(final boolean display) {
   // If the value has changed, we need to update the Application's guiNode
   // by either attaching or detaching this view's guiNode.
   if (displayHUD.compareAndSet(!display, display)) {
     app.enqueue(
         new Callable<Boolean>() {
           @Override
           public Boolean call() throws Exception {
             if (display) {
               rootGuiNode.attachChild(guiNode);
             } else {
               rootGuiNode.detachChild(guiNode);
             }
             return true;
           }
         });
   }
   return;
 }
Esempio n. 5
0
  /**
   * Starts the <code>ViewAppState</code> by attaching it to the specified <code>MasterApplication
   * </code>.
   *
   * @param app The jME-based <code>MasterApplication</code> that will be hosting this <code>
   *     ViewAppState</code>.
   */
  public void start(MasterApplication app) {

    // Do not proceed if the AppState is initialized or the parameter is
    // null.
    if (!isInitialized() && app != null) {
      // Set the app and get the next available ID.
      this.app = app;
      this.id = app.getNextId();

      // Update the names of the root and GUI Node in the
      // MasterApplication's scene graph.
      rootNode.setName("root-" + id);
      guiNode.setName("gui-" + id);

      // Now proceed with the normal start procedure.
      super.start(app);
    }

    return;
  }
Esempio n. 6
0
 /**
  * Sets whether or not to show the {@link #axes}. If the value changes, this will enable/disable
  * the axes in the rendering thread.
  *
  * @param display Whether or not to show the axes.
  * @see #getDisplayAxes()
  */
 public void setDisplayAxes(final boolean display) {
   // If the value has changed, we need to update the Application's scene
   // by either attaching or detaching the axis Spatials.
   if (displayAxes.compareAndSet(!display, display)) {
     app.enqueue(
         new Callable<Boolean>() {
           @Override
           public Boolean call() throws Exception {
             if (display) {
               // Attach the axes to the root Node.
               rootNode.attachChild(axes);
             } else {
               // Detach the axes from the root Node.
               rootNode.detachChild(axes);
             }
             return true;
           }
         });
   }
   return;
 }