예제 #1
0
    /** {@inheritDoc} */
    @Override
    public Component getTreeCellEditorComponent(
        JTree aTree,
        Object aValue,
        boolean aIsSelected,
        boolean aExpanded,
        boolean aLeaf,
        int aRow) {
      ElementTreeNode treeNode = (ElementTreeNode) aValue;

      return super.getTreeCellEditorComponent(
          aTree, treeNode.getText(), aIsSelected, aExpanded, aLeaf, aRow);
    }
예제 #2
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;
  }
예제 #3
0
  /** Removes the current selected group. */
  final void removeSelectedGroup() {
    TreePath[] selectionPaths = this.tree.getSelectionPaths();
    if (selectionPaths == null) {
      return;
    }

    DefaultTreeModel model = (DefaultTreeModel) this.tree.getModel();
    ElementTreeNode rootNode = (ElementTreeNode) model.getRoot();

    for (TreePath selectionPath : selectionPaths) {
      ElementTreeNode treeNode = (ElementTreeNode) selectionPath.getLastPathComponent();
      if (treeNode.getUserObject() instanceof ElementGroup) {
        ElementGroup elementGroup = (ElementGroup) treeNode.getUserObject();

        this.model.removeGroup(elementGroup);

        model.nodesWereRemoved(
            rootNode, new int[] {rootNode.getIndex(treeNode)}, new Object[] {treeNode});
      }
    }
  }
예제 #4
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);
  }
예제 #5
0
 /** Creates a new {@link ElementTreeNode} instance as copy of the given node. */
 public ElementTreeNode(final ElementTreeNode aNode) {
   super(aNode.getUserObject());
   setAllowsChildren(aNode.allowsChildren);
 }