* @todo this method is not yet fully working
*/
public void makeGrid( boolean elastic )
{
final List realOnes = new ArrayList( getComponentCount() );
final Spring xPadSpring, yPadSpring, initialXSpring, initialYSpring;
final int[] colCnt;
final int[] rowCnt;
final int effCols, effRows;
// final SpringLayout layout = new SpringLayout();
Spring maxWidthSpring, maxHeightSpring, spX, spY, spW, spH;
SpringLayout.Constraints cons;
// SpringLayout.Constraints lastCons = null;
// SpringLayout.Constraints lastRowCons = null;
Rectangle r;
Component comp;
JComponent jc;
int rows = 0;
int cols = 0;
// setLayout( layout );
xPadSpring = Spring.constant( xPad );
yPadSpring = Spring.constant( yPad );
initialXSpring = Spring.constant( initialX );
initialYSpring = Spring.constant( initialY );
for( int i = 0; i < getComponentCount(); i++ ) {
comp = getComponent( i );
layout.removeLayoutComponent( comp );
if( !(comp instanceof JComponent) || !comp.isVisible() ) continue;
jc = (JComponent) comp;
r = (Rectangle) jc.getClientProperty( GRID );
if( r == null ) continue;
realOnes.add( jc );
cols = Math.max( cols, r.x + r.width );
rows = Math.max( rows, r.y + r.height );
}
if( (cols == 0) || (rows == 0) ) return;
colCnt = new int[ cols ];
rowCnt = new int[ rows ];
for( int i = 0; i < realOnes.size(); i++ ) {
jc = (JComponent) realOnes.get( i );
r = (Rectangle) jc.getClientProperty( GRID );
for( int col = r.x; col < r.x + r.width; col++ ) {
colCnt[ col ]++;
}
for( int row = r.y; row < r.y + r.height; row++ ) {
rowCnt[ row ]++;
}
}
for( int col = 0, colOff = 0; col < cols; col++ ) {
if( colCnt[ col ] > 0 ) {
colCnt[ col ] = colOff++;
}
}
for( int row = 0, rowOff = 0; row < rows; row++ ) {
if( rowCnt[ row ] > 0 ) {
rowCnt[ row ] = rowOff++;
}
}
effCols = colCnt[ cols - 1 ] + 1;
effRows = rowCnt[ rows - 1 ] + 1;
if( elastic ) {
// maxWidthSpring = Spring.constant( 64 );
// maxHeightSpring = Spring.constant( 32 );
maxWidthSpring = new ComponentWidthRatioSpring( this, 1, effCols );
maxHeightSpring = new ComponentHeightRatioSpring( this, 1, effRows );
} else {
// Calculate Springs that are the max of the width/height so that all
// cells have the same size.
maxWidthSpring = Spring.constant( 0 );
maxHeightSpring = Spring.constant( 0 );
}
for( int i = 0; i < realOnes.size(); i++ ) {
jc = (JComponent) realOnes.get( i );
r = (Rectangle) jc.getClientProperty( GRID );
cons = layout.getConstraints( jc );
spW = new RatioSpring( cons.getWidth(), 1, r.width );
spH = new RatioSpring( cons.getHeight(), 1, r.height );
maxWidthSpring = Spring.max( maxWidthSpring, spW );
maxHeightSpring = Spring.max( maxHeightSpring, spH );
}
System.err.println( "cols "+cols+"; rows "+rows+"; maxWidthSpring "+maxWidthSpring.getValue()+
"; maxHeightSpring "+maxHeightSpring.getValue() );
// Apply the new width/height Spring. This forces all the
// components to have the same size.
// Adjust the x/y constraints of all the cells so that they