Package lupos.gui.operatorgraph

Examples of lupos.gui.operatorgraph.GraphBox


                System.err
                    .println("QueryGraph: GraphWrapper object not found!");

                return -1;
              } else {
                final GraphBox b0 = boxes.get(parent0);
                final GraphBox b1 = boxes.get(parent1);

                if (b0.getX() < b1.getX()) {
                  return -1;
                } else {
                  return 1;
                }
              }
            }
          });

      toSort.addAll(graphWrapperOfLevel.get(level));

      // add the GraphBoxes of all GraphWrappers of this level to the
      // row...
      row.addAllWithoutUpdatingParentsSize(toSort, boxes);

      // add row height and spacing height to y...
      y += row.getHeight() + operatorgraph.SPACING_Y;

      level++; // increment level
    }

    int maxRowId = 0;

    // move each box under it's preceding box / boxes...
    for (int r = 0; r < rows.size(); ++r) { // walk through rows...
      final GraphRow row = rows.get(r); // get current row

      // move first row to most left corner...
      if (levels.get(row.getBoxes().get(0).getOp()) == 0) {
        // define x value for far left box...
        int localX = (int) Math.ceil(operatorgraph.PADDING);

        // walk through boxes of the first row...
        for (final GraphBox localBox : row.getBoxes()) {
          updateXWithoutUpdatingParentsSize(operatorgraph, localBox,
              levels, level,
              localX,
              new HashSet<GraphBox>());

          // update the x value for the next box...
          localX += localBox.width + operatorgraph.PADDING;
        }
      } else {
        // center boxes under preceding boxes...

        // walk through boxes...
        for (final GraphBox box : row.getBoxes()) {
          // get preceding OPs of current box...
          final LinkedList<GraphWrapper> precOps = box.getOp()
              .getPrecedingElements();

          // remove preceding OPs from higher levels...
          for (int j = 0; j < precOps.size(); ++j) {
            if (levels.get(boxes.get(precOps.get(j)).getOp()) > levels
                .get(box.getOp())) {
              precOps.remove(j);
            }
          }

          if (precOps.size() == 0) {
            continue;
          }

          int center = 0;

          // switch over number of preceding OPs...
          if (precOps.size() == 1) { // one preceding OP...
            // move the box under it's preceding box...

            // get preceding box...
            final GraphBox precBox = boxes.get(precOps.get(0));

            // determine center of preceding box...
            center = precBox.getX() + (precBox.width / 2);

            // move box so that center of both boxes are equal...
            updateXWithoutUpdatingParentsSize(operatorgraph, box,
                levels, level,
                center
                - (box.width / 2), new HashSet<GraphBox>());
          } else {
            // center box under preceding boxes...

            // get first preceding box...
            GraphBox preBox = boxes.get(precOps.get(0));

            // determine center of first preceding box...
            center = preBox.getX() + (preBox.width / 2);

            // walk through preceding operators...
            for (int j = 1; j < precOps.size(); ++j) {
              // get preceding box...
              preBox = boxes.get(precOps.get(j));

              // determine center of preceding box...
              final int preBoxCenter = preBox.getX()
                  + (preBox.width / 2);

              // determine new center...
              center = (center + preBoxCenter) / 2;
            }

            // move box to center of preceding boxes...
            updateXWithoutUpdatingParentsSize(operatorgraph, box,
                levels, level,
                center
                - (box.width / 2), new HashSet<GraphBox>());
          }
        }
      }

      // resolve box overlapping...
      GraphBox box = row.getBoxes().get(0); // get first box

      // move left box if not at the right position...
      if (box.getX() < (int) Math.ceil(operatorgraph.PADDING)) {
        updateXWithoutUpdatingParentsSize(operatorgraph, box, levels,
            level,
            (int) Math.ceil(operatorgraph.PADDING),
            new HashSet<GraphBox>());
      }

      // walk through boxes...
      for (int i = 1; i < row.getBoxes().size(); ++i) {
        // get previous box...
        final GraphBox preBox = row.getBoxes().get(i - 1);

        box = row.getBoxes().get(i); // get current box

        // if previous box and current box overlap...
        if (preBox.getX() + preBox.width
            + (int) Math.ceil(operatorgraph.SPACING_X) > box.getX()) {
          // move current box...
          updateXWithoutUpdatingParentsSize(operatorgraph,
              box,
              levels,
              level,
              preBox.getX() + preBox.width
                  + (int) Math.ceil(operatorgraph.SPACING_X),
              new HashSet<GraphBox>());
        }
      }

      // determine ID of longest row...
      if (row.getWidth() > rows.get(maxRowId).getWidth()) {
        maxRowId = r;
      }
    }

    if (rows.size() > 0) {
      final int maxWidth = rows.get(maxRowId).getWidth();

      // walk through all rows previous to maxRowId...
      for (int r = 0; r < maxRowId; ++r) {
        // center the current row...
        rows.get(r).centerWithoutUpdatingParentsSize(maxWidth / 2);
      }

      // --- resolve annotation overlapping - begin ---
      for (final GraphRow row : rows) { // walk through all rows...
        // walk through all boxes of the row...
        for (final GraphBox box : row.getBoxes()) {
          final Hashtable<GraphWrapper, AbstractSuperGuiComponent> lineAnnotations = box
              .getLineAnnotations();
          final Iterator<GraphWrapper> lineAnnotationsGWsIt = lineAnnotations
              .keySet().iterator();

          // box has less than two line annotations...
          if (lineAnnotations.size() < 2) {
            continue;
          }

          GraphWrapper previousAnnotationGW = lineAnnotationsGWsIt
              .next();
          AbstractSuperGuiComponent previousAnnotation = lineAnnotations
              .get(previousAnnotationGW);

          // walk through all but the first annotation...
          while (lineAnnotationsGWsIt.hasNext()) {
            // get current GW...
            final GraphWrapper lineAnnotationGW = lineAnnotationsGWsIt
                .next();

            // get current annotation....
            final AbstractSuperGuiComponent annotation = lineAnnotations
                .get(lineAnnotationGW);

            // check for overlapping...
            if (previousAnnotation.isOverlapping(annotation)) {
              final GraphBox previousAnnotationTargetBox = boxes
                  .get(previousAnnotationGW);
              final GraphBox annotationTargetBox = boxes
                  .get(lineAnnotationGW);

              // move annotation target box...
              if (previousAnnotationTargetBox.getX() <= annotationTargetBox
                  .getX()) {
                final int annotationDistance = (previousAnnotation
                    .getLocation().x + previousAnnotation
                    .getPreferredSize().width)
                    - annotation.getLocation().x;
                final int newX = annotationTargetBox.getX()
                    + annotationTargetBox.width
                    + (int) Math
                        .ceil(operatorgraph.PADDING)
                    + annotationDistance;

                annotationTargetBox
                    .setXWithoutUpdatingParentsSize(newX);
              }
              // move previousAnnotation target box...
              else if (previousAnnotationTargetBox.getX() > annotationTargetBox
                  .getX()) {
                final int annotationDistance = (annotation
                    .getLocation().x + annotation
                    .getPreferredSize().width)
                    - previousAnnotation.getLocation().x;
View Full Code Here


   * @return
   */
  private static boolean isHidingANode(GraphWrapper node, OperatorGraph op) {
    HashMap<GraphWrapper, GraphBox> boxes = op.getBoxes();
    boolean hide = true;
    GraphBox nodeBox = boxes.get(node);
   
    int nodeX = nodeBox.getX();
    int nodeY = nodeBox.getY();
    if ((nodeX == -1) && (nodeY == -1)) {
      return false;
    }
    int nodeXArea = nodeX+nodeBox.width;
    int nodeYArea = nodeY+nodeBox.height;
    int i = 0;
    for (GraphWrapper gw : boxes.keySet()) {
      i++;
     
      GraphBox hideBox = boxes.get(gw);
      int hideX = hideBox.getX();
      int hideY = hideBox.getY();
      if ((hideX == -1) && (hideY == -1)) {
        continue;
      }
      int hideXArea = hideX+hideBox.width;
      int hideYArea = hideY+hideBox.height;
View Full Code Here

   * @param isSet    HashMap with already visited nodes
   */
  public static void setCoordinates(GraphWrapper node, final OperatorGraph op, HashSet<GraphWrapper> isSet, HashSet<Edge> isVisited) {
    HashMap <GraphWrapper, GraphBox> boxes = op.getBoxes();

    GraphBox box = boxes.get(node);
   
    LinkedList<Edge>suc = getEdges(node);   
    /**if (suc.size() == 0) {
      return;
    }**/
   
    for (Edge e : suc) {
      if(isVisited.contains(e)) return;
      isVisited.add(e);

      if (isSet.contains(e.getTarget())) {       
        continue;
      }
     
      //isSet.add(e);
      int type = e.getEdgeType();
      double direction = directions.get(type);
      GraphBox sucBox = boxes.get(e.getTarget());
     
      int x = (int)Math.ceil(box.getX()+(EDGE_LENGTH*Math.cos(direction)));
      int y = (int)Math.ceil(box.getY()+(EDGE_LENGTH*Math.sin(direction)));
     
      if (!isSet.contains(e.getTarget()) && (idHierarchy.get(e.getTarget()) > idHierarchy.get(node))) {
        sucBox.setXWithoutUpdatingParentsSize(x);
        sucBox.setYWithoutUpdatingParentsSize(y);
        isSet.add(e.getTarget());
      }
      else{
        continue;
      }
     
     
     
      if (isHidingANode(e.getTarget(), op)){

        direction += ((Math.PI/180)*AGAINST_OVERLAPPING);
        x = (int)Math.ceil(box.getX()+(EDGE_LENGTH*Math.cos(direction)));
        y = (int)Math.ceil(box.getY()+(EDGE_LENGTH*Math.sin(direction)));
        sucBox.setXWithoutUpdatingParentsSize(x);
        sucBox.setYWithoutUpdatingParentsSize(y);
      }
      setCoordinates(e.getTarget(),op, isSet, isVisited);
    }
   
  }
View Full Code Here

    setDirections(operatorgraph);
    fillIDs(operatorgraph);
   
    GraphWrapper root1 = roots.getFirst();
   
    GraphBox box1 = boxes.get(root1);
    box1.setXWithoutUpdatingParentsSize((int)Math.ceil(operatorgraph.getWidth()/roots.size()+1));
    box1.setYWithoutUpdatingParentsSize((int)Math.ceil(operatorgraph.PADDING));

    setCoordinates(root1, operatorgraph, isSet, isVisited);

    int x = 0; int width = 0;
    for (int i = 1; i < roots.size(); i++) {
      for (GraphBox box : boxes.values()) {
        if (box.getY() == box1.getY()) {
          if (box.getX() > x) {
            x = box.getX(); width = box.width;
          }
        }
      }
      GraphWrapper root = roots.get(i);
      GraphBox rootBox = boxes.get(root);
      int x_Coord = (int)Math.ceil(x + width + operatorgraph.SPACING_X);
      rootBox.setXWithoutUpdatingParentsSize(x_Coord);
      rootBox.setYWithoutUpdatingParentsSize(box1.getY());

      setCoordinates(root, operatorgraph, isSet,isVisited);
     
    }
  }
View Full Code Here

    if(this.boxes.isEmpty()) { // no box in the row, yet...
      b.setX((int) Math.ceil(this.parent.PADDING));
    }
    else { // already boxes in the row...
      // get last box in row...
      final GraphBox last = this.boxes.get(this.boxes.size() - 1);

      b.setX(last.getX() + last.width + (int) Math.ceil(this.parent.getSPACING_X()));
    }

    b.setY(this.y); // move box in y-direction into the row

    this.boxes.add(b); // add new box to boxes list
View Full Code Here

    this.height = Math.max(this.height, b.height);
  }

  public void addAllWithoutUpdatingParentsSize(final Collection<GraphWrapper> cgw, final Map<GraphWrapper, GraphBox> boxesMap) {
    // last box in the row
    GraphBox last = (this.boxes.isEmpty()) ? null : this.boxes.get(this.boxes.size() - 1);

    for(final GraphWrapper gw : cgw) {
      final GraphBox b = boxesMap.get(gw);

      // set new box start position...
      if(last == null) { // no box in the row, yet...
        b.setXWithoutUpdatingParentsSize((int) Math.ceil(this.parent.PADDING));
      }
      else { // already boxes in the row...
        b.setXWithoutUpdatingParentsSize(last.getX() + last.width + (int) Math.ceil(this.parent.getSPACING_X()));
      }

      b.setYWithoutUpdatingParentsSize(this.y); // move box in y-direction into the row

      this.boxes.add(b); // add new box to boxes list

      // set row height to highest height in the row
      this.height = Math.max(this.height, b.height);
View Full Code Here

  public int getWidth() {
    if(this.boxes.size()==0){
      return 0;
    }
    GraphBox mostLeft = this.boxes.get(0);
    GraphBox mostRight = this.boxes.get(0);

    for(int i = 1; i < this.boxes.size(); ++i) {
      final GraphBox tmpBox = this.boxes.get(i);

      if(tmpBox.getX() < mostLeft.getX()) {
        mostLeft = tmpBox;
      }

      if(tmpBox.getX() + tmpBox.width > mostRight.getX() + mostRight.width) {
        mostRight = tmpBox;
      }
    }

    final int mostRightPosition = mostRight.getX() + mostRight.width;
View Full Code Here

TOP

Related Classes of lupos.gui.operatorgraph.GraphBox

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.