|
Re: [Zest/Draw2D] Drag and drop [message #247290 is a reply to message #247242] |
Fri, 13 February 2009 16:47 |
Eclipse User |
|
|
|
Originally posted by: irbull.cs.uvic.ca
hum...
this seems like a bug. Are you using nested (or any zooming)?
cheers,
ian
Bianca wrote:
> Hello,
>
> I have a shell that contains a JFace table viewer on the left side and a
> Zest graph on the right side. I added drag capability to the table
> viewer and drop capability to the graph. I want to allow drop only when
> the dragged item is dropped onto a graph node.
>
> The drop event gives me x and y coordinates but they are not the same as
> the coordinates given by a mouse move listener added to the graph
> (example: drop x 225 drop y 219, mouse move x 40 mouse move y 39). I
> tried to call graph.getRootLayer().translateToRelative(drop coordinates)
> but that just returned the old coordinates. Can anybody help me as to
> how I have to translate the drop coordinates into the right coordinates
> for Graph#getFigureAt?
>
> Kind regards
> Bianca
|
|
|
|
Re: [Zest/Draw2D] Drag and drop [message #767936 is a reply to message #247307] |
Mon, 19 December 2011 08:28 |
Erdal Karaca Messages: 854 Registered: July 2009 |
Senior Member |
|
|
I have the same problem.
I am using this to calculate the relative coords:
protected Object determineTarget(DropTargetEvent event) {
Graph g = viewer.getGraphControl();
Point p = g.getDisplay().map(g.getShell(), g, event.x, event.y - 30);
IFigure fig = g.getFigureAt(p.x, p.y);
if (fig != null) {
for (Object o : g.getNodes()) {
GraphNode gn = (GraphNode) o;
if (gn.getFigure() == fig) {
return gn.getData();
}
}
}
return null;
}
As you can see, I still have to subtract those magic 30 Pixels, though those 30 Pixels dont seem to be sufficient...
Anyone with new/fresh hints?
Bianca Thelen wrote on Sun, 15 February 2009 10:47> this seems like a bug. Are you using nested (or any zooming)?
I am not sure what you mean by nested. I just create a graph to which I
add GraphNodes. I'm not using zooming.
I've found a formula (of sorts), however, which gives me the correct
coordinates for a figure:
public void drop(DropTargetEvent event) {
Point point = new Point(event.x, event.y);
IFigure figureAt = graph.getFigureAt(
(point.x
- graph.getLocation().x
- graph.getShell().getLocation().x),
(point.y
- graph.getLocation().y
- graph.getShell().getLocation().y
- 30));
}
I'm not happy with it but it seems to work. I'm not sure how failsafe it
is though. Probably not very... What I'm bugged most by is the random 30
that I have to substract to get the y-coordinate.
Kind regards
Bianca
|
|
|
Powered by
FUDForum. Page generated in 0.06054 seconds