Пример #1
0
  /** Gets the GUI component for this pane. */
  public JComponent getGUI() {
    if (cwp == null) {
      Object object = mWhiteBoard.get("device_definition");
      Object ctx_obj = mWhiteBoard.get("context");

      if (null != object
          && object instanceof ConfigDefinition
          && null != ctx_obj
          && ctx_obj instanceof ConfigContext) {
        mConfigContext = (ConfigContext) ctx_obj;

        ConfigDefinition def = (ConfigDefinition) object;
        String token = def.getToken();

        // Create a temporary list of ConfigDefinitions to pass to factory.
        java.util.List def_list = new ArrayList();
        def_list.add(def);

        // Initialize a ConfigElementFactory with the needed
        // ConfigDefinition. And create a new ConfigElement.
        ConfigElementFactory temp_factory = new ConfigElementFactory(def_list);
        mConfigElement = temp_factory.create("New " + token, def);

        List list = CustomEditorRegistry.findEditors(token);

        Color start_color = new Color(160, 160, 180);

        Object color = UIManager.get("window");
        if (null != color && color instanceof Color) {
          start_color = (Color) color;
        } else {
          System.out.println("Could not get the desktop color from the  UIManager.");
        }

        // XXX:This will be used after making findEditors -> findEditor
        // if(null != editor)
        if (null == list || list.size() == 0) {
          System.out.println("No CustomEditors registered for token: " + token);

          JScrollPane scroll_pane = new JScrollPane();
          PropertySheet element_prop_sheet =
              PropertySheetFactory.instance()
                  .makeSheet(mConfigContext, mConfigElement, start_color);

          scroll_pane.getViewport().removeAll();
          scroll_pane.getViewport().add(element_prop_sheet, null);
          cwp = scroll_pane;
        } else if (null != list && list.size() > 0) {
          CustomEditor editor = (CustomEditor) list.get(0);
          cwp = (JComponent) editor.getPanel();
          editor.setConfig(mConfigContext, mConfigElement);
        }
      }
    }
    // cwp.init(mWhiteBoard);
    return cwp;
  }
Пример #2
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();
  }
Пример #3
0
  /**
   * Gets a list of the nodes in this model that contain an object of the given class starting with
   * the given node.
   *
   * @param cls the class to search for
   * @param node the node whose subtree will be searched
   * @return a list of matching DefaultMutableTreeNodes
   */
  public List getNodesOfClass(Class cls, DefaultMutableTreeNode node) {
    List matches = new ArrayList();

    // Check if the current node matches
    if (cls.isInstance(node.getUserObject())) {
      matches.add(node);
    }

    // Recurse to the children of the current node
    for (Enumeration e = node.children(); e.hasMoreElements(); ) {
      DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement();
      matches.addAll(getNodesOfClass(cls, child));
    }

    return matches;
  }
Пример #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);
            }
          }
        }
      }
    }