Author: jm
Date: 2012-06-29 08:56:18 -0700 (Fri, 29 Jun 2012)
New Revision: 29727

Modified:
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/ArbitraryGraphicsCanvas.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/BirdsEyeView.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingNavigationRenderingEngineFactory.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingRenderingEngineFactory.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingViewModelFactory.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/CyAnnotator.java
Log:
This was omitted from r29726


Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/ArbitraryGraphicsCanvas.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/ArbitraryGraphicsCanvas.java
        2012-06-29 15:50:42 UTC (rev 29726)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/ArbitraryGraphicsCanvas.java
        2012-06-29 15:56:18 UTC (rev 29727)
@@ -393,4 +393,14 @@
                }
        }
 
+       public void dispose() {
+               // Bug #1178: This class is being leaked by Swing's focus 
subsystem
+               // In order to ensure no other instances get strung along, we 
should
+               // release them here.
+               m_dGraphView = null;
+               m_innerCanvas = null;
+               m_componentToNodeMap = null;
+               m_componentToPointMap = null;
+       }
+
 }

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/BirdsEyeView.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/BirdsEyeView.java
   2012-06-29 15:50:42 UTC (rev 29726)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/BirdsEyeView.java
   2012-06-29 15:56:18 UTC (rev 29727)
@@ -55,6 +55,7 @@
 import org.cytoscape.ding.GraphView;
 import org.cytoscape.ding.impl.events.ViewportChangeListener;
 import org.cytoscape.model.CyNetwork;
+import org.cytoscape.service.util.CyServiceRegistrar;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualLexicon;
 import org.cytoscape.view.model.VisualProperty;
@@ -83,6 +84,7 @@
        
        private final ContentChangeListener m_cLis;
        private final ViewportChangeListener m_vLis;
+       private final CyServiceRegistrar registrar;
 
        private VolatileImage networkImage;
        
@@ -109,13 +111,14 @@
         * @param viewModel
         *            The view to monitor
         */
