コード例 #1
0
  /**
   * Set the currently selected Variable.
   *
   * @param v select this Variable, must be already in the tree.
   */
  public void setSelected(VariableIF v) {
    if (v == null) return;

    // construct chain of variables
    List<VariableIF> vchain = new ArrayList<>();
    vchain.add(v);

    VariableIF vp = v;
    while (vp.isMemberOfStructure()) {
      vp = vp.getParentStructure();
      vchain.add(0, vp); // reverse
    }

    // construct chain of groups
    List<Group> gchain = new ArrayList<>();
    Group gp = vp.getParentGroup();

    gchain.add(gp);
    while (gp.getParentGroup() != null) {
      gp = gp.getParentGroup();
      gchain.add(0, gp); // reverse
    }

    List<Object> pathList = new ArrayList<>();

    // start at root, work down through the nested groups, if any
    GroupNode gnode = (GroupNode) model.getRoot();
    pathList.add(gnode);
    Group parentGroup = gchain.get(0); // always the root group

    for (int i = 1; i < gchain.size(); i++) {
      parentGroup = gchain.get(i);
      gnode = gnode.findNestedGroup(parentGroup);
      assert gnode != null;
      pathList.add(gnode);
    }

    vp = vchain.get(0);
    VariableNode vnode = gnode.findNestedVariable(vp);
    if (vnode == null) return; // not found
    pathList.add(vnode);

    // now work down through the structure members, if any
    for (int i = 1; i < vchain.size(); i++) {
      vp = vchain.get(i);
      vnode = vnode.findNestedVariable(vp);
      if (vnode == null) return; // not found
      pathList.add(vnode);
    }

    // convert to TreePath, and select it
    Object[] paths = pathList.toArray();
    TreePath treePath = new TreePath(paths);
    tree.setSelectionPath(treePath);
    tree.scrollPathToVisible(treePath);
  }
コード例 #2
0
    void makeChildren() {
      children = new ArrayList<>();

      if (var instanceof Structure) {
        Structure s = (Structure) var;
        List vars = s.getVariables();
        for (int i = 0; i < vars.size(); i++)
          children.add(new VariableNode(this, (VariableIF) vars.get(i)));
      }

      if (debugTree) System.out.println("children=" + var.getShortName() + " ");
    }
コード例 #3
0
 public String getToolTipText() {
   return var.toString();
 }
コード例 #4
0
 public String toString() {
   return var.getShortName();
 }
コード例 #5
0
 public int getIndex(TreeNode child) {
   if (debugTree) System.out.println("getIndex=" + var.getShortName() + " " + child);
   return children.indexOf(child);
 }
コード例 #6
0
 VariableNode(TreeNode parent, VariableIF var) {
   this.parent = parent;
   this.var = var;
   if (debugTree) System.out.println("new var=" + var.getShortName() + " ");
   // firePropertyChangeEvent(new PropertyChangeEvent(this, "TreeNode", null, var));
 }