FreeWRL / FreeX3D 4.3.0
FWSFColor.java
1package sai;
2import org.web3d.x3d.sai.*;
3import java.util.*;
4
5public class FWSFColor extends FreeWRLField implements SFColor {
6 FreeWRLBrowser browser;
7 private static int ROWS = 3;
8
10 super(def, b);
11 browser = b;
12 }
13
14 public void getValue(float[] value) throws ArrayIndexOutOfBoundsException {
15 int count;
16 String rep;
17 StringTokenizer tokens;
18
19 if (value.length < ROWS) {
20 throw new ArrayIndexOutOfBoundsException("SFColor getValue passed array of insufficient length");
21 }
22
23 if (command != null) {
24 rep = browser.SendEventOut(nodePtr, offset, datasize, dataType, command);
25 tokens = new StringTokenizer(rep);
26 } else {
27 tokens = new StringTokenizer(RLreturn);
28 }
29
30 for (count = 0; count < ROWS; count++) {
31 value[count] = Float.valueOf(tokens.nextToken()).floatValue();
32 }
33 }
34
35 public void setValue(float[] value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
36 int count;
37 if (value.length < ROWS) {
38 throw new ArrayIndexOutOfBoundsException("SFColor setValue passed degenerate colour value");
39 }
40 for (count = 0; count < ROWS; count++) {
41 if ((value[count] < 0) || (value[count] > 1)) {
42 throw new IllegalArgumentException("SFColor setValue passed invalid colour value");
43 }
44 }
45 browser.newSendEvent(this, "" + value[0] + " " + value[1] + " " + value[2]);
46 }
47}