001: /*
002: * $RCSfile: BindableNode.java,v $
003: *
004: * @(#)BindableNode.java 1.18 98/11/05 20:34:04
005: *
006: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * $Revision: 1.2 $
033: * $Date: 2005/02/03 23:06:52 $
034: * $State: Exp $
035: */
036: /*
037: * @Author: Rick Goldberg
038: * @Author: Doug Gehringer
039: *
040: */
041: package org.jdesktop.j3d.loaders.vrml97.impl;
042:
043: import java.util.Stack;
044:
045: /** Description of the Class */
046: public abstract class BindableNode extends Node {
047:
048: // eventIn
049: SFBool bind;
050: SFTime bindTime;
051:
052: // eventOut
053: SFBool isBound;
054:
055: Stack stack;
056:
057: /**
058: *Constructor for the BindableNode object
059: *
060: *@param loader Description of the Parameter
061: *@param initStack Description of the Parameter
062: */
063: BindableNode(Loader loader, Stack initStack) {
064: super (loader);
065: stack = initStack;
066: bind = new SFBool(false);
067: bindTime = new SFTime();
068: isBound = new SFBool(false);
069: }
070:
071: /**
072: *Constructor for the BindableNode object
073: *
074: *@param loader Description of the Parameter
075: *@param initStack Description of the Parameter
076: *@param bind Description of the Parameter
077: *@param bindTime Description of the Parameter
078: *@param isBound Description of the Parameter
079: */
080: BindableNode(Loader loader, Stack initStack, SFBool bind,
081: SFTime bindTime, SFBool isBound) {
082: super (loader);
083: stack = initStack;
084: this .bind = bind;
085: this .bindTime = bindTime;
086: this .isBound = isBound;
087: }
088:
089: /**
090: * Description of the Method
091: *
092: *@param eventInName Description of the Parameter
093: *@param time Description of the Parameter
094: */
095: public void notifyMethod(String eventInName, double time) {
096: BindableNode top;
097: if (eventInName.equals("bind")) {
098: if (bind.getValue() == true) {
099: if (stack != null) {
100: if (stack.empty()) {
101: top = null;
102: } else {
103: top = (BindableNode) stack.peek();
104: }
105: if (top != this ) {
106: if (stack.contains(this )) {
107: stack.removeElement(this );
108: }
109: stack.push(this );// no matter what
110: //System.out.println("node is bound");
111: browser.bindableChanged(stack);
112: bindTime.setValue(time);
113: }
114: } else {
115: if (loader.debug) {
116: System.out
117: .println("Bind called on bindable with "
118: + "null stack");
119: }
120: }
121: isBound.setValue(true);
122: } else {// bind == false
123: if (stack != null) {
124: if ((BindableNode) stack.peek() == this ) {// i'm on top
125: stack.pop();// remove this from stack
126: // TODO: timestamp of both setValues should be same
127: top = (BindableNode) stack.peek();
128: if (top != null) {
129: top.bind.setValue(true);
130: top.isBound.setValue(true);
131: }
132: browser.bindableChanged(stack);
133: } else {
134: if (stack.contains(this )) {
135: stack.removeElement(this );
136: }
137: }
138: }
139: isBound.setValue(false);
140: }
141: }
142: }
143:
144: /** Description of the Method */
145: void initBindableFields() {
146: bind.init(this , FieldSpec, Field.EVENT_IN, "bind");
147: bindTime.init(this , FieldSpec, Field.EVENT_OUT, "bindTime");
148: isBound.init(this , FieldSpec, Field.EVENT_OUT, "isBound");
149: }
150:
151: /**
152: * Gets the implNode attribute of the BindableNode object
153: *
154: *@return The implNode value
155: */
156: public javax.media.j3d.Node getImplNode() {
157: return implNode;
158: }
159: }
|