Search in sources :

Example 1 with CTConnector

use of org.openxmlformats.schemas.presentationml.x2006.main.CTConnector in project poi by apache.

the class XSLFDrawing method createConnector.

public XSLFConnectorShape createConnector() {
    CTConnector sp = _spTree.addNewCxnSp();
    sp.set(XSLFConnectorShape.prototype(_shapeId++));
    XSLFConnectorShape shape = new XSLFConnectorShape(sp, _sheet);
    shape.setAnchor(new Rectangle2D.Double());
    shape.setLineColor(Color.black);
    shape.setLineWidth(0.75);
    return shape;
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) Rectangle2D(java.awt.geom.Rectangle2D)

Example 2 with CTConnector

use of org.openxmlformats.schemas.presentationml.x2006.main.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 3 with CTConnector

use of org.openxmlformats.schemas.presentationml.x2006.main.CTConnector in project poi by apache.

the class XSLFSheet method removeShape.

/**
     * Removes the specified shape from this sheet, if it is present
     * (optional operation).  If this sheet does not contain the element,
     * it is unchanged.
     *
     * @param xShape shape to be removed from this sheet, if present
     * @return <tt>true</tt> if this sheet contained the specified element
     * @throws IllegalArgumentException if the type of the specified shape
     *         is incompatible with this sheet (optional)
     */
public boolean removeShape(XSLFShape xShape) {
    XmlObject obj = xShape.getXmlObject();
    CTGroupShape spTree = getSpTree();
    if (obj instanceof CTShape) {
        spTree.getSpList().remove(obj);
    } else if (obj instanceof CTGroupShape) {
        spTree.getGrpSpList().remove(obj);
    } else if (obj instanceof CTConnector) {
        spTree.getCxnSpList().remove(obj);
    } else if (obj instanceof CTGraphicalObjectFrame) {
        spTree.getGraphicFrameList().remove(obj);
    } else if (obj instanceof CTPicture) {
        XSLFPictureShape ps = (XSLFPictureShape) xShape;
        removePictureRelation(ps);
        spTree.getPicList().remove(obj);
    } else {
        throw new IllegalArgumentException("Unsupported shape: " + xShape);
    }
    return getShapes().remove(xShape);
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) XmlObject(org.apache.xmlbeans.XmlObject) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 4 with CTConnector

use of org.openxmlformats.schemas.presentationml.x2006.main.CTConnector in project poi by apache.

the class XSLFSheet method buildShapes.

protected static List<XSLFShape> buildShapes(CTGroupShape spTree, XSLFSheet sheet) {
    List<XSLFShape> shapes = new ArrayList<XSLFShape>();
    for (XmlObject ch : spTree.selectPath("*")) {
        if (ch instanceof CTShape) {
            // simple shape
            XSLFAutoShape shape = XSLFAutoShape.create((CTShape) ch, sheet);
            shapes.add(shape);
        } else if (ch instanceof CTGroupShape) {
            shapes.add(new XSLFGroupShape((CTGroupShape) ch, sheet));
        } else if (ch instanceof CTConnector) {
            shapes.add(new XSLFConnectorShape((CTConnector) ch, sheet));
        } else if (ch instanceof CTPicture) {
            shapes.add(new XSLFPictureShape((CTPicture) ch, sheet));
        } else if (ch instanceof CTGraphicalObjectFrame) {
            XSLFGraphicFrame shape = XSLFGraphicFrame.create((CTGraphicalObjectFrame) ch, sheet);
            shapes.add(shape);
        }
    }
    return shapes;
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) ArrayList(java.util.ArrayList) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) XmlObject(org.apache.xmlbeans.XmlObject)

Example 5 with CTConnector

use of org.openxmlformats.schemas.presentationml.x2006.main.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)

Aggregations

CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)7 XmlObject (org.apache.xmlbeans.XmlObject)4 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)4 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)4 CTPicture (org.openxmlformats.schemas.presentationml.x2006.main.CTPicture)4 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)4 Rectangle2D (java.awt.geom.Rectangle2D)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 CTConnection (org.openxmlformats.schemas.drawingml.x2006.main.CTConnection)1 CTNonVisualConnectorProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualConnectorProperties)1 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)1 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)1 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)1 CTConnectorNonVisual (org.openxmlformats.schemas.presentationml.x2006.main.CTConnectorNonVisual)1