private void priorityLayout2(int level[],int priorities[],int bCenters[],int horPositions[]){
  int descOrder[]=new int[priorities.length];
  descOrder[0]=0;
  for (int i=0; i < priorities.length - 1; i++) {
    int j=i;
    int temp=i + 1;
    while (j > -1 && priorities[descOrder[j]] < priorities[temp]) {
      descOrder[j + 1]=descOrder[j];
      j--;
    }
    j++;
    descOrder[j]=temp;
  }
  for (int k=0; k < descOrder.length; k++) {
    for (int i=0; i < descOrder.length; i++) {
      int leftCount=0, rightCount=0, leftNodes[], rightNodes[];
      for (int j=0; j < priorities.length; j++) {
        if (horPositions[level[descOrder[i]]] > horPositions[level[j]]) {
          leftCount++;
        }
 else         if (horPositions[level[descOrder[i]]] < horPositions[level[j]]) {
          rightCount++;
        }
      }
      leftNodes=new int[leftCount];
      rightNodes=new int[rightCount];
      for (int j=0, l=0, r=0; j < priorities.length; j++) {
        if (horPositions[level[descOrder[i]]] > horPositions[level[j]]) {
          leftNodes[l++]=j;
        }
 else         if (horPositions[level[descOrder[i]]] < horPositions[level[j]]) {
          rightNodes[r++]=j;
        }
      }
      while (Math.abs(horPositions[level[descOrder[i]]] - 1 - bCenters[descOrder[i]]) < Math.abs(horPositions[level[descOrder[i]]] - bCenters[descOrder[i]])) {
        int temp=horPositions[level[descOrder[i]]];
        boolean cantMove=false;
        for (int j=leftNodes.length - 1; j >= 0; j--) {
          if (temp - horPositions[level[leftNodes[j]]] > 1) {
            break;
          }
 else           if (priorities[descOrder[i]] <= priorities[leftNodes[j]]) {
            cantMove=true;
            break;
          }
 else {
            temp=horPositions[level[leftNodes[j]]];
          }
        }
        if (cantMove) {
          break;
        }
        temp=horPositions[level[descOrder[i]]] - 1;
        for (int j=leftNodes.length - 1; j >= 0; j--) {
          if (temp == horPositions[level[leftNodes[j]]]) {
            horPositions[level[leftNodes[j]]]=temp=horPositions[level[leftNodes[j]]] - 1;
          }
        }
        horPositions[level[descOrder[i]]]=horPositions[level[descOrder[i]]] - 1;
      }
      while (Math.abs(horPositions[level[descOrder[i]]] + 1 - bCenters[descOrder[i]]) < Math.abs(horPositions[level[descOrder[i]]] - bCenters[descOrder[i]])) {
        int temp=horPositions[level[descOrder[i]]];
        boolean cantMove=false;
        for (        int rightNode : rightNodes) {
          if (horPositions[level[rightNode]] - temp > 1) {
            break;
          }
 else           if (priorities[descOrder[i]] <= priorities[rightNode]) {
            cantMove=true;
            break;
          }
 else {
            temp=horPositions[level[rightNode]];
          }
        }
        if (cantMove) {
          break;
        }
        temp=horPositions[level[descOrder[i]]] + 1;
        for (int j=0; j < rightNodes.length; j++) {
          if (temp == horPositions[level[rightNodes[j]]]) {
            horPositions[level[rightNodes[j]]]=temp=horPositions[level[rightNodes[j]]] + 1;
          }
        }
        horPositions[level[descOrder[i]]]=horPositions[level[descOrder[i]]] + 1;
      }
    }
  }
}

