Search in sources :

Example 6 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class LookAndFeel method getTransitionConstant.

private Transition getTransitionConstant(Transition t, String constant, String slideDir, int speed, boolean forward) {
    Image img = manager.getThemeImageConstant(constant + "Image");
    if (img != null) {
        return CommonTransitions.createTimeline(img);
    }
    String val = manager.getThemeConstant(constant, null);
    if (val == null) {
        return t;
    }
    if (val.equalsIgnoreCase("empty")) {
        return CommonTransitions.createEmpty();
    }
    if (val.equalsIgnoreCase("slide")) {
        if (slideDir.equalsIgnoreCase("horizontal")) {
            return CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, forward, speed);
        } else {
            return CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, forward, speed);
        }
    }
    if (val.equalsIgnoreCase("cover")) {
        if (slideDir.equalsIgnoreCase("horizontal")) {
            return CommonTransitions.createCover(CommonTransitions.SLIDE_HORIZONTAL, forward, speed);
        } else {
            return CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, forward, speed);
        }
    }
    if (val.equalsIgnoreCase("uncover")) {
        if (slideDir.equalsIgnoreCase("horizontal")) {
            return CommonTransitions.createUncover(CommonTransitions.SLIDE_HORIZONTAL, forward, speed);
        } else {
            return CommonTransitions.createUncover(CommonTransitions.SLIDE_VERTICAL, forward, speed);
        }
    }
    if (val.equalsIgnoreCase("fslide")) {
        if (slideDir.equalsIgnoreCase("horizontal")) {
            return CommonTransitions.createFastSlide(CommonTransitions.SLIDE_HORIZONTAL, forward, speed);
        } else {
            return CommonTransitions.createFastSlide(CommonTransitions.SLIDE_VERTICAL, forward, speed);
        }
    }
    if (val.equalsIgnoreCase("fade")) {
        return CommonTransitions.createFade(speed);
    }
    if (val.equalsIgnoreCase("slidefade")) {
        return CommonTransitions.createSlideFadeTitle(forward, speed);
    }
    if (val.equalsIgnoreCase("pulse")) {
        return CommonTransitions.createDialogPulsate();
    }
    if (val.equalsIgnoreCase("bubble")) {
        BubbleTransition transition = new BubbleTransition(speed);
        transition.setRoundBubble(false);
        return transition;
    }
    return t;
}
Also used : BubbleTransition(com.codename1.ui.animations.BubbleTransition)

Example 7 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class RoundRectBorder method paintBorderBackground.

@Override
public void paintBorderBackground(Graphics g, final Component c) {
    final int w = c.getWidth();
    final int h = c.getHeight();
    int x = c.getX();
    int y = c.getY();
    if (shadowOpacity == 0) {
        Style s = c.getStyle();
        if (s.getBgImage() == null) {
            byte type = s.getBackgroundType();
            if (type == Style.BACKGROUND_IMAGE_SCALED || type == Style.BACKGROUND_NONE) {
                GeneralPath gp = createShape(w, h);
                byte bgt = c.getStyle().getBgTransparency();
                if (bgt != 0) {
                    int a = g.getAlpha();
                    g.setAlpha(bgt & 0xff);
                    g.setColor(s.getBgColor());
                    g.translate(x, y);
                    g.fillShape(gp);
                    if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
                        g.setAlpha(strokeOpacity);
                        g.setColor(strokeColor);
                        g.drawShape(gp, this.stroke);
                    }
                    g.translate(-x, -y);
                    g.setAlpha(a);
                }
                if (this.stroke != null && strokeOpacity > 0 && strokeThickness > 0) {
                    int a = g.getAlpha();
                    g.setAlpha(strokeOpacity);
                    g.setColor(strokeColor);
                    g.translate(x, y);
                    g.drawShape(gp, this.stroke);
                    g.translate(-x, -y);
                    g.setAlpha(a);
                }
                return;
            }
        }
    }
    if (w > 0 && h > 0) {
        Image background = (Image) c.getClientProperty(CACHE_KEY + instanceVal);
        if (background != null && background.getWidth() == w && background.getHeight() == h) {
            g.drawImage(background, x, y);
            return;
        }
    } else {
        return;
    }
    Image target = createTargetImage(c, w, h, true);
    g.drawImage(target, x, y);
    c.putClientProperty(CACHE_KEY + instanceVal, target);
    // update the cache with a more refined version and repaint
    Display.getInstance().callSeriallyOnIdle(new Runnable() {

        public void run() {
            if (w == c.getWidth() && h == c.getHeight()) {
                Image target = createTargetImage(c, w, h, false);
                c.putClientProperty(CACHE_KEY + instanceVal, target);
                c.repaint();
            }
        }
    });
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Image(com.codename1.ui.Image)

