Difference between revisions of "API/Samples/Java/Draw/Impress/SDraw"

From Apache OpenOffice Wiki
< API‎ | Samples‎ | Java
Jump to: navigation, search
(Draw document structure)
(Draw document structure)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude>[[Category:API]] [[Category:Samples]] [[Category:Java]] [[Category:Draw]] [[Category:Impress]]</noinclude>
 
 
 
 
 
== Open Drawing documents ==
 
== Open Drawing documents ==
  
you need to specifies the URL of the document to load for loadComponentFromURL() as “private:factory/sdraw”
+
you need to specifiy the URL of the document to load for loadComponentFromURL() as “private:factory/sdraw”
 
+
 
+
  
 
== Draw document structure ==
 
== 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'''.
+
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 '''<idls>com.sun.star.drawing.DrawPage</idls>''' service. Switching to Master View brings up the master page handled by the service '''<idls>com.sun.star.drawing.MasterPage</idls>'''. The Layer View allows access to layers to structure your drawings. These layers can be controlled through '''<idls>com.sun.star.drawing.Layer</idls>''' and '''<idls>com.sun.star.drawing.LayerManager</idls>'''.
  
The com.sun.star.drawing.DrawingDocument service has following interfaces for this purposes:
+
The <idls>com.sun.star.drawing.DrawingDocument</idls> service has following interfaces for this purposes:
  
 
   XDrawPagesSupplier:  
 
   XDrawPagesSupplier:  
Line 20: Line 14:
 
   XStyleFamiliesSupplier:  
 
   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.
+
<idl>com.sun.star.drawing.XDrawPageSupplier</idl> and <idl>com.sun.star.drawing.XMasterPagesSupplier</idl> supplies XDrawPages and <idl>com.sun.star.drawing.MasterPage</idl> via <idl>com.sun.star.container.XIndexAccess</idl>.  
 +
Each DrawPage has support <idl>com.sun.star.drawing.XShapes</idl> interface to manage shapes in this DrawPage.
  
 
The brief summary to access the single shape in Drawing document might be described as:
 
The brief summary to access the single shape in Drawing document might be described as:
Line 28: Line 23:
 
# Call '''getDrawPages()''' method of DrawPagesSupplier to get DrawPages
 
# Call '''getDrawPages()''' method of DrawPagesSupplier to get DrawPages
 
# Querying '''XIndexAccess''' interface of  DrawPages
 
# Querying '''XIndexAccess''' interface of  DrawPages
# Single DrawPage can be accessd through method of '''XIndexAccess: XIndexAccess.getByIndex()'''
+
# Single DrawPage can be accessd through method of <idlm>com.sun.star.container.XXIndexAccess:getByIndex</idlm>
# However, [http://www.openoffice.org/api/docs/common/ref/com/sun/star/container/XIndexAccess.html XIndexAccess.getByIndex()] method returns ANY type, you should querying [http://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/DrawPage.html  XDrawPage] interface before using it.
+
# However, <idlm>com.sun.star.container.XIndexAccess:getByIndex</idlm> method returns ANY type, you should querying <idl>com.sun.star.drawing.DrawPage</idl> interface before using it.
# Going a little bit further, Querying [http://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/XShapes.html XShapesinterface of [http://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/DrawPage.html XDrawPage] to gain access to the list of [http://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/Shapes.html XShape]
+
# Going a little bit further, Querying <idl>com.sun.star.drawing.XShapes</idl> interface of <idl>com.sun.star.drawing.DrawPage</idl> to gain access to the list of <idl>com.sun.star.drawing.Shapes</idl>
  
 
== Shapes ==
 
== Shapes ==
Line 36: Line 31:
 
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.
 
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.
  
<source lang="java">
+
<syntaxhighlight lang="java">
  
 
         //get MSF
 
         //get MSF
Line 58: Line 53:
 
         xShape.setSize(size);
 
         xShape.setSize(size);
 
         xShape.setPosition(position);
 
         xShape.setPosition(position);
</source>
+
</syntaxhighlight>
  
 
ServiceFactory can create several kind of Shape Service, they could be LineShape, PolyLineShape, RectangleShape, TextShape etc.
 
ServiceFactory can create several kind of Shape Service, they could be LineShape, PolyLineShape, RectangleShape, TextShape etc.
Line 66: Line 61:
 
[[Image:ShapeType2.png]]
 
[[Image:ShapeType2.png]]
  
 +
== Example project download ==
 +
 +
[[Image:SDraw.zip]]
  
 
== See Also ==
 
== See Also ==
[http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Drawings/Working_with_Drawing_Documents Working with Drawing Document]
+
*[[API]]
 +
*[[Java]]
 +
*[[Draw]]
 +
*[[Impress]]
  
 
+
[[Category:API]]
== Example project download ==
+
[[Category:Samples]]
 
+
[[Category:Java]]
[[Image:SDraw.zip]]
+
[[Category:Draw]]
 +
[[Category:Impress]]

Latest revision as of 12:26, 31 January 2021

Open Drawing documents

you need to specifiy 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 DrawPage service. Switching to Master View brings up the master page handled by the service MasterPage. The Layer View allows access to layers to structure your drawings. These layers can be controlled through Layer and LayerManager.

The DrawingDocument service has following interfaces for this purposes:

 XDrawPagesSupplier: 
 XMasterPagesSupplier: 
 XLayerSupplier: 
 XStyleFamiliesSupplier: 

com.sun.star.drawing.XDrawPageSupplier and com.sun.star.drawing.XMasterPagesSupplier supplies XDrawPages and com.sun.star.drawing.MasterPage via com.sun.star.container.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 getByIndex
  6. However, getByIndex method returns ANY type, you should querying com.sun.star.drawing.DrawPage interface before using it.
  7. Going a little bit further, Querying com.sun.star.drawing.XShapes interface of com.sun.star.drawing.DrawPage to gain access to the list of com.sun.star.drawing.Shapes

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

Example project download

File:SDraw.zip

See Also

Personal tools