Java Reference
In-Depth Information
Figure 12.10
Slider
In JavaFX, sequences are one dimensional and you cannot create a sequence of a
sequence. There is no notion of a two-dimensional array, like
Object[][]
. Even
if you attempt to create a matrix by assigning another sequence to one item, the
original sequence actually inserts the assigned sequence into itself. To get around
this, we have created a matrix class that uses a JavaFX sequence as a backing
store, but allows manipulation of the individual items using a row, column
approach.
The
Matrix
class contains a variable,
sequence
, that holds the backing
sequence. In addition, the
columns
variable holds the number of columns,
whereas
rows
holds the number or rows in the matrix. Notice that
rows
is read
only and is calculated based on the number of
columns
and the size of the
sequence
. Matrix is defined as illustrated in Listing 12.25.
Listing 12.25
Matrix
public class Matrix {
/** number of columns in Matrix */
public var
columns
: Integer = 1;
/** backing sequence for Matrix */
public var
sequence
: Object[];
/** number of rows in Matrix */
public-read var
rows
: Integer = bind
if(sizeof sequence mod columns > 0)
sizeof sequence / columns + 1
else
sizeof sequence / columns;
There are also
get
and
set
functions that use the row, column addressing
scheme to manipulate cell contents. These use the function
getIndex()
to calcu-
late the offset into the backing sequence by multiplying the row by the number of
columns and adding the column parameter to this.
Search WWH ::
Custom Search