Search in sources :

Example 6 with ListCellRenderer

use of com.codename1.ui.list.ListCellRenderer 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)

Example 7 with ListCellRenderer

use of com.codename1.ui.list.ListCellRenderer in project CodenameOne by codenameone.

the class List method setShouldCalcPreferredSize.

/**
 * {@inheritDoc}
 */
public void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize) {
    super.setShouldCalcPreferredSize(shouldCalcPreferredSize);
    elemSize = null;
    selectedElemSize = null;
    // we should try passing the should calcPreferredSize to the renderer so it can revalidate too
    if (shouldCalcPreferredSize) {
        ListCellRenderer r = getRenderer();
        Object val;
        if (renderingPrototype != null) {
            val = renderingPrototype;
        } else {
            if (getModel().getSize() > 0) {
                val = getModel().getItemAt(0);
            } else {
                return;
            }
        }
        Component c = r.getListCellRendererComponent(this, val, 0, false);
        c.setShouldCalcPreferredSize(shouldCalcPreferredSize);
        c = r.getListCellRendererComponent(this, val, 0, true);
        c.setShouldCalcPreferredSize(shouldCalcPreferredSize);
    }
}
Also used : ListCellRenderer(com.codename1.ui.list.ListCellRenderer) DefaultListCellRenderer(com.codename1.ui.list.DefaultListCellRenderer)

Example 8 with ListCellRenderer

use of com.codename1.ui.list.ListCellRenderer in project CodenameOne by codenameone.

the class ComboBox method setUIID.

/**
 * {@inheritDoc}
 */
public void setUIID(String uiid) {
    super.setUIID(uiid);
    ListCellRenderer r = getRenderer();
    if (r instanceof Component) {
        Component c = (Component) getRenderer();
        c.setUIID(uiid + "Item");
    }
    Component c = getRenderer().getListFocusComponent(this);
    if (c != null) {
        c.setUIID(uiid + "Focus");
    }
}
Also used : ListCellRenderer(com.codename1.ui.list.ListCellRenderer) DefaultListCellRenderer(com.codename1.ui.list.DefaultListCellRenderer)

Aggregations

ListCellRenderer (com.codename1.ui.list.ListCellRenderer)6 DefaultListCellRenderer (com.codename1.ui.list.DefaultListCellRenderer)4 Component (com.codename1.ui.Component)3 MultiButton (com.codename1.components.MultiButton)2 Dimension (com.codename1.ui.geom.Dimension)2 GenericListCellRenderer (com.codename1.ui.list.GenericListCellRenderer)2 ListModel (com.codename1.ui.list.ListModel)2 Container (com.codename1.ui.Container)1 Style (com.codename1.ui.plaf.Style)1