Logo Search packages:      
Sourcecode: filler version File versions  Download package

void friendless::awt::HCodeLayout::layoutContainer ( Container  parent  )  [inline]

Relocates the components of parent according to this layout.

Definition at line 107 of file HCodeLayout.java.

References getCode(), and getExpansion().

                                                  {
        boolean min;
        int height, width, exCount, expansion, h, v;
        Rectangle b = parent.getBounds();
        Insets insets = parent.getInsets();
        if (insets == null) insets = new Insets(0,0,0,0);
        if (debug) {
            System.out.println("HCodeLayout: Bounds: " + b);
            System.out.println("HCodeLayout: Insets: " + insets);
        }
        int actualHeight = b.height - insets.top - insets.bottom;
        int actualWidth = b.width - insets.left - insets.right;
        width = 0;
        exCount = 0;
        Component[] cs = parent.getComponents();
        // calculate preferred sizes
        width = 0;
        for (int i=0; i<cs.length; i++) {
            Dimension d = cs[i].getPreferredSize();
            StringBuffer code = getCode(cs[i]);
            int ex = getExpansion(code);
            if (ex > 0) {
                exCount += ex;
            } else {
                width += d.width;
            }
            width += hgap;
        }
        width -= hgap;
        // calculate size to expand zero height components to
        if (width >= actualWidth) {
            // preferred size is too big, so try minimum size
            min = true;
            width = 0;
            for (int i=0; i<cs.length; i++) {
                Dimension d = cs[i].getMinimumSize();
                StringBuffer code = getCode(cs[i]);
                int ex = getExpansion(code);
                if (ex > 0) {
                    exCount += ex;
                } else {
                    width += d.width;
                }
                width += hgap;
            }
            width -= hgap;
            expansion = 0;
            if ((exCount > 0) && (width < actualWidth)) {
                expansion = (actualWidth - width) / exCount;
            }
        } else if (exCount == 0) {
            // no expandable components
            min = false;
            expansion = 0;
        } else {
            min = false;
            expansion = (actualWidth-width)/exCount;
        }
        // layout
        width = insets.left;
        for (int i=0; i<cs.length; i++) {
            Dimension d = null;
            h = 0;
            // figure out vertical size
            if (min) {
                d = cs[i].getMinimumSize();
            } else {
                d = cs[i].getPreferredSize();
            }
            StringBuffer code = getCode(cs[i]);
            int ex = getExpansion(code);
            if (ex > 0) {
                h = expansion * ex;
                v = 0;
            } else {
                h = d.width;
                v = d.height;
            }
            // figure out vertical placement
            int top = insets.top;
            if (hasCode(code,'f')) {
                v = actualHeight;
            } else if ((v == 0) || (v > actualHeight)) {
                v = actualHeight;
            }
            if (hasCode(code,'b')) {
                top = actualHeight + insets.top - v;
            } else if (hasCode(code,'t')) {
                top = insets.top;
            } else {
                top = insets.top + (actualHeight - v)/2;
            }
            // place it
            cs[i].setBounds(width,top,h,v);
            width += h;
            width += hgap;
        }
    }


Generated by  Doxygen 1.6.0   Back to index