コード例 #1
0
ファイル: ALinearEventTrapper.java プロジェクト: pdewan/YAAS
  public synchronized void elementRemoved(Object source, int pos, int newSize) {

    LinearElement toBeRemoved = root.getVector().get(pos);
    shapes.getShapes().remove(toBeRemoved.getShape());
    visualizer.removeLine(toBeRemoved.getVerticalLine());
    visualizer.removeLine(toBeRemoved.getHorizontalLine());

    LinearElement parent = root;
    LinearElement previousChild = toBeRemoved.getPreviousChild();

    if (pos + 1 <= newSize) // If it is not the last element
    root.getVector().get(pos + 1).setPreviousChild(previousChild);

    parent.getVector().remove(toBeRemoved);

    root.focusPosition();
  }
コード例 #2
0
ファイル: ALinearEventTrapper.java プロジェクト: pdewan/YAAS
  public synchronized void elementInserted(
      Object source, ElementType element, int pos, int newSize) {

    LinearElement parent = root;
    LinearElement previousChild = pos - 1 >= 0 ? root.getVector().get(pos - 1) : null;

    LinearElement newElement = visualizer.initElement(element, parent, previousChild);

    if (pos + 1 < newSize) // if there is a child after us
      // use pos not pos + 1 because the element has not been
      // added to the vector yet, so pos + 1 in the user's
      // vector is pos in the roots vector.
      root.getVector().get(pos).setPreviousChild(newElement);

    parent.getVector().insertElementAt(newElement, pos);
    root.focusPosition();
  }
コード例 #3
0
ファイル: ALinearEventTrapper.java プロジェクト: pdewan/YAAS
  public synchronized void elementChanged(Object source, ElementType element, int pos) {

    LinearElement node = root.getVector().get(pos);
    AnimationUtil.move(
        node,
        node.getX() + boxWidth / 3,
        node.getY(),
        true,
        ((ALinearLayoutManager<ElementType>)
                visualizer.getLayoutManagerOfBuffer((ListenableVector<ElementType>) source))
            .getHighlighting(),
        ((FlexibleShape)
                visualizer.getLayoutManagerOfBuffer((ListenableVector<ElementType>) source))
            .getColor());
    node.setObject(element);

    BoundedShape shape = node.getShape();

    try {
      double shapeStretchFactor = Double.parseDouble(element.toString());
      shape.setWidth((int) (boxWidth * (dynamicWidth ? shapeStretchFactor : 1)));
      shape.setHeight((int) (boxHeight * (dynamicHeight ? shapeStretchFactor : 1)));
    } catch (Exception e) {
      shape.setWidth((int) (boxWidth));
      shape.setHeight((int) (boxHeight));
    }

    if (shape instanceof TextShape) ((TextShape) shape).setText(element.toString());
    if (shape instanceof LabelShape) ((LabelShape) shape).setText(element.toString());

    AnimationUtil.move(
        node,
        node.getX() - boxWidth / 3,
        node.getY(),
        true,
        ((ALinearLayoutManager<ElementType>)
                visualizer.getLayoutManagerOfBuffer((ListenableVector<ElementType>) source))
            .getHighlighting(),
        ((FlexibleShape)
                visualizer.getLayoutManagerOfBuffer((ListenableVector<ElementType>) source))
            .getColor());
  }
コード例 #4
0
ファイル: ALinearEventTrapper.java プロジェクト: pdewan/YAAS
  /*
   * This method takes two elements and exchanges their parents and previous
   * elements. It then makes sure spacing is correct by calling
   * focusPositionAndLines
   *
   * This method assumes index1 < index2
   */
  private synchronized void swapElements(Object newParam, int index1, int index2) {

    // the two elements to be swapped
    LinearElement firstElement = root.getVector().get(index1);
    LinearElement secondElement = root.getVector().get(index2);

    // the two elements after each of the elements to be swapped
    LinearElement secondElementNext;
    LinearElement firstElementNext;
    /*
     * There is a corner case where secondElement.previousChild is
     * firstElement
     */

    // the first element's previous child before it is reassigned
    LinearElement tempPrevChild = firstElement.getPreviousChild();

    if (index2 != index1 + 1) { // the elements are not adjacent

      // set previous elements for the two nodes
      firstElement.setPreviousChild(secondElement.getPreviousChild());
      secondElement.setPreviousChild(tempPrevChild);

      // set previous elements for the nodes referencing the swapped nodes
      if (index1 + 1 < root.getVector().size()) {
        firstElementNext = root.getVector().get(index1 + 1);
        firstElementNext.setPreviousChild(secondElement);
      }
      if (index2 + 1 < root.getVector().size()) {
        secondElementNext = root.getVector().get(index2 + 1);
        secondElementNext.setPreviousChild(firstElement);
      }

    } else { // the elements are adjacent
      firstElement.setPreviousChild(secondElement);
      secondElement.setPreviousChild(tempPrevChild);

      // set previous elements for the nodes referencing the second node
      if (index2 + 1 < root.getVector().size()) {
        secondElementNext = root.getVector().get(index2 + 1);
        secondElementNext.setPreviousChild(firstElement);
      }
    }

    // swap the elements in root
    root.getVector().swap(index1, index2);

    root.focusPosition();
  }