thinwire.util
Class ArrayGrid<R extends ArrayGrid.Row,C extends ArrayGrid.Column>

java.lang.Object
  extended by thinwire.util.ArrayGrid<R,C>
All Implemented Interfaces:
Grid<R,C>

public class ArrayGrid<R extends ArrayGrid.Row,C extends ArrayGrid.Column>
extends java.lang.Object
implements Grid<R,C>

ArrayGrid is an implementation of the Grid interface which provides a disconnected dataset.

The samples below populate an ArrayGrid with values from an array and then print out the values in the ArrayGrid.

Notes

Sample Code:
   int[][] values = new int[][]{ { 0, 1, 2, 3, 4 }, { 10, 11, 12, 13, 14 },
       { 20, 21, 22, 23, 24 }, { 30, 31, 32, 33, 34 }, { 40, 41, 42, 43, 44 } };
   
   ArrayGrid ag = new ArrayGrid();
   
   for (int i = 0; i < 5; i++) {
     ArrayGrid.Column col = new ArrayGrid.Column();
     ag.getColumns().add(col);
   }
   
   for (int i = 0; i < 5; i++) {
     ArrayGrid.Row row = new ArrayGrid.Row();
     ag.getRows().add(row);
   
     for (int j = 0; j < 5; j++) {
       row.set(j, new Integer(values[i][j]));
     }
   }
   
   System.out.println("\r\n");
   
   for (int i = 0; i < 5; i++) {
     ArrayGrid.Row row = (ArrayGrid.Row) ag.getRows().get(i);
     String line = "";
   
     for (int j = 0; j < 5; j++) {
       line += row.get(j) + " ";
     }
     System.out.println(line);
   }
 


Nested Class Summary
static class ArrayGrid.Column
          Contains an ArrayList of objects, each object associated with a different row.
static class ArrayGrid.Row
          Contains an ArrayList of objects, each object associated with a different column.
 
Constructor Summary
  ArrayGrid()
          Construct an ArrayGrid.
  ArrayGrid(Grid<R,C> g)
          Constructs an ArrayGrid based on another grid.
protected ArrayGrid(Grid<R,C> grid, java.lang.Class<? extends ArrayGrid.Row> rowType, java.lang.Class<? extends ArrayGrid.Column> columnType)
          Construct an ArrayGrid, specifying an optional inner Grid, a Row type, and a Column type.
 
Method Summary
protected  void fireItemChange(ItemChangeEvent.Type type, int rowIndex, int columnIndex, java.lang.Object oldValue, java.lang.Object newValue)
           
 java.util.List<C> getColumns()
          Get the Columns belonging to this Grid.
 java.util.List<R> getRows()
          Get the Rows belonging to this Grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayGrid

public ArrayGrid()
Construct an ArrayGrid.


ArrayGrid

public ArrayGrid(Grid<R,C> g)
Constructs an ArrayGrid based on another grid.

Parameters:
g - a grid that should be copied into this grid.

ArrayGrid

protected ArrayGrid(Grid<R,C> grid,
                    java.lang.Class<? extends ArrayGrid.Row> rowType,
                    java.lang.Class<? extends ArrayGrid.Column> columnType)
Construct an ArrayGrid, specifying an optional inner Grid, a Row type, and a Column type.

Parameters:
grid - the inner Grid to which this ArrayGrid provides access. May be null.
rowType - the class to which this ArrayGrid's Rows belong
columnType - the class to which this ArrayGrid's Columns belong
Throws:
java.lang.ClassCastException - if rowType does not extend Grid.Row or columnType does not extend Grid.Column.
Method Detail

getColumns

public java.util.List<C> getColumns()
Description copied from interface: Grid
Get the Columns belonging to this Grid.

Specified by:
getColumns in interface Grid<R extends ArrayGrid.Row,C extends ArrayGrid.Column>
Returns:
a list of all the columns in the Grid.
See Also:
Grid.getColumns()

getRows

public java.util.List<R> getRows()
Description copied from interface: Grid
Get the Rows belonging to this Grid.

Specified by:
getRows in interface Grid<R extends ArrayGrid.Row,C extends ArrayGrid.Column>
Returns:
a list of all the rows in the Grid.
See Also:
Grid.getRows()

fireItemChange

protected void fireItemChange(ItemChangeEvent.Type type,
                              int rowIndex,
                              int columnIndex,
                              java.lang.Object oldValue,
                              java.lang.Object newValue)


ThinWire® is a registered of Custom Credit Systems  Copyright © 2007 All rights reserved.
ThinWire_is_Open_Source_under_the_terms_of_the_LGPLv2.1 SourceForge.net_Project_Page java.net_Member Support_ThinWire,_Digg_our_Story