예제 #1
0
    public Component getTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean selected,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {

      Component c =
          super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

      if (value instanceof VariableNode) {
        VariableNode node = (VariableNode) value;
        tooltipText = node.getToolTipText();

        if (node.var instanceof Structure) {
          Structure s = (Structure) node.var;
          setIcon(structIcon);
          tooltipText = s.getNameAndAttributes();
        } else tooltipText = node.getToolTipText();
      } else if (value instanceof DimensionNode) {
        DimensionNode node = (DimensionNode) value;
        tooltipText = node.getToolTipText();
        setIcon(dimIcon);
      } else if (value instanceof GroupNode) {
        GroupNode node = (GroupNode) value;
        tooltipText = node.getToolTipText();
      }

      return c;
    }
예제 #2
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);
  }
예제 #3
0
  public boolean haveGroup(@NotNull String group) {
    Enumeration<GroupNode> e = children();
    @Nullable GroupNode cn = null;
    while (e.hasMoreElements() && cn == null) {
      GroupNode element = e.nextElement();
      if (element.getName().equals(group)) cn = element;
    }

    return cn != null;
  }
예제 #4
0
  public ComplexBirdNode(double scale, double speed) {
    super();
    this.speed = speed;
    ScaleNode scaleNode = new ScaleNode(new Vector3(scale, scale, scale));
    addChild(scaleNode);

    double widthTrunk = 0.025;
    double heigthTrunk = 0.05;
    double depthTrunk = 0.015;

    // Body
    Vector3 blackish = new Vector3(0.0123, 0.0123, 0.0123);
    ColorNode colorNodeBody = new ColorNode(blackish);
    scaleNode.addChild(colorNodeBody);

    TranslationNode translationNodeBody = new TranslationNode(new Vector3(0, 0, 0.2));
    colorNodeBody.addChild(translationNodeBody);

    body = new CuboidNode(widthTrunk, heigthTrunk, depthTrunk);
    translationNodeBody.addChild(body);

    // Wings
    ColorNode colorNodeWing = new ColorNode(blackish);
    scaleNode.addChild(colorNodeWing);

    wingsGroupNode = new GroupNode();
    colorNodeWing.addChild(wingsGroupNode);

    // left wing
    ScaleNode scaleNodeWingLeft = new ScaleNode(new Vector3(0.06, 0.04, 1));
    wingsGroupNode.addChild(scaleNodeWingLeft);

    TranslationNode translatioNodeWingLeft = new TranslationNode(new Vector3(0.4, 0, 0.2));
    scaleNodeWingLeft.addChild(translatioNodeWingLeft);

    RotationNode rotationNodeWingLeft = new RotationNode(new Vector3(0, 0, 1), 0);
    translatioNodeWingLeft.addChild(rotationNodeWingLeft);

    wing = new SingleTriangleNode();
    rotationNodeWingLeft.addChild(wing);

    // right wing
    ScaleNode scaleNodeWingRight = new ScaleNode(new Vector3(-0.06, 0.04, 1));
    wingsGroupNode.addChild(scaleNodeWingRight);

    TranslationNode translatioNodeWingRight = new TranslationNode(new Vector3(0.4, 0, 0.2));
    scaleNodeWingRight.addChild(translatioNodeWingRight);

    RotationNode rotationNodeWingRight = new RotationNode(new Vector3(0, 0, 1), 0);
    translatioNodeWingRight.addChild(rotationNodeWingRight);

    wing = new SingleTriangleNode();
    rotationNodeWingRight.addChild(wing);
  }
예제 #5
0
  @NotNull
  public GroupNode getGroup(@NotNull String group) {
    Enumeration<GroupNode> e = children();
    @Nullable GroupNode cn = null;
    while (e.hasMoreElements()) {
      GroupNode element = e.nextElement();
      if (element.getName().equals(group)) cn = element;
    }

    if (cn == null) throw new ArrayIndexOutOfBoundsException("no group with {name=" + group + "]");

    return cn;
  }
