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

int [] com::jgoodies::forms::layout::FormLayout::distributedSizes ( List  formSpecs,
int  totalSize,
int  totalPrefSize,
int[]  inputSizes 
) [inline, private]

Distributes free space over columns and rows and returns the sizes after this distribution process.

Parameters:
formSpecs the column/row specifications to work with
totalSize the total available size
totalPrefSize the sum of all preferred sizes
inputSizes the input sizes
Returns:
the distributed sizes

Definition at line 1393 of file FormLayout.java.

References com::jgoodies::forms::layout::FormSpec::getResizeWeight().

Referenced by computeGridOrigins().

                                                      {
        double totalFreeSpace = totalSize - totalPrefSize;
        // Do nothing if there's no free space.
        if (totalFreeSpace < 0)
            return inputSizes;
            
        // Compute the total weight.
        int count = formSpecs.size();
        double totalWeight   = 0.0;
        for (int i=0; i < count; i++) {
            FormSpec formSpec = (FormSpec) formSpecs.get(i);
            totalWeight += formSpec.getResizeWeight();
        }
        
        // Do nothing if there's no resizing column.
        if (totalWeight == 0.0) 
            return inputSizes;
            
        int[] sizes = new int[count];
        
        double restSpace = totalFreeSpace;
        int    roundedRestSpace = (int) totalFreeSpace;
        for (int i=0; i < count; i++) {
            FormSpec formSpec = (FormSpec) formSpecs.get(i);
            double weight = formSpec.getResizeWeight();
            if (weight == FormSpec.NO_GROW) {
                sizes[i] = inputSizes[i];
            } else {
                double roundingCorrection = restSpace - roundedRestSpace;
                double extraSpace = totalFreeSpace * weight / totalWeight;
                double correctedExtraSpace = extraSpace - roundingCorrection;
                int roundedExtraSpace = (int) Math.round(correctedExtraSpace);
                sizes[i] = inputSizes[i] + roundedExtraSpace;
                restSpace -= extraSpace;
                roundedRestSpace -= roundedExtraSpace;
            }
        }
        return sizes;
    }


Generated by  Doxygen 1.6.0   Back to index