API/Samples/Java/Draw/Impress/SDraw

From Apache OpenOffice Wiki
< API‎ | Samples‎ | Java
Jump to: navigation, search



Open Drawing documents

you need to specifies the URL of the document to load for loadComponentFromURL() as “private:factory/sdraw”


Draw document structure

Draw documents maintain their drawing content on draw pages, master pages and layers. If a new draw document is opened, it contains one slide that corresponds to a com.sun.star.drawing.DrawPage service. Switching to Master View brings up the master page handled by the service com.sun.star.drawing.MasterPage. The Layer View allows access to layers to structure your drawings. These layers can be controlled through com.sun.star.drawing.Layer and com.sun.star.drawing.LayerManager.

The com.sun.star.drawing.DrawingDocument service has following interfaces for this purposes:

 XDrawPagesSupplier: 
 XMasterPagesSupplier: 
 XLayerSupplier: 
 XStyleFamiliesSupplier: 

XDrawPagesSupplier and XMasterPagesSupplier supplies XDrawPages and XMasterPages via [XIndexAccess. Each DrawPage has support com.sun.star.drawing.XShapes interface to manage shapes in this DrawPage.

The brief summary to access the single shape in Drawing document might be described as:

  1. Open Drawing document
  2. Querying DrawPagesSupplier interface of Drawing document
  3. Call getDrawPages() method of DrawPagesSupplier to get DrawPages
  4. Querying XIndexAccess interface of DrawPages
  5. Single DrawPage can be accessd through method of XIndexAccess: XIndexAccess.getByIndex()
  6. However, XIndexAccess.getByIndex() method returns ANY type, you should querying XDrawPage interface before using it.
  7. Going a little bit further, Querying XShapes interface of XDrawPage to gain access to the list of XShape

Shapes

Drawings consist of shapes on draw pages. Shapes are drawing elements, such as rectangles, circles, polygons, and lines. To create a drawing, get a shape by its service name at the ServiceFactory of a drawing document and add it to the appropriate DrawPage.

        //get MSF
        com.sun.star.lang.XMultiServiceFactory xDocMSF =
            (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
                com.sun.star.lang.XMultiServiceFactory.class, xDocComp );
 
        ...
 
        oInt = xDocMSF.createInstance("com.sun.star.drawing.EllipseShape");
        xShape = (com.sun.star.drawing.XShape)UnoRuntime.queryInterface(
                    com.sun.star.drawing.XShape.class, oInt);
 
        ...
 
        // set the size and positions
        size.Height = height;
        size.Width = width;
        position.X = x;
        position.Y = y;
        xShape.setSize(size);
        xShape.setPosition(position);

ServiceFactory can create several kind of Shape Service, they could be LineShape, PolyLineShape, RectangleShape, TextShape etc.

ShapeType1.png

ShapeType2.png


See Also

Working with Drawing Document


Example project download

File:SDraw.zip

Personal tools