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