Skip to content

Instantly share code, notes, and snippets.

@momeara
Created August 13, 2015 14:33
Show Gist options
  • Save momeara/ba0a87e8629ffc06f471 to your computer and use it in GitHub Desktop.
Save momeara/ba0a87e8629ffc06f471 to your computer and use it in GitHub Desktop.
view test
public viewtest.internal;
import java.util.Properties;
import org.cytoscape.service.util.AbstractCyActivator;
import org.cytoscape.task.AbstractNetworkViewTask;
import org.cytoscape.task.AbstractNetworkViewTaskFactory;
import org.cytoscape.task.NetworkViewTaskFactory;
import org.osgi.framework.BundleContext;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.VisualStyle;
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.TaskMonitor;
import static org.cytoscape.work.ServiceProperties.*;
public class CyActivator extends AbstractCyActivator {
public class ViewTest extends AbstractNetworkViewTask {
private final VisualMappingManager vmmServiceRef;
public ViewTest(CyNetworkView view, final VisualMappingManager vmmServiceRef){
super(view);
this.vmmServiceRef = vmmServiceRef;
}
@Override
public void run(TaskMonitor monitor) throws Exception {
final CyNetwork network = view.getModel();
final CyTable nodeTable = network.getDefaultNodeTable();
final CyNode node1 = network.addNode();
final CyRow row1 = nodeTable.getRow(node1.getSUID());
row1.set("name", "node1");
VisualStyle style = vmmServiceRef.getCurrentVisualStyle();
style.apply(view);
view.updateView();
}
}
public class ViewTestFactory extends AbstractNetworkViewTaskFactory {
private final VisualMappingManager vmmServiceRef;
public ViewTestFactory( final VisualMappingManager vmmServiceRef){
this.vmmServiceRef = vmmServiceRef;
}
@Override
public TaskIterator createTaskIterator(CyNetworkView view) {
return new TaskIterator(new ViewTest(view, vmmServiceRef));
}
}
@Override
public void start(BundleContext context) throws Exception {
final VisualMappingManager vmmServiceRef = super.getService(context, VisualMappingManager.class);
super.registerService(context, new ViewTestFactory(vmmServiceRef), NetworkViewTaskFactory.class, ezProps(
TITLE, "View Test",
PREFERRED_MENU, "Apps"
));
}
private static Properties ezProps(String... vals) {
final Properties props = new Properties();
for (int i = 0; i < vals.length; i += 2)
props.put(vals[i], vals[i + 1]);
return props;
}
}
@momeara
Copy link
Author

momeara commented Aug 13, 2015

After running the app, it gives this error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: width of node has degenerated to zero after rounding
    at org.cytoscape.ding.impl.DNodeView.setOffset(DNodeView.java:481)
    at org.cytoscape.ding.impl.InnerCanvas$MouseDraggedDelegator.singleLeftClick(InnerCanvas.java:1462)
    at org.cytoscape.ding.impl.InnerCanvas$MouseDraggedDelegator.delegateMouseEvent(InnerCanvas.java:1403)
    at org.cytoscape.ding.impl.InnerCanvas.mouseDragged(InnerCanvas.java:303)
    at org.cytoscape.ding.impl.cyannotator.listeners.CanvasMouseMotionListener.mouseDragged(CanvasMouseMotionListener.java:58)
    at java.awt.AWTEventMulticaster.mouseDragged(AWTEventMulticaster.java:319)
    at java.awt.Component.processMouseMotionEvent(Component.java:6573)
    at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3342)
    at java.awt.Component.processEvent(Component.java:6294)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4550)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment