FreeWRL/FreeX3D  3.0.0
FWMFRotation.java
1 package sai;
2 import org.web3d.x3d.sai.*;
3 import java.util.*;
4 
5 public class FWMFRotation extends FreeWRLMField implements MFRotation {
6  FreeWRLBrowser browser;
7  static final int ROWS = 4;
8 
10  super(def, b);
11  browser = b;
12  }
13 
14  public void getValue(float[][] value) throws ArrayIndexOutOfBoundsException {
15  int lines;
16  int count1;
17  int count2;
18  StringTokenizer tokens;
19  String rep;
20 
21  if (RLreturn == null) {
22  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
23  } else {
24  rep = RLreturn;
25  }
26 
27  tokens = new StringTokenizer(rep);
28 
29  lines = Integer.valueOf(tokens.nextToken()).intValue();
30 
31  if (value.length < lines) {
32  throw new ArrayIndexOutOfBoundsException("MFRotation getValue passed array of insufficient size");
33  }
34 
35  for (count1 = 0; count1 < lines; count1++) {
36  for (count2=0; count2<ROWS; count2++) {
37  value[count1][count2] = Float.valueOf(tokens.nextToken()).floatValue();
38  }
39  }
40  }
41 
42  public void getValue(float[] value) throws ArrayIndexOutOfBoundsException {
43  int lines;
44  int count1;
45  StringTokenizer tokens;
46  String rep;
47 
48  if (RLreturn == null) {
49  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
50  } else {
51  rep = RLreturn;
52  }
53 
54  tokens = new StringTokenizer(rep);
55 
56  lines = Integer.valueOf(tokens.nextToken()).intValue();
57 
58  if (value.length < (lines*ROWS)) {
59  throw new ArrayIndexOutOfBoundsException("MFRotation getValue passed array of insufficient size");
60  }
61 
62  for (count1 = 0; count1 < (lines*ROWS); count1++) {
63  value[count1] = Float.valueOf(tokens.nextToken()).floatValue();
64  }
65  }
66 
67  public void get1Value(int index, float[] value) {
68  int lines;
69  float [][] tval;
70  int count1;
71  int count2;
72  StringTokenizer tokens;
73  String rep;
74 
75  if (RLreturn == null) {
76  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
77  } else {
78  rep = RLreturn;
79  }
80 
81  tokens = new StringTokenizer(rep);
82 
83  lines = Integer.valueOf(tokens.nextToken()).intValue();
84 
85  if (value.length < ROWS) {
86  throw new ArrayIndexOutOfBoundsException("MFRotation get1Value passed array of insufficient size");
87  }
88  if (index > lines) {
89  throw new ArrayIndexOutOfBoundsException("MFRotation get1Value passed index out of bounds");
90  }
91 
92  tval = new float[lines][ROWS];
93 
94  for (count1 = 0; count1 < lines; count1++) {
95  for (count2=0; count2<ROWS; count2++) {
96  tval[count1][count2] = Float.valueOf(tokens.nextToken()).floatValue();
97  }
98  }
99 
100  for (count1 = 0; count1 < ROWS; count1++) {
101  value[count1] = tval[index][count1];
102  }
103  }
104 
105  public void setValue(int numRotations, float[] value) throws ArrayIndexOutOfBoundsException {
106  int count;
107  String val;
108 
109  if (numRotations > (value.length % ROWS)) {
110  numRotations = (value.length % ROWS);
111  }
112 
113  if ((numRotations*ROWS) != (value.length)) {
114  throw new ArrayIndexOutOfBoundsException("MFRotation setValue passed degenrate rotation value");
115  }
116 
117  val = " " + numRotations;
118 
119  for (count = 0; count < (numRotations * ROWS); count++) {
120  val = val + " " + value[count];
121  }
122 
123  browser.newSendEvent(this, val);
124  }
125 
126  public void setValue(int numRotations, float[][] value) throws ArrayIndexOutOfBoundsException {
127  int count;
128  String val;
129 
130  if (numRotations > value.length) {
131  numRotations = value.length;
132  }
133 
134  val = " " + numRotations;
135  for (count = 0; count < numRotations; count++) {
136  if (value[count].length < ROWS) {
137  throw new ArrayIndexOutOfBoundsException("MFRotation setValue passed degenerate rotation value");
138  }
139  val = val + " " + value[count][0] + " " + value[count][1] + " " + value[count][2] + " " + value[count][3];
140  }
141  browser.newSendEvent(this, val);
142  }
143  public void set1Value(int index, float[] value) {
144  browser.newSendEvent(this, " ONEVAL " + index + " " + value[0] + " " + value[1] + " " + value[2] + " " + value[3]);
145  }
146 
147  public void append(float[] value) {
148  int lines;
149  int append_size;
150  int count1, count2;
151  StringTokenizer tokens;
152  String rep;
153  String val;
154 
155  if (RLreturn == null) {
156  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
157  } else {
158  rep = RLreturn;
159  }
160 
161  tokens = new StringTokenizer(rep);
162  lines = Integer.valueOf(tokens.nextToken()).intValue();
163 
164  append_size = value.length;
165 
166  if ((append_size % ROWS)!= 0) {
167  throw new ArrayIndexOutOfBoundsException("Rotation value array contains insufficient number of colors");
168  }
169 
170  val = " " + (lines + (append_size/ROWS));
171 
172  for (count1 = 0; count1 < (lines*ROWS); count1++) {
173  val = val + tokens.nextToken();
174  }
175 
176  for (count1 = 0; count1 < append_size; count1++) {
177  val = val + " " + value[count1];
178  }
179 
180  browser.newSendEvent(this, val);
181  }
182  public void insertValue(int index, float[] value) {
183  int lines;
184  int insert_size;
185  int count1, count2;
186  StringTokenizer tokens;
187  String rep;
188  String val;
189 
190  if (RLreturn == null) {
191  rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
192  } else {
193  rep = RLreturn;
194  }
195 
196  tokens = new StringTokenizer(rep);
197  lines = Integer.valueOf(tokens.nextToken()).intValue();
198 
199  insert_size = value.length;
200 
201  if ((insert_size % ROWS) != 0) {
202  throw new ArrayIndexOutOfBoundsException("Rotation value array contains insufficient number of colors");
203  }
204 
205  if ((index > (lines/ROWS)) || (index < 0)) {
206  throw new ArrayIndexOutOfBoundsException("MFRotation insertValue passed index out of bounds");
207  }
208 
209  val = " " + (lines + (insert_size/ROWS));
210 
211  for (count1 = 0; count1 < (index*ROWS); count1++) {
212  val = val + tokens.nextToken();
213  }
214 
215  for (count1 = 0; count1 < insert_size; count1++) {
216  val = val + " " + value[count1];
217  }
218 
219  for (count1 = (index*ROWS); count1 < (lines*ROWS); count1++) {
220  val = val + tokens.nextToken();
221  }
222 
223  browser.newSendEvent(this, val);
224  }
225 }