Search in sources :

Example 1 with ListCellRenderer

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

the class List method refreshTheme.

/**
 * {@inheritDoc}
 */
public void refreshTheme(boolean merge) {
    ListCellRenderer r = getRenderer();
    if (renderingPrototype != null) {
        r.getListCellRendererComponent(this, renderingPrototype, 0, false).refreshTheme(merge);
    } else {
        if (getModel().getSize() > 0) {
            r.getListCellRendererComponent(this, getModel().getItemAt(0), 0, false).refreshTheme(merge);
        } else {
            r.getListCellRendererComponent(this, "", 0, false).refreshTheme(merge);
        }
    }
    Component focus = r.getListFocusComponent(this);
    if (focus != null) {
        focus.refreshTheme(merge);
    }
    super.refreshTheme(merge);
}
Also used : ListCellRenderer(com.codename1.ui.list.ListCellRenderer) DefaultListCellRenderer(com.codename1.ui.list.DefaultListCellRenderer)

Example 2 with ListCellRenderer

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

the class EmailShare method createListRenderer.

private ListCellRenderer createListRenderer() {
    MultiButton sel = createRendererMultiButton();
    MultiButton unsel = createRendererMultiButton();
    return new GenericListCellRenderer(sel, unsel);
}
Also used : GenericListCellRenderer(com.codename1.ui.list.GenericListCellRenderer) MultiButton(com.codename1.components.MultiButton)

Example 3 with ListCellRenderer

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

the class SMSShare method createListRenderer.

private ListCellRenderer createListRenderer() {
    MultiButton sel = createRendererMultiButton();
    MultiButton unsel = createRendererMultiButton();
    return new GenericListCellRenderer(sel, unsel);
}
Also used : GenericListCellRenderer(com.codename1.ui.list.GenericListCellRenderer) MultiButton(com.codename1.components.MultiButton)

Example 4 with ListCellRenderer

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

the class DefaultLookAndFeel method drawComboBox.

/**
 * {@inheritDoc}
 */
public void drawComboBox(Graphics g, List cb) {
    int border = 2;
    Style style = cb.getStyle();
    int leftPadding = style.getPaddingLeft(cb.isRTL());
    int rightPadding = style.getPaddingRight(cb.isRTL());
    setFG(g, cb);
    ListModel model = cb.getModel();
    ListCellRenderer renderer = cb.getRenderer();
    Object value = model.getItemAt(model.getSelectedIndex());
    int comboImageWidth;
    if (comboImage != null) {
        comboImageWidth = comboImage.getWidth();
    } else {
        comboImageWidth = style.getFont().getHeight();
    }
    int cellX = cb.getX() + style.getPaddingTop();
    if (cb.isRTL()) {
        cellX += comboImageWidth;
    }
    if (model.getSize() > 0) {
        Component cmp = renderer.getListCellRendererComponent(cb, value, model.getSelectedIndex(), cb.hasFocus());
        cmp.setX(cellX);
        cmp.setY(cb.getY() + style.getPaddingTop());
        cmp.setWidth(cb.getWidth() - comboImageWidth - rightPadding - leftPadding);
        cmp.setHeight(cb.getHeight() - style.getPaddingTop() - style.getPaddingBottom());
        cmp.paint(g);
    }
    g.setColor(style.getBgColor());
    int y = cb.getY();
    int height = cb.getHeight();
    int width = comboImageWidth + border;
    int x = cb.getX();
    if (cb.isRTL()) {
        x += leftPadding;
    } else {
        x += cb.getWidth() - comboImageWidth - rightPadding;
    }
    if (comboImage != null) {
        g.drawImage(comboImage, x, y + height / 2 - comboImage.getHeight() / 2);
    } else {
        int color = g.getColor();
        // brighten or darken the color slightly
        int destColor = findDestColor(color);
        g.fillLinearGradient(g.getColor(), destColor, x, y, width, height, false);
        g.setColor(color);
        g.drawRect(x, y, width, height - 1);
        width--;
        height--;
        // g.drawRect(x, y, width, height);
        g.translate(x + 1, y + 1);
        g.setColor(0x111111);
        int x1 = scaleCoordinate(2.5652081f, 16, width);
        int y1 = scaleCoordinate(4.4753664f, 16, height);
        int x2 = scaleCoordinate(8.2872691f, 16, width);
        int y2 = scaleCoordinate(10f, 16, height);
        int x3 = scaleCoordinate(13.516078f, 16, width);
        int y3 = y1;
        g.fillTriangle(x1, y1, x2, y2, x3, y3);
        g.translate(-1, -1);
        g.setColor(style.getFgColor());
        g.fillTriangle(x1, y1, x2, y2, x3, y3);
        // g.setColor(style.getFgColor());
        // g.fillTriangle(x1 + 2, y1 + 2, x2, y2 - 2, x3 - 2, y3 + 2);
        g.translate(-x, -y);
    }
}
Also used : ListModel(com.codename1.ui.list.ListModel) ListCellRenderer(com.codename1.ui.list.ListCellRenderer) Component(com.codename1.ui.Component)

Example 5 with ListCellRenderer

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

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