public class GroupShape extends ShapeBase
To learn more, visit the How to Add Group Shape into a Word Document documentation article.
Remarks:
A GroupShape is a composite node and can have Shape and GroupShape nodes as children.
Each GroupShape defines a new coordinate system for its child shapes. The coordinate system is defined using the ShapeBase.getCoordSize() / ShapeBase.setCoordSize(java.awt.Dimension) and ShapeBase.getCoordOrigin() / ShapeBase.setCoordOrigin(java.awt.Point) properties.
Examples:
Shows how to create a group of shapes, and print its contents using a document visitor.
public void groupOfShapes() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// If you need to create "NonPrimitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, DiagonalCornersRounded
// please use DocumentBuilder.InsertShape methods.
Shape balloon = new Shape(doc, ShapeType.BALLOON);
balloon.setWidth(200.0);
balloon.setHeight(200.0);
balloon.setStrokeColor(Color.RED);
Shape cube = new Shape(doc, ShapeType.CUBE);
cube.setWidth(100.0);
cube.setHeight(100.0);
cube.setStrokeColor(Color.BLUE);
GroupShape group = new GroupShape(doc);
group.appendChild(balloon);
group.appendChild(cube);
Assert.assertTrue(group.isGroup());
builder.insertNode(group);
ShapeInfoPrinter printer = new ShapeInfoPrinter();
group.accept(printer);
System.out.println(printer.getText());
}
/// <summary>
/// Prints the contents of a visited shape group to the console.
/// </summary>
public static class ShapeInfoPrinter extends DocumentVisitor {
public ShapeInfoPrinter() {
mBuilder = new StringBuilder();
}
public String getText() {
return mBuilder.toString();
}
public int visitGroupShapeStart(final GroupShape groupShape) {
mBuilder.append("Shape group started:\r\n");
return VisitorAction.CONTINUE;
}
public int visitGroupShapeEnd(final GroupShape groupShape) {
mBuilder.append("End of shape group\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeStart(final Shape shape) {
mBuilder.append("\tShape - " + shape.getShapeType() + ":\r\n");
mBuilder.append("\t\tWidth: " + shape.getWidth() + "\r\n");
mBuilder.append("\t\tHeight: " + shape.getHeight() + "\r\n");
mBuilder.append("\t\tStroke color: " + shape.getStroke().getColor() + "\r\n");
mBuilder.append("\t\tFill color: " + shape.getFill().getForeColor() + "\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeEnd(final Shape shape) {
mBuilder.append("\tEnd of shape\r\n");
return VisitorAction.CONTINUE;
}
private final StringBuilder mBuilder;
}
| Constructor and Description |
|---|
GroupShape(DocumentBase doc)
Creates a new group shape.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(DocumentVisitor visitor)
Accepts a visitor.
|
int |
acceptEnd(DocumentVisitor visitor)
Accepts a visitor for visiting the end of the GroupShape.
|
int |
acceptStart(DocumentVisitor visitor)
Accepts a visitor for visiting the start of the GroupShape.
|
int |
getNodeType()
Returns
NodeType.GROUP_SHAPE. |
adjustWithEffects, canHaveImage, clearRunAttrs, fetchInheritedRunAttr, fetchInheritedShapeAttr, fetchShapeAttr, getAllowOverlap, getAlternativeText, getAnchorLocked, getAspectRatioLocked, getBehindText, getBlur, getBottom, getBounds, getBoundsInPoints, getBoundsWithEffects, getColor, getCoordOrigin, getCoordSize, getDirectRunAttr, getDirectRunAttr, getDirectShapeAttr, getDistance, getDistanceBottom, getDistanceLeft, getDistanceRight, getDistanceTop, getDocument_IInline, getEdgeRadius, getFill, getFillableBackColor, getFillableBackThemeColor, getFillableBackTintAndShade, getFillableBaseForeColor, getFillableForeColor, getFillableForeThemeColor, getFillableForeTintAndShade, getFillableImageBytes, getFillableTransparency, getFillableVisible, getFilledColor, getFillType, getFlipOrientation, getFont, getGlow, getGradientAngle, getGradientStops, getGradientStyle, getGradientVariant, getHeight, getHeightRelative, getHidden, getHorizontalAlignment, getHRef, getLeft, getLeftRelative, getMarkupLanguage, getName, getOldOn, getOldOpacity, getParentParagraph_IInline, getParentParagraph, getPatternType, getPresetTexture, getRadius, getReflection, getReflectionSize, getReflectionTransparency, getRelativeHorizontalPosition, getRelativeHorizontalSize, getRelativeVerticalPosition, getRelativeVerticalSize, getRight, getRotateWithObject, getRotation, getScreenTip, getShadowColors, getShadowFormat, getShadowTransparency, getShadowType, getShapeRenderer, getShapeType, getSizeInPoints, getSoftEdge, getTarget, getTextureAlignment, getTitle, getTop, getTopRelative, getTransparency, getVerticalAlignment, getVisible, getWidth, getWidthRelative, getWrapSide, getWrapType, getZOrder_IShape, getZOrder, isDecorative, isDecorative, isDeleteRevision, isGroup, isHorizontalRule, isImage, isInline, isInsertRevision, isLayoutInCell, isLayoutInCell, isMoveFromRevision, isMoveToRevision, isSignatureLine, isTopLevel, isWordArt, localToParent, oneColorGradient, patterned, presetTextured, removeGlow, removeMoveRevisions, removeReflection, removeRunAttr, removeShadow, removeShapeAttr, removeSoftEdge, setAllowOverlap, setAlternativeText, setAnchorLocked, setAspectRatioLocked, setBehindText, setBlur, setBounds, setColor, setCoordOrigin, setCoordSize, setDistance, setDistanceBottom, setDistanceLeft, setDistanceRight, setDistanceTop, setEdgeRadius, setFillableBackColor, setFillableBackThemeColor, setFillableBackTintAndShade, setFillableForeColor, setFillableForeThemeColor, setFillableForeTintAndShade, setFillableTransparency, setFillableVisible, setFilledColor, setFlipOrientation, setGradientAngle, setHeight, setHeightRelative, setHidden, setHorizontalAlignment, setHRef, setImage, setLeft, setLeftRelative, setName, setOldOn, setOldOpacity, setRadius, setReflectionSize, setReflectionTransparency, setRelativeHorizontalPosition, setRelativeHorizontalSize, setRelativeVerticalPosition, setRelativeVerticalSize, setRotateWithObject, setRotation, setRunAttr, setScreenTip, setShadowColors, setShadowTransparency, setShadowType, setShapeAttr, setTarget, setTextureAlignment, setTitle, setTop, setTopRelative, setTransparency, setVerticalAlignment, setWidth, setWidthRelative, setWrapSide, setWrapType, setZOrder_IShape, setZOrder, solid, twoColorGradientacceptChildren, acceptCore, appendChild, coreRemoveSelfOnly, getChild, getChildNodes, getContainer, getCount, getCurrentNode, getFirstChild, getLastChild, getNextMatchingNode, getText, hasChildNodes, indexOf, insertAfter, insertBefore, isComposite, iterator, prependChild, removeAllChildren, removeChild, removeSmartTags, selectNodes, selectSingleNodedeepClone, getAncestor, getAncestor, getCustomNodeId, getDocument, getNextSibling, getParentNode, getPreviousSibling, getRange, memberwiseClone, nextPreOrder, nodeTypeToString, previousPreOrder, remove, setCustomNodeId, toString, toString, toString, visitorActionToBoolpublic GroupShape(DocumentBase doc)
Remarks:
By default, the shape is floating and has default location and size.
You should specify desired shape properties after you created a shape.
Examples:
Shows how to create a group of shapes, and print its contents using a document visitor.
public void groupOfShapes() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// If you need to create "NonPrimitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, DiagonalCornersRounded
// please use DocumentBuilder.InsertShape methods.
Shape balloon = new Shape(doc, ShapeType.BALLOON);
balloon.setWidth(200.0);
balloon.setHeight(200.0);
balloon.setStrokeColor(Color.RED);
Shape cube = new Shape(doc, ShapeType.CUBE);
cube.setWidth(100.0);
cube.setHeight(100.0);
cube.setStrokeColor(Color.BLUE);
GroupShape group = new GroupShape(doc);
group.appendChild(balloon);
group.appendChild(cube);
Assert.assertTrue(group.isGroup());
builder.insertNode(group);
ShapeInfoPrinter printer = new ShapeInfoPrinter();
group.accept(printer);
System.out.println(printer.getText());
}
/// <summary>
/// Prints the contents of a visited shape group to the console.
/// </summary>
public static class ShapeInfoPrinter extends DocumentVisitor {
public ShapeInfoPrinter() {
mBuilder = new StringBuilder();
}
public String getText() {
return mBuilder.toString();
}
public int visitGroupShapeStart(final GroupShape groupShape) {
mBuilder.append("Shape group started:\r\n");
return VisitorAction.CONTINUE;
}
public int visitGroupShapeEnd(final GroupShape groupShape) {
mBuilder.append("End of shape group\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeStart(final Shape shape) {
mBuilder.append("\tShape - " + shape.getShapeType() + ":\r\n");
mBuilder.append("\t\tWidth: " + shape.getWidth() + "\r\n");
mBuilder.append("\t\tHeight: " + shape.getHeight() + "\r\n");
mBuilder.append("\t\tStroke color: " + shape.getStroke().getColor() + "\r\n");
mBuilder.append("\t\tFill color: " + shape.getFill().getForeColor() + "\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeEnd(final Shape shape) {
mBuilder.append("\tEnd of shape\r\n");
return VisitorAction.CONTINUE;
}
private final StringBuilder mBuilder;
}
doc - The owner document.public boolean accept(DocumentVisitor visitor) throws java.lang.Exception
Remarks:
Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.
For more info see the Visitor design pattern.
Calls DocumentVisitor.visitGroupShapeStart(com.aspose.words.GroupShape), then calls Node.accept(com.aspose.words.DocumentVisitor) for all child shapes of this group shape and calls DocumentVisitor.visitGroupShapeEnd(com.aspose.words.GroupShape) at the end.
Examples:
Shows how to create a group of shapes, and print its contents using a document visitor.
public void groupOfShapes() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// If you need to create "NonPrimitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, DiagonalCornersRounded
// please use DocumentBuilder.InsertShape methods.
Shape balloon = new Shape(doc, ShapeType.BALLOON);
balloon.setWidth(200.0);
balloon.setHeight(200.0);
balloon.setStrokeColor(Color.RED);
Shape cube = new Shape(doc, ShapeType.CUBE);
cube.setWidth(100.0);
cube.setHeight(100.0);
cube.setStrokeColor(Color.BLUE);
GroupShape group = new GroupShape(doc);
group.appendChild(balloon);
group.appendChild(cube);
Assert.assertTrue(group.isGroup());
builder.insertNode(group);
ShapeInfoPrinter printer = new ShapeInfoPrinter();
group.accept(printer);
System.out.println(printer.getText());
}
/// <summary>
/// Prints the contents of a visited shape group to the console.
/// </summary>
public static class ShapeInfoPrinter extends DocumentVisitor {
public ShapeInfoPrinter() {
mBuilder = new StringBuilder();
}
public String getText() {
return mBuilder.toString();
}
public int visitGroupShapeStart(final GroupShape groupShape) {
mBuilder.append("Shape group started:\r\n");
return VisitorAction.CONTINUE;
}
public int visitGroupShapeEnd(final GroupShape groupShape) {
mBuilder.append("End of shape group\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeStart(final Shape shape) {
mBuilder.append("\tShape - " + shape.getShapeType() + ":\r\n");
mBuilder.append("\t\tWidth: " + shape.getWidth() + "\r\n");
mBuilder.append("\t\tHeight: " + shape.getHeight() + "\r\n");
mBuilder.append("\t\tStroke color: " + shape.getStroke().getColor() + "\r\n");
mBuilder.append("\t\tFill color: " + shape.getFill().getForeColor() + "\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeEnd(final Shape shape) {
mBuilder.append("\tEnd of shape\r\n");
return VisitorAction.CONTINUE;
}
private final StringBuilder mBuilder;
}
accept in class Nodevisitor - The visitor that will visit the nodes.DocumentVisitor stopped the operation before visiting all nodes.java.lang.Exceptionpublic int acceptStart(DocumentVisitor visitor) throws java.lang.Exception
Examples:
Shows how to create a group of shapes, and print its contents using a document visitor.
public void groupOfShapes() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// If you need to create "NonPrimitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, DiagonalCornersRounded
// please use DocumentBuilder.InsertShape methods.
Shape balloon = new Shape(doc, ShapeType.BALLOON);
balloon.setWidth(200.0);
balloon.setHeight(200.0);
balloon.setStrokeColor(Color.RED);
Shape cube = new Shape(doc, ShapeType.CUBE);
cube.setWidth(100.0);
cube.setHeight(100.0);
cube.setStrokeColor(Color.BLUE);
GroupShape group = new GroupShape(doc);
group.appendChild(balloon);
group.appendChild(cube);
Assert.assertTrue(group.isGroup());
builder.insertNode(group);
ShapeInfoPrinter printer = new ShapeInfoPrinter();
group.accept(printer);
System.out.println(printer.getText());
}
/// <summary>
/// Prints the contents of a visited shape group to the console.
/// </summary>
public static class ShapeInfoPrinter extends DocumentVisitor {
public ShapeInfoPrinter() {
mBuilder = new StringBuilder();
}
public String getText() {
return mBuilder.toString();
}
public int visitGroupShapeStart(final GroupShape groupShape) {
mBuilder.append("Shape group started:\r\n");
return VisitorAction.CONTINUE;
}
public int visitGroupShapeEnd(final GroupShape groupShape) {
mBuilder.append("End of shape group\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeStart(final Shape shape) {
mBuilder.append("\tShape - " + shape.getShapeType() + ":\r\n");
mBuilder.append("\t\tWidth: " + shape.getWidth() + "\r\n");
mBuilder.append("\t\tHeight: " + shape.getHeight() + "\r\n");
mBuilder.append("\t\tStroke color: " + shape.getStroke().getColor() + "\r\n");
mBuilder.append("\t\tFill color: " + shape.getFill().getForeColor() + "\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeEnd(final Shape shape) {
mBuilder.append("\tEnd of shape\r\n");
return VisitorAction.CONTINUE;
}
private final StringBuilder mBuilder;
}
acceptStart in class CompositeNodevisitor - The document visitor.VisitorAction constants.java.lang.Exceptionpublic int acceptEnd(DocumentVisitor visitor) throws java.lang.Exception
Examples:
Shows how to create a group of shapes, and print its contents using a document visitor.
public void groupOfShapes() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// If you need to create "NonPrimitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, DiagonalCornersRounded
// please use DocumentBuilder.InsertShape methods.
Shape balloon = new Shape(doc, ShapeType.BALLOON);
balloon.setWidth(200.0);
balloon.setHeight(200.0);
balloon.setStrokeColor(Color.RED);
Shape cube = new Shape(doc, ShapeType.CUBE);
cube.setWidth(100.0);
cube.setHeight(100.0);
cube.setStrokeColor(Color.BLUE);
GroupShape group = new GroupShape(doc);
group.appendChild(balloon);
group.appendChild(cube);
Assert.assertTrue(group.isGroup());
builder.insertNode(group);
ShapeInfoPrinter printer = new ShapeInfoPrinter();
group.accept(printer);
System.out.println(printer.getText());
}
/// <summary>
/// Prints the contents of a visited shape group to the console.
/// </summary>
public static class ShapeInfoPrinter extends DocumentVisitor {
public ShapeInfoPrinter() {
mBuilder = new StringBuilder();
}
public String getText() {
return mBuilder.toString();
}
public int visitGroupShapeStart(final GroupShape groupShape) {
mBuilder.append("Shape group started:\r\n");
return VisitorAction.CONTINUE;
}
public int visitGroupShapeEnd(final GroupShape groupShape) {
mBuilder.append("End of shape group\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeStart(final Shape shape) {
mBuilder.append("\tShape - " + shape.getShapeType() + ":\r\n");
mBuilder.append("\t\tWidth: " + shape.getWidth() + "\r\n");
mBuilder.append("\t\tHeight: " + shape.getHeight() + "\r\n");
mBuilder.append("\t\tStroke color: " + shape.getStroke().getColor() + "\r\n");
mBuilder.append("\t\tFill color: " + shape.getFill().getForeColor() + "\r\n");
return VisitorAction.CONTINUE;
}
public int visitShapeEnd(final Shape shape) {
mBuilder.append("\tEnd of shape\r\n");
return VisitorAction.CONTINUE;
}
private final StringBuilder mBuilder;
}
acceptEnd in class CompositeNodevisitor - The document visitor.VisitorAction constants.java.lang.Exceptionpublic int getNodeType()
NodeType.GROUP_SHAPE.
Examples:
Shows how to traverse a composite node's tree of child nodes.
public void recurseChildren() throws Exception {
Document doc = new Document(getMyDir() + "Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
Assert.assertTrue(doc.isComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
traverseAllNodes(doc, 0);
}
/// <summary>
/// Recursively traverses a node tree while printing the type of each node
/// with an indent depending on depth as well as the contents of all inline nodes.
/// </summary>
public void traverseAllNodes(CompositeNode parentNode, int depth) {
for (Node childNode = parentNode.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
System.out.println(MessageFormat.format("{0}{1}", String.format(" ", depth), Node.nodeTypeToString(childNode.getNodeType())));
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode.isComposite()) {
System.out.println();
traverseAllNodes((CompositeNode) childNode, depth + 1);
} else if (childNode instanceof Inline) {
System.out.println(MessageFormat.format(" - \"{0}\"", childNode.getText().trim()));
} else {
System.out.println();
}
}
}
getNodeType in class NodeNodeType.GROUP_SHAPE. The returned value is one of NodeType constants.