Search in sources :

Example 11 with Image

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

the class DefaultLookAndFeel method getPullToRefreshHeight.

/**
 * {@inheritDoc}
 */
public int getPullToRefreshHeight() {
    if (pull == null) {
        BorderLayout bl = new BorderLayout();
        bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
        pull = new Container(bl);
    }
    if (pullDown == null) {
        pullDown = new Label(getUIManager().localize("pull.down", "Pull down do refresh..."));
        pullDown.setUIID("PullToRefresh");
        Image i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
        if (i == null) {
            i = getDefaultRefreshIcon();
        }
        i = i.rotate(180);
        ((Label) pullDown).setIcon(i);
    }
    if (releaseToRefresh == null) {
        releaseToRefresh = new Label(getUIManager().localize("pull.release", "Release to refresh..."));
        releaseToRefresh.setUIID("PullToRefresh");
        Image i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
        if (i == null) {
            i = getDefaultRefreshIcon();
        }
        ((Label) releaseToRefresh).setIcon(i);
    }
    if (updating == null) {
        updating = new Container(new BoxLayout(BoxLayout.X_AXIS));
        ((Container) updating).addComponent(new InfiniteProgress());
        Label l = new Label(getUIManager().localize("pull.refresh", "Updating..."));
        l.setUIID("PullToRefresh");
        ((Container) updating).addComponent(l);
        pull.getUnselectedStyle().setPadding(0, 0, 0, 0);
        pull.getUnselectedStyle().setMargin(0, 0, 0, 0);
        pull.addComponent(BorderLayout.CENTER, updating);
        pull.layoutContainer();
        pull.setHeight(Math.max(pullDown.getPreferredH(), pull.getPreferredH()));
    }
    String s = UIManager.getInstance().getThemeConstant("pullToRefreshHeight", null);
    if (s != null) {
        float f = Util.toFloatValue(s);
        if (f > 0) {
            return Display.getInstance().convertToPixels(f);
        }
    }
    return pull.getHeight();
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) InfiniteProgress(com.codename1.components.InfiniteProgress) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage)

Example 12 with Image

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

the class DefaultLookAndFeel method drawCheckBox.

/**
 * {@inheritDoc}
 */
public void drawCheckBox(Graphics g, Button cb) {
    if (chkBoxImages != null) {
        Image x;
        if (chkBoxImagesFocus != null && chkBoxImagesFocus[0] != null && cb.hasFocus() && Display.getInstance().shouldRenderSelection(cb)) {
            if (cb.isEnabled()) {
                x = chkBoxImagesFocus[cb.isSelected() ? 1 : 0];
            } else {
                x = chkBoxImagesFocus[cb.isSelected() ? 3 : 2];
            }
        } else {
            if (cb.isEnabled()) {
                x = chkBoxImages[cb.isSelected() ? 1 : 0];
            } else {
                x = chkBoxImages[cb.isSelected() ? 3 : 2];
            }
        }
        drawComponent(g, cb, cb.getIconFromState(), x, 0);
    } else {
        Style style = cb.getStyle();
        // 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 height = cb.getStyle().getFont().getHeight();
        drawComponent(g, cb, cb.getIconFromState(), null, height);
        int gradientColor;
        g.setColor(style.getFgColor());
        gradientColor = style.getBgColor();
        int width = height;
        int rectWidth = scaleCoordinate(12f, 16, width);
        int tX = cb.getX();
        if (cb.isRTL()) {
            tX = tX + cb.getWidth() - style.getPaddingLeft(cb.isRTL()) - rectWidth;
        } else {
            tX += style.getPaddingLeft(cb.isRTL());
        }
        int tY = cb.getY() + style.getPaddingTop() + (cb.getHeight() - style.getPaddingTop() - style.getPaddingBottom()) / 2 - height / 2;
        g.translate(tX, tY);
        int x = scaleCoordinate(1.04f, 16, width);
        int y = scaleCoordinate(4.0f, 16, height);
        int rectHeight = scaleCoordinate(12f, 16, height);
        // brighten or darken the color slightly
        int destColor = findDestColor(gradientColor);
        g.fillLinearGradient(gradientColor, destColor, x + 1, y + 1, rectWidth - 2, rectHeight - 1, false);
        g.drawRoundRect(x, y, rectWidth, rectHeight, 5, 5);
        if (cb.isSelected()) {
            int color = g.getColor();
            g.setColor(0x111111);
            g.translate(0, 1);
            fillCheckbox(g, width, height);
            g.setColor(color);
            g.translate(0, -1);
            fillCheckbox(g, width, height);
        }
        g.translate(-tX, -tY);
    }
}
Also used : Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage)

