public class ArcTutorial
extends java.lang.Object
The code to create the connectors and set up the interaction is much the same as the previous tutorial, except that it uses ArcConnectors instead of StraightConnectors. One noticeable difference is that the connector target uses a a sub-class of the off-the-shelf PerimeterTarget class provided with the Diva canvas. Although this would work:
ConnectorTarget target = new PerimeterTarget();we use a subclass that allows "self-loops." In other words, the default behaviour of targets is not to allow a connection back to the same object; the inner class in this example does allow this.
A second difference is that the initialization of the manipulators is more complicated. Because there are two different kinds of connectors, and we want different manipulators for each, we use an instance of the TypedDecorator class to set this up:
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);A different way to get the same effect would be to use two different SelectionInteractors, one for the arcs with an ArcManipulator and one for the StraightConnectors with a ConnectorManipulator. (Currently, the ArcManipulator looks the same as the ConnectorManipulator, but in the near future it will have additional grab-handles for reshaping the arc.)
To make this example a little more interesting, selected figures have resize handles attached to them. As the figure is resized, attached connectors change accordingly. This tutorial also illustrates the use of the TypedDecorator class to attach different kinds of manipulators to different kinds of figures (in this case, different kinds of connectors).
Modifier and Type | Class and Description |
---|---|
static class |
ArcTutorial.SelfPTarget
SelfPTarget is used to find target sites.
|
Constructor and Description |
---|
ArcTutorial()
Create a JCanvas and put it into a window.
|
Modifier and Type | Method and Description |
---|---|
void |
createConnectors()
Create the connectors between the two figures.
|
void |
createFigures()
Create the figures that we will draw connectors between.
|
static void |
main(java.lang.String[] argv)
Main function
|
void |
setupInteraction()
Set up the interaction so that the connectors stay glued to
the two figures.
|
public void createFigures()
public void createConnectors()
public void setupInteraction()
public static void main(java.lang.String[] argv)