// halo larger than the default so we can click-select connectors
FigureLayer layer = graphicsPane.getForegroundLayer();
layer.setPickHalo(4.0);
// Add the default interactor to both figures
SelectionInteractor si = controller.getSelectionInteractor();
figureA.setInteractor(si);
figureB.setInteractor(si);
figureC.setInteractor(si);
// Add a layer listener to the drag interactor.
// The listener just tells both connectors to reroute themselves.
DragInteractor i = controller.getDragInteractor();
i.addLayerListener(new LayerAdapter() {
public void mouseDragged(LayerEvent e) {
connectorA.reroute();
connectorB.reroute();
connectorC.reroute();
connectorD.reroute();
}
});
// The connector selection interactor uses the same selection model
SelectionInteractor ci = new SelectionInteractor(si.getSelectionModel());
connectorA.setInteractor(ci);
connectorB.setInteractor(ci);
connectorC.setInteractor(ci);
connectorD.setInteractor(ci);
// Tell the selection dragger to select connectors too
controller.getSelectionDragger().addSelectionInteractor(ci);
// Create a manipulator to give resize handles on figures
BoundsManipulator figureManipulator = new BoundsManipulator();
controller.setSelectionManipulator(figureManipulator);
// Make resizing reroute the connectors too
DragInteractor j = figureManipulator.getHandleInteractor();
j.addLayerListener(new LayerAdapter() {
public void mouseDragged(LayerEvent e) {
connectorA.reroute();
connectorB.reroute();
connectorC.reroute();
connectorD.reroute();
}
});
// Create and set up the manipulators for connectors. Straight
// connectors will have an instance of ConnectorManipulator
// attached to them, while arc connectors will have an instance
// of ArcManipulator attached to them.
ConnectorManipulator cManipulator = new ConnectorManipulator();
cManipulator.setSnapHalo(4.0);
cManipulator.setConnectorTarget(target);
ArcManipulator aManipulator = new ArcManipulator();
aManipulator.setSnapHalo(4.0);
aManipulator.setConnectorTarget(target);
TypedDecorator typedDecorator = new TypedDecorator();
typedDecorator.addDecorator(StraightConnector.class, cManipulator);
typedDecorator.addDecorator(ArcConnector.class, aManipulator);
ci.setPrototypeDecorator(typedDecorator);
// In ConnectorTutorial, we used connector listeners to
// illustrate notification call-backs from the manipulator.
// If we were to do that here, we would need a different listener
// for each manipulator. We won't do it, once is enough.