public Point getLocationOf(int idx) {
    ConfigElement vp_elt = (ConfigElement) getElement(idx);
    double x = ((Number) vp_elt.getProperty("origin", 0)).doubleValue() * mDesktopSize.getWidth();
    double y = ((Number) vp_elt.getProperty("origin", 1)).doubleValue() * mDesktopSize.getHeight();

    // Convert y from Juggler coords (bottom left is origin)
    double height =
        ((Number) vp_elt.getProperty("size", 1)).doubleValue() * mDesktopSize.getHeight();
    y = mDesktopSize.getHeight() - y - height;
    return new Point((int) x, (int) y);
  }
Beispiel #2
0
    /**
     * This gets called whenever one of the ConfigElements we are editing has the values of a
     * property get reordered.
     */
    public void propertyValueOrderChanged(ConfigElementEvent evt) {
      ConfigElement src = (ConfigElement) evt.getSource();
      int idx = evt.getIndex();
      PropertyDefinition prop_def = src.getDefinition().getPropertyDefinition(evt.getProperty());
      DefaultMutableTreeNode elt_node = getNodeFor(src);

      // Get the node containing the property description under the source
      // ConfigElement node.
      for (Enumeration e = elt_node.children(); e.hasMoreElements(); ) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();

        if (node.getUserObject().equals(prop_def)) {
          int start_index = Math.min(evt.getIndex0(), evt.getIndex1());
          int end_index = Math.max(evt.getIndex0(), evt.getIndex1());

          List removed_children = new ArrayList();
          for (int c = start_index; c <= end_index; ++c) {
            removed_children.add(getChild(node, c));
          }

          for (Iterator c = removed_children.iterator(); c.hasNext(); ) {
            removeNodeFromParent((MutableTreeNode) c.next());
          }

          String prop_token = prop_def.getToken();
          for (int v = start_index; v <= end_index; ++v) {
            if (prop_def.getType() != ConfigElement.class) {
              // Create a new node for the reordered property value.
              DefaultMutableTreeNode new_node =
                  new DefaultMutableTreeNode(src.getProperty(prop_token, v));

              // Add the new node into the tree.
              insertNodeInto(new_node, node, v);
            } else {
              // Embedded elements are handled specially in that all of
              // their respective child properties and such also need to
              // be added to the tree at this time.
              ConfigElement cur_value = (ConfigElement) src.getProperty(prop_token, v);
              addEmbeddedElement(node, cur_value, v);
            }
          }
        }
      }
    }
  public Dimension getSizeOf(int idx) {
    ConfigElement vp_elt = (ConfigElement) getElement(idx);

    double vp_width = ((Number) vp_elt.getProperty("size", 0)).doubleValue();
    double vp_height = ((Number) vp_elt.getProperty("size", 1)).doubleValue();

    if (vp_width > 1.0) {
      vp_width = 1.0;
    }

    if (vp_height > 1.0) {
      vp_height = 1.0;
    }

    double width = vp_width * mDesktopSize.getWidth();
    double height = vp_height * mDesktopSize.getHeight();

    return new Dimension((int) width, (int) height);
  }
Beispiel #4
0
  /**
   * Adds the nodes necessary to display the property values for the given configuration element
   * described by the given property definition.
   */
  private void addProperty(ConfigElement elt, PropertyDefinition propDef) {
    DefaultMutableTreeNode parent = getNodeFor(elt);

    // This property has only one value, add it in
    if ((propDef.getPropertyValueDefinitionCount() == 1)
        && (!propDef.isVariable())
        && (propDef.getType() != ConfigElement.class)) {
      int idx = parent.getChildCount();
      //         System.out.println("Adding property node for single-valued property: "+
      //                            propDesc.getToken()+"["+idx+"]");
      Object value = elt.getProperty(propDef.getToken(), 0);
      DefaultMutableTreeNode value_node = new DefaultMutableTreeNode(value);
      insertNodeInto(value_node, parent, idx);
    }
    // This property has (or can have) more than one value, add a node that is
    // the parent for all its values.
    else {
      int idx = parent.getChildCount();
      //         System.out.println("Adding property node for multi-valued property: "+
      //                            propDesc.getToken()+"["+idx+"]");
      DefaultMutableTreeNode prop_def_node = new DefaultMutableTreeNode(propDef);
      insertNodeInto(prop_def_node, parent, idx);
      parent = prop_def_node;

      int num_props = elt.getPropertyValueCount(propDef.getToken());
      for (int i = 0; i < num_props; ++i) {
        Object value = elt.getProperty(propDef.getToken(), i);
        if (propDef.getType() != ConfigElement.class) {
          //               System.out.println("Adding property value:
          // "+propDesc.getToken()+"["+i+"]");
          DefaultMutableTreeNode child = new DefaultMutableTreeNode(value);
          int prop_idx = parent.getChildCount();
          insertNodeInto(child, parent, prop_idx);
        } else {
          addEmbeddedElement(parent, (ConfigElement) value, i);
        }
      }
    }
  }
  public void setLocationOf(int idx, Point pt) {
    ConfigElement vp_elt = (ConfigElement) getElement(idx);

    // Convert y to Juggler coords (bottom left is origin)
    double height =
        ((Number) vp_elt.getProperty("size", 1)).doubleValue() * mDesktopSize.getHeight();
    double y = mDesktopSize.height - pt.y - height;

    double vp_origin_x = (double) pt.x / mDesktopSize.getWidth();
    double vp_origin_y = y / mDesktopSize.getHeight();

    if (vp_origin_x < 0.0) {
      vp_origin_x = 0.0;
    }

    if (vp_origin_y < 0.0) {
      vp_origin_y = 0.0;
    }

    vp_elt.setProperty("origin", 0, new Double(vp_origin_x), mContext);
    vp_elt.setProperty("origin", 1, new Double(vp_origin_y), mContext);
  }