Creating a card with the API

How to create a shelf with a card through the API

IlpDataSource dataSource = new IltDefaultDataSource();
// create shelf, set its position and add to data sources
IltShelf s1 = new IltShelf(3, 30, 90, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(20, 50));
dataSource.addObject(s1);

// create card, set its position (relative to the shelf slots) and
// add to data sources
IltCard c1 = new IltCard(null, "card");
c1.setAttributeValue(IltCard.PositionAttribute, 
                     new IlpShelfItemPosition(0, 0, 1, 1));
dataSource.addObject(c1);

// set parent-child relationship
dataSource.setParent(c1.getIdentifier(), s1.getIdentifier());
The result looks like this:
cardAPI.gif
A card in a shelf

How to associate cards with an array shelf by spanning slots

The following code illustrates cards associated with an array shelf through the use of slot spanning.
// create data source
IltDefaultDataSource dataSource = new IltDefaultDataSource();

// Create shelf
IltShelf s1 = new IltShelf(5, 20, 4, 25, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, 
  new IlpPoint(50, 50));
dataSource.addObject(s1);

// Create cards
IltCard c1 = new IltCard(null, "c1");
c1.setAttributeValue(IltCard.PositionAttribute, 
  new IlpShelfItemPosition(0, 0, 2.8f, 1.9f));
dataSource.addObject(c1);
IltCard c2 = new IltCard(null, "c2");
c2.setAttributeValue(IltCard.PositionAttribute, 
  new IlpShelfItemPosition(0, 2, 2.8f, 1.9f));
dataSource.addObject(c2);
IltCard c3 = new IltCard(null, "c3");
c3.setAttributeValue(IltCard.PositionAttribute, 
  new IlpShelfItemPosition(3, 0, 1.8f, 3.9f));
dataSource.addObject(c3);

// create relationship
dataSource.setParent(c1.getIdentifier(), s1.getIdentifier());
dataSource.setParent(c2.getIdentifier(), s1.getIdentifier());
dataSource.setParent(c3.getIdentifier(), s1.getIdentifier());
The result looks like this:
figure5.gif
An array shelf with spanned cards