1 /*
2  * $RCSfile: WakeupCriterion.java,v $
3  *
4  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This code is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 only, as
9  * published by the Free Software Foundation.  Sun designates this
10  * particular file as subject to the "Classpath" exception as provided
11  * by Sun in the LICENSE file that accompanied this code.
12  *
13  * This code is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16  * version 2 for more details (a copy is included in the LICENSE file that
17  * accompanied this code).
18  *
19  * You should have received a copy of the GNU General Public License version
20  * 2 along with this work; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24  * CA 95054 USA or visit www.sun.com if you need additional information or
25  * have any questions.
26  *
27  * $Revision: 1.5 $
28  * $Date: 2008/02/28 20:17:33 $
29  * $State: Exp $
30  */
31 
32 package javax.media.j3d;
33 
34 /**
35  * An abstract class specifying a singleton wakeup Criterion. This
36  * class consists of several subclasses, each of which specifies one
37  * particular wakeup criterion, that criterion's associated arguments
38  * (if any), and either a flag that indicates whether this criterion
39  * caused a Behavior object to awaken or a return field containing the
40  * information that caused the Behavior object to awaken.
41  * <p>
42  * Note that a unique WakeupCriterion object must be used with each instance
43  * of a Behavior. Sharing wakeup criteria among different instances of
44  * a Behavior is illegal.  Similarly, a unique WakeupCriterion object
45  * must be used for each individual element in the set of arrays used
46  * to construct WakeupOr, WakeupAnd, WakeupOrOfAnds, and
47  * WakeupAndOfOrs objects.
48  */
49 
50 public abstract class WakeupCriterion extends WakeupCondition {
51 
52     /**
53      * Flag specifying whether this criterion triggered a wakeup
54      */
55     boolean triggered;
56 
57     /**
58      * Returns true if this criterion triggered the wakeup.
59      * @return true if this criterion triggered the wakeup.
60      */
hasTriggered()61     public boolean hasTriggered(){
62 	return this.triggered;
63     }
64 
65     /**
66      * Set the Criterion's trigger flag to true.
67      */
setTriggered()68     void setTriggered(){
69 	this.triggered = true;
70 	if (this.parent == null) {
71 	    super.setConditionMet(id, Boolean.TRUE);
72 	} else {
73 	    parent.setConditionMet(id, Boolean.TRUE);
74 	}
75     }
76 
77     /**
78      * Initialize And/Or tree and add criterion to the BehaviourStructure.
79      *
80      */
buildTree(WakeupCondition parent, int id, BehaviorRetained b)81     void buildTree(WakeupCondition parent, int id, BehaviorRetained b) {
82 	super.buildTree(parent, id, b);
83 	triggered = false;
84 	addBehaviorCondition(b.universe.behaviorStructure);
85     }
86 
87 
88     /**
89      * This goes through the AndOr tree to remove the various criterion from the
90      * BehaviorStructure.
91      * We can't use  behav.universe.behaviorStructure since behav
92      * may reassign to another universe at this time.
93      *
94      */
cleanTree(BehaviorStructure bs)95     void cleanTree(BehaviorStructure bs){
96 	conditionMet = false;
97 	removeBehaviorCondition(bs);
98     };
99 
100 
101     /**
102      * This goes through the AndOr tree to reset various criterion.
103      */
resetTree()104     void resetTree() {
105 	conditionMet = false;
106 	triggered = false;
107 	resetBehaviorCondition(behav.universe.behaviorStructure);
108     }
109 
110     /**
111      * This is a callback from BehaviorStructure. It is
112      * used to add wakeupCondition to behavior structure.
113      */
addBehaviorCondition(BehaviorStructure bs)114     abstract void addBehaviorCondition(BehaviorStructure bs);
115 
116 
117     /**
118      * This is a callback from BehaviorStructure. It is
119      * used to remove wakeupCondition from behavior structure.
120      */
removeBehaviorCondition(BehaviorStructure bs)121     abstract void removeBehaviorCondition(BehaviorStructure bs);
122 
123     /**
124      * It is used reset wakeupCondition when it is reused.
125      */
resetBehaviorCondition(BehaviorStructure bs)126     abstract void resetBehaviorCondition(BehaviorStructure bs);
127 }
128