Search in sources :

Example 1 with CTConnector

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector in project poi by apache.

the class XSLFConnectorShape method prototype.

/**
     * @param shapeId 1-based shapeId
     */
static CTConnector prototype(int shapeId) {
    CTConnector ct = CTConnector.Factory.newInstance();
    CTConnectorNonVisual nvSpPr = ct.addNewNvCxnSpPr();
    CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
    cnv.setName("Connector " + shapeId);
    cnv.setId(shapeId + 1);
    nvSpPr.addNewCNvCxnSpPr();
    nvSpPr.addNewNvPr();
    CTShapeProperties spPr = ct.addNewSpPr();
    CTPresetGeometry2D prst = spPr.addNewPrstGeom();
    prst.setPrst(STShapeType.LINE);
    prst.addNewAvLst();
    /* CTLineProperties ln = */
    spPr.addNewLn();
    return ct;
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTConnectorNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTConnectorNonVisual)

Example 2 with CTConnector

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector in project poi by apache.

the class XSSFDrawing method addShapes.

private void addShapes(XmlCursor cur, List<XSSFShape> lst) {
    try {
        do {
            cur.push();
            if (cur.toFirstChild()) {
                do {
                    XmlObject obj = cur.getObject();
                    XSSFShape shape;
                    if (obj instanceof CTMarker) {
                        // ignore anchor elements
                        continue;
                    } else if (obj instanceof CTPicture) {
                        shape = new XSSFPicture(this, (CTPicture) obj);
                    } else if (obj instanceof CTConnector) {
                        shape = new XSSFConnector(this, (CTConnector) obj);
                    } else if (obj instanceof CTShape) {
                        shape = hasOleLink(obj) ? new XSSFObjectData(this, (CTShape) obj) : new XSSFSimpleShape(this, (CTShape) obj);
                    } else if (obj instanceof CTGraphicalObjectFrame) {
                        shape = new XSSFGraphicFrame(this, (CTGraphicalObjectFrame) obj);
                    } else if (obj instanceof CTGroupShape) {
                        shape = new XSSFShapeGroup(this, (CTGroupShape) obj);
                    } else if (obj instanceof XmlAnyTypeImpl) {
                        LOG.log(POILogger.WARN, "trying to parse AlternateContent, " + "this unlinks the returned Shapes from the underlying xml content, " + "so those shapes can't be used to modify the drawing, " + "i.e. modifications will be ignored!");
                        // XmlAnyTypeImpl is returned for AlternateContent parts, which might contain a CTDrawing
                        cur.push();
                        cur.toFirstChild();
                        XmlCursor cur2 = null;
                        try {
                            // need to parse AlternateContent again, otherwise the child elements aren't typed,
                            // but also XmlAnyTypes
                            CTDrawing alterWS = CTDrawing.Factory.parse(cur.newXMLStreamReader());
                            cur2 = alterWS.newCursor();
                            if (cur2.toFirstChild()) {
                                addShapes(cur2, lst);
                            }
                        } catch (XmlException e) {
                            LOG.log(POILogger.WARN, "unable to parse CTDrawing in alternate content.", e);
                        } finally {
                            if (cur2 != null) {
                                cur2.dispose();
                            }
                            cur.pop();
                        }
                        continue;
                    } else {
                        // ignore anything else
                        continue;
                    }
                    assert (shape != null);
                    shape.anchor = getAnchorFromParent(obj);
                    lst.add(shape);
                } while (cur.toNextSibling());
            }
            cur.pop();
        } while (cur.toNextSibling());
    } finally {
        cur.dispose();
    }
}
Also used : CTMarker(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker) CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame) CTDrawing(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing) CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTGroupShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape) XmlCursor(org.apache.xmlbeans.XmlCursor) XmlException(org.apache.xmlbeans.XmlException) CTPicture(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject)

Example 3 with CTConnector

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector in project poi by apache.

the class TestXSLFConnectorShape method testAddConnector.

