Connector
Contents
[
Hide
]
This article demonstrates how to connect shapes with connectors and change their targets using Aspose.Slides for Android via Java.
Add a Connector
Insert a connector shape between two points on the slide.
static void addConnector() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IConnector connector = slide.getShapes().addConnector(ShapeType.BentConnector2, 0, 0, 100, 100);
} finally {
presentation.dispose();
}
}
Access a Connector
Retrieve the first connector shape added to a slide.
static void accessConnector() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
slide.getShapes().addConnector(ShapeType.BentConnector2, 0, 0, 100, 100);
// Access the first connector on the slide.
IConnector connector = null;
for (IShape shape : slide.getShapes()) {
if (shape instanceof IConnector) {
connector = (IConnector) shape;
break;
}
}
} finally {
presentation.dispose();
}
}
Remove a Connector
Delete a connector from the slide.
static void removeConnector() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IConnector connector = slide.getShapes().addConnector(ShapeType.BentConnector2, 0, 0, 100, 100);
slide.getShapes().remove(connector);
} finally {
presentation.dispose();
}
}
Reconnect Shapes
Attach a connector to two shapes by assigning start and end targets.
static void reconnectShapes() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape1 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 0, 0, 50, 50);
IAutoShape shape2 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 50, 50);
IConnector connector = slide.getShapes().addConnector(ShapeType.BentConnector2, 0, 0, 100, 100);
connector.setStartShapeConnectedTo(shape1);
connector.setEndShapeConnectedTo(shape2);
} finally {
presentation.dispose();
}
}