How to change a NodeView to show a custom view for a node? I (MarcioSilva) have only a part of the answer. :-)

Here some discussions about my experiences with this and the problems I found. Feel free to add more information to this page.

I started my hack using as a base, the PetalNode from the MDNodes plugin.

Then I started to make my modifications in the drawNodeView() method. I tried to use the PPath class, but I could not find a way to draw arcs of circles with it. Then I overrrided the paint() method from PPath, like this:

   1 PPath n = new PPath() {
   2     public void paint(PPaintContext aPaintContext) {
   4         Arc2D.Double arc = new Arc2D.Double();
   5         arc.setArcByCenter(0,0,40,0,300,Arc2D.PIE);
   6         Graphics2D g2 = aPaintContext.getGraphics();
   8         g2.setPaint(;
   9         g2.fill(arc);
  10     }
  11 };

Then I had trouble selecting nodes that have the new shape. This was fixed with this modification in the selected() method:

   1 public void select() {
   2     selected = true;
   3     nodeView.setSelected(true); // added by mrsva
   4     drawSelected();
   5 }

and with the use of setPathToEllipse() and setBounds() in the drawNodeView() method.

also the context menu doesn't work in the nodes with the changed shape. I tried to change:

   1 view.addContextMethod( "class phoebe.PNodeView",                      // <-- changed line
   2                        "csplugins.mrsva.metadata.MDMenus",
   3                        "getMetaDataMenu",
   4                         new Object[] { view } ,
   5                         CytoscapeInit.getClassLoader() );


   1 view.addContextMethod( "class csplugins.mrsva.metadata.PieChartNode", // <-- changed line
   2                        "csplugins.mrsva.metadata.MDMenus",
   3                        "getMetaDataMenu",
   4                         new Object[] { view } ,
   5                         CytoscapeInit.getClassLoader() ); 

but this didn't helped.

Another problem, which affects the use of custom node views with the MetaNodes plugin, is that Cytoscape raises an exception when one tries to remove a node with the custom node view.

When I tried to remove such nodes (with custom view), I received the following exception:

        at phoebe.PGraphView.removeNodeView(
        at cytoscape.view.BasicGraphViewHandler.removeGraphViewNodes(
        at cytoscape.view.BasicGraphViewHandler.handleGraphPerspectiveEvent(
        at cytoscape.view.GraphViewController.graphPerspectiveChanged(
        at fing.model.GraphPerspectiveChangeListenerChain.graphPerspectiveChanged(
        at fing.model.FGraphPerspective$GraphWeeder.hideNode(
        at fing.model.FGraphPerspective$GraphWeeder.access$300(
        at fing.model.FGraphPerspective.hideNode(
        at metaNodeViewer.model.AbstractMetaNodeModeler.undoModel(
        at metaNodeViewer.MetaNodeUtils.uncollapseNodes(
        at metaNodeViewer.actions.UncollapseSelectedNodesAction.uncollapseSelectedNodes(
        at metaNodeViewer.actions.UncollapseSelectedNodesAction.actionPerformed(
        at javax.swing.AbstractButton.fireActionPerformed(
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(
        at javax.swing.DefaultButtonModel.fireActionPerformed(
        at javax.swing.DefaultButtonModel.setPressed(
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
        at java.awt.AWTEventMulticaster.mouseReleased(
        at java.awt.Component.processMouseEvent(
        at java.awt.Component.processEvent(
        at java.awt.Container.processEvent(
        at java.awt.Component.dispatchEventImpl(
        at java.awt.Container.dispatchEventImpl(
        at java.awt.Component.dispatchEvent(
        at java.awt.LightweightDispatcher.retargetMouseEvent(
        at java.awt.LightweightDispatcher.processMouseEvent(
        at java.awt.LightweightDispatcher.dispatchEvent(
        at java.awt.Container.dispatchEventImpl(
        at java.awt.Window.dispatchEventImpl(
        at java.awt.Component.dispatchEvent(
        at java.awt.EventQueue.dispatchEvent(
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(
        at java.awt.EventDispatchThread.pumpEvents(
        at java.awt.EventDispatchThread.pumpEvents(

I am not sure what that means, but looking at the method on the top of the list (phoebe.PGraphView.removeNodeView) I found that there is a cast to (PNodeView):

PNodeView node_view = ( PNodeView )getNodeView( node );

Shouldn't this be

NodeView node_view = ( NodeView )getNodeView( node );

as NodeView is the interface implemented by PNodeView (and by my PieChartNode)? Shouldn't we use the interface in such cases? If PNodeView is right here, how one can define other node views and remove them?

Then, in the case that the correct cast is NodeView, NodeView should have the interface for removeFromParent(). Here the complete code of phoebe.PGraphView.removeNodeView to explain why:

   1 public NodeView removeNodeView ( int node ) {
   2     PNodeView node_view = ( PNodeView )getNodeView( node );
   3     try {
   4       node_view.removeFromParent();
   5     } catch ( Exception e ) {
   6       System.out.println( "GINY at PGraphView.removeNodeView(int): Parent was most likely null for: "+node);
   7       return null;
   8     }
   9     nodeViewMap.removeKey( perspective.getRootGraphNodeIndex( node_view.getGraphPerspectiveIndex() ) );
  10     ensureNodeSelectionCapacity();
  11     nodeSelectionList.setQuick( node_view.getGraphPerspectiveIndex(), 0 );
  12     return node_view;
  13   }

so, node_view should have the method removeFromParent().

Here is the signature of my class (I didn't changed it from the PetalNode class):

   1 public class PieChartNode extends PPath
   2                           implements NodeView,
   3                                      PropertyChangeListener {

and PPath extends PNode.

Then I tried to modify phoebe and NodeView to test my theory. But when I load the sources of phoebe some methods are not recognized well. For example in the file phoebe.PGraphView, there is a call to edu.umd.cs.piccolo.PNode.firePropertyChange() but seems to be a difference in the signature of this method in PGraphView and in Piccolo. My guess is that a different version of Piccolo was used in the development of Phoebe and I got the version 1.1 of Piccolo website. Which version of Piccolo was used in the development of Phoebe?

Here the error I receive:

"The method firePropertyChange(int, String, Object, Object) in the type
  PNode is not applicable for the arguments (String, null, List)"

in this line:

   1 if ( firePiccoloEvents )
   2     firePropertyChange(PROPERTY_CHILDREN, null, getChildrenReference() ); 

Any ideas/discussion? Please, add your experience to this page.


ChangingNodeView (last edited 2009-02-12 01:03:51 by localhost)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux