Community
Participate
Working Groups
There's a problem with the "find the item under the mouse" snippet. It will work, but not with scaled layouts. The coordinates need to be translated. Moreover, why should I care about the figure? In most cases, I need the node. There's no simple way of reaching the node from the figure anyway, since the figures mapping is private. Let me suggest the followin method for the Graph class: public GraphItem getItemAt(final int x, final int y) { GraphItem result = null; final Point point = new Point(x, y); getRootLayer().translateToRelative(point); final IFigure figureAtPoint = getFigureAt(point.x, point.y); if (figureAtPoint != null) { result = getGraphItem(figureAtPoint); } return result; }
I second this suggestion. The getFigureAt method isn't useful because I just end up with a GraphLabel when I want the GraphNode and there's no way to efficiently get the GraphNode since the figure2ItemMap is private. Please either add the getItemAt method as described above or make the getGraphItem(IFigure figure) method public API.
This problem drove me crazy too. Because of the private Method I had no chance to get my Nested Objects. But I really want to use Zest so here is a small workaround for those who are contaminated such as me ;) For example I want to get the "node" at mouse location when a button is released: graph.addMouseListener(new MouseListener() { public void mouseUp(MouseEvent e) { //this just gives us a GraphLabel etc. like postet above. IFigure figure = graph.getFigureAt(e.x, e.y); ... } ... } Now I do the following using reflections (sorry for that but it works) // first the same as above (still in the mouseUp-method) IFigure figure = graph.getFigureAt(e.x, e.y); GraphItem item = null; // now the bad things begin... try { // getting private field Field f = Graph.class.getDeclaredField("figure2ItemMap"); // set field public f.setAccessible(true); // get field HashMap figure2ItemMap = (HashMap)f.get(graph); f.setAccessible(false); // use field to get the GraphItem item = (GraphItem) figure2ItemMap.get(figure); } catch (Exception e1) { // this should not happen e1.printStackTrace(); } Hope I could help someone. Btw. I first tried it with the "getGraphItem" method but this didn't work. Maybe because it is neither declared as private nor than public. Nevertheless the bug should be fixed sometime. Its just a little public in front of the "getGraphItem" method. :P
Any news on that bug? I would also find an official getGraphItemAt() or similar method very handy.
Re-assigning back to inbox, as Ian is no longer active committer.