001: /*
002: * $RCSfile: MFVec2f.java,v $
003: *
004: * @(#)MFVec2f.java 1.12 98/11/05 20:34:42
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:58 $
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: import java.util.Vector;
045:
046: /** Description of the Class */
047: public class MFVec2f extends MField {
048:
049: float[] vals;
050:
051: /**Constructor for the MFVec2f object */
052: public MFVec2f() {
053: float[] dummy = new float[1];
054: setValue(dummy);
055: }
056:
057: /**
058: *Constructor for the MFVec2f object
059: *
060: *@param values Description of the Parameter
061: */
062: public MFVec2f(float[][] values) {
063: setValue(values);
064: }
065:
066: // What is the size doing here?
067: /**
068: *Constructor for the MFVec2f object
069: *
070: *@param size Description of the Parameter
071: *@param values Description of the Parameter
072: */
073: public MFVec2f(int size, float[] values) {
074: setValue(values);
075: }
076:
077: /**
078: *Constructor for the MFVec2f object
079: *
080: *@param values Description of the Parameter
081: */
082: public MFVec2f(float[] values) {
083: setValue(values);
084: }
085:
086: /**
087: * Gets the value attribute of the MFVec2f object
088: *
089: *@param values Description of the Parameter
090: */
091: public void getValue(float[][] values) {
092: int numVecs = vals.length / 2;
093: for (int i = 0; i < numVecs; i++) {
094: System.arraycopy(vals, i * 2, values[i], 0, 2);
095: }
096: }
097:
098: /**
099: * Gets the value attribute of the MFVec2f object
100: *
101: *@param values Description of the Parameter
102: */
103: public void getValue(float[] values) {
104: System.arraycopy(vals, 0, values, 0, vals.length);
105: }
106:
107: /**
108: * Description of the Method
109: *
110: *@param index Description of the Parameter
111: *@param values Description of the Parameter
112: */
113: public void get1Value(int index, float[] values) {
114: System.arraycopy(vals, index * 2, values, 0, 2);
115: }
116:
117: /**
118: * Description of the Method
119: *
120: *@param index Description of the Parameter
121: *@param vec Description of the Parameter
122: */
123: public void get1Value(int index, SFVec2f vec) {
124: vec.setValue(vals[index], vals[index + 1]);
125: }
126:
127: /**
128: * Sets the value attribute of the MFVec2f object
129: *
130: *@param values The new value value
131: */
132: public void setValue(float[][] values) {
133: vals = new float[values.length * 2];
134: for (int i = 0; i < values.length; i++) {
135: System.arraycopy(values, 0, vals, i * 2, i * 2 + 2);
136: }
137: route();
138:
139: }
140:
141: /**
142: * Sets the value attribute of the MFVec2f object
143: *
144: *@param values The new value value
145: */
146: public void setValue(float[] values) {
147: vals = new float[values.length];
148: System.arraycopy(values, 0, vals, 0, values.length);
149: route();
150: }
151:
152: /**
153: * Sets the value attribute of the MFVec2f object
154: *
155: *@param size The new value value
156: *@param values The new value value
157: */
158: public void setValue(int size, float[] values) {
159: setValue(values);
160: }
161:
162: /**
163: * Sets the value attribute of the MFVec2f object
164: *
165: *@param field The new value value
166: */
167: public void setValue(MFVec2f field) {
168: setValue(field.vals);
169: }
170:
171: /**
172: * Sets the value attribute of the MFVec2f object
173: *
174: *@param field The new value value
175: */
176: public void setValue(ConstMFVec2f field) {
177: setValue((MFVec2f) field.ownerField);
178: }
179:
180: /**
181: * Description of the Method
182: *
183: *@param index Description of the Parameter
184: *@param constvec Description of the Parameter
185: */
186: public void set1Value(int index, ConstSFVec2f constvec) {
187: set1Value(index, (SFVec2f) constvec.ownerField);
188: }
189:
190: /**
191: * Description of the Method
192: *
193: *@param index Description of the Parameter
194: *@param vec Description of the Parameter
195: */
196: public void set1Value(int index, SFVec2f vec) {
197: set1Value(index, vec.vec2f[0], vec.vec2f[1]);
198: }
199:
200: /**
201: * Description of the Method
202: *
203: *@param index Description of the Parameter
204: *@param x Description of the Parameter
205: *@param y Description of the Parameter
206: */
207: public void set1Value(int index, float x, float y) {
208: vals[index * 2 + 0] = x;
209: vals[index * 2 + 1] = y;
210: route();
211: }
212:
213: /**
214: * Description of the Method
215: *
216: *@param index Description of the Parameter
217: *@param constvec Description of the Parameter
218: */
219: public void insertValue(int index, ConstSFVec2f constvec) {
220: insertValue(index, (SFVec2f) constvec.ownerField);
221: route();
222: }
223:
224: /**
225: * Description of the Method
226: *
227: *@param index Description of the Parameter
228: *@param vec Description of the Parameter
229: */
230: public void insertValue(int index, SFVec2f vec) {
231: insertValue(index, vec.vec2f[0], vec.vec2f[1]);
232: }
233:
234: /**
235: * Description of the Method
236: *
237: *@param index Description of the Parameter
238: *@param x Description of the Parameter
239: *@param y Description of the Parameter
240: */
241: public void insertValue(int index, float x, float y) {
242: int i;
243: float[] temp = new float[vals.length + 2];
244: for (i = 0; i < index * 2; i++) {
245: temp[i] = vals[i];
246: }
247: temp[i++] = x;
248: temp[i++] = y;
249: for (; i < temp.length; i++) {
250: temp[i] = vals[i - 2];
251: }
252: vals = temp;
253: route();
254: }
255:
256: /**
257: * Description of the Method
258: *
259: *@param field Description of the Parameter
260: */
261: public void update(Field field) {
262: setValue((MFVec2f) field);
263: }
264:
265: /**
266: * Description of the Method
267: *
268: *@return Description of the Return Value
269: */
270: public Object clone() {
271: MFVec2f ref = new MFVec2f();
272: ref.vals = new float[vals.length];
273: System.arraycopy(vals, 0, ref.vals, 0, vals.length);
274: return ref;
275: }
276:
277: /**
278: * Description of the Method
279: *
280: *@return Description of the Return Value
281: */
282: public ConstField constify() {
283: if (constField == null) {
284: constField = new ConstMFVec2f(this );
285: }
286: return constField;
287: }
288:
289: /**
290: * Gets the size attribute of the MFVec2f object
291: *
292: *@return The size value
293: */
294: public int getSize() {
295: return vals.length / 2;
296: }
297:
298: /** Description of the Method */
299: public void clear() {
300: vals = new float[1];
301: route();
302: }
303:
304: /**
305: * Description of the Method
306: *
307: *@param index Description of the Parameter
308: */
309: public void delete(int index) {
310: int i;
311: float[] temp = new float[vals.length - 2];
312: for (i = 0; i < index * 2; i++) {
313: temp[i] = vals[i];
314: }
315: for (; i < temp.length; i++) {
316: temp[i] = vals[i + 2];
317: }
318: vals = temp;
319: route();
320: }
321:
322: /**
323: * Description of the Method
324: *
325: *@return Description of the Return Value
326: */
327: public vrml.Field wrap() {
328: return new vrml.field.MFVec2f(this);
329: }
330: }
|