|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object thinwire.util.ArrayGrid<R,C>
public class ArrayGrid<R extends ArrayGrid.Row,C extends ArrayGrid.Column>
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.
Grid ag = new ArrayGrid(); Grid.Column col = new ArrayGrid.Column(); ag.getColumns().add(col); ag.getColumns().add(col); //!!! Don't do this.
Grid ag = new ArrayGrid(); Grid.Row row = new ArrayGrid.Row(); ag.getRows().add(row); ag.getRows().add(row); //!!! Don't do this.
Grid ag = new ArrayGrid(); Grid.Row row1 = new ArrayGrid.Row(); ag.getRows().add(row1); Grid.Row row2 = new ArrayGrid.Row(); Grid.row row3 = ag.getRows().set(0, row2); //Be careful with row3. Object rowVal = row3.get(0); //Be careful with rowVal.In the code above, row1 is replaced in ag with row2, and row3 is identical to row1. Despite its removal from ag, row1 (aka row3) still has ag as a parent. If you retrieve an element from row1 (aka row3), the value you retrieve may not be the exact Object placed in row1. The value you retrieve - e.g. rowVal in the code above - is a value converted from the original via ag's policy.
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 |
---|
public ArrayGrid()
public ArrayGrid(Grid<R,C> g)
g
- a grid that should be copied into this grid.protected ArrayGrid(Grid<R,C> grid, java.lang.Class<? extends ArrayGrid.Row> rowType, java.lang.Class<? extends ArrayGrid.Column> columnType)
grid
- the inner Grid to which this ArrayGrid provides access. May be null.rowType
- the class to which this ArrayGrid's Rows belongcolumnType
- the class to which this ArrayGrid's Columns belong
java.lang.ClassCastException
- if rowType does not extend Grid.Row or columnType does
not extend Grid.Column.Method Detail |
---|
public java.util.List<C> getColumns()
Grid
getColumns
in interface Grid<R extends ArrayGrid.Row,C extends ArrayGrid.Column>
Grid.getColumns()
public java.util.List<R> getRows()
Grid
getRows
in interface Grid<R extends ArrayGrid.Row,C extends ArrayGrid.Column>
Grid.getRows()
protected void fireItemChange(ItemChangeEvent.Type type, int rowIndex, int columnIndex, java.lang.Object oldValue, java.lang.Object newValue)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |