Home » Eclipse Projects » GEF » [GEF4] connection questions
|
Re: [GEF4] connection questions [message #1715505 is a reply to message #1715358] |
Tue, 24 November 2015 07:55 |
|
1) Yes, IContentPart is bound to some content. That's needed for creation, synchronization, and lookup. If there is no such content, you could e.g. use a Pair to represent your connection.
2) You can bind a Provider<IAnchor> to your node parts, which can then be used by the connections in their attachToAnchorageVisual() to retrieve an anchor (the logo example demonstrates this). The Provider would have to provide a respective Anchor. You could most easily tweak the ChopBoxAnchor to return the nearest border middle point (the computation strategy is exchangeable) as anchor position.
3) Connection (i.e. the visual node) currently is implemented for bi-directional connections only. On the level of visual parts (controller) the question of whether to use a single controller or not pretty much depends on how interaction is to be handled. If you want to interact which each "segment" on its own, that probably several controllers are the better choice.
|
|
|
Re: [GEF4] connection questions [message #1715641 is a reply to message #1715505] |
Tue, 24 November 2015 21:56 |
Frank Benoit Messages: 179 Registered: July 2009 |
Senior Member |
|
|
Hi
i copied ChopBoxProvider and changed it as SideAnchorProvider
When I just compare the location of the parts, it get weired results, because in the beginning, the positions are not yet layed out. I need to understand layout first, other story
Instead, I want to compute the anchorage point by the role given. As this seems to me the right solution.
In TextNode getContentAnchorages()
@Override
public SetMultimap<TextNode, String> getContentAnchorages() {
HashMultimap<TextNode, String> res = HashMultimap.create();
res.put(getContent(), "START");
res.put(getContent(), "END");
return res;
}
In TextNodeRelation (the part for the connection) getContentAnchorages()
@Override
public SetMultimap<? extends Object, String> getContentAnchorages() {
HashMultimap<Object, String> res = HashMultimap.create();
TextNodeRelation nr = getContent();
res.put( nr.getParent(), "START");
res.put( nr.getChild(), "END");
return res;
}
I use this code to get the roles.
public class SideAnchorProvider implements Provider<IAnchor>, IAdaptable.Bound<IVisualPart<Node, ? extends Node>> {
private ChopBoxAnchor.IComputationStrategy strategy = new ChopBoxAnchor.IComputationStrategy(){
@Override
public Point computePositionInScene(Node anchorage, Node anchored, Point anchoredReferencePointInLocal) {
Map<Node, IVisualPart<Node, ? extends Node>> partMap = visualPart.getRoot().getViewer().getVisualPartMap();
IVisualPart<Node, ? extends Node> anchoredPart = partMap.get(anchored);
IVisualPart<Node, ? extends Node> anchoragePart = partMap.get(anchorage);
String role = anchoredPart.getAnchorages()
.get(anchoragePart)
.iterator().next();
if( "START".equals(role) ){
Bounds bnds = anchorage.getBoundsInLocal();
bnds = anchorage.localToScene(bnds);
return new Point( bnds.getMaxX(), bnds.getMinY() + bnds.getHeight() /2 );
}
if( "END".equals(role) ){
Bounds bnds = anchorage.getBoundsInLocal();
bnds = anchorage.localToScene(bnds);
return new Point( bnds.getMinX(), bnds.getMinY() + bnds.getHeight() /2 );
}
throw new RuntimeException();
}
};
@Override
public IAnchor get() {
if (anchor == null) {
anchor = new ChopBoxAnchor(getAdaptable().getVisual(), strategy );
}
return anchor;
}
@Override
public IVisualPart<Node, ? extends Node> getAdaptable() {
return visualPart;
}
@Override
public void setAdaptable(IVisualPart<Node, ? extends Node> adaptable) {
this.visualPart = adaptable;
}
}
My question is:
Is this a recommended way to handle this?
With the customized router in TextNodeRelation createVisual():
visual.setRouter(new IConnectionRouter(){
@Override
public ICurve routeConnection(Point[] points) {
if (points == null || points.length < 2) {
return new Line(0, 0, 0, 0);
}
if( points.length > 2 ) throw new RuntimeException("len: "+points.length);
Point start = ( points[0].x < points[1].x ) ? points[0] : points[1];
Point end = ( points[0].x > points[1].x ) ? points[0] : points[1];
Point p1 = new Point( start.x + HSPACE, start.y );
Point p2 = new Point( start.x + HSPACE, end.y );
Polyline poly = new Polyline(start, p1, p2, end );
return poly;
}
});
it look now as expected.
thx
Frank
|
|
|
Goto Forum:
Current Time: Sat Apr 27 01:13:27 GMT 2024
Powered by FUDForum. Page generated in 0.03363 seconds
|