Home » Eclipse Projects » GEF » [GEF4] connection questions
| |
Re: [GEF4] connection questions [message #1715641 is a reply to message #1715505] |
Tue, 24 November 2015 16:56  |
Eclipse User |
|
|
|
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: Thu Jul 17 09:49:56 EDT 2025
Powered by FUDForum. Page generated in 0.10830 seconds
|