Author: paperwing
Date: 2012-02-18 18:04:51 -0800 (Sat, 18 Feb 2012)
New Revision: 28324

Modified:
   
csplugins/trunk/toronto/yuedong/multi_renderer/api/presentation-api/src/main/java/org/cytoscape/view/presentation/RenderingEngineManager.java
   
csplugins/trunk/toronto/yuedong/multi_renderer/impl/presentation-impl/src/main/java/org/cytoscape/view/presentation/internal/RenderingEngineManagerImpl.java
Log:
Added support for multiple RenderingEngines per view object by returning the 
collection of engines associated with a given view

Modified: 
csplugins/trunk/toronto/yuedong/multi_renderer/api/presentation-api/src/main/java/org/cytoscape/view/presentation/RenderingEngineManager.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/multi_renderer/api/presentation-api/src/main/java/org/cytoscape/view/presentation/RenderingEngineManager.java
       2012-02-18 00:02:01 UTC (rev 28323)
+++ 
csplugins/trunk/toronto/yuedong/multi_renderer/api/presentation-api/src/main/java/org/cytoscape/view/presentation/RenderingEngineManager.java
       2012-02-19 02:04:51 UTC (rev 28324)
@@ -25,15 +25,14 @@
        VisualLexicon getDefaultVisualLexicon();
 
        /**
-        * Get a rendering engine for the given view model.
-        *
+        * Get the set of rendering engines for the given view model.
+        * 
         * @param viewModel
         *            View model for the presentation.
         * 
-        * @return Rendering engine (presentation) for the given
-        *         view model.
+        * @return All rendering engines for the given view model.
         */
-       RenderingEngine<?> getRenderingEngine(final View<?> viewModel);
+       Collection<RenderingEngine<?>> getRenderingEngines(final View<?> 
viewModel);
        
        /**
         * Get all {@link RenderingEngine}s registered in this manager.

Modified: 
csplugins/trunk/toronto/yuedong/multi_renderer/impl/presentation-impl/src/main/java/org/cytoscape/view/presentation/internal/RenderingEngineManagerImpl.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/multi_renderer/impl/presentation-impl/src/main/java/org/cytoscape/view/presentation/internal/RenderingEngineManagerImpl.java
        2012-02-18 00:02:01 UTC (rev 28323)
+++ 
csplugins/trunk/toronto/yuedong/multi_renderer/impl/presentation-impl/src/main/java/org/cytoscape/view/presentation/internal/RenderingEngineManagerImpl.java
        2012-02-19 02:04:51 UTC (rev 28324)
@@ -2,6 +2,7 @@
 
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 
 import org.cytoscape.view.model.View;
@@ -16,7 +17,7 @@
        
        private static final Logger logger = 
LoggerFactory.getLogger(RenderingEngineManagerImpl.class);
 
-       private final Map<View<?>, RenderingEngine<?>> renderingEngineMap;
+       private final Map<View<?>, Collection<RenderingEngine<?>>> 
renderingEngines;
        
        private static final String FACTORY_ID_TAG = "id";
        private static final String DEFAULT_FACTORY_ID = "ding";
@@ -31,7 +32,7 @@
         * listens to Presentation events and update its map based on them.
         */
        public RenderingEngineManagerImpl() {
-               this.renderingEngineMap = new HashMap<View<?>, 
RenderingEngine<?>>();
+               this.renderingEngines = new HashMap<View<?>, 
Collection<RenderingEngine<?>>>();
                this.factoryMap = new HashMap<String, 
RenderingEngineFactory<?>>();
        }
 
@@ -39,27 +40,47 @@
         * This method never returns null.
         */
        @Override
