Search connection under mouse [message #210393] |
Mon, 27 February 2006 14:16 |
Eclipse User |
|
|
|
Originally posted by: fangrey.mail.ru
How I can determine, is mouse pointer locate in the neighbourhood of connection?
I thus far make as follows:
IFigure connectionLayer = ((ScalableFreeformRootEditPart) (getCurrentViewer().getRootEditPart())).
getLayer(LayerConstants.CONNECTION_LAYER);
int delta = 5;
IFigure findingFigure = null;
int xScale = 0;
int yScale = 0;
for (int i = -delta; i <= delta; i++) {
for (int j = -delta; j <= delta; j++) {
Point relativePosition = getLocation();
findingFigure = connectionLayer.findFigureAt(relativePosition.x + i, relativePosition.y + j);
if (findingFigure != null) {
yScale = j;
break;
}
}
if (findingFigure != null) {
xScale = i;
break;
}
}
if (findingFigure != null && findingFigure instanceof PolylineConnection) {
Object findingEditPart = getCurrentViewer(). findObjectAt(new Point(getLocation().x + xScale,
getLocation().y + yScale));
}
But this solution does not work with the scaled images
|
|
|
Re: Search connection under mouse [message #210405 is a reply to message #210393] |
Mon, 27 February 2006 19:32 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
Connections already have a delta +/- (2 + 1/2 linewidth) pixels (at 100%).
If you want this to be bigger, you could make the width of the line larger,
but paint at a smaller width. You could also override containsPoint to make
the threshold larger.
Your for loop has some issues.
"FanGrey" <fangrey@mail.ru> wrote in message
news:13779333.1141049833123.JavaMail.root@cp1.javalobby.org...
> How I can determine, is mouse pointer locate in the neighbourhood of
> connection?
> I thus far make as follows:
>
> IFigure connectionLayer = ((ScalableFreeformRootEditPart)
> (getCurrentViewer().getRootEditPart())).
> getLayer(LayerConstants.CONNECTION_LAYER);
> int delta = 5;
> IFigure findingFigure = null;
> int xScale = 0;
> int yScale = 0;
> for (int i = -delta; i <= delta; i++) {
> for (int j = -delta; j <= delta; j++) {
> Point relativePosition = getLocation();
> findingFigure = connectionLayer.findFigureAt(relativePosition.x + i,
> relativePosition.y + j);
> if (findingFigure != null) {
> yScale = j;
> break;
> }
> }
> if (findingFigure != null) {
> xScale = i;
> break;
> }
> }
> if (findingFigure != null && findingFigure instanceof PolylineConnection)
> {
> Object findingEditPart = getCurrentViewer(). findObjectAt(new
> Point(getLocation().x + xScale,
> getLocation().y + yScale));
> }
>
> But this solution does not work with the scaled images
|
|
|
Powered by
FUDForum. Page generated in 0.02483 seconds