|
|
Re: Know the Co-ordinates [message #753673 is a reply to message #753476] |
Fri, 28 October 2011 09:56 |
Maqsood Ahmed Messages: 41 Registered: September 2010 |
Member |
|
|
ContainerShape shapeToMove = (ContainerShape) context.getPictogramElement();
Object obj = getBusinessObjectForPictogramElement(shapeToMove);
if (obj instanceof A || obj instanceof B|| obj instanceof C) {
ContainerShape container = shapeToMove.getContainer();
int containerWidth = container.getGraphicsAlgorithm().getWidth();
int containerHeight = container.getGraphicsAlgorithm().getHeight();
int shapeWidth = shapeToMove.getGraphicsAlgorithm().getWidth();
int shapeHeight = shapeToMove.getGraphicsAlgorithm().getHeight();
int shapeX = context.getX();
int shapeY = context.getY();
EList<Shape> children = container.getChildren();
for (Shape node : children) {
if (node instanceof ContainerShape && node != shapeToMove) {
int nodeX = node.getGraphicsAlgorithm().getX();
int nodeY = node.getGraphicsAlgorithm().getY();
int nodeWitdth = node.getGraphicsAlgorithm().getWidth();
int nodeHeight = node.getGraphicsAlgorithm().getHeight();
if ((nodeY < shapeY && nodeY + nodeHeight > shapeY) || (nodeY > shapeY && shapeY + shapeHeight > nodeY)) {
if (shapeX > nodeX && shapeX < nodeX + nodeWitdth) {
System.out.println("FC == 1");
return false;
}
if (shapeX == nodeX) {
System.out.println("FC == 2");
return false;
}
if (shapeX < nodeX && shapeX + shapeWidth > nodeX) {
System.out.println("FC == 3");
return false;
}
} else if (nodeY == shapeY) {
if (nodeX < shapeX && nodeX + nodeWitdth > shapeX) {
System.out.println("FC == 4");
return false;
}
if (nodeX == shapeX || nodeX + nodeWitdth == shapeX + shapeWidth) {
System.out.println("FC ==5");
return false;
}
if (nodeX > shapeX && shapeX + shapeWidth < nodeX) {
System.out.println("FC == 6");
return false;
}
}
}
}
// move towards right
if ((shapeX + shapeWidth) > containerWidth) {
System.out.println("move Right");
return false;
}
// move towards left
if (shapeX < 0) {
System.out.println("move left");
return false;
}
// move towards bottom
if ((shapeY + shapeHeight) > containerHeight) {
System.out.println("bottom");
return false;
}
// move towards top;
if (shapeY < 30) {
System.out.println("top");
return false;
}
// if (shapeX + shapeWidth < GraphitiUtil.getCurrentGraphicalViewer().getDiagram().getChildren().get(0).getGraphicsAlgorithm().getWidth())
// {
// shapeToMove.getGraphicsAlgorithm().get
// System.out.println("core");
// return false;
// }
return true;
I have put system.out.print.. to knw the co-ordinates while i am holding(moving) the shape inside another shape completely.
Pls note : container is diagram , the above code checks generically if a shapeToMove can be moved to a new position taking into account all other diagram childern.
[Updated on: Fri, 28 October 2011 10:12] Report message to a moderator
|
|
|
|
Re: Know the Co-ordinates [message #753946 is a reply to message #753676] |
Mon, 31 October 2011 06:27 |
Maqsood Ahmed Messages: 41 Registered: September 2010 |
Member |
|
|
Hi Andread,
Thanks for your reply. It was really useful, I din't notice that the was available in the context.
I have adapted accordingly.
Solved
Know the Co-ordinates
Move Shape into another shape completely, check using context.getTargetContainer()
and you can return false where you do not want to allow.
You will have to restrict based on co-ordinates when moving within the same container(adding some padding etc..)
Regards
Mak
[Updated on: Mon, 31 October 2011 06:34] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03344 seconds