Search in sources :

Example 56 with Dimension

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

the class Tree method calcPreferredSize.

/**
 * {@inheritDoc}
 */
protected Dimension calcPreferredSize() {
    Dimension d = super.calcPreferredSize();
    // if the tree is entirely collapsed try to reserve at least 6 rows for the content
    int count = getComponentCount();
    for (int iter = 0; iter < count; iter++) {
        if (getComponentAt(iter) instanceof Container) {
            return d;
        }
    }
    int size = Math.max(1, model.getChildren(null).size());
    if (size < 6) {
        return new Dimension(Math.max(d.getWidth(), Display.getInstance().getDisplayWidth() / 4 * 3), d.getHeight() / size * 6);
    }
    return d;
}
Also used : Container(com.codename1.ui.Container) Dimension(com.codename1.ui.geom.Dimension)

Example 57 with Dimension

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

the class BoxLayout 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);
        Style stl = cmp.getStyle();
        if (axis == Y_AXIS) {
            int cmpH = cmp.getPreferredH() + stl.getVerticalMargins();
            height += cmpH;
            width = Math.max(width, cmp.getPreferredW() + stl.getHorizontalMargins());
        } else {
            int cmpW = cmp.getPreferredW() + stl.getHorizontalMargins();
            width += cmpW;
            height = Math.max(height, cmp.getPreferredH() + stl.getVerticalMargins());
        }
    }
    Style s = parent.getStyle();
    dim.setWidth(width + s.getHorizontalPadding());
    dim.setHeight(height + s.getVerticalPadding());
    return dim;
}
Also used : Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

Example 58 with Dimension

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

the class BorderLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    dim.setWidth(0);
    dim.setHeight(0);
    Component east = getEast();
    Component west = getWest();
    Component south = getSouth();
    Component north = getNorth();
    Component center = getCenter();
    if (east != null) {
        dim.setWidth(east.getPreferredW() + east.getStyle().getMarginLeftNoRTL() + east.getStyle().getMarginRightNoRTL());
        dim.setHeight(Math.max(east.getPreferredH() + east.getStyle().getMarginTop() + east.getStyle().getMarginBottom(), dim.getHeight()));
    }
    if (west != null) {
        dim.setWidth(dim.getWidth() + west.getPreferredW() + west.getStyle().getMarginLeftNoRTL() + west.getStyle().getMarginRightNoRTL());
        dim.setHeight(Math.max(west.getPreferredH() + west.getStyle().getMarginTop() + west.getStyle().getMarginBottom(), dim.getHeight()));
    }
    if (center != null) {
        dim.setWidth(dim.getWidth() + center.getPreferredW() + center.getStyle().getMarginLeftNoRTL() + center.getStyle().getMarginRightNoRTL());
        dim.setHeight(Math.max(center.getPreferredH() + center.getStyle().getMarginTop() + center.getStyle().getMarginBottom(), dim.getHeight()));
    }
    if (north != null) {
        dim.setWidth(Math.max(north.getPreferredW() + north.getStyle().getMarginLeftNoRTL() + north.getStyle().getMarginRightNoRTL(), dim.getWidth()));
        dim.setHeight(dim.getHeight() + north.getPreferredH() + north.getStyle().getMarginTop() + north.getStyle().getMarginBottom());
    }
    if (south != null) {
        dim.setWidth(Math.max(south.getPreferredW() + south.getStyle().getMarginLeftNoRTL() + south.getStyle().getMarginRightNoRTL(), dim.getWidth()));
        dim.setHeight(dim.getHeight() + south.getPreferredH() + south.getStyle().getMarginTop() + south.getStyle().getMarginBottom());
    }
    dim.setWidth(dim.getWidth() + parent.getStyle().getHorizontalPadding());
    dim.setHeight(dim.getHeight() + parent.getStyle().getVerticalPadding());
    return dim;
}
Also used : Component(com.codename1.ui.Component)

Example 59 with Dimension

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

the class ImageIO method getImageSize.

/**
 * Returns the image size in pixels
 * @param imageFilePath the path to the image
 * @return the size in pixels
 */
public Dimension getImageSize(String imageFilePath) throws IOException {
    Image img = Image.createImage(imageFilePath);
    Dimension d = new Dimension(img.getWidth(), img.getHeight());
    img.dispose();
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage)

Example 60 with Dimension

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

the class CodenameOneMiGComponentWrapper method getLayoutHashCode.

public int getLayoutHashCode() {
    Dimension d = c.getPreferredSize();
    int hash = (d.getWidth() << 10) + (d.getHeight() << 15);
    if (c.isVisible())
        hash += 1324511;
    String id = getLinkId();
    if (id != null)
        hash += id.hashCode();
    return hash;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

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