use of com.cubrid.common.ui.er.router.Ray in project cubrid-manager by CUBRID.
the class ERMinJoinDirectedGraphLayout method layoutOneCenterGraph.
private void layoutOneCenterGraph(ERTableNode centerNode) {
List<ERTableNode> relationNodes = centerNode.getAllRelationNodes();
int maxDegree = getMaxDegree(relationNodes);
List<ERTableNode> maxDegreeNodes = getNodesByDegree(relationNodes, maxDegree);
if (relationNodes.size() < 5) {
final Ray firstNodeRay = Ray.RIGHT;
buildRelationNodeXY(centerNode, maxDegreeNodes.get(0), firstNodeRay);
List<ERTableNode> relationNodes2MaxNode = maxDegreeNodes.get(0).getAllRelationNodesIn(relationNodes);
List<Ray> adjacentRays = centerNode.getUnOccupiedAdjacentRays(firstNodeRay);
Set<ERTableNode> relationedNodes2MaxNode = new HashSet();
int count = Math.min(relationNodes2MaxNode.size(), adjacentRays.size());
for (int i = 0; i < count; i++) {
buildRelationNodeXY(centerNode, relationNodes2MaxNode.get(i), adjacentRays.get(i));
relationedNodes2MaxNode.add(relationNodes2MaxNode.get(i));
}
for (int i = 0; i < relationNodes.size(); i++) {
if (!relationedNodes2MaxNode.contains(relationNodes.get(i)) && !relationNodes.get(i).isArranged()) {
buildRelationNodeXY(centerNode, relationNodes.get(i), firstNodeRay.getReverseRay());
relationedNodes2MaxNode.add(relationNodes.get(i));
break;
}
}
List<Ray> otherRays = centerNode.getUnOccupiedDirections();
int rayCount = 0;
for (int i = 0; i < relationNodes.size(); i++) {
if (!relationNodes.get(i).isArranged()) {
buildRelationNodeXY(centerNode, relationNodes.get(i), otherRays.get(rayCount++));
}
}
} else {
if (maxDegreeNodes.size() < 2) {
List<ERTableNode> newRelationNodes = getNewExceptNodeList(relationNodes, maxDegreeNodes);
int secodeMaxDegree = getMaxDegree(newRelationNodes);
maxDegreeNodes.add(getNodesByDegree(relationNodes, secodeMaxDegree).get(0));
}
int maxNodehorizonOffset = MIN_SPACE_TWO_TABLES;
int maxNodeVerticalOffset = MIN_SPACE_TWO_TABLES;
if (maxDegree > 1) {
maxNodehorizonOffset += buildLayoutSumLenth(relationNodes, true) / 4;
maxNodeVerticalOffset += buildLayoutSumLenth(relationNodes, false) / 4;
}
boolean MaxDegreeNodesConnected = maxDegreeNodes.get(0).isDirectConnected(maxDegreeNodes.get(1));
buildRelationNodeXY(centerNode, maxDegreeNodes.get(1), Ray.RIGHT, new Dimension(maxNodehorizonOffset, 0));
if (MaxDegreeNodesConnected) {
buildRelationNodeXY(centerNode, maxDegreeNodes.get(0), Ray.DOWN, new Dimension(0, maxNodeVerticalOffset));
} else {
buildRelationNodeXY(centerNode, maxDegreeNodes.get(0), Ray.LEFT, new Dimension(-1 * maxNodehorizonOffset, 0));
}
Set<ERTableNode> builtNodes = new HashSet<ERTableNode>();
builtNodes.add(maxDegreeNodes.get(0));
builtNodes.add(maxDegreeNodes.get(1));
List<ERTableNode> newRelationNodes = getNewExceptNodeList(relationNodes, builtNodes);
ERTableNode maxHightNode = getMaxDimensionNode(newRelationNodes, false);
List upLineNodes = new LinkedList();
List leftOrDownLineNodes = new LinkedList();
newRelationNodes.remove(maxHightNode);
LayoutUtil.splitSimpleTwoHalf(newRelationNodes, upLineNodes, leftOrDownLineNodes);
int avgUpOffset = Math.abs(buildAverageOffset(centerNode, upLineNodes, Ray.UP).height);
int avgLeftOrDownOffset = 0;
if (MaxDegreeNodesConnected) {
avgLeftOrDownOffset = Math.abs(buildAverageOffset(centerNode, leftOrDownLineNodes, Ray.RIGHT).width);
} else {
avgLeftOrDownOffset = Math.abs(buildAverageOffset(centerNode, leftOrDownLineNodes, Ray.DOWN).height);
}
int upnodeCenterX = centerNode.getRectangle().getCenter().x;
int upnodeCenterY = centerNode.getRectangle().getCenter().y - avgUpOffset;
maxHightNode.setStartPointByCenter(upnodeCenterX, upnodeCenterY);
maxHightNode.setArranged(true);
layoutNodesOnLine(upLineNodes, maxHightNode, true);
if (MaxDegreeNodesConnected) {
int leftnodeCenterX = centerNode.getRectangle().getCenter().x - avgLeftOrDownOffset;
int leftnodeCenterY = centerNode.getRectangle().getCenter().y;
if (leftOrDownLineNodes != null && leftOrDownLineNodes.size() > 0) {
((ERTableNode) leftOrDownLineNodes.get(0)).setStartPointByCenter(leftnodeCenterX, leftnodeCenterY);
leftOrDownLineNodes.remove(0);
layoutNodesOnLine(leftOrDownLineNodes, maxHightNode, false);
}
} else {
int downnodeCenterX = centerNode.getRectangle().getCenter().x;
int downnodeCenterY = centerNode.getRectangle().getCenter().y + avgLeftOrDownOffset;
if (leftOrDownLineNodes != null && leftOrDownLineNodes.size() > 0) {
((ERTableNode) leftOrDownLineNodes.get(0)).setStartPointByCenter(downnodeCenterX, downnodeCenterY);
leftOrDownLineNodes.remove(0);
layoutNodesOnLine(leftOrDownLineNodes, maxHightNode, true);
}
}
}
for (ERTableNode node : relationNodes) {
layoutRecursionDirectedSideLine(node.getAllRelationNodes(), node, node.getOneEmptyDirect());
}
}
use of com.cubrid.common.ui.er.router.Ray in project cubrid-manager by CUBRID.
the class ERTableNode method getUnOccupiedAdjacentRays.
public List<Ray> getUnOccupiedAdjacentRays(Ray basicRay) {
Ray oppositeRay = basicRay.getReverseRay();
List<Ray> result = getUnOccupiedDirections();
result.remove(basicRay);
result.remove(oppositeRay);
return result;
}