|
From: SourceForge.net <no...@so...> - 2013-05-17 11:25:47
|
The following forum message was posted by idevc at http://sourceforge.net/projects/jung/forums/forum/252062/topic/8207132: Consider this code called when clicking a button in an interface I am wrapping around the graph using JUNG: public void actionPerformed(ActionEvent e) { String action = e.getActionCommand(); if(action.equalsIgnoreCase("case.r")){ nodesSelected.add(currentNodeSelected); Transformer<MyNode,Paint> vertexColor = new Transformer<MyNode,Paint>() { public Paint transform(MyNode i) { if(i.getID() == currentNodeSelected.getID()){ return Color.YELLOW; }else{ return Color.RED; } } }; panel.getRenderContext().setVertexFillPaintTransformer(vertexColor); } } where currentNodeSelected is of type MyNode (containing an ID of type int which can be retrieved using getID() and String). This code works i.e. when I click the button, the node that was selected changes color. However for the life of me I cannot figure out how to force the node to stay that color. In the above example it is easy to see why: if the node currently selected is different then the node changes color. I thought I could remedy this by maintaining a vector of nodes selected (nodesSelected) and simply loop over them to change the color. However, that somehow doesnt work either. Now all nodes changes color. So my question: How can I, after clicking on a node and subsequently a button, change the color of the selected node and have that node keep that color even when selecting other/new vertices. Thanks in advance |