Hello,
i’m developing a vector drawing API with GWT in order to provide an
abstraction over SVG, VML, and since the VML rendering is very slow,
Flash. Everything works fine but now it’s time to think about event
handling. As I will use this API to visualize an ontology, which may
have hundreds of nodes to display, I don’t want to attach an event
listener to each drawn element (eg. Rectangle). So I think the best
approach is to attach one listener (eg. ClickListener) to the scene
and calculate which element has been clicked. But in this case, I will
only get the DOM element back, but I need the object for further
calculation.
Here is a litte bit of code in order to clarify my question:
//Canvas represents the scene, not the HTML5 tag
private Canvas canvas;
...
//Create a blue rectangle at point 10,10 with 40px width and height
Rectangle r = new Rectangle(10, 10, 40, 40, new SolidFill
(Color.BLUE));
... //Create more rectangles
//add this rectangle to the scene
canvas.add(r);
... //add other rectangles to canvas
//Add an event listener to the underlying DOM node (eg. svg)
Event.setEventListener(
canvas.getElement(),
new EventListener(){
public void onBrowserEvent(Event event){
Element target = event.getTarget();
//Let’s assume the event is a ClickEvent and I want to rotate
the
clicked rectangle by calling its rotate()-method.
//Since event.getTarget() returns the DOM element (eg. rect), I
don’t have a reference to the rectangle object in order to call its
rotate()-Method.
//Are there any best practices to get the rectangle object
belonging
to the DOM element? (eg. Storing all objects in a HashMap with its id
as key?)
}
}
);
Please notice, that this isn't my real code (eg: Canvas extends the
Widget class and overrides the onBrowserEvent-Method). I wanted to
point out the problem without posting to much code...
Many thanks in advance for your efforts & greetings from Austria
Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---