Example 8 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class DefaultLookAndFeel method updateRadioButtonConstants.

private void updateRadioButtonConstants(UIManager m, boolean focus, String append) {
    Image radioSel = m.getThemeImageConstant("radioSelected" + append + "Image");
    if (radioSel != null) {
        Image radioUnsel = m.getThemeImageConstant("radioUnselected" + append + "Image");
        if (radioUnsel != null) {
            Image disUnsel = m.getThemeImageConstant("radioUnselectedDis" + append + "Image");
            Image disSel = m.getThemeImageConstant("radioSelectedDis" + append + "Image");
            if (disUnsel == null) {
                disUnsel = radioUnsel;
            }
            if (disSel == null) {
                disSel = radioSel;
            }
            if (focus) {
                setRadioButtonFocusImages(radioSel, radioUnsel, disSel, disUnsel);
            } else {
                setRadioButtonImages(radioSel, radioUnsel, disSel, disUnsel);
            }
        }
    } else {
        if (!Font.isTrueTypeFileSupported()) {
            return;
        }
        UIManager uim = UIManager.getInstance();
        Style unsel = uim.createStyle("RadioButton.", "", false);
        Style sel = uim.createStyle("RadioButton.", "sel#", true);
        Style dis = uim.createStyle("RadioButton.", "dis#", false);
        FontImage checkedDis = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, dis);
        FontImage uncheckedDis = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, sel);
        if (focus) {
            FontImage checkedSelected = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, sel);
            FontImage uncheckedSelected = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, sel);
            setRadioButtonFocusImages(checkedSelected, uncheckedSelected, checkedDis, uncheckedDis);
        } else {
            FontImage checkedUnselected = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, unsel);
            FontImage uncheckedUnselected = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, unsel);
            setRadioButtonImages(checkedUnselected, uncheckedUnselected, checkedDis, uncheckedDis);
        }
    }
}
Also used : Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage) FontImage(com.codename1.ui.FontImage)

Example 9 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class DefaultLookAndFeel method drawComponent.

