001: /*
002: * $RCSfile: ConfigScreen.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.4 $
041: * $Date: 2007/02/09 17:20:44 $
042: * $State: Exp $
043: */
044:
045: package com.sun.j3d.utils.universe;
046:
047: import java.awt.Window;
048: import javax.media.j3d.Canvas3D;
049: import javax.media.j3d.View;
050: import javax.swing.JFrame;
051: import javax.swing.JPanel;
052: import javax.vecmath.Matrix4d;
053: import javax.vecmath.Point2d;
054:
055: class ConfigScreen extends ConfigObject {
056:
057: /**
058: * The index of this screen in the GraphicsDevice array returned by
059: * GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().
060: */
061: int frameBufferNumber;
062:
063: /**
064: * The physical width in meters of the screen area of the GraphicsDevice
065: * associated with this ConfigScreen. The default is based on a screen
066: * resolution of 90 pixels/inch.
067: */
068: double physicalScreenWidth = 0.0;
069:
070: /**
071: * The physical height in meters of the screen area of the GraphicsDevice
072: * associated with this ConfigScreen. The default is based on a screen
073: * resolution of 90 pixels/inch.
074: */
075: double physicalScreenHeight = 0.0;
076:
077: /**
078: * The trackerBaseToImagePlate transform of this ConfigScreen.
079: * The default is the identity transform.
080: */
081: Matrix4d trackerBaseToImagePlate = null;
082:
083: /**
084: * The headTrackerToLeftImagePlate transform of this ConfigScreen if HMD
085: * mode is in effect. The default is the identity transform.
086: */
087: Matrix4d headTrackerToLeftImagePlate = null;
088:
089: /**
090: * The headTrackerToRightImagePlate transform of this ConfigScreen if HMD
091: * mode is in effect. The default is the identity transform.
092: */
093: Matrix4d headTrackerToRightImagePlate = null;
094:
095: /**
096: * The monoscopicViewPolicy for this ConfigScreen. The default is
097: * View.CYCLOPEAN_EYE_VIEW.
098: */
099: int monoscopicViewPolicy = View.CYCLOPEAN_EYE_VIEW;
100:
101: /**
102: * Boolean indicating whether a full-screen window should be created for
103: * this ConfigScreen. The default is false.
104: */
105: boolean fullScreen = false;
106:
107: /**
108: * Boolean indicating whether a full-screen window with no borders should
109: * be created for this ConfigScreen. The default is false.
110: */
111: boolean noBorderFullScreen = false;
112:
113: /**
114: * The width in pixels for the window to be created for this ConfigScreen
115: * if a full screen window is not specified. The default is 512.
116: */
117: int windowWidthInPixels = 512;
118:
119: /**
120: * The height in pixels for the window to be created for this ConfigScreen
121: * if a full screen window is not specified. The default is 512.
122: */
123: int windowHeightInPixels = 512;
124:
125: /**
126: * The X pixel position of the top-left corner of the window, relative to
127: * the physical screen. The default is 0.
128: */
129: int windowX = 0;
130:
131: /**
132: * The Y pixel position of the top-left corner of the window, relative to
133: * the physical screen. The default is 0.
134: */
135: int windowY = 0;
136:
137: /**
138: * The JFrame created for this ConfigScreen. When running under JDK 1.4
139: * or newer, the JFrame always contains a JPanel which contains the
140: * Canvas3D. When running under JDK 1.3.1 and using a borderless full
141: * screen the JFrame will instead contain a JWindow which will contain the
142: * JPanel and Canvas3D.
143: */
144: JFrame j3dJFrame;
145:
146: /**
147: * The Window created for this ConfigScreen. Under JDK 1.4 or higher this
148: * is the same reference as j3dJFrame. If a borderless full screen is
149: * specified while running under JDK 1.3.1 then this is a JWindow with the
150: * j3dJFrame as its parent.
151: */
152: Window j3dWindow;
153:
154: /**
155: * The JPanel created for this ConfigScreen to hold the Canvas3D.
156: */
157: JPanel j3dJPanel;
158:
159: /**
160: * The Canvas3D created for this ConfigScreen.
161: */
162: Canvas3D j3dCanvas;
163:
164: /**
165: * Processes attributes for this object. Handles commands of the form:<p>
166: * (ScreenAttribute {instanceName} {attrName} {attrValue})
167: * (ScreenProperty {instanceName} {attrName} {attrValue})
168: * (DisplayAttribute {instanceName} {attrName} {attrValue})
169: * (DisplayProperty {instanceName} {attrName} {attrValue})
170: *
171: * @param command the command that invoked this method
172: */
173: protected void setProperty(ConfigCommand command) {
174:
175: String attr = null;
176: Object val = null;
177: String sval = null;
178:
179: if (command.argc != 4) {
180: syntaxError("Incorrect number of arguments to "
181: + command.commandName);
182: }
183:
184: if (!isName(command.argv[2])) {
185: syntaxError("The second argument to " + command.commandName
186: + " must be a property name");
187: }
188:
189: attr = (String) command.argv[2];
190: val = command.argv[3];
191:
192: if (attr.equals("PhysicalScreenWidth")) {
193: if (!(val instanceof Double)) {
194: syntaxError("Value for PhysicalScreenWidth "
195: + "must be a number");
196: }
197: physicalScreenWidth = ((Double) val).doubleValue();
198: } else if (attr.equals("PhysicalScreenHeight")) {
199: if (!(val instanceof Double)) {
200: syntaxError("Value for PhysicalScreenHeight "
201: + "must be a number");
202: }
203: physicalScreenHeight = ((Double) val).doubleValue();
204: } else if (attr.equals("TrackerBaseToImagePlate")) {
205: if (!(val instanceof Matrix4d)) {
206: syntaxError("Value for TrackerBaseToImagePlate "
207: + "must be a 4x3 or 4x4 matrix");
208: }
209: trackerBaseToImagePlate = (Matrix4d) val;
210: } else if (attr.equals("HeadTrackerToLeftImagePlate")) {
211: if (!(val instanceof Matrix4d)) {
212: syntaxError("Value for HeadTrackerToLeftImagePlate "
213: + "must be a 4x3 or 4x4 matrix");
214: }
215: headTrackerToLeftImagePlate = (Matrix4d) val;
216: } else if (attr.equals("HeadTrackerToRightImagePlate")) {
217: if (!(val instanceof Matrix4d)) {
218: syntaxError("Value for HeadTrackerToRightImagePlate "
219: + "must be a 4x3 or 4x4 matrix");
220: }
221: headTrackerToRightImagePlate = (Matrix4d) val;
222: } else if (attr.equals("MonoscopicViewPolicy")) {
223: if (!(val instanceof String)) {
224: syntaxError("Value for MonoscopicViewPolicy "
225: + "must be a name");
226: }
227: sval = (String) val;
228: if (sval.equals("LEFT_EYE_VIEW"))
229: monoscopicViewPolicy = View.LEFT_EYE_VIEW;
230: else if (sval.equals("RIGHT_EYE_VIEW"))
231: monoscopicViewPolicy = View.RIGHT_EYE_VIEW;
232: else if (sval.equals("CYCLOPEAN_EYE_VIEW"))
233: monoscopicViewPolicy = View.CYCLOPEAN_EYE_VIEW;
234: else
235: syntaxError("Invalid value for MonoscopicViewPolicy "
236: + "\"" + sval + "\"");
237: } else if (attr.equals("WindowPosition")) {
238: if (!(val instanceof Point2d)) {
239: syntaxError("WindowPosition must be a Point2d");
240: }
241: Point2d p2d = (Point2d) val;
242: windowX = (int) p2d.x;
243: windowY = (int) p2d.y;
244: } else if (attr.equals("WindowSize")) {
245: if (val instanceof Point2d) {
246: fullScreen = false;
247: noBorderFullScreen = false;
248:
249: Point2d p2d = (Point2d) val;
250: windowWidthInPixels = (int) p2d.x;
251: windowHeightInPixels = (int) p2d.y;
252: } else if (val instanceof String) {
253: String s = (String) val;
254:
255: if (s.equals("FullScreen")) {
256: fullScreen = true;
257: noBorderFullScreen = false;
258: } else if (s.equals("NoBorderFullScreen")) {
259: fullScreen = false;
260: noBorderFullScreen = true;
261: } else {
262: syntaxError("Value for WindowSize "
263: + "must be one of\n" + "\"FullScreen\" "
264: + "\"NoBorderFullScreen\" or Point2d");
265: }
266: } else {
267: syntaxError("Invalid WindowSize value: " + val
268: + "\nValue for WindowSize "
269: + "must be one of\n" + "\"FullScreen\" "
270: + "\"NoBorderFullScreen\" or Point2d");
271: }
272: } else {
273: syntaxError("Unknown " + command.commandName + " \"" + attr
274: + "\"");
275: }
276: }
277:
278: /**
279: * Initializes this object. Handles commands of the form:<p>
280: * (NewScreen {instanceName} {FrameBufferNumber}).
281: *
282: * @param command the command that invoked this method
283: */
284: protected void initialize(ConfigCommand command) {
285: if (command.argc != 3) {
286: syntaxError("Incorrect number of arguments to "
287: + command.commandName);
288: }
289:
290: if (!(command.argv[2] instanceof Double)) {
291: syntaxError("The second argument to " + command.commandName
292: + " must be a GraphicsDevice index");
293: }
294:
295: frameBufferNumber = ((Double) command.argv[2]).intValue();
296: }
297: }
|