/**
* Scaffold to draw cells in groups of 2 rows of 6 cells at a time.
* Represents a year's data with Jan-Jun on top and Jul-Dec on the
* Bottom. Will scroll through the data stored in an array, holding
* as many years as you want, one month per cell.
*/
public class TwoRowsSixCols implements Scaffold
{
private static final int cellWidthInPixels = 30;
private static final int cellHeightInPixels = 50;
/**
* Compute where other cells in the Scaffold
* should be positioned
* relative to the first one on the screen.
*
* @param i which cell needs to be placed,
* first one on screen is index 0,
* not necessarily the first one in the backing array.
*
* @return the relative x,y position
* of where the ith cell should go
* relative to the base cell on the screen.
*/
public static Point shape ( int i )
{
int gridRow = i / 6;
int gridCol = i % 6;
return new Point ( gridCol * cellWidthInPixels, gridRow * cellHeightInPixels );
}
/**
* How many cells are visible on the screen at a time?
*
* @return number of cells visible.
*/
public static int cellsVisible ( )
{
return 12;
}
/**
* Adjust which element of the array gets to go
* in the first cell on screen.
*
* @param candidateEltForFirstCell
* the array element index we are proposing putting in the
* the first cell position on screen.
*
* @param mustDisplayElt
* An array element index that
* must fit on the display, usually near the centre.
*
* @return our revised suggestion for
* which element to display in the first slot.
*/
public static int adjust( int candidateEltForFirstCell, int mustDisplayElt)
{
if ( candidateEltForFirstCell % 12 == 0 )
{
return candidateEltForFirstCell;
}
int smallerCandidateElt = (candidateEltForFirstCell) / 12) * 12;
int biggerCandidateElt = smallerCandidateElt + 12;
if ( mustDisplayElt >= biggerCandidateElt )
{
return biggerCandidateElt;
}
else
{
return smallerCandidateElt;
}
}
}