Ejemplo n.º 1
0
  /**
   * From https://java3d.dev.java.net/issues/show_bug.cgi?id=89 Finds the preferred <code>
   * GraphicsConfiguration</code> object for the system. This object can then be used to create the
   * Canvas3D object for this system.
   *
   * @param window the window in which the Canvas3D will reside
   * @return The best <code>GraphicsConfiguration</code> object for the system.
   */
  private static GraphicsConfiguration getPreferredConfiguration(Window window) {
    if (window == null) return SimpleUniverse.getPreferredConfiguration();
    GraphicsDevice device = window.getGraphicsConfiguration().getDevice();
    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
    String stereo;

    // Check if the user has set the Java 3D stereo option.
    // Getting the system properties causes appletviewer to fail with a
    //  security exception without a try/catch.

    stereo =
        (String)
            java.security.AccessController.doPrivileged(
                new java.security.PrivilegedAction() {
                  public Object run() {
                    return System.getProperty("j3d.stereo");
                  }
                });

    // update template based on properties.
    if (stereo != null) {
      if (stereo.equals("REQUIRED")) template.setStereo(GraphicsConfigTemplate.REQUIRED);
      else if (stereo.equals("PREFERRED")) template.setStereo(GraphicsConfigTemplate.PREFERRED);
    }
    // Return the GraphicsConfiguration that best fits our needs.
    return device.getBestConfiguration(template);
  }
Ejemplo n.º 2
0
  /**
   * Create an instance of the panel configured to show or hide the controls and only shows VRML97
   * content.
   *
   * @param showDash true to show the navigation bar
   * @param dashTop true to put the nav bar at the top
   * @param showUrl true to show the URL location bar
   * @param urlTop true to put the location bar at the top
   * @param urlReadOnly true to make the location bar read only
   * @param showConsole true if the console should be shown immediately
   * @param skinProperties The properties object to configure appearance with
   * @param showStatusBar true to show a status bar
   * @param showFPS true to show the current FPS
   * @param contentDirectory initial directory to load content from. Must be a full path.
   * @param antialiased true to turn on antialiasing
   * @param antialiasingQuality low, medium, high, antialiasing must be turned on for this to
   *     matter.
   * @param primitiveQuality low, medium, high.
   * @param textureQuality low, medium, high.
   * @param skinProperties Customisation of the browser buttons etc
   */
  public BrowserJPanel(
      boolean showDash,
      boolean dashTop,
      boolean showUrl,
      boolean urlTop,
      boolean urlReadOnly,
      boolean showConsole,
      boolean showOpenButton,
      boolean showReloadButton,
      boolean showStatusBar,
      boolean showFPS,
      String contentDirectory,
      boolean antialiased,
      String antialiasingQuality,
      String primitiveQuality,
      String textureQuality,
      Properties skinProperties) {

    super(new BorderLayout());

    setSize(800, 600);

    numSamples = 1;
    frameCycleTime = -1;
    wireframe = false;
    elumensMode = false;

    // JC: Copied from the OpenGL code, so does nothing right now.
    if (antialiased) {
      if (antialiasingQuality.equals("low")) {
        numSamples = 2;
        //                caps.setNumSamples(numSamples);
      } else if (antialiasingQuality.equals("medium")) {
        // TODO: Really need to find the max allowable.  But JOGL startup issues make this a problem
        System.out.println("Trying for 4 samples of antialiasing.");
        numSamples = 4;
        //                caps.setNumSamples(numSamples);
      } else if (antialiasingQuality.equals("high")) {
        System.out.println("Trying for 8 samples of antialiasing.");
        numSamples = 8;
        //                caps.setNumSamples(numSamples);
      }
    }

    console = new SwingConsoleWindow();
    console.messageReport("Initializing Java3D VRML browser.\n");

    addComponentListener(this);

    // We also need a canvas to display stuff with and a universe to set
    // the content in.
    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
    template.setDoubleBuffer(GraphicsConfigTemplate3D.REQUIRED);
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice dev = env.getDefaultScreenDevice();

    GraphicsConfiguration gfx_cfg = dev.getBestConfiguration(template);

    mainCanvas = new VRMLBrowserCanvas(gfx_cfg, true);
    mainCanvas.initialize();
    mainCanvas.setErrorReporter(console);

    j3dCanvas = mainCanvas;

    CursorManager cm = new CursorManager(mainCanvas, skinProperties, console);

    universe = mainCanvas.getUniverse();
    universe.addSensorStatusListener(cm);
    universe.addNavigationStateListener(cm);

    vpManager = mainCanvas.getViewpointManager();

    setupProperties(textureQuality);

    eaiBrowser = new EAIBrowser(universe, browserImpl, eventQueue, console);

    add(mainCanvas, BorderLayout.CENTER);

    // Create these all the time
    statusLabel = new JLabel();
    fpsLabel = new JLabel();
    SwingLocationToolbar tb = null;

    if (showUrl) {
      tb =
          new SwingLocationToolbar(
              universe,
              mainCanvas.getWorldLoaderManager(),
              urlReadOnly,
              showOpenButton,
              showReloadButton,
              contentDirectory,
              skinProperties,
              console);

      if (urlTop) add(tb, BorderLayout.NORTH);
      else add(tb, BorderLayout.SOUTH);
    }

    // Need to fix this as this panel will trash the existing one if they are
    // both at the top or bottom.

    if (showDash) {
      JPanel p2 = new JPanel(new BorderLayout());

      if (dashTop) add(p2, BorderLayout.NORTH);
      else add(p2, BorderLayout.SOUTH);

      navToolbar = new SwingNavigationToolbar(universe, skinProperties, console);
      // navToolbar.setAllowUserStateChange(true);
      SwingViewpointToolbar vp_tb =
          new SwingViewpointToolbar(universe, vpManager, skinProperties, console);

      SwingConsoleButton console_button = new SwingConsoleButton(console, skinProperties);

      p2.add(navToolbar, BorderLayout.WEST);
      p2.add(vp_tb, BorderLayout.CENTER);
      p2.add(console_button, BorderLayout.EAST);

      if (showFPS || showStatusBar) {
        statusBar = new SwingStatusBar(universe, showStatusBar, showFFS, skinProperties, console);

        if (tb != null) {
          tb.setProgressListener(statusBar.getProgressListener());
        }

        p2.add(statusBar, BorderLayout.SOUTH);
      }
    }

    if (showConsole) console.setVisible(true);
  }