FreeWRL/FreeX3D  3.0.0
FWMFString.java
1 package sai;
2 import org.web3d.x3d.sai.*;
3 import java.util.*;
4 
5 public class FWMFString extends FreeWRLMField implements MFString {
6  FreeWRLBrowser browser;
7 
9  super(def, b);
10  browser = b;
11  }
12 
13  public void getValue(String[] value) throws ArrayIndexOutOfBoundsException {
14  String rep;
15  StringTokenizer tokens;
16  int count;
17 
18  if (command != null) {
19  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
20  tokens = new StringTokenizer(rep, "\"");
21  } else {
22  tokens = new StringTokenizer(RLreturn, "\"");
23  }
24 
25  rep = "";
26 
27  if (value.length < (tokens.countTokens()/2)) {
28  throw new ArrayIndexOutOfBoundsException("MFString getValue passed array of insufficient size");
29  }
30 
31  count = 0;
32 
33  while(tokens.hasMoreTokens()) {
34  value[count] = tokens.nextToken();
35  if (value[count].equals("XyZZtitndi")) {
36  value[count] = "";
37  }
38  if (tokens.hasMoreTokens()) rep = tokens.nextToken();
39  count++;
40  }
41  }
42 
43  public String get1Value(int index) throws ArrayIndexOutOfBoundsException {
44  String rep;
45  String[] tstr;
46  StringTokenizer tokens;
47  int count;
48 
49  if (command != null) {
50  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
51  tokens = new StringTokenizer(rep, "\"");
52  } else {
53  tokens = new StringTokenizer(RLreturn, "\"");
54  }
55 
56  rep = "";
57 
58  if (index > (tokens.countTokens()/2)) {
59  throw new ArrayIndexOutOfBoundsException("MFString getValue passed index out of bounds");
60  }
61 
62  count = 0;
63 
64  tstr = new String[(tokens.countTokens()/2)];
65 
66  while(tokens.hasMoreTokens()) {
67  tstr[count] = tokens.nextToken();
68  if (tstr[count].equals("XyZZtitndi")) {
69  tstr[count] = "";
70  }
71  if (tokens.hasMoreTokens()) rep = tokens.nextToken();
72  count++;
73  }
74  return tstr[index];
75  }
76 
77  public void setValue(int numStrings, String[] value) {
78  int count;
79  String sestr;
80 
81  if (value.length < numStrings) {
82  numStrings = value.length;
83  }
84 
85  sestr = ""+numStrings+" ";
86  for (count = 0; count < numStrings; count++) {
87  sestr = sestr + " " + count + ";" + value[count].length() + ":"+value[count] + " ";
88  }
89  browser.newSendEvent(this, sestr);
90  }
91 
92  public void set1Value(int index, String value) {
93  browser.newSendEvent(this, ""+index+1+" "+index+";"+value.length()+":"+value+" ");
94  }
95 
96  public void append(String[] value) {
97  String rep;
98  StringTokenizer tokens;
99  String sestr;
100  int count;
101  int numStrings;
102  int numRx;
103  int index;
104  String tstr;
105  String skip;
106 
107  if (command != null) {
108  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
109  tokens = new StringTokenizer(rep, "\"");
110  } else {
111  tokens = new StringTokenizer(RLreturn, "\"");
112  }
113 
114  numRx = tokens.countTokens()/2;
115  numStrings = value.length;
116 
117  sestr = ""+(numStrings+numRx)+" ";
118 
119  index = 0;
120 
121  while(tokens.hasMoreTokens()) {
122  tstr = tokens.nextToken();
123  if (tstr.equals("XyZZtitndi")) {
124  break;
125  }
126  sestr = sestr + " " + index+ ";" + tstr.length() + ":"+tstr + " ";
127  index++;
128  if (tokens.hasMoreTokens()) {
129  skip = tokens.nextToken();
130  }
131  }
132 
133  for (count = 0; count < value.length; count++) {
134  sestr = sestr + " " + (count+index) + ";" + value[count].length() + ":"+value[count] + " ";
135  }
136  browser.newSendEvent(this, sestr);
137 
138  }
139 
140  public void insertValue(int index, String[] value) {
141  String rep;
142  StringTokenizer tokens;
143  String sestr;
144  int count;
145  int numInsert;
146  int numRx;
147  int numTotal;
148  String tstr;
149  String skip;
150 
151  if (command != null) {
152  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
153  tokens = new StringTokenizer(rep, "\"");
154  } else {
155  tokens = new StringTokenizer(RLreturn, "\"");
156  }
157 
158  numRx = tokens.countTokens()/2;
159  numInsert = value.length;
160  numTotal = numInsert + numRx;
161 
162  sestr = ""+numTotal+" ";
163 
164  count = 0;
165 
166  while((tokens.hasMoreTokens() && (count < index))) {
167  tstr = tokens.nextToken();
168  if (tstr.equals("XyZZtitndi")) {
169  break;
170  }
171  sestr = sestr + " " + count + ";" + tstr.length() + ":"+tstr + " ";
172  count++;
173  if (tokens.hasMoreTokens()) {
174  skip = tokens.nextToken();
175  }
176  }
177 
178  for (int i = 0; i < numInsert; i++) {
179  sestr = sestr + " " + count + ";" + value[i].length() + ":" + value[i] + " ";
180  count++;
181  }
182 
183  while((tokens.hasMoreTokens() && (count < numTotal))) {
184  tstr = tokens.nextToken();
185  if (tstr.equals("XyZZtitndi")) {
186  break;
187  }
188  sestr = sestr + " " + count + ";" + tstr.length() + ":"+tstr + " ";
189  count++;
190  if (tokens.hasMoreTokens()) {
191  skip = tokens.nextToken();
192  }
193  }
194 
195  browser.newSendEvent(this, sestr);
196 
197  }
198 }