001: /*
002: * $RCSfile: Link.java,v $
003: *
004: * Copyright 1997-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:25 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * A Link leaf node allows an application to reference a shared graph,
036: * rooted by a SharedGroup node, from within a branch graph or another
037: * shared graph.
038: * Any number of Link nodes can refer to the same SharedGroup node.
039: */
040:
041: public class Link extends Leaf {
042: /**
043: * For Link nodes, specifies that the node allows access to
044: * its object's SharedGroup information.
045: */
046: public static final int ALLOW_SHARED_GROUP_READ = CapabilityBits.LINK_ALLOW_SHARED_GROUP_READ;
047:
048: /**
049: * For Link nodes, specifies that the node allows writing
050: * its object's SharedGroup information.
051: */
052: public static final int ALLOW_SHARED_GROUP_WRITE = CapabilityBits.LINK_ALLOW_SHARED_GROUP_WRITE;
053:
054: // Array for setting default read capabilities
055: private static final int[] readCapabilities = { ALLOW_SHARED_GROUP_READ };
056:
057: /**
058: * Constructs a Link node object that does not yet point to a
059: * SharedGroup node.
060: */
061: public Link() {
062: // set default read capabilities
063: setDefaultReadCapabilities(readCapabilities);
064: }
065:
066: /**
067: * Constructs a Link node object that points to the specified
068: * SharedGroup node.
069: * @param sharedGroup the SharedGroup node
070: */
071: public Link(SharedGroup sharedGroup) {
072: // set default read capabilities
073: setDefaultReadCapabilities(readCapabilities);
074:
075: ((LinkRetained) this .retained).setSharedGroup(sharedGroup);
076: }
077:
078: /**
079: * Creates the retained mode LinkRetained object that this
080: * Link object will point to.
081: */
082: void createRetained() {
083: this .retained = new LinkRetained();
084: this .retained.setSource(this );
085: }
086:
087: /**
088: * Sets the node's SharedGroup reference.
089: * @param sharedGroup the SharedGroup node to reference
090: * @exception CapabilityNotSetException if appropriate capability is
091: * not set and this object is part of live or compiled scene graph
092: */
093: public void setSharedGroup(SharedGroup sharedGroup) {
094:
095: if (isLiveOrCompiled())
096: if (!this .getCapability(ALLOW_SHARED_GROUP_WRITE))
097: throw new CapabilityNotSetException(J3dI18N
098: .getString("Link0"));
099: ((LinkRetained) this .retained).setSharedGroup(sharedGroup);
100: }
101:
102: /**
103: * Retrieves the node's SharedGroup reference.
104: * @return the SharedGroup node
105: * @exception CapabilityNotSetException if appropriate capability is
106: * not set and this object is part of live or compiled scene graph
107: */
108: public SharedGroup getSharedGroup() {
109:
110: if (isLiveOrCompiled())
111: if (!this .getCapability(ALLOW_SHARED_GROUP_READ))
112: throw new CapabilityNotSetException(J3dI18N
113: .getString("Link1"));
114: return ((LinkRetained) this .retained).getSharedGroup();
115: }
116:
117: /**
118: * Used to create a new instance of the node. This routine is called
119: * by <code>cloneTree</code> to duplicate the current node.
120: * <br>
121: * The cloned Link node will refer to the same
122: * SharedGroup as the original node. The SharedGroup referred to by
123: * this Link node will not be cloned.
124: * @param forceDuplicate when set to <code>true</code>, causes the
125: * <code>duplicateOnCloneTree</code> flag to be ignored. When
126: * <code>false</code>, the value of each node's
127: * <code>duplicateOnCloneTree</code> variable determines whether
128: * NodeComponent data is duplicated or copied.
129: *
130: * @see Node#cloneTree
131: * @see Node#cloneNode
132: * @see Node#duplicateNode
133: * @see NodeComponent#setDuplicateOnCloneTree
134: */
135: public Node cloneNode(boolean forceDuplicate) {
136: Link l = new Link();
137: l.duplicateNode(this , forceDuplicate);
138: return l;
139: }
140:
141: /**
142: * Copies all Link information from
143: * <code>originalNode</code> into
144: * the current node. This method is called from the
145: * <code>cloneNode</code> method which is, in turn, called by the
146: * <code>cloneTree</code> method.<P>
147: *
148: * @param originalNode the original node to duplicate.
149: * @param forceDuplicate when set to <code>true</code>, causes the
150: * <code>duplicateOnCloneTree</code> flag to be ignored. When
151: * <code>false</code>, the value of each node's
152: * <code>duplicateOnCloneTree</code> variable determines whether
153: * NodeComponent data is duplicated or copied.
154: *
155: * @exception RestrictedAccessException if this object is part of a live
156: * or compiled scenegraph.
157: *
158: * @see Node#duplicateNode
159: * @see Node#cloneTree
160: * @see NodeComponent#setDuplicateOnCloneTree
161: */
162: void duplicateAttributes(Node originalNode, boolean forceDuplicate) {
163: super .duplicateAttributes(originalNode, forceDuplicate);
164: ((LinkRetained) retained)
165: .setSharedGroup(((LinkRetained) originalNode.retained)
166: .getSharedGroup());
167: }
168: }
|