@Override
public ITextDocumentTextShape constructNewTextShape(TextInfo textInfo)
throws TextException {
try {
if (xMultiServiceFactory == null)
throw new TextException(
"OpenOffice.org XMultiServiceFactory interface not valid.");
if (xTextShapeContainer == null)
xTextShapeContainer = (XNameContainer) UnoRuntime
.queryInterface(
XNameContainer.class,
xMultiServiceFactory
.createInstance("com.sun.star.drawing.MarkerTable"));
Object textShape = xMultiServiceFactory.createInstance( "com.sun.star.text.TextFrame" );
XShape xWriterShape = (XShape) UnoRuntime.queryInterface(XShape.class, textShape);
///////
xWriterShape.setSize(new Size(200, 200));
XPropertySet xShapeProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, textShape );
xShapeProps.setPropertyValue("HoriOrient", Short.valueOf(textInfo.getHorizontalAlignment()));
xShapeProps.setPropertyValue("VertOrient", Short.valueOf(textInfo.getVerticalAlignment()));
///////
XTextContent xTextShape = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, textShape);
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextShape);
String tempId = "tempTextShapeId" + System.currentTimeMillis();
xTextShapeContainer.insertByName(tempId, textInfo.getID());
xProps.setPropertyValue("AnchorType", textInfo.getAnchor());
xProps.setPropertyValue("FrameIsAutomaticHeight", Boolean.TRUE);
xProps.setPropertyValue("WidthType", new Short((short)2)); // magic value for automatic width
xProps.setPropertyValue("ContentProtected", Boolean.TRUE );
// xProps.setPropertyValue("BackColor", new Integer(0x11334466));
xProps.setPropertyValue("HoriOrient", Short.valueOf(textInfo.getHorizontalAlignment()));
xProps.setPropertyValue("VertOrient", Short.valueOf(textInfo.getVerticalAlignment()));
xProps.setPropertyValue("BackColor", new Integer(0xffffffff));
xProps.setPropertyValue("BackColorTransparency", new Short(( short ) 100));
ITextDocumentTextShape textDocumentTextShape = new TextDocumentTextShape(
textDocument, xTextShape, textInfo);
////////
XText xShapeText = ( XText ) UnoRuntime.queryInterface(XText.class, textShape);
textDocumentTextShape.setXText(xShapeText);
////////
if (textShapeToTextShapeIds == null)
textShapeToTextShapeIds = new HashMap<ITextDocumentTextShape, String>();
textShapeToTextShapeIds.put(textDocumentTextShape, tempId);
return textDocumentTextShape;
} catch (Exception exception) {
TextException textException = new TextException(exception
.getMessage());
textException.initCause(exception);
throw textException;
}
}