How to display arbitrary yFiles (Java) realizers on a flex client using SWF nodes

Tips & Tricks

Summary

This article demonstrates how an arbitrary yFiles (Java) node realizer can be converted into SWF based vector graphics and displayed on the client using SWFNodeStyle.

Description

Although yFiles Flex offers some compatibility styles for displaying Java node realizers on the client, displaying (custom) realizers which have no corresponding styles on the client can be difficult. A viable approach can be to export these realizers into a vector based graphics format and display the images of these nodes on the client.

To serialize nodes as SWF nodes, one can use the provided SWFNodeSerializer.java and register it to the com.yworks.yfiles.server.graphml.support.Graph2DRoundtripSupport:

Graph2DRoundtripSupport support = new Graph2DRoundtripSupport() {

      public LayoutGraph createRoundtripGraph() {
        LayoutGraph graph = super.createRoundtripGraph();
        graph.addDataProvider(SWFNodeSerializer.NODE_2_SWF_CACHE_DPKEY, Maps.createHashedDataMap());
        return graph;
      }

      protected void configureHandler(GraphMLIOHandler handler) {
        super.configureHandler(handler);
        RealizerSerializerManager rsm = handler.getRealizerSerializerManager();
        SWFNodeSerializer shapeSwfNodeSerializer = new SWFNodeSerializer( ShapeNodeRealizer.class );
        SWFNodeSerializer gnrSwfNodeSerializer = new SWFNodeSerializer( GenericNodeRealizer.class );
        rsm.addNodeRealizerSerializer(shapeSwfNodeSerializer);
        rsm.addNodeRealizerSerializer(gnrSwfNodeSerializer);
      }
    };

The LoadSWFGraphServlet.java demonstrates how to extend the com.yworks.yfiles.server.graphml.demo.servlets.LoadGraphMLServlet to use the custom serializer.

The attached SWFNodeSerializer needs the FreeHEP VectorGraphics Java library.

Resources

Categories this article belongs to:
yFiles FLEX > yFiles FLEX Java Server API > Manipulating yFiles FLEX GraphML Style Data
yFiles FLEX > Using yFiles FLEX with a yFiles Server > Communicating with yFiles Java on the Server
Applies to:
yFiles FLEX: 1.6, 1.7, 1.8
Keywords:
SWF - SWFNodeStyle - conversion - image conversion