Key Features of Shapes and Groups

All shapes and groups share these common attributes, provided by the ShapeOrGroup superclass:

Navigation

All shapes and groups are placed within a parent container, which is either a page or a group.

This method will return the parent container that the shape or group resides within:

ShapeContainer getParent()

Alternatively, the following method will always return the page, irrespective of the grouping, if any. This is useful if you don't know whether the parent container is a page or a group:

Page getPage()

Cut, Copy and Paste

All shapes and groups can be cut or copied, and then pasted into any group or page.

To copy a shape or group use:

Clipboard copy()

To cut a shape or group use:

Clipboard cut()

Please note that an object's absolute coordinates (see Bounding boxes and coordinates below) are preserved when it is cut or copied and pasted. This means that if you cut a shape or group from one group and paste it into another, its visual appearance will remain constant.

Size, Position and Rotation

Sizing, positioning and rotation sets where a shape or group lives on a page (or within another group). The methods related to sizing and positioning are some of the most commonly used of all methods.

Every shape or group has a default size (usually about 1" by 1") and position (at the top left corner of the page) when created. Therefore you will almost always need to set its size and position (and rotation if required) on the page.

You change an object's size and position by setting the coordinates of its bounding box (see 'Bounding Boxes and Coordinates' below). You change an object's rotation by setting its rotation property (see the Rotation section later in this chapter).

Bounding boxes and coordinates

All shapes and groups have a bounding box, which defines the position and size of the object. The bounding box specifies the coordinates (x- and y-axis) of an object's top left corner together with its height and width.

The coordinate system of each page originates from its top left corner, with the positive x-axis stretching to the right and the positive y-axis stretching downward. All coordinates are specified in Master Units (576 Master Units equal 1 inch).

Absolute coordinates reflect the page coordinate system. Therefore an object's absolute coordinates define its size and position relative to the page.

Relative coordinates reflect a container's coordinate system. Therefore an object's relative coordinates define its size and position relative to its parent container.

Shapes and groups' bounding box are specified in relative coordinates. Given this, if a shape or group stands alone (i.e. the parent container is the page) then its absolute and relative coordinates are the same.

Alternatively, if a shape or group is contained in a group then its bounding box coordinates are relative to the containing group's coordinate system (for more information see Group Coordinate System in the Working with Groups chapter later in this Guide). This can be a little confusing until you play with it a bit. In essence the group bounding box and group coordinates specify a transformation applied to the shapes coordinates. The main advantage of this approach is that it is easy to move or stretch all the shapes within a group, because you only need to change the bounding box of the group and not every object with in it. Since the contained shapes are relative to the group, if you move the group, you move the contents.

Size and position

The bounding box of a shape or group is always specified relative to its parent container. Unless the object is within a group, the parent container is always the page. A bounding box is always represented as if the object has no rotation, i.e. its rotation is at 0 degrees. (See the 'Rotation' section below).

To get the bounds of any shape or group use:

java.awt.Rectangle getBounds()

To set the bounds (change the size and position) of any shape of group use:

void setBounds(java.awt.Rectangle rect)

Manipulating a group as a whole does not change the relative bounds of the individual objects, as returned by getBounds(), within the group. However, if an object is within a group, its absolute and relative coordinates may be different. The getBounds() method will return the object's coordinates relative to its parent container, whereas the getAbsoluteCoords() method (below) will return the object's coordinates relative to the page.

To get the absolute coordinates a shape or group use:

java.awt.Rectangle getAbsoluteCoords()

Rotation

A shape or group can also be rotated. An object is always rotated around the centre of its bounding box. An object's rotation is also defined in terms of relative rotation, i.e. relative to its container.

To either retrieve or apply a (relative) rotation to an object you use its rotation property (see the 'Properties' section below).

To get an object's absolute rotation use:

double getAbsoluteRotation()

Properties

Properties allow you to change the appearance of a shape or group and include fill, line, rotation, alt text, text properties, etc.

Some properties are stand-alone and some work as a set. That is, to achieve a certain effect, you need to set more than one property. For example setting the fill color has no effect unless the shape is also set to have a fill.

Most properties apply only to shapes, however, there are some that also apply to groups. The ShapeProperties interface defines all the supported properties and their value constants, where appropriate. The full list of properties currently supported in the library includes:

Properties applying to both groups and shapes

