*
* @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
*/
public Dimension preferredLayoutSize(Container theParent) {
synchronized (theParent.getTreeLock()) {
RelativeMatrix myBackend = this.getBackend();
initializeMatrixForContainer(theParent, myBackend);
// Check for dynamic sizes
boolean hasDynamicWidth = false;
boolean hasDynamicHeight = false;
for (Component thisComponent : this.constraints.keySet()) {
RelativeConstraints theseConstraints = this.constraints.get(thisComponent);
for (Binding thisBinding : theseConstraints.bindings) {
// If any of our bindings uses a dimensional variable, we have a dynamic size.
if (thisBinding.usesDimensionalVariable()) {
if (thisBinding.isHorizontal()) {
hasDynamicWidth = true;
} else {
hasDynamicHeight = true;
}
break;
}
}
}
// Calculate the screen size if we're going to need it.
int screenWidth = 0;
int screenHeight = 0;
if (hasDynamicWidth || hasDynamicHeight) {
GraphicsConfiguration graphicsConfig = theParent.getGraphicsConfiguration();
if (graphicsConfig == null) {
screenWidth = 640;
screenHeight = 480;
} else {
GraphicsDevice gs = graphicsConfig.getDevice();
DisplayMode dm = gs.getDisplayMode();
screenWidth = dm.getWidth();
screenHeight = dm.getHeight();
}
// If we found dynamic sizes, return the maximum size possible, and we're done.
if (hasDynamicWidth && hasDynamicHeight) {
return new Dimension(screenWidth, screenHeight);
}
}
// Otherwise, we have to generate solutions:
Map<Variable, Double> solutions = myBackend.solve();
// Now we find the max and min extents from all four corners:
double maxLeftExtent = 0.0, maxTopExtent = 0.0;
double minRightExtent = theParent.getSize().getWidth(), minBottomExtent = theParent.getSize().getHeight();