Example 13 with Image

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

the class RoundBorder 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 (w > 0 && h > 0) {
        Object k = c.getClientProperty(CACHE_KEY + instanceVal);
        if (k instanceof CacheValue) {
            CacheValue val = (CacheValue) k;
            if (val.modificationTime == modificationTime && val.img.getWidth() == w && val.img.getHeight() == h) {
                g.drawImage(val.img, x, y);
                return;
            }
        }
    } else {
        return;
    }
    Image target = createTargetImage(c, w, h, true);
    g.drawImage(target, x, y);
    c.putClientProperty(CACHE_KEY + instanceVal, new CacheValue(target, modificationTime));
    // 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, new CacheValue(target, modificationTime));
                c.repaint();
            }
        }
    });
}
Also used : Image(com.codename1.ui.Image)

Example 14 with Image

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

the class Resources method openFileImpl.

private void openFileImpl(InputStream input) throws IOException {
    this.input = new DataInputStream(input);
    int resourceCount = this.input.readShort();
    if (resourceCount < 0) {
        throw new IOException("Invalid resource file!");
    }
    boolean password = false;
    keyOffset = 0;
    for (int iter = 0; iter < resourceCount; iter++) {
        byte magic = this.input.readByte();
        String id = this.input.readUTF();
        if (password) {
            magic = (byte) decode(magic & 0xff);
            char[] chars = id.toCharArray();
            int clen = chars.length;
            for (int i = 0; i < clen; i++) {
                chars[i] = (char) decode(chars[i] & 0xffff);
            }
            id = new String(chars);
        }
        startingEntry(id, magic);
        switch(magic) {
            case MAGIC_PASSWORD:
                checkKey(id);
                password = true;
                continue;
            case MAGIC_HEADER:
                readHeader();
                continue;
            case MAGIC_THEME:
                setResource(id, MAGIC_THEME, loadTheme(id, magic == MAGIC_THEME));
                continue;
            case MAGIC_IMAGE:
                Image img = createImage();
                img.setImageName(id);
                setResource(id, magic, img);
                continue;
            case MAGIC_FONT:
                setResource(id, magic, loadFont(this.input, id, false));
                continue;
            case MAGIC_DATA:
                setResource(id, magic, createData());
                continue;
            case MAGIC_UI:
                setResource(id, magic, createData());
                continue;
            case MAGIC_L10N:
                setResource(id, magic, loadL10N());
                continue;
            // legacy file support to be removed
            case MAGIC_IMAGE_LEGACY:
                setResource(id, MAGIC_IMAGE, createImage());
                continue;
            case MAGIC_INDEXED_IMAGE_LEGACY:
                setResource(id, MAGIC_IMAGE, createPackedImage8());
                continue;
            case MAGIC_THEME_LEGACY:
                setResource(id, MAGIC_THEME, loadTheme(id, magic == MAGIC_THEME));
                continue;
            case MAGIC_FONT_LEGACY:
                setResource(id, MAGIC_FONT, loadFont(this.input, id, false));
                continue;
            case MAGIC_INDEXED_FONT_LEGACY:
                setResource(id, MAGIC_FONT, loadFont(this.input, id, true));
                continue;
            default:
                throw new IOException("Corrupt theme file unrecognized magic number: " + Integer.toHexString(magic & 0xff));
        }
    }
}
Also used : IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage)

Example 15 with Image

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

the class Resources method loadBitmapFont.

Font loadBitmapFont(DataInputStream input, String id, com.codename1.ui.Font font) throws IOException {
    Image bitmap = createImage(input);
    int charCount = input.readShort();
    int[] cutOffsets = new int[charCount];
    int[] charWidth = new int[charCount];
    for (int iter = 0; iter < charCount; iter++) {
        cutOffsets[iter] = input.readShort();
    }
    for (int iter = 0; iter < charCount; iter++) {
        charWidth[iter] = input.readByte();
    }
    String charset = input.readUTF();
    readRenderingHint(input);
    if (font == null) {
        if (Font.isBitmapFontEnabled()) {
            Font old = Font.getBitmapFont(id);
            if (old != null) {
                // old resource file use Font.clearBitmapCache()
                return old;
            }
            return Font.createBitmapFont(id, bitmap, cutOffsets, charWidth, charset);
        }
    }
    return font;
}
Also used : Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage) Font(com.codename1.ui.Font)

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