From: SourceForge.net <no...@so...> - 2012-01-29 11:27:50
|
The following forum message was posted by igorkvasnicka at http://sourceforge.net/projects/jung/forums/forum/252062/topic/4981017: Hi, I am wondering why VisualizationViewer does not have removeGraphMouseListener method. I looked into sources and I created my own VisualizationViewer implementation with this method, if you want to, you can use it (I think, this remove method is quite usefull in plugable system like JUNG) [code]public class MyVisualizationViewer extends VisualizationViewer<TopologyVertex, TopologyEdge> { private Map<GraphMouseListener<TopologyVertex>, MouseListenerTranslator<TopologyVertex, TopologyEdge>> mapping; public MyVisualizationViewer(Layout<TopologyVertex, TopologyEdge> layout) { super(layout); mapping = new WeakHashMap<GraphMouseListener<TopologyVertex>, MouseListenerTranslator<TopologyVertex, TopologyEdge>>(); //use WeakHashMap to make it GC friendly } @Override public void addGraphMouseListener(GraphMouseListener<TopologyVertex> gel) { MouseListenerTranslator<TopologyVertex, TopologyEdge> mouseListenerTranslator = new MouseListenerTranslator<TopologyVertex, TopologyEdge>(gel, this); mapping.put(gel, mouseListenerTranslator); addMouseListener(mouseListenerTranslator); } public void removeGraphMouseListener(GraphMouseListener<TopologyVertex> gel) { if (!mapping.containsKey(gel)) { return; } MouseListener l = mapping.get(gel); removeMouseListener(l); } }[/code] |