Example usage for org.apache.poi.xdgf.usermodel XDGFShape getParentShape

List of usage examples for org.apache.poi.xdgf.usermodel XDGFShape getParentShape

Introduction

In this page you can find the example usage for org.apache.poi.xdgf.usermodel XDGFShape getParentShape.

Prototype

public XDGFShape getParentShape() 

Source Link

Usage

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected boolean reassignTextNodeToParent(XDGFShape shape, ShapeData shapeData) {

    // keep looking at parents to see if they're a good match
    ShapeData parentMatch = null;/*  ww w  .  j a  v a2s.c o m*/
    XDGFShape current = shape;
    ArrayList<ShapeData> duplicates = new ArrayList<>();

    double x = shapeData.bounds.getMinX();
    double width = shapeData.bounds.getWidth();

    while (current.hasParent()) {

        XDGFShape parent = current.getParentShape();
        ShapeData parentData = getShape(parent.getID());

        if (parentData != null) {

            double parentWidth = parentData.bounds.getWidth();
            double px = parentData.bounds.getMinX();

            if (Math.abs(width - parentWidth) > 0.0001 || Math.abs(px - x) > 0.0001)
                break;

            // found a potential match
            if (!parentData.hasText) {

                // discard duplicate useless shapes
                if (parentMatch != null)
                    duplicates.add(parentMatch);

                parentMatch = parentData;
            }
        }

        current = parent;
    }

    // if there's a parent match, reassign the text
    if (parentMatch != null) {
        XDGFText text = shape.getText();

        parentMatch.vertex.setProperty("label", shape.getTextAsString());
        parentMatch.vertex.setProperty("textRef", shape.getID());
        parentMatch.vertex.setProperty("textRefWhy", "reassignToParent");
        parentMatch.hasText = true;
        parentMatch.isInteresting = true;
        parentMatch.textCenter = text.getTextCenter();

        helper.onReassignToParent(parentMatch, shape);

        for (ShapeData dup : duplicates) {
            removeShape(dup);
        }

        return true;
    }

    return false;
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected ShapeData findShapeOrParent(long id) {

    ShapeData sd = getShape(id);/*from  ww  w.j a  va2s.  c om*/
    if (sd != null)
        return sd;

    // find a parent that is in the graph already
    XDGFShape shape = pageContents.getShapeById(id);

    while (sd == null) {
        shape = shape.getParentShape();
        if (shape == null)
            break;

        sd = getShape(shape.getID());
    }

    return sd;
}

From source file:com.bbn.poi.xdgf.parsers.VisioPageParser.java

License:Apache License

protected ShapeData findTopmostParentWithGeom(ShapeData shapeData) {

    ShapeData shapeWithGeom = (shapeData.hasGeometry ? shapeData : null);

    XDGFShape shape = pageContents.getShapeById(shapeData.shapeId);

    while (true) {
        shape = shape.getParentShape();
        if (shape == null)
            break;

        shapeData = getShape(shape.getID());
        if (shapeData != null && shapeData.hasGeometry)
            shapeWithGeom = shapeData;//from w  w w  .jav a  2 s.c om
    }

    return shapeWithGeom;
}