private void priorityLayout2 ( int level [ ] , int priorities [ ] , int bCenters [ ] , int horPositions [ ] ) { int descOrder [ ] = new int [ priorities . length ] ; descOrder [ 0 ] = 0 ; for ( int i = 0 ; i < priorities . length - 1 ; i ++ ) { int j = i ; int temp = i + 1 ; while ( j > - 1 && priorities [ descOrder [ j ] ] < priorities [ temp ] ) { descOrder [ j + 1 ] = descOrder [ j ] ; j -- ; } j ++ ; descOrder [ j ] = temp ; } for ( int k = 0 ; k < descOrder . length ; k ++ ) { for ( int i = 0 ; i < descOrder . length ; i ++ ) { int leftCount = 0 , rightCount = 0 , leftNodes [ ] , rightNodes [ ] ; for ( int j = 0 ; j < priorities . length ; j ++ ) { if ( horPositions [ level [ descOrder [ i ] ] ] > horPositions [ level [ j ] ] ) { leftCount ++ ; } else if ( horPositions [ level [ descOrder [ i ] ] ] < horPositions [ level [ j ] ] ) { rightCount ++ ; } } leftNodes = new int [ leftCount ] ; rightNodes = new int [ rightCount ] ; for ( int j = 0 , l = 0 , r = 0 ; j < priorities . length ; j ++ ) { if ( horPositions [ level [ descOrder [ i ] ] ] > horPositions [ level [ j ] ] ) { leftNodes [ l ++ ] = j ; } else if ( horPositions [ level [ descOrder [ i ] ] ] < horPositions [ level [ j ] ] ) { rightNodes [ r ++ ] = j ; } } while ( Math . abs ( horPositions [ level [ descOrder [ i ] ] ] - 1 - bCenters [ descOrder [ i ] ] ) < Math . abs ( horPositions [ level [ descOrder [ i ] ] ] - bCenters [ descOrder [ i ] ] ) ) { int temp = horPositions [ level [ descOrder [ i ] ] ] ; boolean cantMove = false ; for ( int j = leftNodes . length - 1 ; j >= 0 ; j -- ) { if ( temp - horPositions [ level [ leftNodes [ j ] ] ] > 1 ) { break ; } else if ( priorities [ descOrder [ i ] ] <= priorities [ leftNodes [ j ] ] ) { cantMove = true ; break ; } else { temp = horPositions [ level [ leftNodes [ j ] ] ] ; } } if ( cantMove ) { break ; } temp = horPositions [ level [ descOrder [ i ] ] ] - 1 ; for ( int j = leftNodes . length - 1 ; j >= 0 ; j -- ) { if ( temp == horPositions [ level [ leftNodes [ j ] ] ] ) { horPositions [ level [ leftNodes [ j ] ] ] = temp = horPositions [ level [ leftNodes [ j ] ] ] - 1 ; } } horPositions [ level [ descOrder [ i ] ] ] = horPositions [ level [ descOrder [ i ] ] ] - 1 ; } while ( Math . abs ( horPositions [ level [ descOrder [ i ] ] ] + 1 - bCenters [ descOrder [ i ] ] ) < Math . abs ( horPositions [ level [ descOrder [ i ] ] ] - bCenters [ descOrder [ i ] ] ) ) { int temp = horPositions [ level [ descOrder [ i ] ] ] ; boolean cantMove = false ; for ( int rightNode : rightNodes ) { if ( horPositions [ level [ rightNode ] ] - temp > 1 ) { break ; } else if ( priorities [ descOrder [ i ] ] <= priorities [ rightNode ] ) { cantMove = true ; break ; } else { temp = horPositions [ level [ rightNode ] ] ; } } if ( cantMove ) { break ; } temp = horPositions [ level [ descOrder [ i ] ] ] + 1 ; for ( int j = 0 ; j < rightNodes . length ; j ++ ) { if ( temp == horPositions [ level [ rightNodes [ j ] ] ] ) { horPositions [ level [ rightNodes [ j ] ] ] = temp = horPositions [ level [ rightNodes [ j ] ] ] + 1 ; } } horPositions [ level [ descOrder [ i ] ] ] = horPositions [ level [ descOrder [ i ] ] ] + 1 ; } } } }
this method is used by prioritylayout1 ( ) . it should not be called directly . this method does the actual moving of the vertices in each level based on their priorities and barycenters .