Property

Type

Description

ALT_TEXT

String

The alternate text

TRANSFORM_ROTATION

Double

The rotation of a shape or group, in degrees, where 0 <= rotation <360

Protection properties (shapes only)

This set of properties sets whether various editing capabilities are enabled in PowerPoint. They do not have any effect when working within the library.

Property

Type

Description

LOCK_AGAINST_SELECT

Boolean

Whether the shape may be selected. If a shape cannot be selected in PowerPoint, it cannot be edited

Fill properties (shapes only)

This set of properties defines the type, color and style of the filled area of a shape. Note that generally you need to enable fills (using FILL), select the desired type of fill (using FILL_TYPE) and then set any specific fill properties.

Property

Type

Description

FILL

Boolean

Specifies whether the shape is filled

FILL_TYPE

Integer

Specifies the fill type (one of FILL_TYPE_*). Fill types include solid, pattern, texture, picture, shade and background

FILL_COLOR

PPColor

Specifies the fill color to be used for solid fills

FILL_OPACITY

Double

Specifies how opaque the fill color is (from 0 to 1)

FILL_BACK_COLOR

PPColor

Specifies the background fill color, used for pattern or texture fills

FILL_BACK_OPACITY

Double

Specifies how opaque the background fill color is (from 0 to 1)

FILL_PICTURE

Integer

Specifies the index of the picture used as a fill for this shape. Zero indicates no picture

Line properties (shapes only)

This set of properties defines types, colors and styles of the lines bordering a shape. Note that generally you need to enable lines (using LINE), select the type of line (using LINE_TYPE) and then set any specific line.

Property

Type

Description

LINE

Boolean

Specifies whether the shape has a border

LINE_TYPE

Integer

Specifies the line type (one of LINE_TYPE_*). Line types include solid, pattern, texture and picture

LINE_STYLE

Integer

Specifies the line style (one of LINE_STYLE_*). Line styles include simple (single line), double, thick-thin, thin-thick, triple

LINE_WIDTH

Integer

Specifies the line width (in EMUs)

LINE_COLOR

PPColor

Specifies the line color

LINE_BACK_COLOR

PPColor

Specifies the background line color

LINE_DASHING

Integer

Specifies the line dashing style (one of LINE_DASHING_*). Line dashing styles include dashing solid (a solid pen dash), system dash, system dot, system dash-dot, system dash-dot-dot, dots, dashes, long dashes, dash-dot, long dash-dot, long dash-dot-dot,

LINE_END

Integer

Specifies the line end style (one of LINE_END_*). Line end styles include no line ending, arrow (isosceles triangle), stealth (arrow with a notch in black), diamond, oval, open (an unfilled arrow), and small, medium and large line-end lengths.

LINE_END_WIDTH

Integer

Specifies the line end width (one of LINE_END_SIZE_*)

LINE_END_LENGTH

Integer

Specifies the line end length (one of LINE_END_SIZE_*)

LINE_START

Integer

Specifies the line end style (one of LINE_END_*)

LINE_START_WIDTH

Integer

Specifies the line end width (one of LINE_END_SIZE_*)

LINE_START_LENGTH

Integer

Specifies the line end length (one of LINE_END_SIZE_*)

Picture properties (shape only)

This set of properties defines the picture index to be used in a shape and whether the picture has any cropping applied.

Property

Type

Description

PICTURE

Integer

Specifies the index of the picture in this shape, zero if none

PICTURE_NAME

String

Specifies the name of the picture in this shape

PICTURE_CROP_BOTTOM

Double

Specifies the fraction of the height to crop from the bottom

PICTURE_CROP_TOP

Double

Specifies the fraction of the height to crop from the top

PICTURE_CROP_LEFT

Double

Specifies the fraction of the width to crop from the left

PICTURE_CROP_RIGHT

Double

Specifies the fraction of the width to crop from the right

PICTURE_FLAGS

Integer

Specifies picture flags describing: (a) the value of PICTURE_NAME, (PICTURE_FLAG_COMMENT, PICTURE_FLAG_FILE or PICTURE_FLAG_URL) and (b) whether the picture is linked (PICTURE_FLAG_LINK_TO_FILE) or embedded (0)

Text properties (shape only)

This set of properties defines the anchor point, margins, flow, rotation and wrapping of text in a shape.

Property

Type

Description

