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

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

Introduction

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

Prototype

public String getTextAsString() 

Source Link

Usage

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

License:Apache License

public ShapeData(XDGFShape shape, AffineTransform globalTransform) {

    Path2D shapeBounds;//from   w  w  w.  jav a2 s.c  o  m
    Path2D path = shape.getPath();

    // some 1d shapes don't have a path associated with them, 
    // if they have subshapes... 
    if (shape.isShape1D() && path != null) {
        path1D = path;
        path1D.transform(globalTransform);
        path1D = GeomUtils.roundPath(path1D);
        hasGeometry = true;

        calculate1dEndpoints();
        shapeBounds = path1D; // use path as bounds
    } else {
        // calculate bounding boxes + other geometry information we'll need later
        shapeBounds = shape.getBoundsAsPath();

        shapeBounds.transform(globalTransform);
        shapeBounds = GeomUtils.roundPath(shapeBounds);

        path2D = shapeBounds;
        hasGeometry = (path != null);
    }

    this.bounds = shapeBounds.getBounds2D();

    this.shape = shape;
    this.shapeId = shape.getID();
    this.rtreeBounds = SpatialTools.convertRect(this.bounds);
    this.area = this.rtreeBounds.area();

    this.isInteresting = isInteresting(shape);

    this.lineColor = shape.getLineColor();
    this.linePattern = shape.getLinePattern();

    hasText = shape.hasText() && !shape.getTextAsString().isEmpty();
    isTextbox = hasText && !shape.hasMaster() && !shape.hasMasterShape();

    if (hasText)
        textCenter = globalTransform.transform(shape.getText().getTextCenter(), null);
}

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

License:Apache License

protected void collectShapes() {

    pageContents.visitShapes(new ShapeVisitor() {

        @Override/*w w w.  ja va2s. c o  m*/
        public org.apache.poi.xdgf.usermodel.shape.ShapeVisitorAcceptor getAcceptor() {
            return new ShapeDataAcceptor();
        };

        @Override
        public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {

            ShapeData shapeData = new ShapeData(shape, globalTransform);

            if (shapeData.hasText && reassignTextNodeToParent(shape, shapeData)) {
                return;
            }

            String id = pageId + ": " + shape.getID();
            Vertex vertex = graph.addVertex(id);

            shapeData.vertex = vertex;

            // useful properties for later... 
            vertex.setProperty("label", shape.getTextAsString());
            vertex.setProperty("shapeId", shape.getID());

            vertex.setProperty("group", "");
            vertex.setProperty("groupId", "");
            vertex.setProperty("inSecondaryGroup", false);
            vertex.setProperty("is1d", shape.isShape1D());
            vertex.setProperty("name", shape.getName());
            vertex.setProperty("pageName", pageName);
            vertex.setProperty("symbolName", shape.getSymbolName());
            vertex.setProperty("type", shape.getShapeType());

            // this isn't actually accurate
            //vertex.setProperty("visible", shape.isVisible());

            // local coordinates
            vertex.setProperty("x", shapeData.getCenterX());
            vertex.setProperty("y", shapeData.getCenterY());

            helper.onCreate(shapeData, shape);

            shapesMap.put(shape.getID(), shapeData);
            shapes.add(shapeData);
        }
    });
}

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;/*  w w  w . ja  v  a 2 s  .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;
}