Search in sources :

Example 46 with Dimension

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

the class DefaultLookAndFeel method getComboBoxPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getComboBoxPreferredSize(List cb) {
    Dimension d = getListPreferredSize(cb);
    if (comboImage != null) {
        d.setWidth(d.getWidth() + comboImage.getWidth());
        d.setHeight(Math.max(d.getHeight(), comboImage.getHeight()));
    }
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 47 with Dimension

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

the class DefaultLookAndFeel method getListPreferredSizeImpl.

private Dimension getListPreferredSizeImpl(List l) {
    int width = 0;
    int height = 0;
    int selectedHeight;
    int selectedWidth;
    ListModel model = l.getModel();
    int numOfcomponents = Math.max(model.getSize(), l.getMinElementHeight());
    numOfcomponents = Math.min(numOfcomponents, l.getMaxElementHeight());
    Object prototype = l.getRenderingPrototype();
    Style unselectedEntryStyle = null;
    Style selectedEntryStyle;
    if (prototype != null) {
        ListCellRenderer renderer = l.getRenderer();
        Component cmp = renderer.getListCellRendererComponent(l, prototype, 0, false);
        height = cmp.getPreferredH();
        width = cmp.getPreferredW();
        unselectedEntryStyle = cmp.getStyle();
        cmp = renderer.getListCellRendererComponent(l, prototype, 0, true);
        selectedEntryStyle = cmp.getStyle();
        selectedHeight = Math.max(height, cmp.getPreferredH());
        selectedWidth = Math.max(width, cmp.getPreferredW());
    } else {
        int hightCalcComponents = Math.min(l.getListSizeCalculationSampleCount(), numOfcomponents);
        Object dummyProto = l.getRenderingPrototype();
        if (model.getSize() > 0 && dummyProto == null) {
            dummyProto = model.getItemAt(0);
        }
        ListCellRenderer renderer = l.getRenderer();
        for (int i = 0; i < hightCalcComponents; i++) {
            Object value;
            if (i < model.getSize()) {
                value = model.getItemAt(i);
            } else {
                value = dummyProto;
            }
            Component cmp = renderer.getListCellRendererComponent(l, value, i, false);
            if (cmp instanceof Container) {
                cmp.setShouldCalcPreferredSize(true);
            }
            unselectedEntryStyle = cmp.getStyle();
            height = Math.max(height, cmp.getPreferredH());
            width = Math.max(width, cmp.getPreferredW());
        }
        selectedEntryStyle = unselectedEntryStyle;
        selectedHeight = height;
        selectedWidth = width;
        if (model.getSize() > 0) {
            Object value = model.getItemAt(0);
            Component cmp = renderer.getListCellRendererComponent(l, value, 0, true);
            if (cmp instanceof Container) {
                cmp.setShouldCalcPreferredSize(true);
            }
            selectedHeight = Math.max(height, cmp.getPreferredH());
            selectedWidth = Math.max(width, cmp.getPreferredW());
            selectedEntryStyle = cmp.getStyle();
        }
    }
    if (unselectedEntryStyle != null) {
        selectedWidth += selectedEntryStyle.getMarginLeftNoRTL() + selectedEntryStyle.getMarginRightNoRTL();
        selectedHeight += selectedEntryStyle.getMarginTop() + selectedEntryStyle.getMarginBottom();
        width += unselectedEntryStyle.getMarginLeftNoRTL() + unselectedEntryStyle.getMarginRightNoRTL();
        height += unselectedEntryStyle.getMarginTop() + unselectedEntryStyle.getMarginBottom();
    }
    Style lStyle = l.getStyle();
    int verticalPadding = lStyle.getPaddingTop() + lStyle.getPaddingBottom();
    int horizontalPadding = lStyle.getPaddingRightNoRTL() + lStyle.getPaddingLeftNoRTL() + l.getSideGap();
    if (numOfcomponents == 0) {
        return new Dimension(horizontalPadding, verticalPadding);
    }
    // If combobox without ever importing the ComboBox class dependency
    if (l.getOrientation() > List.HORIZONTAL) {
        int boxWidth = l.getStyle().getFont().getHeight() + 2;
        return new Dimension(boxWidth + selectedWidth + horizontalPadding, selectedHeight + verticalPadding);
    } else {
        if (l.getOrientation() == List.VERTICAL) {
            return new Dimension(selectedWidth + horizontalPadding, selectedHeight + (height + l.getItemGap()) * (numOfcomponents - 1) + verticalPadding);
        } else {
            return new Dimension(selectedWidth + (width + l.getItemGap()) * (numOfcomponents - 1) + horizontalPadding, selectedHeight + verticalPadding);
        }
    }
}
Also used : Container(com.codename1.ui.Container) ListModel(com.codename1.ui.list.ListModel) ListCellRenderer(com.codename1.ui.list.ListCellRenderer) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 48 with Dimension

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

the class DefaultLookAndFeel method getCheckBoxPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getCheckBoxPreferredSize(Button cb) {
    if (cb.isToggle()) {
        return getButtonPreferredSize(cb);
    }
    threeImageCache[0] = cb.getMaskedIcon();
    threeImageCache[1] = cb.getRolloverIcon();
    threeImageCache[2] = cb.getPressedIcon();
    if (chkBoxImages != null) {
        return getPreferredSize(cb, threeImageCache, chkBoxImages[0]);
    }
    Dimension d = getPreferredSize(cb, threeImageCache, null);
    // checkbox square needs to be the height and width of the font height even
    // when no text is in the check box this is a good indication of phone DPI
    int checkBoxSquareSize = cb.getStyle().getFont().getHeight();
    // allow for checkboxes without a string within them
    d.setHeight(Math.max(checkBoxSquareSize, d.getHeight()));
    d.setWidth(d.getWidth() + checkBoxSquareSize + cb.getGap());
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 49 with Dimension

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

the class DefaultLookAndFeel method getPreferredSize.

/**
 * {@inheritDoc}
 */
private Dimension getPreferredSize(Label l, Image[] icons, Image stateImage) {
    int prefW = 0;
    int prefH = 0;
    Style style = l.getStyle();
    int gap = l.getGap();
    int ilen = icons.length;
    for (int i = 0; i < ilen; i++) {
        Image icon = icons[i];
        if (icon != null) {
            prefW = Math.max(prefW, icon.getWidth());
            prefH = Math.max(prefH, icon.getHeight());
        }
    }
    String text = l.getText();
    Font font = style.getFont();
    if (font == null) {
        System.out.println("Missing font for " + l);
        font = Font.getDefaultFont();
    }
    if (text != null && text.length() > 0) {
        // add the text size
        switch(l.getTextPosition()) {
            case Label.LEFT:
            case Label.RIGHT:
                prefW += font.stringWidth(text);
                prefH = Math.max(prefH, font.getHeight());
                break;
            case Label.BOTTOM:
            case Label.TOP:
                prefW = Math.max(prefW, font.stringWidth(text));
                prefH += font.getHeight();
                break;
        }
    }
    // add the state image(relevant for CheckBox\RadioButton)
    if (stateImage != null) {
        prefW += (stateImage.getWidth() + gap);
        prefH = Math.max(prefH, stateImage.getHeight());
    }
    if (icons[0] != null && text != null && text.length() > 0) {
        switch(l.getTextPosition()) {
            case Label.LEFT:
            case Label.RIGHT:
                prefW += gap;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                prefH += gap;
                break;
        }
    }
    if (l.isShowEvenIfBlank()) {
        prefH += style.getVerticalPadding();
        prefW += style.getHorizontalPadding();
    } else {
        if (prefH != 0) {
            prefH += style.getVerticalPadding();
        }
        if (prefW != 0) {
            prefW += style.getHorizontalPadding();
        }
    }
    if (style.getBorder() != null) {
        prefW = Math.max(style.getBorder().getMinimumWidth(), prefW);
        prefH = Math.max(style.getBorder().getMinimumHeight(), prefH);
    }
    if (isBackgroundImageDetermineSize() && style.getBgImage() != null) {
        prefW = Math.max(style.getBgImage().getWidth(), prefW);
        prefH = Math.max(style.getBgImage().getHeight(), prefH);
    }
    return new Dimension(prefW, prefH);
}
Also used : Dimension(com.codename1.ui.geom.Dimension) Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage) Font(com.codename1.ui.Font)

Example 50 with Dimension

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

the class Spinner method calcPreferredSize.

/**
 * {@inheritDoc}
 */
protected Dimension calcPreferredSize() {
    int boxWidth = 0;
    int verticalPadding = getStyle().getVerticalPadding();
    int horizontalPadding = getStyle().getHorizontalPadding();
    Object prototype = getRenderingPrototype();
    int selectedHeight;
    ListCellRenderer renderer = getRenderer();
    Component cmp;
    if (prototype != null) {
        cmp = renderer.getListCellRendererComponent(this, prototype, 0, true);
    } else {
        if (getModel().getSize() > 0) {
            cmp = renderer.getListCellRendererComponent(this, getModel().getItemAt(0), 0, true);
        } else {
            cmp = renderer.getListCellRendererComponent(this, null, 0, true);
        }
    }
    selectedHeight = cmp.getPreferredH();
    if (spinnerHandle != null) {
        if (spinnerHandle.getHeight() > selectedHeight) {
            selectedHeight = spinnerHandle.getHeight();
        }
        boxWidth += spinnerHandle.getWidth();
    }
    Dimension d;
    if (Display.getInstance().isTouchScreenDevice()) {
        if (ios7Mode) {
            d = new Dimension(cmp.getPreferredW() + boxWidth + horizontalPadding, (selectedHeight * 8 + verticalPadding));
        } else {
            d = new Dimension(cmp.getPreferredW() + boxWidth + horizontalPadding, (selectedHeight * getUIManager().getThemeConstant("spinnerElementsInt", 3) + verticalPadding));
        }
    } else {
        d = new Dimension(cmp.getPreferredW() + boxWidth + horizontalPadding, (selectedHeight + verticalPadding));
    }
    Style style = getStyle();
    if (style.getBorder() != null) {
        d.setWidth(Math.max(style.getBorder().getMinimumWidth(), d.getWidth()));
        d.setHeight(Math.max(style.getBorder().getMinimumHeight(), d.getHeight()));
    }
    return d;
}
Also used : ListCellRenderer(com.codename1.ui.list.ListCellRenderer) DefaultListCellRenderer(com.codename1.ui.list.DefaultListCellRenderer) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) 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