if (arg1.getPrecedingElements() == null
|| arg1.getPrecedingElements().size() == 0) {
return 1;
}
final GraphWrapper parent0 = arg0
.getPrecedingElements().get(0);
final GraphWrapper parent1 = arg1
.getPrecedingElements().get(0);
if (parent0.equals(parent1)) {
final GraphWrapperIDTuple gwidT0 = parent0
.getGraphWrapperIDTuple(arg0);
final GraphWrapperIDTuple gwidT1 = parent1
.getGraphWrapperIDTuple(arg1);
if (gwidT0.getId() == gwidT1.getId()) { // siblings
// !
for (final GraphWrapperIDTuple gwidtuple : parent0
.getSucceedingElements()) {
if (gwidtuple.getOperator()
.equals(arg0)) {
return -1;
} else if (gwidtuple.getOperator()
.equals(arg1)) {
return 1;
}
}
} else if (gwidT0.getId() < gwidT1.getId()) {
return -1;
} else if (gwidT0.getId() > gwidT1.getId()) {
return 1;
}
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);