Java Reference
In-Depth Information
Listing 5.22
Grid Layout Functions - alignX()/alignY()
function alignX(node:Node, col:Integer): Number {
var alignment = _hAlignments[col];
if(alignment == Alignment.NORTHEAST or
alignment == Alignment.EAST or
alignment == Alignment.SOUTHEAST) {
return 0.0;
} else if(alignment == Alignment.NORTHWEST or
alignment == Alignment.WEST or
alignment == Alignment.SOUTHWEST) {
return colWidths[col] -
getNodePreferredWidth(node);
} else { // CENTER
return (colWidths[col] -
getNodePreferredWidth(node))/2;
}
}
function alignY(node:Node, row:Integer): Number {
var alignment = _vAlignments[row];
if(alignment == Alignment.NORTHEAST or
alignment == Alignment.NORTH or
alignment == Alignment.NORTHWEST) {
return 0.0;
} else if(alignment == Alignment.SOUTHEAST or
alignment == Alignment.SOUTH or
alignment == Alignment.SOUTHWEST) {
return rowHeights[row] -
getNodePreferredHeight(node);
} else { // CENTER
return (rowHeights[row] -
getNodePreferredHeight(node))/2;
}
}
To kick start the layout, we add a postinit block to do the layout. This does the
layout after all the instance variables in the class have been through the initializa-
tion process. We added a Boolean variable postInitted to indicate that this step
has completed.
postinit {
layout();
postInitted = true;
}
Now, we have to do one more thing. Whenever any of the public instance vari-
ables change, we need to recalculate the layout. We do this by adding on replace
triggers to these variable declarations. For example:
 
Search WWH ::




Custom Search