Class ArcTutorial
- java.lang.Object
-
- diva.canvas.tutorial.ArcTutorial
-
public class ArcTutorial extends java.lang.Object
This tutorial shows how to use "arc" connectors. In this example, the connectors are attached to "perimeter sites" -- that is, sites that can relocated themselves to maintain themselves on the perimeter of an object. Unlike the first connector example, this one does not need to create a special kind of figure, as perimeter sites can attach to any figure that has a rectangle or circle shape.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).
- Version:
- $Id$
- Author:
- John Reekie
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ArcTutorial.SelfPTarget
SelfPTarget is used to find target sites.
-
Constructor Summary
Constructors Constructor Description ArcTutorial()
Create a JCanvas and put it into a window.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 functionvoid
setupInteraction()
Set up the interaction so that the connectors stay glued to the two figures.
-
-
-
Method Detail
-
createFigures
public void createFigures()
Create the figures that we will draw connectors between. This is fairly uninteresting.
-
createConnectors
public void createConnectors()
Create the connectors between the two figures. We will firstly create one StraightConnector with a circle and an arrowhead on it, and then an ArcConnector.
-
setupInteraction
public void setupInteraction()
Set up the interaction so that the connectors stay glued to the two figures. Since BasicController has already set up an interactor for us, we will attach a listener to the drag interactor and just call the connectors to re-route whenever the nmouse moves.
-
main
public static void main(java.lang.String[] argv)
Main function
-
-