Ejemplo n.º 1
0
    /**
     * This gets called whenever one of the ConfigElements we are editing removes a property value.
     */
    public void propertyValueRemoved(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)) {
          // The newly removed property value must be a child to this node
          System.out.println("Removing child " + idx + " from node: " + node.getUserObject());
          DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(idx);

          // If the child is an embedded element, stop listening to it
          if (child.getUserObject() instanceof ConfigElement) {
            ConfigElement removed_elt = (ConfigElement) child.getUserObject();
            removed_elt.removeConfigElementListener(this);
          }

          // Physically remove the child from the tree
          removeNodeFromParent(child);
        }
      }
    }
Ejemplo n.º 2
0
 public void propertyValueAdded(ConfigElementEvent event) {
   if (event.getProperty().equals("simulator_viewports")
       || event.getProperty().equals("surface_viewports")) {
     mViewports.add(0, event.getValue());
     fireItemsInserted(new int[] {0});
   }
 }
Ejemplo n.º 3
0
    /**
     * This gets called whenever one of the ConfigElements we are editing adds a new property value.
     */
    public void propertyValueAdded(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)) {
          // The newly inserted property value must be added as a child to
          // this node
          if (prop_def.getType() != ConfigElement.class) {
            DefaultMutableTreeNode new_child = new DefaultMutableTreeNode(evt.getValue());
            insertNodeInto(new_child, node, idx);
          } 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.
            addEmbeddedElement(node, (ConfigElement) evt.getValue(), idx);
          }
        }
      }
    }
Ejemplo n.º 4
0
 public void propertyValueRemoved(ConfigElementEvent event) {
   if (event.getProperty().equals("simulator_viewports")
       || event.getProperty().equals("surface_viewports")) {
     int idx = getIndexOf(event.getValue());
     if (idx != -1) {
       mViewports.remove(idx);
       fireItemsRemoved(new int[] {idx}, new Object[] {event.getValue()});
     }
   }
 }
Ejemplo n.º 5
0
 /** This gets called whenever one of the ConfigElements we are modeling has changed its name. */
 public void nameChanged(ConfigElementEvent evt) {
   ConfigElement src = (ConfigElement) evt.getSource();
   DefaultMutableTreeNode root = (DefaultMutableTreeNode) getRoot();
   DefaultMutableTreeNode name_node = (DefaultMutableTreeNode) root.getChildAt(0);
   name_node.setUserObject(src.getName());
   fireTreeNodesChanged(
       this, new Object[] {getPathToRoot(root)}, new int[] {0}, new Object[] {name_node});
 }
Ejemplo n.º 6
0
    /**
     * This gets called whenever one of the ConfigElements we are editing has one of its property
     * values change.
     */
    public void propertyValueChanged(ConfigElementEvent evt) {
      ConfigElement src = (ConfigElement) evt.getSource();
      int idx = evt.getIndex();
      PropertyDefinition prop_def = src.getDefinition().getPropertyDefinition(evt.getProperty());
      DefaultMutableTreeNode elt_node = getNodeFor(src);

      // Multi-valued properties and embedded elements are treated specially
      if ((prop_def.getPropertyValueDefinitionCount() > 1)
          || (prop_def.isVariable())
          || (prop_def.getType() == ConfigElement.class)) {
        // Look for the property definition node
        for (Enumeration e = elt_node.children(); e.hasMoreElements(); ) {
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
          if (node.getUserObject().equals(prop_def)) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(idx);
            fireTreeNodesChanged(
                this,
                new Object[] {getPathToRoot(node)},
                new int[] {node.getIndex(child)},
                new Object[] {child});
          }
        }
      }
      // Property value is not an embedded element
      else {
        // Take into account the extra two rows at the top of the table
        if (elt_node == getRoot()) {
          idx += 2;
        }

        fireTreeNodesChanged(
            this,
            new Object[] {getPathToRoot(elt_node)},
            new int[] {idx},
            new Object[] {elt_node.getChildAt(idx)});
      }
    }
Ejemplo n.º 7
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.º 8
0
 /** Called whenever one of the displays contained within the model changes. */
 public void nameChanged(ConfigElementEvent evt) {
   int idx = getIndexOf(evt.getSource());
   if (idx != -1) {
     fireItemsChanged(new int[] {idx});
   }
 }