Search in sources :

Example 41 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project cubrid-manager by CUBRID.

the class ERMinJoinDirectedGraphLayout method layout4.

private void layout4() {
    int maxDegree = getMaxDegree(joinDirectedGraph.nodes);
    List<ERTableNode> maxDegreeNodes = getNodesByDegree(maxDegree);
    if (maxDegree == 2 && maxDegreeNodes.size() == 2) {
        buildRelationNodeXY(maxDegreeNodes.get(0), maxDegreeNodes.get(1), Ray.RIGHT);
        // build the right node
        List<ERTableNode> node = maxDegreeNodes.get(1).getAllRelationNodesExcept(maxDegreeNodes.get(0));
        buildRelationNodeXY(maxDegreeNodes.get(1), node.get(0), Ray.RIGHT);
        // build the left node
        node = maxDegreeNodes.get(0).getAllRelationNodesExcept(maxDegreeNodes.get(1));
        buildRelationNodeXY(maxDegreeNodes.get(0), node.get(0), Ray.LEFT);
    } else if (maxDegree == 2 && maxDegreeNodes.size() == 4) {
        buildRelationNodeXY(maxDegreeNodes.get(0), maxDegreeNodes.get(1), Ray.RIGHT);
        boolean isConn = maxDegreeNodes.get(0).isDirectConnected(maxDegreeNodes.get(2));
        if (isConn) {
            buildRelationNodeXY(maxDegreeNodes.get(0), maxDegreeNodes.get(2), Ray.DOWN);
            buildRelationNodeXY(maxDegreeNodes.get(1), maxDegreeNodes.get(3), Ray.DOWN);
        } else {
            buildRelationNodeXY(maxDegreeNodes.get(0), maxDegreeNodes.get(3), Ray.DOWN);
            buildRelationNodeXY(maxDegreeNodes.get(1), maxDegreeNodes.get(2), Ray.DOWN);
        }
    } else if (maxDegree == 3 && maxDegreeNodes.size() >= 2) {
        // for triangle
        List<ERTableNode> exceptNodes = new LinkedList<ERTableNode>();
        exceptNodes.add(maxDegreeNodes.get(0));
        exceptNodes.add(maxDegreeNodes.get(1));
        List<ERTableNode> upDownNodes = getNewExceptNodeList(joinDirectedGraph.nodes, exceptNodes);
        ERTableNode maxWidthNode = ERTableNode.getMaxSizeNode(upDownNodes, true);
        Dimension offsetD1 = buildDefaultCenterOffset(maxDegreeNodes.get(0), maxWidthNode, Ray.RIGHT);
        Dimension offsetD2 = buildDefaultCenterOffset(maxWidthNode, maxDegreeNodes.get(1), Ray.RIGHT);
        Dimension offsetD = new Dimension(offsetD1.width + offsetD2.width, offsetD1.height + offsetD2.height);
        buildRelationNodeXY(maxDegreeNodes.get(0), maxDegreeNodes.get(1), Ray.RIGHT, offsetD);
        BuildTriangleThirdNode(maxDegreeNodes.get(0), maxDegreeNodes.get(1), upDownNodes.get(0), Ray.UP);
        BuildTriangleThirdNode(maxDegreeNodes.get(0), maxDegreeNodes.get(1), upDownNodes.get(1), Ray.DOWN);
    } else {
        layoutMultiNodes();
    }
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) LinkedList(java.util.LinkedList)

Example 42 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project cubrid-manager by CUBRID.

the class ERMinJoinDirectedGraphLayout method buildDefaultCenterOffset.

private Dimension buildDefaultCenterOffset(ERTableNode basicNode, ERTableNode otherNode, Ray ray) {
    Dimension basicD = basicNode.getDefaultPreferredSize();
    Dimension otherD = otherNode.getDefaultPreferredSize();
    Dimension offsetD = new Dimension((basicD.width + otherD.width) / 4, (basicD.height + otherD.height) / 4);
    // space offset
    offsetD.width = offsetD.width * ray.x;
    offsetD.height = offsetD.height * ray.y;
    // add the space of the two rectangle
    offsetD.width += (basicD.width / 2) * ray.x + (otherD.width / 2) * ray.x;
    offsetD.height += (basicD.height / 2) * ray.y + (otherD.height / 2) * ray.y;
    return offsetD;
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 43 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project cubrid-manager by CUBRID.

the class ERMinJoinDirectedGraphLayout method getMaxDimensionNode.

private ERTableNode getMaxDimensionNode(Collection<ERTableNode> allNodes, boolean horizon) {
    int max = -1;
    ERTableNode feedBackNode = null;
    for (ERTableNode node : allNodes) {
        Dimension d = node.getDefaultPreferredSize();
        if (horizon) {
            if (d.width > max) {
                max = d.width;
                feedBackNode = node;
            }
        } else {
            if (d.height > max) {
                max = d.height;
                feedBackNode = node;
            }
        }
    }
    return feedBackNode;
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point)

Example 44 with Dimension

use of org.eclipse.draw2d.geometry.Dimension 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());
    }
}
Also used : NodeList(org.eclipse.draw2d.graph.NodeList) List(java.util.List) LinkedList(java.util.LinkedList) Ray(com.cubrid.common.ui.er.router.Ray) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 45 with Dimension

use of org.eclipse.draw2d.geometry.Dimension in project cubrid-manager by CUBRID.

the class ERMinJoinDirectedGraphLayout method BuildTriangleThirdNode.

public void BuildTriangleThirdNode(ERTableNode one, ERTableNode two, ERTableNode targetNode, Ray ray) {
    int distance = MIN_SPACE_TWO_TABLES;
    Dimension d1 = buildDefaultCenterOffset(one, targetNode, ray);
    Dimension d2 = buildDefaultCenterOffset(two, targetNode, ray);
    if (ray.equals(Ray.UP) || ray.equals(Ray.DOWN)) {
        distance = (d1.height + d2.height) / 2;
        Point center = getCenterPoint(one, two);
        center.y += distance;
        targetNode.setStartPointByCenter(center);
    } else if (ray.equals(Ray.LEFT) || ray.equals(Ray.RIGHT)) {
        distance = (d1.width + d2.width) / 2;
        Point center = getCenterPoint(one, two);
        center.x += distance;
        targetNode.setStartPointByCenter(center);
    }
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Dimension (org.eclipse.draw2d.geometry.Dimension)180 Rectangle (org.eclipse.draw2d.geometry.Rectangle)80 Point (org.eclipse.draw2d.geometry.Point)70 IFigure (org.eclipse.draw2d.IFigure)31 List (java.util.List)16 Insets (org.eclipse.draw2d.geometry.Insets)10 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)8 PointList (org.eclipse.draw2d.geometry.PointList)6 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)6 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)6 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)5 ArrayList (java.util.ArrayList)4 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)4 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)4 Font (org.eclipse.swt.graphics.Font)4 Point (org.eclipse.swt.graphics.Point)4 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)3 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)3 Label (org.eclipse.draw2d.Label)3 SimpleHtmlFigure (org.talend.commons.ui.utils.workbench.gef.SimpleHtmlFigure)3