-       public BirdsEyeView(final DGraphView viewModel) {
+       public BirdsEyeView(final DGraphView viewModel, final 
CyServiceRegistrar registrar) {
                super();
 
                if (viewModel == null)
                        throw new NullPointerException("DGraphView is null.");
 
                this.viewModel = viewModel;
+               this.registrar = registrar;
 
                m_cLis = new InnerContentChangeListener();
                m_vLis = new InnerViewportChangeListener();
@@ -375,4 +378,13 @@
        public void printCanvas(Graphics printCanvas) {
                throw new UnsupportedOperationException("Printing is not 
supported for Bird's eye view.");
        }
+
+       public void registerServices() {
+               registrar.registerAllServices(this, new Properties());
+       }
+       
+       @Override
+       public void dispose() {
+               registrar.unregisterAllServices(this);
+       }
 }

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
     2012-06-29 15:50:42 UTC (rev 29726)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
     2012-06-29 15:56:18 UTC (rev 29727)
@@ -108,6 +108,7 @@
 import org.cytoscape.model.events.AddedNodesListener;
 import org.cytoscape.model.subnetwork.CyRootNetworkManager;
 import org.cytoscape.model.subnetwork.CySubNetwork;
+import org.cytoscape.service.util.CyServiceRegistrar;
 import org.cytoscape.spacial.SpacialEntry2DEnumerator;
 import org.cytoscape.spacial.SpacialIndex2D;
 import org.cytoscape.spacial.SpacialIndex2DFactory;
@@ -402,11 +403,12 @@
        private final AnnotationFactoryManager annMgr;
 
        private boolean annotationsLoaded = false;
+       private boolean servicesRegistered;
        
        private final VisualMappingManager vmm;
 
        private final CyNetworkViewManager netViewMgr; 
-       
+       private final CyServiceRegistrar registrar;
        private final HandleFactory handleFactory;
 
        /**
@@ -422,10 +424,12 @@
                        CyEventHelper eventHelper,
                        CyNetworkTableManager tableMgr,
                        AnnotationFactoryManager annMgr, final DingGraphLOD 
dingGraphLOD, final VisualMappingManager vmm,
-                       final CyNetworkViewManager netViewMgr, final 
HandleFactory handleFactory) {
+                       final CyNetworkViewManager netViewMgr,
+                       final HandleFactory handleFactory,
+                       final CyServiceRegistrar registrar) {
                
                this(view.getModel(), dataFactory, cyRoot, undo, 
spacialFactory, dingLexicon, 
-                               vtfl, manager, eventHelper, tableMgr, annMgr, 
dingGraphLOD, vmm, netViewMgr, handleFactory);
+                               vtfl, manager, eventHelper, tableMgr, annMgr, 
dingGraphLOD, vmm, netViewMgr, handleFactory, registrar);
        }
 
        
@@ -453,10 +457,13 @@
                        CyEventHelper cyEventHelper,
                        CyNetworkTableManager tableMgr,
                        AnnotationFactoryManager annMgr, final DingGraphLOD 
dingGraphLOD, final VisualMappingManager vmm,
-                       final CyNetworkViewManager netViewMgr, final 
HandleFactory handleFactory) {
+                       final CyNetworkViewManager netViewMgr,
+                       final HandleFactory handleFactory,
+                       final CyServiceRegistrar registrar) {
                super(model);
                this.props = new Properties();
                this.vmm = vmm;
+               this.registrar = registrar;
                this.handleFactory = handleFactory;
                
                long start = System.currentTimeMillis();
@@ -2190,6 +2197,8 @@
 
        private String title;
 
+       private AddDeleteHandler addDeleteHandler;
+
        /**
         * DOCUMENT ME!
         *
@@ -2716,4 +2725,29 @@
        public String toString() {
                return "DGraphView: suid=" + suid + ", model=" + model;
        }
+
+       public void registerServices() {
+               synchronized (this) {
+                       if (servicesRegistered)
+                               return;
+                       registrar.registerAllServices(this, new Properties());
+                       addDeleteHandler = new AddDeleteHandler(this);
+                       registrar.registerAllServices(addDeleteHandler, new 
Properties());
+                       servicesRegistered = true;
+               }
+       }
+       
+       @Override
+       public void dispose() {
+               synchronized (this) {
+                       if (!servicesRegistered)
+                               return;
+                       registrar.unregisterAllServices(this);
+                       if (addDeleteHandler != null)
+                               
registrar.unregisterAllServices(addDeleteHandler);
+                       servicesRegistered = false;
+                       
+                       cyAnnotator.dispose();
+               }
+       }
 }

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingNavigationRenderingEngineFactory.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingNavigationRenderingEngineFactory.java
   2012-06-29 15:50:42 UTC (rev 29726)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingNavigationRenderingEngineFactory.java
   2012-06-29 15:56:18 UTC (rev 29727)
@@ -68,13 +68,13 @@
                //final RenderingEngine<CyNetwork> engine = 
appManager.getCurrentRenderingEngine();
                
                // Create instance of an engine.
-               final BirdsEyeView bev = new BirdsEyeView(dgv);
+               final BirdsEyeView bev = new BirdsEyeView(dgv, registrar);
 
                container.setLayout(new BorderLayout());
                container.add(bev, BorderLayout.CENTER);
 
                // Register this rendering engine as service.
-               this.registrar.registerAllServices(bev, new Properties());
+               bev.registerServices();
 
                logger.debug("Bird's Eye View had been set to the component.  
Network Model = " + view.getModel().getSUID());
                return bev;

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingRenderingEngineFactory.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingRenderingEngineFactory.java
     2012-06-29 15:50:42 UTC (rev 29726)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingRenderingEngineFactory.java
     2012-06-29 15:56:18 UTC (rev 29727)
@@ -120,11 +120,12 @@
                                dgv = (DGraphView) view;                        
        
                                logger.info("%%%%%%% This view is DGV.");
                        }
-                       else
+                       else {
                                dgv = new DGraphView(targetView, 
dataTableFactory,
                                        rootNetworkManager, undo, 
spacialFactory, dingLexicon,
-                                       vtfListener,dialogTaskManager, 
eventHelper, tableMgr, annMgr, dingGraphLOD, vmm, netViewMgr, handleFactory);
-
+                                       vtfListener,dialogTaskManager, 
eventHelper, tableMgr, annMgr, dingGraphLOD, vmm, netViewMgr, handleFactory, 
registrar);
+                               dgv.registerServices();
+                       }
                        logger.info("DGraphView created as a presentation for 
view model: "
                                        + targetView.getSUID());
                        vtfListener.viewMap.put(targetView, new 
WeakReference<DGraphView>(dgv));
@@ -144,10 +145,6 @@
                                        "frame object is not of type 
JInternalFrame, which is invalid for this implementation of 
PresentationFactory");
                }
 
-               registrar.registerAllServices(dgv, new Properties());
-               final AddDeleteHandler addDeleteHandler = new 
AddDeleteHandler(dgv);
-               registrar.registerAllServices(addDeleteHandler, new 
Properties());
-               
                return dgv;
        }
 

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingViewModelFactory.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingViewModelFactory.java
   2012-06-29 15:50:42 UTC (rev 29726)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DingViewModelFactory.java
   2012-06-29 15:56:18 UTC (rev 29727)
@@ -77,9 +77,9 @@
                        throw new IllegalArgumentException("Cannot create view 
without model.");
 
                final DGraphView dgv = new DGraphView(network, 
dataTableFactory, rootNetworkManager, undo, spacialFactory, dingLexicon,
-                               vtfListener, dialogTaskManager, eventHelper, 
tableMgr, annMgr, dingGraphLOD, vmm, netViewMgr, handleFactory);
+                               vtfListener, dialogTaskManager, eventHelper, 
tableMgr, annMgr, dingGraphLOD, vmm, netViewMgr, handleFactory, registrar);
 
-               registrar.registerAllServices(dgv, new Properties());
+               dgv.registerServices();
 
                return dgv;
        }

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/CyAnnotator.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/CyAnnotator.java
        2012-06-29 15:50:42 UTC (rev 29726)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/CyAnnotator.java
        2012-06-29 15:56:18 UTC (rev 29727)
@@ -53,6 +53,11 @@
 
        private Set<Annotation> selectedAnnotations = new HashSet<Annotation>();
 
+       private CanvasMouseMotionListener mouseMotionListener;
+       private CanvasMouseListener mouseListener;
+       private CanvasKeyListener keyListener;
+       private CanvasMouseWheelListener mouseWheelListener;
+
        public CyAnnotator(DGraphView view, AnnotationFactoryManager 
annotationFactoryManager) {
                this.view = view;
                this.foreGroundCanvas = 
@@ -65,18 +70,38 @@
        }
 
        private void initListeners() {
-               foreGroundCanvas.addMouseListener(new CanvasMouseListener(this, 
view));
-               foreGroundCanvas.addMouseMotionListener(new 
CanvasMouseMotionListener(this, view));
-               foreGroundCanvas.addKeyListener(new CanvasKeyListener(this, 
view));
+               mouseListener = new CanvasMouseListener(this, view);
+               mouseMotionListener = new CanvasMouseMotionListener(this, view);
+               keyListener = new CanvasKeyListener(this, view);
+               mouseWheelListener = new CanvasMouseWheelListener(this, view);
+               
+               foreGroundCanvas.addMouseListener(mouseListener);
+               foreGroundCanvas.addMouseMotionListener(mouseMotionListener);
+               foreGroundCanvas.addKeyListener(keyListener);
                foreGroundCanvas.setFocusable(true);
 
                //The created annotations resize (Their font changes), if we 
zoom in and out
-               foreGroundCanvas.addMouseWheelListener(new 
CanvasMouseWheelListener(this, view));
+               foreGroundCanvas.addMouseWheelListener(mouseWheelListener);
 
                //We also setup this class as a ViewportChangeListener to the 
current networkview
                myViewportChangeListener=new MyViewportChangeListener();
                view.addViewportChangeListener(myViewportChangeListener);
        }
+       
+       public void dispose() {
+               // Bug #1178: Swing's focus subsystem is leaking 
foreGroundCanvas.
+               // We need to remove all our listeners from that class to 
ensure we
+               // don't leak anything further.
+               foreGroundCanvas.removeMouseListener(mouseListener);
+               foreGroundCanvas.removeMouseMotionListener(mouseMotionListener);
+               foreGroundCanvas.removeKeyListener(keyListener);
+               foreGroundCanvas.removeMouseWheelListener(mouseWheelListener);
+               
+               view.removeViewportChangeListener(myViewportChangeListener);
+               
+               foreGroundCanvas.dispose();
+               backGroundCanvas.dispose();
+       }
 
        public void loadAnnotations() {
                // System.out.println("Loading annotations");

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to