Ejemplo n.º 1
0
  /** Clears the data in the model. */
  private void clear() {
    // Stop listening to all config elements in the tree
    List nodes = getNodesOfClass(ConfigElement.class);
    for (Iterator itr = nodes.iterator(); itr.hasNext(); ) {
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) itr.next();
      ConfigElement elt = (ConfigElement) node.getUserObject();
      elt.removeConfigElementListener(mElementListener);
    }

    // Clear out all the old nodes from the tree.
    ((DefaultMutableTreeNode) getRoot()).removeAllChildren();
  }
Ejemplo n.º 2
0
  /**
   * Adds a new embedded configuration element to the given parent node at the given index relative
   * to the parent node.
   */
  private void addEmbeddedElement(DefaultMutableTreeNode parent, ConfigElement elt, int index) {
    elt.addConfigElementListener(mElementListener);
    //      System.out.println("Adding embedded element node for element: "+
    //                         elt.getName()+"["+index+"]");
    DefaultMutableTreeNode elt_node = new DefaultMutableTreeNode(elt);
    insertNodeInto(elt_node, parent, index);

    //      System.out.println("Adding in properties ...");
    for (Iterator itr = elt.getDefinition().getPropertyDefinitions().iterator(); itr.hasNext(); ) {
      PropertyDefinition prop_def = (PropertyDefinition) itr.next();
      addProperty(elt, prop_def);
    }
  }
Ejemplo n.º 3
0
  public ViewportPlacerModel(Dimension desktopSize, ConfigContext ctx, ConfigElement elt) {
    mDesktopSize = desktopSize;
    mContext = ctx;
    mDisplayElement = elt;
    mDisplayElement.addConfigElementListener(mChangeListener);

    Iterator i;
    for (i = elt.getPropertyValues("simulator_viewports").iterator(); i.hasNext(); ) {
      mViewports.add(i.next());
    }

    for (i = elt.getPropertyValues("surface_viewports").iterator(); i.hasNext(); ) {
      mViewports.add(i.next());
    }
  }
Ejemplo n.º 4
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);
            }
          }
        }
      }
    }
Ejemplo n.º 5
0
  /** Sets the configuration element this table model represents. */
  public void setElement(ConfigElement elt) {
    // Clear out all the old nodes from the tree.
    clear();

    mElement = elt;
    mElement.addConfigElementListener(mElementListener);
    setRoot(new DefaultMutableTreeNode(mElement));

    // First node is name
    DefaultMutableTreeNode name_node = new DefaultMutableTreeNode(mElement.getName());
    insertNodeInto(name_node, (MutableTreeNode) getRoot(), 0);

    // Second node is type
    DefaultMutableTreeNode type_node =
        new DefaultMutableTreeNode(mElement.getDefinition().getName());
    insertNodeInto(type_node, (MutableTreeNode) getRoot(), 1);

    // Remaining nodes are the properties
    for (Iterator itr = mElement.getDefinition().getPropertyDefinitions().iterator();
        itr.hasNext(); ) {
      PropertyDefinition prop_def = (PropertyDefinition) itr.next();
      addProperty(mElement, prop_def);
    }
  }