TEXT_ANCHOR

Integer

Specifies the text anchor point (one of TEXT_ANCHOR_*)

TEXT_MARGIN_BOTTOM

Integer

Specifies the bottom text margin (in EMUs)

TEXT_MARGIN_LEFT

Integer

Specifies the left text margin (in EMUs)

TEXT_MARGIN_RIGHT

Integer

Specifies the right text margin (in EMUs)

TEXT_MARGIN_TOP

Integer

Specifies the top text margin (in EMUs)

TEXT_FLOW

Integer

Specifies the direction of text flow (one of TEXT_FLOW_*}

TEXT_ROTATION

Integer

Specifies the text rotation relative to its shape (from 0 to 3)

TEXT_WRAP

Integer

Specifies the text wrapping mode (one of TEXT_WRAP_*)

TEXT_FIT_SHAPE_TO_TEXT

Boolean

Specifies whether to resize shape to fit text (does not change shape bounds)

Geometry properties (shape only)

These settings are specified in 'geo coordinates'. The geo coordinate space is an abstract coordinate space that is ultimately mapped to the actual shape bounds. When setting the adjustment handles, they are specified relative to the geo bounding box, obtained from the GEO_* properties. It is recommended to treat the GEO_* properties as read only.

Property

Type

Description

ADJUST_VALUE

Integer

The first shape adjustment handle, specified in geo coordinates

ADJUST_VALUE_2

Integer

The second shape adjustment handle, specified in geo coordinates

ADJUST_VALUE_3

Integer

The third shape adjustment handle, specified in geo coordinates

GEO_BOTTOM

Integer

The bottom edge of the shape bounds specified in geo coordinates (read-only)

GEO_LEFT

Integer

The left edge of the shape bounds specified in geo coordinates (read-only)

GEO_RIGHT

Integer

The right edge of the shape bounds specified in geo coordinates (read-only)

GEO_TOP

Integer

The top edge of the shape bounds specified in geo coordinates (read-only)

Shadow style properties (shape only)

This set of properties defines any shadowing to be applied to the shape.

Property

Type

Description

SHADOW

Boolean

Whether the shape has a shadow

SHADOW_COLOR

PPColor

The color to be used for the shadow

SHADOW_OFFSET_X

Integer

The x-offset at which to position the shadow (in EMUs)

SHADOW_OFFSET_Y

Integer

The y-offset at which to position the shadow (in EMUs)

Working with properties

The methods for working with an object's properties provide quite a low-level interface to PowerPoint, often allowing you to access and set properties that are not supported in PowerPoint. This allows you to work with many possible combinations to change the appearance of objects.

If you are working with combinations that PowerPoint doesn't support by default, test these thoroughly to ensure you get the results you intended.

To set a property on any shape or group, you supply the property key and desired value. The value must be of the correct type as listed in the tables above.

To set a shape property use:

void set(int property, java.lang.Object value)

To get a shape property use:

java.lang.Object get(int property)

Ordering

Changing the order of a shape or group on a page (or in a group) allows you to determine which objects are on top and which are underneath. Every object has an order, even though the ordering is only observable when shapes or groups overlap.

The order(int) method allows you to change the order of an object within its container (e.g. the order of shapes and/or groups on a page or the order of shapes and/or groups within a group) by specifying an order direction.

To order an object use:

void order(int direction)

You will need to provide one of the following order directions. These reflect the order paradigm used in PowerPoint, i.e. you can move the object one level backward or forward in the order hierarchy or move it to the back or front.

ShapeOrGroup.ORDER_BACKWARD
ShapeOrGroup.ORDER_FORWARD
ShapeOrGroup.ORDER_TO_BACK
ShapeOrGroup.ORDER_TO_FRONT

Flipping

A shape or group can be flipped horizontally or vertically. The bounds of an object are not affected if it is flipped.

To check if an object has been flipped horizontally use (method returns true if the object is flipped):

boolean isFlippedHorizontal()

To set an object to flip horizontally use:

void setFlippedHorizontal(boolean flipped)

To check if an object has been flipped vertically use (method returns true if the object is flipped):

boolean isFlippedVertical()

To set an object to flip vertically use:

void setFlippedVertical(boolean flipped)

Page generated: 2008-01-18 02:53:28 GMT TonicPoint Builder Developer's Guide -- Version 2.3