FreeWRL / FreeX3D 4.3.0
FreeWRLMField.java
1package sai;
2import org.web3d.x3d.sai.*;
3import java.util.*;
4
5public class FreeWRLMField extends FreeWRLField implements MField {
6 FreeWRLBrowser browser;
8 super(def, b);
9 browser = b;
10 }
11 public int size() throws InvalidFieldException, ConnectionException {
12 int lines;
13 StringTokenizer tokens;
14 String rep;
15
16 checkValid();
17 if (RLreturn == null) {
18 rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
19 } else {
20 rep = RLreturn;
21 }
22
23 tokens = new StringTokenizer(rep);
24 if (dataType.equals("q")) {
25 lines = tokens.countTokens();;
26 } else {
27 lines = Integer.valueOf(tokens.nextToken()).intValue();
28 }
29 return lines;
30 }
31 public void clear() throws InvalidFieldException, ConnectionException {
32 String val;
33 checkValid();
34 val = " 0";
35 browser.newSendEvent(this, val);
36 }
37 public void remove(int index) throws InvalidFieldException, ConnectionException, ArrayIndexOutOfBoundsException {
38 int lines;
39 int count1, count2;
40 int size;
41 StringTokenizer tokens;
42 String rep;
43 String val;
44
45 checkValid();
46
47 if (RLreturn == null) {
48 rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
49 } else {
50 rep = RLreturn;
51 }
52
53 System.out.println("got rep: " + rep);
54
55 tokens = new StringTokenizer(rep);
56 if (this instanceof MFNode) {
57 lines = tokens.countTokens();
58 } else {
59 lines = Integer.valueOf(tokens.nextToken()).intValue();
60 }
61
62 if ((index > lines) || (index < 0)) {
63 throw new ArrayIndexOutOfBoundsException("MFField remove passed index out of bounds");
64 }
65
66 lines--;
67
68 val = " " + lines;
69
70 if (this instanceof MFNode) {
71 clear();
72 size = tokens.countTokens();
73
74 for (count1 = 0; count1 < lines; count1++) {
75 for (count2 = 0; count2 < size; count2++) {
76 if (count1 != index) {
77 browser.SendChildEvent(nodePtr, offset, command,tokens.nextToken());
78 } else {
79 tokens.nextToken();
80 }
81 }
82 }
83 } else {
84
85 size = tokens.countTokens() / lines;
86 for (count1 = 0; count1 < lines; count1++) {
87 for (count2 = 0; count2 < size; count2++) {
88 if (count1 != index) {
89 val = val + tokens.nextToken();
90 } else {
91 tokens.nextToken();
92 }
93 }
94 }
95 browser.newSendEvent(this, val);
96 }
97 }
98}