Border item positioning (fixed relative to parent figure) [message #138456] |
Thu, 21 June 2007 16:23  |
Eclipse User |
|
|
|
Originally posted by: jacob.barde.swri.org
I have some [parent] figures I am trying to have their ports (child
figures) located at specific coordinates around the parent.
I have overridden the parentEditPart's addBorderItem(...) method so as
to position the port at least on the correct side of the parent figure.
However the default placement (the middle of the side), simply won't do.
E.g. as it is now, a figure is drawn on the canvas as this (i = input
port, o = output port):
o
---------
| |
i| |
| |
---------
o
And what I need is to have these ports at specific locations:
o <-- at a set coordinate (validLocation?)
---------
| |
i| |
| |
---------
o
I've been working with locator.setConstraint(...) to no avail, is this
where I should be concerned with for this feature?
tips and/or snippets would be much appreciated.
__________ parentEditPart snippet _______________
protected void addBorderItem(IFigure borderItemContainer,
IBorderItemEditPart borderItemEditPart) {
IFigure parentFig = getMainFigure();
Rectangle parentRect = parentFig.getBounds();
opCount++;
if(borderItemEditPart instanceof InputPortEditPart) {
BorderItemLocator locator = new BorderItemLocator(parentFig,
PositionConstants.WEST);
locator.setBorderItemOffset(new Dimension(0, 0));
borderItemContainer.add(borderItemEditPart.getFigure(),
locator);
} else if(borderItemEditPart instanceof OutputPortEditPart) {
BorderItemLocator locator = null;
if(opCount % 2 == 0) {
locator = new BorderItemLocator(parentFig,
PositionConstants.NORTH);
} else {
locator = new BorderItemLocator(parentFig,
PositionConstants.SOUTH);
}
locator.setBorderItemOffset(new Dimension(0, 0));
locator.setConstraint(parentRect);
borderItemContainer.add(borderItemEditPart.getFigure(),
locator);
} else {
super.addBorderItem(borderItemContainer, borderItemEditPart);
}
}
|
|
|
Re: Border item positioning (fixed relative to parent figure) [message #138681 is a reply to message #138456] |
Fri, 22 June 2007 08:50  |
Eclipse User |
|
|
|
Jacob,
I would suggest writing your own locator for the border items. You may
be able to subclass BorderItemLocator, but it may be just as easy to
write from scratch. You can also look at existing implementors of the
Locator interface to see if there is another locator out there that
could be of use to you.
You probably want to implement IBorderItemLocator as well, but you can
read its javadoc to see where it is used.
I hope this helps.
- Cherie
Jacob Barde wrote:
> I have some [parent] figures I am trying to have their ports (child
> figures) located at specific coordinates around the parent.
>
> I have overridden the parentEditPart's addBorderItem(...) method so as
> to position the port at least on the correct side of the parent figure.
> However the default placement (the middle of the side), simply won't do.
>
> E.g. as it is now, a figure is drawn on the canvas as this (i = input
> port, o = output port):
>
> o
> ---------
> | |
> i| |
> | |
> ---------
> o
>
> And what I need is to have these ports at specific locations:
>
> o <-- at a set coordinate (validLocation?)
> ---------
> | |
> i| |
> | |
> ---------
> o
>
> I've been working with locator.setConstraint(...) to no avail, is this
> where I should be concerned with for this feature?
>
> tips and/or snippets would be much appreciated.
>
>
>
> __________ parentEditPart snippet _______________
>
> protected void addBorderItem(IFigure borderItemContainer,
> IBorderItemEditPart borderItemEditPart) {
>
> IFigure parentFig = getMainFigure();
> Rectangle parentRect = parentFig.getBounds();
>
> opCount++;
>
> if(borderItemEditPart instanceof InputPortEditPart) {
> BorderItemLocator locator = new BorderItemLocator(parentFig,
> PositionConstants.WEST);
> locator.setBorderItemOffset(new Dimension(0, 0));
> borderItemContainer.add(borderItemEditPart.getFigure(),
> locator);
>
> } else if(borderItemEditPart instanceof OutputPortEditPart) {
> BorderItemLocator locator = null;
> if(opCount % 2 == 0) {
> locator = new BorderItemLocator(parentFig,
> PositionConstants.NORTH);
> } else {
> locator = new BorderItemLocator(parentFig,
> PositionConstants.SOUTH);
> }
> locator.setBorderItemOffset(new Dimension(0, 0));
> locator.setConstraint(parentRect);
> borderItemContainer.add(borderItemEditPart.getFigure(),
> locator);
> } else {
> super.addBorderItem(borderItemContainer, borderItemEditPart);
> }
> }
|
|
|
Powered by
FUDForum. Page generated in 0.04049 seconds