JGraph 5.4

Event Notification in GraphLayoutCache

The GraphLayoutCache does no longer implement the Observable interface, it now has a full-featured event notification mechanism. The listener should implement the GraphLayoutCacheListener interface and add the instance using the addGraphLayoutCacheListener method on the layout cache. The layout cache delivers GraphLayoutCacheEvents from which you can retrieve the new and the previous attributes. (Note: This will be required to optimize repaint upon changes.) The getInserted and getRemoved methods return the cells that have been shown or hidden.

How to migrate?

For code migration all existing observers should now implement the above interface with the respective method and remove the observer's update method:

class ACacheListener implements GraphLayoutCacheListener { 
   public void graphLayoutCacheChanged(GraphLayoutCacheEvent e) { 
      ...

AttributeMap Does Not Store User Object

This fundamental change has the following advantages:

  • No custom storage map injection at cell creation time, i.e. so no setAttributeMap() call required

  • Graphcells must no longer keep the user object and the attribute map in sync

  • No double-referencing of the same user object from graphcell and attribute map

On the downside this adds another control attribute, in other words: You can not use attributes with the name value in a storage map.

How to migrate?

If you are using custom user objects then you should have implemented a custom attribute map with at least a valueChanged and clone method to take care of your custom user objects. If the attribute map only contains these two methods it is no longer required. Instead, you should create or use the custom graph model and override the following two methods:

public class GPGraphModel extends DefaultGraphModel { 
   protected Object cloneUserObject(Object userObject) { 
           ... 
   } 
   protected Object valueForCellChanged(Object cell, Object newValue) { 
           ... 
   } 
}

If the attribute map is no longer required then all calls to cell.setAttributes that were used to inject the map may also be removed. (See GPGraphModel in the JGraphpad project for an example.)

New Methods

3 useful static helper methods have been added to the DefaultGraphModel:

  • DefaultGraphModel.setSource/Target: Sets the source or target of an edge

  • DefaultGraphModel.getUserObject: Gets the user object from a graph cell

In the GraphModelChange the getConnectionSet and getParentMap methods have been added.

Other Changes

3 new attributes are available to control cell behaviour, 1 attribute has been renamed:

  • selectable/childrenSelectable: Enable/disable selection of cells and children

  • constrained: Forces constrained sizing on a cell

  • groupBorder attribute is now called inset

The JGraph.convertValueToString method has been changed to no longer map the cell. Instead, it uses the cell's toString method to determine the value. The method still handles view-local values though. See source code and javadocs for more details on the implementation.

Abbott Tests

Timothy Wall has contributed test code for the Abbot testing framework. Please see the test directory. You must download the latest version of Abbot to compile and run the tests.