private void drawComponent(Graphics g, Label l, Image icon, Image stateIcon, int preserveSpaceForState) {
    setFG(g, l);
    int gap = l.getGap();
    int stateIconSize = 0;
    int stateIconYPosition = 0;
    String text = l.getText();
    Style style = l.getStyle();
    int cmpX = l.getX();
    int cmpY = l.getY();
    int cmpHeight = l.getHeight();
    int cmpWidth = l.getWidth();
    boolean rtl = l.isRTL();
    int leftPadding = style.getPaddingLeft(rtl);
    int rightPadding = style.getPaddingRight(rtl);
    int topPadding = style.getPaddingTop();
    int bottomPadding = style.getPaddingBottom();
    Font font = style.getFont();
    int fontHeight = 0;
    if (text == null) {
        text = "";
    }
    if (text.length() > 0) {
        fontHeight = font.getHeight();
    }
    int x = cmpX + leftPadding;
    int y = cmpY + topPadding;
    boolean opposite = false;
    if (stateIcon != null) {
        // square image width == height
        stateIconSize = stateIcon.getWidth();
        preserveSpaceForState = stateIconSize + gap;
        stateIconYPosition = cmpY + topPadding + (cmpHeight - topPadding - bottomPadding) / 2 - stateIconSize / 2;
        int tX = cmpX;
        if (((Button) l).isOppositeSide()) {
            if (rtl) {
                tX += leftPadding;
            } else {
                tX = tX + cmpWidth - leftPadding - stateIconSize;
            }
            cmpWidth -= leftPadding - stateIconSize;
            preserveSpaceForState = 0;
            opposite = true;
        } else {
            x = cmpX + leftPadding + preserveSpaceForState;
            if (rtl) {
                tX = tX + cmpWidth - leftPadding - stateIconSize;
            } else {
                tX += leftPadding;
            }
        }
        g.drawImage(stateIcon, tX, stateIconYPosition);
    }
    // default for bottom left alignment
    int align = reverseAlignForBidi(l, style.getAlignment());
    int textPos = reverseAlignForBidi(l, l.getTextPosition());
    // set initial x,y position according to the alignment and textPosition
    if (align == Component.LEFT) {
        switch(textPos) {
            case Label.LEFT:
            case Label.RIGHT:
                y = y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? icon.getHeight() : 0), fontHeight))) / 2;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                y = y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? icon.getHeight() + gap : 0) + fontHeight)) / 2;
                break;
        }
    } else if (align == Component.CENTER) {
        switch(textPos) {
            case Label.LEFT:
            case Label.RIGHT:
                x = x + (cmpWidth - (preserveSpaceForState + leftPadding + rightPadding + ((icon != null) ? icon.getWidth() + l.getGap() : 0) + l.getStringWidth(font))) / 2;
                if (!opposite) {
                    x = Math.max(x, cmpX + leftPadding + preserveSpaceForState);
                } else {
                    x = Math.min(x, cmpX + leftPadding + preserveSpaceForState);
                }
                y = y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? icon.getHeight() : 0), fontHeight))) / 2;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                x = x + (cmpWidth - (preserveSpaceForState + leftPadding + rightPadding + Math.max(((icon != null) ? icon.getWidth() + l.getGap() : 0), l.getStringWidth(font)))) / 2;
                if (!opposite) {
                    x = Math.max(x, cmpX + leftPadding + preserveSpaceForState);
                } else {
                    x = Math.min(x, cmpX + leftPadding + preserveSpaceForState);
                }
                y = y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? icon.getHeight() + gap : 0) + fontHeight)) / 2;
                break;
        }
    } else if (align == Component.RIGHT) {
        switch(textPos) {
            case Label.LEFT:
            case Label.RIGHT:
                x = cmpX + cmpWidth - rightPadding - (((icon != null) ? (icon.getWidth() + gap) : 0) + l.getStringWidth(font));
                if (l.isRTL()) {
                    if (!opposite) {
                        x = Math.max(x - preserveSpaceForState, cmpX + leftPadding);
                    } else {
                        x = Math.min(x - preserveSpaceForState, cmpX + leftPadding);
                    }
                } else {
                    if (!opposite) {
                        x = Math.max(x, cmpX + leftPadding + preserveSpaceForState);
                    } else {
                        x = Math.min(x, cmpX + leftPadding + preserveSpaceForState);
                    }
                }
                y = y + (cmpHeight - (topPadding + bottomPadding + Math.max(((icon != null) ? icon.getHeight() : 0), fontHeight))) / 2;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                x = cmpX + cmpWidth - rightPadding - (Math.max(((icon != null) ? (icon.getWidth()) : 0), l.getStringWidth(font)));
                if (!opposite) {
                    x = Math.max(x, cmpX + leftPadding + preserveSpaceForState);
                } else {
                    x = Math.min(x, cmpX + leftPadding + preserveSpaceForState);
                }
                y = y + (cmpHeight - (topPadding + bottomPadding + ((icon != null) ? icon.getHeight() + gap : 0) + fontHeight)) / 2;
                break;
        }
    }
    int textSpaceW = cmpWidth - rightPadding - leftPadding;
    if (icon != null && (textPos == Label.RIGHT || textPos == Label.LEFT)) {
        textSpaceW = textSpaceW - icon.getWidth();
    }
    if (stateIcon != null) {
        textSpaceW = textSpaceW - stateIconSize;
    } else {
        textSpaceW = textSpaceW - preserveSpaceForState;
    }
    if (icon == null) {
        // no icon only string
        drawLabelString(g, l, text, x, y, textSpaceW);
    } else {
        int strWidth = l.getStringWidth(font);
        int iconWidth = icon.getWidth();
        int iconHeight = icon.getHeight();
        int iconStringWGap;
        int iconStringHGap;
        switch(textPos) {
            case Label.LEFT:
                if (iconHeight > fontHeight) {
                    iconStringHGap = (iconHeight - fontHeight) / 2;
                    strWidth = drawLabelStringValign(g, l, text, x, y, iconStringHGap, iconHeight, textSpaceW, fontHeight);
                    g.drawImage(icon, x + strWidth + gap, y);
                } else {
                    iconStringHGap = (fontHeight - iconHeight) / 2;
                    strWidth = drawLabelString(g, l, text, x, y, textSpaceW);
                    g.drawImage(icon, x + strWidth + gap, y + iconStringHGap);
                }
                break;
            case Label.RIGHT:
                if (iconHeight > fontHeight) {
                    iconStringHGap = (iconHeight - fontHeight) / 2;
                    g.drawImage(icon, x, y);
                    drawLabelStringValign(g, l, text, x + iconWidth + gap, y, iconStringHGap, iconHeight, textSpaceW, fontHeight);
                } else {
                    iconStringHGap = (fontHeight - iconHeight) / 2;
                    g.drawImage(icon, x, y + iconStringHGap);
                    drawLabelString(g, l, text, x + iconWidth + gap, y, textSpaceW);
                }
                break;
            case Label.BOTTOM:
                if (iconWidth > strWidth) {
                    // center align the smaller
                    iconStringWGap = (iconWidth - strWidth) / 2;
                    g.drawImage(icon, x, y);
                    drawLabelString(g, l, text, x + iconStringWGap, y + iconHeight + gap, textSpaceW);
                } else {
                    iconStringWGap = (Math.min(strWidth, textSpaceW) - iconWidth) / 2;
                    g.drawImage(icon, x + iconStringWGap, y);
                    drawLabelString(g, l, text, x, y + iconHeight + gap, textSpaceW);
                }
                break;
            case Label.TOP:
                if (iconWidth > strWidth) {
                    // center align the smaller
                    iconStringWGap = (iconWidth - strWidth) / 2;
                    drawLabelString(g, l, text, x + iconStringWGap, y, textSpaceW);
                    g.drawImage(icon, x, y + fontHeight + gap);
                } else {
                    iconStringWGap = (Math.min(strWidth, textSpaceW) - iconWidth) / 2;
                    drawLabelString(g, l, text, x, y, textSpaceW);
                    g.drawImage(icon, x + iconStringWGap, y + fontHeight + gap);
                }
                break;
        }
    }
}
Also used : Button(com.codename1.ui.Button) Font(com.codename1.ui.Font)

