Пример #1
0
  /** @return a tree structure based on the initial element model. */
  private DefaultMutableTreeNode createTree() {
    ElementTreeNode rootNode = new ElementTreeNode();

    for (ElementGroup group : this.model.getGroups()) {
      ElementTreeNode groupNode = new ElementTreeNode(group);
      rootNode.add(groupNode);

      for (SignalElement element : group.getElements()) {
        groupNode.add(new ElementTreeNode(element));
      }
    }

    return rootNode;
  }
Пример #2
0
  /** Adds a new group to our tree and element model. */
  final void addNewGroup() {
    DefaultTreeModel model = (DefaultTreeModel) this.tree.getModel();

    boolean groupSummaryVisibleByDefault = UIManager.getBoolean(GROUP_SUMMARY_VISIBLE_DEFAULT);
    boolean scopeVisibleByDefault = UIManager.getBoolean(ANALOG_SCOPE_VISIBLE_DEFAULT);

    int groupCount = this.model.getGroups().size();
    String name = String.format("Group %d", Integer.valueOf(groupCount + 1));

    // Create model structure...
    ElementGroup newGroup = this.model.addGroup(name);
    newGroup.setVisible(true);

    SignalElement groupSummaryElement = SignalElement.createGroupSummaryElement(newGroup);
    groupSummaryElement.setEnabled(groupSummaryVisibleByDefault);
    newGroup.addElement(groupSummaryElement);

    SignalElement analogScopeElement = SignalElement.createAnalogScopeElement(newGroup);
    analogScopeElement.setEnabled(scopeVisibleByDefault);
    newGroup.addElement(analogScopeElement);

    // Create tree structure...
    ElementTreeNode rootNode = (ElementTreeNode) model.getRoot();

    ElementTreeNode groupNode = new ElementTreeNode(newGroup);
    rootNode.add(groupNode);

    groupNode.add(new ElementTreeNode(groupSummaryElement));
    groupNode.add(new ElementTreeNode(analogScopeElement));

    int index = rootNode.getIndex(groupNode);

    model.nodesWereInserted(rootNode, new int[] {index});
    model.nodeStructureChanged(groupNode);

    this.tree.expandRow(index);
  }