Creating a card carrier with the API

When creating a card carrier from the API, you must specify the number of slots it uses. This value is set in the constructor.

How to create a card carrier with the API

The following example shows how to create an empty card carrier with two free slots.
IltDefaultDataSource dataSource = new IltDefaultDataSource();
IltShelf s1 = new IltShelf(4, 20, 100, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(50, 50));
dataSource.addObject(s1);

IltCardCarrier cc1 = new IltCardCarrier(null, 2);  // number of slots
cc1.setAttributeValue(IltCardCarrier.PositionAttribute, 
  new IlpShelfItemPosition(1, 0, 1, 1));
dataSource.addObject(cc1);

dataSource.setParent(cc1.getIdentifier(), s1.getIdentifier());
The result looks like this:
Image5.gif
Shelf with a card carrier containing two free slots

How to create a shelf with two card carriers

The following code creates a shelf with two card carriers.
// Create a data source
IltDefaultDataSource dataSource = new IltDefaultDataSource();

// create shelf, set its position and add to data source
IltShelf s1 = new IltShelf(4, 20, 200, 0);
s1.setAttributeValue(IltShelf.PositionAttribute, new IlpPoint(50, 50));
dataSource.addObject(s1);

// create card carrier 1, set its position (relative to s1)
// and add to data source
IltCardCarrier cc1 = new IltCardCarrier(null, 2);
cc1.setAttributeValue(IltCardCarrier.PositionAttribute, 
  IlpShelfItemPosition(1, 0, 1, 1));
dataSource.addObject(cc1);

// create card carrier 2, set its position (relative to s1)
// and add to data source
IltCardCarrier cc2 = new IltCardCarrier(null, 1);
cc2.setAttributeValue(IltCardCarrier.PositionAttribute,
  new IlpShelfItemPosition(3, 0, 1, 1));
dataSource.addObject(cc2);

// create card 1, set its position (relative to cc1) and add 
// to data source
// note that the position is instance of IlpPoint, not
// IlpShelfItemPosition (card carriers require just one slot index and span)
IltCard c1 = new IltCard(null, "card1");
c1.setAttributeValue(IltCard.PositionAttribute, new IlpPoint(1, 1));
dataSource.addObject(c1);

// create card 2, set its position (relative to cc2) and add
// to data source
IltCard c2 = new IltCard(null, "card2");
c2.setAttributeValue(IltCard.PositionAttribute, new IlpPoint(0, 1));
dataSource.addObject(c2);

// set relationship
dataSource.setParent(c1.getIdentifier(), cc1.getIdentifier());
dataSource.setParent(c2.getIdentifier(), cc2.getIdentifier());
dataSource.setParent(cc1.getIdentifier(), s1.getIdentifier());
dataSource.setParent(cc2.getIdentifier(), s1.getIdentifier());
The result looks like this:
Image6.gif
Shelf with two card carriers
In this figure, the carrier of card1 has a free slot also. The second card carrier is fully occupied by card2 only.