001: /*
002: * $RCSfile: MFNode.java,v $
003: *
004: * @(#)MFNode.java 1.18 98/11/05 20:34:40
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: * $Revision: 1.2 $
032: * $Date: 2005/02/03 23:06:57 $
033: * $State: Exp $
034: */
035: /*
036: * @Author: Rick Goldberg
037: * @Author: Doug Gehringer
038: *
039: */
040: package org.jdesktop.j3d.loaders.vrml97.impl;
041:
042: import java.util.Observable;
043: import java.util.Observer;
044:
045: /** Description of the Class */
046: public class MFNode extends MField {
047:
048: BaseNode[] nodes;
049:
050: /**Constructor for the MFNode object */
051: public MFNode() {
052: nodes = new BaseNode[0];
053: }
054:
055: /**
056: *Constructor for the MFNode object
057: *
058: *@param values Description of the Parameter
059: */
060: public MFNode(BaseNode[] values) {
061: nodes = new BaseNode[values.length];
062: System.arraycopy(values, 0, nodes, 0, values.length);
063: }
064:
065: /**
066: * Gets the value attribute of the MFNode object
067: *
068: *@param values Description of the Parameter
069: */
070: public void getValue(BaseNode values[]) {
071: System.arraycopy(nodes, 0, values, 0, nodes.length);
072: }
073:
074: /**
075: * Gets the value attribute of the MFNode object
076: *
077: *@return The value value
078: */
079: public BaseNode[] getValue() {
080: return nodes;
081: }
082:
083: /**
084: * Sets the value attribute of the MFNode object
085: *
086: *@param values The new value value
087: */
088: public void setValue(BaseNode[] values) {
089: nodes = new BaseNode[values.length];
090: System.arraycopy(values, 0, nodes, 0, values.length);
091: route();
092: }
093:
094: /**
095: * Sets the value attribute of the MFNode object
096: *
097: *@param size The new value value
098: *@param value The new value value
099: */
100: public void setValue(int size, BaseNode[] value) {
101: // does this really mean take the first size of value?
102: setValue(value);
103: }
104:
105: /**
106: * Sets the value attribute of the MFNode object
107: *
108: *@param node The new value value
109: */
110: public void setValue(MFNode node) {
111: setValue((BaseNode[]) node.nodes);
112: }
113:
114: /**
115: * Sets the value attribute of the MFNode object
116: *
117: *@param constNode The new value value
118: */
119: public void setValue(ConstMFNode constNode) {
120: setValue((MFNode) constNode.ownerField);
121: }
122:
123: /**
124: * Description of the Method
125: *
126: *@param index Description of the Parameter
127: *@return Description of the Return Value
128: */
129: public BaseNode get1Value(int index) {
130: return (nodes[index]);
131: }
132:
133: /**
134: * Description of the Method
135: *
136: *@param index Description of the Parameter
137: *@param f Description of the Parameter
138: */
139: public void set1Value(int index, BaseNode f) {
140: nodes[index] = f;
141: route();
142: }
143:
144: /**
145: * Description of the Method
146: *
147: *@param index Description of the Parameter
148: *@param csfn Description of the Parameter
149: */
150: public void set1Value(int index, ConstSFNode csfn) {
151: set1Value(index, (SFNode) csfn.ownerField);
152: }
153:
154: /**
155: * Description of the Method
156: *
157: *@param index Description of the Parameter
158: *@param sfnod Description of the Parameter
159: */
160: public void set1Value(int index, SFNode sfnod) {
161: set1Value(index, sfnod.node);
162: }
163:
164: /**
165: * Adds a feature to the Value attribute of the MFNode object
166: *
167: *@param f The feature to be added to the Value attribute
168: */
169: public void addValue(BaseNode f) {
170: BaseNode[] temp = new BaseNode[nodes.length + 1];
171: for (int i = 0; i < temp.length - 1; i++) {
172: temp[i] = nodes[i];
173: }
174: temp[temp.length - 1] = f;
175: nodes = temp;
176:
177: route();
178: }
179:
180: /**
181: * Adds a feature to the Value attribute of the MFNode object
182: *
183: *@param constsfnod The feature to be added to the Value attribute
184: */
185: public void addValue(ConstSFNode constsfnod) {
186: addValue((SFNode) constsfnod.ownerField);
187: }
188:
189: /**
190: * Adds a feature to the Value attribute of the MFNode object
191: *
192: *@param sfnod The feature to be added to the Value attribute
193: */
194: public void addValue(SFNode sfnod) {
195: addValue(sfnod.node);
196: }
197:
198: /**
199: * Description of the Method
200: *
201: *@param index Description of the Parameter
202: *@param f Description of the Parameter
203: */
204: public void insertValue(int index, BaseNode f) {
205: BaseNode[] temp = new BaseNode[nodes.length + 1];
206: for (int i = 0; i < index; i++) {
207: temp[i] = nodes[i];
208: }
209: temp[index] = f;
210: for (int i = index + 1; i < temp.length + 1; i++) {
211: temp[i] = nodes[i - 1];
212: }
213: nodes = temp;
214: route();
215: }
216:
217: /**
218: * Description of the Method
219: *
220: *@param index Description of the Parameter
221: *@param constsfnod Description of the Parameter
222: */
223: public void insertValue(int index, ConstSFNode constsfnod) {
224: insertValue(index, (SFNode) constsfnod.ownerField);
225: }
226:
227: /**
228: * Description of the Method
229: *
230: *@param index Description of the Parameter
231: *@param constsfnod Description of the Parameter
232: */
233: public void insertValue(int index, SFNode constsfnod) {
234: insertValue(index, constsfnod.node);
235: }
236:
237: /**
238: * Description of the Method
239: *
240: *@param field Description of the Parameter
241: */
242: public synchronized void update(Field field) {
243: setValue((MFNode) field);
244: }
245:
246: /**
247: * Description of the Method
248: *
249: *@return Description of the Return Value
250: */
251: public synchronized Object clone() {
252: MFNode ref = new MFNode(nodes);
253: // deep copy
254: for (int i = 0; i < ref.nodes.length; i++) {
255: if (nodes[i] != null) {
256: BaseNode cloneNode = (BaseNode) nodes[i].clone();
257: ref.nodes[i] = cloneNode;
258: if (nodes[i].loader.debug) {
259: System.out.println("MFNode.clone(): child " + i
260: + " = " + cloneNode.toStringId() + " = "
261: + cloneNode);
262: }
263: nodes[i].loader.registerClone(nodes[i], cloneNode);
264: nodes[i].loader.cleanUp();
265: }
266: }
267: return ref;
268: }
269:
270: /**
271: * Description of the Method
272: *
273: *@return Description of the Return Value
274: */
275: public synchronized ConstField constify() {
276: if (constField == null) {
277: constField = new ConstMFNode(this );
278: }
279: return constField;
280: }
281:
282: /**
283: * Gets the size attribute of the MFNode object
284: *
285: *@return The size value
286: */
287: public int getSize() {
288: return nodes.length;
289: }
290:
291: /** Description of the Method */
292: public void clear() {
293: nodes = null;
294: }
295:
296: // todo
297: /**
298: * Description of the Method
299: *
300: *@param n Description of the Parameter
301: */
302: public void delete(int n) {
303: ;
304: }
305:
306: /**
307: * Description of the Method
308: *
309: *@return Description of the Return Value
310: */
311: public vrml.Field wrap() {
312: return new vrml.field.MFNode(this );
313: }
314:
315: /**
316: * Description of the Method
317: *
318: *@return Description of the Return Value
319: */
320: public String toString() {
321: String retval = "[\n";
322: for (int i = 0; i < nodes.length; i++) {
323: retval += nodes[i] + "\n";
324: }
325: retval += "]\n";
326: return retval;
327: }
328: }
|