Logo Search packages:      
Sourcecode: libjgoodies-forms-java version File versions  Download package

Dimension com::jgoodies::forms::layout::FormLayout::computeLayoutSize ( Container  parent,
Measure  defaultWidthMeasure,
Measure  defaultHeightMeasure 
) [inline, private]

Computes and returns the layout size of the given parent container using the specified measures.

Parameters:
parent the container in which to do the layout
defaultWidthMeasure the measure used to compute the default width
defaultHeightMeasure the measure used to compute the default height
Returns:
the layout size of the parent container

Definition at line 1070 of file FormLayout.java.

References colComponents, colGroupIndices, colSpecs, computeMaximumFixedSpanTable(), computeOrigins(), constraintMap, com::jgoodies::forms::layout::CellConstraints::gridHeight, com::jgoodies::forms::layout::CellConstraints::gridWidth, com::jgoodies::forms::layout::CellConstraints::gridX, com::jgoodies::forms::layout::CellConstraints::gridY, groupedSizes(), initializeColAndRowComponentLists(), maximumSizes(), minimumWidthMeasure, rowComponents, rowGroupIndices, rowSpecs, com::jgoodies::forms::layout::FormLayout::Measure::sizeOf(), and sum().

Referenced by minimumLayoutSize(), and preferredLayoutSize().

                                                                       {
        synchronized (parent.getTreeLock()) {
            initializeColAndRowComponentLists();
            int[] colWidths  = maximumSizes(parent, colSpecs, colComponents, 
                                            minimumWidthMeasure,
                                            preferredWidthMeasure,
                                            defaultWidthMeasure);
            int[] rowHeights = maximumSizes(parent, rowSpecs, rowComponents,
                                            minimumHeightMeasure, 
                                            preferredHeightMeasure,
                                            defaultHeightMeasure);
            int[] groupedWidths  = groupedSizes(colGroupIndices, colWidths);
            int[] groupedHeights = groupedSizes(rowGroupIndices, rowHeights);

            // Convert sizes to origins.
            int[] xOrigins = computeOrigins(groupedWidths,  0);
            int[] yOrigins = computeOrigins(groupedHeights, 0);

            int width1  = sum(groupedWidths);
            int height1 = sum(groupedHeights);
            int maxWidth = width1;
            int maxHeight = height1;

            /*
             * Take components that span multiple columns or rows into account.
             * This shall be done if and only if a component spans an interval
             * that can grow. 
             */
            // First computes the maximum number of cols/rows a component
            // can span without spanning a growing column.
            int[] maxFixedSizeColsTable = computeMaximumFixedSpanTable(colSpecs);
            int[] maxFixedSizeRowsTable = computeMaximumFixedSpanTable(rowSpecs);
            
            for (Iterator i = constraintMap.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry entry = (Map.Entry) i.next();
                Component component = (Component) entry.getKey();
                if (!component.isVisible()) 
                    continue;
                
                CellConstraints constraints = (CellConstraints) entry.getValue();
                if ((constraints.gridWidth > 1) && 
                    (constraints.gridWidth > maxFixedSizeColsTable[constraints.gridX-1])) {
                    //int compWidth = minimumWidthMeasure.sizeOf(component);
                    int compWidth = defaultWidthMeasure.sizeOf(component);
                    //int compWidth = preferredWidthMeasure.sizeOf(component);
                    int gridX1 = constraints.gridX-1;
                    int gridX2 = gridX1 + constraints.gridWidth;
                    int lead  = xOrigins[gridX1];
                    int trail = width1 - xOrigins[gridX2];
                    int myWidth = lead + compWidth + trail;
                    if (myWidth > maxWidth) {
                        maxWidth = myWidth;
                    }
                }
            
                if ((constraints.gridHeight > 1) && 
                    (constraints.gridHeight > maxFixedSizeRowsTable[constraints.gridY-1])) {
                    //int compHeight = minimumHeightMeasure.sizeOf(component);
                    int compHeight = defaultHeightMeasure.sizeOf(component);
                    //int compHeight = preferredHeightMeasure.sizeOf(component);
                    int gridY1 = constraints.gridY-1;
                    int gridY2 = gridY1 + constraints.gridHeight;
                    int lead  = yOrigins[gridY1];
                    int trail = height1 - yOrigins[gridY2];
                    int myHeight = lead + compHeight + trail;
                    if (myHeight > maxHeight) {
                        maxHeight = myHeight;
                    }
                }
            }
            Insets insets = parent.getInsets();
            int width  = maxWidth  + insets.left + insets.right;
            int height = maxHeight + insets.top  + insets.bottom; 
            return new Dimension(width, height);
        }
    }


Generated by  Doxygen 1.6.0   Back to index