Search in sources :

Example 51 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class CoordinateLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    Dimension retVal = new Dimension();
    int numOfcomponents = parent.getComponentCount();
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        retVal.setWidth(Math.max(retVal.getWidth(), cmp.getX() + cmp.getPreferredW()));
        retVal.setHeight(Math.max(retVal.getHeight(), cmp.getY() + cmp.getPreferredH()));
    }
    return retVal;
}
Also used : Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 52 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class GridLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    int width = 0;
    int height = 0;
    int numOfcomponents = parent.getComponentCount();
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        width = Math.max(width, cmp.getPreferredW() + cmp.getStyle().getMarginLeftNoRTL() + cmp.getStyle().getMarginRightNoRTL());
        height = Math.max(height, cmp.getPreferredH() + cmp.getStyle().getMarginTop() + cmp.getStyle().getMarginBottom());
    }
    boolean landscapeMode = isLandscapeMode();
    autoSizeCols(parent, parent.getWidth(), landscapeMode);
    int rows, columns;
    if (landscapeMode) {
        rows = landscapeRows;
        columns = landscapeColumns;
    } else {
        rows = portraitRows;
        columns = portraitColumns;
    }
    if (columns > 1) {
        width = width * columns;
    }
    if (rows > 1) {
        if (numOfcomponents > rows * columns) {
            // if there are more components than planned
            height = height * (numOfcomponents / columns + (numOfcomponents % columns == 0 ? 0 : 1));
        } else {
            height = height * rows;
        }
    }
    Style s = parent.getStyle();
    return new Dimension(width + s.getHorizontalPadding(), height + s.getVerticalPadding());
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 53 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class GridBagLayoutInfo method initCompsArray.

private Dimension initCompsArray(Container parent, Component[] components) {
    int maxW = 0;
    int maxH = 0;
    int i = 0;
    for (Component comp : comptable.keySet()) {
        GridBagConstraints cons = comptable.get(comp);
        if ((comp.getParent() == parent) && comp.isVisible()) {
            components[i++] = comp;
        }
        if ((cons.gridx != GridBagConstraints.RELATIVE) && (cons.gridy != GridBagConstraints.RELATIVE)) {
            maxW = Math.max(maxW, cons.gridx + cons.gridwidth);
            maxH = Math.max(maxH, cons.gridy + cons.gridheight);
        }
    }
    return new Dimension(maxW, maxH);
}
Also used : Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 54 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class GridBagLayoutInfo method validate.

private void validate(Container parent, ParentInfo info) {
    if (info.valid) {
        return;
    }
    info.valid = true;
    resetCache(parent, info);
    info.orientation = parent.isRTL();
    Dimension maxSize = initCompsArray(parent, info.components);
    new RelativeTranslator(maxSize.getWidth(), maxSize.getHeight()).translate(info);
    initCompSides(info);
    info.grid.validate(info);
    if (layoutInfo == null) {
        layoutInfo = new GridBagLayoutInfo(info.grid.lookupWidths(), info.grid.lookupHeights());
    } else {
        layoutInfo.update(info.grid.lookupWidths(), info.grid.lookupHeights());
    }
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 55 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class GroupLayout method layoutContainer.

/**
 * Returns the minimum size for the specified container.
 *
 * @param parent the container to return size for
 * @throws IllegalArgumentException if <code>parent</code> is not
 *         the same <code>Container</code> that this was created with
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 * @see java.awt.Container#getMinimumSize
 */
/*public Dimension minimumLayoutSize(Container parent) {
        checkParent(parent);
        prepare(MIN_SIZE);
        return adjustSize(horizontalGroup.getMinimumSize(HORIZONTAL),
                verticalGroup.getMinimumSize(VERTICAL));
    }*/
/**
 * Lays out the specified container.
 *
 * @param parent the container to be laid out
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    int insetLeft = parent.getStyle().getMarginLeftNoRTL();
    int insetTop = parent.getStyle().getMarginTop();
    int insetRight = parent.getStyle().getMarginRightNoRTL();
    int insetBottom = parent.getStyle().getMarginBottom();
    int width = parent.getWidth() - insetLeft - insetRight;
    int height = parent.getHeight() - insetTop - insetBottom;
    boolean ltr = isLeftToRight();
    if (getAutocreateGaps() || getAutocreateContainerGaps() || hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0, width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0, height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    Iterator componentInfo = componentInfos.values().iterator();
    while (componentInfo.hasNext()) {
        ComponentInfo info = (ComponentInfo) componentInfo.next();
        Component c = info.getComponent();
        info.setBounds(insetLeft, insetTop, width, ltr);
    }
}
Also used : Iterator(java.util.Iterator) Component(com.codename1.ui.Component)

Aggregations

Dimension (com.codename1.ui.geom.Dimension)74 Style (com.codename1.ui.plaf.Style)27 Component (com.codename1.ui.Component)16 Image (com.codename1.ui.Image)16 Rectangle (com.codename1.ui.geom.Rectangle)9 EncodedImage (com.codename1.ui.EncodedImage)8 Label (com.codename1.ui.Label)7 Container (com.codename1.ui.Container)6 FileEncodedImage (com.codename1.components.FileEncodedImage)5 StorageImage (com.codename1.components.StorageImage)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 Form (com.codename1.ui.Form)4 Dimension (java.awt.Dimension)4 Font (com.codename1.ui.Font)3 FontImage (com.codename1.ui.FontImage)3 TextArea (com.codename1.ui.TextArea)3 ActionListener (com.codename1.ui.events.ActionListener)3 Point (com.codename1.ui.geom.Point)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Border (com.codename1.ui.plaf.Border)3