Search in sources :

Example 81 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class DefaultLookAndFeel method drawLabelString.

/**
 * Implements the drawString for the text component and adjust the valign
 * assuming the icon is in one of the sides
 */
private int drawLabelString(Graphics g, Label l, String text, int x, int y, int textSpaceW) {
    Style style = l.getStyle();
    int cx = g.getClipX();
    int cy = g.getClipY();
    int cw = g.getClipWidth();
    int ch = g.getClipHeight();
    // g.pushClip();
    g.clipRect(x, cy, textSpaceW, ch);
    if (l.isTickerRunning()) {
        Font font = style.getFont();
        if (l.getShiftText() > 0) {
            if (l.getShiftText() > textSpaceW) {
                l.setShiftText(x - l.getX() - l.getStringWidth(font));
            }
        } else if (l.getShiftText() + l.getStringWidth(font) < 0) {
            l.setShiftText(textSpaceW);
        }
    }
    int drawnW = drawLabelText(g, l, text, x, y, textSpaceW);
    g.setClip(cx, cy, cw, ch);
    return drawnW;
}
Also used : Font(com.codename1.ui.Font)

Example 82 with Style

use of com.codename1.charts.compat.Paint.Style 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 83 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class DefaultLookAndFeel method updateCheckBoxConstants.

private void updateCheckBoxConstants(UIManager m, boolean focus, String append) {
    Image checkSel = m.getThemeImageConstant("checkBoxChecked" + append + "Image");
    if (checkSel != null) {
        Image checkUnsel = m.getThemeImageConstant("checkBoxUnchecked" + append + "Image");
        if (checkUnsel != null) {
            Image disUnsel = m.getThemeImageConstant("checkBoxUncheckDis" + append + "Image");
            Image disSel = m.getThemeImageConstant("checkBoxCheckDis" + append + "Image");
            if (disSel == null) {
                disSel = checkSel;
            }
            if (disUnsel == null) {
                disUnsel = checkUnsel;
            }
            if (focus) {
                setCheckBoxFocusImages(checkSel, checkUnsel, disSel, disUnsel);
            } else {
                setCheckBoxImages(checkSel, checkUnsel, disSel, disUnsel);
            }
        }
        if (checkUnsel != null) {
            if (focus) {
                setCheckBoxFocusImages(checkSel, checkUnsel, checkSel, checkUnsel);
            } else {
                setCheckBoxImages(checkSel, checkUnsel);
            }
        }
    } else {
        if (!Font.isTrueTypeFileSupported()) {
            return;
        }
        UIManager uim = UIManager.getInstance();
        Style unsel = uim.createStyle("CheckBox.", "", false);
        Style sel = uim.createStyle("CheckBox.", "sel#", true);
        Style dis = uim.createStyle("CheckBox.", "dis#", false);
        FontImage checkedDis = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX, dis);
        FontImage uncheckedDis = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX_OUTLINE_BLANK, sel);
        if (focus) {
            FontImage checkedSelected = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX, sel);
            FontImage uncheckedSelected = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX_OUTLINE_BLANK, sel);
            setCheckBoxFocusImages(checkedSelected, uncheckedSelected, checkedDis, uncheckedDis);
        } else {
            FontImage checkedUnselected = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX, unsel);
            FontImage uncheckedUnselected = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX_OUTLINE_BLANK, unsel);
            setCheckBoxImages(checkedUnselected, uncheckedUnselected, checkedDis, uncheckedDis);
        }
    }
}
Also used : Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage) FontImage(com.codename1.ui.FontImage)

Example 84 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class DefaultLookAndFeel method refreshTheme.

/**
 * {@inheritDoc}
 */
public void refreshTheme(boolean b) {
    chkBoxImages = null;
    comboImage = null;
    rButtonImages = null;
    chkBoxImagesFocus = null;
    rButtonImagesFocus = null;
    super.refreshTheme(b);
    UIManager m = getUIManager();
    Image combo = m.getThemeImageConstant("comboImage");
    if (combo != null) {
        setComboBoxImage(combo);
    } else {
        if (Font.isNativeFontSchemeSupported()) {
            Style c = UIManager.getInstance().createStyle("ComboBox.", "", false);
            combo = FontImage.createMaterial(FontImage.MATERIAL_ARROW_DROP_DOWN, c);
            setComboBoxImage(combo);
        }
    }
    updateCheckBoxConstants(m, false, "");
    updateCheckBoxConstants(m, true, "Focus");
    updateRadioButtonConstants(m, false, "");
    updateRadioButtonConstants(m, true, "Focus");
}
Also used : Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage)

Example 85 with Style

use of com.codename1.charts.compat.Paint.Style 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)

Aggregations

Style (com.codename1.ui.plaf.Style)103 Dimension (com.codename1.ui.geom.Dimension)28 Component (com.codename1.ui.Component)25 Image (com.codename1.ui.Image)20 Rectangle (com.codename1.ui.geom.Rectangle)13 Container (com.codename1.ui.Container)11 Font (com.codename1.ui.Font)11 FontImage (com.codename1.ui.FontImage)11 Border (com.codename1.ui.plaf.Border)8 Form (com.codename1.ui.Form)6 Label (com.codename1.ui.Label)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 IOException (java.io.IOException)6 UIManager (com.codename1.ui.plaf.UIManager)5 Vector (java.util.Vector)5 Dialog (com.codename1.ui.Dialog)4 EncodedImage (com.codename1.ui.EncodedImage)4 Graphics (com.codename1.ui.Graphics)4 TextArea (com.codename1.ui.TextArea)4 SpanButton (com.codename1.components.SpanButton)3