Author: clopes
Date: 2012-11-21 10:39:40 -0800 (Wed, 21 Nov 2012)
New Revision: 30828

Modified:
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReader.java
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/SessionXGMMLNetworkReader.java
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/SessionXGMMLNetworkViewReader.java
Log:
Minor changes to improve performance.

Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReader.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReader.java
    2012-11-21 15:34:36 UTC (rev 30827)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReader.java
    2012-11-21 18:39:40 UTC (rev 30828)
@@ -107,7 +107,7 @@
        }
 
        @Override
-       public void run(TaskMonitor tm) throws Exception {
+       public void run(final TaskMonitor tm) throws Exception {
                tm.setProgress(0.0);
                init(tm);
                
@@ -146,14 +146,14 @@
                return netView;
        }
        
-       protected void init(TaskMonitor tm) {
+       protected void init(final TaskMonitor tm) {
                readDataMgr.init();
                readDataMgr.setViewFormat(false); // TODO: refactor readDataMgr 
and delete this line
                
                // Now user has the option to import network into different 
collection
-               
this.initNodeMap(name2RootMap.get(rootNetworkList.getSelectedValue()), 
this.targetColumnList.getSelectedValue());               
-               this.readDataMgr.setNodeMap(this.nMap);
-               
this.readDataMgr.setParentNetwork(name2RootMap.get(rootNetworkList.getSelectedValue()));
+               
initNodeMap(name2RootMap.get(rootNetworkList.getSelectedValue()), 
this.targetColumnList.getSelectedValue());            
+               readDataMgr.setNodeMap(this.nMap);
+               
readDataMgr.setParentNetwork(name2RootMap.get(rootNetworkList.getSelectedValue()));
        }
        
        protected void complete(TaskMonitor tm) {
@@ -168,7 +168,7 @@
         * @throws SAXException
         * @throws ParserConfigurationException
         */
-       protected void readXGMML(TaskMonitor tm) throws SAXException, 
IOException {
+       protected void readXGMML(final TaskMonitor tm) throws SAXException, 
IOException {
                final SAXParserFactory spf = SAXParserFactory.newInstance();
 
                try {
@@ -198,45 +198,54 @@
                }
        }
        
-       protected void setNetworkViewProperties(CyNetworkView netView) {
+       protected void setNetworkViewProperties(final CyNetworkView netView) {
                final CyNetwork network = netView.getModel();
+               final String name = network.getRow(network).get(CyNetwork.NAME, 
String.class);
                
-               String name = network.getRow(network).get(CyNetwork.NAME, 
String.class);
-               
                if (name != null)
                        
netView.setVisualProperty(BasicVisualLexicon.NETWORK_TITLE, name);
                
-               Map<String, String> atts = 
readDataMgr.getGraphicsAttributes(network);
+               final Map<String, String> atts = 
readDataMgr.getGraphicsAttributes(network);
                setVisualProperties(netView, netView, atts);
        }
        
-       protected void setNodeViewProperties(CyNetworkView netView, 
View<CyNode> nodeView) {
+       protected void setNodeViewProperties(final CyNetworkView netView, final 
View<CyNode> nodeView) {
                final CyNode node = nodeView.getModel();
                final Map<String, String> atts = 
readDataMgr.getGraphicsAttributes(node);
                setVisualProperties(netView, nodeView, atts);
        }
 
-       protected void setEdgeViewProperties(CyNetworkView netView, 
View<CyEdge> edgeView) {
+       protected void setEdgeViewProperties(final CyNetworkView netView, final 
View<CyEdge> edgeView) {
                final CyEdge edge = edgeView.getModel();
                final Map<String, String> atts = 
readDataMgr.getGraphicsAttributes(edge);
                setVisualProperties(netView, edgeView, atts);
+               
+               // For 2.x compatibility
+               final Bend bend = 
edgeView.getVisualProperty(BasicVisualLexicon.EDGE_BEND);
+               
+               if (bend != null && bend != 
EdgeBendVisualProperty.DEFAULT_EDGE_BEND) {
+                       final List<Handle> handles = bend.getAllHandles();
+                       
+                       for (final Handle handle : handles)
+                               handle.defineHandle(netView, edgeView, 
Double.NaN, Double.NaN);
+               }
        }
        
        @SuppressWarnings({ "rawtypes", "unchecked" })
        protected void setVisualProperties(final CyNetworkView netView, final 
View<? extends CyIdentifiable> view,
-                       Map<String, String> atts) {
+                       final Map<String, String> atts) {
                if (view != null && atts != null) {
-                       CyIdentifiable model = view.getModel();
+                       final CyIdentifiable model = view.getModel();
                        Class<?> type = CyNetwork.class;
                        
                        if (model instanceof CyNode)      type = CyNode.class;
                        else if (model instanceof CyEdge) type = CyEdge.class;
 
-                       Set<String> attSet = atts.keySet();
+                       final Set<String> attSet = atts.keySet();
 
-                       for (String attName : attSet) {
+                       for (final String attName : attSet) {
                                String attValue = atts.get(attName);
-                               VisualProperty vp = visualLexicon.lookup(type, 
attName);
+                               final VisualProperty vp = 
visualLexicon.lookup(type, attName);
                                
                                if (vp != null) {
                                        if (isXGMMLTransparency(attName))
@@ -254,43 +263,45 @@
                                        
unrecognizedVisualPropertyMgr.addUnrecognizedVisualProperty(netView, view, 
attName, attValue);
                                }
                        }
-                       
-                       // For 2.x compatibility
-                       final Bend bend = 
view.getVisualProperty(BasicVisualLexicon.EDGE_BEND);
-                       if (bend != null && bend != 
EdgeBendVisualProperty.DEFAULT_EDGE_BEND) {
-                               final List<Handle> handles = 
bend.getAllHandles();
-                               for (Handle handle : handles) {
-                                       handle.defineHandle(netView, 
(View<CyEdge>) view, Double.NaN, Double.NaN);
-                               }
-                       }
                }
        }
        
+       private static final Pattern DIRECT_NODE_PROPS_PATTERN = 
Pattern.compile("x|y|z");
+       private static final Pattern DIRECT_NET_PROPS_PATTERN = Pattern.compile(
+                       
"GRAPH_VIEW_(ZOOM|CENTER_(X|Y))|NETWORK_(WIDTH|HEIGHT|SCALE_FACTOR|CENTER_(X|Y|Z)_LOCATION)");
+       
        /**
         * It tells which graphics attributes should be set as locked 
properties.
         * @param element
         * @param attName
         * @return
         */
-       protected boolean isLockedVisualProperty(final CyIdentifiable element, 
String attName) {
-               // These are NOT locked properties
-               boolean b = !((element instanceof CyNode) && 
attName.matches("x|y|z"));
-               b = b &&
-                       !((element instanceof CyNetwork) && 
-                                       
attName.matches("GRAPH_VIEW_(ZOOM|CENTER_(X|Y))|" + 
-                                                                       
"NETWORK_(WIDTH|HEIGHT|SCALE_FACTOR|CENTER_(X|Y|Z)_LOCATION)"));
+       protected boolean isLockedVisualProperty(final CyIdentifiable element, 
final String attName) {
+               boolean locked = true;
+               
+               // These must NOT be set as locked properties
+               if (element instanceof CyNetwork) {
+                       final Matcher netMatcher = 
DIRECT_NET_PROPS_PATTERN.matcher(attName);
+                       locked = !netMatcher.matches();
+               } else if (element instanceof CyNode) {
+                       final Matcher nodeMatcher = 
DIRECT_NODE_PROPS_PATTERN.matcher(attName);
+                       locked = !nodeMatcher.matches();
+               } else if (element instanceof CyEdge) {
+                       // Nothing to do here; all edge properties are locked 
by default.
+               }
 
-               return b;
+               return locked;
        }
-
        
        private static final Pattern TRANSPARENCY_PATTERN = 
Pattern.compile("(cy:)?(node|edge)Transparency");
+       
        static boolean isXGMMLTransparency(final String attName) {
                final Matcher matcher = TRANSPARENCY_PATTERN.matcher(attName);
                return matcher.matches();
        }
 
        private static final Pattern OLD_FONT_PATTERN = 
Pattern.compile("(cy:)?(node|edge)LabelFont");
+       
        static boolean isOldFont(final String attName) {
                final Matcher matcher = OLD_FONT_PATTERN.matcher(attName);
                return matcher.matches();

Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/SessionXGMMLNetworkReader.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/SessionXGMMLNetworkReader.java
     2012-11-21 15:34:36 UTC (rev 30827)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/SessionXGMMLNetworkReader.java
     2012-11-21 18:39:40 UTC (rev 30828)
@@ -27,7 +27,6 @@
 
        private final CyRootNetworkManager cyRootNetworkManager;
        private CyRootNetwork parent;
-       //private CyApplicationManager cyApplicationManager;
        
        public SessionXGMMLNetworkReader(final InputStream inputStream,
                                                                         final 
CyNetworkViewFactory cyNetworkViewFactory,
@@ -43,35 +42,34 @@
                                unrecognizedVisualPropertyMgr, 
cyNetworkManager, cyRootNetworkManager, cyApplicationManager);
 
                this.cyRootNetworkManager = cyRootNetworkManager;
-               //this.cyApplicationManager = cyApplicationManager;
        }
 
-       public void setParent(CyNetwork n) {
+       public void setParent(final CyNetwork n) {
                this.parent = n != null ? 
cyRootNetworkManager.getRootNetwork(n) : null;
        }
        
        @Override
-       protected void init(TaskMonitor tm) {
+       protected void init(final TaskMonitor tm) {
                super.init(tm);
                readDataMgr.setViewFormat(false);
                readDataMgr.setParentNetwork(parent);
        }
        
        @Override
-       protected void setNetworkViewProperties(CyNetworkView netView) {
+       protected void setNetworkViewProperties(final CyNetworkView netView) {
                // Only for Cytocape 2.x files. In Cy3 the visual properties 
are saved in the view xgmml file.
                if (readDataMgr.getDocumentVersion() < 3.0)
                        super.setNetworkViewProperties(netView);
        }
 
        @Override
-       protected void setNodeViewProperties(CyNetworkView netView, 
View<CyNode> nodeView) {
+       protected void setNodeViewProperties(final CyNetworkView netView, final 
View<CyNode> nodeView) {
                if (readDataMgr.getDocumentVersion() < 3.0)
                        super.setNodeViewProperties(netView, nodeView);
        }
 
        @Override
-       protected void setEdgeViewProperties(CyNetworkView netView, 
View<CyEdge> edgeView) {
+       protected void setEdgeViewProperties(final CyNetworkView netView, final 
View<CyEdge> edgeView) {
                if (readDataMgr.getDocumentVersion() < 3.0)
                        super.setEdgeViewProperties(netView, edgeView);
        }

Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/SessionXGMMLNetworkViewReader.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/SessionXGMMLNetworkViewReader.java
 2012-11-21 15:34:36 UTC (rev 30827)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/SessionXGMMLNetworkViewReader.java
 2012-11-21 18:39:40 UTC (rev 30828)
@@ -71,13 +71,13 @@
        }
        
        @Override
-       protected void init(TaskMonitor tm) {
+       protected void init(final TaskMonitor tm) {
                super.init(tm);
                readDataMgr.setViewFormat(true);
        }
        
        @Override
-       protected void setNetworkViewProperties(CyNetworkView netView) {
+       protected void setNetworkViewProperties(final CyNetworkView netView) {
                // Direct visual properties
                Map<String, String> atts = 
readDataMgr.getViewGraphicsAttributes(readDataMgr.getNetworkId(), false);
                this.settingLockedVisualProperties = false;
@@ -93,12 +93,12 @@
        }
 
        @Override
-       protected void setNodeViewProperties(CyNetworkView netView, 
View<CyNode> nodeView) {
+       protected void setNodeViewProperties(final CyNetworkView netView, final 
View<CyNode> nodeView) {
                final CyNode node = nodeView.getModel();
                
                // When parsing view-format XGMML, the manager does not have 
the network model
                // to create a map by CyNode objects, so the graphics mapping 
is indexed by the old element id.
-               Object oldId = readDataMgr.getCache().getOldId(node.getSUID());
+               final Object oldId = 
readDataMgr.getCache().getOldId(node.getSUID());
                
                // Direct visual properties
                Map<String, String> atts = 
readDataMgr.getViewGraphicsAttributes(oldId, false);
@@ -112,12 +112,12 @@
        }
 
        @Override
-       protected void setEdgeViewProperties(CyNetworkView netView, 
View<CyEdge> edgeView) {
+       protected void setEdgeViewProperties(final CyNetworkView netView, final 
View<CyEdge> edgeView) {
                final CyEdge edge = edgeView.getModel();
                
                // When parsing view-format XGMML, the manager does not have 
the network model
                // to create a map by CyEdge objects, so the graphics mapping 
is indexed by the old element id.
-               Object oldId = readDataMgr.getCache().getOldId(edge.getSUID());
+               final Object oldId = 
readDataMgr.getCache().getOldId(edge.getSUID());
                
                // Direct visual properties
                Map<String, String> atts = 
readDataMgr.getViewGraphicsAttributes(oldId, false);

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