1 /* 2 * $RCSfile: ConfigScreen.java,v $ 3 * 4 * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * - Redistribution of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * - Redistribution in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * Neither the name of Sun Microsystems, Inc. or the names of 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * This software is provided "AS IS," without a warranty of any 23 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 24 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 25 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY 26 * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 27 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 28 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS 29 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 30 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, 31 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND 32 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR 33 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGES. 35 * 36 * You acknowledge that this software is not designed, licensed or 37 * intended for use in the design, construction, operation or 38 * maintenance of any nuclear facility. 39 * 40 * $Revision: 1.4 $ 41 * $Date: 2007/02/09 17:20:44 $ 42 * $State: Exp $ 43 */ 44 45 package com.sun.j3d.utils.universe ; 46 47 import java.awt.Window ; 48 import javax.media.j3d.Canvas3D ; 49 import javax.media.j3d.View ; 50 import javax.swing.JFrame ; 51 import javax.swing.JPanel ; 52 import javax.vecmath.Matrix4d ; 53 import javax.vecmath.Point2d ; 54 55 class ConfigScreen extends ConfigObject { 56 57 /** 58 * The index of this screen in the GraphicsDevice array returned by 59 * GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(). 60 */ 61 int frameBufferNumber ; 62 63 /** 64 * The physical width in meters of the screen area of the GraphicsDevice 65 * associated with this ConfigScreen. The default is based on a screen 66 * resolution of 90 pixels/inch. 67 */ 68 double physicalScreenWidth = 0.0 ; 69 70 /** 71 * The physical height in meters of the screen area of the GraphicsDevice 72 * associated with this ConfigScreen. The default is based on a screen 73 * resolution of 90 pixels/inch. 74 */ 75 double physicalScreenHeight = 0.0 ; 76 77 /** 78 * The trackerBaseToImagePlate transform of this ConfigScreen. 79 * The default is the identity transform. 80 */ 81 Matrix4d trackerBaseToImagePlate = null ; 82 83 /** 84 * The headTrackerToLeftImagePlate transform of this ConfigScreen if HMD 85 * mode is in effect. The default is the identity transform. 86 */ 87 Matrix4d headTrackerToLeftImagePlate = null ; 88 89 /** 90 * The headTrackerToRightImagePlate transform of this ConfigScreen if HMD 91 * mode is in effect. The default is the identity transform. 92 */ 93 Matrix4d headTrackerToRightImagePlate = null ; 94 95 /** 96 * The monoscopicViewPolicy for this ConfigScreen. The default is 97 * View.CYCLOPEAN_EYE_VIEW. 98 */ 99 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 */ setProperty(ConfigCommand command)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 } 199 else if (attr.equals("PhysicalScreenHeight")) { 200 if (!(val instanceof Double)) { 201 syntaxError("Value for PhysicalScreenHeight " + 202 "must be a number") ; 203 } 204 physicalScreenHeight = ((Double)val).doubleValue() ; 205 } 206 else if (attr.equals("TrackerBaseToImagePlate")) { 207 if (!(val instanceof Matrix4d)) { 208 syntaxError("Value for TrackerBaseToImagePlate " + 209 "must be a 4x3 or 4x4 matrix") ; 210 } 211 trackerBaseToImagePlate = (Matrix4d)val ; 212 } 213 else if (attr.equals("HeadTrackerToLeftImagePlate")) { 214 if (!(val instanceof Matrix4d)) { 215 syntaxError("Value for HeadTrackerToLeftImagePlate " 216 + "must be a 4x3 or 4x4 matrix") ; 217 } 218 headTrackerToLeftImagePlate = (Matrix4d)val ; 219 } 220 else if (attr.equals("HeadTrackerToRightImagePlate")) { 221 if (!(val instanceof Matrix4d)) { 222 syntaxError("Value for HeadTrackerToRightImagePlate " 223 + "must be a 4x3 or 4x4 matrix") ; 224 } 225 headTrackerToRightImagePlate = (Matrix4d)val ; 226 } 227 else if (attr.equals("MonoscopicViewPolicy")) { 228 if (!(val instanceof String)) { 229 syntaxError("Value for MonoscopicViewPolicy " + 230 "must be a name") ; 231 } 232 sval = (String)val ; 233 if (sval.equals("LEFT_EYE_VIEW")) 234 monoscopicViewPolicy = View.LEFT_EYE_VIEW ; 235 else if (sval.equals("RIGHT_EYE_VIEW")) 236 monoscopicViewPolicy = View.RIGHT_EYE_VIEW ; 237 else if (sval.equals("CYCLOPEAN_EYE_VIEW")) 238 monoscopicViewPolicy = View.CYCLOPEAN_EYE_VIEW ; 239 else 240 syntaxError("Invalid value for MonoscopicViewPolicy " 241 + "\"" + sval + "\"") ; 242 } 243 else if (attr.equals("WindowPosition")) { 244 if (! (val instanceof Point2d)) { 245 syntaxError("WindowPosition must be a Point2d") ; 246 } 247 Point2d p2d = (Point2d)val ; 248 windowX = (int)p2d.x ; 249 windowY = (int)p2d.y ; 250 } 251 else if (attr.equals("WindowSize")) { 252 if (val instanceof Point2d) { 253 fullScreen = false ; 254 noBorderFullScreen = false ; 255 256 Point2d p2d = (Point2d)val ; 257 windowWidthInPixels = (int)p2d.x ; 258 windowHeightInPixels = (int)p2d.y ; 259 } 260 else if (val instanceof String) { 261 String s = (String)val ; 262 263 if (s.equals("FullScreen")) { 264 fullScreen = true ; 265 noBorderFullScreen = false ; 266 } else if (s.equals("NoBorderFullScreen")) { 267 fullScreen = false ; 268 noBorderFullScreen = true ; 269 } else { 270 syntaxError("Value for WindowSize " + 271 "must be one of\n" + "\"FullScreen\" " + 272 "\"NoBorderFullScreen\" or Point2d") ; 273 } 274 } 275 else { 276 syntaxError("Invalid WindowSize value: " + val + 277 "\nValue for WindowSize " + 278 "must be one of\n" + "\"FullScreen\" " + 279 "\"NoBorderFullScreen\" or Point2d") ; 280 } 281 } 282 else { 283 syntaxError("Unknown " + command.commandName + 284 " \"" + attr + "\"") ; 285 } 286 } 287 288 /** 289 * Initializes this object. Handles commands of the form:<p> 290 * (NewScreen {instanceName} {FrameBufferNumber}). 291 * 292 * @param command the command that invoked this method 293 */ initialize(ConfigCommand command)294 protected void initialize(ConfigCommand command) { 295 if (command.argc != 3) { 296 syntaxError("Incorrect number of arguments to " + 297 command.commandName) ; 298 } 299 300 if (!(command.argv[2] instanceof Double)) { 301 syntaxError("The second argument to " + command.commandName + 302 " must be a GraphicsDevice index") ; 303 } 304 305 frameBufferNumber = ((Double)command.argv[2]).intValue() ; 306 } 307 } 308