-       public RenderingEngine<?> getRenderingEngine(final View<?> viewModel) {
-               return renderingEngineMap.get(viewModel);
+       public Collection<RenderingEngine<?>> getRenderingEngines(final View<?> 
viewModel) {
+               return renderingEngines.get(viewModel);
        }
 
        @Override
        public Collection<RenderingEngine<?>> getAllRenderingEngines() {
-               return renderingEngineMap.values();
+               Collection<RenderingEngine<?>> result = new 
HashSet<RenderingEngine<?>>();
+               
+               for (Collection<RenderingEngine<?>> collection : 
renderingEngines.values()) {
+                       result.addAll(collection);
+               }
+               
+               return result;
        }
        
 
        @Override
        public void addRenderingEngine(final RenderingEngine<?> 
renderingEngine) {
                final View<?> viewModel = renderingEngine.getViewModel();
-               this.renderingEngineMap.put(viewModel, renderingEngine);
+               
+               Collection<RenderingEngine<?>> collection = 
renderingEngines.get(viewModel);
+               
+               if (collection == null) {
+                       collection = new HashSet<RenderingEngine<?>>();
+                       collection.add(renderingEngine);
+                       renderingEngines.put(viewModel, collection);
+               } else {
+                       collection.add(renderingEngine);
+               }
        }
        
 
        @Override
        public void removeRenderingEngine(RenderingEngine<?> renderingEngine) {
                final View<?> viewModel = renderingEngine.getViewModel();
-               this.renderingEngineMap.remove(viewModel);
+               Collection<RenderingEngine<?>> collection = 
renderingEngines.get(viewModel);
+               collection.remove(renderingEngine);
+               
+               if (collection.isEmpty()) {
+                       this.renderingEngines.remove(viewModel);
+               }
        }
        
 
@@ -72,39 +93,39 @@
        }
        
        
-//     public void addRenderingEngineFactory(
-//                     final RenderingEngineFactory<?> factory, Map metadata) {
-//             final Object idObject = metadata.get(FACTORY_ID_TAG);
-//
-//             if (idObject == null)
-//                     throw new IllegalArgumentException(
-//                                     "Could not add factory: ID metadata is 
missing for RenderingEngineFactory.");
-//
-//             final String id = idObject.toString();
-//
-//             this.factoryMap.put(id, factory);
-//             
-//             // Register default lexicon
-//             if(id.equals(DEFAULT_FACTORY_ID))
-//                     defaultLexicon = factory.getVisualLexicon();
-//             
-//             logger.debug("New engine registered: " + factory.getClass());
-//     }
-//
-//     public void removeRenderingEngineFactory(
-//                     final RenderingEngineFactory<?> factory, Map metadata) {
-//             final Object idObject = metadata.get(FACTORY_ID_TAG);
-//
-//             if (idObject == null)
-//                     throw new IllegalArgumentException(
-//                                     "Could not remove factory: ID metadata 
is missing for RenderingEngineFactory.");
-//
-//             final String id = idObject.toString();
-//
-//             RenderingEngineFactory<?> toBeRemoved = 
this.factoryMap.remove(id);
-//
-//             toBeRemoved = null;
-//
-//     }
+       public void addRenderingEngineFactory(
+                       final RenderingEngineFactory<?> factory, Map metadata) {
+               final Object idObject = metadata.get(FACTORY_ID_TAG);
 
+               if (idObject == null)
+                       throw new IllegalArgumentException(
+                                       "Could not add factory: ID metadata is 
missing for RenderingEngineFactory.");
+
+               final String id = idObject.toString();
+
+               this.factoryMap.put(id, factory);
+               
+               // Register default lexicon
+               if(id.equals(DEFAULT_FACTORY_ID))
+                       defaultLexicon = factory.getVisualLexicon();
+               
+               logger.debug("New engine registered: " + factory.getClass());
+       }
+
+       public void removeRenderingEngineFactory(
+                       final RenderingEngineFactory<?> factory, Map metadata) {
+               final Object idObject = metadata.get(FACTORY_ID_TAG);
+
+               if (idObject == null)
+                       throw new IllegalArgumentException(
+                                       "Could not remove factory: ID metadata 
is missing for RenderingEngineFactory.");
+
+               final String id = idObject.toString();
+
+               RenderingEngineFactory<?> toBeRemoved = 
this.factoryMap.remove(id);
+
+               toBeRemoved = null;
+
+       }
+
 }

-- 
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