Configuring a network component through the API

For details of the classes involved in the architecture of the network component, see Architecture of the network component.
The following example shows how to configure the network view through the API. For details o programming the individual services, see Network component services.

How to configure the network view with the API

IlpNetworkView view = network.getView();

 //Toolbar
 view.getToolBar().add(new IlpNetworkSelectButton(view));
 view.getToolBar().add(new IlpNetworkZoomResetButton(view));
 // Overview
 view.setOverviewVisible(true);
 // View interactor
 IltSelectInteractor selInteractor = new IltSelectInteractor();
 selInteractor.setEditingAllowed(true);
 IlpViewsViewInteractor viewsInteractor = 
    new IlpViewsViewInteractor(selInteractor);
 view.getController().setViewInteractor(viewsInteractor); 
 // Zoom policy
 view.setZoomPolicy(
   new IltMixedZoomPolicy() {{
     setZoomThreshold(2.0);
   }});
 // Layout
 view.setNodeLayout(new IlvGridLayout());
 view.setLinkLayout(new IltShortLinkLayout());
 // Background
 view.addBackgroundURL(
   context.getURLAccessService().getFileLocation(
     "data/images/europe.jpg"));
 // LayerPolicy
 view.getCompositeGrapher().setLayerPolicy(myLayerPolicy)
 // Position
 view.setPositionConverter(
   new IlpGeographicPositionConverter(projection,true));

How to configure the network adapter with the API

The following example shows how to configure the network adapter through the API. For details on programming the individual services, see Network component services.
IlpNetworkAdapter adapter = network.getAdapter();

// Filter
IlpFilter myFilter = new MyFilter();
// (it is the same as network.setFilter(myFilter);)
adapter.setFilter(myFilter);

// Origin
List myOrigins = new ArrayList();
myOrigins.add(objectID_1);
myOrigins.add(objectID_2);
:
:
myOrigins.add(objectID_n);
// in this case we want to display the origins
boolean showOrigin = true;
adapter.setOrigins(myOrigins, showOrigin);

// Expansion Strategy Factory
// Usually the expansion strategy factory relies
// on the adapter to access the data source and
// to load/release objects
IlpExpansionStrategyFactory myExpFactory = new 
  MyExpansionStrategyFactory(adapter);
adapter.setExpansionStrategyFactory(myExpFactory);

// Position Attribute
// Here, imagine that MyObject implements IlpObject
// interface and defines "Placement" as the 
// IlpAttribute that defines the object position
IlpClass myObjectClass = MyObject.getIlpClass();
IlpAttribute myPosAttrib = MyObject.Placement;
adapter.setPositionAttribute(myObjectClass, myPosAttrib);

// Node and Link Factory
IlpNetworkNodeFactory myNodeFactory = new MyNodeFactory();
adapter.setNodeFactory(myNodeFactory);

IlpNetworkLinkFactory myLinkFactory = new MyLinkFactory();
adapter.setLinkFactory(myLinkFactory);