I have a java application that maps a relationship between objects. Built
using Swing it consists of JButtons and arrows between them. I am looking
into porting this into powerpoint. I am using Apache POI XSLF to do this.
For each buttons I am creating XSLFPictureShape object to store the button
img and a XSLFTextParagraph to store the button name. I am then using
XSLFConnectorShape to create a connection between a pair of
XSLFPictureShape objects.
The problem I am running into is when I try to group the pictureShape and
the textParagraph into a XSLFGroupShape and then create the connection, the
resulting ppt acts funny by locking some groups and in other groups it does
not update the connection shape or position.

A simple code demo of my problem is as follows:

    XMLSlideShow pptx = new XMLSlideShow();
    XSLFSlide slide = pptx.createSlide();
    XSLFGroupShape group1 = slide.createGroup();
    XSLFAutoShape rect1 = group1.createAutoShape();
    rect1.setShapeType(XSLFShapeType.RECT);
    rect1.setAnchor(new Rectangle(100, 100, 100, 100));
    rect1.setFillColor(Color.blue);
    XSLFTextBox parentTextBox = group1.createTextBox();
    XSLFTextParagraph p = parentTextBox.addNewTextParagraph();
    XSLFTextRun r1 = p.addNewTextRun();
    r1.setText("Box one");
    parentTextBox.setAnchor(new Rectangle(150,150,50,50));

    XSLFGroupShape group2 = slide.createGroup();
    XSLFAutoShape rect2 = group2.createAutoShape();
    rect2.setShapeType(XSLFShapeType.RECT);
    rect2.setAnchor(new Rectangle(300, 300, 100, 100));
    rect2.setFillColor(Color.red);
    XSLFTextBox childTextBox = group2.createTextBox();
    XSLFTextParagraph p1 = childTextBox.addNewTextParagraph();
    XSLFTextRun r2 = p1.addNewTextRun();
    r2.setText("Box two");
    childTextBox.setAnchor(new Rectangle(350,350,50,50));

    XSLFConnectorShape connector1 = slide.createConnector();
    connector1.setAnchor(new Rectangle(200, 150, 100, 200));

    CTConnector ctConnector = (CTConnector)connector1.getXmlObject();
    
ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.STRAIGHT_CONNECTOR_1);
    CTLineEndProperties lineEnd = CTLineEndProperties.Factory.newInstance();
    lineEnd.setType(STLineEndType.TRIANGLE);
    ctConnector.getSpPr().getLn().setTailEnd(lineEnd);
    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);

    FileOutputStream out;
    try {
        out = new FileOutputStream("xslf-connector.pptx");

    pptx.write(out);
    out.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

The connections work fine when I do not add the pictureShape to a group.
But then the text and the picture can no longer be dragged together. Is
this a limitation of the framework?

I tried using Apache POI HSLF but couldn't find a way to create
connections. Any help would be appreciated.


Cheers,


Archie

Reply via email to