Continuing issues with BoxRelativeAnchor [message #799351] |
Wed, 15 February 2012 19:36 |
Josef Pohl Messages: 82 Registered: January 2012 |
Member |
|
|
Hi all,
Sorry to harp on this a bit more but I am continuing to struggle with some odd behavior on BoxRelativeAnchors.
So to give a bit of background:
I have a inivisible rectangle with a nested polygon.
I want the Connection features to connect directly to the polygon, not to the outer invisible rectangle.
To do this I instantiated a BoxRelativeAnchor that is held on another polygon of the same size and shape.
Here is the code from the Add Feature, where containerShape is the outer PE containing all elements, p is the polygon GA, and polyxy is the array holding the point by point definition of p and here pbox.
BoxRelativeAnchor box = peCreateService.createBoxRelativeAnchor(containerShape);
box.setRelativeWidth(0.0);
box.setRelativeHeight(0.0);
box.setReferencedGraphicsAlgorithm(p);
Polygon pbox = gaService.createPolygon(box, polyxy);
pbox.setLineVisible(false);
pbox.setFilled(false);
gaService.setLocationAndSize(pbox, 0 , 0, width, height);
// call the layout feature
layoutPictogramElement(containerShape);
return containerShape;
The observed behavior from this is that when I select on the polygon itself I do not get the selection box that you would expect, namely the one that defines the container shape allowing me to resize and move the container. I get a box that is related to the BoxRelativeAnchor. (see first attached image)
I make connections to this feature and I can select it (by clicking in the polygon)
and move it independently of the rest of the feature. (Although only within the limits of the outer container.) (see second attached image)
Try as I might I have not been able to turn off the selection of this box or to pass it back up the chain.
Is there something I am missing here in the way the BoxRelativeAnchor relates to the outer containerShape?
Is there no way to turn off the selection of the BoxRelativeAnchor? Or better yet, simply couple it with the outer containerShape or the visible polygon?
Here are the relevant portions of my ToolBehaviorProvider. The getSelection code is kind of worthless as it does not do what I would have thought. And the BoxRelative stuff in the other methods does not provide any additional behavior changes.
@Override
public GraphicsAlgorithm[] getClickArea(PictogramElement pe) {
IFeatureProvider featureProvider = getFeatureProvider();
Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);
if (pe instanceof BoxRelativeAnchor){
if(bo == null){
BoxRelativeAnchor bra = (BoxRelativeAnchor) pe;
GraphicsAlgorithm ga = bra.getReferencedGraphicsAlgorithm();
ContainerShape cs = (ContainerShape) ga.getPictogramElement();
bo = featureProvider.getBusinessObjectForPictogramElement(cs);
// return new GraphicsAlgorithm[] {ga};
}
}
if (bo instanceof Goal) {
GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
GraphicsAlgorithm rectangle = invisible.getGraphicsAlgorithmChildren().get(0);
return new GraphicsAlgorithm[] { rectangle };
}
else if (bo instanceof Strategy) {
//System.out.println("At strategy Area");
GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
GraphicsAlgorithm parallel = invisible.getGraphicsAlgorithmChildren().get(0);
GraphicsAlgorithm anchorbox = null;
if(pe instanceof ContainerShape){
if(pe instanceof AnchorContainer){
EList<Anchor> alist = ((ContainerShape) pe).getAnchors();
Anchor anch = alist.get(0);
anchorbox = anch.getGraphicsAlgorithm();
}
}
return new GraphicsAlgorithm[] {parallel, anchorbox};
}
return super.getClickArea(pe);
}
@Override
public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
IFeatureProvider featureProvider = getFeatureProvider();
Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);
if (pe instanceof BoxRelativeAnchor){
System.out.println("Box found");
if(bo == null){
System.out.println("\t and Null");
BoxRelativeAnchor bra = (BoxRelativeAnchor) pe;
GraphicsAlgorithm ga = bra.getReferencedGraphicsAlgorithm();
ContainerShape cs = (ContainerShape) ga.getPictogramElement();
bo = featureProvider.getBusinessObjectForPictogramElement(cs);
// return new GraphicsAlgorithm[] {ga};
}
}
if (bo instanceof Goal) {
GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
EList<GraphicsAlgorithm> graphicsAlgorithmChildren = invisible.getGraphicsAlgorithmChildren();
if (!graphicsAlgorithmChildren.isEmpty()) {
return graphicsAlgorithmChildren.get(0);
}
}
else if (bo instanceof Strategy) {
GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
EList<GraphicsAlgorithm> graphicsAlgorithmChildren = invisible.getGraphicsAlgorithmChildren();
if (!graphicsAlgorithmChildren.isEmpty()) {
return graphicsAlgorithmChildren.get(0);
}
}
return super.getSelectionBorder(pe);
}
@Override
public PictogramElement getSelection(PictogramElement originalPe, PictogramElement[] oldSelection){
GraphicsAlgorithm ga = originalPe.getGraphicsAlgorithm();
System.out.println("Original GA: " + ga.getClass());
if(ga.getLineVisible()){
System.out.println("\t visible");
}
IFeatureProvider featureProvider = getFeatureProvider();
if (originalPe instanceof ContainerShape){
Object bo = featureProvider.getBusinessObjectForPictogramElement(originalPe);
if(bo instanceof Strategy){
EList<Anchor> alist = ((ContainerShape) originalPe).getAnchors();
if(alist != null){
if(alist.get(0) instanceof BoxRelativeAnchor){
System.out.println("Found BRA");
BoxRelativeAnchor bra = (BoxRelativeAnchor) alist.get(0);
GraphicsAlgorithm gaBra = bra.getReferencedGraphicsAlgorithm();
return gaBra.getPictogramElement();
}
}
}
}
return null;
}
Thanks everyone.
Joe
-
Attachment: odd_box.png
(Size: 11.89KB, Downloaded 448 times) -
Attachment: snapshot2.png
(Size: 7.38KB, Downloaded 459 times)
|
|
|
|
Powered by
FUDForum. Page generated in 0.03376 seconds