Author: jm
Date: 2012-11-21 07:34:36 -0800 (Wed, 21 Nov 2012)
New Revision: 30827
Added:
core3/samples/trunk/sample18/src/main/java/org/cytoscape/sample/internal/ApplyMyLayoutTaskFactory.java
Log:
Forgot to add this...
Added:
core3/samples/trunk/sample18/src/main/java/org/cytoscape/sample/internal/ApplyMyLayoutTaskFactory.java
===================================================================
---
core3/samples/trunk/sample18/src/main/java/org/cytoscape/sample/internal/ApplyMyLayoutTaskFactory.java
(rev 0)
+++
core3/samples/trunk/sample18/src/main/java/org/cytoscape/sample/internal/ApplyMyLayoutTaskFactory.java
2012-11-21 15:34:36 UTC (rev 30827)
@@ -0,0 +1,50 @@
+package org.cytoscape.sample.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cytoscape.task.NetworkViewTaskFactory;
+import org.cytoscape.view.layout.CyLayoutAlgorithm;
+import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.TunableSetter;
+
+/**
+ * Applies MyLayout to the given CyNetworkView with specific Tunable
+ * parameters.
+ */
+public class ApplyMyLayoutTaskFactory implements NetworkViewTaskFactory {
+ private CyLayoutAlgorithmManager layoutManager;
+ private TunableSetter tunableSetter;
+
+ public ApplyMyLayoutTaskFactory(CyLayoutAlgorithmManager layoutManager,
TunableSetter tunableSetter) {
+ this.layoutManager = layoutManager;
+ this.tunableSetter = tunableSetter;
+ }
+
+ public TaskIterator createTaskIterator(CyNetworkView view) {
+ // Get an instance of the layout. We usually won't know at
runtime
+ // what the implementation class is so we won't cast it to
anything.
+ CyLayoutAlgorithm layout = layoutManager.getLayout("myLayout");
+
+ // Create a new context for the layout so we can configure the
settings
+ // without changing the user's defaults.
+ Object context = layout.createLayoutContext();
+
+ // Use TunableSetter to change the values on the Tunable fields
on
+ // the context object (in this case, MyLayoutContext). These
values
+ // get applied when the tasks are run.
+ Map<String, Object> tunableValues = new HashMap<String,
Object>();
+ tunableValues.put("XRange", 50);
+ tunableValues.put("YRange", 50);
+ tunableSetter.applyTunables(context, tunableValues);
+
+ String layoutAttribute = null;
+ return layout.createTaskIterator(view, context,
CyLayoutAlgorithm.ALL_NODE_VIEWS, layoutAttribute);
+ }
+
+ public boolean isReady(CyNetworkView view) {
+ return view != 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.