Author: clopes
Date: 2012-08-28 13:25:41 -0700 (Tue, 28 Aug 2012)
New Revision: 30284

Modified:
   
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CySessionManagerImpl.java
Log:
Fixes #1273 (Network view width/height not restored correctly)

Modified: 
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CySessionManagerImpl.java
===================================================================
--- 
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CySessionManagerImpl.java
   2012-08-28 18:01:57 UTC (rev 30283)
+++ 
core3/impl/trunk/session-impl/impl/src/main/java/org/cytoscape/session/internal/CySessionManagerImpl.java
   2012-08-28 20:25:41 UTC (rev 30284)
@@ -70,6 +70,8 @@
 import org.cytoscape.session.events.SessionSavedListener;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.CyNetworkViewManager;
+import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.presentation.property.BasicVisualLexicon;
 import org.cytoscape.view.vizmap.VisualMappingManager;
 import org.cytoscape.view.vizmap.VisualStyle;
 import org.cytoscape.work.undo.UndoSupport;
@@ -86,7 +88,7 @@
        private String currentFileName;
        private CySession currentSession;
 
-       private final CyEventHelper cyEventHelper;
+       private final CyEventHelper eventHelper;
        private final CyApplicationManager appMgr;
        private final CyNetworkManager netMgr;
        private final CyTableManager tblMgr;
@@ -102,7 +104,7 @@
 
        private static final Logger logger = 
LoggerFactory.getLogger(CySessionManagerImpl.class);
 
-       public CySessionManagerImpl(final CyEventHelper cyEventHelper,
+       public CySessionManagerImpl(final CyEventHelper eventHelper,
                                                                final 
CyApplicationManager appMgr,
                                                                final 
CyNetworkManager netMgr,
                                                                final 
CyTableManager tblMgr,
@@ -112,7 +114,7 @@
                                                                final 
CyRootNetworkManager rootNetMgr,
                                                                final 
CyServiceRegistrar registrar,
                                                                final 
UndoSupport undo) {
-               this.cyEventHelper = cyEventHelper;
+               this.eventHelper = eventHelper;
                this.appMgr = appMgr;
                this.netMgr = netMgr;
                this.tblMgr = tblMgr;
@@ -130,7 +132,7 @@
                // Apps who want to save anything to a session will have to 
listen for this event
                // and will then be responsible for adding files through 
SessionAboutToBeSavedEvent.addAppFiles(..)
                final SessionAboutToBeSavedEvent savingEvent = new 
SessionAboutToBeSavedEvent(this);
-               cyEventHelper.fireEvent(savingEvent);
+               eventHelper.fireEvent(savingEvent);
 
                final Set<CyNetwork> networks = getSerializableNetworks();
                final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
@@ -269,7 +271,7 @@
                currentSession = sess;
                currentFileName = fileName;
 
-               cyEventHelper.fireEvent(new SessionLoadedEvent(this, 
currentSession, getCurrentSessionFileName()));
+               eventHelper.fireEvent(new SessionLoadedEvent(this, 
currentSession, getCurrentSessionFileName()));
        }
 
        /**
@@ -345,18 +347,41 @@
                
                for (CyNetworkView nv : netViews) {
                        CyNetwork network = nv.getModel();
+                       
                        if (network.getRow(network).get(CyNetwork.SELECTED, 
Boolean.class)) {
                                selectedViews.add(nv);
                        }
                }
                
+               Map<CyNetworkView, Map<VisualProperty<?>, Object>> viewVPMap = 
+                               new HashMap<CyNetworkView, 
Map<VisualProperty<?>,Object>>();
+               
                if (netViews != null) {
                        for (CyNetworkView nv : netViews) {
-                               if (nv != null)
+                               if (nv != null) {
+                                       // Save the original values of these 
visual properties,
+                                       // because we will have to set them 
again after the views are rendered
+                                       Map<VisualProperty<?>, Object> vpMap = 
new HashMap<VisualProperty<?>, Object>();
+                                       viewVPMap.put(nv, vpMap);
+                                       
vpMap.put(BasicVisualLexicon.NETWORK_HEIGHT, 
nv.getVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT));
+                                       
vpMap.put(BasicVisualLexicon.NETWORK_WIDTH, 
nv.getVisualProperty(BasicVisualLexicon.NETWORK_WIDTH));
+                                       
                                        nvMgr.addNetworkView(nv);
+                               }
                        }
                }
 
+               // Let's guarantee the network views are rendered
+               eventHelper.flushPayloadEvents();
+               
+               // Set the saved visual properties again, because the renderer 
may have overwritten the original values
+               for (Entry<CyNetworkView, Map<VisualProperty<?>, Object>> 
entry1 : viewVPMap.entrySet()) {
+                       CyNetworkView nv = entry1.getKey();
+                       
+                       for (Entry<VisualProperty<?>, Object> entry2 : 
entry1.getValue().entrySet())
+                               nv.setVisualProperty(entry2.getKey(), 
entry2.getValue());
+               }
+               
                appMgr.setSelectedNetworkViews(selectedViews);
        }
 

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