@Test
public void testAddConnector() throws IOException {
    XMLSlideShow pptx = new XMLSlideShow();
    XSLFSlide slide = pptx.createSlide();
    XSLFAutoShape rect1 = slide.createAutoShape();
    rect1.setShapeType(ShapeType.RECT);
    rect1.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
    rect1.setFillColor(Color.blue);
    XSLFAutoShape rect2 = slide.createAutoShape();
    rect2.setShapeType(ShapeType.RECT);
    rect2.setAnchor(new Rectangle2D.Double(300, 300, 100, 100));
    rect2.setFillColor(Color.red);
    XSLFConnectorShape connector1 = slide.createConnector();
    connector1.setAnchor(new Rectangle2D.Double(200, 150, 100, 200));
    CTConnector ctConnector = (CTConnector) connector1.getXmlObject();
    ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.BENT_CONNECTOR_3);
    CTNonVisualConnectorProperties cx = ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
    // connection start
    CTConnection stCxn = cx.addNewStCxn();
    stCxn.setId(rect1.getShapeId());
    // side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
    stCxn.setIdx(2);
    CTConnection end = cx.addNewEndCxn();
    end.setId(rect2.getShapeId());
    // side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
    end.setIdx(3);
    pptx.close();
}
Also used : CTConnection(org.openxmlformats.schemas.drawingml.x2006.main.CTConnection) CTNonVisualConnectorProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualConnectorProperties) CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) Rectangle2D(java.awt.geom.Rectangle2D) Test(org.junit.Test)

Example 4 with CTConnector

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector in project poi by apache.

the class XSSFConnector method prototype.

/**
     * Initialize default structure of a new auto-shape
     *
     */
protected static CTConnector prototype() {
    if (prototype == null) {
        CTConnector shape = CTConnector.Factory.newInstance();
        CTConnectorNonVisual nv = shape.addNewNvCxnSpPr();
        CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
        nvp.setId(1);
        nvp.setName("Shape 1");
        nv.addNewCNvCxnSpPr();
        CTShapeProperties sp = shape.addNewSpPr();
        CTTransform2D t2d = sp.addNewXfrm();
        CTPositiveSize2D p1 = t2d.addNewExt();
        p1.setCx(0);
        p1.setCy(0);
        CTPoint2D p2 = t2d.addNewOff();
        p2.setX(0);
        p2.setY(0);
        CTPresetGeometry2D geom = sp.addNewPrstGeom();
        geom.setPrst(STShapeType.LINE);
        geom.addNewAvLst();
        CTShapeStyle style = shape.addNewStyle();
        CTSchemeColor scheme = style.addNewLnRef().addNewSchemeClr();
        scheme.setVal(STSchemeColorVal.ACCENT_1);
        style.getLnRef().setIdx(1);
        CTStyleMatrixReference fillref = style.addNewFillRef();
        fillref.setIdx(0);
        fillref.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
        CTStyleMatrixReference effectRef = style.addNewEffectRef();
        effectRef.setIdx(0);
        effectRef.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
        CTFontReference fontRef = style.addNewFontRef();
        fontRef.setIdx(STFontCollectionIndex.MINOR);
        fontRef.addNewSchemeClr().setVal(STSchemeColorVal.TX_1);
        prototype = shape;
    }
    return prototype;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTFontReference(org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference) CTConnectorNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnectorNonVisual)

Example 5 with CTConnector

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector in project poi by apache.

the class XSSFDrawing method createConnector.

/**
     * Creates a simple shape.  This includes such shapes as lines, rectangles,
     * and ovals.
     *
     * @param anchor    the client anchor describes how this group is attached
     *                  to the sheet.
     * @return  the newly created shape.
     */
public XSSFConnector createConnector(XSSFClientAnchor anchor) {
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
    CTConnector ctShape = ctAnchor.addNewCxnSp();
    ctShape.set(XSSFConnector.prototype());
    XSSFConnector shape = new XSSFConnector(this, ctShape);
    shape.anchor = anchor;
    return shape;
}
Also used : CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Aggregations

CTConnector (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector)4 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)2 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)2 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)2 CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)2 Rectangle2D (java.awt.geom.Rectangle2D)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlException (org.apache.xmlbeans.XmlException)1 XmlObject (org.apache.xmlbeans.XmlObject)1 XmlAnyTypeImpl (org.apache.xmlbeans.impl.values.XmlAnyTypeImpl)1 Test (org.junit.Test)1 CTConnection (org.openxmlformats.schemas.drawingml.x2006.main.CTConnection)1 CTFontReference (org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference)1 CTNonVisualConnectorProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualConnectorProperties)1 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)1 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)1 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)1 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)1 CTStyleMatrixReference (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference)1 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)1