/* */ package com.sun.j3d.utils.universe;
/* */
/* */ import com.sun.j3d.audioengines.headspace.HeadspaceMixer;
/* */ import java.awt.BorderLayout;
/* */ import java.awt.Container;
/* */ import java.awt.Frame;
/* */ import java.awt.GraphicsConfiguration;
/* */ import java.awt.GraphicsDevice;
/* */ import java.awt.GraphicsEnvironment;
/* */ import java.awt.Panel;
/* */ import java.awt.Rectangle;
/* */ import java.awt.Window;
/* */ import java.awt.event.WindowAdapter;
/* */ import java.awt.event.WindowEvent;
/* */ import java.net.URL;
/* */ import java.util.HashMap;
/* */ import javax.media.j3d.AudioDevice;
/* */ import javax.media.j3d.Canvas3D;
/* */ import javax.media.j3d.GraphicsConfigTemplate3D;
/* */ import javax.media.j3d.PhysicalBody;
/* */ import javax.media.j3d.PhysicalEnvironment;
/* */ import javax.media.j3d.Screen3D;
/* */ import javax.media.j3d.Transform3D;
/* */ import javax.media.j3d.View;
/* */ import javax.swing.JFrame;
/* */ import javax.swing.JPanel;
/* */ import javax.swing.JWindow;
/* */
/* */ public class Viewer
/* */ {
/* */ private static final boolean debug = false;
/* 101 */ private static PhysicalBody physicalBody = null;
/* 102 */ private static PhysicalEnvironment physicalEnvironment = null;
/* 103 */ private View view = null;
/* 104 */ private ViewerAvatar avatar = null;
/* 105 */ private Canvas3D[] canvases = null;
/* 106 */ private JFrame[] j3dJFrames = null;
/* 107 */ private JPanel[] j3dJPanels = null;
/* 108 */ private Window[] j3dWindows = null;
/* 109 */ private ViewingPlatform viewingPlatform = null;
/* */
/* 112 */ static HashMap viewerMap = new HashMap(5);
/* 113 */ private float dvrFactor = 1.0F;
/* 114 */ private boolean doDvr = false;
/* 115 */ private boolean doDvrResizeCompensation = true;
/* */
/* */ public static Viewer getViewer(View view)
/* */ {
/* 131 */ Viewer viewer = null;
/* 132 */ synchronized (viewerMap)
/* */ {
/* 134 */ viewer = (Viewer)viewerMap.get(view);
/* */ }
/* 136 */ return viewer;
/* */ }
/* */
/* */ public static Viewer removeViewerMapEntry(View view)
/* */ {
/* 153 */ Viewer viewer = null;
/* 154 */ synchronized (viewerMap)
/* */ {
/* 156 */ viewer = (Viewer)viewerMap.remove(view);
/* */ }
/* */
/* 160 */ return viewer;
/* */ }
/* */
/* */ public static void clearViewerMap()
/* */ {
/* 174 */ synchronized (viewerMap) {
/* 175 */ viewerMap.clear();
/* */ }
/* */ }
/* */
/* */ public boolean isDvrEnabled()
/* */ {
/* 193 */ return this.doDvr;
/* */ }
/* */
/* */ public void setDvrEnable(boolean dvr)
/* */ {
/* 208 */ this.doDvr = dvr;
/* 209 */ this.view.repaint();
/* */ }
/* */
/* */ public float getDvrFactor()
/* */ {
/* 224 */ return this.dvrFactor;
/* */ }
/* */
/* */ public void setDvrFactor(float dvr)
/* */ {
/* 240 */ this.dvrFactor = dvr;
/* 241 */ this.view.repaint();
/* */ }
/* */
/* */ public void setDvrResizeCompensationEnable(boolean dvrRCE)
/* */ {
/* 257 */ this.doDvrResizeCompensation = dvrRCE;
/* 258 */ this.view.repaint();
/* */ }
/* */
/* */ public boolean getDvrResizeCompensationEnable()
/* */ {
/* 272 */ return this.doDvrResizeCompensation;
/* */ }
/* */
/* */ public Viewer()
/* */ {
/* 283 */ this(null, null, null, true);
/* */ }
/* */
/* */ public Viewer(Canvas3D userCanvas)
/* */ {
/* 298 */ this(new Canvas3D[] { userCanvas == null ? null : userCanvas }, null, null, true);
/* */ }
/* */
/* */ public Viewer(Canvas3D[] userCanvases)
/* */ {
/* 314 */ this(userCanvases, null, null, true);
/* */ }
/* */
/* */ public Viewer(Canvas3D[] userCanvases, PhysicalBody userBody, PhysicalEnvironment userEnvironment, boolean setVisible)
/* */ {
/* 334 */ if (userBody == null)
/* 335 */ physicalBody = new PhysicalBody();
/* */ else {
/* 337 */ physicalBody = userBody;
/* */ }
/* */
/* 340 */ if (userEnvironment == null)
/* 341 */ physicalEnvironment = new PhysicalEnvironment();
/* */ else {
/* 343 */ physicalEnvironment = userEnvironment;
/* */ }
/* */
/* 347 */ if (userCanvases == null) {
/* 348 */ GraphicsConfiguration config = ConfiguredUniverse.getPreferredConfiguration();
/* */
/* 351 */ this.canvases = new Canvas3D[1];
/* 352 */ this.canvases[0] = new Canvas3D(config);
/* */ try {
/* 354 */ this.canvases[0].setFocusable(true); } catch (NoSuchMethodError e) {
/* */ }
/* 356 */ createFramesAndPanels(setVisible);
/* */ }
/* */ else {
/* 359 */ this.canvases = new Canvas3D[userCanvases.length];
/* 360 */ for (int i = 0; i < userCanvases.length; i++) {
/* 361 */ this.canvases[i] = userCanvases[i];
/* */ try {
/* 363 */ this.canvases[i].setFocusable(true);
/* */ }
/* */ catch (NoSuchMethodError e)
/* */ {
/* */ }
/* */ }
/* */ }
/* 370 */ this.view = new View();
/* */
/* 372 */ synchronized (viewerMap) {
/* 373 */ viewerMap.put(this.view, this);
/* */ }
/* 375 */ for (int i = 0; i < this.canvases.length; i++) {
/* 376 */ this.view.addCanvas3D(this.canvases[i]);
/* */ }
/* 378 */ this.view.setPhysicalBody(physicalBody);
/* 379 */ this.view.setPhysicalEnvironment(physicalEnvironment);
/* */ }
/* */
/* */ /** @deprecated */
/* */ public Viewer(URL userConfig)
/* */ {
/* 395 */ this(null, userConfig);
/* */ }
/* */
/* */ /** @deprecated */
/* */ public Viewer(Canvas3D userCanvas, URL userConfig)
/* */ {
/* 413 */ if (physicalBody == null) {
/* 414 */ physicalBody = new PhysicalBody();
/* */ }
/* */
/* 418 */ if (physicalEnvironment == null) {
/* 419 */ physicalEnvironment = new PhysicalEnvironment();
/* */ }
/* */
/* 423 */ if (userCanvas == null) {
/* 424 */ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
/* */
/* 427 */ this.canvases = new Canvas3D[1];
/* 428 */ this.canvases[0] = new Canvas3D(config);
/* 429 */ createFramesAndPanels(true);
/* */ }
/* */ else {
/* 432 */ this.canvases = new Canvas3D[1];
/* 433 */ this.canvases[0] = userCanvas;
/* */ }
/* */ try
/* */ {
/* 437 */ this.canvases[0].setFocusable(true);
/* */ }
/* */ catch (NoSuchMethodError e)
/* */ {
/* */ }
/* 442 */ this.view = new View();
/* */
/* 444 */ synchronized (viewerMap) {
/* 445 */ viewerMap.put(this.view, this);
/* */ }
/* 447 */ this.view.addCanvas3D(this.canvases[0]);
/* 448 */ this.view.setPhysicalBody(physicalBody);
/* 449 */ this.view.setPhysicalEnvironment(physicalEnvironment);
/* */ }
/* */
/* */ Viewer(ConfigScreen[] cs, ConfigView cv, boolean setVisible)
/* */ {
/* 467 */ this.view = cv.j3dView;
/* */
/* 469 */ synchronized (viewerMap) {
/* 470 */ viewerMap.put(this.view, this);
/* */ }
/* */
/* 474 */ physicalBody = cv.physicalBody;
/* 475 */ physicalEnvironment = cv.physicalEnvironment;
/* */
/* 492 */ GraphicsEnvironment graphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
/* 493 */ GraphicsDevice[] devices = graphicsEnv.getScreenDevices();
/* */
/* 495 */ if (devices == null) {
/* 496 */ throw new RuntimeException("\nNo screen devices available in local environment");
/* */ }
/* */
/* 513 */ this.canvases = new Canvas3D[cs.length];
/* 514 */ this.j3dJFrames = new JFrame[cs.length];
/* 515 */ this.j3dJPanels = new JPanel[cs.length];
/* 516 */ this.j3dWindows = new Window[cs.length];
/* */
/* 519 */ GraphicsConfigTemplate3D tpl3D = new GraphicsConfigTemplate3D();
/* 520 */ if (cv.stereoEnable) {
/* 521 */ tpl3D.setStereo(2);
/* */ }
/* 523 */ if (cv.antialiasingEnable) {
/* 524 */ tpl3D.setSceneAntialiasing(2);
/* */ }
/* */
/* 530 */ for (int i = 0; i < cs.length; i++) {
/* 531 */ if (cs[i].frameBufferNumber >= devices.length) {
/* 532 */ cs[i]; throw new ArrayIndexOutOfBoundsException(ConfigScreen.errorMessage(cs[i].creatingCommand, "Screen " + cs[i].frameBufferNumber + " is invalid; " + (devices.length - 1) + " is the maximum local index."));
/* */ }
/* */
/* 540 */ GraphicsConfiguration cfg = devices[cs[i].frameBufferNumber].getBestConfiguration(tpl3D);
/* */
/* 543 */ if (cfg == null) {
/* 544 */ throw new RuntimeException("\nNo GraphicsConfiguration on screen " + cs[i].frameBufferNumber + " conforms to template");
/* */ }
/* */
/* 548 */ Rectangle bounds = cfg.getBounds();
/* 549 */ cs[i].j3dJFrame = (this.j3dJFrames[i] = = new JFrame(cs[i].instanceName, cfg));
/* */ Container contentPane;
/* 552 */ if (cs[i].noBorderFullScreen) {
/* */ Container contentPane;
/* */ try {
/* 555 */ this.j3dJFrames[i].setUndecorated(true);
/* */
/* 557 */ cs[i].j3dWindow = (this.j3dWindows[i] = = this.j3dJFrames[i]);
/* 558 */ contentPane = this.j3dJFrames[i].getContentPane();
/* */ }
/* */ catch (NoSuchMethodError e)
/* */ {
/* 562 */ JWindow jwin = new JWindow(this.j3dJFrames[i], cfg);
/* */
/* 564 */ cs[i].j3dWindow = (this.j3dWindows[i] = = jwin);
/* 565 */ contentPane = jwin.getContentPane();
/* */ }
/* */
/* 568 */ contentPane.setLayout(new BorderLayout());
/* 569 */ this.j3dWindows[i].setSize(bounds.width, bounds.height);
/* 570 */ this.j3dWindows[i].setLocation(bounds.x, bounds.y);
/* */ }
/* */ else {
/* 573 */ cs[i].j3dWindow = (this.j3dWindows[i] = = this.j3dJFrames[i]);
/* */
/* 575 */ contentPane = this.j3dJFrames[i].getContentPane();
/* 576 */ contentPane.setLayout(new BorderLayout());
/* */
/* 578 */ if (cs[i].fullScreen) {
/* 579 */ this.j3dWindows[i].setSize(bounds.width, bounds.height);
/* 580 */ this.j3dWindows[i].setLocation(bounds.x, bounds.y);
/* */ }
/* */ else {
/* 583 */ this.j3dWindows[i].setSize(cs[i].windowWidthInPixels, cs[i].windowHeightInPixels);
/* */
/* 585 */ this.j3dWindows[i].setLocation(bounds.x + cs[i].windowX, bounds.y + cs[i].windowY);
/* */ }
/* */
/* */ }
/* */
/* 591 */ cs[i].j3dCanvas = (this.canvases[i] = = new Canvas3D(cfg));
/* 592 */ this.canvases[i].setStereoEnable(cv.stereoEnable);
/* 593 */ this.canvases[i].setMonoscopicViewPolicy(cs[i].monoscopicViewPolicy);
/* */
/* 596 */ Screen3D screen = this.canvases[i].getScreen3D();
/* */
/* 598 */ if (cs[i].physicalScreenWidth != 0.0D) {
/* 599 */ screen.setPhysicalScreenWidth(cs[i].physicalScreenWidth);
/* */ }
/* 601 */ if (cs[i].physicalScreenHeight != 0.0D) {
/* 602 */ screen.setPhysicalScreenHeight(cs[i].physicalScreenHeight);
/* */ }
/* 604 */ if (cs[i].trackerBaseToImagePlate != null) {
/* 605 */ screen.setTrackerBaseToImagePlate(new Transform3D(cs[i].trackerBaseToImagePlate));
/* */ }
/* */
/* 608 */ if (cs[i].headTrackerToLeftImagePlate != null) {
/* 609 */ screen.setHeadTrackerToLeftImagePlate(new Transform3D(cs[i].headTrackerToLeftImagePlate));
/* */ }
/* */
/* 612 */ if (cs[i].headTrackerToRightImagePlate != null) {
/* 613 */ screen.setHeadTrackerToRightImagePlate(new Transform3D(cs[i].headTrackerToRightImagePlate));
/* */ }
/* */
/* 617 */ cs[i].j3dJPanel = (this.j3dJPanels[i] = = new JPanel());
/* 618 */ this.j3dJPanels[i].setLayout(new BorderLayout());
/* 619 */ this.j3dJPanels[i].add("Center", this.canvases[i]);
/* */
/* 622 */ contentPane.add("Center", this.j3dJPanels[i]);
/* */
/* 625 */ this.view.addCanvas3D(this.canvases[i]);
/* */
/* 628 */ addWindowCloseListener(this.j3dWindows[i]);
/* */ try
/* */ {
/* 634 */ this.canvases[i].setFocusable(true);
/* */ }
/* */ catch (NoSuchMethodError e)
/* */ {
/* */ }
/* */
/* */ }
/* */
/* 653 */ if (setVisible)
/* */ {
/* 655 */ setVisible(true);
/* */ }
/* */ }
/* */
/* */ private void createFramesAndPanels(boolean setVisible)
/* */ {
/* 661 */ this.j3dJFrames = new JFrame[this.canvases.length];
/* 662 */ this.j3dJPanels = new JPanel[this.canvases.length];
/* 663 */ this.j3dWindows = new Window[this.canvases.length];
/* */
/* 665 */ for (int i = 0; i < this.canvases.length; i++)
/* */ {
/* */ void tmp64_61 = new JFrame(); this.j3dJFrames[i] = tmp64_61; this.j3dWindows[i] = tmp64_61;
/* 667 */ this.j3dJFrames[i].getContentPane().setLayout(new BorderLayout());
/* 668 */ this.j3dJFrames[i].setSize(256, 256);
/* */
/* 671 */ this.j3dJPanels[i] = new JPanel();
/* 672 */ this.j3dJPanels[i].setLayout(new BorderLayout());
/* 673 */ this.j3dJPanels[i].add("Center", this.canvases[i]);
/* 674 */ this.j3dJFrames[i].getContentPane().add("Center", this.j3dJPanels[i]);
/* 675 */ if (setVisible) {
/* 676 */ this.j3dJFrames[i].setVisible(true);
/* */ }
/* 678 */ addWindowCloseListener(this.j3dJFrames[i]);
/* */ }
/* */ }
/* */
/* */ public void setVisible(boolean visible)
/* */ {
/* 690 */ for (int i = 0; i < this.j3dWindows.length; i++)
/* 691 */ this.j3dWindows[i].setVisible(visible);
/* */ }
/* */
/* */ public View getView()
/* */ {
/* 701 */ return this.view;
/* */ }
/* */
/* */ public void setViewingPlatform(ViewingPlatform platform)
/* */ {
/* 712 */ if (this.viewingPlatform != null) {
/* 713 */ this.viewingPlatform.removeViewer(this);
/* */ }
/* */
/* 716 */ this.viewingPlatform = platform;
/* */
/* 718 */ if (platform != null) {
/* 719 */ this.view.attachViewPlatform(platform.getViewPlatform());
/* 720 */ platform.addViewer(this);
/* */
/* 722 */ if (this.avatar != null)
/* 723 */ this.viewingPlatform.setAvatar(this, this.avatar);
/* */ }
/* */ else {
/* 726 */ this.view.attachViewPlatform(null);
/* */ }
/* */ }
/* */
/* */ public ViewingPlatform getViewingPlatform()
/* */ {
/* 735 */ return this.viewingPlatform;
/* */ }
/* */
/* */ public void setAvatar(ViewerAvatar avatar)
/* */ {
/* 749 */ if (this.avatar == avatar) {
/* 750 */ return;
/* */ }
/* 752 */ this.avatar = avatar;
/* 753 */ if (this.viewingPlatform != null)
/* 754 */ this.viewingPlatform.setAvatar(this, this.avatar);
/* */ }
/* */
/* */ public ViewerAvatar getAvatar()
/* */ {
/* 766 */ return this.avatar;
/* */ }
/* */
/* */ public PhysicalBody getPhysicalBody()
/* */ {
/* 775 */ return physicalBody;
/* */ }
/* */
/* */ public PhysicalEnvironment getPhysicalEnvironment()
/* */ {
/* 785 */ return physicalEnvironment;
/* */ }
/* */
/* */ public Canvas3D getCanvas3D()
/* */ {
/* 796 */ return this.canvases[0];
/* */ }
/* */
/* */ public Canvas3D getCanvas3D(int canvasNum)
/* */ {
/* 810 */ if (canvasNum > this.canvases.length) {
/* 811 */ return null;
/* */ }
/* 813 */ return this.canvases[canvasNum];
/* */ }
/* */
/* */ public Canvas3D[] getCanvas3Ds()
/* */ {
/* 824 */ Canvas3D[] ret = new Canvas3D[this.canvases.length];
/* 825 */ for (int i = 0; i < this.canvases.length; i++) {
/* 826 */ ret[i] = this.canvases[i];
/* */ }
/* 828 */ return ret;
/* */ }
/* */
/* */ /** @deprecated */
/* */ public Canvas3D getCanvases()
/* */ {
/* 836 */ return getCanvas3D();
/* */ }
/* */
/* */ /** @deprecated */
/* */ public Frame getFrame()
/* */ {
/* 846 */ throw new UnsupportedOperationException("\nAWT Frame components are not created by the Viewer class");
/* */ }
/* */
/* */ public JFrame getJFrame(int frameNum)
/* */ {
/* 868 */ if ((this.j3dJFrames == null) || (frameNum > this.j3dJFrames.length)) {
/* 869 */ return null;
/* */ }
/* 871 */ return this.j3dJFrames[frameNum];
/* */ }
/* */
/* */ public JFrame[] getJFrames()
/* */ {
/* 891 */ if (this.j3dJFrames == null) {
/* 892 */ return null;
/* */ }
/* 894 */ JFrame[] ret = new JFrame[this.j3dJFrames.length];
/* 895 */ for (int i = 0; i < this.j3dJFrames.length; i++) {
/* 896 */ ret[i] = this.j3dJFrames[i];
/* */ }
/* 898 */ return ret;
/* */ }
/* */
/* */ /** @deprecated */
/* */ public Panel getPanel()
/* */ {
/* 908 */ throw new UnsupportedOperationException("\nAWT Panel components are not created by the Viewer class");
/* */ }
/* */
/* */ public JPanel getJPanel(int panelNum)
/* */ {
/* 924 */ if ((this.j3dJPanels == null) || (panelNum > this.j3dJPanels.length)) {
/* 925 */ return null;
/* */ }
/* 927 */ return this.j3dJPanels[panelNum];
/* */ }
/* */
/* */ public JPanel[] getJPanels()
/* */ {
/* 941 */ if (this.j3dJPanels == null) {
/* 942 */ return null;
/* */ }
/* 944 */ JPanel[] ret = new JPanel[this.j3dJPanels.length];
/* 945 */ for (int i = 0; i < this.j3dJPanels.length; i++) {
/* 946 */ ret[i] = this.j3dJPanels[i];
/* */ }
/* 948 */ return ret;
/* */ }
/* */
/* */ public AudioDevice createAudioDevice()
/* */ {
/* 959 */ if (physicalEnvironment != null) {
/* 960 */ HeadspaceMixer mixer = new HeadspaceMixer(physicalEnvironment);
/* 961 */ mixer.initialize();
/* 962 */ return mixer;
/* */ }
/* */
/* 965 */ return null;
/* */ }
/* */
/* */ public SimpleUniverse getUniverse()
/* */ {
/* 976 */ return getViewingPlatform().getUniverse();
/* */ }
/* */
/* */ void addWindowCloseListener(Window win)
/* */ {
/* 984 */ SecurityManager sm = System.getSecurityManager();
/* 985 */ boolean doExit = true;
/* */
/* 987 */ if (sm != null) {
/* */ try {
/* 989 */ sm.checkExit(0);
/* */ } catch (SecurityException e) {
/* 991 */ doExit = false;
/* */ }
/* */ }
/* 994 */ boolean _doExit = doExit;
/* */
/* 996 */ win.addWindowListener(new WindowAdapter() { private final boolean val$_doExit;
/* */
/* 998 */ public void windowClosing(WindowEvent winEvent) { Window w = winEvent.getWindow();
/* 999 */ w.hide();
/* */ try {
/* 1001 */ w.dispose(); } catch (IllegalStateException e) {
/* */ }
/* 1003 */ if (this.val$_doExit)
/* 1004 */ System.exit(0);
/* */ }
/* */ });
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name: com.sun.j3d.utils.universe.Viewer
* JD-Core Version: 0.6.2
*/