Ejemplo n.º 1
0
  /**
   * Sets a property based on the index. According to C.6.13.1 if the index is greater than the
   * current number of nodes, expand the size by one and add the new value to the end.
   *
   * @param index The index of the property to set
   * @param start The object who's property is being set
   * @param value The value being requested
   */
  public void put(int index, Scriptable start, Object value) {

    if (readOnly && !scriptField) {
      Context.reportError(READONLY_MSG);
      return;
    }

    if (!(value instanceof SFVec2d)) {
      Context.reportError(OBJECT_NOT_VEC_MSG);
      return;
    }

    Scriptable node = (SFVec2d) value;
    if (node.getParentScope() == null) node.setParentScope(this);

    if (index >= valueList.size()) {
      int toAdd = index - valueList.size();

      valueList.ensureCapacity(index + 1);

      // Add default values
      for (int i = 0; i < toAdd; i++) {
        valueList.add(new SFVec2d());
      }

      valueList.add(value);
      sizeInt.setValue(valueList.size());
    } else if (index >= 0) {
      valueList.set(index, value);
    }

    dataChanged = true;
  }
Ejemplo n.º 2
0
  /** Get the value at the given index. */
  public Object get(int index, Scriptable start) {
    Object ret_val = NOT_FOUND;

    if ((index >= 0) && (index < valueList.size())) {
      ret_val = valueList.get(index);

      // could be null because the source data was an array. If so,
      // create the object and then put that into the arraylist.
      if (ret_val == null) {
        int idx = index * 2;
        workArray[0] = doubleData[idx++];
        workArray[1] = doubleData[idx];

        SFVec2d n = new SFVec2d(workArray);
        n.setParentScope(this);
        valueList.set(index, n);

        ret_val = n;
      }
    } else if (index >= 0) {
      // Not in the array but the spec says we must expand to meet this
      // new size and return a valid object
      for (int i = valueList.size(); i <= index; i++) {
        SFVec2d n = new SFVec2d();
        n.setParentScope(this);
        valueList.add(n);
      }
      sizeInt.setValue(valueList.size());

      ret_val = (SFVec2d) valueList.get(index);
    }
    return ret_val;
  }
Ejemplo n.º 3
0
  /**
   * Construct a field based on an array of SFVec2d objects.
   *
   * @param args the objects
   */
  public MFVec2d(Object[] args) {
    this();

    int cnt = 0;

    for (int i = 0; i < args.length; i++) {
      if (args[i] == jsUndefined) continue;

      if (!(args[i] instanceof SFVec2d)) throw new IllegalArgumentException("Non SFVec2d given");

      cnt++;
      valueList.add(args[i]);
    }

    sizeInt.setValue(cnt);
  }
Ejemplo n.º 4
0
  /** Construct a field based on a flattened array of data (sourced from a node). */
  public MFVec2d(double[] values, int numValid) {
    this();

    int elements = numValid / 2;

    if (numValid != 0) {
      doubleData = new double[numValid];
      System.arraycopy(values, 0, doubleData, 0, numValid);

      // back fill the list with empty data.
      valueList.ensureCapacity(elements);
      for (int i = 0; i < elements; i++) valueList.add(null);
    }

    sizeInt.setValue(elements);
  }
Ejemplo n.º 5
0
  /**
   * Update the node's raw data from the underlying model. If this wrapper has a local changed copy
   * of the data that has not yet been committed to the underlying model, this request is ignored
   * and the current data stays.
   *
   * @param values The list of values to update here
   * @param numValid The number of valid values to use from the array
   */
  public void updateRawData(double[] values, int numValid) {
    if (dataChanged) return;

    valueList.clear();

    int elements = numValid / 2;

    if (numValid != 0) {
      doubleData = new double[numValid];
      System.arraycopy(values, 0, doubleData, 0, numValid);

      // back fill the list with empty data.
      valueList.ensureCapacity(elements);
      for (int i = 0; i < elements; i++) valueList.add(null);
    }

    sizeInt.setValue(elements);
  }