Positionning a border item [message #630235] |
Fri, 01 October 2010 09:35 |
Cedric Moonen Messages: 274 Registered: August 2009 |
Senior Member |
|
|
Hello,
In my diagram, I have a node with child elements on the border (it is a block with input/output ports on the border). To do this, in my gmfgraph, I set the "Affixed parent side" property of my port Node.
When the user add ports on the block figures, the first port is set in the middle of the parent side, then other ports which are added are positionned each time under the last one (if the parent side is WEST). In case the parent side is EAST, the first port is also positionned in the middle of the side, but other ports are posionned above.
I would like my first port to be positionned at the top of the side (with a margin) and other ports under it.
Is there an easy way to do this or do I have to create my own BorderItemLocator ? If I have to override BorderItemLocator, which method do I have to override in order to achieve the desired result ?
The ports won't be selectable, so the user won't be able to move them once they have been created (and they will be created programmatically, depending on the type of block which is created).
Thanks for your help.
|
|
|
Re: Positionning a border item [message #630255 is a reply to message #630235] |
Fri, 01 October 2010 10:37 |
emil salageanu Messages: 94 Registered: June 2010 Location: Nice, France |
Member |
|
|
Hi Cedric,
I have a figure which positions its children on the border. Depending on some information in the child figure I decide which position it should have on the parent's border.
in the parent figure editpart , in the addFixedChild method, I check some conditions on the child, and then I do something like:
int position = findPositionForThisChild(....);
BorderItemLocator locator = new MyCustom_BorderItemlocator(
getMainFigure(), position);
getBorderedFigure().getBorderItemContainer().setConstraint(
newChildFigure, locator);
And then, in my border locator, I position my child exactly in the middle, on the SOUTH or EAST border.
protected Point getPreferredLocation(int side, IFigure borderItem) {
Rectangle bounds = getParentBorder();
int parentFigureWidth = bounds.width;
int parentFigureHeight = bounds.height;
int parentFigureX = bounds.x;
int parentFigureY = bounds.y;
int x = parentFigureX;
int y = parentFigureY;
Dimension borderItemSize = getSize(borderItem);
if (side == PositionConstants.SOUTH) {
x += parentFigureWidth / 2 - borderItemSize.width/2 ;
y = parentFigureY + parentFigureHeight
- getBorderItemOffset().height;
}
else
if (side == PositionConstants.EAST)
{
x += parentFigureWidth - getBorderItemOffset().width;
y += parentFigureHeight /2 - borderItemSize.height/2;
}
return new Point(x, y);
}
I hope it will help,
cheers,
Emil.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03743 seconds