001: /*
002: * $RCSfile: ConfigViewPlatformBehavior.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.lang.reflect.*;
048: import java.util.ArrayList;
049: import javax.vecmath.Matrix4d;
050: import javax.media.j3d.Bounds;
051: import javax.media.j3d.Canvas3D;
052: import javax.media.j3d.Sensor;
053: import javax.media.j3d.Transform3D;
054: import com.sun.j3d.utils.behaviors.vp.ViewPlatformBehavior;
055:
056: class ConfigViewPlatformBehavior extends ConfigObject {
057:
058: // All known configurable properties.
059: private Transform3D homeTransform = null;
060: private Bounds schedulingBounds = null;
061: private int schedulingInterval = -1;
062:
063: /**
064: * The corresponding ViewPlatformBehavior instance.
065: */
066: ViewPlatformBehavior viewPlatformBehavior;
067:
068: /**
069: * Processes properties for this object. Handles commands of the form:<p>
070: * (ViewPlatformBehaviorProperty {instanceName} {attrName} {arg} ...)
071: *
072: * @param command the command that invoked this method
073: */
074: protected void setProperty(ConfigCommand cmd) {
075:
076: int argc = cmd.argc;
077: Object[] argv = cmd.argv;
078:
079: if (argc < 4) {
080: syntaxError("Wrong number of arguments to "
081: + cmd.commandName);
082: }
083:
084: if (!isName(argv[2])) {
085: syntaxError("The second argument to " + cmd.commandName
086: + " must be a property name");
087: }
088:
089: String attribute = (String) argv[2];
090: if (attribute.equals("HomeTransform")) {
091: if (!(argv[3] instanceof Matrix4d)) {
092: syntaxError("HomeTransform must be a Matrix4d");
093: }
094: homeTransform = new Transform3D((Matrix4d) argv[3]);
095: } else if (attribute.equals("SchedulingBounds")) {
096: if (!(argv[3] instanceof Bounds)) {
097: syntaxError("SchedulingBounds must be an instance of Bounds");
098: }
099: schedulingBounds = (Bounds) argv[3];
100: } else if (attribute.equals("SchedulingInterval")) {
101: if (!(argv[3] instanceof Double)) {
102: syntaxError("SchedulingInterval must be a priority (number)");
103: }
104: schedulingInterval = ((Double) argv[3]).intValue();
105: } else {
106: // It's not any of the pre-defined attributes. Add it to the
107: // properties list for the behavior instance itself to evaluate.
108: properties.add(cmd);
109: }
110: }
111:
112: /**
113: * Instantiate a ViewPlatformBehavior of the given class name.<p>
114: *
115: * NOTE: All ConfigView and ConfigSensor objects must be processed before
116: * calling this method.
117: *
118: * @return the configured ViewPlatformBehavior, or null if error
119: */
120: ViewPlatformBehavior createViewPlatformBehavior() {
121:
122: viewPlatformBehavior = (ViewPlatformBehavior) createTargetObject();
123:
124: // Set known attributes.
125: if (homeTransform != null)
126: viewPlatformBehavior.setHomeTransform(homeTransform);
127:
128: if (schedulingBounds != null)
129: viewPlatformBehavior.setSchedulingBounds(schedulingBounds);
130:
131: if (schedulingInterval != -1)
132: viewPlatformBehavior
133: .setSchedulingInterval(schedulingInterval);
134:
135: // Unknown properties in the concrete instance are evaluated later.
136: return viewPlatformBehavior;
137: }
138: }
|