Example 10 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class DefaultLookAndFeel method drawRadioButton.

/**
 * {@inheritDoc}
 */
public void drawRadioButton(Graphics g, Button rb) {
    if (rButtonImages != null) {
        Image x;
        if (rButtonImagesFocus != null && rButtonImagesFocus[0] != null && rb.hasFocus() && Display.getInstance().shouldRenderSelection(rb)) {
            if (rb.isEnabled()) {
                x = rButtonImagesFocus[rb.isSelected() ? 1 : 0];
            } else {
                x = rButtonImagesFocus[rb.isSelected() ? 3 : 2];
            }
        } else {
            if (rb.isEnabled()) {
                x = rButtonImages[rb.isSelected() ? 1 : 0];
            } else {
                x = rButtonImages[rb.isSelected() ? 3 : 2];
            }
        }
        drawComponent(g, rb, rb.getIconFromState(), x, 0);
    } else {
        Style style = rb.getStyle();
        // radio button radius needs to be of the size of the font height even
        // when no text is in the radio button this is a good indication of phone DPI
        int height = rb.getStyle().getFont().getHeight();
        drawComponent(g, rb, rb.getIconFromState(), null, height + rb.getGap());
        g.setColor(style.getFgColor());
        int x = rb.getX();
        if (rb.isRTL()) {
            x = x + rb.getWidth() - style.getPaddingLeft(rb.isRTL()) - height;
        } else {
            x += style.getPaddingLeft(rb.isRTL());
        }
        int y = rb.getY();
        // center the RadioButton
        y += Math.max(0, rb.getHeight() / 2 - height / 2);
        g.drawArc(x, y, height, height, 0, 360);
        if (rb.isSelected()) {
            int color = g.getColor();
            int destColor = findDestColor(color);
            g.fillRadialGradient(color, destColor, x + 3, y + 3, height - 5, height - 5);
        }
    }
}
Also used : Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage)

Aggregations

Image (com.codename1.ui.Image)82 EncodedImage (com.codename1.ui.EncodedImage)46 IOException (java.io.IOException)29 Hashtable (java.util.Hashtable)19 AnimationObject (com.codename1.ui.animations.AnimationObject)18 BufferedImage (java.awt.image.BufferedImage)18 Style (com.codename1.ui.plaf.Style)16 Form (com.codename1.ui.Form)15 ActionEvent (com.codename1.ui.events.ActionEvent)14 Dimension (com.codename1.ui.geom.Dimension)14 FontImage (com.codename1.ui.FontImage)13 BorderLayout (com.codename1.ui.layouts.BorderLayout)13 Timeline (com.codename1.ui.animations.Timeline)12 ActionListener (com.codename1.ui.events.ActionListener)12 Border (com.codename1.ui.plaf.Border)12 Container (com.codename1.ui.Container)11 InputStream (java.io.InputStream)11 Graphics (com.codename1.ui.Graphics)10 Label (com.codename1.ui.Label)10 Button (com.codename1.ui.Button)9