예제 #6
0
  /**
   * Searchs for subgroups of a determined group
   *
   * @param n GroupNode
   */
  private void checkExtraNodes(GroupNode n) {

    LOG.trace("checkExtraNodes");
    TreeGroupDAO tgm = DataAccessDriver.getInstance().newTreeGroupDAO();

    List childGroups = tgm.selectGroups(n.getId());

    for (Iterator iter = childGroups.iterator(); iter.hasNext(); ) {
      GroupNode f = (GroupNode) iter.next();

      this.checkExtraNodes(f);

      n.addNode(f);
    }
  }
 private void addUsageNodes(
     @NotNull GroupNode root,
     @NotNull final UsageViewImpl usageView,
     @NotNull List<UsageNode> outNodes) {
   for (UsageNode node : root.getUsageNodes()) {
     Usage usage = node.getUsage();
     if (usageView.isVisible(usage)) {
       node.setParent(root);
       outNodes.add(node);
     }
   }
   for (GroupNode groupNode : root.getSubGroups()) {
     groupNode.setParent(root);
     addUsageNodes(groupNode, usageView, outNodes);
   }
 }
예제 #8
0
  /** To be called on a logic update. */
  public void update() {
    for (Node child : wingsGroupNode.getAllChildren()) {
      RotationNode rotationNode = (RotationNode) child.getChildNode(0).getChildNode(0);
      double currentAngle = rotationNode.getAngle();

      if (currentAngle >= 80) {
        double currentY = flappingAxis.get(1);

        // "flip" axis
        flappingAxis = new Vector3(0, currentY * -1, 0);
        rotationNode.setAngle(10);
        // rotationNode.setRotationAxis(flappingAxis);
      }
      rotationNode.setAngle(currentAngle + flappingSpeed);
    }
  }
예제 #9
0
  public ParseTree parse(String ea) throws ParseError {

    String e = ea;
    if (verbose) {
      E.info("Parsing: " + e);
    }
    e = e.trim();

    if (e.lastIndexOf("(") == 0 && e.indexOf(")") == e.length() - 1) {
      e = e.substring(1, e.length() - 1);
      // E.info("Replaced with: " + e);
    }

    ArrayList<Node> nodes = tokenize(e);
    // now we've got a list of tokens, and each is linked to is neighbor on either side

    if (verbose) {
      E.info("tokens: " + nodes);
    }

    // a group node to hold the whole lot, the same as is used for the content of bracketed chunks
    GroupNode groot = new GroupNode(null);
    groot.addAll(nodes);

    // some nodes will get replaced, but the operators remain throughout and will be needed later
    // to claim their operands. Use a list here so we can sort by precedence.
    ArrayList<AbstractOperatorNode> ops = new ArrayList<AbstractOperatorNode>();
    ArrayList<GroupNode> gnodes = new ArrayList<GroupNode>();
    ArrayList<FunctionNode> fnodes = new ArrayList<FunctionNode>();

    for (Node n : nodes) {
      if (n instanceof AbstractOperatorNode) {
        ops.add((AbstractOperatorNode) n);
      }
      if (n instanceof GroupNode) {
        gnodes.add((GroupNode) n);
      }
      if (n instanceof FunctionNode) {
        fnodes.add((FunctionNode) n);
      }
    }

    // Right parentheses have been mapped to group nodes. Left parentheses
    // are still present. Make each group node claim the content back to the corresponding
    // opening parenthesis. By starting at the left and processing groups as
    // we come to them we don't need recursion

    for (GroupNode gn : gnodes) {
      gn.gatherPreceeding();
    }

    if (verbose) {
      E.info("Root group: " + groot.toString());
    }

    AbstractOperatorNode[] aops = ops.toArray(new AbstractOperatorNode[ops.size()]);
    Arrays.sort(aops, new PrecedenceComparator());

    for (FunctionNode fn : fnodes) {
      fn.claim();
    }

    for (AbstractOperatorNode op : aops) {
      op.claim();
    }

    for (GroupNode gn : gnodes) {
      gn.supplantByChild();
    }

    ParseTreeNode root = null;
    if (groot.getChildren().size() == 1) {
      Node fc = groot.getChildren().get(0);
      if (fc instanceof ParseTreeNode) {
        root = (ParseTreeNode) fc;
      } else {
        throw new ParseError("root node is not evaluable " + fc);
      }
    } else {
      StringBuilder sb = new StringBuilder();
      sb.append(" too many children left in container: " + groot.getChildren().size());
      sb.append("\n");
      for (Node n : groot.getChildren()) {
        sb.append("Node: " + n + "\n");
      }

      throw new ParseError(sb.toString());
    }

    ParseTree ret = new ParseTree(root);
    return ret;
  }