001: /*
002: * $RCSfile: SharedGroup.java,v $
003: *
004: * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.6 $
028: * $Date: 2008/02/28 20:17:30 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * The SharedGroup provides the ability to manipulate an
036: * instanced scene graph.
037: * A SharedGroup node allows multiple Link leaf nodes to share its
038: * subgraph according to the following semantics:
039: * <P><UL>
040: * <LI>A SharedGroup may be referenced by one or more Link leaf
041: * nodes. Any runtime changes to a node or component object in this
042: * shared subgraph affect all graphs that refer to this subgraph.</LI><P>
043: *
044: * <LI>A SharedGroup may be compiled by calling its compile method
045: * prior to being referenced by any Link leaf nodes.</LI><P>
046: *
047: * <LI>Only Link leaf nodes may refer to SharedGroup nodes. A
048: * SharedGroup node cannot have parents or be attached to a Locale.</LI><P>
049: * </UL>
050: *
051: * A shared subgraph may contain any group node, except an embedded
052: * SharedGroup node (SharedGroup nodes cannot have parents). However,
053: * only the following leaf nodes may appear in a shared subgraph:
054: * <P><UL>
055: * <LI>Light</LI>
056: * <LI>Link</LI>
057: * <LI>Morph</LI>
058: * <LI>Shape</LI>
059: * <LI>Sound</LI></UL><P>
060: *
061: * An IllegalSharingException is thrown if any of the following leaf nodes
062: * appear in a shared subgraph:<P>
063: * <UL>
064: * <LI>AlternateAppearance</LI>
065: * <LI>Background</LI>
066: * <LI>Behavior</LI>
067: * <LI>BoundingLeaf</LI>
068: * <LI>Clip</LI>
069: * <LI>Fog</LI>
070: * <LI>ModelClip</LI>
071: * <LI>Soundscape</LI>
072: * <LI>ViewPlatform</LI></UL>
073: * <P>
074: *
075: * @see IllegalSharingException
076: */
077:
078: public class SharedGroup extends Group {
079:
080: /**
081: * Specifies that this SharedGroup node allows reading the
082: * list of links that refer to this node.
083: *
084: * @since Java 3D 1.3
085: */
086: public static final int ALLOW_LINK_READ = CapabilityBits.SHARED_GROUP_ALLOW_LINK_READ;
087:
088: // Array for setting default read capabilities
089: private static final int[] readCapabilities = { ALLOW_LINK_READ };
090:
091: /**
092: * Constructs and initializes a new SharedGroup node object.
093: */
094: public SharedGroup() {
095: // set default read capabilities
096: setDefaultReadCapabilities(readCapabilities);
097: }
098:
099: /**
100: * Returns the list of Link nodes that refer to this SharedGroup node.
101: * @return An array of Link nodes that refer to this SharedGroup node.
102: *
103: * @since Java 3D 1.3
104: */
105: public Link[] getLinks() {
106: if (isLiveOrCompiled()) {
107: if (!this .getCapability(ALLOW_LINK_READ)) {
108: throw new CapabilityNotSetException(J3dI18N
109: .getString("SharedGroup1"));
110: }
111: }
112: return ((SharedGroupRetained) retained).getLinks();
113: }
114:
115: /**
116: * Creates the retained mode SharedGroupRetained object that this
117: * SharedGroup component object will point to.
118: */
119: void createRetained() {
120: this .retained = new SharedGroupRetained();
121: this .retained.setSource(this );
122: }
123:
124: /**
125: * Compiles the source SharedGroup associated with this object and
126: * creates and caches a compiled scene graph.
127: * @exception SceneGraphCycleException if there is a cycle in the
128: * scene graph
129: * @exception RestrictedAccessException if the method is called
130: * when this object is part of a live scene graph.
131: */
132: public void compile() {
133: if (isLive()) {
134: throw new RestrictedAccessException(J3dI18N
135: .getString("SharedGroup0"));
136: }
137:
138: if (isCompiled() == false) {
139: // will throw SceneGraphCycleException if there is a cycle
140: // in the scene graph
141: checkForCycle();
142:
143: ((SharedGroupRetained) this .retained).compile();
144: }
145: }
146:
147: /**
148: * Used to create a new instance of the node. This routine is called
149: * by <code>cloneTree</code> to duplicate the current node.
150: * @param forceDuplicate when set to <code>true</code>, causes the
151: * <code>duplicateOnCloneTree</code> flag to be ignored. When
152: * <code>false</code>, the value of each node's
153: * <code>duplicateOnCloneTree</code> variable determines whether
154: * NodeComponent data is duplicated or copied.
155: *
156: * @see Node#cloneTree
157: * @see Node#cloneNode
158: * @see Node#duplicateNode
159: * @see NodeComponent#setDuplicateOnCloneTree
160: */
161: public Node cloneNode(boolean forceDuplicate) {
162: SharedGroup sg = new SharedGroup();
163: sg.duplicateNode(this, forceDuplicate);
164: return sg;
165: }
166: }
|