Topic
No replies
SystemAdmin
SystemAdmin
2606 Posts
ACCEPTED ANSWER

Pinned topic converting point coordinates

‏2013-02-04T19:48:46Z |
Let's say in a mouse listener I get a point where mouse was clicked. Presumably it is in the view's coordinates. How do I convert it to graphic coordinates and back? Basically I'm looking for implementation of two methods toGraphicCoordinates() and toViewCoordinates().




class MyAdapter 

extends MouseAdapter 
{ 

private IlvManagerView view;   MyAdapter(IlvManagerView view) 
{ this.view=view; 
}   

public 

void mouseClicked(MouseEvent evt) 
{ Point clickPoint=evt.getPoint(); IlvGraphic g=view.getManager().getObject(clickPoint,view); IlvPoint graphicCoordinates=toGraphicCoordinates(clickPoint,view,g); Point viewCoordinatesFromGraphicCoordinates=toViewCoordinates(graphicCoordinates, view, g); 

assert clickPoint.equals(viewCoordinatesFromGraphicCoordinates); 
}   

public IlvPoint toGraphicCoordinates(Point viewCoordinates, IlvManageView view, IlvGraphic graphic) 
{ ??? 
}   

public Point toViewCoordinates(IlvPoint graphicCoordinates, IlvManagerView view, IlvGraphic graphic) 
{ ??? 
} 
}