Translate from mouse (x, y) coordinates to graphic objects and data model entities

Article ID: 2199
Last updated: 28 May, 2018
Article ID: 2199
Last updated: 28 May, 2018
Revision: 3
Views: 820
Posted: 22 Apr, 2010
by Dean J.
Updated: 28 May, 2018
by Gargani A.

Question

How do I translate from mouse (x, y) coordinates to graphic objects and data model entities?

Answer

The graphic objects in the Gantt chart can be translated to its data model entities by accessing the IlvManager objects, and checking its type with the instanceof operator.

Once the type of the graphic object is identified, it can be cast to IlvConstraintGraphic, or IlvActivityGraphic, and retrieve the underlaying IlvConstraint, or IlvActivity respectively.

The example below shows an implementation of this procedure. It can be extended to handle other kinds of graphics:

class MousePicker extends MouseMotionAdapter {
 private IlvGanttSheet _ganttSheet;

 public MousePicker(IlvGanttSheet ganttSheet) {
  _ganttSheet = ganttSheet;
  _ganttSheet.addMouseMotionListener(this);
 }

 public void mouseMoved(MouseEvent e) {
  IlvPoint p = new IlvPoint(e.getX(), e.getY());
  IlvGraphic graphic = _ganttSheet.getManager().getObject(p, _ganttSheet);
  if (graphic instanceof IlvActivityGraphic) {
   IlvActivity a = ((IlvActivityGraphic)graphic).getActivity();
   ... do something with activity ....
  else if (graphic instanceof IlvConstraintGraphic) {
   IlvConstraint c = ((IlvConstraintGraphic)graphic).getConstraint();
   ... do something with constraint ....
  }
 }
}
This article was:   Helpful | Not helpful
Report an issue
Article ID: 2199
Last updated: 28 May, 2018
Revision: 3
Views: 820
Posted: 22 Apr, 2010 by Dean J.
Updated: 28 May, 2018 by Gargani A.
Also listed in


Others in this category